virtiofsd: Format imported files to qemu style
[qemu/kevin.git] / tools / virtiofsd / fuse_lowlevel.h
blobadb9054bb1419e40db7acc50a0413959c7b40b25
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;
108 * Additional context associated with requests.
110 * Note that the reported client uid, gid and pid may be zero in some
111 * situations. For example, if the FUSE file system is running in a
112 * PID or user namespace but then accessed from outside the namespace,
113 * there is no valid uid/pid/gid that could be reported.
115 struct fuse_ctx {
116 /** User ID of the calling process */
117 uid_t uid;
119 /** Group ID of the calling process */
120 gid_t gid;
122 /** Thread ID of the calling process */
123 pid_t pid;
125 /** Umask of the calling process */
126 mode_t umask;
129 struct fuse_forget_data {
130 fuse_ino_t ino;
131 uint64_t nlookup;
134 /* 'to_set' flags in setattr */
135 #define FUSE_SET_ATTR_MODE (1 << 0)
136 #define FUSE_SET_ATTR_UID (1 << 1)
137 #define FUSE_SET_ATTR_GID (1 << 2)
138 #define FUSE_SET_ATTR_SIZE (1 << 3)
139 #define FUSE_SET_ATTR_ATIME (1 << 4)
140 #define FUSE_SET_ATTR_MTIME (1 << 5)
141 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
142 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
143 #define FUSE_SET_ATTR_CTIME (1 << 10)
146 * Request methods and replies
150 * Low level filesystem operations
152 * Most of the methods (with the exception of init and destroy)
153 * receive a request handle (fuse_req_t) as their first argument.
154 * This handle must be passed to one of the specified reply functions.
156 * This may be done inside the method invocation, or after the call
157 * has returned. The request handle is valid until one of the reply
158 * functions is called.
160 * Other pointer arguments (name, fuse_file_info, etc) are not valid
161 * after the call has returned, so if they are needed later, their
162 * contents have to be copied.
164 * In general, all methods are expected to perform any necessary
165 * permission checking. However, a filesystem may delegate this task
166 * to the kernel by passing the `default_permissions` mount option to
167 * `fuse_session_new()`. In this case, methods will only be called if
168 * the kernel's permission check has succeeded.
170 * The filesystem sometimes needs to handle a return value of -ENOENT
171 * from the reply function, which means, that the request was
172 * interrupted, and the reply discarded. For example if
173 * fuse_reply_open() return -ENOENT means, that the release method for
174 * this file will not be called.
176 struct fuse_lowlevel_ops {
178 * Initialize filesystem
180 * This function is called when libfuse establishes
181 * communication with the FUSE kernel module. The file system
182 * should use this module to inspect and/or modify the
183 * connection parameters provided in the `conn` structure.
185 * Note that some parameters may be overwritten by options
186 * passed to fuse_session_new() which take precedence over the
187 * values set in this handler.
189 * There's no reply to this function
191 * @param userdata the user data passed to fuse_session_new()
193 void (*init)(void *userdata, struct fuse_conn_info *conn);
196 * Clean up filesystem.
198 * Called on filesystem exit. When this method is called, the
199 * connection to the kernel may be gone already, so that eg. calls
200 * to fuse_lowlevel_notify_* will fail.
202 * There's no reply to this function
204 * @param userdata the user data passed to fuse_session_new()
206 void (*destroy)(void *userdata);
209 * Look up a directory entry by name and get its attributes.
211 * Valid replies:
212 * fuse_reply_entry
213 * fuse_reply_err
215 * @param req request handle
216 * @param parent inode number of the parent directory
217 * @param name the name to look up
219 void (*lookup)(fuse_req_t req, fuse_ino_t parent, const char *name);
222 * Forget about an inode
224 * This function is called when the kernel removes an inode
225 * from its internal caches.
227 * The inode's lookup count increases by one for every call to
228 * fuse_reply_entry and fuse_reply_create. The nlookup parameter
229 * indicates by how much the lookup count should be decreased.
231 * Inodes with a non-zero lookup count may receive request from
232 * the kernel even after calls to unlink, rmdir or (when
233 * overwriting an existing file) rename. Filesystems must handle
234 * such requests properly and it is recommended to defer removal
235 * of the inode until the lookup count reaches zero. Calls to
236 * unlink, rmdir or rename will be followed closely by forget
237 * unless the file or directory is open, in which case the
238 * kernel issues forget only after the release or releasedir
239 * calls.
241 * Note that if a file system will be exported over NFS the
242 * inodes lifetime must extend even beyond forget. See the
243 * generation field in struct fuse_entry_param above.
245 * On unmount the lookup count for all inodes implicitly drops
246 * to zero. It is not guaranteed that the file system will
247 * receive corresponding forget messages for the affected
248 * inodes.
250 * Valid replies:
251 * fuse_reply_none
253 * @param req request handle
254 * @param ino the inode number
255 * @param nlookup the number of lookups to forget
257 void (*forget)(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
260 * Get file attributes.
262 * If writeback caching is enabled, the kernel may have a
263 * better idea of a file's length than the FUSE file system
264 * (eg if there has been a write that extended the file size,
265 * but that has not yet been passed to the filesystem.n
267 * In this case, the st_size value provided by the file system
268 * will be ignored.
270 * Valid replies:
271 * fuse_reply_attr
272 * fuse_reply_err
274 * @param req request handle
275 * @param ino the inode number
276 * @param fi for future use, currently always NULL
278 void (*getattr)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
281 * Set file attributes
283 * In the 'attr' argument only members indicated by the 'to_set'
284 * bitmask contain valid values. Other members contain undefined
285 * values.
287 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
288 * expected to reset the setuid and setgid bits if the file
289 * size or owner is being changed.
291 * If the setattr was invoked from the ftruncate() system call
292 * under Linux kernel versions 2.6.15 or later, the fi->fh will
293 * contain the value set by the open method or will be undefined
294 * if the open method didn't set any value. Otherwise (not
295 * ftruncate call, or kernel version earlier than 2.6.15) the fi
296 * parameter will be NULL.
298 * Valid replies:
299 * fuse_reply_attr
300 * fuse_reply_err
302 * @param req request handle
303 * @param ino the inode number
304 * @param attr the attributes
305 * @param to_set bit mask of attributes which should be set
306 * @param fi file information, or NULL
308 void (*setattr)(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
309 int to_set, struct fuse_file_info *fi);
312 * Read symbolic link
314 * Valid replies:
315 * fuse_reply_readlink
316 * fuse_reply_err
318 * @param req request handle
319 * @param ino the inode number
321 void (*readlink)(fuse_req_t req, fuse_ino_t ino);
324 * Create file node
326 * Create a regular file, character device, block device, fifo or
327 * socket node.
329 * Valid replies:
330 * fuse_reply_entry
331 * fuse_reply_err
333 * @param req request handle
334 * @param parent inode number of the parent directory
335 * @param name to create
336 * @param mode file type and mode with which to create the new file
337 * @param rdev the device number (only valid if created file is a device)
339 void (*mknod)(fuse_req_t req, fuse_ino_t parent, const char *name,
340 mode_t mode, dev_t rdev);
343 * Create a directory
345 * Valid replies:
346 * fuse_reply_entry
347 * fuse_reply_err
349 * @param req request handle
350 * @param parent inode number of the parent directory
351 * @param name to create
352 * @param mode with which to create the new file
354 void (*mkdir)(fuse_req_t req, fuse_ino_t parent, const char *name,
355 mode_t mode);
358 * Remove a file
360 * If the file's inode's lookup count is non-zero, the file
361 * system is expected to postpone any removal of the inode
362 * until the lookup count reaches zero (see description of the
363 * forget function).
365 * Valid replies:
366 * fuse_reply_err
368 * @param req request handle
369 * @param parent inode number of the parent directory
370 * @param name to remove
372 void (*unlink)(fuse_req_t req, fuse_ino_t parent, const char *name);
375 * Remove a directory
377 * If the directory's inode's lookup count is non-zero, the
378 * file system is expected to postpone any removal of the
379 * inode until the lookup count reaches zero (see description
380 * of the forget function).
382 * Valid replies:
383 * fuse_reply_err
385 * @param req request handle
386 * @param parent inode number of the parent directory
387 * @param name to remove
389 void (*rmdir)(fuse_req_t req, fuse_ino_t parent, const char *name);
392 * Create a symbolic link
394 * Valid replies:
395 * fuse_reply_entry
396 * fuse_reply_err
398 * @param req request handle
399 * @param link the contents of the symbolic link
400 * @param parent inode number of the parent directory
401 * @param name to create
403 void (*symlink)(fuse_req_t req, const char *link, fuse_ino_t parent,
404 const char *name);
407 * Rename a file
409 * If the target exists it should be atomically replaced. If
410 * the target's inode's lookup count is non-zero, the file
411 * system is expected to postpone any removal of the inode
412 * until the lookup count reaches zero (see description of the
413 * forget function).
415 * If this request is answered with an error code of ENOSYS, this is
416 * treated as a permanent failure with error code EINVAL, i.e. all
417 * future bmap requests will fail with EINVAL without being
418 * send to the filesystem process.
420 * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
421 * RENAME_NOREPLACE is specified, the filesystem must not
422 * overwrite *newname* if it exists and return an error
423 * instead. If `RENAME_EXCHANGE` is specified, the filesystem
424 * must atomically exchange the two files, i.e. both must
425 * exist and neither may be deleted.
427 * Valid replies:
428 * fuse_reply_err
430 * @param req request handle
431 * @param parent inode number of the old parent directory
432 * @param name old name
433 * @param newparent inode number of the new parent directory
434 * @param newname new name
436 void (*rename)(fuse_req_t req, fuse_ino_t parent, const char *name,
437 fuse_ino_t newparent, const char *newname,
438 unsigned int flags);
441 * Create a hard link
443 * Valid replies:
444 * fuse_reply_entry
445 * fuse_reply_err
447 * @param req request handle
448 * @param ino the old inode number
449 * @param newparent inode number of the new parent directory
450 * @param newname new name to create
452 void (*link)(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
453 const char *newname);
456 * Open a file
458 * Open flags are available in fi->flags. The following rules
459 * apply.
461 * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
462 * filtered out / handled by the kernel.
464 * - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
465 * by the filesystem to check if the operation is
466 * permitted. If the ``-o default_permissions`` mount
467 * option is given, this check is already done by the
468 * kernel before calling open() and may thus be omitted by
469 * the filesystem.
471 * - When writeback caching is enabled, the kernel may send
472 * read requests even for files opened with O_WRONLY. The
473 * filesystem should be prepared to handle this.
475 * - When writeback caching is disabled, the filesystem is
476 * expected to properly handle the O_APPEND flag and ensure
477 * that each write is appending to the end of the file.
479 * - When writeback caching is enabled, the kernel will
480 * handle O_APPEND. However, unless all changes to the file
481 * come through the kernel this will not work reliably. The
482 * filesystem should thus either ignore the O_APPEND flag
483 * (and let the kernel handle it), or return an error
484 * (indicating that reliably O_APPEND is not available).
486 * Filesystem may store an arbitrary file handle (pointer,
487 * index, etc) in fi->fh, and use this in other all other file
488 * operations (read, write, flush, release, fsync).
490 * Filesystem may also implement stateless file I/O and not store
491 * anything in fi->fh.
493 * There are also some flags (direct_io, keep_cache) which the
494 * filesystem may set in fi, to change the way the file is opened.
495 * See fuse_file_info structure in <fuse_common.h> for more details.
497 * If this request is answered with an error code of ENOSYS
498 * and FUSE_CAP_NO_OPEN_SUPPORT is set in
499 * `fuse_conn_info.capable`, this is treated as success and
500 * future calls to open and release will also succeed without being
501 * sent to the filesystem process.
503 * Valid replies:
504 * fuse_reply_open
505 * fuse_reply_err
507 * @param req request handle
508 * @param ino the inode number
509 * @param fi file information
511 void (*open)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
514 * Read data
516 * Read should send exactly the number of bytes requested except
517 * on EOF or error, otherwise the rest of the data will be
518 * substituted with zeroes. An exception to this is when the file
519 * has been opened in 'direct_io' mode, in which case the return
520 * value of the read system call will reflect the return value of
521 * this operation.
523 * fi->fh will contain the value set by the open method, or will
524 * be undefined if the open method didn't set any value.
526 * Valid replies:
527 * fuse_reply_buf
528 * fuse_reply_iov
529 * fuse_reply_data
530 * fuse_reply_err
532 * @param req request handle
533 * @param ino the inode number
534 * @param size number of bytes to read
535 * @param off offset to read from
536 * @param fi file information
538 void (*read)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
539 struct fuse_file_info *fi);
542 * Write data
544 * Write should return exactly the number of bytes requested
545 * except on error. An exception to this is when the file has
546 * been opened in 'direct_io' mode, in which case the return value
547 * of the write system call will reflect the return value of this
548 * operation.
550 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
551 * expected to reset the setuid and setgid bits.
553 * fi->fh will contain the value set by the open method, or will
554 * be undefined if the open method didn't set any value.
556 * Valid replies:
557 * fuse_reply_write
558 * fuse_reply_err
560 * @param req request handle
561 * @param ino the inode number
562 * @param buf data to write
563 * @param size number of bytes to write
564 * @param off offset to write to
565 * @param fi file information
567 void (*write)(fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size,
568 off_t off, struct fuse_file_info *fi);
571 * Flush method
573 * This is called on each close() of the opened file.
575 * Since file descriptors can be duplicated (dup, dup2, fork), for
576 * one open call there may be many flush calls.
578 * Filesystems shouldn't assume that flush will always be called
579 * after some writes, or that if will be called at all.
581 * fi->fh will contain the value set by the open method, or will
582 * be undefined if the open method didn't set any value.
584 * NOTE: the name of the method is misleading, since (unlike
585 * fsync) the filesystem is not forced to flush pending writes.
586 * One reason to flush data is if the filesystem wants to return
587 * write errors during close. However, such use is non-portable
588 * because POSIX does not require [close] to wait for delayed I/O to
589 * complete.
591 * If the filesystem supports file locking operations (setlk,
592 * getlk) it should remove all locks belonging to 'fi->owner'.
594 * If this request is answered with an error code of ENOSYS,
595 * this is treated as success and future calls to flush() will
596 * succeed automatically without being send to the filesystem
597 * process.
599 * Valid replies:
600 * fuse_reply_err
602 * @param req request handle
603 * @param ino the inode number
604 * @param fi file information
606 * [close]:
607 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
609 void (*flush)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
612 * Release an open file
614 * Release is called when there are no more references to an open
615 * file: all file descriptors are closed and all memory mappings
616 * are unmapped.
618 * For every open call there will be exactly one release call (unless
619 * the filesystem is force-unmounted).
621 * The filesystem may reply with an error, but error values are
622 * not returned to close() or munmap() which triggered the
623 * release.
625 * fi->fh will contain the value set by the open method, or will
626 * be undefined if the open method didn't set any value.
627 * fi->flags will contain the same flags as for open.
629 * Valid replies:
630 * fuse_reply_err
632 * @param req request handle
633 * @param ino the inode number
634 * @param fi file information
636 void (*release)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
639 * Synchronize file contents
641 * If the datasync parameter is non-zero, then only the user data
642 * should be flushed, not the meta data.
644 * If this request is answered with an error code of ENOSYS,
645 * this is treated as success and future calls to fsync() will
646 * succeed automatically without being send to the filesystem
647 * process.
649 * Valid replies:
650 * fuse_reply_err
652 * @param req request handle
653 * @param ino the inode number
654 * @param datasync flag indicating if only data should be flushed
655 * @param fi file information
657 void (*fsync)(fuse_req_t req, fuse_ino_t ino, int datasync,
658 struct fuse_file_info *fi);
661 * Open a directory
663 * Filesystem may store an arbitrary file handle (pointer, index,
664 * etc) in fi->fh, and use this in other all other directory
665 * stream operations (readdir, releasedir, fsyncdir).
667 * If this request is answered with an error code of ENOSYS and
668 * FUSE_CAP_NO_OPENDIR_SUPPORT is set in `fuse_conn_info.capable`,
669 * this is treated as success and future calls to opendir and
670 * releasedir will also succeed without being sent to the filesystem
671 * process. In addition, the kernel will cache readdir results
672 * as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR.
674 * Valid replies:
675 * fuse_reply_open
676 * fuse_reply_err
678 * @param req request handle
679 * @param ino the inode number
680 * @param fi file information
682 void (*opendir)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
685 * Read directory
687 * Send a buffer filled using fuse_add_direntry(), with size not
688 * exceeding the requested size. Send an empty buffer on end of
689 * stream.
691 * fi->fh will contain the value set by the opendir method, or
692 * will be undefined if the opendir method didn't set any value.
694 * Returning a directory entry from readdir() does not affect
695 * its lookup count.
697 * If off_t is non-zero, then it will correspond to one of the off_t
698 * values that was previously returned by readdir() for the same
699 * directory handle. In this case, readdir() should skip over entries
700 * coming before the position defined by the off_t value. If entries
701 * are added or removed while the directory handle is open, they filesystem
702 * may still include the entries that have been removed, and may not
703 * report the entries that have been created. However, addition or
704 * removal of entries must never cause readdir() to skip over unrelated
705 * entries or to report them more than once. This means
706 * that off_t can not be a simple index that enumerates the entries
707 * that have been returned but must contain sufficient information to
708 * uniquely determine the next directory entry to return even when the
709 * set of entries is changing.
711 * The function does not have to report the '.' and '..'
712 * entries, but is allowed to do so. Note that, if readdir does
713 * not return '.' or '..', they will not be implicitly returned,
714 * and this behavior is observable by the caller.
716 * Valid replies:
717 * fuse_reply_buf
718 * fuse_reply_data
719 * fuse_reply_err
721 * @param req request handle
722 * @param ino the inode number
723 * @param size maximum number of bytes to send
724 * @param off offset to continue reading the directory stream
725 * @param fi file information
727 void (*readdir)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
728 struct fuse_file_info *fi);
731 * Release an open directory
733 * For every opendir call there will be exactly one releasedir
734 * call (unless the filesystem is force-unmounted).
736 * fi->fh will contain the value set by the opendir method, or
737 * will be undefined if the opendir method didn't set any value.
739 * Valid replies:
740 * fuse_reply_err
742 * @param req request handle
743 * @param ino the inode number
744 * @param fi file information
746 void (*releasedir)(fuse_req_t req, fuse_ino_t ino,
747 struct fuse_file_info *fi);
750 * Synchronize directory contents
752 * If the datasync parameter is non-zero, then only the directory
753 * contents should be flushed, not the meta data.
755 * fi->fh will contain the value set by the opendir method, or
756 * will be undefined if the opendir method didn't set any value.
758 * If this request is answered with an error code of ENOSYS,
759 * this is treated as success and future calls to fsyncdir() will
760 * succeed automatically without being send to the filesystem
761 * process.
763 * Valid replies:
764 * fuse_reply_err
766 * @param req request handle
767 * @param ino the inode number
768 * @param datasync flag indicating if only data should be flushed
769 * @param fi file information
771 void (*fsyncdir)(fuse_req_t req, fuse_ino_t ino, int datasync,
772 struct fuse_file_info *fi);
775 * Get file system statistics
777 * Valid replies:
778 * fuse_reply_statfs
779 * fuse_reply_err
781 * @param req request handle
782 * @param ino the inode number, zero means "undefined"
784 void (*statfs)(fuse_req_t req, fuse_ino_t ino);
787 * Set an extended attribute
789 * If this request is answered with an error code of ENOSYS, this is
790 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
791 * future setxattr() requests will fail with EOPNOTSUPP without being
792 * send to the filesystem process.
794 * Valid replies:
795 * fuse_reply_err
797 void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
798 const char *value, size_t size, int flags);
801 * Get an extended attribute
803 * If size is zero, the size of the value should be sent with
804 * fuse_reply_xattr.
806 * If the size is non-zero, and the value fits in the buffer, the
807 * value should be sent with fuse_reply_buf.
809 * If the size is too small for the value, the ERANGE error should
810 * be sent.
812 * If this request is answered with an error code of ENOSYS, this is
813 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
814 * future getxattr() requests will fail with EOPNOTSUPP without being
815 * send to the filesystem process.
817 * Valid replies:
818 * fuse_reply_buf
819 * fuse_reply_data
820 * fuse_reply_xattr
821 * fuse_reply_err
823 * @param req request handle
824 * @param ino the inode number
825 * @param name of the extended attribute
826 * @param size maximum size of the value to send
828 void (*getxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
829 size_t size);
832 * List extended attribute names
834 * If size is zero, the total size of the attribute list should be
835 * sent with fuse_reply_xattr.
837 * If the size is non-zero, and the null character separated
838 * attribute list fits in the buffer, the list should be sent with
839 * fuse_reply_buf.
841 * If the size is too small for the list, the ERANGE error should
842 * be sent.
844 * If this request is answered with an error code of ENOSYS, this is
845 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
846 * future listxattr() requests will fail with EOPNOTSUPP without being
847 * send to the filesystem process.
849 * Valid replies:
850 * fuse_reply_buf
851 * fuse_reply_data
852 * fuse_reply_xattr
853 * fuse_reply_err
855 * @param req request handle
856 * @param ino the inode number
857 * @param size maximum size of the list to send
859 void (*listxattr)(fuse_req_t req, fuse_ino_t ino, size_t size);
862 * Remove an extended attribute
864 * If this request is answered with an error code of ENOSYS, this is
865 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
866 * future removexattr() requests will fail with EOPNOTSUPP without being
867 * send to the filesystem process.
869 * Valid replies:
870 * fuse_reply_err
872 * @param req request handle
873 * @param ino the inode number
874 * @param name of the extended attribute
876 void (*removexattr)(fuse_req_t req, fuse_ino_t ino, const char *name);
879 * Check file access permissions
881 * This will be called for the access() and chdir() system
882 * calls. If the 'default_permissions' mount option is given,
883 * this method is not called.
885 * This method is not called under Linux kernel versions 2.4.x
887 * If this request is answered with an error code of ENOSYS, this is
888 * treated as a permanent success, i.e. this and all future access()
889 * requests will succeed without being send to the filesystem process.
891 * Valid replies:
892 * fuse_reply_err
894 * @param req request handle
895 * @param ino the inode number
896 * @param mask requested access mode
898 void (*access)(fuse_req_t req, fuse_ino_t ino, int mask);
901 * Create and open a file
903 * If the file does not exist, first create it with the specified
904 * mode, and then open it.
906 * See the description of the open handler for more
907 * information.
909 * If this method is not implemented or under Linux kernel
910 * versions earlier than 2.6.15, the mknod() and open() methods
911 * will be called instead.
913 * If this request is answered with an error code of ENOSYS, the handler
914 * is treated as not implemented (i.e., for this and future requests the
915 * mknod() and open() handlers will be called instead).
917 * Valid replies:
918 * fuse_reply_create
919 * fuse_reply_err
921 * @param req request handle
922 * @param parent inode number of the parent directory
923 * @param name to create
924 * @param mode file type and mode with which to create the new file
925 * @param fi file information
927 void (*create)(fuse_req_t req, fuse_ino_t parent, const char *name,
928 mode_t mode, struct fuse_file_info *fi);
931 * Test for a POSIX file lock
933 * Valid replies:
934 * fuse_reply_lock
935 * fuse_reply_err
937 * @param req request handle
938 * @param ino the inode number
939 * @param fi file information
940 * @param lock the region/type to test
942 void (*getlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
943 struct flock *lock);
946 * Acquire, modify or release a POSIX file lock
948 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
949 * owner, but otherwise this is not always the case. For checking
950 * lock ownership, 'fi->owner' must be used. The l_pid field in
951 * 'struct flock' should only be used to fill in this field in
952 * getlk().
954 * Note: if the locking methods are not implemented, the kernel
955 * will still allow file locking to work locally. Hence these are
956 * only interesting for network filesystems and similar.
958 * Valid replies:
959 * fuse_reply_err
961 * @param req request handle
962 * @param ino the inode number
963 * @param fi file information
964 * @param lock the region/type to set
965 * @param sleep locking operation may sleep
967 void (*setlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
968 struct flock *lock, int sleep);
971 * Map block index within file to block index within device
973 * Note: This makes sense only for block device backed filesystems
974 * mounted with the 'blkdev' option
976 * If this request is answered with an error code of ENOSYS, this is
977 * treated as a permanent failure, i.e. all future bmap() requests will
978 * fail with the same error code without being send to the filesystem
979 * process.
981 * Valid replies:
982 * fuse_reply_bmap
983 * fuse_reply_err
985 * @param req request handle
986 * @param ino the inode number
987 * @param blocksize unit of block index
988 * @param idx block index within file
990 void (*bmap)(fuse_req_t req, fuse_ino_t ino, size_t blocksize,
991 uint64_t idx);
994 * Ioctl
996 * Note: For unrestricted ioctls (not allowed for FUSE
997 * servers), data in and out areas can be discovered by giving
998 * iovs and setting FUSE_IOCTL_RETRY in *flags*. For
999 * restricted ioctls, kernel prepares in/out data area
1000 * according to the information encoded in cmd.
1002 * Valid replies:
1003 * fuse_reply_ioctl_retry
1004 * fuse_reply_ioctl
1005 * fuse_reply_ioctl_iov
1006 * fuse_reply_err
1008 * @param req request handle
1009 * @param ino the inode number
1010 * @param cmd ioctl command
1011 * @param arg ioctl argument
1012 * @param fi file information
1013 * @param flags for FUSE_IOCTL_* flags
1014 * @param in_buf data fetched from the caller
1015 * @param in_bufsz number of fetched bytes
1016 * @param out_bufsz maximum size of output data
1018 * Note : the unsigned long request submitted by the application
1019 * is truncated to 32 bits.
1021 void (*ioctl)(fuse_req_t req, fuse_ino_t ino, unsigned int cmd, void *arg,
1022 struct fuse_file_info *fi, unsigned flags, const void *in_buf,
1023 size_t in_bufsz, size_t out_bufsz);
1026 * Poll for IO readiness
1028 * Note: If ph is non-NULL, the client should notify
1029 * when IO readiness events occur by calling
1030 * fuse_lowlevel_notify_poll() with the specified ph.
1032 * Regardless of the number of times poll with a non-NULL ph
1033 * is received, single notification is enough to clear all.
1034 * Notifying more times incurs overhead but doesn't harm
1035 * correctness.
1037 * The callee is responsible for destroying ph with
1038 * fuse_pollhandle_destroy() when no longer in use.
1040 * If this request is answered with an error code of ENOSYS, this is
1041 * treated as success (with a kernel-defined default poll-mask) and
1042 * future calls to pull() will succeed the same way without being send
1043 * to the filesystem process.
1045 * Valid replies:
1046 * fuse_reply_poll
1047 * fuse_reply_err
1049 * @param req request handle
1050 * @param ino the inode number
1051 * @param fi file information
1052 * @param ph poll handle to be used for notification
1054 void (*poll)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1055 struct fuse_pollhandle *ph);
1058 * Write data made available in a buffer
1060 * This is a more generic version of the ->write() method. If
1061 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
1062 * kernel supports splicing from the fuse device, then the
1063 * data will be made available in pipe for supporting zero
1064 * copy data transfer.
1066 * buf->count is guaranteed to be one (and thus buf->idx is
1067 * always zero). The write_buf handler must ensure that
1068 * bufv->off is correctly updated (reflecting the number of
1069 * bytes read from bufv->buf[0]).
1071 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
1072 * expected to reset the setuid and setgid bits.
1074 * Valid replies:
1075 * fuse_reply_write
1076 * fuse_reply_err
1078 * @param req request handle
1079 * @param ino the inode number
1080 * @param bufv buffer containing the data
1081 * @param off offset to write to
1082 * @param fi file information
1084 void (*write_buf)(fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv,
1085 off_t off, struct fuse_file_info *fi);
1088 * Callback function for the retrieve request
1090 * Valid replies:
1091 * fuse_reply_none
1093 * @param req request handle
1094 * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
1095 * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
1096 * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
1097 * @param bufv the buffer containing the returned data
1099 void (*retrieve_reply)(fuse_req_t req, void *cookie, fuse_ino_t ino,
1100 off_t offset, struct fuse_bufvec *bufv);
1103 * Forget about multiple inodes
1105 * See description of the forget function for more
1106 * information.
1108 * Valid replies:
1109 * fuse_reply_none
1111 * @param req request handle
1113 void (*forget_multi)(fuse_req_t req, size_t count,
1114 struct fuse_forget_data *forgets);
1117 * Acquire, modify or release a BSD file lock
1119 * Note: if the locking methods are not implemented, the kernel
1120 * will still allow file locking to work locally. Hence these are
1121 * only interesting for network filesystems and similar.
1123 * Valid replies:
1124 * fuse_reply_err
1126 * @param req request handle
1127 * @param ino the inode number
1128 * @param fi file information
1129 * @param op the locking operation, see flock(2)
1131 void (*flock)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1132 int op);
1135 * Allocate requested space. If this function returns success then
1136 * subsequent writes to the specified range shall not fail due to the lack
1137 * of free space on the file system storage media.
1139 * If this request is answered with an error code of ENOSYS, this is
1140 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1141 * future fallocate() requests will fail with EOPNOTSUPP without being
1142 * send to the filesystem process.
1144 * Valid replies:
1145 * fuse_reply_err
1147 * @param req request handle
1148 * @param ino the inode number
1149 * @param offset starting point for allocated region
1150 * @param length size of allocated region
1151 * @param mode determines the operation to be performed on the given range,
1152 * see fallocate(2)
1154 void (*fallocate)(fuse_req_t req, fuse_ino_t ino, int mode, off_t offset,
1155 off_t length, struct fuse_file_info *fi);
1158 * Read directory with attributes
1160 * Send a buffer filled using fuse_add_direntry_plus(), with size not
1161 * exceeding the requested size. Send an empty buffer on end of
1162 * stream.
1164 * fi->fh will contain the value set by the opendir method, or
1165 * will be undefined if the opendir method didn't set any value.
1167 * In contrast to readdir() (which does not affect the lookup counts),
1168 * the lookup count of every entry returned by readdirplus(), except "."
1169 * and "..", is incremented by one.
1171 * Valid replies:
1172 * fuse_reply_buf
1173 * fuse_reply_data
1174 * fuse_reply_err
1176 * @param req request handle
1177 * @param ino the inode number
1178 * @param size maximum number of bytes to send
1179 * @param off offset to continue reading the directory stream
1180 * @param fi file information
1182 void (*readdirplus)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1183 struct fuse_file_info *fi);
1186 * Copy a range of data from one file to another
1188 * Performs an optimized copy between two file descriptors without the
1189 * additional cost of transferring data through the FUSE kernel module
1190 * to user space (glibc) and then back into the FUSE filesystem again.
1192 * In case this method is not implemented, glibc falls back to reading
1193 * data from the source and writing to the destination. Effectively
1194 * doing an inefficient copy of the data.
1196 * If this request is answered with an error code of ENOSYS, this is
1197 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1198 * future copy_file_range() requests will fail with EOPNOTSUPP without
1199 * being send to the filesystem process.
1201 * Valid replies:
1202 * fuse_reply_write
1203 * fuse_reply_err
1205 * @param req request handle
1206 * @param ino_in the inode number or the source file
1207 * @param off_in starting point from were the data should be read
1208 * @param fi_in file information of the source file
1209 * @param ino_out the inode number or the destination file
1210 * @param off_out starting point where the data should be written
1211 * @param fi_out file information of the destination file
1212 * @param len maximum size of the data to copy
1213 * @param flags passed along with the copy_file_range() syscall
1215 void (*copy_file_range)(fuse_req_t req, fuse_ino_t ino_in, off_t off_in,
1216 struct fuse_file_info *fi_in, fuse_ino_t ino_out,
1217 off_t off_out, struct fuse_file_info *fi_out,
1218 size_t len, int flags);
1221 * Find next data or hole after the specified offset
1223 * If this request is answered with an error code of ENOSYS, this is
1224 * treated as a permanent failure, i.e. all future lseek() requests will
1225 * fail with the same error code without being send to the filesystem
1226 * process.
1228 * Valid replies:
1229 * fuse_reply_lseek
1230 * fuse_reply_err
1232 * @param req request handle
1233 * @param ino the inode number
1234 * @param off offset to start search from
1235 * @param whence either SEEK_DATA or SEEK_HOLE
1236 * @param fi file information
1238 void (*lseek)(fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1239 struct fuse_file_info *fi);
1243 * Reply with an error code or success.
1245 * Possible requests:
1246 * all except forget
1248 * Whereever possible, error codes should be chosen from the list of
1249 * documented error conditions in the corresponding system calls
1250 * manpage.
1252 * An error code of ENOSYS is sometimes treated specially. This is
1253 * indicated in the documentation of the affected handler functions.
1255 * The following requests may be answered with a zero error code:
1256 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1257 * removexattr, setlk.
1259 * @param req request handle
1260 * @param err the positive error value, or zero for success
1261 * @return zero for success, -errno for failure to send reply
1263 int fuse_reply_err(fuse_req_t req, int err);
1266 * Don't send reply
1268 * Possible requests:
1269 * forget
1270 * forget_multi
1271 * retrieve_reply
1273 * @param req request handle
1275 void fuse_reply_none(fuse_req_t req);
1278 * Reply with a directory entry
1280 * Possible requests:
1281 * lookup, mknod, mkdir, symlink, link
1283 * Side effects:
1284 * increments the lookup count on success
1286 * @param req request handle
1287 * @param e the entry parameters
1288 * @return zero for success, -errno for failure to send reply
1290 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1293 * Reply with a directory entry and open parameters
1295 * currently the following members of 'fi' are used:
1296 * fh, direct_io, keep_cache
1298 * Possible requests:
1299 * create
1301 * Side effects:
1302 * increments the lookup count on success
1304 * @param req request handle
1305 * @param e the entry parameters
1306 * @param fi file information
1307 * @return zero for success, -errno for failure to send reply
1309 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1310 const struct fuse_file_info *fi);
1313 * Reply with attributes
1315 * Possible requests:
1316 * getattr, setattr
1318 * @param req request handle
1319 * @param attr the attributes
1320 * @param attr_timeout validity timeout (in seconds) for the attributes
1321 * @return zero for success, -errno for failure to send reply
1323 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1324 double attr_timeout);
1327 * Reply with the contents of a symbolic link
1329 * Possible requests:
1330 * readlink
1332 * @param req request handle
1333 * @param link symbolic link contents
1334 * @return zero for success, -errno for failure to send reply
1336 int fuse_reply_readlink(fuse_req_t req, const char *link);
1339 * Reply with open parameters
1341 * currently the following members of 'fi' are used:
1342 * fh, direct_io, keep_cache
1344 * Possible requests:
1345 * open, opendir
1347 * @param req request handle
1348 * @param fi file information
1349 * @return zero for success, -errno for failure to send reply
1351 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1354 * Reply with number of bytes written
1356 * Possible requests:
1357 * write
1359 * @param req request handle
1360 * @param count the number of bytes written
1361 * @return zero for success, -errno for failure to send reply
1363 int fuse_reply_write(fuse_req_t req, size_t count);
1366 * Reply with data
1368 * Possible requests:
1369 * read, readdir, getxattr, listxattr
1371 * @param req request handle
1372 * @param buf buffer containing data
1373 * @param size the size of data in bytes
1374 * @return zero for success, -errno for failure to send reply
1376 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1379 * Reply with data copied/moved from buffer(s)
1381 * Zero copy data transfer ("splicing") will be used under
1382 * the following circumstances:
1384 * 1. FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.want, and
1385 * 2. the kernel supports splicing from the fuse device
1386 * (FUSE_CAP_SPLICE_WRITE is set in fuse_conn_info.capable), and
1387 * 3. *flags* does not contain FUSE_BUF_NO_SPLICE
1388 * 4. The amount of data that is provided in file-descriptor backed
1389 * buffers (i.e., buffers for which bufv[n].flags == FUSE_BUF_FD)
1390 * is at least twice the page size.
1392 * In order for SPLICE_F_MOVE to be used, the following additional
1393 * conditions have to be fulfilled:
1395 * 1. FUSE_CAP_SPLICE_MOVE is set in fuse_conn_info.want, and
1396 * 2. the kernel supports it (i.e, FUSE_CAP_SPLICE_MOVE is set in
1397 fuse_conn_info.capable), and
1398 * 3. *flags* contains FUSE_BUF_SPLICE_MOVE
1400 * Note that, if splice is used, the data is actually spliced twice:
1401 * once into a temporary pipe (to prepend header data), and then again
1402 * into the kernel. If some of the provided buffers are memory-backed,
1403 * the data in them is copied in step one and spliced in step two.
1405 * The FUSE_BUF_SPLICE_FORCE_SPLICE and FUSE_BUF_SPLICE_NONBLOCK flags
1406 * are silently ignored.
1408 * Possible requests:
1409 * read, readdir, getxattr, listxattr
1411 * Side effects:
1412 * when used to return data from a readdirplus() (but not readdir())
1413 * call, increments the lookup count of each returned entry by one
1414 * on success.
1416 * @param req request handle
1417 * @param bufv buffer vector
1418 * @param flags flags controlling the copy
1419 * @return zero for success, -errno for failure to send reply
1421 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1422 enum fuse_buf_copy_flags flags);
1425 * Reply with data vector
1427 * Possible requests:
1428 * read, readdir, getxattr, listxattr
1430 * @param req request handle
1431 * @param iov the vector containing the data
1432 * @param count the size of vector
1433 * @return zero for success, -errno for failure to send reply
1435 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1438 * Reply with filesystem statistics
1440 * Possible requests:
1441 * statfs
1443 * @param req request handle
1444 * @param stbuf filesystem statistics
1445 * @return zero for success, -errno for failure to send reply
1447 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1450 * Reply with needed buffer size
1452 * Possible requests:
1453 * getxattr, listxattr
1455 * @param req request handle
1456 * @param count the buffer size needed in bytes
1457 * @return zero for success, -errno for failure to send reply
1459 int fuse_reply_xattr(fuse_req_t req, size_t count);
1462 * Reply with file lock information
1464 * Possible requests:
1465 * getlk
1467 * @param req request handle
1468 * @param lock the lock information
1469 * @return zero for success, -errno for failure to send reply
1471 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1474 * Reply with block index
1476 * Possible requests:
1477 * bmap
1479 * @param req request handle
1480 * @param idx block index within device
1481 * @return zero for success, -errno for failure to send reply
1483 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1486 * Filling a buffer in readdir
1490 * Add a directory entry to the buffer
1492 * Buffer needs to be large enough to hold the entry. If it's not,
1493 * then the entry is not filled in but the size of the entry is still
1494 * returned. The caller can check this by comparing the bufsize
1495 * parameter with the returned entry size. If the entry size is
1496 * larger than the buffer size, the operation failed.
1498 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1499 * st_mode field are used. The other fields are ignored.
1501 * *off* should be any non-zero value that the filesystem can use to
1502 * identify the current point in the directory stream. It does not
1503 * need to be the actual physical position. A value of zero is
1504 * reserved to mean "from the beginning", and should therefore never
1505 * be used (the first call to fuse_add_direntry should be passed the
1506 * offset of the second directory entry).
1508 * @param req request handle
1509 * @param buf the point where the new entry will be added to the buffer
1510 * @param bufsize remaining size of the buffer
1511 * @param name the name of the entry
1512 * @param stbuf the file attributes
1513 * @param off the offset of the next entry
1514 * @return the space needed for the entry
1516 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1517 const char *name, const struct stat *stbuf, off_t off);
1520 * Add a directory entry to the buffer with the attributes
1522 * See documentation of `fuse_add_direntry()` for more details.
1524 * @param req request handle
1525 * @param buf the point where the new entry will be added to the buffer
1526 * @param bufsize remaining size of the buffer
1527 * @param name the name of the entry
1528 * @param e the directory entry
1529 * @param off the offset of the next entry
1530 * @return the space needed for the entry
1532 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1533 const char *name,
1534 const struct fuse_entry_param *e, off_t off);
1537 * Reply to ask for data fetch and output buffer preparation. ioctl
1538 * will be retried with the specified input data fetched and output
1539 * buffer prepared.
1541 * Possible requests:
1542 * ioctl
1544 * @param req request handle
1545 * @param in_iov iovec specifying data to fetch from the caller
1546 * @param in_count number of entries in in_iov
1547 * @param out_iov iovec specifying addresses to write output to
1548 * @param out_count number of entries in out_iov
1549 * @return zero for success, -errno for failure to send reply
1551 int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
1552 size_t in_count, const struct iovec *out_iov,
1553 size_t out_count);
1556 * Reply to finish ioctl
1558 * Possible requests:
1559 * ioctl
1561 * @param req request handle
1562 * @param result result to be passed to the caller
1563 * @param buf buffer containing output data
1564 * @param size length of output data
1566 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1569 * Reply to finish ioctl with iov buffer
1571 * Possible requests:
1572 * ioctl
1574 * @param req request handle
1575 * @param result result to be passed to the caller
1576 * @param iov the vector containing the data
1577 * @param count the size of vector
1579 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1580 int count);
1583 * Reply with poll result event mask
1585 * @param req request handle
1586 * @param revents poll result event mask
1588 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1591 * Reply with offset
1593 * Possible requests:
1594 * lseek
1596 * @param req request handle
1597 * @param off offset of next data or hole
1598 * @return zero for success, -errno for failure to send reply
1600 int fuse_reply_lseek(fuse_req_t req, off_t off);
1603 * Notification
1607 * Notify IO readiness event
1609 * For more information, please read comment for poll operation.
1611 * @param ph poll handle to notify IO readiness event for
1613 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1616 * Notify to invalidate cache for an inode.
1618 * Added in FUSE protocol version 7.12. If the kernel does not support
1619 * this (or a newer) version, the function will return -ENOSYS and do
1620 * nothing.
1622 * If the filesystem has writeback caching enabled, invalidating an
1623 * inode will first trigger a writeback of all dirty pages. The call
1624 * will block until all writeback requests have completed and the
1625 * inode has been invalidated. It will, however, not wait for
1626 * completion of pending writeback requests that have been issued
1627 * before.
1629 * If there are no dirty pages, this function will never block.
1631 * @param se the session object
1632 * @param ino the inode number
1633 * @param off the offset in the inode where to start invalidating
1634 * or negative to invalidate attributes only
1635 * @param len the amount of cache to invalidate or 0 for all
1636 * @return zero for success, -errno for failure
1638 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1639 off_t off, off_t len);
1642 * Notify to invalidate parent attributes and the dentry matching
1643 * parent/name
1645 * To avoid a deadlock this function must not be called in the
1646 * execution path of a related filesytem operation or within any code
1647 * that could hold a lock that could be needed to execute such an
1648 * operation. As of kernel 4.18, a "related operation" is a lookup(),
1649 * symlink(), mknod(), mkdir(), unlink(), rename(), link() or create()
1650 * request for the parent, and a setattr(), unlink(), rmdir(),
1651 * rename(), setxattr(), removexattr(), readdir() or readdirplus()
1652 * request for the inode itself.
1654 * When called correctly, this function will never block.
1656 * Added in FUSE protocol version 7.12. If the kernel does not support
1657 * this (or a newer) version, the function will return -ENOSYS and do
1658 * nothing.
1660 * @param se the session object
1661 * @param parent inode number
1662 * @param name file name
1663 * @param namelen strlen() of file name
1664 * @return zero for success, -errno for failure
1666 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1667 const char *name, size_t namelen);
1670 * This function behaves like fuse_lowlevel_notify_inval_entry() with
1671 * the following additional effect (at least as of Linux kernel 4.8):
1673 * If the provided *child* inode matches the inode that is currently
1674 * associated with the cached dentry, and if there are any inotify
1675 * watches registered for the dentry, then the watchers are informed
1676 * that the dentry has been deleted.
1678 * To avoid a deadlock this function must not be called while
1679 * executing a related filesytem operation or while holding a lock
1680 * that could be needed to execute such an operation (see the
1681 * description of fuse_lowlevel_notify_inval_entry() for more
1682 * details).
1684 * When called correctly, this function will never block.
1686 * Added in FUSE protocol version 7.18. If the kernel does not support
1687 * this (or a newer) version, the function will return -ENOSYS and do
1688 * nothing.
1690 * @param se the session object
1691 * @param parent inode number
1692 * @param child inode number
1693 * @param name file name
1694 * @param namelen strlen() of file name
1695 * @return zero for success, -errno for failure
1697 int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent,
1698 fuse_ino_t child, const char *name,
1699 size_t namelen);
1702 * Store data to the kernel buffers
1704 * Synchronously store data in the kernel buffers belonging to the
1705 * given inode. The stored data is marked up-to-date (no read will be
1706 * performed against it, unless it's invalidated or evicted from the
1707 * cache).
1709 * If the stored data overflows the current file size, then the size
1710 * is extended, similarly to a write(2) on the filesystem.
1712 * If this function returns an error, then the store wasn't fully
1713 * completed, but it may have been partially completed.
1715 * Added in FUSE protocol version 7.15. If the kernel does not support
1716 * this (or a newer) version, the function will return -ENOSYS and do
1717 * nothing.
1719 * @param se the session object
1720 * @param ino the inode number
1721 * @param offset the starting offset into the file to store to
1722 * @param bufv buffer vector
1723 * @param flags flags controlling the copy
1724 * @return zero for success, -errno for failure
1726 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1727 off_t offset, struct fuse_bufvec *bufv,
1728 enum fuse_buf_copy_flags flags);
1730 * Retrieve data from the kernel buffers
1732 * Retrieve data in the kernel buffers belonging to the given inode.
1733 * If successful then the retrieve_reply() method will be called with
1734 * the returned data.
1736 * Only present pages are returned in the retrieve reply. Retrieving
1737 * stops when it finds a non-present page and only data prior to that
1738 * is returned.
1740 * If this function returns an error, then the retrieve will not be
1741 * completed and no reply will be sent.
1743 * This function doesn't change the dirty state of pages in the kernel
1744 * buffer. For dirty pages the write() method will be called
1745 * regardless of having been retrieved previously.
1747 * Added in FUSE protocol version 7.15. If the kernel does not support
1748 * this (or a newer) version, the function will return -ENOSYS and do
1749 * nothing.
1751 * @param se the session object
1752 * @param ino the inode number
1753 * @param size the number of bytes to retrieve
1754 * @param offset the starting offset into the file to retrieve from
1755 * @param cookie user data to supply to the reply callback
1756 * @return zero for success, -errno for failure
1758 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
1759 size_t size, off_t offset, void *cookie);
1763 * Utility functions
1767 * Get the userdata from the request
1769 * @param req request handle
1770 * @return the user data passed to fuse_session_new()
1772 void *fuse_req_userdata(fuse_req_t req);
1775 * Get the context from the request
1777 * The pointer returned by this function will only be valid for the
1778 * request's lifetime
1780 * @param req request handle
1781 * @return the context structure
1783 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1786 * Get the current supplementary group IDs for the specified request
1788 * Similar to the getgroups(2) system call, except the return value is
1789 * always the total number of group IDs, even if it is larger than the
1790 * specified size.
1792 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1793 * the group list to userspace, hence this function needs to parse
1794 * "/proc/$TID/task/$TID/status" to get the group IDs.
1796 * This feature may not be supported on all operating systems. In
1797 * such a case this function will return -ENOSYS.
1799 * @param req request handle
1800 * @param size size of given array
1801 * @param list array of group IDs to be filled in
1802 * @return the total number of supplementary group IDs or -errno on failure
1804 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1807 * Callback function for an interrupt
1809 * @param req interrupted request
1810 * @param data user data
1812 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1815 * Register/unregister callback for an interrupt
1817 * If an interrupt has already happened, then the callback function is
1818 * called from within this function, hence it's not possible for
1819 * interrupts to be lost.
1821 * @param req request handle
1822 * @param func the callback function or NULL for unregister
1823 * @param data user data passed to the callback function
1825 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1826 void *data);
1829 * Check if a request has already been interrupted
1831 * @param req request handle
1832 * @return 1 if the request has been interrupted, 0 otherwise
1834 int fuse_req_interrupted(fuse_req_t req);
1838 * Inquiry functions
1842 * Print low-level version information to stdout.
1844 void fuse_lowlevel_version(void);
1847 * Print available low-level options to stdout. This is not an
1848 * exhaustive list, but includes only those options that may be of
1849 * interest to an end-user of a file system.
1851 void fuse_lowlevel_help(void);
1854 * Print available options for `fuse_parse_cmdline()`.
1856 void fuse_cmdline_help(void);
1859 * Filesystem setup & teardown
1862 struct fuse_cmdline_opts {
1863 int foreground;
1864 int debug;
1865 int nodefault_subtype;
1866 char *mountpoint;
1867 int show_version;
1868 int show_help;
1869 unsigned int max_idle_threads;
1873 * Utility function to parse common options for simple file systems
1874 * using the low-level API. A help text that describes the available
1875 * options can be printed with `fuse_cmdline_help`. A single
1876 * non-option argument is treated as the mountpoint. Multiple
1877 * non-option arguments will result in an error.
1879 * If neither -o subtype= or -o fsname= options are given, a new
1880 * subtype option will be added and set to the basename of the program
1881 * (the fsname will remain unset, and then defaults to "fuse").
1883 * Known options will be removed from *args*, unknown options will
1884 * remain.
1886 * @param args argument vector (input+output)
1887 * @param opts output argument for parsed options
1888 * @return 0 on success, -1 on failure
1890 int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts);
1893 * Create a low level session.
1895 * Returns a session structure suitable for passing to
1896 * fuse_session_mount() and fuse_session_loop().
1898 * This function accepts most file-system independent mount options
1899 * (like context, nodev, ro - see mount(8)), as well as the general
1900 * fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and
1901 * -o default_permissions, but not ``-o use_ino``). Instead of `-o
1902 * debug`, debugging may also enabled with `-d` or `--debug`.
1904 * If not all options are known, an error message is written to stderr
1905 * and the function returns NULL.
1907 * Option parsing skips argv[0], which is assumed to contain the
1908 * program name. To prevent accidentally passing an option in
1909 * argv[0], this element must always be present (even if no options
1910 * are specified). It may be set to the empty string ('\0') if no
1911 * reasonable value can be provided.
1913 * @param args argument vector
1914 * @param op the (low-level) filesystem operations
1915 * @param op_size sizeof(struct fuse_lowlevel_ops)
1916 * @param userdata user data
1918 * @return the fuse session on success, NULL on failure
1920 struct fuse_session *fuse_session_new(struct fuse_args *args,
1921 const struct fuse_lowlevel_ops *op,
1922 size_t op_size, void *userdata);
1925 * Mount a FUSE file system.
1927 * @param mountpoint the mount point path
1928 * @param se session object
1930 * @return 0 on success, -1 on failure.
1932 int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
1935 * Enter a single threaded, blocking event loop.
1937 * When the event loop terminates because the connection to the FUSE
1938 * kernel module has been closed, this function returns zero. This
1939 * happens when the filesystem is unmounted regularly (by the
1940 * filesystem owner or root running the umount(8) or fusermount(1)
1941 * command), or if connection is explicitly severed by writing ``1``
1942 * to the``abort`` file in ``/sys/fs/fuse/connections/NNN``. The only
1943 * way to distinguish between these two conditions is to check if the
1944 * filesystem is still mounted after the session loop returns.
1946 * When some error occurs during request processing, the function
1947 * returns a negated errno(3) value.
1949 * If the loop has been terminated because of a signal handler
1950 * installed by fuse_set_signal_handlers(), this function returns the
1951 * (positive) signal value that triggered the exit.
1953 * @param se the session
1954 * @return 0, -errno, or a signal value
1956 int fuse_session_loop(struct fuse_session *se);
1959 * Flag a session as terminated.
1961 * This function is invoked by the POSIX signal handlers, when
1962 * registered using fuse_set_signal_handlers(). It will cause any
1963 * running event loops to terminate on the next opportunity.
1965 * @param se the session
1967 void fuse_session_exit(struct fuse_session *se);
1970 * Reset the terminated flag of a session
1972 * @param se the session
1974 void fuse_session_reset(struct fuse_session *se);
1977 * Query the terminated flag of a session
1979 * @param se the session
1980 * @return 1 if exited, 0 if not exited
1982 int fuse_session_exited(struct fuse_session *se);
1985 * Ensure that file system is unmounted.
1987 * In regular operation, the file system is typically unmounted by the
1988 * user calling umount(8) or fusermount(1), which then terminates the
1989 * FUSE session loop. However, the session loop may also terminate as
1990 * a result of an explicit call to fuse_session_exit() (e.g. by a
1991 * signal handler installed by fuse_set_signal_handler()). In this
1992 * case the filesystem remains mounted, but any attempt to access it
1993 * will block (while the filesystem process is still running) or give
1994 * an ESHUTDOWN error (after the filesystem process has terminated).
1996 * If the communication channel with the FUSE kernel module is still
1997 * open (i.e., if the session loop was terminated by an explicit call
1998 * to fuse_session_exit()), this function will close it and unmount
1999 * the filesystem. If the communication channel has been closed by the
2000 * kernel, this method will do (almost) nothing.
2002 * NOTE: The above semantics mean that if the connection to the kernel
2003 * is terminated via the ``/sys/fs/fuse/connections/NNN/abort`` file,
2004 * this method will *not* unmount the filesystem.
2006 * @param se the session
2008 void fuse_session_unmount(struct fuse_session *se);
2011 * Destroy a session
2013 * @param se the session
2015 void fuse_session_destroy(struct fuse_session *se);
2018 * Custom event loop support
2022 * Return file descriptor for communication with kernel.
2024 * The file selector can be used to integrate FUSE with a custom event
2025 * loop. Whenever data is available for reading on the provided fd,
2026 * the event loop should call `fuse_session_receive_buf` followed by
2027 * `fuse_session_process_buf` to process the request.
2029 * The returned file descriptor is valid until `fuse_session_unmount`
2030 * is called.
2032 * @param se the session
2033 * @return a file descriptor
2035 int fuse_session_fd(struct fuse_session *se);
2038 * Process a raw request supplied in a generic buffer
2040 * The fuse_buf may contain a memory buffer or a pipe file descriptor.
2042 * @param se the session
2043 * @param buf the fuse_buf containing the request
2045 void fuse_session_process_buf(struct fuse_session *se,
2046 const struct fuse_buf *buf);
2049 * Read a raw request from the kernel into the supplied buffer.
2051 * Depending on file system options, system capabilities, and request
2052 * size the request is either read into a memory buffer or spliced
2053 * into a temporary pipe.
2055 * @param se the session
2056 * @param buf the fuse_buf to store the request in
2057 * @return the actual size of the raw request, or -errno on error
2059 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
2061 #endif /* FUSE_LOWLEVEL_H_ */