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
42extern "C" {
43#endif
44
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
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)
148struct fuse_loop_config_v1; /* forward declaration */
150#else
151struct fuse_loop_config_v1 {
152#endif
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
187#define FUSE_CAP_ASYNC_READ (1 << 0)
188
195#define FUSE_CAP_POSIX_LOCKS (1 << 1)
196
204#define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
205
216#define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
217
224#define FUSE_CAP_DONT_MASK (1 << 6)
225
232#define FUSE_CAP_SPLICE_WRITE (1 << 7)
233
240#define FUSE_CAP_SPLICE_MOVE (1 << 8)
241
249#define FUSE_CAP_SPLICE_READ (1 << 9)
250
262#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
263
269#define FUSE_CAP_IOCTL_DIR (1 << 11)
270
291#define FUSE_CAP_AUTO_INVAL_DATA (1 << 12)
292
299#define FUSE_CAP_READDIRPLUS (1 << 13)
300
327#define FUSE_CAP_READDIRPLUS_AUTO (1 << 14)
328
338#define FUSE_CAP_ASYNC_DIO (1 << 15)
339
347#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
348
362#define FUSE_CAP_NO_OPEN_SUPPORT (1 << 17)
363
370#define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
371
389#define FUSE_CAP_POSIX_ACL (1 << 19)
390
398#define FUSE_CAP_HANDLE_KILLPRIV (1 << 20)
399
415#define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 21)
416
428#define FUSE_CAP_CACHE_SYMLINKS (1 << 23)
429
443#define FUSE_CAP_NO_OPENDIR_SUPPORT (1 << 24)
444
466#define FUSE_CAP_EXPLICIT_INVAL_DATA (1 << 25)
467
482#define FUSE_CAP_EXPIRE_ONLY (1 << 26)
483
489#define FUSE_CAP_SETXATTR_EXT (1 << 27)
490
498#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1 << 28)
499
510#define FUSE_CAP_PASSTHROUGH (1 << 29)
511
518#define FUSE_CAP_NO_EXPORT_SUPPORT (1 << 30)
519
530#define FUSE_IOCTL_COMPAT (1 << 0)
531#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
532#define FUSE_IOCTL_RETRY (1 << 2)
533#define FUSE_IOCTL_DIR (1 << 4)
534
535#define FUSE_IOCTL_MAX_IOV 256
536
552 uint32_t proto_major;
553
557 uint32_t proto_minor;
558
562 uint32_t max_write;
563
576 uint32_t max_read;
577
582
588 uint32_t capable;
589
600 uint32_t want;
601
631
641
657 uint32_t time_gran;
658
675#define FUSE_BACKING_STACKED_UNDER (0)
676#define FUSE_BACKING_STACKED_OVER (1)
677 uint32_t max_backing_stack_depth;
678
687 uint32_t no_interrupt : 1;
688
689 /* reserved bits for future use */
690 uint32_t padding : 31;
691
696 uint64_t capable_ext;
697
706 uint64_t want_ext;
707
711 uint32_t reserved[16];
712};
713fuse_static_assert(sizeof(struct fuse_conn_info) == 128,
714 "Size of struct fuse_conn_info must be 128 bytes");
715
716struct fuse_session;
717struct fuse_pollhandle;
718struct fuse_conn_info_opts;
719
762struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
763
771void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
772 struct fuse_conn_info *conn);
773
780int fuse_daemonize(int foreground);
781
787int fuse_version(void);
788
794const char *fuse_pkgversion(void);
795
801void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
802
803/* ----------------------------------------------------------- *
804 * Data buffer *
805 * ----------------------------------------------------------- */
806
817 FUSE_BUF_IS_FD = (1 << 1),
818
827
835 FUSE_BUF_FD_RETRY = (1 << 3)
837
879
886struct fuse_buf {
890 size_t size;
891
896
902 void *mem;
903
909 int fd;
910
916 off_t pos;
917
924 size_t mem_size;
925};
926
939 size_t count;
940
944 size_t idx;
945
949 size_t off;
950
954 struct fuse_buf buf[1];
955};
956
962{
963 uint32_t major;
964 uint32_t minor;
965 uint32_t hotfix;
966 uint32_t padding;
967};
968
969/* Initialize bufvec with a single buffer of given size */
970#define FUSE_BUFVEC_INIT(size__) \
971 ((struct fuse_bufvec) { \
972 /* .count= */ 1, \
973 /* .idx = */ 0, \
974 /* .off = */ 0, \
975 /* .buf = */ { /* [0] = */ { \
976 /* .size = */ (size__), \
977 /* .flags = */ (enum fuse_buf_flags) 0, \
978 /* .mem = */ NULL, \
979 /* .fd = */ -1, \
980 /* .pos = */ 0, \
981 /* .mem_size = */ 0, \
982 } } \
983 } )
984
991size_t fuse_buf_size(const struct fuse_bufvec *bufv);
992
1001ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
1002 enum fuse_buf_copy_flags flags);
1003
1004/* ----------------------------------------------------------- *
1005 * Signal handling *
1006 * ----------------------------------------------------------- */
1007
1023int fuse_set_signal_handlers(struct fuse_session *se);
1024
1040int fuse_set_fail_signal_handlers(struct fuse_session *se);
1041
1053void fuse_remove_signal_handlers(struct fuse_session *se);
1054
1060#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
1066struct fuse_loop_config *fuse_loop_cfg_create(void);
1067
1071void fuse_loop_cfg_destroy(struct fuse_loop_config *config);
1072
1076void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config,
1077 unsigned int value);
1078
1082void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config,
1083 unsigned int value);
1084
1088void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config,
1089 unsigned int value);
1090
1097void fuse_loop_cfg_convert(struct fuse_loop_config *config,
1098 struct fuse_loop_config_v1 *v1_conf);
1099#endif
1100
1101
1102static inline bool fuse_set_feature_flag(struct fuse_conn_info *conn,
1103 uint64_t flag)
1104{
1105 if (conn->capable_ext & flag) {
1106 conn->want_ext |= flag;
1107 return true;
1108 }
1109 return false;
1110}
1111
1112static inline void fuse_unset_feature_flag(struct fuse_conn_info *conn,
1113 uint64_t flag)
1114{
1115 conn->want_ext &= ~flag;
1116}
1117
1118static inline bool fuse_get_feature_flag(struct fuse_conn_info *conn,
1119 uint64_t flag)
1120{
1121 return conn->capable_ext & flag ? true : false;
1122}
1123
1124/* ----------------------------------------------------------- *
1125 * Compatibility stuff *
1126 * ----------------------------------------------------------- */
1127
1128#if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
1129# error only API version 30 or greater is supported
1130#endif
1131
1132#ifdef __cplusplus
1133}
1134#endif
1135
1136
1137/*
1138 * This interface uses 64 bit off_t.
1139 *
1140 * On 32bit systems please add -D_FILE_OFFSET_BITS=64 to your compile flags!
1141 */
1142
1143#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
1144_Static_assert(sizeof(off_t) == 8, "fuse: off_t must be 64bit");
1145#else
1146struct _fuse_off_t_must_be_64bit_dummy_struct \
1147 { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
1148#endif
1149
1150#endif /* FUSE_COMMON_H_ */
int fuse_set_fail_signal_handlers(struct fuse_session *se)
int fuse_set_signal_handlers(struct fuse_session *se)
size_t fuse_buf_size(const struct fuse_bufvec *bufv)
Definition buffer.c:22
void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts, struct fuse_conn_info *conn)
Definition helper.c:412
fuse_buf_flags
@ FUSE_BUF_FD_SEEK
@ FUSE_BUF_FD_RETRY
@ FUSE_BUF_IS_FD
ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, enum fuse_buf_copy_flags flags)
Definition buffer.c:284
struct fuse_conn_info_opts * fuse_parse_conn_info_opts(struct fuse_args *args)
Definition helper.c:459
const char * fuse_pkgversion(void)
Definition fuse.c:5234
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
int fuse_version(void)
Definition fuse.c:5229
void fuse_remove_signal_handlers(struct fuse_session *se)
fuse_buf_copy_flags
@ FUSE_BUF_SPLICE_NONBLOCK
@ FUSE_BUF_FORCE_SPLICE
@ FUSE_BUF_NO_SPLICE
@ FUSE_BUF_SPLICE_MOVE
int fuse_daemonize(int foreground)
Definition helper.c:253
fuse_buf_flags
enum fuse_buf_flags flags
size_t mem_size
off_t pos
void * mem
size_t size
uint32_t time_gran
uint32_t proto_major
uint32_t congestion_threshold
uint32_t proto_minor
uint32_t max_write
uint64_t capable_ext
uint32_t max_readahead
uint32_t no_interrupt
uint32_t max_read
uint32_t max_background
uint32_t capable
uint64_t want_ext
uint64_t lock_owner
uint32_t writepage
Definition fuse_common.h:68
uint32_t poll_events
uint32_t cache_readdir
Definition fuse_common.h:97
uint32_t nonseekable
Definition fuse_common.h:86
int32_t backing_id
uint32_t parallel_direct_writes
uint32_t padding
uint32_t noflush
uint64_t compat_flags
uint32_t flush
Definition fuse_common.h:82
uint32_t direct_io
Definition fuse_common.h:71
uint32_t keep_cache
Definition fuse_common.h:77
unsigned int max_idle_threads