libfuse

fuse_common.h
Go to the documentation of this file.
1/* FUSE: Filesystem in Userspace
2 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
3
4 This program can be distributed under the terms of the GNU LGPLv2.
5 See the file COPYING.LIB.
6*/
7
10#include <stdbool.h>
11#if !defined(FUSE_H_) && !defined(FUSE_LOWLEVEL_H_)
12#error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
13#endif
14
15#ifndef FUSE_COMMON_H_
16#define FUSE_COMMON_H_
17
18#ifdef HAVE_LIBFUSE_PRIVATE_CONFIG_H
19#include "fuse_config.h"
20#endif
21
22#include "libfuse_config.h"
23
24#include "fuse_opt.h"
25#include "fuse_log.h"
26#include <stdint.h>
27#include <sys/types.h>
28#include <assert.h>
29
30#define FUSE_MAKE_VERSION(maj, min) ((maj) * 100 + (min))
31#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
32
33#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
34 (!defined(__cplusplus) && defined(__STDC_VERSION__) && \
35 __STDC_VERSION__ >= 201112L)
36#define fuse_static_assert(condition, message) static_assert(condition, message)
37#else
38#define fuse_static_assert(condition, message)
39#endif
40
41#ifdef __cplusplus
42 extern "C" {
43#endif
44
58 struct fuse_file_info {
60 int32_t flags;
61
68 uint32_t writepage : 1;
69
71 uint32_t direct_io : 1;
72
77 uint32_t keep_cache : 1;
78
82 uint32_t flush : 1;
83
86 uint32_t nonseekable : 1;
87
88 /* Indicates that flock locks for this file should be
89 released. If set, lock_owner shall contain a valid value.
90 May only be set in ->release(). */
91 uint32_t flock_release : 1;
92
97 uint32_t cache_readdir : 1;
98
101 uint32_t noflush : 1;
102
105 uint32_t parallel_direct_writes : 1;
106
108 uint32_t padding : 23;
109 uint32_t padding2 : 32;
110 uint32_t padding3 : 32;
111
115 uint64_t fh;
116
118 uint64_t lock_owner;
119
122 uint32_t poll_events;
123
127 int32_t backing_id;
128
130 uint64_t compat_flags;
131
132 uint64_t reserved[2];
133};
134fuse_static_assert(sizeof(struct fuse_file_info) == 64,
135 "fuse_file_info size mismatch");
136
147#if FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
148 struct fuse_loop_config_v1; /* forward declaration */
149 struct fuse_loop_config {
150#else
151 struct fuse_loop_config_v1 {
152#endif
157 int clone_fd;
158
169 unsigned int max_idle_threads;
170};
171
172
173/**************************************************************************
174 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want' *
175 **************************************************************************/
176
177 enum fuse_capability {
188 FUSE_CAP_ASYNC_READ = (1 << 0),
189
196 FUSE_CAP_POSIX_LOCKS = (1 << 1),
197
205 FUSE_CAP_ATOMIC_O_TRUNC = (1 << 3),
206
217 FUSE_CAP_EXPORT_SUPPORT = (1 << 4),
218
225 FUSE_CAP_DONT_MASK = (1 << 6),
226
233 FUSE_CAP_SPLICE_WRITE = (1 << 7),
234
241 FUSE_CAP_SPLICE_MOVE = (1 << 8),
242
250 FUSE_CAP_SPLICE_READ = (1 << 9),
251
263 FUSE_CAP_FLOCK_LOCKS = (1 << 10),
264
270 FUSE_CAP_IOCTL_DIR = (1 << 11),
271
292 FUSE_CAP_AUTO_INVAL_DATA = (1 << 12),
293
300 FUSE_CAP_READDIRPLUS = (1 << 13),
301
328 FUSE_CAP_READDIRPLUS_AUTO = (1 << 14),
329
339 FUSE_CAP_ASYNC_DIO = (1 << 15),
340
348 FUSE_CAP_WRITEBACK_CACHE = (1 << 16),
349
363 FUSE_CAP_NO_OPEN_SUPPORT = (1 << 17),
364
371 FUSE_CAP_PARALLEL_DIROPS = (1 << 18),
372
390 FUSE_CAP_POSIX_ACL = (1 << 19),
391
399 FUSE_CAP_HANDLE_KILLPRIV = (1 << 20),
400
416 FUSE_CAP_HANDLE_KILLPRIV_V2 = (1 << 21),
417
429 FUSE_CAP_CACHE_SYMLINKS = (1 << 23),
430
444 FUSE_CAP_NO_OPENDIR_SUPPORT = (1 << 24),
445
467 FUSE_CAP_EXPLICIT_INVAL_DATA = (1 << 25),
468
483 FUSE_CAP_EXPIRE_ONLY = (1 << 26),
484
490 FUSE_CAP_SETXATTR_EXT = (1 << 27),
491
499 FUSE_CAP_DIRECT_IO_ALLOW_MMAP = (1 << 28),
500
511 FUSE_CAP_PASSTHROUGH = (1 << 29),
512
519 FUSE_CAP_NO_EXPORT_SUPPORT = (1 << 30),
520
524 FUSE_CAP_CURRENT_MAX
525};
526
537#define FUSE_IOCTL_COMPAT (1 << 0)
538#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
539#define FUSE_IOCTL_RETRY (1 << 2)
540#define FUSE_IOCTL_DIR (1 << 4)
541
542#define FUSE_IOCTL_MAX_IOV 256
543
555 struct fuse_conn_info {
559 uint32_t proto_major;
560
564 uint32_t proto_minor;
565
569 uint32_t max_write;
570
583 uint32_t max_read;
584
588 uint32_t max_readahead;
589
595 uint32_t capable;
596
607 uint32_t want;
608
637 uint32_t max_background;
638
647 uint32_t congestion_threshold;
648
664 uint32_t time_gran;
665
682#define FUSE_BACKING_STACKED_UNDER (0)
683#define FUSE_BACKING_STACKED_OVER (1)
684 uint32_t max_backing_stack_depth;
685
694 uint32_t no_interrupt : 1;
695
696 /* reserved bits for future use */
697 uint32_t padding : 31;
698
703 uint64_t capable_ext;
704
713 uint64_t want_ext;
714
718 uint32_t reserved[16];
719};
720fuse_static_assert(sizeof(struct fuse_conn_info) == 128,
721 "Size of struct fuse_conn_info must be 128 bytes");
722
723 struct fuse_session;
724 struct fuse_pollhandle;
725 struct fuse_conn_info_opts;
726
769 struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
770
778 void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
779 struct fuse_conn_info *conn);
780
787 int fuse_daemonize(int foreground);
788
794 int fuse_version(void);
795
801 const char *fuse_pkgversion(void);
802
808 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
809
810/* ----------------------------------------------------------- *
811 * Data buffer *
812 * ----------------------------------------------------------- */
813
817 enum fuse_buf_flags {
824 FUSE_BUF_IS_FD = (1 << 1),
825
833 FUSE_BUF_FD_SEEK = (1 << 2),
834
842 FUSE_BUF_FD_RETRY = (1 << 3)
843};
844
848 enum fuse_buf_copy_flags {
858 FUSE_BUF_NO_SPLICE = (1 << 1),
859
866 FUSE_BUF_FORCE_SPLICE = (1 << 2),
867
875 FUSE_BUF_SPLICE_MOVE = (1 << 3),
876
884 FUSE_BUF_SPLICE_NONBLOCK= (1 << 4)
885};
886
893 struct fuse_buf {
897 size_t size;
898
902 enum fuse_buf_flags flags;
903
909 void *mem;
910
916 int fd;
917
923 off_t pos;
924
931 size_t mem_size;
932};
933
942 struct fuse_bufvec {
946 size_t count;
947
951 size_t idx;
952
956 size_t off;
957
961 struct fuse_buf buf[1];
962};
963
968 struct libfuse_version
969{
970 uint32_t major;
971 uint32_t minor;
972 uint32_t hotfix;
973 uint32_t padding;
974};
975
976/* Initialize bufvec with a single buffer of given size */
977#define FUSE_BUFVEC_INIT(size__) \
978 ((struct fuse_bufvec) { \
979 /* .count= */ 1, \
980 /* .idx = */ 0, \
981 /* .off = */ 0, \
982 /* .buf = */ { /* [0] = */ { \
983 /* .size = */ (size__), \
984 /* .flags = */ (enum fuse_buf_flags) 0, \
985 /* .mem = */ NULL, \
986 /* .fd = */ -1, \
987 /* .pos = */ 0, \
988 /* .mem_size = */ 0, \
989 } } \
990 } )
991
998 size_t fuse_buf_size(const struct fuse_bufvec *bufv);
999
1008ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
1009 enum fuse_buf_copy_flags flags);
1010
1011/* ----------------------------------------------------------- *
1012 * Signal handling *
1013 * ----------------------------------------------------------- */
1014
1030 int fuse_set_signal_handlers(struct fuse_session *se);
1031
1047 int fuse_set_fail_signal_handlers(struct fuse_session *se);
1048
1060 void fuse_remove_signal_handlers(struct fuse_session *se);
1061
1067#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
1073 struct fuse_loop_config *fuse_loop_cfg_create(void);
1074
1078 void fuse_loop_cfg_destroy(struct fuse_loop_config *config);
1079
1083 void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config,
1084 unsigned int value);
1085
1089 void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config,
1090 unsigned int value);
1091
1095 void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config,
1096 unsigned int value);
1097
1104 void fuse_loop_cfg_convert(struct fuse_loop_config *config,
1105 struct fuse_loop_config_v1 *v1_conf);
1106#endif
1107
1108
1109 static inline bool fuse_set_feature_flag(struct fuse_conn_info *conn,
1110 uint64_t flag)
1111{
1112 if (conn->capable_ext & flag) {
1113 conn->want_ext |= flag;
1114 return true;
1115 }
1116 return false;
1117}
1118
1119 static inline void fuse_unset_feature_flag(struct fuse_conn_info *conn,
1120 uint64_t flag)
1121{
1122 conn->want_ext &= ~flag;
1123}
1124
1125 static inline bool fuse_get_feature_flag(struct fuse_conn_info *conn,
1126 uint64_t flag)
1127{
1128 return conn->capable_ext & flag ? true : false;
1129}
1130
1131/* ----------------------------------------------------------- *
1132 * Compatibility stuff *
1133 * ----------------------------------------------------------- */
1134
1135#if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
1136# error only API version 30 or greater is supported
1137#endif
1138
1139#ifdef __cplusplus
1140}
1141#endif
1142
1143
1144/*
1145 * This interface uses 64 bit off_t.
1146 *
1147 * On 32bit systems please add -D_FILE_OFFSET_BITS=64 to your compile flags!
1148 */
1149
1150#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1151_Static_assert(sizeof(off_t) == 8, "fuse: off_t must be 64bit");
1152#else
1153 struct _fuse_off_t_must_be_64bit_dummy_struct \
1154 { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
1155#endif
1156
1157#endif /* FUSE_COMMON_H_ */
fuse_set_fail_signal_handlers
int fuse_set_fail_signal_handlers(struct fuse_session *se)
Definition fuse_signals.c:158
fuse_set_signal_handlers
int fuse_set_signal_handlers(struct fuse_session *se)
Definition fuse_signals.c:138
fuse_capability
fuse_capability
Definition fuse_common.h:177
FUSE_CAP_CURRENT_MAX
@ FUSE_CAP_CURRENT_MAX
Definition fuse_common.h:524
fuse_buf_size
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
Definition buffer.c:22
fuse_apply_conn_info_opts
void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts, struct fuse_conn_info *conn)
Definition helper.c:416
fuse_buf_flags
fuse_buf_flags
Definition fuse_common.h:817
FUSE_BUF_FD_SEEK
@ FUSE_BUF_FD_SEEK
Definition fuse_common.h:833
FUSE_BUF_FD_RETRY
@ FUSE_BUF_FD_RETRY
Definition fuse_common.h:842
FUSE_BUF_IS_FD
@ FUSE_BUF_IS_FD
Definition fuse_common.h:824
fuse_buf_copy
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
Definition buffer.c:284
fuse_parse_conn_info_opts
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
Definition helper.c:463
fuse_pkgversion
const char * fuse_pkgversion(void)
Definition fuse.c:5218
fuse_pollhandle_destroy
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
Definition fuse_lowlevel.c:1906
fuse_version
int fuse_version(void)
Definition fuse.c:5213
fuse_remove_signal_handlers
void fuse_remove_signal_handlers(struct fuse_session *se)
Definition fuse_signals.c:180
fuse_buf_copy_flags
fuse_buf_copy_flags
Definition fuse_common.h:848
FUSE_BUF_SPLICE_NONBLOCK
@ FUSE_BUF_SPLICE_NONBLOCK
Definition fuse_common.h:884
FUSE_BUF_FORCE_SPLICE
@ FUSE_BUF_FORCE_SPLICE
Definition fuse_common.h:866
FUSE_BUF_NO_SPLICE
@ FUSE_BUF_NO_SPLICE
Definition fuse_common.h:858
FUSE_BUF_SPLICE_MOVE
@ FUSE_BUF_SPLICE_MOVE
Definition fuse_common.h:875
fuse_daemonize
int fuse_daemonize(int foreground)
Definition helper.c:253
FUSE_CAP_IOCTL_DIR
#define FUSE_CAP_IOCTL_DIR
Definition fuse_common.h:269
FUSE_CAP_DONT_MASK
#define FUSE_CAP_DONT_MASK
Definition fuse_common.h:224
FUSE_CAP_HANDLE_KILLPRIV
#define FUSE_CAP_HANDLE_KILLPRIV
Definition fuse_common.h:398
FUSE_CAP_AUTO_INVAL_DATA
#define FUSE_CAP_AUTO_INVAL_DATA
Definition fuse_common.h:291
FUSE_CAP_HANDLE_KILLPRIV_V2
#define FUSE_CAP_HANDLE_KILLPRIV_V2
Definition fuse_common.h:415
FUSE_CAP_SPLICE_READ
#define FUSE_CAP_SPLICE_READ
Definition fuse_common.h:249
FUSE_CAP_PARALLEL_DIROPS
#define FUSE_CAP_PARALLEL_DIROPS
Definition fuse_common.h:370
FUSE_CAP_WRITEBACK_CACHE
#define FUSE_CAP_WRITEBACK_CACHE
Definition fuse_common.h:347
FUSE_CAP_EXPIRE_ONLY
#define FUSE_CAP_EXPIRE_ONLY
Definition fuse_common.h:482
FUSE_CAP_ATOMIC_O_TRUNC
#define FUSE_CAP_ATOMIC_O_TRUNC
Definition fuse_common.h:204
FUSE_CAP_ASYNC_READ
#define FUSE_CAP_ASYNC_READ
Definition fuse_common.h:187
FUSE_CAP_SPLICE_WRITE
#define FUSE_CAP_SPLICE_WRITE
Definition fuse_common.h:232
FUSE_CAP_CACHE_SYMLINKS
#define FUSE_CAP_CACHE_SYMLINKS
Definition fuse_common.h:428
FUSE_CAP_POSIX_ACL
#define FUSE_CAP_POSIX_ACL
Definition fuse_common.h:389
fuse_buf_flags
fuse_buf_flags
Definition fuse_common.h:810
FUSE_CAP_EXPORT_SUPPORT
#define FUSE_CAP_EXPORT_SUPPORT
Definition fuse_common.h:216
FUSE_CAP_POSIX_LOCKS
#define FUSE_CAP_POSIX_LOCKS
Definition fuse_common.h:195
FUSE_CAP_EXPLICIT_INVAL_DATA
#define FUSE_CAP_EXPLICIT_INVAL_DATA
Definition fuse_common.h:466
FUSE_CAP_READDIRPLUS_AUTO
#define FUSE_CAP_READDIRPLUS_AUTO
Definition fuse_common.h:327
FUSE_CAP_NO_OPENDIR_SUPPORT
#define FUSE_CAP_NO_OPENDIR_SUPPORT
Definition fuse_common.h:443
FUSE_CAP_ASYNC_DIO
#define FUSE_CAP_ASYNC_DIO
Definition fuse_common.h:338
FUSE_CAP_PASSTHROUGH
#define FUSE_CAP_PASSTHROUGH
Definition fuse_common.h:510
FUSE_CAP_DIRECT_IO_ALLOW_MMAP
#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP
Definition fuse_common.h:498
FUSE_CAP_NO_OPEN_SUPPORT
#define FUSE_CAP_NO_OPEN_SUPPORT
Definition fuse_common.h:362
FUSE_CAP_READDIRPLUS
#define FUSE_CAP_READDIRPLUS
Definition fuse_common.h:299
FUSE_CAP_SETXATTR_EXT
#define FUSE_CAP_SETXATTR_EXT
Definition fuse_common.h:489
FUSE_CAP_SPLICE_MOVE
#define FUSE_CAP_SPLICE_MOVE
Definition fuse_common.h:240
FUSE_CAP_NO_EXPORT_SUPPORT
#define FUSE_CAP_NO_EXPORT_SUPPORT
Definition fuse_common.h:518
FUSE_CAP_FLOCK_LOCKS
#define FUSE_CAP_FLOCK_LOCKS
Definition fuse_common.h:262
fuse_log.h
fuse_opt.h
fuse_args
Definition fuse_opt.h:109
fuse_buf
Definition fuse_common.h:893
fuse_buf::flags
enum fuse_buf_flags flags
Definition fuse_common.h:902
fuse_buf::mem_size
size_t mem_size
Definition fuse_common.h:931
fuse_buf::fd
int fd
Definition fuse_common.h:916
fuse_buf::pos
off_t pos
Definition fuse_common.h:923
fuse_buf::mem
void * mem
Definition fuse_common.h:909
fuse_buf::size
size_t size
Definition fuse_common.h:897
fuse_bufvec
Definition fuse_common.h:942
fuse_bufvec::off
size_t off
Definition fuse_common.h:956
fuse_bufvec::idx
size_t idx
Definition fuse_common.h:951
fuse_bufvec::count
size_t count
Definition fuse_common.h:946
fuse_conn_info
Definition fuse_common.h:555
fuse_conn_info::time_gran
uint32_t time_gran
Definition fuse_common.h:664
fuse_conn_info::proto_major
uint32_t proto_major
Definition fuse_common.h:559
fuse_conn_info::want
uint32_t want
Definition fuse_common.h:607
fuse_conn_info::congestion_threshold
uint32_t congestion_threshold
Definition fuse_common.h:647
fuse_conn_info::proto_minor
uint32_t proto_minor
Definition fuse_common.h:564
fuse_conn_info::max_write
uint32_t max_write
Definition fuse_common.h:569
fuse_conn_info::capable_ext
uint64_t capable_ext
Definition fuse_common.h:703
fuse_conn_info::max_readahead
uint32_t max_readahead
Definition fuse_common.h:588
fuse_conn_info::no_interrupt
uint32_t no_interrupt
Definition fuse_common.h:694
fuse_conn_info::max_read
uint32_t max_read
Definition fuse_common.h:583
fuse_conn_info::max_background
uint32_t max_background
Definition fuse_common.h:637
fuse_conn_info::capable
uint32_t capable
Definition fuse_common.h:595
fuse_conn_info::want_ext
uint64_t want_ext
Definition fuse_common.h:713
fuse_file_info
Definition fuse_common.h:58
fuse_file_info::lock_owner
uint64_t lock_owner
Definition fuse_common.h:118
fuse_file_info::fh
uint64_t fh
Definition fuse_common.h:115
fuse_file_info::writepage
uint32_t writepage
Definition fuse_common.h:68
fuse_file_info::poll_events
uint32_t poll_events
Definition fuse_common.h:122
fuse_file_info::cache_readdir
uint32_t cache_readdir
Definition fuse_common.h:97
fuse_file_info::nonseekable
uint32_t nonseekable
Definition fuse_common.h:86
fuse_file_info::backing_id
int32_t backing_id
Definition fuse_common.h:127
fuse_file_info::parallel_direct_writes
uint32_t parallel_direct_writes
Definition fuse_common.h:105
fuse_file_info::padding
uint32_t padding
Definition fuse_common.h:108
fuse_file_info::noflush
uint32_t noflush
Definition fuse_common.h:101
fuse_file_info::compat_flags
uint64_t compat_flags
Definition fuse_common.h:130
fuse_file_info::flush
uint32_t flush
Definition fuse_common.h:82
fuse_file_info::direct_io
uint32_t direct_io
Definition fuse_common.h:71
fuse_file_info::keep_cache
uint32_t keep_cache
Definition fuse_common.h:77
fuse_file_info::flags
int32_t flags
Definition fuse_common.h:60
fuse_loop_config
Definition fuse_common.h:149
fuse_loop_config::clone_fd
int clone_fd
Definition fuse_common.h:157
fuse_loop_config::max_idle_threads
unsigned int max_idle_threads
Definition fuse_common.h:169
libfuse_version
Definition fuse_common.h:969