libfuse: fuse-3.17.1.dir/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
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)
148struct fuse_loop_config_v1; /* forward declaration */
149 struct 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
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
548 struct fuse_conn_info {
552 uint32_t proto_major;
553
557 uint32_t proto_minor;
558
562 uint32_t max_write;
563
576 uint32_t max_read;
577
581 uint32_t max_readahead;
582
588 uint32_t capable;
589
600 uint32_t want;
601
630 uint32_t max_background;
631
640 uint32_t congestion_threshold;
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
810 enum fuse_buf_flags {
817 FUSE_BUF_IS_FD = (1 << 1),
818
826 FUSE_BUF_FD_SEEK = (1 << 2),
827
835 FUSE_BUF_FD_RETRY = (1 << 3)
836};
837
841 enum fuse_buf_copy_flags {
851 FUSE_BUF_NO_SPLICE = (1 << 1),
852
859 FUSE_BUF_FORCE_SPLICE = (1 << 2),
860
868 FUSE_BUF_SPLICE_MOVE = (1 << 3),
869
877 FUSE_BUF_SPLICE_NONBLOCK= (1 << 4)
878};
879
886 struct fuse_buf {
890 size_t size;
891
895 enum fuse_buf_flags flags;
896
902 void *mem;
903
909 int fd;
910
916 off_t pos;
917
924 size_t mem_size;
925};
926
935 struct fuse_bufvec {
939 size_t count;
940
944 size_t idx;
945
949 size_t off;
950
954 struct fuse_buf buf[1];
955};
956
961 struct libfuse_version
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_ */
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_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:412
fuse_buf_flags
fuse_buf_flags
Definition fuse_common.h:810
FUSE_BUF_FD_SEEK
@ FUSE_BUF_FD_SEEK
Definition fuse_common.h:826
FUSE_BUF_FD_RETRY
@ FUSE_BUF_FD_RETRY
Definition fuse_common.h:835
FUSE_BUF_IS_FD
@ FUSE_BUF_IS_FD
Definition fuse_common.h:817
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:459
fuse_pkgversion
const char * fuse_pkgversion(void)
Definition fuse.c:5234
fuse_pollhandle_destroy
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph)
Definition fuse_lowlevel.c:1907
fuse_version
int fuse_version(void)
Definition fuse.c:5229
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:841
FUSE_BUF_SPLICE_NONBLOCK
@ FUSE_BUF_SPLICE_NONBLOCK
Definition fuse_common.h:877
FUSE_BUF_FORCE_SPLICE
@ FUSE_BUF_FORCE_SPLICE
Definition fuse_common.h:859
FUSE_BUF_NO_SPLICE
@ FUSE_BUF_NO_SPLICE
Definition fuse_common.h:851
FUSE_BUF_SPLICE_MOVE
@ FUSE_BUF_SPLICE_MOVE
Definition fuse_common.h:868
fuse_daemonize
int fuse_daemonize(int foreground)
Definition helper.c:253
fuse_buf_flags
fuse_buf_flags
Definition fuse_common.h:808
fuse_log.h
fuse_opt.h
fuse_args
Definition fuse_opt.h:109
fuse_buf
Definition fuse_common.h:886
fuse_buf::flags
enum fuse_buf_flags flags
Definition fuse_common.h:895
fuse_buf::mem_size
size_t mem_size
Definition fuse_common.h:924
fuse_buf::fd
int fd
Definition fuse_common.h:909
fuse_buf::pos
off_t pos
Definition fuse_common.h:916
fuse_buf::mem
void * mem
Definition fuse_common.h:902
fuse_buf::size
size_t size
Definition fuse_common.h:890
fuse_bufvec
Definition fuse_common.h:935
fuse_bufvec::off
size_t off
Definition fuse_common.h:949
fuse_bufvec::idx
size_t idx
Definition fuse_common.h:944
fuse_bufvec::count
size_t count
Definition fuse_common.h:939
fuse_conn_info
Definition fuse_common.h:548
fuse_conn_info::time_gran
uint32_t time_gran
Definition fuse_common.h:657
fuse_conn_info::proto_major
uint32_t proto_major
Definition fuse_common.h:552
fuse_conn_info::want
uint32_t want
Definition fuse_common.h:600
fuse_conn_info::congestion_threshold
uint32_t congestion_threshold
Definition fuse_common.h:640
fuse_conn_info::proto_minor
uint32_t proto_minor
Definition fuse_common.h:557
fuse_conn_info::max_write
uint32_t max_write
Definition fuse_common.h:562
fuse_conn_info::capable_ext
uint64_t capable_ext
Definition fuse_common.h:696
fuse_conn_info::max_readahead
uint32_t max_readahead
Definition fuse_common.h:581
fuse_conn_info::no_interrupt
uint32_t no_interrupt
Definition fuse_common.h:687
fuse_conn_info::max_read
uint32_t max_read
Definition fuse_common.h:576
fuse_conn_info::max_background
uint32_t max_background
Definition fuse_common.h:630
fuse_conn_info::capable
uint32_t capable
Definition fuse_common.h:588
fuse_conn_info::want_ext
uint64_t want_ext
Definition fuse_common.h:706
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:962