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