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 LGPL2.txt
7*/
8
9#ifndef LIB_FUSE_I_H_
10#define LIB_FUSE_I_H_
11
12#include "fuse.h"
13#include "fuse_lowlevel.h"
14#include "util.h"
15
16#include <pthread.h>
17#include <semaphore.h>
18#include <stdint.h>
19#include <stdbool.h>
20#include <errno.h>
21#include <stdatomic.h>
22
23#define MIN(a, b) \
24({ \
25 typeof(a) _a = (a); \
26 typeof(b) _b = (b); \
27 _a < _b ? _a : _b; \
28})
29
30struct mount_opts;
31struct fuse_ring_pool;
32
33struct fuse_req {
34 struct fuse_session *se;
35 uint64_t unique;
36 _Atomic int ref_cnt;
37 pthread_mutex_t lock;
38 struct fuse_ctx ctx;
39 struct fuse_chan *ch;
40 int interrupted;
41 struct {
42 unsigned int ioctl_64bit : 1;
43 unsigned int is_uring : 1;
44 unsigned int is_copy_file_range_64 : 1;
45 } flags;
46 union {
47 struct {
48 uint64_t unique;
49 } i;
50 struct {
52 void *data;
53 } ni;
54 } u;
55 struct fuse_req *next;
56 struct fuse_req *prev;
57};
58
59struct fuse_notify_req {
60 uint64_t unique;
61 void (*reply)(struct fuse_notify_req *, fuse_req_t, fuse_ino_t,
62 const void *, const struct fuse_buf *);
63 struct fuse_notify_req *next;
64 struct fuse_notify_req *prev;
65};
66
67struct fuse_session_uring {
68 bool enable;
69 unsigned int q_depth;
70 struct fuse_ring_pool *pool;
71};
72
73struct fuse_session {
74 _Atomic(char *)mountpoint;
75 int fd;
76 struct fuse_custom_io *io;
77 struct mount_opts *mo;
78 int debug;
79 int deny_others;
80 struct fuse_lowlevel_ops op;
81 int got_init;
82 struct cuse_data *cuse_data;
83 void *userdata;
84 uid_t owner;
85 struct fuse_conn_info conn;
86 struct fuse_req list;
87 struct fuse_req interrupts;
88 pthread_mutex_t lock;
89 int got_destroy;
90 pthread_key_t pipe_key;
91 int broken_splice_nonblock;
92 uint64_t notify_ctr;
93 struct fuse_notify_req notify_list;
94 _Atomic size_t bufsize;
95 int error;
96
97 /*
98 * This is useful if any kind of ABI incompatibility is found at
99 * a later version, to 'fix' it at run time.
100 */
101 struct libfuse_version version;
102
103 /* thread synchronization */
104 _Atomic bool mt_exited;
105 pthread_mutex_t mt_lock;
106 sem_t mt_finish;
107
108 /* true if reading requests from /dev/fuse are handled internally */
109 bool buf_reallocable;
110
111 /* io_uring */
112 struct fuse_session_uring uring;
113
114 /*
115 * conn->want and conn_want_ext options set by libfuse , needed
116 * to correctly convert want to want_ext
117 */
118 uint32_t conn_want;
119 uint64_t conn_want_ext;
120};
121
122struct fuse_chan {
123 pthread_mutex_t lock;
124 int ctr;
125 int fd;
126};
127
135struct fuse_module {
136 char *name;
137 fuse_module_factory_t factory;
138 struct fuse_module *next;
139 struct fusemod_so *so;
140 int ctr;
141};
142
151#if FUSE_USE_VERSION >= FUSE_MAKE_VERSION(3, 12)
152struct fuse_loop_config
153{
154 /* verififier that a correct struct was was passed. This is especially
155 * needed, as versions below (3, 12) were using a public struct
156 * (now called fuse_loop_config_v1), which was hard to extend with
157 * additional parameters, without risking that file system implementations
158 * would not have noticed and might either pass uninitialized members
159 * or even too small structs.
160 * fuse_loop_config_v1 has clone_fd at this offset, which should be either 0
161 * or 1. v2 or even higher version just need to set a value here
162 * which not conflicting and very unlikely as having been set by
163 * file system implementation.
164 */
165 int version_id;
166
171 int clone_fd;
184
190 unsigned int max_threads;
191};
192#endif
193
194/* ----------------------------------------------------------- *
195 * Channel interface (when using -o clone_fd) *
196 * ----------------------------------------------------------- */
197
204struct fuse_chan *fuse_chan_get(struct fuse_chan *ch);
205
211void fuse_chan_put(struct fuse_chan *ch);
212
213struct mount_opts *parse_mount_opts(struct fuse_args *args);
214void destroy_mount_opts(struct mount_opts *mo);
215void fuse_mount_version(void);
216unsigned get_max_read(struct mount_opts *o);
217void fuse_kern_unmount(const char *mountpoint, int fd);
218int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo);
219
220int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
221 int count);
222void fuse_free_req(fuse_req_t req);
223void list_init_req(struct fuse_req *req);
224
225void _cuse_lowlevel_init(fuse_req_t req, const fuse_ino_t nodeid,
226 const void *req_header, const void *req_payload);
227void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeide, const void *inarg);
228
229int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);
230
231void fuse_buf_free(struct fuse_buf *buf);
232
233int fuse_session_receive_buf_internal(struct fuse_session *se,
234 struct fuse_buf *buf,
235 struct fuse_chan *ch);
236void fuse_session_process_buf_internal(struct fuse_session *se,
237 const struct fuse_buf *buf,
238 struct fuse_chan *ch);
239
240struct fuse *fuse_new_31(struct fuse_args *args, const struct fuse_operations *op,
241 size_t op_size, void *private_data);
242int fuse_loop_mt_312(struct fuse *f, struct fuse_loop_config *config);
243int fuse_session_loop_mt_312(struct fuse_session *se, struct fuse_loop_config *config);
244
250int fuse_loop_cfg_verify(struct fuse_loop_config *config);
251
252
253/*
254 * This can be changed dynamically on recent kernels through the
255 * /proc/sys/fs/fuse/max_pages_limit interface.
256 *
257 * Older kernels will always use the default value.
258 */
259#define FUSE_DEFAULT_MAX_PAGES_LIMIT 256
260#define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
261
262/* room needed in buffer to accommodate header */
263#define FUSE_BUFFER_HEADER_SIZE 0x1000
264
265
266#endif /* LIB_FUSE_I_H_*/
struct fuse_fs *(* fuse_module_factory_t)(struct fuse_args *args, struct fuse_fs *fs[])
Definition fuse.h:1383
void(* fuse_interrupt_func_t)(fuse_req_t req, void *data)
struct fuse_req * fuse_req_t
uint64_t fuse_ino_t
unsigned int max_threads
Definition fuse_i.h:166
unsigned int max_idle_threads