libfuse: fuse-3.17.1.dir/lib/fuse_i.h Source File

libfuse

fuse_i.h
1/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
4
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB
7*/
8
9#include "fuse.h"
10#include "fuse_lowlevel.h"
11#include "util.h"
12
13#include <stdint.h>
14#include <stdbool.h>
15#include <errno.h>
16
17#define MIN(a, b) \
18({ \
19 typeof(a) _a = (a); \
20 typeof(b) _b = (b); \
21 _a < _b ? _a : _b; \
22})
23
24struct mount_opts;
25
26struct fuse_req {
27 struct fuse_session *se;
28 uint64_t unique;
29 _Atomic int ref_cnt;
30 pthread_mutex_t lock;
31 struct fuse_ctx ctx;
32 struct fuse_chan *ch;
33 int interrupted;
34 unsigned int ioctl_64bit : 1;
35 union {
36 struct {
37 uint64_t unique;
38 } i;
39 struct {
40 fuse_interrupt_func_t func;
41 void *data;
42 } ni;
43 } u;
44 struct fuse_req *next;
45 struct fuse_req *prev;
46};
47
48struct fuse_notify_req {
49 uint64_t unique;
50 void (*reply)(struct fuse_notify_req *, fuse_req_t, fuse_ino_t,
51 const void *, const struct fuse_buf *);
52 struct fuse_notify_req *next;
53 struct fuse_notify_req *prev;
54};
55
56struct fuse_session {
57 char *mountpoint;
58 volatile int exited;
59 int fd;
60 struct fuse_custom_io *io;
61 struct mount_opts *mo;
62 int debug;
63 int deny_others;
64 struct fuse_lowlevel_ops op;
65 int got_init;
66 struct cuse_data *cuse_data;
67 void *userdata;
68 uid_t owner;
69 struct fuse_conn_info conn;
70 struct fuse_req list;
71 struct fuse_req interrupts;
72 pthread_mutex_t lock;
73 int got_destroy;
74 pthread_key_t pipe_key;
75 int broken_splice_nonblock;
76 uint64_t notify_ctr;
77 struct fuse_notify_req notify_list;
78 size_t bufsize;
79 int error;
80
81 /* This is useful if any kind of ABI incompatibility is found at
82 * a later version, to 'fix' it at run time.
83 */
84 struct libfuse_version version;
85 bool buf_reallocable;
86};
87
88struct fuse_chan {
89 pthread_mutex_t lock;
90 int ctr;
91 int fd;
92};
93
101 struct fuse_module {
102 char *name;
103 fuse_module_factory_t factory;
104 struct fuse_module *next;
105 struct fusemod_so *so;
106 int ctr;
107};
108
117#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
118struct fuse_loop_config
119{
120 /* verififier that a correct struct was was passed. This is especially
121 * needed, as versions below (3, 12) were using a public struct
122 * (now called fuse_loop_config_v1), which was hard to extend with
123 * additional parameters, without risking that file system implementations
124 * would not have noticed and might either pass uninitialized members
125 * or even too small structs.
126 * fuse_loop_config_v1 has clone_fd at this offset, which should be either 0
127 * or 1. v2 or even higher version just need to set a value here
128 * which not conflicting and very unlikely as having been set by
129 * file system implementation.
130 */
131 int version_id;
132
137 int clone_fd;
149 int max_idle_threads;
150
156 unsigned int max_threads;
157};
158#endif
159
160/* ----------------------------------------------------------- *
161 * Channel interface (when using -o clone_fd) *
162 * ----------------------------------------------------------- */
163
170struct fuse_chan *fuse_chan_get(struct fuse_chan *ch);
171
177void fuse_chan_put(struct fuse_chan *ch);
178
179struct mount_opts *parse_mount_opts(struct fuse_args *args);
180void destroy_mount_opts(struct mount_opts *mo);
181void fuse_mount_version(void);
182unsigned get_max_read(struct mount_opts *o);
183void fuse_kern_unmount(const char *mountpoint, int fd);
184int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo);
185
186int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
187 int count);
188void fuse_free_req(fuse_req_t req);
189
190void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeide, const void *inarg);
191
192int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);
193
194void fuse_buf_free(struct fuse_buf *buf);
195
196int fuse_session_receive_buf_internal(struct fuse_session *se,
197 struct fuse_buf *buf,
198 struct fuse_chan *ch);
199void fuse_session_process_buf_internal(struct fuse_session *se,
200 const struct fuse_buf *buf,
201 struct fuse_chan *ch);
202
203struct fuse *fuse_new_31(struct fuse_args *args, const struct fuse_operations *op,
204 size_t op_size, void *private_data);
205int fuse_loop_mt_312(struct fuse *f, struct fuse_loop_config *config);
206int fuse_session_loop_mt_312(struct fuse_session *se, struct fuse_loop_config *config);
207
213int fuse_loop_cfg_verify(struct fuse_loop_config *config);
214
215
216/*
217 * This can be changed dynamically on recent kernels through the
218 * /proc/sys/fs/fuse/max_pages_limit interface.
219 *
220 * Older kernels will always use the default value.
221 */
222#define FUSE_DEFAULT_MAX_PAGES_LIMIT 256
223#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
224
225/* room needed in buffer to accommodate header */
226#define FUSE_BUFFER_HEADER_SIZE 0x1000
227
231static inline int convert_to_conn_want_ext(struct fuse_conn_info *conn,
232 uint64_t want_ext_default,
233 uint32_t want_default)
234{
235 /*
236 * Convert want to want_ext if necessary.
237 * For the high level interface this function might be called
238 * twice, once from the high level interface and once from the
239 * low level interface. Both, with different want_ext_default and
240 * want_default values. In order to suppress a failure for the
241 * second call, we check if the lower 32 bits of want_ext are
242 * already set to the value of want.
243 */
244 if (conn->want != want_default &&
245 fuse_lower_32_bits(conn->want_ext) != conn->want) {
246 if (conn->want_ext != want_ext_default) {
247 fuse_log(FUSE_LOG_ERR,
248 "fuse: both 'want' and 'want_ext' are set\n");
249 return -EINVAL;
250 }
251
252 /* high bits from want_ext, low bits from want */
253 conn->want_ext = fuse_higher_32_bits(conn->want_ext) |
254 conn->want;
255 }
256
257 return 0;
258}
fuse_module_factory_t
struct fuse_fs *(* fuse_module_factory_t)(struct fuse_args *args, struct fuse_fs *fs[])
Definition fuse.h:1386
fuse_log
void fuse_log(enum fuse_log_level level, const char *fmt,...)
Definition fuse_log.c:77
fuse_interrupt_func_t
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
Definition fuse_lowlevel.h:1948
fuse_req_t
struct fuse_req * fuse_req_t
Definition fuse_lowlevel.h:50
fuse_ino_t
uint64_t fuse_ino_t
Definition fuse_lowlevel.h:47
fuse_args
Definition fuse_opt.h:109
fuse_buf
Definition fuse_common.h:886
fuse_conn_info
Definition fuse_common.h:548
fuse_conn_info::want
uint32_t want
Definition fuse_common.h:600
fuse_conn_info::want_ext
uint64_t want_ext
Definition fuse_common.h:706
fuse_ctx
Definition fuse_lowlevel.h:112
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_threads
unsigned int max_threads
Definition fuse_i.h:156
fuse_loop_config::max_idle_threads
int max_idle_threads
Definition fuse_i.h:149
fuse_lowlevel_ops
Definition fuse_lowlevel.h:206
fuse_module
Definition fuse_i.h:101
fuse_operations
Definition fuse.h:349
libfuse_version
Definition fuse_common.h:962