util/vfio-helpers: Trace PCI I/O config accesses
[qemu/ar7.git] / tools / virtiofsd / fuse_lowlevel.h
blob9c06240f9e61ea259241a3ec77e9cf2ff8d5856f
1 /*
2 * FUSE: Filesystem in Userspace
3 * Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 * This program can be distributed under the terms of the GNU LGPLv2.
6 * See the file COPYING.LIB.
7 */
9 #ifndef FUSE_LOWLEVEL_H_
10 #define FUSE_LOWLEVEL_H_
12 /**
13 * @file
15 * Low level API
17 * IMPORTANT: you should define FUSE_USE_VERSION before including this
18 * header. To use the newest API define it to 31 (recommended for any
19 * new application).
22 #ifndef FUSE_USE_VERSION
23 #error FUSE_USE_VERSION not defined
24 #endif
26 #include "fuse_common.h"
28 #include <fcntl.h>
29 #include <sys/stat.h>
30 #include <sys/statvfs.h>
31 #include <sys/types.h>
32 #include <sys/uio.h>
33 #include <utime.h>
36 * Miscellaneous definitions
39 /** The node ID of the root inode */
40 #define FUSE_ROOT_ID 1
42 /** Inode number type */
43 typedef uint64_t fuse_ino_t;
45 /** Request pointer type */
46 typedef struct fuse_req *fuse_req_t;
48 /**
49 * Session
51 * This provides hooks for processing requests, and exiting
53 struct fuse_session;
55 /** Directory entry parameters supplied to fuse_reply_entry() */
56 struct fuse_entry_param {
57 /**
58 * Unique inode number
60 * In lookup, zero means negative entry (from version 2.5)
61 * Returning ENOENT also means negative entry, but by setting zero
62 * ino the kernel may cache negative entries for entry_timeout
63 * seconds.
65 fuse_ino_t ino;
67 /**
68 * Generation number for this entry.
70 * If the file system will be exported over NFS, the
71 * ino/generation pairs need to be unique over the file
72 * system's lifetime (rather than just the mount time). So if
73 * the file system reuses an inode after it has been deleted,
74 * it must assign a new, previously unused generation number
75 * to the inode at the same time.
78 uint64_t generation;
80 /**
81 * Inode attributes.
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.
88 struct stat attr;
90 /**
91 * Validity timeout (in seconds) for inode attributes. If
92 * attributes only change as a result of requests that come
93 * through the kernel, this should be set to a very large
94 * value.
96 double attr_timeout;
98 /**
99 * Validity timeout (in seconds) for the name. If directory
100 * entries are changed/deleted only as a result of requests
101 * that come through the kernel, this should be set to a very
102 * large value.
104 double entry_timeout;
107 * Flags for fuse_attr.flags that do not fit into attr.
109 uint32_t attr_flags;
113 * Additional context associated with requests.
115 * Note that the reported client uid, gid and pid may be zero in some
116 * situations. For example, if the FUSE file system is running in a
117 * PID or user namespace but then accessed from outside the namespace,
118 * there is no valid uid/pid/gid that could be reported.
120 struct fuse_ctx {
121 /** User ID of the calling process */
122 uid_t uid;
124 /** Group ID of the calling process */
125 gid_t gid;
127 /** Thread ID of the calling process */
128 pid_t pid;
130 /** Umask of the calling process */
131 mode_t umask;
134 struct fuse_forget_data {
135 fuse_ino_t ino;
136 uint64_t nlookup;
139 /* 'to_set' flags in setattr */
140 #define FUSE_SET_ATTR_MODE (1 << 0)
141 #define FUSE_SET_ATTR_UID (1 << 1)
142 #define FUSE_SET_ATTR_GID (1 << 2)
143 #define FUSE_SET_ATTR_SIZE (1 << 3)
144 #define FUSE_SET_ATTR_ATIME (1 << 4)
145 #define FUSE_SET_ATTR_MTIME (1 << 5)
146 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
147 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
148 #define FUSE_SET_ATTR_CTIME (1 << 10)
151 * Request methods and replies
155 * Low level filesystem operations
157 * Most of the methods (with the exception of init and destroy)
158 * receive a request handle (fuse_req_t) as their first argument.
159 * This handle must be passed to one of the specified reply functions.
161 * This may be done inside the method invocation, or after the call
162 * has returned. The request handle is valid until one of the reply
163 * functions is called.
165 * Other pointer arguments (name, fuse_file_info, etc) are not valid
166 * after the call has returned, so if they are needed later, their
167 * contents have to be copied.
169 * In general, all methods are expected to perform any necessary
170 * permission checking. However, a filesystem may delegate this task
171 * to the kernel by passing the `default_permissions` mount option to
172 * `fuse_session_new()`. In this case, methods will only be called if
173 * the kernel's permission check has succeeded.
175 * The filesystem sometimes needs to handle a return value of -ENOENT
176 * from the reply function, which means, that the request was
177 * interrupted, and the reply discarded. For example if
178 * fuse_reply_open() return -ENOENT means, that the release method for
179 * this file will not be called.
181 struct fuse_lowlevel_ops {
183 * Initialize filesystem
185 * This function is called when libfuse establishes
186 * communication with the FUSE kernel module. The file system
187 * should use this module to inspect and/or modify the
188 * connection parameters provided in the `conn` structure.
190 * Note that some parameters may be overwritten by options
191 * passed to fuse_session_new() which take precedence over the
192 * values set in this handler.
194 * There's no reply to this function
196 * @param userdata the user data passed to fuse_session_new()
198 void (*init)(void *userdata, struct fuse_conn_info *conn);
201 * Clean up filesystem.
203 * Called on filesystem exit. When this method is called, the
204 * connection to the kernel may be gone already, so that eg. calls
205 * to fuse_lowlevel_notify_* will fail.
207 * There's no reply to this function
209 * @param userdata the user data passed to fuse_session_new()
211 void (*destroy)(void *userdata);
214 * Look up a directory entry by name and get its attributes.
216 * Valid replies:
217 * fuse_reply_entry
218 * fuse_reply_err
220 * @param req request handle
221 * @param parent inode number of the parent directory
222 * @param name the name to look up
224 void (*lookup)(fuse_req_t req, fuse_ino_t parent, const char *name);
227 * Forget about an inode
229 * This function is called when the kernel removes an inode
230 * from its internal caches.
232 * The inode's lookup count increases by one for every call to
233 * fuse_reply_entry and fuse_reply_create. The nlookup parameter
234 * indicates by how much the lookup count should be decreased.
236 * Inodes with a non-zero lookup count may receive request from
237 * the kernel even after calls to unlink, rmdir or (when
238 * overwriting an existing file) rename. Filesystems must handle
239 * such requests properly and it is recommended to defer removal
240 * of the inode until the lookup count reaches zero. Calls to
241 * unlink, rmdir or rename will be followed closely by forget
242 * unless the file or directory is open, in which case the
243 * kernel issues forget only after the release or releasedir
244 * calls.
246 * Note that if a file system will be exported over NFS the
247 * inodes lifetime must extend even beyond forget. See the
248 * generation field in struct fuse_entry_param above.
250 * On unmount the lookup count for all inodes implicitly drops
251 * to zero. It is not guaranteed that the file system will
252 * receive corresponding forget messages for the affected
253 * inodes.
255 * Valid replies:
256 * fuse_reply_none
258 * @param req request handle
259 * @param ino the inode number
260 * @param nlookup the number of lookups to forget
262 void (*forget)(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
265 * Get file attributes.
267 * If writeback caching is enabled, the kernel may have a
268 * better idea of a file's length than the FUSE file system
269 * (eg if there has been a write that extended the file size,
270 * but that has not yet been passed to the filesystem.n
272 * In this case, the st_size value provided by the file system
273 * will be ignored.
275 * Valid replies:
276 * fuse_reply_attr
277 * fuse_reply_err
279 * @param req request handle
280 * @param ino the inode number
281 * @param fi for future use, currently always NULL
283 void (*getattr)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
286 * Set file attributes
288 * In the 'attr' argument only members indicated by the 'to_set'
289 * bitmask contain valid values. Other members contain undefined
290 * values.
292 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
293 * expected to reset the setuid and setgid bits if the file
294 * size or owner is being changed.
296 * If the setattr was invoked from the ftruncate() system call
297 * under Linux kernel versions 2.6.15 or later, the fi->fh will
298 * contain the value set by the open method or will be undefined
299 * if the open method didn't set any value. Otherwise (not
300 * ftruncate call, or kernel version earlier than 2.6.15) the fi
301 * parameter will be NULL.
303 * Valid replies:
304 * fuse_reply_attr
305 * fuse_reply_err
307 * @param req request handle
308 * @param ino the inode number
309 * @param attr the attributes
310 * @param to_set bit mask of attributes which should be set
311 * @param fi file information, or NULL
313 void (*setattr)(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
314 int to_set, struct fuse_file_info *fi);
317 * Read symbolic link
319 * Valid replies:
320 * fuse_reply_readlink
321 * fuse_reply_err
323 * @param req request handle
324 * @param ino the inode number
326 void (*readlink)(fuse_req_t req, fuse_ino_t ino);
329 * Create file node
331 * Create a regular file, character device, block device, fifo or
332 * socket node.
334 * Valid replies:
335 * fuse_reply_entry
336 * fuse_reply_err
338 * @param req request handle
339 * @param parent inode number of the parent directory
340 * @param name to create
341 * @param mode file type and mode with which to create the new file
342 * @param rdev the device number (only valid if created file is a device)
344 void (*mknod)(fuse_req_t req, fuse_ino_t parent, const char *name,
345 mode_t mode, dev_t rdev);
348 * Create a directory
350 * Valid replies:
351 * fuse_reply_entry
352 * fuse_reply_err
354 * @param req request handle
355 * @param parent inode number of the parent directory
356 * @param name to create
357 * @param mode with which to create the new file
359 void (*mkdir)(fuse_req_t req, fuse_ino_t parent, const char *name,
360 mode_t mode);
363 * Remove a file
365 * If the file's inode's lookup count is non-zero, the file
366 * system is expected to postpone any removal of the inode
367 * until the lookup count reaches zero (see description of the
368 * forget function).
370 * Valid replies:
371 * fuse_reply_err
373 * @param req request handle
374 * @param parent inode number of the parent directory
375 * @param name to remove
377 void (*unlink)(fuse_req_t req, fuse_ino_t parent, const char *name);
380 * Remove a directory
382 * If the directory's inode's lookup count is non-zero, the
383 * file system is expected to postpone any removal of the
384 * inode until the lookup count reaches zero (see description
385 * of the forget function).
387 * Valid replies:
388 * fuse_reply_err
390 * @param req request handle
391 * @param parent inode number of the parent directory
392 * @param name to remove
394 void (*rmdir)(fuse_req_t req, fuse_ino_t parent, const char *name);
397 * Create a symbolic link
399 * Valid replies:
400 * fuse_reply_entry
401 * fuse_reply_err
403 * @param req request handle
404 * @param link the contents of the symbolic link
405 * @param parent inode number of the parent directory
406 * @param name to create
408 void (*symlink)(fuse_req_t req, const char *link, fuse_ino_t parent,
409 const char *name);
412 * Rename a file
414 * If the target exists it should be atomically replaced. If
415 * the target's inode's lookup count is non-zero, the file
416 * system is expected to postpone any removal of the inode
417 * until the lookup count reaches zero (see description of the
418 * forget function).
420 * If this request is answered with an error code of ENOSYS, this is
421 * treated as a permanent failure with error code EINVAL, i.e. all
422 * future bmap requests will fail with EINVAL without being
423 * send to the filesystem process.
425 * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
426 * RENAME_NOREPLACE is specified, the filesystem must not
427 * overwrite *newname* if it exists and return an error
428 * instead. If `RENAME_EXCHANGE` is specified, the filesystem
429 * must atomically exchange the two files, i.e. both must
430 * exist and neither may be deleted.
432 * Valid replies:
433 * fuse_reply_err
435 * @param req request handle
436 * @param parent inode number of the old parent directory
437 * @param name old name
438 * @param newparent inode number of the new parent directory
439 * @param newname new name
441 void (*rename)(fuse_req_t req, fuse_ino_t parent, const char *name,
442 fuse_ino_t newparent, const char *newname,
443 unsigned int flags);
446 * Create a hard link
448 * Valid replies:
449 * fuse_reply_entry
450 * fuse_reply_err
452 * @param req request handle
453 * @param ino the old inode number
454 * @param newparent inode number of the new parent directory
455 * @param newname new name to create
457 void (*link)(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
458 const char *newname);
461 * Open a file
463 * Open flags are available in fi->flags. The following rules
464 * apply.
466 * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
467 * filtered out / handled by the kernel.
469 * - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
470 * by the filesystem to check if the operation is
471 * permitted. If the ``-o default_permissions`` mount
472 * option is given, this check is already done by the
473 * kernel before calling open() and may thus be omitted by
474 * the filesystem.
476 * - When writeback caching is enabled, the kernel may send
477 * read requests even for files opened with O_WRONLY. The
478 * filesystem should be prepared to handle this.
480 * - When writeback caching is disabled, the filesystem is
481 * expected to properly handle the O_APPEND flag and ensure
482 * that each write is appending to the end of the file.
484 * - When writeback caching is enabled, the kernel will
485 * handle O_APPEND. However, unless all changes to the file
486 * come through the kernel this will not work reliably. The
487 * filesystem should thus either ignore the O_APPEND flag
488 * (and let the kernel handle it), or return an error
489 * (indicating that reliably O_APPEND is not available).
491 * Filesystem may store an arbitrary file handle (pointer,
492 * index, etc) in fi->fh, and use this in other all other file
493 * operations (read, write, flush, release, fsync).
495 * Filesystem may also implement stateless file I/O and not store
496 * anything in fi->fh.
498 * There are also some flags (direct_io, keep_cache) which the
499 * filesystem may set in fi, to change the way the file is opened.
500 * See fuse_file_info structure in <fuse_common.h> for more details.
502 * If this request is answered with an error code of ENOSYS
503 * and FUSE_CAP_NO_OPEN_SUPPORT is set in
504 * `fuse_conn_info.capable`, this is treated as success and
505 * future calls to open and release will also succeed without being
506 * sent to the filesystem process.
508 * Valid replies:
509 * fuse_reply_open
510 * fuse_reply_err
512 * @param req request handle
513 * @param ino the inode number
514 * @param fi file information
516 void (*open)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
519 * Read data
521 * Read should send exactly the number of bytes requested except
522 * on EOF or error, otherwise the rest of the data will be
523 * substituted with zeroes. An exception to this is when the file
524 * has been opened in 'direct_io' mode, in which case the return
525 * value of the read system call will reflect the return value of
526 * this operation.
528 * fi->fh will contain the value set by the open method, or will
529 * be undefined if the open method didn't set any value.
531 * Valid replies:
532 * fuse_reply_buf
533 * fuse_reply_iov
534 * fuse_reply_data
535 * fuse_reply_err
537 * @param req request handle
538 * @param ino the inode number
539 * @param size number of bytes to read
540 * @param off offset to read from
541 * @param fi file information
543 void (*read)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
544 struct fuse_file_info *fi);
547 * Write data
549 * Write should return exactly the number of bytes requested
550 * except on error. An exception to this is when the file has
551 * been opened in 'direct_io' mode, in which case the return value
552 * of the write system call will reflect the return value of this
553 * operation.
555 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
556 * expected to reset the setuid and setgid bits.
558 * fi->fh will contain the value set by the open method, or will
559 * be undefined if the open method didn't set any value.
561 * Valid replies:
562 * fuse_reply_write
563 * fuse_reply_err
565 * @param req request handle
566 * @param ino the inode number
567 * @param buf data to write
568 * @param size number of bytes to write
569 * @param off offset to write to
570 * @param fi file information
572 void (*write)(fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size,
573 off_t off, struct fuse_file_info *fi);
576 * Flush method
578 * This is called on each close() of the opened file.
580 * Since file descriptors can be duplicated (dup, dup2, fork), for
581 * one open call there may be many flush calls.
583 * Filesystems shouldn't assume that flush will always be called
584 * after some writes, or that if will be called at all.
586 * fi->fh will contain the value set by the open method, or will
587 * be undefined if the open method didn't set any value.
589 * NOTE: the name of the method is misleading, since (unlike
590 * fsync) the filesystem is not forced to flush pending writes.
591 * One reason to flush data is if the filesystem wants to return
592 * write errors during close. However, such use is non-portable
593 * because POSIX does not require [close] to wait for delayed I/O to
594 * complete.
596 * If the filesystem supports file locking operations (setlk,
597 * getlk) it should remove all locks belonging to 'fi->owner'.
599 * If this request is answered with an error code of ENOSYS,
600 * this is treated as success and future calls to flush() will
601 * succeed automatically without being send to the filesystem
602 * process.
604 * Valid replies:
605 * fuse_reply_err
607 * @param req request handle
608 * @param ino the inode number
609 * @param fi file information
611 * [close]:
612 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
614 void (*flush)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
617 * Release an open file
619 * Release is called when there are no more references to an open
620 * file: all file descriptors are closed and all memory mappings
621 * are unmapped.
623 * For every open call there will be exactly one release call (unless
624 * the filesystem is force-unmounted).
626 * The filesystem may reply with an error, but error values are
627 * not returned to close() or munmap() which triggered the
628 * release.
630 * fi->fh will contain the value set by the open method, or will
631 * be undefined if the open method didn't set any value.
632 * fi->flags will contain the same flags as for open.
634 * Valid replies:
635 * fuse_reply_err
637 * @param req request handle
638 * @param ino the inode number
639 * @param fi file information
641 void (*release)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
644 * Synchronize file contents
646 * If the datasync parameter is non-zero, then only the user data
647 * should be flushed, not the meta data.
649 * If this request is answered with an error code of ENOSYS,
650 * this is treated as success and future calls to fsync() will
651 * succeed automatically without being send to the filesystem
652 * process.
654 * Valid replies:
655 * fuse_reply_err
657 * @param req request handle
658 * @param ino the inode number
659 * @param datasync flag indicating if only data should be flushed
660 * @param fi file information
662 void (*fsync)(fuse_req_t req, fuse_ino_t ino, int datasync,
663 struct fuse_file_info *fi);
666 * Open a directory
668 * Filesystem may store an arbitrary file handle (pointer, index,
669 * etc) in fi->fh, and use this in other all other directory
670 * stream operations (readdir, releasedir, fsyncdir).
672 * If this request is answered with an error code of ENOSYS and
673 * FUSE_CAP_NO_OPENDIR_SUPPORT is set in `fuse_conn_info.capable`,
674 * this is treated as success and future calls to opendir and
675 * releasedir will also succeed without being sent to the filesystem
676 * process. In addition, the kernel will cache readdir results
677 * as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR.
679 * Valid replies:
680 * fuse_reply_open
681 * fuse_reply_err
683 * @param req request handle
684 * @param ino the inode number
685 * @param fi file information
687 void (*opendir)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
690 * Read directory
692 * Send a buffer filled using fuse_add_direntry(), with size not
693 * exceeding the requested size. Send an empty buffer on end of
694 * stream.
696 * fi->fh will contain the value set by the opendir method, or
697 * will be undefined if the opendir method didn't set any value.
699 * Returning a directory entry from readdir() does not affect
700 * its lookup count.
702 * If off_t is non-zero, then it will correspond to one of the off_t
703 * values that was previously returned by readdir() for the same
704 * directory handle. In this case, readdir() should skip over entries
705 * coming before the position defined by the off_t value. If entries
706 * are added or removed while the directory handle is open, they filesystem
707 * may still include the entries that have been removed, and may not
708 * report the entries that have been created. However, addition or
709 * removal of entries must never cause readdir() to skip over unrelated
710 * entries or to report them more than once. This means
711 * that off_t can not be a simple index that enumerates the entries
712 * that have been returned but must contain sufficient information to
713 * uniquely determine the next directory entry to return even when the
714 * set of entries is changing.
716 * The function does not have to report the '.' and '..'
717 * entries, but is allowed to do so. Note that, if readdir does
718 * not return '.' or '..', they will not be implicitly returned,
719 * and this behavior is observable by the caller.
721 * Valid replies:
722 * fuse_reply_buf
723 * fuse_reply_data
724 * fuse_reply_err
726 * @param req request handle
727 * @param ino the inode number
728 * @param size maximum number of bytes to send
729 * @param off offset to continue reading the directory stream
730 * @param fi file information
732 void (*readdir)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
733 struct fuse_file_info *fi);
736 * Release an open directory
738 * For every opendir call there will be exactly one releasedir
739 * call (unless the filesystem is force-unmounted).
741 * fi->fh will contain the value set by the opendir method, or
742 * will be undefined if the opendir method didn't set any value.
744 * Valid replies:
745 * fuse_reply_err
747 * @param req request handle
748 * @param ino the inode number
749 * @param fi file information
751 void (*releasedir)(fuse_req_t req, fuse_ino_t ino,
752 struct fuse_file_info *fi);
755 * Synchronize directory contents
757 * If the datasync parameter is non-zero, then only the directory
758 * contents should be flushed, not the meta data.
760 * fi->fh will contain the value set by the opendir method, or
761 * will be undefined if the opendir method didn't set any value.
763 * If this request is answered with an error code of ENOSYS,
764 * this is treated as success and future calls to fsyncdir() will
765 * succeed automatically without being send to the filesystem
766 * process.
768 * Valid replies:
769 * fuse_reply_err
771 * @param req request handle
772 * @param ino the inode number
773 * @param datasync flag indicating if only data should be flushed
774 * @param fi file information
776 void (*fsyncdir)(fuse_req_t req, fuse_ino_t ino, int datasync,
777 struct fuse_file_info *fi);
780 * Get file system statistics
782 * Valid replies:
783 * fuse_reply_statfs
784 * fuse_reply_err
786 * @param req request handle
787 * @param ino the inode number, zero means "undefined"
789 void (*statfs)(fuse_req_t req, fuse_ino_t ino);
792 * Set an extended attribute
794 * If this request is answered with an error code of ENOSYS, this is
795 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
796 * future setxattr() requests will fail with EOPNOTSUPP without being
797 * send to the filesystem process.
799 * Valid replies:
800 * fuse_reply_err
802 void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
803 const char *value, size_t size, int flags);
806 * Get an extended attribute
808 * If size is zero, the size of the value should be sent with
809 * fuse_reply_xattr.
811 * If the size is non-zero, and the value fits in the buffer, the
812 * value should be sent with fuse_reply_buf.
814 * If the size is too small for the value, the ERANGE error should
815 * be sent.
817 * If this request is answered with an error code of ENOSYS, this is
818 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
819 * future getxattr() requests will fail with EOPNOTSUPP without being
820 * send to the filesystem process.
822 * Valid replies:
823 * fuse_reply_buf
824 * fuse_reply_data
825 * fuse_reply_xattr
826 * fuse_reply_err
828 * @param req request handle
829 * @param ino the inode number
830 * @param name of the extended attribute
831 * @param size maximum size of the value to send
833 void (*getxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
834 size_t size);
837 * List extended attribute names
839 * If size is zero, the total size of the attribute list should be
840 * sent with fuse_reply_xattr.
842 * If the size is non-zero, and the null character separated
843 * attribute list fits in the buffer, the list should be sent with
844 * fuse_reply_buf.
846 * If the size is too small for the list, the ERANGE error should
847 * be sent.
849 * If this request is answered with an error code of ENOSYS, this is
850 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
851 * future listxattr() requests will fail with EOPNOTSUPP without being
852 * send to the filesystem process.
854 * Valid replies:
855 * fuse_reply_buf
856 * fuse_reply_data
857 * fuse_reply_xattr
858 * fuse_reply_err
860 * @param req request handle
861 * @param ino the inode number
862 * @param size maximum size of the list to send
864 void (*listxattr)(fuse_req_t req, fuse_ino_t ino, size_t size);
867 * Remove an extended attribute
869 * If this request is answered with an error code of ENOSYS, this is
870 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
871 * future removexattr() requests will fail with EOPNOTSUPP without being
872 * send to the filesystem process.
874 * Valid replies:
875 * fuse_reply_err
877 * @param req request handle
878 * @param ino the inode number
879 * @param name of the extended attribute
881 void (*removexattr)(fuse_req_t req, fuse_ino_t ino, const char *name);
884 * Check file access permissions
886 * This will be called for the access() and chdir() system
887 * calls. If the 'default_permissions' mount option is given,
888 * this method is not called.
890 * This method is not called under Linux kernel versions 2.4.x
892 * If this request is answered with an error code of ENOSYS, this is
893 * treated as a permanent success, i.e. this and all future access()
894 * requests will succeed without being send to the filesystem process.
896 * Valid replies:
897 * fuse_reply_err
899 * @param req request handle
900 * @param ino the inode number
901 * @param mask requested access mode
903 void (*access)(fuse_req_t req, fuse_ino_t ino, int mask);
906 * Create and open a file
908 * If the file does not exist, first create it with the specified
909 * mode, and then open it.
911 * See the description of the open handler for more
912 * information.
914 * If this method is not implemented or under Linux kernel
915 * versions earlier than 2.6.15, the mknod() and open() methods
916 * will be called instead.
918 * If this request is answered with an error code of ENOSYS, the handler
919 * is treated as not implemented (i.e., for this and future requests the
920 * mknod() and open() handlers will be called instead).
922 * Valid replies:
923 * fuse_reply_create
924 * fuse_reply_err
926 * @param req request handle
927 * @param parent inode number of the parent directory
928 * @param name to create
929 * @param mode file type and mode with which to create the new file
930 * @param fi file information
932 void (*create)(fuse_req_t req, fuse_ino_t parent, const char *name,
933 mode_t mode, struct fuse_file_info *fi);
936 * Test for a POSIX file lock
938 * Valid replies:
939 * fuse_reply_lock
940 * fuse_reply_err
942 * @param req request handle
943 * @param ino the inode number
944 * @param fi file information
945 * @param lock the region/type to test
947 void (*getlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
948 struct flock *lock);
951 * Acquire, modify or release a POSIX file lock
953 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
954 * owner, but otherwise this is not always the case. For checking
955 * lock ownership, 'fi->owner' must be used. The l_pid field in
956 * 'struct flock' should only be used to fill in this field in
957 * getlk().
959 * Note: if the locking methods are not implemented, the kernel
960 * will still allow file locking to work locally. Hence these are
961 * only interesting for network filesystems and similar.
963 * Valid replies:
964 * fuse_reply_err
966 * @param req request handle
967 * @param ino the inode number
968 * @param fi file information
969 * @param lock the region/type to set
970 * @param sleep locking operation may sleep
972 void (*setlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
973 struct flock *lock, int sleep);
976 * Map block index within file to block index within device
978 * Note: This makes sense only for block device backed filesystems
979 * mounted with the 'blkdev' option
981 * If this request is answered with an error code of ENOSYS, this is
982 * treated as a permanent failure, i.e. all future bmap() requests will
983 * fail with the same error code without being send to the filesystem
984 * process.
986 * Valid replies:
987 * fuse_reply_bmap
988 * fuse_reply_err
990 * @param req request handle
991 * @param ino the inode number
992 * @param blocksize unit of block index
993 * @param idx block index within file
995 void (*bmap)(fuse_req_t req, fuse_ino_t ino, size_t blocksize,
996 uint64_t idx);
999 * Ioctl
1001 * Note: For unrestricted ioctls (not allowed for FUSE
1002 * servers), data in and out areas can be discovered by giving
1003 * iovs and setting FUSE_IOCTL_RETRY in *flags*. For
1004 * restricted ioctls, kernel prepares in/out data area
1005 * according to the information encoded in cmd.
1007 * Valid replies:
1008 * fuse_reply_ioctl_retry
1009 * fuse_reply_ioctl
1010 * fuse_reply_ioctl_iov
1011 * fuse_reply_err
1013 * @param req request handle
1014 * @param ino the inode number
1015 * @param cmd ioctl command
1016 * @param arg ioctl argument
1017 * @param fi file information
1018 * @param flags for FUSE_IOCTL_* flags
1019 * @param in_buf data fetched from the caller
1020 * @param in_bufsz number of fetched bytes
1021 * @param out_bufsz maximum size of output data
1023 * Note : the unsigned long request submitted by the application
1024 * is truncated to 32 bits.
1026 void (*ioctl)(fuse_req_t req, fuse_ino_t ino, unsigned int cmd, void *arg,
1027 struct fuse_file_info *fi, unsigned flags, const void *in_buf,
1028 size_t in_bufsz, size_t out_bufsz);
1031 * Poll for IO readiness
1033 * Note: If ph is non-NULL, the client should notify
1034 * when IO readiness events occur by calling
1035 * fuse_lowlevel_notify_poll() with the specified ph.
1037 * Regardless of the number of times poll with a non-NULL ph
1038 * is received, single notification is enough to clear all.
1039 * Notifying more times incurs overhead but doesn't harm
1040 * correctness.
1042 * The callee is responsible for destroying ph with
1043 * fuse_pollhandle_destroy() when no longer in use.
1045 * If this request is answered with an error code of ENOSYS, this is
1046 * treated as success (with a kernel-defined default poll-mask) and
1047 * future calls to pull() will succeed the same way without being send
1048 * to the filesystem process.
1050 * Valid replies:
1051 * fuse_reply_poll
1052 * fuse_reply_err
1054 * @param req request handle
1055 * @param ino the inode number
1056 * @param fi file information
1057 * @param ph poll handle to be used for notification
1059 void (*poll)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1060 struct fuse_pollhandle *ph);
1063 * Write data made available in a buffer
1065 * This is a more generic version of the ->write() method. If
1066 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
1067 * kernel supports splicing from the fuse device, then the
1068 * data will be made available in pipe for supporting zero
1069 * copy data transfer.
1071 * buf->count is guaranteed to be one (and thus buf->idx is
1072 * always zero). The write_buf handler must ensure that
1073 * bufv->off is correctly updated (reflecting the number of
1074 * bytes read from bufv->buf[0]).
1076 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
1077 * expected to reset the setuid and setgid bits.
1079 * Valid replies:
1080 * fuse_reply_write
1081 * fuse_reply_err
1083 * @param req request handle
1084 * @param ino the inode number
1085 * @param bufv buffer containing the data
1086 * @param off offset to write to
1087 * @param fi file information
1089 void (*write_buf)(fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv,
1090 off_t off, struct fuse_file_info *fi);
1093 * Forget about multiple inodes
1095 * See description of the forget function for more
1096 * information.
1098 * Valid replies:
1099 * fuse_reply_none
1101 * @param req request handle
1103 void (*forget_multi)(fuse_req_t req, size_t count,
1104 struct fuse_forget_data *forgets);
1107 * Acquire, modify or release a BSD file lock
1109 * Note: if the locking methods are not implemented, the kernel
1110 * will still allow file locking to work locally. Hence these are
1111 * only interesting for network filesystems and similar.
1113 * Valid replies:
1114 * fuse_reply_err
1116 * @param req request handle
1117 * @param ino the inode number
1118 * @param fi file information
1119 * @param op the locking operation, see flock(2)
1121 void (*flock)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1122 int op);
1125 * Allocate requested space. If this function returns success then
1126 * subsequent writes to the specified range shall not fail due to the lack
1127 * of free space on the file system storage media.
1129 * If this request is answered with an error code of ENOSYS, this is
1130 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1131 * future fallocate() requests will fail with EOPNOTSUPP without being
1132 * send to the filesystem process.
1134 * Valid replies:
1135 * fuse_reply_err
1137 * @param req request handle
1138 * @param ino the inode number
1139 * @param offset starting point for allocated region
1140 * @param length size of allocated region
1141 * @param mode determines the operation to be performed on the given range,
1142 * see fallocate(2)
1144 void (*fallocate)(fuse_req_t req, fuse_ino_t ino, int mode, off_t offset,
1145 off_t length, struct fuse_file_info *fi);
1148 * Read directory with attributes
1150 * Send a buffer filled using fuse_add_direntry_plus(), with size not
1151 * exceeding the requested size. Send an empty buffer on end of
1152 * stream.
1154 * fi->fh will contain the value set by the opendir method, or
1155 * will be undefined if the opendir method didn't set any value.
1157 * In contrast to readdir() (which does not affect the lookup counts),
1158 * the lookup count of every entry returned by readdirplus(), except "."
1159 * and "..", is incremented by one.
1161 * Valid replies:
1162 * fuse_reply_buf
1163 * fuse_reply_data
1164 * fuse_reply_err
1166 * @param req request handle
1167 * @param ino the inode number
1168 * @param size maximum number of bytes to send
1169 * @param off offset to continue reading the directory stream
1170 * @param fi file information
1172 void (*readdirplus)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1173 struct fuse_file_info *fi);
1176 * Copy a range of data from one file to another
1178 * Performs an optimized copy between two file descriptors without the
1179 * additional cost of transferring data through the FUSE kernel module
1180 * to user space (glibc) and then back into the FUSE filesystem again.
1182 * In case this method is not implemented, glibc falls back to reading
1183 * data from the source and writing to the destination. Effectively
1184 * doing an inefficient copy of the data.
1186 * If this request is answered with an error code of ENOSYS, this is
1187 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1188 * future copy_file_range() requests will fail with EOPNOTSUPP without
1189 * being send to the filesystem process.
1191 * Valid replies:
1192 * fuse_reply_write
1193 * fuse_reply_err
1195 * @param req request handle
1196 * @param ino_in the inode number or the source file
1197 * @param off_in starting point from were the data should be read
1198 * @param fi_in file information of the source file
1199 * @param ino_out the inode number or the destination file
1200 * @param off_out starting point where the data should be written
1201 * @param fi_out file information of the destination file
1202 * @param len maximum size of the data to copy
1203 * @param flags passed along with the copy_file_range() syscall
1205 void (*copy_file_range)(fuse_req_t req, fuse_ino_t ino_in, off_t off_in,
1206 struct fuse_file_info *fi_in, fuse_ino_t ino_out,
1207 off_t off_out, struct fuse_file_info *fi_out,
1208 size_t len, int flags);
1211 * Find next data or hole after the specified offset
1213 * If this request is answered with an error code of ENOSYS, this is
1214 * treated as a permanent failure, i.e. all future lseek() requests will
1215 * fail with the same error code without being send to the filesystem
1216 * process.
1218 * Valid replies:
1219 * fuse_reply_lseek
1220 * fuse_reply_err
1222 * @param req request handle
1223 * @param ino the inode number
1224 * @param off offset to start search from
1225 * @param whence either SEEK_DATA or SEEK_HOLE
1226 * @param fi file information
1228 void (*lseek)(fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1229 struct fuse_file_info *fi);
1233 * Reply with an error code or success.
1235 * Possible requests:
1236 * all except forget
1238 * Whereever possible, error codes should be chosen from the list of
1239 * documented error conditions in the corresponding system calls
1240 * manpage.
1242 * An error code of ENOSYS is sometimes treated specially. This is
1243 * indicated in the documentation of the affected handler functions.
1245 * The following requests may be answered with a zero error code:
1246 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1247 * removexattr, setlk.
1249 * @param req request handle
1250 * @param err the positive error value, or zero for success
1251 * @return zero for success, -errno for failure to send reply
1253 int fuse_reply_err(fuse_req_t req, int err);
1256 * Don't send reply
1258 * Possible requests:
1259 * forget
1260 * forget_multi
1261 * retrieve_reply
1263 * @param req request handle
1265 void fuse_reply_none(fuse_req_t req);
1268 * Reply with a directory entry
1270 * Possible requests:
1271 * lookup, mknod, mkdir, symlink, link
1273 * Side effects:
1274 * increments the lookup count on success
1276 * @param req request handle
1277 * @param e the entry parameters
1278 * @return zero for success, -errno for failure to send reply
1280 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1283 * Reply with a directory entry and open parameters
1285 * currently the following members of 'fi' are used:
1286 * fh, direct_io, keep_cache
1288 * Possible requests:
1289 * create
1291 * Side effects:
1292 * increments the lookup count on success
1294 * @param req request handle
1295 * @param e the entry parameters
1296 * @param fi file information
1297 * @return zero for success, -errno for failure to send reply
1299 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1300 const struct fuse_file_info *fi);
1303 * Reply with attributes
1305 * Possible requests:
1306 * getattr, setattr
1308 * @param req request handle
1309 * @param attr the attributes
1310 * @param attr_timeout validity timeout (in seconds) for the attributes
1311 * @return zero for success, -errno for failure to send reply
1313 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1314 double attr_timeout);
1317 * Reply with the contents of a symbolic link
1319 * Possible requests:
1320 * readlink
1322 * @param req request handle
1323 * @param link symbolic link contents
1324 * @return zero for success, -errno for failure to send reply
1326 int fuse_reply_readlink(fuse_req_t req, const char *link);
1329 * Reply with open parameters
1331 * currently the following members of 'fi' are used:
1332 * fh, direct_io, keep_cache
1334 * Possible requests:
1335 * open, opendir
1337 * @param req request handle
1338 * @param fi file information
1339 * @return zero for success, -errno for failure to send reply
1341 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1344 * Reply with number of bytes written
1346 * Possible requests:
1347 * write
1349 * @param req request handle
1350 * @param count the number of bytes written
1351 * @return zero for success, -errno for failure to send reply
1353 int fuse_reply_write(fuse_req_t req, size_t count);
1356 * Reply with data
1358 * Possible requests:
1359 * read, readdir, getxattr, listxattr
1361 * @param req request handle
1362 * @param buf buffer containing data
1363 * @param size the size of data in bytes
1364 * @return zero for success, -errno for failure to send reply
1366 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1369 * Reply with data copied/moved from buffer(s)
1371 * Possible requests:
1372 * read, readdir, getxattr, listxattr
1374 * Side effects:
1375 * when used to return data from a readdirplus() (but not readdir())
1376 * call, increments the lookup count of each returned entry by one
1377 * on success.
1379 * @param req request handle
1380 * @param bufv buffer vector
1381 * @return zero for success, -errno for failure to send reply
1383 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv);
1386 * Reply with data vector
1388 * Possible requests:
1389 * read, readdir, getxattr, listxattr
1391 * @param req request handle
1392 * @param iov the vector containing the data
1393 * @param count the size of vector
1394 * @return zero for success, -errno for failure to send reply
1396 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1399 * Reply with filesystem statistics
1401 * Possible requests:
1402 * statfs
1404 * @param req request handle
1405 * @param stbuf filesystem statistics
1406 * @return zero for success, -errno for failure to send reply
1408 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1411 * Reply with needed buffer size
1413 * Possible requests:
1414 * getxattr, listxattr
1416 * @param req request handle
1417 * @param count the buffer size needed in bytes
1418 * @return zero for success, -errno for failure to send reply
1420 int fuse_reply_xattr(fuse_req_t req, size_t count);
1423 * Reply with file lock information
1425 * Possible requests:
1426 * getlk
1428 * @param req request handle
1429 * @param lock the lock information
1430 * @return zero for success, -errno for failure to send reply
1432 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1435 * Reply with block index
1437 * Possible requests:
1438 * bmap
1440 * @param req request handle
1441 * @param idx block index within device
1442 * @return zero for success, -errno for failure to send reply
1444 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1447 * Filling a buffer in readdir
1451 * Add a directory entry to the buffer
1453 * Buffer needs to be large enough to hold the entry. If it's not,
1454 * then the entry is not filled in but the size of the entry is still
1455 * returned. The caller can check this by comparing the bufsize
1456 * parameter with the returned entry size. If the entry size is
1457 * larger than the buffer size, the operation failed.
1459 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1460 * st_mode field are used. The other fields are ignored.
1462 * *off* should be any non-zero value that the filesystem can use to
1463 * identify the current point in the directory stream. It does not
1464 * need to be the actual physical position. A value of zero is
1465 * reserved to mean "from the beginning", and should therefore never
1466 * be used (the first call to fuse_add_direntry should be passed the
1467 * offset of the second directory entry).
1469 * @param req request handle
1470 * @param buf the point where the new entry will be added to the buffer
1471 * @param bufsize remaining size of the buffer
1472 * @param name the name of the entry
1473 * @param stbuf the file attributes
1474 * @param off the offset of the next entry
1475 * @return the space needed for the entry
1477 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1478 const char *name, const struct stat *stbuf, off_t off);
1481 * Add a directory entry to the buffer with the attributes
1483 * See documentation of `fuse_add_direntry()` for more details.
1485 * @param req request handle
1486 * @param buf the point where the new entry will be added to the buffer
1487 * @param bufsize remaining size of the buffer
1488 * @param name the name of the entry
1489 * @param e the directory entry
1490 * @param off the offset of the next entry
1491 * @return the space needed for the entry
1493 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1494 const char *name,
1495 const struct fuse_entry_param *e, off_t off);
1498 * Reply to ask for data fetch and output buffer preparation. ioctl
1499 * will be retried with the specified input data fetched and output
1500 * buffer prepared.
1502 * Possible requests:
1503 * ioctl
1505 * @param req request handle
1506 * @param in_iov iovec specifying data to fetch from the caller
1507 * @param in_count number of entries in in_iov
1508 * @param out_iov iovec specifying addresses to write output to
1509 * @param out_count number of entries in out_iov
1510 * @return zero for success, -errno for failure to send reply
1512 int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
1513 size_t in_count, const struct iovec *out_iov,
1514 size_t out_count);
1517 * Reply to finish ioctl
1519 * Possible requests:
1520 * ioctl
1522 * @param req request handle
1523 * @param result result to be passed to the caller
1524 * @param buf buffer containing output data
1525 * @param size length of output data
1527 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1530 * Reply to finish ioctl with iov buffer
1532 * Possible requests:
1533 * ioctl
1535 * @param req request handle
1536 * @param result result to be passed to the caller
1537 * @param iov the vector containing the data
1538 * @param count the size of vector
1540 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1541 int count);
1544 * Reply with poll result event mask
1546 * @param req request handle
1547 * @param revents poll result event mask
1549 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1552 * Reply with offset
1554 * Possible requests:
1555 * lseek
1557 * @param req request handle
1558 * @param off offset of next data or hole
1559 * @return zero for success, -errno for failure to send reply
1561 int fuse_reply_lseek(fuse_req_t req, off_t off);
1564 * Notification
1568 * Notify IO readiness event
1570 * For more information, please read comment for poll operation.
1572 * @param ph poll handle to notify IO readiness event for
1574 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1577 * Notify to invalidate cache for an inode.
1579 * Added in FUSE protocol version 7.12. If the kernel does not support
1580 * this (or a newer) version, the function will return -ENOSYS and do
1581 * nothing.
1583 * If the filesystem has writeback caching enabled, invalidating an
1584 * inode will first trigger a writeback of all dirty pages. The call
1585 * will block until all writeback requests have completed and the
1586 * inode has been invalidated. It will, however, not wait for
1587 * completion of pending writeback requests that have been issued
1588 * before.
1590 * If there are no dirty pages, this function will never block.
1592 * @param se the session object
1593 * @param ino the inode number
1594 * @param off the offset in the inode where to start invalidating
1595 * or negative to invalidate attributes only
1596 * @param len the amount of cache to invalidate or 0 for all
1597 * @return zero for success, -errno for failure
1599 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1600 off_t off, off_t len);
1603 * Notify to invalidate parent attributes and the dentry matching
1604 * parent/name
1606 * To avoid a deadlock this function must not be called in the
1607 * execution path of a related filesytem operation or within any code
1608 * that could hold a lock that could be needed to execute such an
1609 * operation. As of kernel 4.18, a "related operation" is a lookup(),
1610 * symlink(), mknod(), mkdir(), unlink(), rename(), link() or create()
1611 * request for the parent, and a setattr(), unlink(), rmdir(),
1612 * rename(), setxattr(), removexattr(), readdir() or readdirplus()
1613 * request for the inode itself.
1615 * When called correctly, this function will never block.
1617 * Added in FUSE protocol version 7.12. If the kernel does not support
1618 * this (or a newer) version, the function will return -ENOSYS and do
1619 * nothing.
1621 * @param se the session object
1622 * @param parent inode number
1623 * @param name file name
1624 * @param namelen strlen() of file name
1625 * @return zero for success, -errno for failure
1627 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1628 const char *name, size_t namelen);
1631 * This function behaves like fuse_lowlevel_notify_inval_entry() with
1632 * the following additional effect (at least as of Linux kernel 4.8):
1634 * If the provided *child* inode matches the inode that is currently
1635 * associated with the cached dentry, and if there are any inotify
1636 * watches registered for the dentry, then the watchers are informed
1637 * that the dentry has been deleted.
1639 * To avoid a deadlock this function must not be called while
1640 * executing a related filesytem operation or while holding a lock
1641 * that could be needed to execute such an operation (see the
1642 * description of fuse_lowlevel_notify_inval_entry() for more
1643 * details).
1645 * When called correctly, this function will never block.
1647 * Added in FUSE protocol version 7.18. If the kernel does not support
1648 * this (or a newer) version, the function will return -ENOSYS and do
1649 * nothing.
1651 * @param se the session object
1652 * @param parent inode number
1653 * @param child inode number
1654 * @param name file name
1655 * @param namelen strlen() of file name
1656 * @return zero for success, -errno for failure
1658 int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent,
1659 fuse_ino_t child, const char *name,
1660 size_t namelen);
1663 * Store data to the kernel buffers
1665 * Synchronously store data in the kernel buffers belonging to the
1666 * given inode. The stored data is marked up-to-date (no read will be
1667 * performed against it, unless it's invalidated or evicted from the
1668 * cache).
1670 * If the stored data overflows the current file size, then the size
1671 * is extended, similarly to a write(2) on the filesystem.
1673 * If this function returns an error, then the store wasn't fully
1674 * completed, but it may have been partially completed.
1676 * Added in FUSE protocol version 7.15. If the kernel does not support
1677 * this (or a newer) version, the function will return -ENOSYS and do
1678 * nothing.
1680 * @param se the session object
1681 * @param ino the inode number
1682 * @param offset the starting offset into the file to store to
1683 * @param bufv buffer vector
1684 * @return zero for success, -errno for failure
1686 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1687 off_t offset, struct fuse_bufvec *bufv);
1690 * Utility functions
1694 * Get the userdata from the request
1696 * @param req request handle
1697 * @return the user data passed to fuse_session_new()
1699 void *fuse_req_userdata(fuse_req_t req);
1702 * Get the context from the request
1704 * The pointer returned by this function will only be valid for the
1705 * request's lifetime
1707 * @param req request handle
1708 * @return the context structure
1710 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1713 * Callback function for an interrupt
1715 * @param req interrupted request
1716 * @param data user data
1718 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1721 * Register/unregister callback for an interrupt
1723 * If an interrupt has already happened, then the callback function is
1724 * called from within this function, hence it's not possible for
1725 * interrupts to be lost.
1727 * @param req request handle
1728 * @param func the callback function or NULL for unregister
1729 * @param data user data passed to the callback function
1731 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1732 void *data);
1735 * Check if a request has already been interrupted
1737 * @param req request handle
1738 * @return 1 if the request has been interrupted, 0 otherwise
1740 int fuse_req_interrupted(fuse_req_t req);
1743 * Check if the session is connected via virtio
1745 * @param se session object
1746 * @return 1 if the session is a virtio session
1748 int fuse_lowlevel_is_virtio(struct fuse_session *se);
1751 * Inquiry functions
1755 * Print low-level version information to stdout.
1757 void fuse_lowlevel_version(void);
1760 * Print available low-level options to stdout. This is not an
1761 * exhaustive list, but includes only those options that may be of
1762 * interest to an end-user of a file system.
1764 void fuse_lowlevel_help(void);
1767 * Print available options for `fuse_parse_cmdline()`.
1769 void fuse_cmdline_help(void);
1772 * Filesystem setup & teardown
1775 struct fuse_cmdline_opts {
1776 int foreground;
1777 int debug;
1778 int nodefault_subtype;
1779 int show_version;
1780 int show_help;
1781 int print_capabilities;
1782 int syslog;
1783 int log_level;
1784 unsigned int max_idle_threads;
1785 unsigned long rlimit_nofile;
1789 * Utility function to parse common options for simple file systems
1790 * using the low-level API. A help text that describes the available
1791 * options can be printed with `fuse_cmdline_help`. A single
1792 * non-option argument is treated as the mountpoint. Multiple
1793 * non-option arguments will result in an error.
1795 * If neither -o subtype= or -o fsname= options are given, a new
1796 * subtype option will be added and set to the basename of the program
1797 * (the fsname will remain unset, and then defaults to "fuse").
1799 * Known options will be removed from *args*, unknown options will
1800 * remain.
1802 * @param args argument vector (input+output)
1803 * @param opts output argument for parsed options
1804 * @return 0 on success, -1 on failure
1806 int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts);
1809 * Create a low level session.
1811 * Returns a session structure suitable for passing to
1812 * fuse_session_mount() and fuse_session_loop().
1814 * This function accepts most file-system independent mount options
1815 * (like context, nodev, ro - see mount(8)), as well as the general
1816 * fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and
1817 * -o default_permissions, but not ``-o use_ino``). Instead of `-o
1818 * debug`, debugging may also enabled with `-d` or `--debug`.
1820 * If not all options are known, an error message is written to stderr
1821 * and the function returns NULL.
1823 * Option parsing skips argv[0], which is assumed to contain the
1824 * program name. To prevent accidentally passing an option in
1825 * argv[0], this element must always be present (even if no options
1826 * are specified). It may be set to the empty string ('\0') if no
1827 * reasonable value can be provided.
1829 * @param args argument vector
1830 * @param op the (low-level) filesystem operations
1831 * @param op_size sizeof(struct fuse_lowlevel_ops)
1832 * @param userdata user data
1834 * @return the fuse session on success, NULL on failure
1836 struct fuse_session *fuse_session_new(struct fuse_args *args,
1837 const struct fuse_lowlevel_ops *op,
1838 size_t op_size, void *userdata);
1841 * Mount a FUSE file system.
1843 * @param se session object
1845 * @return 0 on success, -1 on failure.
1847 int fuse_session_mount(struct fuse_session *se);
1850 * Enter a single threaded, blocking event loop.
1852 * When the event loop terminates because the connection to the FUSE
1853 * kernel module has been closed, this function returns zero. This
1854 * happens when the filesystem is unmounted regularly (by the
1855 * filesystem owner or root running the umount(8) or fusermount(1)
1856 * command), or if connection is explicitly severed by writing ``1``
1857 * to the``abort`` file in ``/sys/fs/fuse/connections/NNN``. The only
1858 * way to distinguish between these two conditions is to check if the
1859 * filesystem is still mounted after the session loop returns.
1861 * When some error occurs during request processing, the function
1862 * returns a negated errno(3) value.
1864 * If the loop has been terminated because of a signal handler
1865 * installed by fuse_set_signal_handlers(), this function returns the
1866 * (positive) signal value that triggered the exit.
1868 * @param se the session
1869 * @return 0, -errno, or a signal value
1871 int fuse_session_loop(struct fuse_session *se);
1874 * Flag a session as terminated.
1876 * This function is invoked by the POSIX signal handlers, when
1877 * registered using fuse_set_signal_handlers(). It will cause any
1878 * running event loops to terminate on the next opportunity.
1880 * @param se the session
1882 void fuse_session_exit(struct fuse_session *se);
1885 * Reset the terminated flag of a session
1887 * @param se the session
1889 void fuse_session_reset(struct fuse_session *se);
1892 * Query the terminated flag of a session
1894 * @param se the session
1895 * @return 1 if exited, 0 if not exited
1897 int fuse_session_exited(struct fuse_session *se);
1900 * Ensure that file system is unmounted.
1902 * In regular operation, the file system is typically unmounted by the
1903 * user calling umount(8) or fusermount(1), which then terminates the
1904 * FUSE session loop. However, the session loop may also terminate as
1905 * a result of an explicit call to fuse_session_exit() (e.g. by a
1906 * signal handler installed by fuse_set_signal_handler()). In this
1907 * case the filesystem remains mounted, but any attempt to access it
1908 * will block (while the filesystem process is still running) or give
1909 * an ESHUTDOWN error (after the filesystem process has terminated).
1911 * If the communication channel with the FUSE kernel module is still
1912 * open (i.e., if the session loop was terminated by an explicit call
1913 * to fuse_session_exit()), this function will close it and unmount
1914 * the filesystem. If the communication channel has been closed by the
1915 * kernel, this method will do (almost) nothing.
1917 * NOTE: The above semantics mean that if the connection to the kernel
1918 * is terminated via the ``/sys/fs/fuse/connections/NNN/abort`` file,
1919 * this method will *not* unmount the filesystem.
1921 * @param se the session
1923 void fuse_session_unmount(struct fuse_session *se);
1926 * Destroy a session
1928 * @param se the session
1930 void fuse_session_destroy(struct fuse_session *se);
1933 * Custom event loop support
1937 * Return file descriptor for communication with kernel.
1939 * The file selector can be used to integrate FUSE with a custom event
1940 * loop. Whenever data is available for reading on the provided fd,
1941 * the event loop should call `fuse_session_receive_buf` followed by
1942 * `fuse_session_process_buf` to process the request.
1944 * The returned file descriptor is valid until `fuse_session_unmount`
1945 * is called.
1947 * @param se the session
1948 * @return a file descriptor
1950 int fuse_session_fd(struct fuse_session *se);
1953 * Process a raw request supplied in a generic buffer
1955 * The fuse_buf may contain a memory buffer or a pipe file descriptor.
1957 * @param se the session
1958 * @param buf the fuse_buf containing the request
1960 void fuse_session_process_buf(struct fuse_session *se,
1961 const struct fuse_buf *buf);
1964 * Read a raw request from the kernel into the supplied buffer.
1966 * Depending on file system options, system capabilities, and request
1967 * size the request is either read into a memory buffer or spliced
1968 * into a temporary pipe.
1970 * @param se the session
1971 * @param buf the fuse_buf to store the request in
1972 * @return the actual size of the raw request, or -errno on error
1974 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
1976 #endif /* FUSE_LOWLEVEL_H_ */