target/ppc: Fix 7448 support
[qemu.git] / tools / virtiofsd / fuse_lowlevel.h
blobc55c0ca2fc1c09e137c46cacdc5589e2146325f6
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)
146 #define FUSE_SET_ATTR_KILL_SUIDGID (1 << 11)
149 * Request methods and replies
153 * Low level filesystem operations
155 * Most of the methods (with the exception of init and destroy)
156 * receive a request handle (fuse_req_t) as their first argument.
157 * This handle must be passed to one of the specified reply functions.
159 * This may be done inside the method invocation, or after the call
160 * has returned. The request handle is valid until one of the reply
161 * functions is called.
163 * Other pointer arguments (name, fuse_file_info, etc) are not valid
164 * after the call has returned, so if they are needed later, their
165 * contents have to be copied.
167 * In general, all methods are expected to perform any necessary
168 * permission checking. However, a filesystem may delegate this task
169 * to the kernel by passing the `default_permissions` mount option to
170 * `fuse_session_new()`. In this case, methods will only be called if
171 * the kernel's permission check has succeeded.
173 * The filesystem sometimes needs to handle a return value of -ENOENT
174 * from the reply function, which means, that the request was
175 * interrupted, and the reply discarded. For example if
176 * fuse_reply_open() return -ENOENT means, that the release method for
177 * this file will not be called.
179 struct fuse_lowlevel_ops {
181 * Initialize filesystem
183 * This function is called when libfuse establishes
184 * communication with the FUSE kernel module. The file system
185 * should use this module to inspect and/or modify the
186 * connection parameters provided in the `conn` structure.
188 * Note that some parameters may be overwritten by options
189 * passed to fuse_session_new() which take precedence over the
190 * values set in this handler.
192 * There's no reply to this function
194 * @param userdata the user data passed to fuse_session_new()
196 void (*init)(void *userdata, struct fuse_conn_info *conn);
199 * Clean up filesystem.
201 * Called on filesystem exit. When this method is called, the
202 * connection to the kernel may be gone already, so that eg. calls
203 * to fuse_lowlevel_notify_* will fail.
205 * There's no reply to this function
207 * @param userdata the user data passed to fuse_session_new()
209 void (*destroy)(void *userdata);
212 * Look up a directory entry by name and get its attributes.
214 * Valid replies:
215 * fuse_reply_entry
216 * fuse_reply_err
218 * @param req request handle
219 * @param parent inode number of the parent directory
220 * @param name the name to look up
222 void (*lookup)(fuse_req_t req, fuse_ino_t parent, const char *name);
225 * Forget about an inode
227 * This function is called when the kernel removes an inode
228 * from its internal caches.
230 * The inode's lookup count increases by one for every call to
231 * fuse_reply_entry and fuse_reply_create. The nlookup parameter
232 * indicates by how much the lookup count should be decreased.
234 * Inodes with a non-zero lookup count may receive request from
235 * the kernel even after calls to unlink, rmdir or (when
236 * overwriting an existing file) rename. Filesystems must handle
237 * such requests properly and it is recommended to defer removal
238 * of the inode until the lookup count reaches zero. Calls to
239 * unlink, rmdir or rename will be followed closely by forget
240 * unless the file or directory is open, in which case the
241 * kernel issues forget only after the release or releasedir
242 * calls.
244 * Note that if a file system will be exported over NFS the
245 * inodes lifetime must extend even beyond forget. See the
246 * generation field in struct fuse_entry_param above.
248 * On unmount the lookup count for all inodes implicitly drops
249 * to zero. It is not guaranteed that the file system will
250 * receive corresponding forget messages for the affected
251 * inodes.
253 * Valid replies:
254 * fuse_reply_none
256 * @param req request handle
257 * @param ino the inode number
258 * @param nlookup the number of lookups to forget
260 void (*forget)(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
263 * Get file attributes.
265 * If writeback caching is enabled, the kernel may have a
266 * better idea of a file's length than the FUSE file system
267 * (eg if there has been a write that extended the file size,
268 * but that has not yet been passed to the filesystem.n
270 * In this case, the st_size value provided by the file system
271 * will be ignored.
273 * Valid replies:
274 * fuse_reply_attr
275 * fuse_reply_err
277 * @param req request handle
278 * @param ino the inode number
279 * @param fi for future use, currently always NULL
281 void (*getattr)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
284 * Set file attributes
286 * In the 'attr' argument only members indicated by the 'to_set'
287 * bitmask contain valid values. Other members contain undefined
288 * values.
290 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
291 * expected to reset the setuid and setgid bits if the file
292 * size or owner is being changed.
294 * If the setattr was invoked from the ftruncate() system call
295 * under Linux kernel versions 2.6.15 or later, the fi->fh will
296 * contain the value set by the open method or will be undefined
297 * if the open method didn't set any value. Otherwise (not
298 * ftruncate call, or kernel version earlier than 2.6.15) the fi
299 * parameter will be NULL.
301 * Valid replies:
302 * fuse_reply_attr
303 * fuse_reply_err
305 * @param req request handle
306 * @param ino the inode number
307 * @param attr the attributes
308 * @param to_set bit mask of attributes which should be set
309 * @param fi file information, or NULL
311 void (*setattr)(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
312 int to_set, struct fuse_file_info *fi);
315 * Read symbolic link
317 * Valid replies:
318 * fuse_reply_readlink
319 * fuse_reply_err
321 * @param req request handle
322 * @param ino the inode number
324 void (*readlink)(fuse_req_t req, fuse_ino_t ino);
327 * Create file node
329 * Create a regular file, character device, block device, fifo or
330 * socket node.
332 * Valid replies:
333 * fuse_reply_entry
334 * fuse_reply_err
336 * @param req request handle
337 * @param parent inode number of the parent directory
338 * @param name to create
339 * @param mode file type and mode with which to create the new file
340 * @param rdev the device number (only valid if created file is a device)
342 void (*mknod)(fuse_req_t req, fuse_ino_t parent, const char *name,
343 mode_t mode, dev_t rdev);
346 * Create a directory
348 * Valid replies:
349 * fuse_reply_entry
350 * fuse_reply_err
352 * @param req request handle
353 * @param parent inode number of the parent directory
354 * @param name to create
355 * @param mode with which to create the new file
357 void (*mkdir)(fuse_req_t req, fuse_ino_t parent, const char *name,
358 mode_t mode);
361 * Remove a file
363 * If the file's inode's lookup count is non-zero, the file
364 * system is expected to postpone any removal of the inode
365 * until the lookup count reaches zero (see description of the
366 * forget function).
368 * Valid replies:
369 * fuse_reply_err
371 * @param req request handle
372 * @param parent inode number of the parent directory
373 * @param name to remove
375 void (*unlink)(fuse_req_t req, fuse_ino_t parent, const char *name);
378 * Remove a directory
380 * If the directory's inode's lookup count is non-zero, the
381 * file system is expected to postpone any removal of the
382 * inode until the lookup count reaches zero (see description
383 * of the forget function).
385 * Valid replies:
386 * fuse_reply_err
388 * @param req request handle
389 * @param parent inode number of the parent directory
390 * @param name to remove
392 void (*rmdir)(fuse_req_t req, fuse_ino_t parent, const char *name);
395 * Create a symbolic link
397 * Valid replies:
398 * fuse_reply_entry
399 * fuse_reply_err
401 * @param req request handle
402 * @param link the contents of the symbolic link
403 * @param parent inode number of the parent directory
404 * @param name to create
406 void (*symlink)(fuse_req_t req, const char *link, fuse_ino_t parent,
407 const char *name);
410 * Rename a file
412 * If the target exists it should be atomically replaced. If
413 * the target's inode's lookup count is non-zero, the file
414 * system is expected to postpone any removal of the inode
415 * until the lookup count reaches zero (see description of the
416 * forget function).
418 * If this request is answered with an error code of ENOSYS, this is
419 * treated as a permanent failure with error code EINVAL, i.e. all
420 * future bmap requests will fail with EINVAL without being
421 * send to the filesystem process.
423 * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If
424 * RENAME_NOREPLACE is specified, the filesystem must not
425 * overwrite *newname* if it exists and return an error
426 * instead. If `RENAME_EXCHANGE` is specified, the filesystem
427 * must atomically exchange the two files, i.e. both must
428 * exist and neither may be deleted.
430 * Valid replies:
431 * fuse_reply_err
433 * @param req request handle
434 * @param parent inode number of the old parent directory
435 * @param name old name
436 * @param newparent inode number of the new parent directory
437 * @param newname new name
439 void (*rename)(fuse_req_t req, fuse_ino_t parent, const char *name,
440 fuse_ino_t newparent, const char *newname,
441 unsigned int flags);
444 * Create a hard link
446 * Valid replies:
447 * fuse_reply_entry
448 * fuse_reply_err
450 * @param req request handle
451 * @param ino the old inode number
452 * @param newparent inode number of the new parent directory
453 * @param newname new name to create
455 void (*link)(fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
456 const char *newname);
459 * Open a file
461 * Open flags are available in fi->flags. The following rules
462 * apply.
464 * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
465 * filtered out / handled by the kernel.
467 * - Access modes (O_RDONLY, O_WRONLY, O_RDWR) should be used
468 * by the filesystem to check if the operation is
469 * permitted. If the ``-o default_permissions`` mount
470 * option is given, this check is already done by the
471 * kernel before calling open() and may thus be omitted by
472 * the filesystem.
474 * - When writeback caching is enabled, the kernel may send
475 * read requests even for files opened with O_WRONLY. The
476 * filesystem should be prepared to handle this.
478 * - When writeback caching is disabled, the filesystem is
479 * expected to properly handle the O_APPEND flag and ensure
480 * that each write is appending to the end of the file.
482 * - When writeback caching is enabled, the kernel will
483 * handle O_APPEND. However, unless all changes to the file
484 * come through the kernel this will not work reliably. The
485 * filesystem should thus either ignore the O_APPEND flag
486 * (and let the kernel handle it), or return an error
487 * (indicating that reliably O_APPEND is not available).
489 * Filesystem may store an arbitrary file handle (pointer,
490 * index, etc) in fi->fh, and use this in other all other file
491 * operations (read, write, flush, release, fsync).
493 * Filesystem may also implement stateless file I/O and not store
494 * anything in fi->fh.
496 * There are also some flags (direct_io, keep_cache) which the
497 * filesystem may set in fi, to change the way the file is opened.
498 * See fuse_file_info structure in <fuse_common.h> for more details.
500 * If this request is answered with an error code of ENOSYS
501 * and FUSE_CAP_NO_OPEN_SUPPORT is set in
502 * `fuse_conn_info.capable`, this is treated as success and
503 * future calls to open and release will also succeed without being
504 * sent to the filesystem process.
506 * Valid replies:
507 * fuse_reply_open
508 * fuse_reply_err
510 * @param req request handle
511 * @param ino the inode number
512 * @param fi file information
514 void (*open)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
517 * Read data
519 * Read should send exactly the number of bytes requested except
520 * on EOF or error, otherwise the rest of the data will be
521 * substituted with zeroes. An exception to this is when the file
522 * has been opened in 'direct_io' mode, in which case the return
523 * value of the read system call will reflect the return value of
524 * this operation.
526 * fi->fh will contain the value set by the open method, or will
527 * be undefined if the open method didn't set any value.
529 * Valid replies:
530 * fuse_reply_buf
531 * fuse_reply_iov
532 * fuse_reply_data
533 * fuse_reply_err
535 * @param req request handle
536 * @param ino the inode number
537 * @param size number of bytes to read
538 * @param off offset to read from
539 * @param fi file information
541 void (*read)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
542 struct fuse_file_info *fi);
545 * Write data
547 * Write should return exactly the number of bytes requested
548 * except on error. An exception to this is when the file has
549 * been opened in 'direct_io' mode, in which case the return value
550 * of the write system call will reflect the return value of this
551 * operation.
553 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
554 * expected to reset the setuid and setgid bits.
556 * fi->fh will contain the value set by the open method, or will
557 * be undefined if the open method didn't set any value.
559 * Valid replies:
560 * fuse_reply_write
561 * fuse_reply_err
563 * @param req request handle
564 * @param ino the inode number
565 * @param buf data to write
566 * @param size number of bytes to write
567 * @param off offset to write to
568 * @param fi file information
570 void (*write)(fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size,
571 off_t off, struct fuse_file_info *fi);
574 * Flush method
576 * This is called on each close() of the opened file.
578 * Since file descriptors can be duplicated (dup, dup2, fork), for
579 * one open call there may be many flush calls.
581 * Filesystems shouldn't assume that flush will always be called
582 * after some writes, or that if will be called at all.
584 * fi->fh will contain the value set by the open method, or will
585 * be undefined if the open method didn't set any value.
587 * NOTE: the name of the method is misleading, since (unlike
588 * fsync) the filesystem is not forced to flush pending writes.
589 * One reason to flush data is if the filesystem wants to return
590 * write errors during close. However, such use is non-portable
591 * because POSIX does not require [close] to wait for delayed I/O to
592 * complete.
594 * If the filesystem supports file locking operations (setlk,
595 * getlk) it should remove all locks belonging to 'fi->owner'.
597 * If this request is answered with an error code of ENOSYS,
598 * this is treated as success and future calls to flush() will
599 * succeed automatically without being send to the filesystem
600 * process.
602 * Valid replies:
603 * fuse_reply_err
605 * @param req request handle
606 * @param ino the inode number
607 * @param fi file information
609 * [close]:
610 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
612 void (*flush)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
615 * Release an open file
617 * Release is called when there are no more references to an open
618 * file: all file descriptors are closed and all memory mappings
619 * are unmapped.
621 * For every open call there will be exactly one release call (unless
622 * the filesystem is force-unmounted).
624 * The filesystem may reply with an error, but error values are
625 * not returned to close() or munmap() which triggered the
626 * release.
628 * fi->fh will contain the value set by the open method, or will
629 * be undefined if the open method didn't set any value.
630 * fi->flags will contain the same flags as for open.
632 * Valid replies:
633 * fuse_reply_err
635 * @param req request handle
636 * @param ino the inode number
637 * @param fi file information
639 void (*release)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
642 * Synchronize file contents
644 * If the datasync parameter is non-zero, then only the user data
645 * should be flushed, not the meta data.
647 * If this request is answered with an error code of ENOSYS,
648 * this is treated as success and future calls to fsync() will
649 * succeed automatically without being send to the filesystem
650 * process.
652 * Valid replies:
653 * fuse_reply_err
655 * @param req request handle
656 * @param ino the inode number
657 * @param datasync flag indicating if only data should be flushed
658 * @param fi file information
660 void (*fsync)(fuse_req_t req, fuse_ino_t ino, int datasync,
661 struct fuse_file_info *fi);
664 * Open a directory
666 * Filesystem may store an arbitrary file handle (pointer, index,
667 * etc) in fi->fh, and use this in other all other directory
668 * stream operations (readdir, releasedir, fsyncdir).
670 * If this request is answered with an error code of ENOSYS and
671 * FUSE_CAP_NO_OPENDIR_SUPPORT is set in `fuse_conn_info.capable`,
672 * this is treated as success and future calls to opendir and
673 * releasedir will also succeed without being sent to the filesystem
674 * process. In addition, the kernel will cache readdir results
675 * as if opendir returned FOPEN_KEEP_CACHE | FOPEN_CACHE_DIR.
677 * Valid replies:
678 * fuse_reply_open
679 * fuse_reply_err
681 * @param req request handle
682 * @param ino the inode number
683 * @param fi file information
685 void (*opendir)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
688 * Read directory
690 * Send a buffer filled using fuse_add_direntry(), with size not
691 * exceeding the requested size. Send an empty buffer on end of
692 * stream.
694 * fi->fh will contain the value set by the opendir method, or
695 * will be undefined if the opendir method didn't set any value.
697 * Returning a directory entry from readdir() does not affect
698 * its lookup count.
700 * If off_t is non-zero, then it will correspond to one of the off_t
701 * values that was previously returned by readdir() for the same
702 * directory handle. In this case, readdir() should skip over entries
703 * coming before the position defined by the off_t value. If entries
704 * are added or removed while the directory handle is open, they filesystem
705 * may still include the entries that have been removed, and may not
706 * report the entries that have been created. However, addition or
707 * removal of entries must never cause readdir() to skip over unrelated
708 * entries or to report them more than once. This means
709 * that off_t can not be a simple index that enumerates the entries
710 * that have been returned but must contain sufficient information to
711 * uniquely determine the next directory entry to return even when the
712 * set of entries is changing.
714 * The function does not have to report the '.' and '..'
715 * entries, but is allowed to do so. Note that, if readdir does
716 * not return '.' or '..', they will not be implicitly returned,
717 * and this behavior is observable by the caller.
719 * Valid replies:
720 * fuse_reply_buf
721 * fuse_reply_data
722 * fuse_reply_err
724 * @param req request handle
725 * @param ino the inode number
726 * @param size maximum number of bytes to send
727 * @param off offset to continue reading the directory stream
728 * @param fi file information
730 void (*readdir)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
731 struct fuse_file_info *fi);
734 * Release an open directory
736 * For every opendir call there will be exactly one releasedir
737 * call (unless the filesystem is force-unmounted).
739 * fi->fh will contain the value set by the opendir method, or
740 * will be undefined if the opendir method didn't set any value.
742 * Valid replies:
743 * fuse_reply_err
745 * @param req request handle
746 * @param ino the inode number
747 * @param fi file information
749 void (*releasedir)(fuse_req_t req, fuse_ino_t ino,
750 struct fuse_file_info *fi);
753 * Synchronize directory contents
755 * If the datasync parameter is non-zero, then only the directory
756 * contents should be flushed, not the meta data.
758 * fi->fh will contain the value set by the opendir method, or
759 * will be undefined if the opendir method didn't set any value.
761 * If this request is answered with an error code of ENOSYS,
762 * this is treated as success and future calls to fsyncdir() will
763 * succeed automatically without being send to the filesystem
764 * process.
766 * Valid replies:
767 * fuse_reply_err
769 * @param req request handle
770 * @param ino the inode number
771 * @param datasync flag indicating if only data should be flushed
772 * @param fi file information
774 void (*fsyncdir)(fuse_req_t req, fuse_ino_t ino, int datasync,
775 struct fuse_file_info *fi);
778 * Get file system statistics
780 * Valid replies:
781 * fuse_reply_statfs
782 * fuse_reply_err
784 * @param req request handle
785 * @param ino the inode number, zero means "undefined"
787 void (*statfs)(fuse_req_t req, fuse_ino_t ino);
790 * Set an extended attribute
792 * If this request is answered with an error code of ENOSYS, this is
793 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
794 * future setxattr() requests will fail with EOPNOTSUPP without being
795 * send to the filesystem process.
797 * Valid replies:
798 * fuse_reply_err
800 void (*setxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
801 const char *value, size_t size, int flags,
802 uint32_t setxattr_flags);
805 * Get an extended attribute
807 * If size is zero, the size of the value should be sent with
808 * fuse_reply_xattr.
810 * If the size is non-zero, and the value fits in the buffer, the
811 * value should be sent with fuse_reply_buf.
813 * If the size is too small for the value, the ERANGE error should
814 * be sent.
816 * If this request is answered with an error code of ENOSYS, this is
817 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
818 * future getxattr() requests will fail with EOPNOTSUPP without being
819 * send to the filesystem process.
821 * Valid replies:
822 * fuse_reply_buf
823 * fuse_reply_data
824 * fuse_reply_xattr
825 * fuse_reply_err
827 * @param req request handle
828 * @param ino the inode number
829 * @param name of the extended attribute
830 * @param size maximum size of the value to send
832 void (*getxattr)(fuse_req_t req, fuse_ino_t ino, const char *name,
833 size_t size);
836 * List extended attribute names
838 * If size is zero, the total size of the attribute list should be
839 * sent with fuse_reply_xattr.
841 * If the size is non-zero, and the null character separated
842 * attribute list fits in the buffer, the list should be sent with
843 * fuse_reply_buf.
845 * If the size is too small for the list, the ERANGE error should
846 * be sent.
848 * If this request is answered with an error code of ENOSYS, this is
849 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
850 * future listxattr() requests will fail with EOPNOTSUPP without being
851 * send to the filesystem process.
853 * Valid replies:
854 * fuse_reply_buf
855 * fuse_reply_data
856 * fuse_reply_xattr
857 * fuse_reply_err
859 * @param req request handle
860 * @param ino the inode number
861 * @param size maximum size of the list to send
863 void (*listxattr)(fuse_req_t req, fuse_ino_t ino, size_t size);
866 * Remove an extended attribute
868 * If this request is answered with an error code of ENOSYS, this is
869 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
870 * future removexattr() requests will fail with EOPNOTSUPP without being
871 * send to the filesystem process.
873 * Valid replies:
874 * fuse_reply_err
876 * @param req request handle
877 * @param ino the inode number
878 * @param name of the extended attribute
880 void (*removexattr)(fuse_req_t req, fuse_ino_t ino, const char *name);
883 * Check file access permissions
885 * This will be called for the access() and chdir() system
886 * calls. If the 'default_permissions' mount option is given,
887 * this method is not called.
889 * This method is not called under Linux kernel versions 2.4.x
891 * If this request is answered with an error code of ENOSYS, this is
892 * treated as a permanent success, i.e. this and all future access()
893 * requests will succeed without being send to the filesystem process.
895 * Valid replies:
896 * fuse_reply_err
898 * @param req request handle
899 * @param ino the inode number
900 * @param mask requested access mode
902 void (*access)(fuse_req_t req, fuse_ino_t ino, int mask);
905 * Create and open a file
907 * If the file does not exist, first create it with the specified
908 * mode, and then open it.
910 * See the description of the open handler for more
911 * information.
913 * If this method is not implemented or under Linux kernel
914 * versions earlier than 2.6.15, the mknod() and open() methods
915 * will be called instead.
917 * If this request is answered with an error code of ENOSYS, the handler
918 * is treated as not implemented (i.e., for this and future requests the
919 * mknod() and open() handlers will be called instead).
921 * Valid replies:
922 * fuse_reply_create
923 * fuse_reply_err
925 * @param req request handle
926 * @param parent inode number of the parent directory
927 * @param name to create
928 * @param mode file type and mode with which to create the new file
929 * @param fi file information
931 void (*create)(fuse_req_t req, fuse_ino_t parent, const char *name,
932 mode_t mode, struct fuse_file_info *fi);
935 * Test for a POSIX file lock
937 * Valid replies:
938 * fuse_reply_lock
939 * fuse_reply_err
941 * @param req request handle
942 * @param ino the inode number
943 * @param fi file information
944 * @param lock the region/type to test
946 void (*getlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
947 struct flock *lock);
950 * Acquire, modify or release a POSIX file lock
952 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
953 * owner, but otherwise this is not always the case. For checking
954 * lock ownership, 'fi->owner' must be used. The l_pid field in
955 * 'struct flock' should only be used to fill in this field in
956 * getlk().
958 * Note: if the locking methods are not implemented, the kernel
959 * will still allow file locking to work locally. Hence these are
960 * only interesting for network filesystems and similar.
962 * Valid replies:
963 * fuse_reply_err
965 * @param req request handle
966 * @param ino the inode number
967 * @param fi file information
968 * @param lock the region/type to set
969 * @param sleep locking operation may sleep
971 void (*setlk)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
972 struct flock *lock, int sleep);
975 * Map block index within file to block index within device
977 * Note: This makes sense only for block device backed filesystems
978 * mounted with the 'blkdev' option
980 * If this request is answered with an error code of ENOSYS, this is
981 * treated as a permanent failure, i.e. all future bmap() requests will
982 * fail with the same error code without being send to the filesystem
983 * process.
985 * Valid replies:
986 * fuse_reply_bmap
987 * fuse_reply_err
989 * @param req request handle
990 * @param ino the inode number
991 * @param blocksize unit of block index
992 * @param idx block index within file
994 void (*bmap)(fuse_req_t req, fuse_ino_t ino, size_t blocksize,
995 uint64_t idx);
998 * Ioctl
1000 * Note: For unrestricted ioctls (not allowed for FUSE
1001 * servers), data in and out areas can be discovered by giving
1002 * iovs and setting FUSE_IOCTL_RETRY in *flags*. For
1003 * restricted ioctls, kernel prepares in/out data area
1004 * according to the information encoded in cmd.
1006 * Valid replies:
1007 * fuse_reply_ioctl_retry
1008 * fuse_reply_ioctl
1009 * fuse_reply_ioctl_iov
1010 * fuse_reply_err
1012 * @param req request handle
1013 * @param ino the inode number
1014 * @param cmd ioctl command
1015 * @param arg ioctl argument
1016 * @param fi file information
1017 * @param flags for FUSE_IOCTL_* flags
1018 * @param in_buf data fetched from the caller
1019 * @param in_bufsz number of fetched bytes
1020 * @param out_bufsz maximum size of output data
1022 * Note : the unsigned long request submitted by the application
1023 * is truncated to 32 bits.
1025 void (*ioctl)(fuse_req_t req, fuse_ino_t ino, unsigned int cmd, void *arg,
1026 struct fuse_file_info *fi, unsigned flags, const void *in_buf,
1027 size_t in_bufsz, size_t out_bufsz);
1030 * Poll for IO readiness
1032 * Note: If ph is non-NULL, the client should notify
1033 * when IO readiness events occur by calling
1034 * fuse_lowlevel_notify_poll() with the specified ph.
1036 * Regardless of the number of times poll with a non-NULL ph
1037 * is received, single notification is enough to clear all.
1038 * Notifying more times incurs overhead but doesn't harm
1039 * correctness.
1041 * The callee is responsible for destroying ph with
1042 * fuse_pollhandle_destroy() when no longer in use.
1044 * If this request is answered with an error code of ENOSYS, this is
1045 * treated as success (with a kernel-defined default poll-mask) and
1046 * future calls to pull() will succeed the same way without being send
1047 * to the filesystem process.
1049 * Valid replies:
1050 * fuse_reply_poll
1051 * fuse_reply_err
1053 * @param req request handle
1054 * @param ino the inode number
1055 * @param fi file information
1056 * @param ph poll handle to be used for notification
1058 void (*poll)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1059 struct fuse_pollhandle *ph);
1062 * Write data made available in a buffer
1064 * This is a more generic version of the ->write() method. If
1065 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
1066 * kernel supports splicing from the fuse device, then the
1067 * data will be made available in pipe for supporting zero
1068 * copy data transfer.
1070 * buf->count is guaranteed to be one (and thus buf->idx is
1071 * always zero). The write_buf handler must ensure that
1072 * bufv->off is correctly updated (reflecting the number of
1073 * bytes read from bufv->buf[0]).
1075 * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is
1076 * expected to reset the setuid and setgid bits.
1078 * Valid replies:
1079 * fuse_reply_write
1080 * fuse_reply_err
1082 * @param req request handle
1083 * @param ino the inode number
1084 * @param bufv buffer containing the data
1085 * @param off offset to write to
1086 * @param fi file information
1088 void (*write_buf)(fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv,
1089 off_t off, struct fuse_file_info *fi);
1092 * Forget about multiple inodes
1094 * See description of the forget function for more
1095 * information.
1097 * Valid replies:
1098 * fuse_reply_none
1100 * @param req request handle
1102 void (*forget_multi)(fuse_req_t req, size_t count,
1103 struct fuse_forget_data *forgets);
1106 * Acquire, modify or release a BSD file lock
1108 * Note: if the locking methods are not implemented, the kernel
1109 * will still allow file locking to work locally. Hence these are
1110 * only interesting for network filesystems and similar.
1112 * Valid replies:
1113 * fuse_reply_err
1115 * @param req request handle
1116 * @param ino the inode number
1117 * @param fi file information
1118 * @param op the locking operation, see flock(2)
1120 void (*flock)(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
1121 int op);
1124 * Allocate requested space. If this function returns success then
1125 * subsequent writes to the specified range shall not fail due to the lack
1126 * of free space on the file system storage media.
1128 * If this request is answered with an error code of ENOSYS, this is
1129 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1130 * future fallocate() requests will fail with EOPNOTSUPP without being
1131 * send to the filesystem process.
1133 * Valid replies:
1134 * fuse_reply_err
1136 * @param req request handle
1137 * @param ino the inode number
1138 * @param offset starting point for allocated region
1139 * @param length size of allocated region
1140 * @param mode determines the operation to be performed on the given range,
1141 * see fallocate(2)
1143 void (*fallocate)(fuse_req_t req, fuse_ino_t ino, int mode, off_t offset,
1144 off_t length, struct fuse_file_info *fi);
1147 * Read directory with attributes
1149 * Send a buffer filled using fuse_add_direntry_plus(), with size not
1150 * exceeding the requested size. Send an empty buffer on end of
1151 * stream.
1153 * fi->fh will contain the value set by the opendir method, or
1154 * will be undefined if the opendir method didn't set any value.
1156 * In contrast to readdir() (which does not affect the lookup counts),
1157 * the lookup count of every entry returned by readdirplus(), except "."
1158 * and "..", is incremented by one.
1160 * Valid replies:
1161 * fuse_reply_buf
1162 * fuse_reply_data
1163 * fuse_reply_err
1165 * @param req request handle
1166 * @param ino the inode number
1167 * @param size maximum number of bytes to send
1168 * @param off offset to continue reading the directory stream
1169 * @param fi file information
1171 void (*readdirplus)(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1172 struct fuse_file_info *fi);
1175 * Copy a range of data from one file to another
1177 * Performs an optimized copy between two file descriptors without the
1178 * additional cost of transferring data through the FUSE kernel module
1179 * to user space (glibc) and then back into the FUSE filesystem again.
1181 * In case this method is not implemented, glibc falls back to reading
1182 * data from the source and writing to the destination. Effectively
1183 * doing an inefficient copy of the data.
1185 * If this request is answered with an error code of ENOSYS, this is
1186 * treated as a permanent failure with error code EOPNOTSUPP, i.e. all
1187 * future copy_file_range() requests will fail with EOPNOTSUPP without
1188 * being send to the filesystem process.
1190 * Valid replies:
1191 * fuse_reply_write
1192 * fuse_reply_err
1194 * @param req request handle
1195 * @param ino_in the inode number or the source file
1196 * @param off_in starting point from were the data should be read
1197 * @param fi_in file information of the source file
1198 * @param ino_out the inode number or the destination file
1199 * @param off_out starting point where the data should be written
1200 * @param fi_out file information of the destination file
1201 * @param len maximum size of the data to copy
1202 * @param flags passed along with the copy_file_range() syscall
1204 void (*copy_file_range)(fuse_req_t req, fuse_ino_t ino_in, off_t off_in,
1205 struct fuse_file_info *fi_in, fuse_ino_t ino_out,
1206 off_t off_out, struct fuse_file_info *fi_out,
1207 size_t len, int flags);
1210 * Find next data or hole after the specified offset
1212 * If this request is answered with an error code of ENOSYS, this is
1213 * treated as a permanent failure, i.e. all future lseek() requests will
1214 * fail with the same error code without being send to the filesystem
1215 * process.
1217 * Valid replies:
1218 * fuse_reply_lseek
1219 * fuse_reply_err
1221 * @param req request handle
1222 * @param ino the inode number
1223 * @param off offset to start search from
1224 * @param whence either SEEK_DATA or SEEK_HOLE
1225 * @param fi file information
1227 void (*lseek)(fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
1228 struct fuse_file_info *fi);
1232 * Reply with an error code or success.
1234 * Possible requests:
1235 * all except forget
1237 * Whereever possible, error codes should be chosen from the list of
1238 * documented error conditions in the corresponding system calls
1239 * manpage.
1241 * An error code of ENOSYS is sometimes treated specially. This is
1242 * indicated in the documentation of the affected handler functions.
1244 * The following requests may be answered with a zero error code:
1245 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1246 * removexattr, setlk.
1248 * @param req request handle
1249 * @param err the positive error value, or zero for success
1250 * @return zero for success, -errno for failure to send reply
1252 int fuse_reply_err(fuse_req_t req, int err);
1255 * Don't send reply
1257 * Possible requests:
1258 * forget
1259 * forget_multi
1260 * retrieve_reply
1262 * @param req request handle
1264 void fuse_reply_none(fuse_req_t req);
1267 * Reply with a directory entry
1269 * Possible requests:
1270 * lookup, mknod, mkdir, symlink, link
1272 * Side effects:
1273 * increments the lookup count on success
1275 * @param req request handle
1276 * @param e the entry parameters
1277 * @return zero for success, -errno for failure to send reply
1279 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1282 * Reply with a directory entry and open parameters
1284 * currently the following members of 'fi' are used:
1285 * fh, direct_io, keep_cache
1287 * Possible requests:
1288 * create
1290 * Side effects:
1291 * increments the lookup count on success
1293 * @param req request handle
1294 * @param e the entry parameters
1295 * @param fi file information
1296 * @return zero for success, -errno for failure to send reply
1298 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1299 const struct fuse_file_info *fi);
1302 * Reply with attributes
1304 * Possible requests:
1305 * getattr, setattr
1307 * @param req request handle
1308 * @param attr the attributes
1309 * @param attr_timeout validity timeout (in seconds) for the attributes
1310 * @return zero for success, -errno for failure to send reply
1312 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1313 double attr_timeout);
1316 * Reply with the contents of a symbolic link
1318 * Possible requests:
1319 * readlink
1321 * @param req request handle
1322 * @param link symbolic link contents
1323 * @return zero for success, -errno for failure to send reply
1325 int fuse_reply_readlink(fuse_req_t req, const char *link);
1328 * Reply with open parameters
1330 * currently the following members of 'fi' are used:
1331 * fh, direct_io, keep_cache
1333 * Possible requests:
1334 * open, opendir
1336 * @param req request handle
1337 * @param fi file information
1338 * @return zero for success, -errno for failure to send reply
1340 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1343 * Reply with number of bytes written
1345 * Possible requests:
1346 * write
1348 * @param req request handle
1349 * @param count the number of bytes written
1350 * @return zero for success, -errno for failure to send reply
1352 int fuse_reply_write(fuse_req_t req, size_t count);
1355 * Reply with data
1357 * Possible requests:
1358 * read, readdir, getxattr, listxattr
1360 * @param req request handle
1361 * @param buf buffer containing data
1362 * @param size the size of data in bytes
1363 * @return zero for success, -errno for failure to send reply
1365 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1368 * Reply with data copied/moved from buffer(s)
1370 * Possible requests:
1371 * read, readdir, getxattr, listxattr
1373 * Side effects:
1374 * when used to return data from a readdirplus() (but not readdir())
1375 * call, increments the lookup count of each returned entry by one
1376 * on success.
1378 * @param req request handle
1379 * @param bufv buffer vector
1380 * @return zero for success, -errno for failure to send reply
1382 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv);
1385 * Reply with data vector
1387 * Possible requests:
1388 * read, readdir, getxattr, listxattr
1390 * @param req request handle
1391 * @param iov the vector containing the data
1392 * @param count the size of vector
1393 * @return zero for success, -errno for failure to send reply
1395 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1398 * Reply with filesystem statistics
1400 * Possible requests:
1401 * statfs
1403 * @param req request handle
1404 * @param stbuf filesystem statistics
1405 * @return zero for success, -errno for failure to send reply
1407 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1410 * Reply with needed buffer size
1412 * Possible requests:
1413 * getxattr, listxattr
1415 * @param req request handle
1416 * @param count the buffer size needed in bytes
1417 * @return zero for success, -errno for failure to send reply
1419 int fuse_reply_xattr(fuse_req_t req, size_t count);
1422 * Reply with file lock information
1424 * Possible requests:
1425 * getlk
1427 * @param req request handle
1428 * @param lock the lock information
1429 * @return zero for success, -errno for failure to send reply
1431 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1434 * Reply with block index
1436 * Possible requests:
1437 * bmap
1439 * @param req request handle
1440 * @param idx block index within device
1441 * @return zero for success, -errno for failure to send reply
1443 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1446 * Filling a buffer in readdir
1450 * Add a directory entry to the buffer
1452 * Buffer needs to be large enough to hold the entry. If it's not,
1453 * then the entry is not filled in but the size of the entry is still
1454 * returned. The caller can check this by comparing the bufsize
1455 * parameter with the returned entry size. If the entry size is
1456 * larger than the buffer size, the operation failed.
1458 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1459 * st_mode field are used. The other fields are ignored.
1461 * *off* should be any non-zero value that the filesystem can use to
1462 * identify the current point in the directory stream. It does not
1463 * need to be the actual physical position. A value of zero is
1464 * reserved to mean "from the beginning", and should therefore never
1465 * be used (the first call to fuse_add_direntry should be passed the
1466 * offset of the second directory entry).
1468 * @param req request handle
1469 * @param buf the point where the new entry will be added to the buffer
1470 * @param bufsize remaining size of the buffer
1471 * @param name the name of the entry
1472 * @param stbuf the file attributes
1473 * @param off the offset of the next entry
1474 * @return the space needed for the entry
1476 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1477 const char *name, const struct stat *stbuf, off_t off);
1480 * Add a directory entry to the buffer with the attributes
1482 * See documentation of `fuse_add_direntry()` for more details.
1484 * @param req request handle
1485 * @param buf the point where the new entry will be added to the buffer
1486 * @param bufsize remaining size of the buffer
1487 * @param name the name of the entry
1488 * @param e the directory entry
1489 * @param off the offset of the next entry
1490 * @return the space needed for the entry
1492 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1493 const char *name,
1494 const struct fuse_entry_param *e, off_t off);
1497 * Reply to ask for data fetch and output buffer preparation. ioctl
1498 * will be retried with the specified input data fetched and output
1499 * buffer prepared.
1501 * Possible requests:
1502 * ioctl
1504 * @param req request handle
1505 * @param in_iov iovec specifying data to fetch from the caller
1506 * @param in_count number of entries in in_iov
1507 * @param out_iov iovec specifying addresses to write output to
1508 * @param out_count number of entries in out_iov
1509 * @return zero for success, -errno for failure to send reply
1511 int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov,
1512 size_t in_count, const struct iovec *out_iov,
1513 size_t out_count);
1516 * Reply to finish ioctl
1518 * Possible requests:
1519 * ioctl
1521 * @param req request handle
1522 * @param result result to be passed to the caller
1523 * @param buf buffer containing output data
1524 * @param size length of output data
1526 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1529 * Reply to finish ioctl with iov buffer
1531 * Possible requests:
1532 * ioctl
1534 * @param req request handle
1535 * @param result result to be passed to the caller
1536 * @param iov the vector containing the data
1537 * @param count the size of vector
1539 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1540 int count);
1543 * Reply with poll result event mask
1545 * @param req request handle
1546 * @param revents poll result event mask
1548 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1551 * Reply with offset
1553 * Possible requests:
1554 * lseek
1556 * @param req request handle
1557 * @param off offset of next data or hole
1558 * @return zero for success, -errno for failure to send reply
1560 int fuse_reply_lseek(fuse_req_t req, off_t off);
1563 * Notification
1567 * Notify IO readiness event
1569 * For more information, please read comment for poll operation.
1571 * @param ph poll handle to notify IO readiness event for
1573 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1576 * Notify to invalidate cache for an inode.
1578 * Added in FUSE protocol version 7.12. If the kernel does not support
1579 * this (or a newer) version, the function will return -ENOSYS and do
1580 * nothing.
1582 * If the filesystem has writeback caching enabled, invalidating an
1583 * inode will first trigger a writeback of all dirty pages. The call
1584 * will block until all writeback requests have completed and the
1585 * inode has been invalidated. It will, however, not wait for
1586 * completion of pending writeback requests that have been issued
1587 * before.
1589 * If there are no dirty pages, this function will never block.
1591 * @param se the session object
1592 * @param ino the inode number
1593 * @param off the offset in the inode where to start invalidating
1594 * or negative to invalidate attributes only
1595 * @param len the amount of cache to invalidate or 0 for all
1596 * @return zero for success, -errno for failure
1598 int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino,
1599 off_t off, off_t len);
1602 * Notify to invalidate parent attributes and the dentry matching
1603 * parent/name
1605 * To avoid a deadlock this function must not be called in the
1606 * execution path of a related filesystem operation or within any code
1607 * that could hold a lock that could be needed to execute such an
1608 * operation. As of kernel 4.18, a "related operation" is a lookup(),
1609 * symlink(), mknod(), mkdir(), unlink(), rename(), link() or create()
1610 * request for the parent, and a setattr(), unlink(), rmdir(),
1611 * rename(), setxattr(), removexattr(), readdir() or readdirplus()
1612 * request for the inode itself.
1614 * When called correctly, this function will never block.
1616 * Added in FUSE protocol version 7.12. If the kernel does not support
1617 * this (or a newer) version, the function will return -ENOSYS and do
1618 * nothing.
1620 * @param se the session object
1621 * @param parent inode number
1622 * @param name file name
1623 * @param namelen strlen() of file name
1624 * @return zero for success, -errno for failure
1626 int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent,
1627 const char *name, size_t namelen);
1630 * This function behaves like fuse_lowlevel_notify_inval_entry() with
1631 * the following additional effect (at least as of Linux kernel 4.8):
1633 * If the provided *child* inode matches the inode that is currently
1634 * associated with the cached dentry, and if there are any inotify
1635 * watches registered for the dentry, then the watchers are informed
1636 * that the dentry has been deleted.
1638 * To avoid a deadlock this function must not be called while
1639 * executing a related filesystem operation or while holding a lock
1640 * that could be needed to execute such an operation (see the
1641 * description of fuse_lowlevel_notify_inval_entry() for more
1642 * details).
1644 * When called correctly, this function will never block.
1646 * Added in FUSE protocol version 7.18. If the kernel does not support
1647 * this (or a newer) version, the function will return -ENOSYS and do
1648 * nothing.
1650 * @param se the session object
1651 * @param parent inode number
1652 * @param child inode number
1653 * @param name file name
1654 * @param namelen strlen() of file name
1655 * @return zero for success, -errno for failure
1657 int fuse_lowlevel_notify_delete(struct fuse_session *se, fuse_ino_t parent,
1658 fuse_ino_t child, const char *name,
1659 size_t namelen);
1662 * Store data to the kernel buffers
1664 * Synchronously store data in the kernel buffers belonging to the
1665 * given inode. The stored data is marked up-to-date (no read will be
1666 * performed against it, unless it's invalidated or evicted from the
1667 * cache).
1669 * If the stored data overflows the current file size, then the size
1670 * is extended, similarly to a write(2) on the filesystem.
1672 * If this function returns an error, then the store wasn't fully
1673 * completed, but it may have been partially completed.
1675 * Added in FUSE protocol version 7.15. If the kernel does not support
1676 * this (or a newer) version, the function will return -ENOSYS and do
1677 * nothing.
1679 * @param se the session object
1680 * @param ino the inode number
1681 * @param offset the starting offset into the file to store to
1682 * @param bufv buffer vector
1683 * @return zero for success, -errno for failure
1685 int fuse_lowlevel_notify_store(struct fuse_session *se, fuse_ino_t ino,
1686 off_t offset, struct fuse_bufvec *bufv);
1689 * Utility functions
1693 * Get the userdata from the request
1695 * @param req request handle
1696 * @return the user data passed to fuse_session_new()
1698 void *fuse_req_userdata(fuse_req_t req);
1701 * Get the context from the request
1703 * The pointer returned by this function will only be valid for the
1704 * request's lifetime
1706 * @param req request handle
1707 * @return the context structure
1709 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1712 * Callback function for an interrupt
1714 * @param req interrupted request
1715 * @param data user data
1717 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1720 * Register/unregister callback for an interrupt
1722 * If an interrupt has already happened, then the callback function is
1723 * called from within this function, hence it's not possible for
1724 * interrupts to be lost.
1726 * @param req request handle
1727 * @param func the callback function or NULL for unregister
1728 * @param data user data passed to the callback function
1730 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1731 void *data);
1734 * Check if a request has already been interrupted
1736 * @param req request handle
1737 * @return 1 if the request has been interrupted, 0 otherwise
1739 int fuse_req_interrupted(fuse_req_t req);
1742 * Check if the session is connected via virtio
1744 * @param se session object
1745 * @return 1 if the session is a virtio session
1747 int fuse_lowlevel_is_virtio(struct fuse_session *se);
1750 * Inquiry functions
1754 * Print low-level version information to stdout.
1756 void fuse_lowlevel_version(void);
1759 * Print available low-level options to stdout. This is not an
1760 * exhaustive list, but includes only those options that may be of
1761 * interest to an end-user of a file system.
1763 void fuse_lowlevel_help(void);
1766 * Print available options for `fuse_parse_cmdline()`.
1768 void fuse_cmdline_help(void);
1771 * Filesystem setup & teardown
1774 struct fuse_cmdline_opts {
1775 int foreground;
1776 int debug;
1777 int nodefault_subtype;
1778 int show_version;
1779 int show_help;
1780 int print_capabilities;
1781 int syslog;
1782 int log_level;
1783 unsigned int max_idle_threads;
1784 unsigned long rlimit_nofile;
1788 * Utility function to parse common options for simple file systems
1789 * using the low-level API. A help text that describes the available
1790 * options can be printed with `fuse_cmdline_help`. A single
1791 * non-option argument is treated as the mountpoint. Multiple
1792 * non-option arguments will result in an error.
1794 * If neither -o subtype= or -o fsname= options are given, a new
1795 * subtype option will be added and set to the basename of the program
1796 * (the fsname will remain unset, and then defaults to "fuse").
1798 * Known options will be removed from *args*, unknown options will
1799 * remain.
1801 * @param args argument vector (input+output)
1802 * @param opts output argument for parsed options
1803 * @return 0 on success, -1 on failure
1805 int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts);
1808 * Create a low level session.
1810 * Returns a session structure suitable for passing to
1811 * fuse_session_mount() and fuse_session_loop().
1813 * This function accepts most file-system independent mount options
1814 * (like context, nodev, ro - see mount(8)), as well as the general
1815 * fuse mount options listed in mount.fuse(8) (e.g. -o allow_root and
1816 * -o default_permissions, but not ``-o use_ino``). Instead of `-o
1817 * debug`, debugging may also enabled with `-d` or `--debug`.
1819 * If not all options are known, an error message is written to stderr
1820 * and the function returns NULL.
1822 * Option parsing skips argv[0], which is assumed to contain the
1823 * program name. To prevent accidentally passing an option in
1824 * argv[0], this element must always be present (even if no options
1825 * are specified). It may be set to the empty string ('\0') if no
1826 * reasonable value can be provided.
1828 * @param args argument vector
1829 * @param op the (low-level) filesystem operations
1830 * @param op_size sizeof(struct fuse_lowlevel_ops)
1831 * @param userdata user data
1833 * @return the fuse session on success, NULL on failure
1835 struct fuse_session *fuse_session_new(struct fuse_args *args,
1836 const struct fuse_lowlevel_ops *op,
1837 size_t op_size, void *userdata);
1840 * Mount a FUSE file system.
1842 * @param se session object
1844 * @return 0 on success, -1 on failure.
1846 int fuse_session_mount(struct fuse_session *se);
1849 * Enter a single threaded, blocking event loop.
1851 * When the event loop terminates because the connection to the FUSE
1852 * kernel module has been closed, this function returns zero. This
1853 * happens when the filesystem is unmounted regularly (by the
1854 * filesystem owner or root running the umount(8) or fusermount(1)
1855 * command), or if connection is explicitly severed by writing ``1``
1856 * to the``abort`` file in ``/sys/fs/fuse/connections/NNN``. The only
1857 * way to distinguish between these two conditions is to check if the
1858 * filesystem is still mounted after the session loop returns.
1860 * When some error occurs during request processing, the function
1861 * returns a negated errno(3) value.
1863 * If the loop has been terminated because of a signal handler
1864 * installed by fuse_set_signal_handlers(), this function returns the
1865 * (positive) signal value that triggered the exit.
1867 * @param se the session
1868 * @return 0, -errno, or a signal value
1870 int fuse_session_loop(struct fuse_session *se);
1873 * Flag a session as terminated.
1875 * This function is invoked by the POSIX signal handlers, when
1876 * registered using fuse_set_signal_handlers(). It will cause any
1877 * running event loops to terminate on the next opportunity.
1879 * @param se the session
1881 void fuse_session_exit(struct fuse_session *se);
1884 * Reset the terminated flag of a session
1886 * @param se the session
1888 void fuse_session_reset(struct fuse_session *se);
1891 * Query the terminated flag of a session
1893 * @param se the session
1894 * @return 1 if exited, 0 if not exited
1896 int fuse_session_exited(struct fuse_session *se);
1899 * Ensure that file system is unmounted.
1901 * In regular operation, the file system is typically unmounted by the
1902 * user calling umount(8) or fusermount(1), which then terminates the
1903 * FUSE session loop. However, the session loop may also terminate as
1904 * a result of an explicit call to fuse_session_exit() (e.g. by a
1905 * signal handler installed by fuse_set_signal_handler()). In this
1906 * case the filesystem remains mounted, but any attempt to access it
1907 * will block (while the filesystem process is still running) or give
1908 * an ESHUTDOWN error (after the filesystem process has terminated).
1910 * If the communication channel with the FUSE kernel module is still
1911 * open (i.e., if the session loop was terminated by an explicit call
1912 * to fuse_session_exit()), this function will close it and unmount
1913 * the filesystem. If the communication channel has been closed by the
1914 * kernel, this method will do (almost) nothing.
1916 * NOTE: The above semantics mean that if the connection to the kernel
1917 * is terminated via the ``/sys/fs/fuse/connections/NNN/abort`` file,
1918 * this method will *not* unmount the filesystem.
1920 * @param se the session
1922 void fuse_session_unmount(struct fuse_session *se);
1925 * Destroy a session
1927 * @param se the session
1929 void fuse_session_destroy(struct fuse_session *se);
1932 * Custom event loop support
1936 * Return file descriptor for communication with kernel.
1938 * The file selector can be used to integrate FUSE with a custom event
1939 * loop. Whenever data is available for reading on the provided fd,
1940 * the event loop should call `fuse_session_receive_buf` followed by
1941 * `fuse_session_process_buf` to process the request.
1943 * The returned file descriptor is valid until `fuse_session_unmount`
1944 * is called.
1946 * @param se the session
1947 * @return a file descriptor
1949 int fuse_session_fd(struct fuse_session *se);
1952 * Process a raw request supplied in a generic buffer
1954 * The fuse_buf may contain a memory buffer or a pipe file descriptor.
1956 * @param se the session
1957 * @param buf the fuse_buf containing the request
1959 void fuse_session_process_buf(struct fuse_session *se,
1960 const struct fuse_buf *buf);
1963 * Read a raw request from the kernel into the supplied buffer.
1965 * Depending on file system options, system capabilities, and request
1966 * size the request is either read into a memory buffer or spliced
1967 * into a temporary pipe.
1969 * @param se the session
1970 * @param buf the fuse_buf to store the request in
1971 * @return the actual size of the raw request, or -errno on error
1973 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
1975 #endif /* FUSE_LOWLEVEL_H_ */