libfuse: fuse-3.17.1-rc1/include/fuse_common.h Source File

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
58struct 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)
148struct fuse_loop_config_v1; /* forward declaration */
149struct fuse_loop_config {
150#else
151struct 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
555struct 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
723struct fuse_session;
724struct fuse_pollhandle;
725struct fuse_conn_info_opts;
726
769struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
770
778void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
779 struct fuse_conn_info *conn);
780
787int fuse_daemonize(int foreground);
788
794int fuse_version(void);
795
801const char *fuse_pkgversion(void);
802
808void 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
893struct 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
942struct 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
968struct 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
998size_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
1030int fuse_set_signal_handlers(struct fuse_session *se);
1031
1047int fuse_set_fail_signal_handlers(struct fuse_session *se);
1048
1060void fuse_remove_signal_handlers(struct fuse_session *se);
1061
1067#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
1073struct fuse_loop_config *fuse_loop_cfg_create(void);
1074
1078void fuse_loop_cfg_destroy(struct fuse_loop_config *config);
1079
1083void fuse_loop_cfg_set_idle_threads(struct fuse_loop_config *config,
1084 unsigned int value);
1085
1089void fuse_loop_cfg_set_max_threads(struct fuse_loop_config *config,
1090 unsigned int value);
1091
1095void fuse_loop_cfg_set_clone_fd(struct fuse_loop_config *config,
1096 unsigned int value);
1097
1104void fuse_loop_cfg_convert(struct fuse_loop_config *config,
1105 struct fuse_loop_config_v1 *v1_conf);
1106#endif
1107
1108
1109static 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
1119static inline void fuse_unset_feature_flag(struct fuse_conn_info *conn,
1120 uint64_t flag)
1121{
1122 conn->want_ext &= ~flag;
1123}
1124
1125static 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
1153struct _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_CAP_POSIX_ACL
@ FUSE_CAP_POSIX_ACL
Definition fuse_common.h:390
FUSE_CAP_READDIRPLUS
@ FUSE_CAP_READDIRPLUS
Definition fuse_common.h:300
FUSE_CAP_NO_OPENDIR_SUPPORT
@ FUSE_CAP_NO_OPENDIR_SUPPORT
Definition fuse_common.h:444
FUSE_CAP_PARALLEL_DIROPS
@ FUSE_CAP_PARALLEL_DIROPS
Definition fuse_common.h:371
FUSE_CAP_ASYNC_DIO
@ FUSE_CAP_ASYNC_DIO
Definition fuse_common.h:339
FUSE_CAP_NO_EXPORT_SUPPORT
@ FUSE_CAP_NO_EXPORT_SUPPORT
Definition fuse_common.h:519
FUSE_CAP_WRITEBACK_CACHE
@ FUSE_CAP_WRITEBACK_CACHE
Definition fuse_common.h:348
FUSE_CAP_IOCTL_DIR
@ FUSE_CAP_IOCTL_DIR
Definition fuse_common.h:270
FUSE_CAP_AUTO_INVAL_DATA
@ FUSE_CAP_AUTO_INVAL_DATA
Definition fuse_common.h:292
FUSE_CAP_SPLICE_READ
@ FUSE_CAP_SPLICE_READ
Definition fuse_common.h:250
FUSE_CAP_SPLICE_MOVE
@ FUSE_CAP_SPLICE_MOVE
Definition fuse_common.h:241
FUSE_CAP_POSIX_LOCKS
@ FUSE_CAP_POSIX_LOCKS
Definition fuse_common.h:196
FUSE_CAP_HANDLE_KILLPRIV_V2
@ FUSE_CAP_HANDLE_KILLPRIV_V2
Definition fuse_common.h:416
FUSE_CAP_HANDLE_KILLPRIV
@ FUSE_CAP_HANDLE_KILLPRIV
Definition fuse_common.h:399
FUSE_CAP_DONT_MASK
@ FUSE_CAP_DONT_MASK
Definition fuse_common.h:225
FUSE_CAP_ATOMIC_O_TRUNC
@ FUSE_CAP_ATOMIC_O_TRUNC
Definition fuse_common.h:205
FUSE_CAP_SPLICE_WRITE
@ FUSE_CAP_SPLICE_WRITE
Definition fuse_common.h:233
FUSE_CAP_PASSTHROUGH
@ FUSE_CAP_PASSTHROUGH
Definition fuse_common.h:511
FUSE_CAP_FLOCK_LOCKS
@ FUSE_CAP_FLOCK_LOCKS
Definition fuse_common.h:263
FUSE_CAP_EXPIRE_ONLY
@ FUSE_CAP_EXPIRE_ONLY
Definition fuse_common.h:483
FUSE_CAP_EXPORT_SUPPORT
@ FUSE_CAP_EXPORT_SUPPORT
Definition fuse_common.h:217
FUSE_CAP_READDIRPLUS_AUTO
@ FUSE_CAP_READDIRPLUS_AUTO
Definition fuse_common.h:328
FUSE_CAP_NO_OPEN_SUPPORT
@ FUSE_CAP_NO_OPEN_SUPPORT
Definition fuse_common.h:363
FUSE_CAP_DIRECT_IO_ALLOW_MMAP
@ FUSE_CAP_DIRECT_IO_ALLOW_MMAP
Definition fuse_common.h:499
FUSE_CAP_SETXATTR_EXT
@ FUSE_CAP_SETXATTR_EXT
Definition fuse_common.h:490
FUSE_CAP_ASYNC_READ
@ FUSE_CAP_ASYNC_READ
Definition fuse_common.h:188
FUSE_CAP_CACHE_SYMLINKS
@ FUSE_CAP_CACHE_SYMLINKS
Definition fuse_common.h:429
FUSE_CAP_EXPLICIT_INVAL_DATA
@ FUSE_CAP_EXPLICIT_INVAL_DATA
Definition fuse_common.h:467
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_log.h
fuse_opt.h
fuse_args
Definition fuse_opt.h:109
fuse_buf
Definition fuse_common.h:893
fuse_bufvec
Definition fuse_common.h:942
fuse_conn_info
Definition fuse_common.h:555
fuse_conn_info::capable_ext
uint64_t capable_ext
Definition fuse_common.h:703
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
libfuse_version
Definition fuse_common.h:969