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 {
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 _Atomic 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
86 /* true if reading requests from /dev/fuse are handled internally */
87 bool buf_reallocable;
88};
89
90struct fuse_chan {
91 pthread_mutex_t lock;
92 int ctr;
93 int fd;
94};
95
104 char *name;
105 fuse_module_factory_t factory;
106 struct fuse_module *next;
107 struct fusemod_so *so;
108 int ctr;
109};
110
119#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
120struct fuse_loop_config
121{
122 /* verififier that a correct struct was was passed. This is especially
123 * needed, as versions below (3, 12) were using a public struct
124 * (now called fuse_loop_config_v1), which was hard to extend with
125 * additional parameters, without risking that file system implementations
126 * would not have noticed and might either pass uninitialized members
127 * or even too small structs.
128 * fuse_loop_config_v1 has clone_fd at this offset, which should be either 0
129 * or 1. v2 or even higher version just need to set a value here
130 * which not conflicting and very unlikely as having been set by
131 * file system implementation.
132 */
133 int version_id;
134
139 int clone_fd;
152
158 unsigned int max_threads;
159};
160#endif
161
162/* ----------------------------------------------------------- *
163 * Channel interface (when using -o clone_fd) *
164 * ----------------------------------------------------------- */
165
172struct fuse_chan *fuse_chan_get(struct fuse_chan *ch);
173
179void fuse_chan_put(struct fuse_chan *ch);
180
181struct mount_opts *parse_mount_opts(struct fuse_args *args);
182void destroy_mount_opts(struct mount_opts *mo);
183void fuse_mount_version(void);
184unsigned get_max_read(struct mount_opts *o);
185void fuse_kern_unmount(const char *mountpoint, int fd);
186int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo);
187
188int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
189 int count);
190void fuse_free_req(fuse_req_t req);
191
192void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeide, const void *inarg);
193
194int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);
195
196void fuse_buf_free(struct fuse_buf *buf);
197
198int fuse_session_receive_buf_internal(struct fuse_session *se,
199 struct fuse_buf *buf,
200 struct fuse_chan *ch);
201void fuse_session_process_buf_internal(struct fuse_session *se,
202 const struct fuse_buf *buf,
203 struct fuse_chan *ch);
204
205struct fuse *fuse_new_31(struct fuse_args *args, const struct fuse_operations *op,
206 size_t op_size, void *private_data);
207int fuse_loop_mt_312(struct fuse *f, struct fuse_loop_config *config);
208int fuse_session_loop_mt_312(struct fuse_session *se, struct fuse_loop_config *config);
209
215int fuse_loop_cfg_verify(struct fuse_loop_config *config);
216
217
218/*
219 * This can be changed dynamically on recent kernels through the
220 * /proc/sys/fs/fuse/max_pages_limit interface.
221 *
222 * Older kernels will always use the default value.
223 */
224#define FUSE_DEFAULT_MAX_PAGES_LIMIT 256
225#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
226
227/* room needed in buffer to accommodate header */
228#define FUSE_BUFFER_HEADER_SIZE 0x1000
229
233static inline int convert_to_conn_want_ext(struct fuse_conn_info *conn,
234 uint64_t want_ext_default,
235 uint32_t want_default)
236{
237 /*
238 * Convert want to want_ext if necessary.
239 * For the high level interface this function might be called
240 * twice, once from the high level interface and once from the
241 * low level interface. Both, with different want_ext_default and
242 * want_default values. In order to suppress a failure for the
243 * second call, we check if the lower 32 bits of want_ext are
244 * already set to the value of want.
245 */
246 if (conn->want != want_default &&
247 fuse_lower_32_bits(conn->want_ext) != conn->want) {
248 if (conn->want_ext != want_ext_default) {
249 fuse_log(FUSE_LOG_ERR,
250 "fuse: both 'want' and 'want_ext' are set\n");
251 return -EINVAL;
252 }
253
254 /* high bits from want_ext, low bits from want */
255 conn->want_ext = fuse_higher_32_bits(conn->want_ext) |
256 conn->want;
257 }
258
259 /* ensure there won't be a second conversion */
260 conn->want = fuse_lower_32_bits(conn->want_ext);
261
262 return 0;
263}
struct fuse_fs *(* fuse_module_factory_t)(struct fuse_args *args, struct fuse_fs *fs[])
Definition fuse.h:1383
void fuse_log(enum fuse_log_level level, const char *fmt,...)
Definition fuse_log.c:77
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
struct fuse_req * fuse_req_t
uint64_t fuse_ino_t
uint64_t want_ext
unsigned int max_threads
Definition fuse_i.h:158
int max_idle_threads
Definition fuse_i.h:151