• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FUSE_LOWLEVEL_H_
10 #define FUSE_LOWLEVEL_H_
11 
12 /** @file
13  *
14  * Low level API
15  *
16  * IMPORTANT: you should define FUSE_USE_VERSION before including this
17  * header.  To use the newest API define it to 35 (recommended for any
18  * new application).
19  */
20 
21 #ifndef FUSE_USE_VERSION
22 #error FUSE_USE_VERSION not defined
23 #endif
24 
25 #include "fuse_common.h"
26 
27 #include <utime.h>
28 #include <fcntl.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/statvfs.h>
32 #include <sys/uio.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* ----------------------------------------------------------- *
39  * Miscellaneous definitions				       *
40  * ----------------------------------------------------------- */
41 
42 /** The node ID of the root inode */
43 #define FUSE_ROOT_ID 1
44 
45 /** Inode number type */
46 typedef uint64_t fuse_ino_t;
47 
48 /** Request pointer type */
49 typedef struct fuse_req *fuse_req_t;
50 
51 /**
52  * Session
53  *
54  * This provides hooks for processing requests, and exiting
55  */
56 struct fuse_session;
57 
58 /** Directory entry parameters supplied to fuse_reply_entry() */
59 struct fuse_entry_param {
60 	/** Unique inode number
61 	 *
62 	 * In lookup, zero means negative entry (from version 2.5)
63 	 * Returning ENOENT also means negative entry, but by setting zero
64 	 * ino the kernel may cache negative entries for entry_timeout
65 	 * seconds.
66 	 */
67 	fuse_ino_t ino;
68 
69 	/** Generation number for this entry.
70 	 *
71 	 * If the file system will be exported over NFS, the
72 	 * ino/generation pairs need to be unique over the file
73 	 * system's lifetime (rather than just the mount time). So if
74 	 * the file system reuses an inode after it has been deleted,
75 	 * it must assign a new, previously unused generation number
76 	 * to the inode at the same time.
77 	 *
78 	 */
79 	uint64_t generation;
80 
81 	/** Inode attributes.
82 	 *
83 	 * Even if attr_timeout == 0, attr must be correct. For example,
84 	 * for open(), FUSE uses attr.st_size from lookup() to determine
85 	 * how many bytes to request. If this value is not correct,
86 	 * incorrect data will be returned.
87 	 */
88 	struct stat attr;
89 
90 	/** Validity timeout (in seconds) for inode attributes. If
91 	    attributes only change as a result of requests that come
92 	    through the kernel, this should be set to a very large
93 	    value. */
94 	double attr_timeout;
95 
96 	/** Validity timeout (in seconds) for the name. If directory
97 	    entries are changed/deleted only as a result of requests
98 	    that come through the kernel, this should be set to a very
99 	    large value. */
100 	double entry_timeout;
101 };
102 
103 /**
104  * Additional context associated with requests.
105  *
106  * Note that the reported client uid, gid and pid may be zero in some
107  * situations. For example, if the FUSE file system is running in a
108  * PID or user namespace but then accessed from outside the namespace,
109  * there is no valid uid/pid/gid that could be reported.
110  */
111 struct fuse_ctx {
112 	/** User ID of the calling process */
113 	uid_t uid;
114 
115 	/** Group ID of the calling process */
116 	gid_t gid;
117 
118 	/** Thread ID of the calling process */
119 	pid_t pid;
120 
121 	/** Umask of the calling process */
122 	mode_t umask;
123 };
124 
125 struct fuse_forget_data {
126 	fuse_ino_t ino;
127 	uint64_t nlookup;
128 };
129 
130 struct fuse_custom_io {
131 	ssize_t (*writev)(int fd, struct iovec *iov, int count, void *userdata);
132 	ssize_t (*read)(int fd, void *buf, size_t buf_len, void *userdata);
133 	ssize_t (*splice_receive)(int fdin, off_t *offin, int fdout,
134 					  off_t *offout, size_t len,
135 				  	  unsigned int flags, void *userdata);
136 	ssize_t (*splice_send)(int fdin, off_t *offin, int fdout,
137 				     off_t *offout, size_t len,
138 			           unsigned int flags, void *userdata);
139 };
140 
141 /**
142  * Flags for fuse_lowlevel_notify_entry()
143  * 0 = invalidate entry
144  * FUSE_LL_EXPIRE_ONLY = expire entry
145 */
146 enum fuse_notify_entry_flags {
147 	FUSE_LL_INVALIDATE = 0,
148 	FUSE_LL_EXPIRE_ONLY	= (1 << 0),
149 };
150 
151 /* 'to_set' flags in setattr */
152 #define FUSE_SET_ATTR_MODE	(1 << 0)
153 #define FUSE_SET_ATTR_UID	(1 << 1)
154 #define FUSE_SET_ATTR_GID	(1 << 2)
155 #define FUSE_SET_ATTR_SIZE	(1 << 3)
156 #define FUSE_SET_ATTR_ATIME	(1 << 4)
157 #define FUSE_SET_ATTR_MTIME	(1 << 5)
158 #define FUSE_SET_ATTR_ATIME_NOW	(1 << 7)
159 #define FUSE_SET_ATTR_MTIME_NOW	(1 << 8)
160 #define FUSE_SET_ATTR_FORCE	(1 << 9)
161 #define FUSE_SET_ATTR_CTIME	(1 << 10)
162 #define FUSE_SET_ATTR_KILL_SUID	(1 << 11)
163 #define FUSE_SET_ATTR_KILL_SGID	(1 << 12)
164 #define FUSE_SET_ATTR_FILE	(1 << 13)
165 #define FUSE_SET_ATTR_KILL_PRIV	(1 << 14)
166 #define FUSE_SET_ATTR_OPEN	(1 << 15)
167 #define FUSE_SET_ATTR_TIMES_SET	(1 << 16)
168 #define FUSE_SET_ATTR_TOUCH	(1 << 17)
169 
170 /* ----------------------------------------------------------- *
171  * Request methods and replies				       *
172  * ----------------------------------------------------------- */
173 
174 /**
175  * Low level filesystem operations
176  *
177  * Most of the methods (with the exception of init and destroy)
178  * receive a request handle (fuse_req_t) as their first argument.
179  * This handle must be passed to one of the specified reply functions.
180  *
181  * This may be done inside the method invocation, or after the call
182  * has returned.  The request handle is valid until one of the reply
183  * functions is called.
184  *
185  * Other pointer arguments (name, fuse_file_info, etc) are not valid
186  * after the call has returned, so if they are needed later, their
187  * contents have to be copied.
188  *
189  * In general, all methods are expected to perform any necessary
190  * permission checking. However, a filesystem may delegate this task
191  * to the kernel by passing the `default_permissions` mount option to
192  * `fuse_session_new()`. In this case, methods will only be called if
193  * the kernel's permission check has succeeded.
194  *
195  * The filesystem sometimes needs to handle a return value of -ENOENT
196  * from the reply function, which means, that the request was
197  * interrupted, and the reply discarded.  For example if
198  * fuse_reply_open() return -ENOENT means, that the release method for
199  * this file will not be called.
200  */
201 struct fuse_lowlevel_ops {
202 	/**
203 	 * Initialize filesystem
204 	 *
205 	 * This function is called when libfuse establishes
206 	 * communication with the FUSE kernel module. The file system
207 	 * should use this module to inspect and/or modify the
208 	 * connection parameters provided in the `conn` structure.
209 	 *
210 	 * Note that some parameters may be overwritten by options
211 	 * passed to fuse_session_new() which take precedence over the
212 	 * values set in this handler.
213 	 *
214 	 * There's no reply to this function
215 	 *
216 	 * @param userdata the user data passed to fuse_session_new()
217 	 */
218 	void (*init) (void *userdata, struct fuse_conn_info *conn);
219 
220 	/**
221 	 * Clean up filesystem.
222 	 *
223 	 * Called on filesystem exit. When this method is called, the
224 	 * connection to the kernel may be gone already, so that eg. calls
225 	 * to fuse_lowlevel_notify_* will fail.
226 	 *
227 	 * There's no reply to this function
228 	 *
229 	 * @param userdata the user data passed to fuse_session_new()
230 	 */
231 	void (*destroy) (void *userdata);
232 
233 	/**
234 	 * Look up a directory entry by name and get its attributes.
235 	 *
236 	 * Valid replies:
237 	 *   fuse_reply_entry
238 	 *   fuse_reply_err
239 	 *
240 	 * @param req request handle
241 	 * @param parent inode number of the parent directory
242 	 * @param name the name to look up
243 	 */
244 	void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
245 
246 	/**
247 	 * Forget about an inode
248 	 *
249 	 * This function is called when the kernel removes an inode
250 	 * from its internal caches.
251 	 *
252 	 * The inode's lookup count increases by one for every call to
253 	 * fuse_reply_entry and fuse_reply_create. The nlookup parameter
254 	 * indicates by how much the lookup count should be decreased.
255 	 *
256 	 * Inodes with a non-zero lookup count may receive request from
257 	 * the kernel even after calls to unlink, rmdir or (when
258 	 * overwriting an existing file) rename. Filesystems must handle
259 	 * such requests properly and it is recommended to defer removal
260 	 * of the inode until the lookup count reaches zero. Calls to
261 	 * unlink, rmdir or rename will be followed closely by forget
262 	 * unless the file or directory is open, in which case the
263 	 * kernel issues forget only after the release or releasedir
264 	 * calls.
265 	 *
266 	 * Note that if a file system will be exported over NFS the
267 	 * inodes lifetime must extend even beyond forget. See the
268 	 * generation field in struct fuse_entry_param above.
269 	 *
270 	 * On unmount the lookup count for all inodes implicitly drops
271 	 * to zero. It is not guaranteed that the file system will
272 	 * receive corresponding forget messages for the affected
273 	 * inodes.
274 	 *
275 	 * Valid replies:
276 	 *   fuse_reply_none
277 	 *
278 	 * @param req request handle
279 	 * @param ino the inode number
280 	 * @param nlookup the number of lookups to forget
281 	 */
282 	void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
283 
284 	/**
285 	 * Get file attributes.
286 	 *
287 	 * If writeback caching is enabled, the kernel may have a
288 	 * better idea of a file's length than the FUSE file system
289 	 * (eg if there has been a write that extended the file size,
290 	 * but that has not yet been passed to the filesystem.n
291 	 *
292 	 * In this case, the st_size value provided by the file system
293 	 * will be ignored.
294 	 *
295 	 * Valid replies:
296 	 *   fuse_reply_attr
297 	 *   fuse_reply_err
298 	 *
299 	 * @param req request handle
300 	 * @param ino the inode number
301 	 * @param fi for future use, currently always NULL
302 	 */
303 	void (*getattr) (fuse_req_t req, fuse_ino_t ino,
304 			 struct fuse_file_info *fi);
305 
306 	/**
307 	 * Set file attributes
308 	 *
309 	 * In the 'attr' argument only members indicated by the 'to_set'
310 	 * bitmask contain valid values.  Other members contain undefined
311 	 * values.
312 	 *
313 	 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
314 	 * expected to reset the setuid and setgid bits if the file
315 	 * size or owner is being changed.
316 	 *
317 	 * This method will not be called to update st_atime or st_ctime implicitly
318 	 * (eg. after a read() request), and only be called to implicitly update st_mtime
319 	 * if writeback caching is active. It is the filesystem's responsibility to update
320 	 * these timestamps when needed, and (if desired) to implement mount options like
321 	 * `noatime` or `relatime`.
322 	 *
323 	 * If the setattr was invoked from the ftruncate() system call
324 	 * under Linux kernel versions 2.6.15 or later, the fi->fh will
325 	 * contain the value set by the open method or will be undefined
326 	 * if the open method didn't set any value.  Otherwise (not
327 	 * ftruncate call, or kernel version earlier than 2.6.15) the fi
328 	 * parameter will be NULL.
329 	 *
330 	 * Valid replies:
331 	 *   fuse_reply_attr
332 	 *   fuse_reply_err
333 	 *
334 	 * @param req request handle
335 	 * @param ino the inode number
336 	 * @param attr the attributes
337 	 * @param to_set bit mask of attributes which should be set
338 	 * @param fi file information, or NULL
339 	 */
340 	void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
341 			 int to_set, struct fuse_file_info *fi);
342 
343 	/**
344 	 * Read symbolic link
345 	 *
346 	 * Valid replies:
347 	 *   fuse_reply_readlink
348 	 *   fuse_reply_err
349 	 *
350 	 * @param req request handle
351 	 * @param ino the inode number
352 	 */
353 	void (*readlink) (fuse_req_t req, fuse_ino_t ino);
354 
355 	/**
356 	 * Create file node
357 	 *
358 	 * Create a regular file, character device, block device, fifo or
359 	 * socket node.
360 	 *
361 	 * Valid replies:
362 	 *   fuse_reply_entry
363 	 *   fuse_reply_err
364 	 *
365 	 * @param req request handle
366 	 * @param parent inode number of the parent directory
367 	 * @param name to create
368 	 * @param mode file type and mode with which to create the new file
369 	 * @param rdev the device number (only valid if created file is a device)
370 	 */
371 	void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
372 		       mode_t mode, dev_t rdev);
373 
374 	/**
375 	 * Create a directory
376 	 *
377 	 * Valid replies:
378 	 *   fuse_reply_entry
379 	 *   fuse_reply_err
380 	 *
381 	 * @param req request handle
382 	 * @param parent inode number of the parent directory
383 	 * @param name to create
384 	 * @param mode with which to create the new file
385 	 */
386 	void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
387 		       mode_t mode);
388 
389 	/**
390 	 * Remove a file
391 	 *
392 	 * If the file's inode's lookup count is non-zero, the file
393 	 * system is expected to postpone any removal of the inode
394 	 * until the lookup count reaches zero (see description of the
395 	 * forget function).
396 	 *
397 	 * Valid replies:
398 	 *   fuse_reply_err
399 	 *
400 	 * @param req request handle
401 	 * @param parent inode number of the parent directory
402 	 * @param name to remove
403 	 */
404 	void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
405 
406 	/**
407 	 * Remove a directory
408 	 *
409 	 * If the directory's inode's lookup count is non-zero, the
410 	 * file system is expected to postpone any removal of the
411 	 * inode until the lookup count reaches zero (see description
412 	 * of the forget function).
413 	 *
414 	 * Valid replies:
415 	 *   fuse_reply_err
416 	 *
417 	 * @param req request handle
418 	 * @param parent inode number of the parent directory
419 	 * @param name to remove
420 	 */
421 	void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
422 
423 	/**
424 	 * Create a symbolic link
425 	 *
426 	 * Valid replies:
427 	 *   fuse_reply_entry
428 	 *   fuse_reply_err
429 	 *
430 	 * @param req request handle
431 	 * @param link the contents of the symbolic link
432 	 * @param parent inode number of the parent directory
433 	 * @param name to create
434 	 */
435 	void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
436 			 const char *name);
437 
438 	/** Rename a file
439 	 *
440 	 * If the target exists it should be atomically replaced. If
441 	 * the target's inode's lookup count is non-zero, the file
442 	 * system is expected to postpone any removal of the inode
443 	 * until the lookup count reaches zero (see description of the
444 	 * forget function).
445 	 *
446 	 * If this request is answered with an error code of ENOSYS, this is
447 	 * treated as a permanent failure with error code EINVAL, i.e. all
448 	 * future bmap requests will fail with EINVAL without being
449 	 * send to the filesystem process.
450 	 *
451 	 * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
452 	 * RENAME_NOREPLACE is specified, the filesystem must not
453 	 * overwrite *newname* if it exists and return an error
454 	 * instead. If `RENAME_EXCHANGE` is specified, the filesystem
455 	 * must atomically exchange the two files, i.e. both must
456 	 * exist and neither may be deleted.
457 	 *
458 	 * Valid replies:
459 	 *   fuse_reply_err
460 	 *
461 	 * @param req request handle
462 	 * @param parent inode number of the old parent directory
463 	 * @param name old name
464 	 * @param newparent inode number of the new parent directory
465 	 * @param newname new name
466 	 */
467 	void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
468 			fuse_ino_t newparent, const char *newname,
469 			unsigned int flags);
470 
471 	/**
472 	 * Create a hard link
473 	 *
474 	 * Valid replies:
475 	 *   fuse_reply_entry
476 	 *   fuse_reply_err
477 	 *
478 	 * @param req request handle
479 	 * @param ino the old inode number
480 	 * @param newparent inode number of the new parent directory
481 	 * @param newname new name to create
482 	 */
483 	void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
484 		      const char *newname);
485 
486 	/**
487 	 * Open a file
488 	 *
489 	 * Open flags are available in fi->flags. The following rules
490 	 * apply.
491 	 *
492 	 *  - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
493 	 *    filtered out / handled by the kernel.
494 	 *
495 	 *  - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
496 	 *    by the filesystem to check if the operation is
497 	 *    permitted.  If the ``-o default_permissions`` mount
498 	 *    option is given, this check is already done by the
499 	 *    kernel before calling open() and may thus be omitted by
500 	 *    the filesystem.
501 	 *
502 	 *  - When writeback caching is enabled, the kernel may send
503 	 *    read requests even for files opened with O_WRONLY. The
504 	 *    filesystem should be prepared to handle this.
505 	 *
506 	 *  - When writeback caching is disabled, the filesystem is
507 	 *    expected to properly handle the O_APPEND flag and ensure
508 	 *    that each write is appending to the end of the file.
509 	 *
510          *  - When writeback caching is enabled, the kernel will
511 	 *    handle O_APPEND. However, unless all changes to the file
512 	 *    come through the kernel this will not work reliably. The
513 	 *    filesystem should thus either ignore the O_APPEND flag
514 	 *    (and let the kernel handle it), or return an error
515 	 *    (indicating that reliably O_APPEND is not available).
516 	 *
517 	 * Filesystem may store an arbitrary file handle (pointer,
518 	 * index, etc) in fi->fh, and use this in other all other file
519 	 * operations (read, write, flush, release, fsync).
520 	 *
521 	 * Filesystem may also implement stateless file I/O and not store
522 	 * anything in fi->fh.
523 	 *
524 	 * There are also some flags (direct_io, keep_cache) which the
525 	 * filesystem may set in fi, to change the way the file is opened.
526 	 * See fuse_file_info structure in <fuse_common.h> for more details.
527 	 *
528 	 * If this request is answered with an error code of ENOSYS
529 	 * and FUSE_CAP_NO_OPEN_SUPPORT is set in
530 	 * `fuse_conn_info.capable`, this is treated as success and
531 	 * future calls to open and release will also succeed without being
532 	 * sent to the filesystem process.
533 	 *
534 	 * Valid replies:
535 	 *   fuse_reply_open
536 	 *   fuse_reply_err
537 	 *
538 	 * @param req request handle
539 	 * @param ino the inode number
540 	 * @param fi file information
541 	 */
542 	void (*open) (fuse_req_t req, fuse_ino_t ino,
543 		      struct fuse_file_info *fi);
544 
545 	/**
546 	 * Read data
547 	 *
548 	 * Read should send exactly the number of bytes requested except
549 	 * on EOF or error, otherwise the rest of the data will be
550 	 * substituted with zeroes.  An exception to this is when the file
551 	 * has been opened in 'direct_io' mode, in which case the return
552 	 * value of the read system call will reflect the return value of
553 	 * this operation.
554 	 *
555 	 * fi->fh will contain the value set by the open method, or will
556 	 * be undefined if the open method didn't set any value.
557 	 *
558 	 * Valid replies:
559 	 *   fuse_reply_buf
560 	 *   fuse_reply_iov
561 	 *   fuse_reply_data
562 	 *   fuse_reply_err
563 	 *
564 	 * @param req request handle
565 	 * @param ino the inode number
566 	 * @param size number of bytes to read
567 	 * @param off offset to read from
568 	 * @param fi file information
569 	 */
570 	void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
571 		      struct fuse_file_info *fi);
572 
573 	/**
574 	 * Write data
575 	 *
576 	 * Write should return exactly the number of bytes requested
577 	 * except on error.  An exception to this is when the file has
578 	 * been opened in 'direct_io' mode, in which case the return value
579 	 * of the write system call will reflect the return value of this
580 	 * operation.
581 	 *
582 	 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
583 	 * expected to reset the setuid and setgid bits.
584 	 *
585 	 * fi->fh will contain the value set by the open method, or will
586 	 * be undefined if the open method didn't set any value.
587 	 *
588 	 * Valid replies:
589 	 *   fuse_reply_write
590 	 *   fuse_reply_err
591 	 *
592 	 * @param req request handle
593 	 * @param ino the inode number
594 	 * @param buf data to write
595 	 * @param size number of bytes to write
596 	 * @param off offset to write to
597 	 * @param fi file information
598 	 */
599 	void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
600 		       size_t size, off_t off, struct fuse_file_info *fi);
601 
602 	/**
603 	 * Flush method
604 	 *
605 	 * This is called on each close() of the opened file.
606 	 *
607 	 * Since file descriptors can be duplicated (dup, dup2, fork), for
608 	 * one open call there may be many flush calls.
609 	 *
610 	 * Filesystems shouldn't assume that flush will always be called
611 	 * after some writes, or that if will be called at all.
612 	 *
613 	 * fi->fh will contain the value set by the open method, or will
614 	 * be undefined if the open method didn't set any value.
615 	 *
616 	 * NOTE: the name of the method is misleading, since (unlike
617 	 * fsync) the filesystem is not forced to flush pending writes.
618 	 * One reason to flush data is if the filesystem wants to return
619 	 * write errors during close.  However, such use is non-portable
620 	 * because POSIX does not require [close] to wait for delayed I/O to
621 	 * complete.
622 	 *
623 	 * If the filesystem supports file locking operations (setlk,
624 	 * getlk) it should remove all locks belonging to 'fi->owner'.
625 	 *
626 	 * If this request is answered with an error code of ENOSYS,
627 	 * this is treated as success and future calls to flush() will
628 	 * succeed automatically without being send to the filesystem
629 	 * process.
630 	 *
631 	 * Valid replies:
632 	 *   fuse_reply_err
633 	 *
634 	 * @param req request handle
635 	 * @param ino the inode number
636 	 * @param fi file information
637 	 *
638 	 * [close]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
639 	 */
640 	void (*flush) (fuse_req_t req, fuse_ino_t ino,
641 		       struct fuse_file_info *fi);
642 
643 	/**
644 	 * Release an open file
645 	 *
646 	 * Release is called when there are no more references to an open
647 	 * file: all file descriptors are closed and all memory mappings
648 	 * are unmapped.
649 	 *
650 	 * For every open call there will be exactly one release call (unless
651 	 * the filesystem is force-unmounted).
652 	 *
653 	 * The filesystem may reply with an error, but error values are
654 	 * not returned to close() or munmap() which triggered the
655 	 * release.
656 	 *
657 	 * fi->fh will contain the value set by the open method, or will
658 	 * be undefined if the open method didn't set any value.
659 	 * fi->flags will contain the same flags as for open.
660 	 *
661 	 * Valid replies:
662 	 *   fuse_reply_err
663 	 *
664 	 * @param req request handle
665 	 * @param ino the inode number
666 	 * @param fi file information
667 	 */
668 	void (*release) (fuse_req_t req, fuse_ino_t ino,
669 			 struct fuse_file_info *fi);
670 
671 	/**
672 	 * Synchronize file contents
673 	 *
674 	 * If the datasync parameter is non-zero, then only the user data
675 	 * should be flushed, not the meta data.
676 	 *
677 	 * If this request is answered with an error code of ENOSYS,
678 	 * this is treated as success and future calls to fsync() will
679 	 * succeed automatically without being send to the filesystem
680 	 * process.
681 	 *
682 	 * Valid replies:
683 	 *   fuse_reply_err
684 	 *
685 	 * @param req request handle
686 	 * @param ino the inode number
687 	 * @param datasync flag indicating if only data should be flushed
688 	 * @param fi file information
689 	 */
690 	void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
691 		       struct fuse_file_info *fi);
692 
693 	/**
694 	 * Open a directory
695 	 *
696 	 * Filesystem may store an arbitrary file handle (pointer, index,
697 	 * etc) in fi->fh, and use this in other all other directory
698 	 * stream operations (readdir, releasedir, fsyncdir).
699 	 *
700 	 * If this request is answered with an error code of ENOSYS and
701 	 * FUSE_CAP_NO_OPENDIR_SUPPORT is set in `fuse_conn_info.capable`,
702 	 * this is treated as success and future calls to opendir and
703 	 * releasedir will also succeed without being sent to the filesystem
704 	 * process. In addition, the kernel will cache readdir results
705 	 * as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR.
706 	 *
707 	 * Valid replies:
708 	 *   fuse_reply_open
709 	 *   fuse_reply_err
710 	 *
711 	 * @param req request handle
712 	 * @param ino the inode number
713 	 * @param fi file information
714 	 */
715 	void (*opendir) (fuse_req_t req, fuse_ino_t ino,
716 			 struct fuse_file_info *fi);
717 
718 	/**
719 	 * Read directory
720 	 *
721 	 * Send a buffer filled using fuse_add_direntry(), with size not
722 	 * exceeding the requested size.  Send an empty buffer on end of
723 	 * stream.
724 	 *
725 	 * fi->fh will contain the value set by the opendir method, or
726 	 * will be undefined if the opendir method didn't set any value.
727 	 *
728 	 * Returning a directory entry from readdir() does not affect
729 	 * its lookup count.
730 	 *
731          * If off_t is non-zero, then it will correspond to one of the off_t
732 	 * values that was previously returned by readdir() for the same
733 	 * directory handle. In this case, readdir() should skip over entries
734 	 * coming before the position defined by the off_t value. If entries
735 	 * are added or removed while the directory handle is open, the filesystem
736 	 * may still include the entries that have been removed, and may not
737 	 * report the entries that have been created. However, addition or
738 	 * removal of entries must never cause readdir() to skip over unrelated
739 	 * entries or to report them more than once. This means
740 	 * that off_t can not be a simple index that enumerates the entries
741 	 * that have been returned but must contain sufficient information to
742 	 * uniquely determine the next directory entry to return even when the
743 	 * set of entries is changing.
744 	 *
745 	 * The function does not have to report the '.' and '..'
746 	 * entries, but is allowed to do so. Note that, if readdir does
747 	 * not return '.' or '..', they will not be implicitly returned,
748 	 * and this behavior is observable by the caller.
749 	 *
750 	 * Valid replies:
751 	 *   fuse_reply_buf
752 	 *   fuse_reply_data
753 	 *   fuse_reply_err
754 	 *
755 	 * @param req request handle
756 	 * @param ino the inode number
757 	 * @param size maximum number of bytes to send
758 	 * @param off offset to continue reading the directory stream
759 	 * @param fi file information
760 	 */
761 	void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
762 			 struct fuse_file_info *fi);
763 
764 	/**
765 	 * Release an open directory
766 	 *
767 	 * For every opendir call there will be exactly one releasedir
768 	 * call (unless the filesystem is force-unmounted).
769 	 *
770 	 * fi->fh will contain the value set by the opendir method, or
771 	 * will be undefined if the opendir method didn't set any value.
772 	 *
773 	 * Valid replies:
774 	 *   fuse_reply_err
775 	 *
776 	 * @param req request handle
777 	 * @param ino the inode number
778 	 * @param fi file information
779 	 */
780 	void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
781 			    struct fuse_file_info *fi);
782 
783 	/**
784 	 * Synchronize directory contents
785 	 *
786 	 * If the datasync parameter is non-zero, then only the directory
787 	 * contents should be flushed, not the meta data.
788 	 *
789 	 * fi->fh will contain the value set by the opendir method, or
790 	 * will be undefined if the opendir method didn't set any value.
791 	 *
792 	 * If this request is answered with an error code of ENOSYS,
793 	 * this is treated as success and future calls to fsyncdir() will
794 	 * succeed automatically without being send to the filesystem
795 	 * process.
796 	 *
797 	 * Valid replies:
798 	 *   fuse_reply_err
799 	 *
800 	 * @param req request handle
801 	 * @param ino the inode number
802 	 * @param datasync flag indicating if only data should be flushed
803 	 * @param fi file information
804 	 */
805 	void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
806 			  struct fuse_file_info *fi);
807 
808 	/**
809 	 * Get file system statistics
810 	 *
811 	 * Valid replies:
812 	 *   fuse_reply_statfs
813 	 *   fuse_reply_err
814 	 *
815 	 * @param req request handle
816 	 * @param ino the inode number, zero means "undefined"
817 	 */
818 	void (*statfs) (fuse_req_t req, fuse_ino_t ino);
819 
820 	/**
821 	 * Set an extended attribute
822 	 *
823 	 * If this request is answered with an error code of ENOSYS, this is
824 	 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
825 	 * future setxattr() requests will fail with EOPNOTSUPP without being
826 	 * send to the filesystem process.
827 	 *
828 	 * Valid replies:
829 	 *   fuse_reply_err
830 	 */
831 	void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
832 			  const char *value, size_t size, int flags);
833 
834 	/**
835 	 * Get an extended attribute
836 	 *
837 	 * If size is zero, the size of the value should be sent with
838 	 * fuse_reply_xattr.
839 	 *
840 	 * If the size is non-zero, and the value fits in the buffer, the
841 	 * value should be sent with fuse_reply_buf.
842 	 *
843 	 * If the size is too small for the value, the ERANGE error should
844 	 * be sent.
845 	 *
846 	 * If this request is answered with an error code of ENOSYS, this is
847 	 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
848 	 * future getxattr() requests will fail with EOPNOTSUPP without being
849 	 * send to the filesystem process.
850 	 *
851 	 * Valid replies:
852 	 *   fuse_reply_buf
853 	 *   fuse_reply_data
854 	 *   fuse_reply_xattr
855 	 *   fuse_reply_err
856 	 *
857 	 * @param req request handle
858 	 * @param ino the inode number
859 	 * @param name of the extended attribute
860 	 * @param size maximum size of the value to send
861 	 */
862 	void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
863 			  size_t size);
864 
865 	/**
866 	 * List extended attribute names
867 	 *
868 	 * If size is zero, the total size of the attribute list should be
869 	 * sent with fuse_reply_xattr.
870 	 *
871 	 * If the size is non-zero, and the null character separated
872 	 * attribute list fits in the buffer, the list should be sent with
873 	 * fuse_reply_buf.
874 	 *
875 	 * If the size is too small for the list, the ERANGE error should
876 	 * be sent.
877 	 *
878 	 * If this request is answered with an error code of ENOSYS, this is
879 	 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
880 	 * future listxattr() requests will fail with EOPNOTSUPP without being
881 	 * send to the filesystem process.
882 	 *
883 	 * Valid replies:
884 	 *   fuse_reply_buf
885 	 *   fuse_reply_data
886 	 *   fuse_reply_xattr
887 	 *   fuse_reply_err
888 	 *
889 	 * @param req request handle
890 	 * @param ino the inode number
891 	 * @param size maximum size of the list to send
892 	 */
893 	void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
894 
895 	/**
896 	 * Remove an extended attribute
897 	 *
898 	 * If this request is answered with an error code of ENOSYS, this is
899 	 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
900 	 * future removexattr() requests will fail with EOPNOTSUPP without being
901 	 * send to the filesystem process.
902 	 *
903 	 * Valid replies:
904 	 *   fuse_reply_err
905 	 *
906 	 * @param req request handle
907 	 * @param ino the inode number
908 	 * @param name of the extended attribute
909 	 */
910 	void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
911 
912 	/**
913 	 * Check file access permissions
914 	 *
915 	 * This will be called for the access() and chdir() system
916 	 * calls.  If the 'default_permissions' mount option is given,
917 	 * this method is not called.
918 	 *
919 	 * This method is not called under Linux kernel versions 2.4.x
920 	 *
921 	 * If this request is answered with an error code of ENOSYS, this is
922 	 * treated as a permanent success, i.e. this and all future access()
923 	 * requests will succeed without being send to the filesystem process.
924 	 *
925 	 * Valid replies:
926 	 *   fuse_reply_err
927 	 *
928 	 * @param req request handle
929 	 * @param ino the inode number
930 	 * @param mask requested access mode
931 	 */
932 	void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
933 
934 	/**
935 	 * Create and open a file
936 	 *
937 	 * If the file does not exist, first create it with the specified
938 	 * mode, and then open it.
939 	 *
940 	 * See the description of the open handler for more
941 	 * information.
942 	 *
943 	 * If this method is not implemented or under Linux kernel
944 	 * versions earlier than 2.6.15, the mknod() and open() methods
945 	 * will be called instead.
946 	 *
947 	 * If this request is answered with an error code of ENOSYS, the handler
948 	 * is treated as not implemented (i.e., for this and future requests the
949 	 * mknod() and open() handlers will be called instead).
950 	 *
951 	 * Valid replies:
952 	 *   fuse_reply_create
953 	 *   fuse_reply_err
954 	 *
955 	 * @param req request handle
956 	 * @param parent inode number of the parent directory
957 	 * @param name to create
958 	 * @param mode file type and mode with which to create the new file
959 	 * @param fi file information
960 	 */
961 	void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
962 			mode_t mode, struct fuse_file_info *fi);
963 
964 	/**
965 	 * Test for a POSIX file lock
966 	 *
967 	 * Valid replies:
968 	 *   fuse_reply_lock
969 	 *   fuse_reply_err
970 	 *
971 	 * @param req request handle
972 	 * @param ino the inode number
973 	 * @param fi file information
974 	 * @param lock the region/type to test
975 	 */
976 	void (*getlk) (fuse_req_t req, fuse_ino_t ino,
977 		       struct fuse_file_info *fi, struct flock *lock);
978 
979 	/**
980 	 * Acquire, modify or release a POSIX file lock
981 	 *
982 	 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
983 	 * owner, but otherwise this is not always the case.  For checking
984 	 * lock ownership, 'fi->owner' must be used.  The l_pid field in
985 	 * 'struct flock' should only be used to fill in this field in
986 	 * getlk().
987 	 *
988 	 * Note: if the locking methods are not implemented, the kernel
989 	 * will still allow file locking to work locally.  Hence these are
990 	 * only interesting for network filesystems and similar.
991 	 *
992 	 * Valid replies:
993 	 *   fuse_reply_err
994 	 *
995 	 * @param req request handle
996 	 * @param ino the inode number
997 	 * @param fi file information
998 	 * @param lock the region/type to set
999 	 * @param sleep locking operation may sleep
1000 	 */
1001 	void (*setlk) (fuse_req_t req, fuse_ino_t ino,
1002 		       struct fuse_file_info *fi,
1003 		       struct flock *lock, int sleep);
1004 
1005 	/**
1006 	 * Map block index within file to block index within device
1007 	 *
1008 	 * Note: This makes sense only for block device backed filesystems
1009 	 * mounted with the 'blkdev' option
1010 	 *
1011 	 * If this request is answered with an error code of ENOSYS, this is
1012 	 * treated as a permanent failure, i.e. all future bmap() requests will
1013 	 * fail with the same error code without being send to the filesystem
1014 	 * process.
1015 	 *
1016 	 * Valid replies:
1017 	 *   fuse_reply_bmap
1018 	 *   fuse_reply_err
1019 	 *
1020 	 * @param req request handle
1021 	 * @param ino the inode number
1022 	 * @param blocksize unit of block index
1023 	 * @param idx block index within file
1024 	 */
1025 	void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
1026 		      uint64_t idx);
1027 
1028 #if FUSE_USE_VERSION < 35
1029 	void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd,
1030 		       void *arg, struct fuse_file_info *fi, unsigned flags,
1031 		       const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1032 #else
1033 	/**
1034 	 * Ioctl
1035 	 *
1036 	 * Note: For unrestricted ioctls (not allowed for FUSE
1037 	 * servers), data in and out areas can be discovered by giving
1038 	 * iovs and setting FUSE_IOCTL_RETRY in *flags*.  For
1039 	 * restricted ioctls, kernel prepares in/out data area
1040 	 * according to the information encoded in cmd.
1041 	 *
1042 	 * Valid replies:
1043 	 *   fuse_reply_ioctl_retry
1044 	 *   fuse_reply_ioctl
1045 	 *   fuse_reply_ioctl_iov
1046 	 *   fuse_reply_err
1047 	 *
1048 	 * @param req request handle
1049 	 * @param ino the inode number
1050 	 * @param cmd ioctl command
1051 	 * @param arg ioctl argument
1052 	 * @param fi file information
1053 	 * @param flags for FUSE_IOCTL_* flags
1054 	 * @param in_buf data fetched from the caller
1055 	 * @param in_bufsz number of fetched bytes
1056 	 * @param out_bufsz maximum size of output data
1057 	 *
1058 	 * Note : the unsigned long request submitted by the application
1059 	 * is truncated to 32 bits.
1060 	 */
1061 	void (*ioctl) (fuse_req_t req, fuse_ino_t ino, unsigned int cmd,
1062 		       void *arg, struct fuse_file_info *fi, unsigned flags,
1063 		       const void *in_buf, size_t in_bufsz, size_t out_bufsz);
1064 #endif
1065 
1066 	/**
1067 	 * Poll for IO readiness
1068 	 *
1069 	 * Note: If ph is non-NULL, the client should notify
1070 	 * when IO readiness events occur by calling
1071 	 * fuse_lowlevel_notify_poll() with the specified ph.
1072 	 *
1073 	 * Regardless of the number of times poll with a non-NULL ph
1074 	 * is received, single notification is enough to clear all.
1075 	 * Notifying more times incurs overhead but doesn't harm
1076 	 * correctness.
1077 	 *
1078 	 * The callee is responsible for destroying ph with
1079 	 * fuse_pollhandle_destroy() when no longer in use.
1080 	 *
1081 	 * If this request is answered with an error code of ENOSYS, this is
1082 	 * treated as success (with a kernel-defined default poll-mask) and
1083 	 * future calls to pull() will succeed the same way without being send
1084 	 * to the filesystem process.
1085 	 *
1086 	 * Valid replies:
1087 	 *   fuse_reply_poll
1088 	 *   fuse_reply_err
1089 	 *
1090 	 * @param req request handle
1091 	 * @param ino the inode number
1092 	 * @param fi file information
1093 	 * @param ph poll handle to be used for notification
1094 	 */
1095 	void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1096 		      struct fuse_pollhandle *ph);
1097 
1098 	/**
1099 	 * Write data made available in a buffer
1100 	 *
1101 	 * This is a more generic version of the ->write() method.  If
1102 	 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
1103 	 * kernel supports splicing from the fuse device, then the
1104 	 * data will be made available in pipe for supporting zero
1105 	 * copy data transfer.
1106 	 *
1107 	 * buf->count is guaranteed to be one (and thus buf->idx is
1108 	 * always zero). The write_buf handler must ensure that
1109 	 * bufv->off is correctly updated (reflecting the number of
1110 	 * bytes read from bufv->buf[0]).
1111 	 *
1112 	 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
1113 	 * expected to reset the setuid and setgid bits.
1114 	 *
1115 	 * Valid replies:
1116 	 *   fuse_reply_write
1117 	 *   fuse_reply_err
1118 	 *
1119 	 * @param req request handle
1120 	 * @param ino the inode number
1121 	 * @param bufv buffer containing the data
1122 	 * @param off offset to write to
1123 	 * @param fi file information
1124 	 */
1125 	void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
1126 			   struct fuse_bufvec *bufv, off_t off,
1127 			   struct fuse_file_info *fi);
1128 
1129 	/**
1130 	 * Callback function for the retrieve request
1131 	 *
1132 	 * Valid replies:
1133 	 *	fuse_reply_none
1134 	 *
1135 	 * @param req request handle
1136 	 * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
1137 	 * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
1138 	 * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
1139 	 * @param bufv the buffer containing the returned data
1140 	 */
1141 	void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
1142 				off_t offset, struct fuse_bufvec *bufv);
1143 
1144 	/**
1145 	 * Forget about multiple inodes
1146 	 *
1147 	 * See description of the forget function for more
1148 	 * information.
1149 	 *
1150 	 * Valid replies:
1151 	 *   fuse_reply_none
1152 	 *
1153 	 * @param req request handle
1154 	 */
1155 	void (*forget_multi) (fuse_req_t req, size_t count,
1156 			      struct fuse_forget_data *forgets);
1157 
1158 	/**
1159 	 * Acquire, modify or release a BSD file lock
1160 	 *
1161 	 * Note: if the locking methods are not implemented, the kernel
1162 	 * will still allow file locking to work locally.  Hence these are
1163 	 * only interesting for network filesystems and similar.
1164 	 *
1165 	 * Valid replies:
1166 	 *   fuse_reply_err
1167 	 *
1168 	 * @param req request handle
1169 	 * @param ino the inode number
1170 	 * @param fi file information
1171 	 * @param op the locking operation, see flock(2)
1172 	 */
1173 	void (*flock) (fuse_req_t req, fuse_ino_t ino,
1174 		       struct fuse_file_info *fi, int op);
1175 
1176 	/**
1177 	 * Allocate requested space. If this function returns success then
1178 	 * subsequent writes to the specified range shall not fail due to the lack
1179 	 * of free space on the file system storage media.
1180 	 *
1181 	 * If this request is answered with an error code of ENOSYS, this is
1182 	 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1183 	 * future fallocate() requests will fail with EOPNOTSUPP without being
1184 	 * send to the filesystem process.
1185 	 *
1186 	 * Valid replies:
1187 	 *   fuse_reply_err
1188 	 *
1189 	 * @param req request handle
1190 	 * @param ino the inode number
1191 	 * @param offset starting point for allocated region
1192 	 * @param length size of allocated region
1193 	 * @param mode determines the operation to be performed on the given range,
1194 	 *             see fallocate(2)
1195 	 */
1196 	void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
1197 		       off_t offset, off_t length, struct fuse_file_info *fi);
1198 
1199 	/**
1200 	 * Read directory with attributes
1201 	 *
1202 	 * Send a buffer filled using fuse_add_direntry_plus(), with size not
1203 	 * exceeding the requested size.  Send an empty buffer on end of
1204 	 * stream.
1205 	 *
1206 	 * fi->fh will contain the value set by the opendir method, or
1207 	 * will be undefined if the opendir method didn't set any value.
1208 	 *
1209 	 * In contrast to readdir() (which does not affect the lookup counts),
1210 	 * the lookup count of every entry returned by readdirplus(), except "."
1211 	 * and "..", is incremented by one.
1212 	 *
1213 	 * Valid replies:
1214 	 *   fuse_reply_buf
1215 	 *   fuse_reply_data
1216 	 *   fuse_reply_err
1217 	 *
1218 	 * @param req request handle
1219 	 * @param ino the inode number
1220 	 * @param size maximum number of bytes to send
1221 	 * @param off offset to continue reading the directory stream
1222 	 * @param fi file information
1223 	 */
1224 	void (*readdirplus) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1225 			 struct fuse_file_info *fi);
1226 
1227 	/**
1228 	 * Copy a range of data from one file to another
1229 	 *
1230 	 * Performs an optimized copy between two file descriptors without the
1231 	 * additional cost of transferring data through the FUSE kernel module
1232 	 * to user space (glibc) and then back into the FUSE filesystem again.
1233 	 *
1234 	 * In case this method is not implemented, glibc falls back to reading
1235 	 * data from the source and writing to the destination. Effectively
1236 	 * doing an inefficient copy of the data.
1237 	 *
1238 	 * If this request is answered with an error code of ENOSYS, this is
1239 	 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1240 	 * future copy_file_range() requests will fail with EOPNOTSUPP without
1241 	 * being send to the filesystem process.
1242 	 *
1243 	 * Valid replies:
1244 	 *   fuse_reply_write
1245 	 *   fuse_reply_err
1246 	 *
1247 	 * @param req request handle
1248 	 * @param ino_in the inode number or the source file
1249 	 * @param off_in starting point from were the data should be read
1250 	 * @param fi_in file information of the source file
1251 	 * @param ino_out the inode number or the destination file
1252 	 * @param off_out starting point where the data should be written
1253 	 * @param fi_out file information of the destination file
1254 	 * @param len maximum size of the data to copy
1255 	 * @param flags passed along with the copy_file_range() syscall
1256 	 */
1257 	void (*copy_file_range) (fuse_req_t req, fuse_ino_t ino_in,
1258 				 off_t off_in, struct fuse_file_info *fi_in,
1259 				 fuse_ino_t ino_out, off_t off_out,
1260 				 struct fuse_file_info *fi_out, size_t len,
1261 				 int flags);
1262 
1263 	/**
1264 	 * Find next data or hole after the specified offset
1265 	 *
1266 	 * If this request is answered with an error code of ENOSYS, this is
1267 	 * treated as a permanent failure, i.e. all future lseek() requests will
1268 	 * fail with the same error code without being send to the filesystem
1269 	 * process.
1270 	 *
1271 	 * Valid replies:
1272 	 *   fuse_reply_lseek
1273 	 *   fuse_reply_err
1274 	 *
1275 	 * @param req request handle
1276 	 * @param ino the inode number
1277 	 * @param off offset to start search from
1278 	 * @param whence either SEEK_DATA or SEEK_HOLE
1279 	 * @param fi file information
1280 	 */
1281 	void (*lseek) (fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1282 		       struct fuse_file_info *fi);
1283 };
1284 
1285 /**
1286  * Reply with an error code or success.
1287  *
1288  * Possible requests:
1289  *   all except forget, forget_multi, retrieve_reply
1290  *
1291  * Wherever possible, error codes should be chosen from the list of
1292  * documented error conditions in the corresponding system calls
1293  * manpage.
1294  *
1295  * An error code of ENOSYS is sometimes treated specially. This is
1296  * indicated in the documentation of the affected handler functions.
1297  *
1298  * The following requests may be answered with a zero error code:
1299  * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1300  * removexattr, setlk.
1301  *
1302  * @param req request handle
1303  * @param err the positive error value, or zero for success
1304  * @return zero for success, -errno for failure to send reply
1305  */
1306 int fuse_reply_err(fuse_req_t req, int err);
1307 
1308 /**
1309  * Don't send reply
1310  *
1311  * Possible requests:
1312  *   forget
1313  *   forget_multi
1314  *   retrieve_reply
1315  *
1316  * @param req request handle
1317  */
1318 void fuse_reply_none(fuse_req_t req);
1319 
1320 /**
1321  * Reply with a directory entry
1322  *
1323  * Possible requests:
1324  *   lookup, mknod, mkdir, symlink, link
1325  *
1326  * Side effects:
1327  *   increments the lookup count on success
1328  *
1329  * @param req request handle
1330  * @param e the entry parameters
1331  * @return zero for success, -errno for failure to send reply
1332  */
1333 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1334 
1335 /**
1336  * Reply with a directory entry and open parameters
1337  *
1338  * currently the following members of 'fi' are used:
1339  *   fh, direct_io, keep_cache
1340  *
1341  * Possible requests:
1342  *   create
1343  *
1344  * Side effects:
1345  *   increments the lookup count on success
1346  *
1347  * @param req request handle
1348  * @param e the entry parameters
1349  * @param fi file information
1350  * @return zero for success, -errno for failure to send reply
1351  */
1352 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1353 		      const struct fuse_file_info *fi);
1354 
1355 /**
1356  * Reply with attributes
1357  *
1358  * Possible requests:
1359  *   getattr, setattr
1360  *
1361  * @param req request handle
1362  * @param attr the attributes
1363  * @param attr_timeout	validity timeout (in seconds) for the attributes
1364  * @return zero for success, -errno for failure to send reply
1365  */
1366 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1367 		    double attr_timeout);
1368 
1369 /**
1370  * Reply with the contents of a symbolic link
1371  *
1372  * Possible requests:
1373  *   readlink
1374  *
1375  * @param req request handle
1376  * @param link symbolic link contents
1377  * @return zero for success, -errno for failure to send reply
1378  */
1379 int fuse_reply_readlink(fuse_req_t req, const char *link);
1380 
1381 /**
1382  * Reply with open parameters
1383  *
1384  * currently the following members of 'fi' are used:
1385  *   fh, direct_io, keep_cache
1386  *
1387  * Possible requests:
1388  *   open, opendir
1389  *
1390  * @param req request handle
1391  * @param fi file information
1392  * @return zero for success, -errno for failure to send reply
1393  */
1394 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1395 
1396 /**
1397  * Reply with number of bytes written
1398  *
1399  * Possible requests:
1400  *   write
1401  *
1402  * @param req request handle
1403  * @param count the number of bytes written
1404  * @return zero for success, -errno for failure to send reply
1405  */
1406 int fuse_reply_write(fuse_req_t req, size_t count);
1407 
1408 /**
1409  * Reply with data
1410  *
1411  * Possible requests:
1412  *   read, readdir, getxattr, listxattr
1413  *
1414  * @param req request handle
1415  * @param buf buffer containing data
1416  * @param size the size of data in bytes
1417  * @return zero for success, -errno for failure to send reply
1418  */
1419 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1420 
1421 /**
1422  * Reply with data copied/moved from buffer(s)
1423  *
1424  * Zero copy data transfer ("splicing") will be used under
1425  * the following circumstances:
1426  *
1427  * 1. FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.want, and
1428  * 2. the kernel supports splicing from the fuse device
1429  *    (FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.capable), and
1430  * 3. *flags* does not contain FUSE_BUF_NO_SPLICE
1431  * 4. The amount of data that is provided in file-descriptor backed
1432  *    buffers (i.e., buffers for which bufv[n].flags == FUSE_BUF_FD)
1433  *    is at least twice the page size.
1434  *
1435  * In order for SPLICE_F_MOVE to be used, the following additional
1436  * conditions have to be fulfilled:
1437  *
1438  * 1. FUSE_CAP_SPLICE_MOVE is set in fuse_conn_info.want, and
1439  * 2. the kernel supports it (i.e, FUSE_CAP_SPLICE_MOVE is set in
1440       fuse_conn_info.capable), and
1441  * 3. *flags* contains FUSE_BUF_SPLICE_MOVE
1442  *
1443  * Note that, if splice is used, the data is actually spliced twice:
1444  * once into a temporary pipe (to prepend header data), and then again
1445  * into the kernel. If some of the provided buffers are memory-backed,
1446  * the data in them is copied in step one and spliced in step two.
1447  *
1448  * The FUSE_BUF_SPLICE_FORCE_SPLICE and FUSE_BUF_SPLICE_NONBLOCK flags
1449  * are silently ignored.
1450  *
1451  * Possible requests:
1452  *   read, readdir, getxattr, listxattr
1453  *
1454  * Side effects:
1455  *   when used to return data from a readdirplus() (but not readdir())
1456  *   call, increments the lookup count of each returned entry by one
1457  *   on success.
1458  *
1459  * @param req request handle
1460  * @param bufv buffer vector
1461  * @param flags flags controlling the copy
1462  * @return zero for success, -errno for failure to send reply
1463  */
1464 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1465 		    enum fuse_buf_copy_flags flags);
1466 
1467 /**
1468  * Reply with data vector
1469  *
1470  * Possible requests:
1471  *   read, readdir, getxattr, listxattr
1472  *
1473  * @param req request handle
1474  * @param iov the vector containing the data
1475  * @param count the size of vector
1476  * @return zero for success, -errno for failure to send reply
1477  */
1478 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1479 
1480 /**
1481  * Reply with filesystem statistics
1482  *
1483  * Possible requests:
1484  *   statfs
1485  *
1486  * @param req request handle
1487  * @param stbuf filesystem statistics
1488  * @return zero for success, -errno for failure to send reply
1489  */
1490 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1491 
1492 /**
1493  * Reply with needed buffer size
1494  *
1495  * Possible requests:
1496  *   getxattr, listxattr
1497  *
1498  * @param req request handle
1499  * @param count the buffer size needed in bytes
1500  * @return zero for success, -errno for failure to send reply
1501  */
1502 int fuse_reply_xattr(fuse_req_t req, size_t count);
1503 
1504 /**
1505  * Reply with file lock information
1506  *
1507  * Possible requests:
1508  *   getlk
1509  *
1510  * @param req request handle
1511  * @param lock the lock information
1512  * @return zero for success, -errno for failure to send reply
1513  */
1514 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1515 
1516 /**
1517  * Reply with block index
1518  *
1519  * Possible requests:
1520  *   bmap
1521  *
1522  * @param req request handle
1523  * @param idx block index within device
1524  * @return zero for success, -errno for failure to send reply
1525  */
1526 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1527 
1528 /* ----------------------------------------------------------- *
1529  * Filling a buffer in readdir				       *
1530  * ----------------------------------------------------------- */
1531 
1532 /**
1533  * Add a directory entry to the buffer
1534  *
1535  * Buffer needs to be large enough to hold the entry.  If it's not,
1536  * then the entry is not filled in but the size of the entry is still
1537  * returned.  The caller can check this by comparing the bufsize
1538  * parameter with the returned entry size.  If the entry size is
1539  * larger than the buffer size, the operation failed.
1540  *
1541  * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1542  * st_mode field are used.  The other fields are ignored.
1543  *
1544  * *off* should be any non-zero value that the filesystem can use to
1545  * identify the current point in the directory stream. It does not
1546  * need to be the actual physical position. A value of zero is
1547  * reserved to mean "from the beginning", and should therefore never
1548  * be used (the first call to fuse_add_direntry should be passed the
1549  * offset of the second directory entry).
1550  *
1551  * @param req request handle
1552  * @param buf the point where the new entry will be added to the buffer
1553  * @param bufsize remaining size of the buffer
1554  * @param name the name of the entry
1555  * @param stbuf the file attributes
1556  * @param off the offset of the next entry
1557  * @return the space needed for the entry
1558  */
1559 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1560 			 const char *name, const struct stat *stbuf,
1561 			 off_t off);
1562 
1563 /**
1564  * Add a directory entry to the buffer with the attributes
1565  *
1566  * See documentation of `fuse_add_direntry()` for more details.
1567  *
1568  * @param req request handle
1569  * @param buf the point where the new entry will be added to the buffer
1570  * @param bufsize remaining size of the buffer
1571  * @param name the name of the entry
1572  * @param e the directory entry
1573  * @param off the offset of the next entry
1574  * @return the space needed for the entry
1575  */
1576 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1577 			      const char *name,
1578 			      const struct fuse_entry_param *e, off_t off);
1579 
1580 /**
1581  * Reply to ask for data fetch and output buffer preparation.  ioctl
1582  * will be retried with the specified input data fetched and output
1583  * buffer prepared.
1584  *
1585  * Possible requests:
1586  *   ioctl
1587  *
1588  * @param req request handle
1589  * @param in_iov iovec specifying data to fetch from the caller
1590  * @param in_count number of entries in in_iov
1591  * @param out_iov iovec specifying addresses to write output to
1592  * @param out_count number of entries in out_iov
1593  * @return zero for success, -errno for failure to send reply
1594  */
1595 int fuse_reply_ioctl_retry(fuse_req_t req,
1596 			   const struct iovec *in_iov, size_t in_count,
1597 			   const struct iovec *out_iov, size_t out_count);
1598 
1599 /**
1600  * Reply to finish ioctl
1601  *
1602  * Possible requests:
1603  *   ioctl
1604  *
1605  * @param req request handle
1606  * @param result result to be passed to the caller
1607  * @param buf buffer containing output data
1608  * @param size length of output data
1609  */
1610 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1611 
1612 /**
1613  * Reply to finish ioctl with iov buffer
1614  *
1615  * Possible requests:
1616  *   ioctl
1617  *
1618  * @param req request handle
1619  * @param result result to be passed to the caller
1620  * @param iov the vector containing the data
1621  * @param count the size of vector
1622  */
1623 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1624 			 int count);
1625 
1626 /**
1627  * Reply with poll result event mask
1628  *
1629  * @param req request handle
1630  * @param revents poll result event mask
1631  */
1632 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1633 
1634 /**
1635  * Reply with offset
1636  *
1637  * Possible requests:
1638  *   lseek
1639  *
1640  * @param req request handle
1641  * @param off offset of next data or hole
1642  * @return zero for success, -errno for failure to send reply
1643  */
1644 int fuse_reply_lseek(fuse_req_t req, off_t off);
1645 
1646 /* ----------------------------------------------------------- *
1647  * Notification						       *
1648  * ----------------------------------------------------------- */
1649 
1650 /**
1651  * Notify IO readiness event
1652  *
1653  * For more information, please read comment for poll operation.
1654  *
1655  * @param ph poll handle to notify IO readiness event for
1656  */
1657 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1658 
1659 /**
1660  * Notify to invalidate cache for an inode.
1661  *
1662  * Added in FUSE protocol version 7.12. If the kernel does not support
1663  * this (or a newer) version, the function will return -ENOSYS and do
1664  * nothing.
1665  *
1666  * If the filesystem has writeback caching enabled, invalidating an
1667  * inode will first trigger a writeback of all dirty pages. The call
1668  * will block until all writeback requests have completed and the
1669  * inode has been invalidated. It will, however, not wait for
1670  * completion of pending writeback requests that have been issued
1671  * before.
1672  *
1673  * If there are no dirty pages, this function will never block.
1674  *
1675  * @param se the session object
1676  * @param ino the inode number
1677  * @param off the offset in the inode where to start invalidating
1678  *            or negative to invalidate attributes only
1679  * @param len the amount of cache to invalidate or 0 for all
1680  * @return zero for success, -errno for failure
1681  */
1682 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1683 				     off_t off, off_t len);
1684 
1685 /**
1686  * Notify to invalidate parent attributes and the dentry matching parent/name
1687  *
1688  * To avoid a deadlock this function must not be called in the
1689  * execution path of a related filesystem operation or within any code
1690  * that could hold a lock that could be needed to execute such an
1691  * operation. As of kernel 4.18, a "related operation" is a lookup(),
1692  * symlink(), mknod(), mkdir(), unlink(), rename(), link() or create()
1693  * request for the parent, and a setattr(), unlink(), rmdir(),
1694  * rename(), setxattr(), removexattr(), readdir() or readdirplus()
1695  * request for the inode itself.
1696  *
1697  * When called correctly, this function will never block.
1698  *
1699  * Added in FUSE protocol version 7.12. If the kernel does not support
1700  * this (or a newer) version, the function will return -ENOSYS and do
1701  * nothing.
1702  *
1703  * @param se the session object
1704  * @param parent inode number
1705  * @param name file name
1706  * @param namelen strlen() of file name
1707  * @return zero for success, -errno for failure
1708  */
1709 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1710 				     const char *name, size_t namelen);
1711 
1712 /**
1713  * Notify to expire parent attributes and the dentry matching parent/name
1714  *
1715  * Same restrictions apply as for fuse_lowlevel_notify_inval_entry()
1716  *
1717  * Compared to invalidating an entry, expiring the entry results not in a
1718  * forceful removal of that entry from kernel cache but instead the next access
1719  * to it forces a lookup from the filesystem.
1720  *
1721  * This makes a difference for overmounted dentries, where plain invalidation
1722  * would detach all submounts before dropping the dentry from the cache.
1723  * If only expiry is set on the dentry, then any overmounts are left alone and
1724  * until ->d_revalidate() is called.
1725  *
1726  * Note: ->d_revalidate() is not called for the case of following a submount,
1727  * so invalidation will only be triggered for the non-overmounted case.
1728  * The dentry could also be mounted in a different mount instance, in which case
1729  * any submounts will still be detached.
1730  *
1731  * Added in FUSE protocol version 7.38. If the kernel does not support
1732  * this (or a newer) version, the function will return -ENOSYS and do nothing.
1733  *
1734  * @param se the session object
1735  * @param parent inode number
1736  * @param name file name
1737  * @param namelen strlen() of file name
1738  * @return zero for success, -errno for failure, -enosys if no kernel support
1739 */
1740 int fuse_lowlevel_notify_expire_entry(struct fuse_session *se, fuse_ino_t parent,
1741                                       const char *name, size_t namelen);
1742 
1743 /**
1744  * This function behaves like fuse_lowlevel_notify_inval_entry() with
1745  * the following additional effect (at least as of Linux kernel 4.8):
1746  *
1747  * If the provided *child* inode matches the inode that is currently
1748  * associated with the cached dentry, and if there are any inotify
1749  * watches registered for the dentry, then the watchers are informed
1750  * that the dentry has been deleted.
1751  *
1752  * To avoid a deadlock this function must not be called while
1753  * executing a related filesystem operation or while holding a lock
1754  * that could be needed to execute such an operation (see the
1755  * description of fuse_lowlevel_notify_inval_entry() for more
1756  * details).
1757  *
1758  * When called correctly, this function will never block.
1759  *
1760  * Added in FUSE protocol version 7.18. If the kernel does not support
1761  * this (or a newer) version, the function will return -ENOSYS and do
1762  * nothing.
1763  *
1764  * @param se the session object
1765  * @param parent inode number
1766  * @param child inode number
1767  * @param name file name
1768  * @param namelen strlen() of file name
1769  * @return zero for success, -errno for failure
1770  */
1771 int fuse_lowlevel_notify_delete(struct fuse_session *se,
1772 				fuse_ino_t parent, fuse_ino_t child,
1773 				const char *name, size_t namelen);
1774 
1775 /**
1776  * Store data to the kernel buffers
1777  *
1778  * Synchronously store data in the kernel buffers belonging to the
1779  * given inode.  The stored data is marked up-to-date (no read will be
1780  * performed against it, unless it's invalidated or evicted from the
1781  * cache).
1782  *
1783  * If the stored data overflows the current file size, then the size
1784  * is extended, similarly to a write(2) on the filesystem.
1785  *
1786  * If this function returns an error, then the store wasn't fully
1787  * completed, but it may have been partially completed.
1788  *
1789  * Added in FUSE protocol version 7.15. If the kernel does not support
1790  * this (or a newer) version, the function will return -ENOSYS and do
1791  * nothing.
1792  *
1793  * @param se the session object
1794  * @param ino the inode number
1795  * @param offset the starting offset into the file to store to
1796  * @param bufv buffer vector
1797  * @param flags flags controlling the copy
1798  * @return zero for success, -errno for failure
1799  */
1800 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1801 			       off_t offset, struct fuse_bufvec *bufv,
1802 			       enum fuse_buf_copy_flags flags);
1803 /**
1804  * Retrieve data from the kernel buffers
1805  *
1806  * Retrieve data in the kernel buffers belonging to the given inode.
1807  * If successful then the retrieve_reply() method will be called with
1808  * the returned data.
1809  *
1810  * Only present pages are returned in the retrieve reply.  Retrieving
1811  * stops when it finds a non-present page and only data prior to that
1812  * is returned.
1813  *
1814  * If this function returns an error, then the retrieve will not be
1815  * completed and no reply will be sent.
1816  *
1817  * This function doesn't change the dirty state of pages in the kernel
1818  * buffer.  For dirty pages the write() method will be called
1819  * regardless of having been retrieved previously.
1820  *
1821  * Added in FUSE protocol version 7.15. If the kernel does not support
1822  * this (or a newer) version, the function will return -ENOSYS and do
1823  * nothing.
1824  *
1825  * @param se the session object
1826  * @param ino the inode number
1827  * @param size the number of bytes to retrieve
1828  * @param offset the starting offset into the file to retrieve from
1829  * @param cookie user data to supply to the reply callback
1830  * @return zero for success, -errno for failure
1831  */
1832 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1833 				  size_t size, off_t offset, void *cookie);
1834 
1835 
1836 /* ----------------------------------------------------------- *
1837  * Utility functions					       *
1838  * ----------------------------------------------------------- */
1839 
1840 /**
1841  * Get the userdata from the request
1842  *
1843  * @param req request handle
1844  * @return the user data passed to fuse_session_new()
1845  */
1846 void *fuse_req_userdata(fuse_req_t req);
1847 
1848 /**
1849  * Get the context from the request
1850  *
1851  * The pointer returned by this function will only be valid for the
1852  * request's lifetime
1853  *
1854  * @param req request handle
1855  * @return the context structure
1856  */
1857 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1858 
1859 /**
1860  * Get the current supplementary group IDs for the specified request
1861  *
1862  * Similar to the getgroups(2) system call, except the return value is
1863  * always the total number of group IDs, even if it is larger than the
1864  * specified size.
1865  *
1866  * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1867  * the group list to userspace, hence this function needs to parse
1868  * "/proc/$TID/task/$TID/status" to get the group IDs.
1869  *
1870  * This feature may not be supported on all operating systems.  In
1871  * such a case this function will return -ENOSYS.
1872  *
1873  * @param req request handle
1874  * @param size size of given array
1875  * @param list array of group IDs to be filled in
1876  * @return the total number of supplementary group IDs or -errno on failure
1877  */
1878 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1879 
1880 /**
1881  * Callback function for an interrupt
1882  *
1883  * @param req interrupted request
1884  * @param data user data
1885  */
1886 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1887 
1888 /**
1889  * Register/unregister callback for an interrupt
1890  *
1891  * If an interrupt has already happened, then the callback function is
1892  * called from within this function, hence it's not possible for
1893  * interrupts to be lost.
1894  *
1895  * @param req request handle
1896  * @param func the callback function or NULL for unregister
1897  * @param data user data passed to the callback function
1898  */
1899 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1900 			     void *data);
1901 
1902 /**
1903  * Check if a request has already been interrupted
1904  *
1905  * @param req request handle
1906  * @return 1 if the request has been interrupted, 0 otherwise
1907  */
1908 int fuse_req_interrupted(fuse_req_t req);
1909 
1910 
1911 /* ----------------------------------------------------------- *
1912  * Inquiry functions                                           *
1913  * ----------------------------------------------------------- */
1914 
1915 /**
1916  * Print low-level version information to stdout.
1917  */
1918 void fuse_lowlevel_version(void);
1919 
1920 /**
1921  * Print available low-level options to stdout. This is not an
1922  * exhaustive list, but includes only those options that may be of
1923  * interest to an end-user of a file system.
1924  */
1925 void fuse_lowlevel_help(void);
1926 
1927 /**
1928  * Print available options for `fuse_parse_cmdline()`.
1929  */
1930 void fuse_cmdline_help(void);
1931 
1932 /* ----------------------------------------------------------- *
1933  * Filesystem setup & teardown                                 *
1934  * ----------------------------------------------------------- */
1935 
1936 /**
1937  * Note: Any addition to this struct needs to create a compatibility symbol
1938  *       for fuse_parse_cmdline(). For ABI compatibility reasons it is also
1939  *       not possible to remove struct members.
1940  */
1941 struct fuse_cmdline_opts {
1942 	int singlethread;
1943 	int foreground;
1944 	int debug;
1945 	int nodefault_subtype;
1946 	char *mountpoint;
1947 	int show_version;
1948 	int show_help;
1949 	int clone_fd;
1950 	unsigned int max_idle_threads; /* discouraged, due to thread
1951 	                                * destruct overhead */
1952 
1953 	/* Added in libfuse-3.12 */
1954 	unsigned int max_threads;
1955 };
1956 
1957 /**
1958  * Utility function to parse common options for simple file systems
1959  * using the low-level API. A help text that describes the available
1960  * options can be printed with `fuse_cmdline_help`. A single
1961  * non-option argument is treated as the mountpoint. Multiple
1962  * non-option arguments will result in an error.
1963  *
1964  * If neither -o subtype= or -o fsname= options are given, a new
1965  * subtype option will be added and set to the basename of the program
1966  * (the fsname will remain unset, and then defaults to "fuse").
1967  *
1968  * Known options will be removed from *args*, unknown options will
1969  * remain.
1970  *
1971  * @param args argument vector (input+output)
1972  * @param opts output argument for parsed options
1973  * @return 0 on success, -1 on failure
1974  */
1975 #if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS))
1976 int fuse_parse_cmdline(struct fuse_args *args,
1977 		       struct fuse_cmdline_opts *opts);
1978 #else
1979 #if FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
1980 int fuse_parse_cmdline_30(struct fuse_args *args,
1981 			   struct fuse_cmdline_opts *opts);
1982 #define fuse_parse_cmdline(args, opts) fuse_parse_cmdline_30(args, opts)
1983 #else
1984 int fuse_parse_cmdline_312(struct fuse_args *args,
1985 			   struct fuse_cmdline_opts *opts);
1986 #define fuse_parse_cmdline(args, opts) fuse_parse_cmdline_312(args, opts)
1987 #endif
1988 #endif
1989 
1990 /**
1991  * Create a low level session.
1992  *
1993  * Returns a session structure suitable for passing to
1994  * fuse_session_mount() and fuse_session_loop().
1995  *
1996  * This function accepts most file-system independent mount options
1997  * (like context, nodev, ro - see mount(8)), as well as the general
1998  * fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and
1999  * -o default_permissions, but not ``-o use_ino``).  Instead of `-o
2000  * debug`, debugging may also enabled with `-d` or `--debug`.
2001  *
2002  * If not all options are known, an error message is written to stderr
2003  * and the function returns NULL.
2004  *
2005  * Option parsing skips argv[0], which is assumed to contain the
2006  * program name. To prevent accidentally passing an option in
2007  * argv[0], this element must always be present (even if no options
2008  * are specified). It may be set to the empty string ('\0') if no
2009  * reasonable value can be provided.
2010  *
2011  * @param args argument vector
2012  * @param op the (low-level) filesystem operations
2013  * @param op_size sizeof(struct fuse_lowlevel_ops)
2014  * @param userdata user data
2015  *
2016  * @return the fuse session on success, NULL on failure
2017  **/
2018 struct fuse_session *fuse_session_new(struct fuse_args *args,
2019 				      const struct fuse_lowlevel_ops *op,
2020 				      size_t op_size, void *userdata);
2021 
2022 /**
2023  * Set a file descriptor for the session.
2024  *
2025  * This function can be used if you want to have a custom communication
2026  * interface instead of using a mountpoint. In practice, this means that instead
2027  * of calling fuse_session_mount() and fuse_session_unmount(), one could call
2028  * fuse_session_custom_io() where fuse_session_mount() would have otherwise been
2029  * called.
2030  *
2031  * In `io`, implementations for read and writev MUST be provided. Otherwise -1
2032  * will be returned and `fd` will not be used. Implementations for `splice_send`
2033  * and `splice_receive` are optional. If they are not provided splice will not
2034  * be used for send or receive respectively.
2035  *
2036  * The provided file descriptor `fd` will be closed when fuse_session_destroy()
2037  * is called.
2038  *
2039  * @param se session object
2040  * @param io Custom io to use when retrieving/sending requests/responses
2041  * @param fd file descriptor for the session
2042  *
2043  * @return 0  on success
2044  * @return -EINVAL if `io`, `io->read` or `ìo->writev` are NULL
2045  * @return -EBADF  if `fd` was smaller than 0
2046  * @return -errno  if failed to allocate memory to store `io`
2047  *
2048  **/
2049 int fuse_session_custom_io(struct fuse_session *se,
2050 				   const struct fuse_custom_io *io, int fd);
2051 
2052 /**
2053  * Mount a FUSE file system.
2054  *
2055  * @param mountpoint the mount point path
2056  * @param se session object
2057  *
2058  * @return 0 on success, -1 on failure.
2059  **/
2060 int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
2061 
2062 /**
2063  * Enter a single threaded, blocking event loop.
2064  *
2065  * When the event loop terminates because the connection to the FUSE
2066  * kernel module has been closed, this function returns zero. This
2067  * happens when the filesystem is unmounted regularly (by the
2068  * filesystem owner or root running the umount(8) or fusermount(1)
2069  * command), or if connection is explicitly severed by writing ``1``
2070  * to the``abort`` file in ``/sys/fs/fuse/connections/NNN``. The only
2071  * way to distinguish between these two conditions is to check if the
2072  * filesystem is still mounted after the session loop returns.
2073  *
2074  * When some error occurs during request processing, the function
2075  * returns a negated errno(3) value.
2076  *
2077  * If the loop has been terminated because of a signal handler
2078  * installed by fuse_set_signal_handlers(), this function returns the
2079  * (positive) signal value that triggered the exit.
2080  *
2081  * @param se the session
2082  * @return 0, -errno, or a signal value
2083  */
2084 int fuse_session_loop(struct fuse_session *se);
2085 
2086 #if FUSE_USE_VERSION < 32
2087 	int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd);
2088 	#define fuse_session_loop_mt(se, clone_fd) fuse_session_loop_mt_31(se, clone_fd)
2089 #elif FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12)
2090 	int fuse_session_loop_mt_32(struct fuse_session *se, struct fuse_loop_config *config);
2091 	#define fuse_session_loop_mt(se, config) fuse_session_loop_mt_32(se, config)
2092 #else
2093 	#if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS))
2094 		/**
2095 		 * Enter a multi-threaded event loop.
2096 		 *
2097 		 * For a description of the return value and the conditions when the
2098 		 * event loop exits, refer to the documentation of
2099 		 * fuse_session_loop().
2100 		 *
2101 		 * @param se the session
2102 		 * @param config session loop configuration
2103 		 * @return see fuse_session_loop()
2104 		 */
2105 		int fuse_session_loop_mt(struct fuse_session *se, struct fuse_loop_config *config);
2106 	#else
2107 		int fuse_session_loop_mt_312(struct fuse_session *se, struct fuse_loop_config *config);
2108 		#define fuse_session_loop_mt(se, config) fuse_session_loop_mt_312(se, config)
2109 	#endif
2110 #endif
2111 
2112 /**
2113  * Flag a session as terminated.
2114  *
2115  * This will cause any running event loops to terminate on the next opportunity. If this function is
2116  * called by a thread that is not a FUSE worker thread, the next
2117  * opportunity will be when FUSE a request is received (which may be far in the future if the
2118  * filesystem is not currently being used by any clients). One way to avoid this delay is to
2119  * afterwards sent a signal to the main thread (if fuse_set_signal_handlers() is used, SIGPIPE
2120  * will cause the main thread to wake-up but otherwise be ignored).
2121  *
2122  * @param se the session
2123  */
2124 void fuse_session_exit(struct fuse_session *se);
2125 
2126 /**
2127  * Reset the terminated flag of a session
2128  *
2129  * @param se the session
2130  */
2131 void fuse_session_reset(struct fuse_session *se);
2132 
2133 /**
2134  * Query the terminated flag of a session
2135  *
2136  * @param se the session
2137  * @return 1 if exited, 0 if not exited
2138  */
2139 int fuse_session_exited(struct fuse_session *se);
2140 
2141 /**
2142  * Ensure that file system is unmounted.
2143  *
2144  * In regular operation, the file system is typically unmounted by the
2145  * user calling umount(8) or fusermount(1), which then terminates the
2146  * FUSE session loop. However, the session loop may also terminate as
2147  * a result of an explicit call to fuse_session_exit() (e.g. by a
2148  * signal handler installed by fuse_set_signal_handler()). In this
2149  * case the filesystem remains mounted, but any attempt to access it
2150  * will block (while the filesystem process is still running) or give
2151  * an ESHUTDOWN error (after the filesystem process has terminated).
2152  *
2153  * If the communication channel with the FUSE kernel module is still
2154  * open (i.e., if the session loop was terminated by an explicit call
2155  * to fuse_session_exit()), this function will close it and unmount
2156  * the filesystem. If the communication channel has been closed by the
2157  * kernel, this method will do (almost) nothing.
2158  *
2159  * NOTE: The above semantics mean that if the connection to the kernel
2160  * is terminated via the ``/sys/fs/fuse/connections/NNN/abort`` file,
2161  * this method will *not* unmount the filesystem.
2162  *
2163  * @param se the session
2164  */
2165 void fuse_session_unmount(struct fuse_session *se);
2166 
2167 /**
2168  * Destroy a session
2169  *
2170  * @param se the session
2171  */
2172 void fuse_session_destroy(struct fuse_session *se);
2173 
2174 /* ----------------------------------------------------------- *
2175  * Custom event loop support                                   *
2176  * ----------------------------------------------------------- */
2177 
2178 /**
2179  * Return file descriptor for communication with kernel.
2180  *
2181  * The file selector can be used to integrate FUSE with a custom event
2182  * loop. Whenever data is available for reading on the provided fd,
2183  * the event loop should call `fuse_session_receive_buf` followed by
2184  * `fuse_session_process_buf` to process the request.
2185  *
2186  * The returned file descriptor is valid until `fuse_session_unmount`
2187  * is called.
2188  *
2189  * @param se the session
2190  * @return a file descriptor
2191  */
2192 int fuse_session_fd(struct fuse_session *se);
2193 
2194 /**
2195  * Process a raw request supplied in a generic buffer
2196  *
2197  * The fuse_buf may contain a memory buffer or a pipe file descriptor.
2198  *
2199  * @param se the session
2200  * @param buf the fuse_buf containing the request
2201  */
2202 void fuse_session_process_buf(struct fuse_session *se,
2203 			      const struct fuse_buf *buf);
2204 
2205 /**
2206  * Read a raw request from the kernel into the supplied buffer.
2207  *
2208  * Depending on file system options, system capabilities, and request
2209  * size the request is either read into a memory buffer or spliced
2210  * into a temporary pipe.
2211  *
2212  * @param se the session
2213  * @param buf the fuse_buf to store the request in
2214  * @return the actual size of the raw request, or -errno on error
2215  */
2216 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
2217 
2218 #ifdef __cplusplus
2219 }
2220 #endif
2221 
2222 #endif /* FUSE_LOWLEVEL_H_ */
2223