meson: Display host binaries information altogether
[qemu/ar7.git] / tools / virtiofsd / fuse_lowlevel.h
blob0e10a14bc9d8a5d049ba6efad9420d02122e46ce
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 <sys/statvfs.h>
29 #include <sys/uio.h>
30 #include <utime.h>
33 * Miscellaneous definitions
36 /** The node ID of the root inode */
37 #define FUSE_ROOT_ID 1
39 /** Inode number type */
40 typedef uint64_t fuse_ino_t;
42 /** Request pointer type */
43 typedef struct fuse_req *fuse_req_t;
45 /**
46 * Session
48 * This provides hooks for processing requests, and exiting
50 struct fuse_session;
52 /** Directory entry parameters supplied to fuse_reply_entry() */
53 struct fuse_entry_param {
54 /**
55 * Unique inode number
57 * In lookup, zero means negative entry (from version 2.5)
58 * Returning ENOENT also means negative entry, but by setting zero
59 * ino the kernel may cache negative entries for entry_timeout
60 * seconds.
62 fuse_ino_t ino;
64 /**
65 * Generation number for this entry.
67 * If the file system will be exported over NFS, the
68 * ino/generation pairs need to be unique over the file
69 * system's lifetime (rather than just the mount time). So if
70 * the file system reuses an inode after it has been deleted,
71 * it must assign a new, previously unused generation number
72 * to the inode at the same time.
75 uint64_t generation;
77 /**
78 * Inode attributes.
80 * Even if attr_timeout == 0, attr must be correct. For example,
81 * for open(), FUSE uses attr.st_size from lookup() to determine
82 * how many bytes to request. If this value is not correct,
83 * incorrect data will be returned.
85 struct stat attr;
87 /**
88 * Validity timeout (in seconds) for inode attributes. If
89 * attributes only change as a result of requests that come
90 * through the kernel, this should be set to a very large
91 * value.
93 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.
101 double entry_timeout;
104 * Flags for fuse_attr.flags that do not fit into attr.
106 uint32_t attr_flags;
110 * Additional context associated with requests.
112 * Note that the reported client uid, gid and pid may be zero in some
113 * situations. For example, if the FUSE file system is running in a
114 * PID or user namespace but then accessed from outside the namespace,
115 * there is no valid uid/pid/gid that could be reported.
117 struct fuse_ctx {
118 /** User ID of the calling process */
119 uid_t uid;
121 /** Group ID of the calling process */
122 gid_t gid;
124 /** Thread ID of the calling process */
125 pid_t pid;
127 /** Umask of the calling process */
128 mode_t umask;
131 struct fuse_forget_data {
132 fuse_ino_t ino;
133 uint64_t nlookup;
136 /* 'to_set' flags in setattr */
137 #define FUSE_SET_ATTR_MODE (1 << 0)
138 #define FUSE_SET_ATTR_UID (1 << 1)
139 #define FUSE_SET_ATTR_GID (1 << 2)
140 #define FUSE_SET_ATTR_SIZE (1 << 3)
141 #define FUSE_SET_ATTR_ATIME (1 << 4)
142 #define FUSE_SET_ATTR_MTIME (1 << 5)
143 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
144 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
145 #define FUSE_SET_ATTR_CTIME (1 << 10)
148 * Request methods and replies
152 * Low level filesystem operations
154 * Most of the methods (with the exception of init and destroy)
155 * receive a request handle (fuse_req_t) as their first argument.
156 * This handle must be passed to one of the specified reply functions.
158 * This may be done inside the method invocation, or after the call
159 * has returned. The request handle is valid until one of the reply
160 * functions is called.
162 * Other pointer arguments (name, fuse_file_info, etc) are not valid
163 * after the call has returned, so if they are needed later, their
164 * contents have to be copied.
166 * In general, all methods are expected to perform any necessary
167 * permission checking. However, a filesystem may delegate this task
168 * to the kernel by passing the `default_permissions` mount option to
169 * `fuse_session_new()`. In this case, methods will only be called if
170 * the kernel's permission check has succeeded.
172 * The filesystem sometimes needs to handle a return value of -ENOENT
173 * from the reply function, which means, that the request was
174 * interrupted, and the reply discarded. For example if
175 * fuse_reply_open() return -ENOENT means, that the release method for
176 * this file will not be called.
178 struct fuse_lowlevel_ops {
180 * Initialize filesystem
182 * This function is called when libfuse establishes
183 * communication with the FUSE kernel module. The file system
184 * should use this module to inspect and/or modify the
185 * connection parameters provided in the `conn` structure.
187 * Note that some parameters may be overwritten by options
188 * passed to fuse_session_new() which take precedence over the
189 * values set in this handler.
191 * There's no reply to this function
193 * @param userdata the user data passed to fuse_session_new()
195 void (*init)(void *userdata, struct fuse_conn_info *conn);
198 * Clean up filesystem.
200 * Called on filesystem exit. When this method is called, the
201 * connection to the kernel may be gone already, so that eg. calls
202 * to fuse_lowlevel_notify_* will fail.
204 * There's no reply to this function
206 * @param userdata the user data passed to fuse_session_new()
208 void (*destroy)(void *userdata);
211 * Look up a directory entry by name and get its attributes.
213 * Valid replies:
214 * fuse_reply_entry
215 * fuse_reply_err
217 * @param req request handle
218 * @param parent inode number of the parent directory
219 * @param name the name to look up
221 void (*lookup)(fuse_req_t req, fuse_ino_t parent, const char *name);
224 * Forget about an inode
226 * This function is called when the kernel removes an inode
227 * from its internal caches.
229 * The inode's lookup count increases by one for every call to
230 * fuse_reply_entry and fuse_reply_create. The nlookup parameter
231 * indicates by how much the lookup count should be decreased.
233 * Inodes with a non-zero lookup count may receive request from
234 * the kernel even after calls to unlink, rmdir or (when
235 * overwriting an existing file) rename. Filesystems must handle
236 * such requests properly and it is recommended to defer removal
237 * of the inode until the lookup count reaches zero. Calls to
238 * unlink, rmdir or rename will be followed closely by forget
239 * unless the file or directory is open, in which case the
240 * kernel issues forget only after the release or releasedir
241 * calls.
243 * Note that if a file system will be exported over NFS the
244 * inodes lifetime must extend even beyond forget. See the
245 * generation field in struct fuse_entry_param above.
247 * On unmount the lookup count for all inodes implicitly drops
248 * to zero. It is not guaranteed that the file system will
249 * receive corresponding forget messages for the affected
250 * inodes.
252 * Valid replies:
253 * fuse_reply_none
255 * @param req request handle
256 * @param ino the inode number
257 * @param nlookup the number of lookups to forget
259 void (*forget)(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
262 * Get file attributes.
264 * If writeback caching is enabled, the kernel may have a
265 * better idea of a file's length than the FUSE file system
266 * (eg if there has been a write that extended the file size,
267 * but that has not yet been passed to the filesystem.n
269 * In this case, the st_size value provided by the file system
270 * will be ignored.
272 * Valid replies:
273 * fuse_reply_attr
274 * fuse_reply_err
276 * @param req request handle
277 * @param ino the inode number
278 * @param fi for future use, currently always NULL
280 void (*getattr)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
283 * Set file attributes
285 * In the 'attr' argument only members indicated by the 'to_set'
286 * bitmask contain valid values. Other members contain undefined
287 * values.
289 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
290 * expected to reset the setuid and setgid bits if the file
291 * size or owner is being changed.
293 * If the setattr was invoked from the ftruncate() system call
294 * under Linux kernel versions 2.6.15 or later, the fi->fh will
295 * contain the value set by the open method or will be undefined
296 * if the open method didn't set any value. Otherwise (not
297 * ftruncate call, or kernel version earlier than 2.6.15) the fi
298 * parameter will be NULL.
300 * Valid replies:
301 * fuse_reply_attr
302 * fuse_reply_err
304 * @param req request handle
305 * @param ino the inode number
306 * @param attr the attributes
307 * @param to_set bit mask of attributes which should be set
308 * @param fi file information, or NULL
310 void (*setattr)(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
311 int to_set, struct fuse_file_info *fi);
314 * Read symbolic link
316 * Valid replies:
317 * fuse_reply_readlink
318 * fuse_reply_err
320 * @param req request handle
321 * @param ino the inode number
323 void (*readlink)(fuse_req_t req, fuse_ino_t ino);
326 * Create file node
328 * Create a regular file, character device, block device, fifo or
329 * socket node.
331 * Valid replies:
332 * fuse_reply_entry
333 * fuse_reply_err
335 * @param req request handle
336 * @param parent inode number of the parent directory
337 * @param name to create
338 * @param mode file type and mode with which to create the new file
339 * @param rdev the device number (only valid if created file is a device)
341 void (*mknod)(fuse_req_t req, fuse_ino_t parent, const char *name,
342 mode_t mode, dev_t rdev);
345 * Create a directory
347 * Valid replies:
348 * fuse_reply_entry
349 * fuse_reply_err
351 * @param req request handle
352 * @param parent inode number of the parent directory
353 * @param name to create
354 * @param mode with which to create the new file
356 void (*mkdir)(fuse_req_t req, fuse_ino_t parent, const char *name,
357 mode_t mode);
360 * Remove a file
362 * If the file's inode's lookup count is non-zero, the file
363 * system is expected to postpone any removal of the inode
364 * until the lookup count reaches zero (see description of the
365 * forget function).
367 * Valid replies:
368 * fuse_reply_err
370 * @param req request handle
371 * @param parent inode number of the parent directory
372 * @param name to remove
374 void (*unlink)(fuse_req_t req, fuse_ino_t parent, const char *name);
377 * Remove a directory
379 * If the directory's inode's lookup count is non-zero, the
380 * file system is expected to postpone any removal of the
381 * inode until the lookup count reaches zero (see description
382 * of the forget function).
384 * Valid replies:
385 * fuse_reply_err
387 * @param req request handle
388 * @param parent inode number of the parent directory
389 * @param name to remove
391 void (*rmdir)(fuse_req_t req, fuse_ino_t parent, const char *name);
394 * Create a symbolic link
396 * Valid replies:
397 * fuse_reply_entry
398 * fuse_reply_err
400 * @param req request handle
401 * @param link the contents of the symbolic link
402 * @param parent inode number of the parent directory
403 * @param name to create
405 void (*symlink)(fuse_req_t req, const char *link, fuse_ino_t parent,
406 const char *name);
409 * Rename a file
411 * If the target exists it should be atomically replaced. If
412 * the target's inode's lookup count is non-zero, the file
413 * system is expected to postpone any removal of the inode
414 * until the lookup count reaches zero (see description of the
415 * forget function).
417 * If this request is answered with an error code of ENOSYS, this is
418 * treated as a permanent failure with error code EINVAL, i.e. all
419 * future bmap requests will fail with EINVAL without being
420 * send to the filesystem process.
422 * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
423 * RENAME_NOREPLACE is specified, the filesystem must not
424 * overwrite *newname* if it exists and return an error
425 * instead. If `RENAME_EXCHANGE` is specified, the filesystem
426 * must atomically exchange the two files, i.e. both must
427 * exist and neither may be deleted.
429 * Valid replies:
430 * fuse_reply_err
432 * @param req request handle
433 * @param parent inode number of the old parent directory
434 * @param name old name
435 * @param newparent inode number of the new parent directory
436 * @param newname new name
438 void (*rename)(fuse_req_t req, fuse_ino_t parent, const char *name,
439 fuse_ino_t newparent, const char *newname,
440 unsigned int flags);
443 * Create a hard link
445 * Valid replies:
446 * fuse_reply_entry
447 * fuse_reply_err
449 * @param req request handle
450 * @param ino the old inode number
451 * @param newparent inode number of the new parent directory
452 * @param newname new name to create
454 void (*link)(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
455 const char *newname);
458 * Open a file
460 * Open flags are available in fi->flags. The following rules
461 * apply.
463 * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
464 * filtered out / handled by the kernel.
466 * - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
467 * by the filesystem to check if the operation is
468 * permitted. If the ``-o default_permissions`` mount
469 * option is given, this check is already done by the
470 * kernel before calling open() and may thus be omitted by
471 * the filesystem.
473 * - When writeback caching is enabled, the kernel may send
474 * read requests even for files opened with O_WRONLY. The
475 * filesystem should be prepared to handle this.
477 * - When writeback caching is disabled, the filesystem is
478 * expected to properly handle the O_APPEND flag and ensure
479 * that each write is appending to the end of the file.
481 * - When writeback caching is enabled, the kernel will
482 * handle O_APPEND. However, unless all changes to the file
483 * come through the kernel this will not work reliably. The
484 * filesystem should thus either ignore the O_APPEND flag
485 * (and let the kernel handle it), or return an error
486 * (indicating that reliably O_APPEND is not available).
488 * Filesystem may store an arbitrary file handle (pointer,
489 * index, etc) in fi->fh, and use this in other all other file
490 * operations (read, write, flush, release, fsync).
492 * Filesystem may also implement stateless file I/O and not store
493 * anything in fi->fh.
495 * There are also some flags (direct_io, keep_cache) which the
496 * filesystem may set in fi, to change the way the file is opened.
497 * See fuse_file_info structure in <fuse_common.h> for more details.
499 * If this request is answered with an error code of ENOSYS
500 * and FUSE_CAP_NO_OPEN_SUPPORT is set in
501 * `fuse_conn_info.capable`, this is treated as success and
502 * future calls to open and release will also succeed without being
503 * sent to the filesystem process.
505 * Valid replies:
506 * fuse_reply_open
507 * fuse_reply_err
509 * @param req request handle
510 * @param ino the inode number
511 * @param fi file information
513 void (*open)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
516 * Read data
518 * Read should send exactly the number of bytes requested except
519 * on EOF or error, otherwise the rest of the data will be
520 * substituted with zeroes. An exception to this is when the file
521 * has been opened in 'direct_io' mode, in which case the return
522 * value of the read system call will reflect the return value of
523 * this operation.
525 * fi->fh will contain the value set by the open method, or will
526 * be undefined if the open method didn't set any value.
528 * Valid replies:
529 * fuse_reply_buf
530 * fuse_reply_iov
531 * fuse_reply_data
532 * fuse_reply_err
534 * @param req request handle
535 * @param ino the inode number
536 * @param size number of bytes to read
537 * @param off offset to read from
538 * @param fi file information
540 void (*read)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
541 struct fuse_file_info *fi);
544 * Write data
546 * Write should return exactly the number of bytes requested
547 * except on error. An exception to this is when the file has
548 * been opened in 'direct_io' mode, in which case the return value
549 * of the write system call will reflect the return value of this
550 * operation.
552 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
553 * expected to reset the setuid and setgid bits.
555 * fi->fh will contain the value set by the open method, or will
556 * be undefined if the open method didn't set any value.
558 * Valid replies:
559 * fuse_reply_write
560 * fuse_reply_err
562 * @param req request handle
563 * @param ino the inode number
564 * @param buf data to write
565 * @param size number of bytes to write
566 * @param off offset to write to
567 * @param fi file information
569 void (*write)(fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size,
570 off_t off, struct fuse_file_info *fi);
573 * Flush method
575 * This is called on each close() of the opened file.
577 * Since file descriptors can be duplicated (dup, dup2, fork), for
578 * one open call there may be many flush calls.
580 * Filesystems shouldn't assume that flush will always be called
581 * after some writes, or that if will be called at all.
583 * fi->fh will contain the value set by the open method, or will
584 * be undefined if the open method didn't set any value.
586 * NOTE: the name of the method is misleading, since (unlike
587 * fsync) the filesystem is not forced to flush pending writes.
588 * One reason to flush data is if the filesystem wants to return
589 * write errors during close. However, such use is non-portable
590 * because POSIX does not require [close] to wait for delayed I/O to
591 * complete.
593 * If the filesystem supports file locking operations (setlk,
594 * getlk) it should remove all locks belonging to 'fi->owner'.
596 * If this request is answered with an error code of ENOSYS,
597 * this is treated as success and future calls to flush() will
598 * succeed automatically without being send to the filesystem
599 * process.
601 * Valid replies:
602 * fuse_reply_err
604 * @param req request handle
605 * @param ino the inode number
606 * @param fi file information
608 * [close]:
609 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
611 void (*flush)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
614 * Release an open file
616 * Release is called when there are no more references to an open
617 * file: all file descriptors are closed and all memory mappings
618 * are unmapped.
620 * For every open call there will be exactly one release call (unless
621 * the filesystem is force-unmounted).
623 * The filesystem may reply with an error, but error values are
624 * not returned to close() or munmap() which triggered the
625 * release.
627 * fi->fh will contain the value set by the open method, or will
628 * be undefined if the open method didn't set any value.
629 * fi->flags will contain the same flags as for open.
631 * Valid replies:
632 * fuse_reply_err
634 * @param req request handle
635 * @param ino the inode number
636 * @param fi file information
638 void (*release)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
641 * Synchronize file contents
643 * If the datasync parameter is non-zero, then only the user data
644 * should be flushed, not the meta data.
646 * If this request is answered with an error code of ENOSYS,
647 * this is treated as success and future calls to fsync() will
648 * succeed automatically without being send to the filesystem
649 * process.
651 * Valid replies:
652 * fuse_reply_err
654 * @param req request handle
655 * @param ino the inode number
656 * @param datasync flag indicating if only data should be flushed
657 * @param fi file information
659 void (*fsync)(fuse_req_t req, fuse_ino_t ino, int datasync,
660 struct fuse_file_info *fi);
663 * Open a directory
665 * Filesystem may store an arbitrary file handle (pointer, index,
666 * etc) in fi->fh, and use this in other all other directory
667 * stream operations (readdir, releasedir, fsyncdir).
669 * If this request is answered with an error code of ENOSYS and
670 * FUSE_CAP_NO_OPENDIR_SUPPORT is set in `fuse_conn_info.capable`,
671 * this is treated as success and future calls to opendir and
672 * releasedir will also succeed without being sent to the filesystem
673 * process. In addition, the kernel will cache readdir results
674 * as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR.
676 * Valid replies:
677 * fuse_reply_open
678 * fuse_reply_err
680 * @param req request handle
681 * @param ino the inode number
682 * @param fi file information
684 void (*opendir)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
687 * Read directory
689 * Send a buffer filled using fuse_add_direntry(), with size not
690 * exceeding the requested size. Send an empty buffer on end of
691 * stream.
693 * fi->fh will contain the value set by the opendir method, or
694 * will be undefined if the opendir method didn't set any value.
696 * Returning a directory entry from readdir() does not affect
697 * its lookup count.
699 * If off_t is non-zero, then it will correspond to one of the off_t
700 * values that was previously returned by readdir() for the same
701 * directory handle. In this case, readdir() should skip over entries
702 * coming before the position defined by the off_t value. If entries
703 * are added or removed while the directory handle is open, they filesystem
704 * may still include the entries that have been removed, and may not
705 * report the entries that have been created. However, addition or
706 * removal of entries must never cause readdir() to skip over unrelated
707 * entries or to report them more than once. This means
708 * that off_t can not be a simple index that enumerates the entries
709 * that have been returned but must contain sufficient information to
710 * uniquely determine the next directory entry to return even when the
711 * set of entries is changing.
713 * The function does not have to report the '.' and '..'
714 * entries, but is allowed to do so. Note that, if readdir does
715 * not return '.' or '..', they will not be implicitly returned,
716 * and this behavior is observable by the caller.
718 * Valid replies:
719 * fuse_reply_buf
720 * fuse_reply_data
721 * fuse_reply_err
723 * @param req request handle
724 * @param ino the inode number
725 * @param size maximum number of bytes to send
726 * @param off offset to continue reading the directory stream
727 * @param fi file information
729 void (*readdir)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
730 struct fuse_file_info *fi);
733 * Release an open directory
735 * For every opendir call there will be exactly one releasedir
736 * call (unless the filesystem is force-unmounted).
738 * fi->fh will contain the value set by the opendir method, or
739 * will be undefined if the opendir method didn't set any value.
741 * Valid replies:
742 * fuse_reply_err
744 * @param req request handle
745 * @param ino the inode number
746 * @param fi file information
748 void (*releasedir)(fuse_req_t req, fuse_ino_t ino,
749 struct fuse_file_info *fi);
752 * Synchronize directory contents
754 * If the datasync parameter is non-zero, then only the directory
755 * contents should be flushed, not the meta data.
757 * fi->fh will contain the value set by the opendir method, or
758 * will be undefined if the opendir method didn't set any value.
760 * If this request is answered with an error code of ENOSYS,
761 * this is treated as success and future calls to fsyncdir() will
762 * succeed automatically without being send to the filesystem
763 * process.
765 * Valid replies:
766 * fuse_reply_err
768 * @param req request handle
769 * @param ino the inode number
770 * @param datasync flag indicating if only data should be flushed
771 * @param fi file information
773 void (*fsyncdir)(fuse_req_t req, fuse_ino_t ino, int datasync,
774 struct fuse_file_info *fi);
777 * Get file system statistics
779 * Valid replies:
780 * fuse_reply_statfs
781 * fuse_reply_err
783 * @param req request handle
784 * @param ino the inode number, zero means "undefined"
786 void (*statfs)(fuse_req_t req, fuse_ino_t ino);
789 * Set an extended attribute
791 * If this request is answered with an error code of ENOSYS, this is
792 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
793 * future setxattr() requests will fail with EOPNOTSUPP without being
794 * send to the filesystem process.
796 * Valid replies:
797 * fuse_reply_err
799 void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
800 const char *value, size_t size, int flags);
803 * Get an extended attribute
805 * If size is zero, the size of the value should be sent with
806 * fuse_reply_xattr.
808 * If the size is non-zero, and the value fits in the buffer, the
809 * value should be sent with fuse_reply_buf.
811 * If the size is too small for the value, the ERANGE error should
812 * be sent.
814 * If this request is answered with an error code of ENOSYS, this is
815 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
816 * future getxattr() requests will fail with EOPNOTSUPP without being
817 * send to the filesystem process.
819 * Valid replies:
820 * fuse_reply_buf
821 * fuse_reply_data
822 * fuse_reply_xattr
823 * fuse_reply_err
825 * @param req request handle
826 * @param ino the inode number
827 * @param name of the extended attribute
828 * @param size maximum size of the value to send
830 void (*getxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
831 size_t size);
834 * List extended attribute names
836 * If size is zero, the total size of the attribute list should be
837 * sent with fuse_reply_xattr.
839 * If the size is non-zero, and the null character separated
840 * attribute list fits in the buffer, the list should be sent with
841 * fuse_reply_buf.
843 * If the size is too small for the list, the ERANGE error should
844 * be sent.
846 * If this request is answered with an error code of ENOSYS, this is
847 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
848 * future listxattr() requests will fail with EOPNOTSUPP without being
849 * send to the filesystem process.
851 * Valid replies:
852 * fuse_reply_buf
853 * fuse_reply_data
854 * fuse_reply_xattr
855 * fuse_reply_err
857 * @param req request handle
858 * @param ino the inode number
859 * @param size maximum size of the list to send
861 void (*listxattr)(fuse_req_t req, fuse_ino_t ino, size_t size);
864 * Remove an extended attribute
866 * If this request is answered with an error code of ENOSYS, this is
867 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
868 * future removexattr() requests will fail with EOPNOTSUPP without being
869 * send to the filesystem process.
871 * Valid replies:
872 * fuse_reply_err
874 * @param req request handle
875 * @param ino the inode number
876 * @param name of the extended attribute
878 void (*removexattr)(fuse_req_t req, fuse_ino_t ino, const char *name);
881 * Check file access permissions
883 * This will be called for the access() and chdir() system
884 * calls. If the 'default_permissions' mount option is given,
885 * this method is not called.
887 * This method is not called under Linux kernel versions 2.4.x
889 * If this request is answered with an error code of ENOSYS, this is
890 * treated as a permanent success, i.e. this and all future access()
891 * requests will succeed without being send to the filesystem process.
893 * Valid replies:
894 * fuse_reply_err
896 * @param req request handle
897 * @param ino the inode number
898 * @param mask requested access mode
900 void (*access)(fuse_req_t req, fuse_ino_t ino, int mask);
903 * Create and open a file
905 * If the file does not exist, first create it with the specified
906 * mode, and then open it.
908 * See the description of the open handler for more
909 * information.
911 * If this method is not implemented or under Linux kernel
912 * versions earlier than 2.6.15, the mknod() and open() methods
913 * will be called instead.
915 * If this request is answered with an error code of ENOSYS, the handler
916 * is treated as not implemented (i.e., for this and future requests the
917 * mknod() and open() handlers will be called instead).
919 * Valid replies:
920 * fuse_reply_create
921 * fuse_reply_err
923 * @param req request handle
924 * @param parent inode number of the parent directory
925 * @param name to create
926 * @param mode file type and mode with which to create the new file
927 * @param fi file information
929 void (*create)(fuse_req_t req, fuse_ino_t parent, const char *name,
930 mode_t mode, struct fuse_file_info *fi);
933 * Test for a POSIX file lock
935 * Valid replies:
936 * fuse_reply_lock
937 * fuse_reply_err
939 * @param req request handle
940 * @param ino the inode number
941 * @param fi file information
942 * @param lock the region/type to test
944 void (*getlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
945 struct flock *lock);
948 * Acquire, modify or release a POSIX file lock
950 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
951 * owner, but otherwise this is not always the case. For checking
952 * lock ownership, 'fi->owner' must be used. The l_pid field in
953 * 'struct flock' should only be used to fill in this field in
954 * getlk().
956 * Note: if the locking methods are not implemented, the kernel
957 * will still allow file locking to work locally. Hence these are
958 * only interesting for network filesystems and similar.
960 * Valid replies:
961 * fuse_reply_err
963 * @param req request handle
964 * @param ino the inode number
965 * @param fi file information
966 * @param lock the region/type to set
967 * @param sleep locking operation may sleep
969 void (*setlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
970 struct flock *lock, int sleep);
973 * Map block index within file to block index within device
975 * Note: This makes sense only for block device backed filesystems
976 * mounted with the 'blkdev' option
978 * If this request is answered with an error code of ENOSYS, this is
979 * treated as a permanent failure, i.e. all future bmap() requests will
980 * fail with the same error code without being send to the filesystem
981 * process.
983 * Valid replies:
984 * fuse_reply_bmap
985 * fuse_reply_err
987 * @param req request handle
988 * @param ino the inode number
989 * @param blocksize unit of block index
990 * @param idx block index within file
992 void (*bmap)(fuse_req_t req, fuse_ino_t ino, size_t blocksize,
993 uint64_t idx);
996 * Ioctl
998 * Note: For unrestricted ioctls (not allowed for FUSE
999 * servers), data in and out areas can be discovered by giving
1000 * iovs and setting FUSE_IOCTL_RETRY in *flags*. For
1001 * restricted ioctls, kernel prepares in/out data area
1002 * according to the information encoded in cmd.
1004 * Valid replies:
1005 * fuse_reply_ioctl_retry
1006 * fuse_reply_ioctl
1007 * fuse_reply_ioctl_iov
1008 * fuse_reply_err
1010 * @param req request handle
1011 * @param ino the inode number
1012 * @param cmd ioctl command
1013 * @param arg ioctl argument
1014 * @param fi file information
1015 * @param flags for FUSE_IOCTL_* flags
1016 * @param in_buf data fetched from the caller
1017 * @param in_bufsz number of fetched bytes
1018 * @param out_bufsz maximum size of output data
1020 * Note : the unsigned long request submitted by the application
1021 * is truncated to 32 bits.
1023 void (*ioctl)(fuse_req_t req, fuse_ino_t ino, unsigned int cmd, void *arg,
1024 struct fuse_file_info *fi, unsigned flags, const void *in_buf,
1025 size_t in_bufsz, size_t out_bufsz);
1028 * Poll for IO readiness
1030 * Note: If ph is non-NULL, the client should notify
1031 * when IO readiness events occur by calling
1032 * fuse_lowlevel_notify_poll() with the specified ph.
1034 * Regardless of the number of times poll with a non-NULL ph
1035 * is received, single notification is enough to clear all.
1036 * Notifying more times incurs overhead but doesn't harm
1037 * correctness.
1039 * The callee is responsible for destroying ph with
1040 * fuse_pollhandle_destroy() when no longer in use.
1042 * If this request is answered with an error code of ENOSYS, this is
1043 * treated as success (with a kernel-defined default poll-mask) and
1044 * future calls to pull() will succeed the same way without being send
1045 * to the filesystem process.
1047 * Valid replies:
1048 * fuse_reply_poll
1049 * fuse_reply_err
1051 * @param req request handle
1052 * @param ino the inode number
1053 * @param fi file information
1054 * @param ph poll handle to be used for notification
1056 void (*poll)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1057 struct fuse_pollhandle *ph);
1060 * Write data made available in a buffer
1062 * This is a more generic version of the ->write() method. If
1063 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
1064 * kernel supports splicing from the fuse device, then the
1065 * data will be made available in pipe for supporting zero
1066 * copy data transfer.
1068 * buf->count is guaranteed to be one (and thus buf->idx is
1069 * always zero). The write_buf handler must ensure that
1070 * bufv->off is correctly updated (reflecting the number of
1071 * bytes read from bufv->buf[0]).
1073 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
1074 * expected to reset the setuid and setgid bits.
1076 * Valid replies:
1077 * fuse_reply_write
1078 * fuse_reply_err
1080 * @param req request handle
1081 * @param ino the inode number
1082 * @param bufv buffer containing the data
1083 * @param off offset to write to
1084 * @param fi file information
1086 void (*write_buf)(fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv,
1087 off_t off, struct fuse_file_info *fi);
1090 * Forget about multiple inodes
1092 * See description of the forget function for more
1093 * information.
1095 * Valid replies:
1096 * fuse_reply_none
1098 * @param req request handle
1100 void (*forget_multi)(fuse_req_t req, size_t count,
1101 struct fuse_forget_data *forgets);
1104 * Acquire, modify or release a BSD file lock
1106 * Note: if the locking methods are not implemented, the kernel
1107 * will still allow file locking to work locally. Hence these are
1108 * only interesting for network filesystems and similar.
1110 * Valid replies:
1111 * fuse_reply_err
1113 * @param req request handle
1114 * @param ino the inode number
1115 * @param fi file information
1116 * @param op the locking operation, see flock(2)
1118 void (*flock)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1119 int op);
1122 * Allocate requested space. If this function returns success then
1123 * subsequent writes to the specified range shall not fail due to the lack
1124 * of free space on the file system storage media.
1126 * If this request is answered with an error code of ENOSYS, this is
1127 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1128 * future fallocate() requests will fail with EOPNOTSUPP without being
1129 * send to the filesystem process.
1131 * Valid replies:
1132 * fuse_reply_err
1134 * @param req request handle
1135 * @param ino the inode number
1136 * @param offset starting point for allocated region
1137 * @param length size of allocated region
1138 * @param mode determines the operation to be performed on the given range,
1139 * see fallocate(2)
1141 void (*fallocate)(fuse_req_t req, fuse_ino_t ino, int mode, off_t offset,
1142 off_t length, struct fuse_file_info *fi);
1145 * Read directory with attributes
1147 * Send a buffer filled using fuse_add_direntry_plus(), with size not
1148 * exceeding the requested size. Send an empty buffer on end of
1149 * stream.
1151 * fi->fh will contain the value set by the opendir method, or
1152 * will be undefined if the opendir method didn't set any value.
1154 * In contrast to readdir() (which does not affect the lookup counts),
1155 * the lookup count of every entry returned by readdirplus(), except "."
1156 * and "..", is incremented by one.
1158 * Valid replies:
1159 * fuse_reply_buf
1160 * fuse_reply_data
1161 * fuse_reply_err
1163 * @param req request handle
1164 * @param ino the inode number
1165 * @param size maximum number of bytes to send
1166 * @param off offset to continue reading the directory stream
1167 * @param fi file information
1169 void (*readdirplus)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1170 struct fuse_file_info *fi);
1173 * Copy a range of data from one file to another
1175 * Performs an optimized copy between two file descriptors without the
1176 * additional cost of transferring data through the FUSE kernel module
1177 * to user space (glibc) and then back into the FUSE filesystem again.
1179 * In case this method is not implemented, glibc falls back to reading
1180 * data from the source and writing to the destination. Effectively
1181 * doing an inefficient copy of the data.
1183 * If this request is answered with an error code of ENOSYS, this is
1184 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1185 * future copy_file_range() requests will fail with EOPNOTSUPP without
1186 * being send to the filesystem process.
1188 * Valid replies:
1189 * fuse_reply_write
1190 * fuse_reply_err
1192 * @param req request handle
1193 * @param ino_in the inode number or the source file
1194 * @param off_in starting point from were the data should be read
1195 * @param fi_in file information of the source file
1196 * @param ino_out the inode number or the destination file
1197 * @param off_out starting point where the data should be written
1198 * @param fi_out file information of the destination file
1199 * @param len maximum size of the data to copy
1200 * @param flags passed along with the copy_file_range() syscall
1202 void (*copy_file_range)(fuse_req_t req, fuse_ino_t ino_in, off_t off_in,
1203 struct fuse_file_info *fi_in, fuse_ino_t ino_out,
1204 off_t off_out, struct fuse_file_info *fi_out,
1205 size_t len, int flags);
1208 * Find next data or hole after the specified offset
1210 * If this request is answered with an error code of ENOSYS, this is
1211 * treated as a permanent failure, i.e. all future lseek() requests will
1212 * fail with the same error code without being send to the filesystem
1213 * process.
1215 * Valid replies:
1216 * fuse_reply_lseek
1217 * fuse_reply_err
1219 * @param req request handle
1220 * @param ino the inode number
1221 * @param off offset to start search from
1222 * @param whence either SEEK_DATA or SEEK_HOLE
1223 * @param fi file information
1225 void (*lseek)(fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1226 struct fuse_file_info *fi);
1230 * Reply with an error code or success.
1232 * Possible requests:
1233 * all except forget
1235 * Whereever possible, error codes should be chosen from the list of
1236 * documented error conditions in the corresponding system calls
1237 * manpage.
1239 * An error code of ENOSYS is sometimes treated specially. This is
1240 * indicated in the documentation of the affected handler functions.
1242 * The following requests may be answered with a zero error code:
1243 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1244 * removexattr, setlk.
1246 * @param req request handle
1247 * @param err the positive error value, or zero for success
1248 * @return zero for success, -errno for failure to send reply
1250 int fuse_reply_err(fuse_req_t req, int err);
1253 * Don't send reply
1255 * Possible requests:
1256 * forget
1257 * forget_multi
1258 * retrieve_reply
1260 * @param req request handle
1262 void fuse_reply_none(fuse_req_t req);
1265 * Reply with a directory entry
1267 * Possible requests:
1268 * lookup, mknod, mkdir, symlink, link
1270 * Side effects:
1271 * increments the lookup count on success
1273 * @param req request handle
1274 * @param e the entry parameters
1275 * @return zero for success, -errno for failure to send reply
1277 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1280 * Reply with a directory entry and open parameters
1282 * currently the following members of 'fi' are used:
1283 * fh, direct_io, keep_cache
1285 * Possible requests:
1286 * create
1288 * Side effects:
1289 * increments the lookup count on success
1291 * @param req request handle
1292 * @param e the entry parameters
1293 * @param fi file information
1294 * @return zero for success, -errno for failure to send reply
1296 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1297 const struct fuse_file_info *fi);
1300 * Reply with attributes
1302 * Possible requests:
1303 * getattr, setattr
1305 * @param req request handle
1306 * @param attr the attributes
1307 * @param attr_timeout validity timeout (in seconds) for the attributes
1308 * @return zero for success, -errno for failure to send reply
1310 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1311 double attr_timeout);
1314 * Reply with the contents of a symbolic link
1316 * Possible requests:
1317 * readlink
1319 * @param req request handle
1320 * @param link symbolic link contents
1321 * @return zero for success, -errno for failure to send reply
1323 int fuse_reply_readlink(fuse_req_t req, const char *link);
1326 * Reply with open parameters
1328 * currently the following members of 'fi' are used:
1329 * fh, direct_io, keep_cache
1331 * Possible requests:
1332 * open, opendir
1334 * @param req request handle
1335 * @param fi file information
1336 * @return zero for success, -errno for failure to send reply
1338 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1341 * Reply with number of bytes written
1343 * Possible requests:
1344 * write
1346 * @param req request handle
1347 * @param count the number of bytes written
1348 * @return zero for success, -errno for failure to send reply
1350 int fuse_reply_write(fuse_req_t req, size_t count);
1353 * Reply with data
1355 * Possible requests:
1356 * read, readdir, getxattr, listxattr
1358 * @param req request handle
1359 * @param buf buffer containing data
1360 * @param size the size of data in bytes
1361 * @return zero for success, -errno for failure to send reply
1363 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1366 * Reply with data copied/moved from buffer(s)
1368 * Possible requests:
1369 * read, readdir, getxattr, listxattr
1371 * Side effects:
1372 * when used to return data from a readdirplus() (but not readdir())
1373 * call, increments the lookup count of each returned entry by one
1374 * on success.
1376 * @param req request handle
1377 * @param bufv buffer vector
1378 * @return zero for success, -errno for failure to send reply
1380 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv);
1383 * Reply with data vector
1385 * Possible requests:
1386 * read, readdir, getxattr, listxattr
1388 * @param req request handle
1389 * @param iov the vector containing the data
1390 * @param count the size of vector
1391 * @return zero for success, -errno for failure to send reply
1393 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1396 * Reply with filesystem statistics
1398 * Possible requests:
1399 * statfs
1401 * @param req request handle
1402 * @param stbuf filesystem statistics
1403 * @return zero for success, -errno for failure to send reply
1405 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1408 * Reply with needed buffer size
1410 * Possible requests:
1411 * getxattr, listxattr
1413 * @param req request handle
1414 * @param count the buffer size needed in bytes
1415 * @return zero for success, -errno for failure to send reply
1417 int fuse_reply_xattr(fuse_req_t req, size_t count);
1420 * Reply with file lock information
1422 * Possible requests:
1423 * getlk
1425 * @param req request handle
1426 * @param lock the lock information
1427 * @return zero for success, -errno for failure to send reply
1429 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1432 * Reply with block index
1434 * Possible requests:
1435 * bmap
1437 * @param req request handle
1438 * @param idx block index within device
1439 * @return zero for success, -errno for failure to send reply
1441 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1444 * Filling a buffer in readdir
1448 * Add a directory entry to the buffer
1450 * Buffer needs to be large enough to hold the entry. If it's not,
1451 * then the entry is not filled in but the size of the entry is still
1452 * returned. The caller can check this by comparing the bufsize
1453 * parameter with the returned entry size. If the entry size is
1454 * larger than the buffer size, the operation failed.
1456 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1457 * st_mode field are used. The other fields are ignored.
1459 * *off* should be any non-zero value that the filesystem can use to
1460 * identify the current point in the directory stream. It does not
1461 * need to be the actual physical position. A value of zero is
1462 * reserved to mean "from the beginning", and should therefore never
1463 * be used (the first call to fuse_add_direntry should be passed the
1464 * offset of the second directory entry).
1466 * @param req request handle
1467 * @param buf the point where the new entry will be added to the buffer
1468 * @param bufsize remaining size of the buffer
1469 * @param name the name of the entry
1470 * @param stbuf the file attributes
1471 * @param off the offset of the next entry
1472 * @return the space needed for the entry
1474 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1475 const char *name, const struct stat *stbuf, off_t off);
1478 * Add a directory entry to the buffer with the attributes
1480 * See documentation of `fuse_add_direntry()` for more details.
1482 * @param req request handle
1483 * @param buf the point where the new entry will be added to the buffer
1484 * @param bufsize remaining size of the buffer
1485 * @param name the name of the entry
1486 * @param e the directory entry
1487 * @param off the offset of the next entry
1488 * @return the space needed for the entry
1490 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1491 const char *name,
1492 const struct fuse_entry_param *e, off_t off);
1495 * Reply to ask for data fetch and output buffer preparation. ioctl
1496 * will be retried with the specified input data fetched and output
1497 * buffer prepared.
1499 * Possible requests:
1500 * ioctl
1502 * @param req request handle
1503 * @param in_iov iovec specifying data to fetch from the caller
1504 * @param in_count number of entries in in_iov
1505 * @param out_iov iovec specifying addresses to write output to
1506 * @param out_count number of entries in out_iov
1507 * @return zero for success, -errno for failure to send reply
1509 int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
1510 size_t in_count, const struct iovec *out_iov,
1511 size_t out_count);
1514 * Reply to finish ioctl
1516 * Possible requests:
1517 * ioctl
1519 * @param req request handle
1520 * @param result result to be passed to the caller
1521 * @param buf buffer containing output data
1522 * @param size length of output data
1524 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1527 * Reply to finish ioctl with iov buffer
1529 * Possible requests:
1530 * ioctl
1532 * @param req request handle
1533 * @param result result to be passed to the caller
1534 * @param iov the vector containing the data
1535 * @param count the size of vector
1537 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1538 int count);
1541 * Reply with poll result event mask
1543 * @param req request handle
1544 * @param revents poll result event mask
1546 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1549 * Reply with offset
1551 * Possible requests:
1552 * lseek
1554 * @param req request handle
1555 * @param off offset of next data or hole
1556 * @return zero for success, -errno for failure to send reply
1558 int fuse_reply_lseek(fuse_req_t req, off_t off);
1561 * Notification
1565 * Notify IO readiness event
1567 * For more information, please read comment for poll operation.
1569 * @param ph poll handle to notify IO readiness event for
1571 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1574 * Notify to invalidate cache for an inode.
1576 * Added in FUSE protocol version 7.12. If the kernel does not support
1577 * this (or a newer) version, the function will return -ENOSYS and do
1578 * nothing.
1580 * If the filesystem has writeback caching enabled, invalidating an
1581 * inode will first trigger a writeback of all dirty pages. The call
1582 * will block until all writeback requests have completed and the
1583 * inode has been invalidated. It will, however, not wait for
1584 * completion of pending writeback requests that have been issued
1585 * before.
1587 * If there are no dirty pages, this function will never block.
1589 * @param se the session object
1590 * @param ino the inode number
1591 * @param off the offset in the inode where to start invalidating
1592 * or negative to invalidate attributes only
1593 * @param len the amount of cache to invalidate or 0 for all
1594 * @return zero for success, -errno for failure
1596 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1597 off_t off, off_t len);
1600 * Notify to invalidate parent attributes and the dentry matching
1601 * parent/name
1603 * To avoid a deadlock this function must not be called in the
1604 * execution path of a related filesytem operation or within any code
1605 * that could hold a lock that could be needed to execute such an
1606 * operation. As of kernel 4.18, a "related operation" is a lookup(),
1607 * symlink(), mknod(), mkdir(), unlink(), rename(), link() or create()
1608 * request for the parent, and a setattr(), unlink(), rmdir(),
1609 * rename(), setxattr(), removexattr(), readdir() or readdirplus()
1610 * request for the inode itself.
1612 * When called correctly, this function will never block.
1614 * Added in FUSE protocol version 7.12. If the kernel does not support
1615 * this (or a newer) version, the function will return -ENOSYS and do
1616 * nothing.
1618 * @param se the session object
1619 * @param parent inode number
1620 * @param name file name
1621 * @param namelen strlen() of file name
1622 * @return zero for success, -errno for failure
1624 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1625 const char *name, size_t namelen);
1628 * This function behaves like fuse_lowlevel_notify_inval_entry() with
1629 * the following additional effect (at least as of Linux kernel 4.8):
1631 * If the provided *child* inode matches the inode that is currently
1632 * associated with the cached dentry, and if there are any inotify
1633 * watches registered for the dentry, then the watchers are informed
1634 * that the dentry has been deleted.
1636 * To avoid a deadlock this function must not be called while
1637 * executing a related filesytem operation or while holding a lock
1638 * that could be needed to execute such an operation (see the
1639 * description of fuse_lowlevel_notify_inval_entry() for more
1640 * details).
1642 * When called correctly, this function will never block.
1644 * Added in FUSE protocol version 7.18. If the kernel does not support
1645 * this (or a newer) version, the function will return -ENOSYS and do
1646 * nothing.
1648 * @param se the session object
1649 * @param parent inode number
1650 * @param child inode number
1651 * @param name file name
1652 * @param namelen strlen() of file name
1653 * @return zero for success, -errno for failure
1655 int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent,
1656 fuse_ino_t child, const char *name,
1657 size_t namelen);
1660 * Store data to the kernel buffers
1662 * Synchronously store data in the kernel buffers belonging to the
1663 * given inode. The stored data is marked up-to-date (no read will be
1664 * performed against it, unless it's invalidated or evicted from the
1665 * cache).
1667 * If the stored data overflows the current file size, then the size
1668 * is extended, similarly to a write(2) on the filesystem.
1670 * If this function returns an error, then the store wasn't fully
1671 * completed, but it may have been partially completed.
1673 * Added in FUSE protocol version 7.15. If the kernel does not support
1674 * this (or a newer) version, the function will return -ENOSYS and do
1675 * nothing.
1677 * @param se the session object
1678 * @param ino the inode number
1679 * @param offset the starting offset into the file to store to
1680 * @param bufv buffer vector
1681 * @return zero for success, -errno for failure
1683 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1684 off_t offset, struct fuse_bufvec *bufv);
1687 * Utility functions
1691 * Get the userdata from the request
1693 * @param req request handle
1694 * @return the user data passed to fuse_session_new()
1696 void *fuse_req_userdata(fuse_req_t req);
1699 * Get the context from the request
1701 * The pointer returned by this function will only be valid for the
1702 * request's lifetime
1704 * @param req request handle
1705 * @return the context structure
1707 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1710 * Callback function for an interrupt
1712 * @param req interrupted request
1713 * @param data user data
1715 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1718 * Register/unregister callback for an interrupt
1720 * If an interrupt has already happened, then the callback function is
1721 * called from within this function, hence it's not possible for
1722 * interrupts to be lost.
1724 * @param req request handle
1725 * @param func the callback function or NULL for unregister
1726 * @param data user data passed to the callback function
1728 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1729 void *data);
1732 * Check if a request has already been interrupted
1734 * @param req request handle
1735 * @return 1 if the request has been interrupted, 0 otherwise
1737 int fuse_req_interrupted(fuse_req_t req);
1740 * Check if the session is connected via virtio
1742 * @param se session object
1743 * @return 1 if the session is a virtio session
1745 int fuse_lowlevel_is_virtio(struct fuse_session *se);
1748 * Inquiry functions
1752 * Print low-level version information to stdout.
1754 void fuse_lowlevel_version(void);
1757 * Print available low-level options to stdout. This is not an
1758 * exhaustive list, but includes only those options that may be of
1759 * interest to an end-user of a file system.
1761 void fuse_lowlevel_help(void);
1764 * Print available options for `fuse_parse_cmdline()`.
1766 void fuse_cmdline_help(void);
1769 * Filesystem setup & teardown
1772 struct fuse_cmdline_opts {
1773 int foreground;
1774 int debug;
1775 int nodefault_subtype;
1776 int show_version;
1777 int show_help;
1778 int print_capabilities;
1779 int syslog;
1780 int log_level;
1781 unsigned int max_idle_threads;
1782 unsigned long rlimit_nofile;
1786 * Utility function to parse common options for simple file systems
1787 * using the low-level API. A help text that describes the available
1788 * options can be printed with `fuse_cmdline_help`. A single
1789 * non-option argument is treated as the mountpoint. Multiple
1790 * non-option arguments will result in an error.
1792 * If neither -o subtype= or -o fsname= options are given, a new
1793 * subtype option will be added and set to the basename of the program
1794 * (the fsname will remain unset, and then defaults to "fuse").
1796 * Known options will be removed from *args*, unknown options will
1797 * remain.
1799 * @param args argument vector (input+output)
1800 * @param opts output argument for parsed options
1801 * @return 0 on success, -1 on failure
1803 int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts);
1806 * Create a low level session.
1808 * Returns a session structure suitable for passing to
1809 * fuse_session_mount() and fuse_session_loop().
1811 * This function accepts most file-system independent mount options
1812 * (like context, nodev, ro - see mount(8)), as well as the general
1813 * fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and
1814 * -o default_permissions, but not ``-o use_ino``). Instead of `-o
1815 * debug`, debugging may also enabled with `-d` or `--debug`.
1817 * If not all options are known, an error message is written to stderr
1818 * and the function returns NULL.
1820 * Option parsing skips argv[0], which is assumed to contain the
1821 * program name. To prevent accidentally passing an option in
1822 * argv[0], this element must always be present (even if no options
1823 * are specified). It may be set to the empty string ('\0') if no
1824 * reasonable value can be provided.
1826 * @param args argument vector
1827 * @param op the (low-level) filesystem operations
1828 * @param op_size sizeof(struct fuse_lowlevel_ops)
1829 * @param userdata user data
1831 * @return the fuse session on success, NULL on failure
1833 struct fuse_session *fuse_session_new(struct fuse_args *args,
1834 const struct fuse_lowlevel_ops *op,
1835 size_t op_size, void *userdata);
1838 * Mount a FUSE file system.
1840 * @param se session object
1842 * @return 0 on success, -1 on failure.
1844 int fuse_session_mount(struct fuse_session *se);
1847 * Enter a single threaded, blocking event loop.
1849 * When the event loop terminates because the connection to the FUSE
1850 * kernel module has been closed, this function returns zero. This
1851 * happens when the filesystem is unmounted regularly (by the
1852 * filesystem owner or root running the umount(8) or fusermount(1)
1853 * command), or if connection is explicitly severed by writing ``1``
1854 * to the``abort`` file in ``/sys/fs/fuse/connections/NNN``. The only
1855 * way to distinguish between these two conditions is to check if the
1856 * filesystem is still mounted after the session loop returns.
1858 * When some error occurs during request processing, the function
1859 * returns a negated errno(3) value.
1861 * If the loop has been terminated because of a signal handler
1862 * installed by fuse_set_signal_handlers(), this function returns the
1863 * (positive) signal value that triggered the exit.
1865 * @param se the session
1866 * @return 0, -errno, or a signal value
1868 int fuse_session_loop(struct fuse_session *se);
1871 * Flag a session as terminated.
1873 * This function is invoked by the POSIX signal handlers, when
1874 * registered using fuse_set_signal_handlers(). It will cause any
1875 * running event loops to terminate on the next opportunity.
1877 * @param se the session
1879 void fuse_session_exit(struct fuse_session *se);
1882 * Reset the terminated flag of a session
1884 * @param se the session
1886 void fuse_session_reset(struct fuse_session *se);
1889 * Query the terminated flag of a session
1891 * @param se the session
1892 * @return 1 if exited, 0 if not exited
1894 int fuse_session_exited(struct fuse_session *se);
1897 * Ensure that file system is unmounted.
1899 * In regular operation, the file system is typically unmounted by the
1900 * user calling umount(8) or fusermount(1), which then terminates the
1901 * FUSE session loop. However, the session loop may also terminate as
1902 * a result of an explicit call to fuse_session_exit() (e.g. by a
1903 * signal handler installed by fuse_set_signal_handler()). In this
1904 * case the filesystem remains mounted, but any attempt to access it
1905 * will block (while the filesystem process is still running) or give
1906 * an ESHUTDOWN error (after the filesystem process has terminated).
1908 * If the communication channel with the FUSE kernel module is still
1909 * open (i.e., if the session loop was terminated by an explicit call
1910 * to fuse_session_exit()), this function will close it and unmount
1911 * the filesystem. If the communication channel has been closed by the
1912 * kernel, this method will do (almost) nothing.
1914 * NOTE: The above semantics mean that if the connection to the kernel
1915 * is terminated via the ``/sys/fs/fuse/connections/NNN/abort`` file,
1916 * this method will *not* unmount the filesystem.
1918 * @param se the session
1920 void fuse_session_unmount(struct fuse_session *se);
1923 * Destroy a session
1925 * @param se the session
1927 void fuse_session_destroy(struct fuse_session *se);
1930 * Custom event loop support
1934 * Return file descriptor for communication with kernel.
1936 * The file selector can be used to integrate FUSE with a custom event
1937 * loop. Whenever data is available for reading on the provided fd,
1938 * the event loop should call `fuse_session_receive_buf` followed by
1939 * `fuse_session_process_buf` to process the request.
1941 * The returned file descriptor is valid until `fuse_session_unmount`
1942 * is called.
1944 * @param se the session
1945 * @return a file descriptor
1947 int fuse_session_fd(struct fuse_session *se);
1950 * Process a raw request supplied in a generic buffer
1952 * The fuse_buf may contain a memory buffer or a pipe file descriptor.
1954 * @param se the session
1955 * @param buf the fuse_buf containing the request
1957 void fuse_session_process_buf(struct fuse_session *se,
1958 const struct fuse_buf *buf);
1961 * Read a raw request from the kernel into the supplied buffer.
1963 * Depending on file system options, system capabilities, and request
1964 * size the request is either read into a memory buffer or spliced
1965 * into a temporary pipe.
1967 * @param se the session
1968 * @param buf the fuse_buf to store the request in
1969 * @return the actual size of the raw request, or -errno on error
1971 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
1973 #endif /* FUSE_LOWLEVEL_H_ */