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.
9 #ifndef _FUSE_LOWLEVEL_H_
10 #define _FUSE_LOWLEVEL_H_
16 * IMPORTANT: you should define FUSE_USE_VERSION before including this
17 * header. To use the newest API define it to 26 (recommended for any
18 * new application), to use the old API define it to 24 (default) or
22 #ifndef FUSE_USE_VERSION
23 #define FUSE_USE_VERSION 24
26 #include "fuse_common.h"
30 #include <sys/types.h>
32 #include <sys/statvfs.h>
39 /* ----------------------------------------------------------- *
40 * Miscellaneous definitions *
41 * ----------------------------------------------------------- */
43 /** The node ID of the root inode */
44 #define FUSE_ROOT_ID 1
46 /** Inode number type */
47 typedef unsigned long fuse_ino_t
;
49 /** Request pointer type */
50 typedef struct fuse_req
*fuse_req_t
;
55 * This provides hooks for processing requests, and exiting
62 * A communication channel, providing hooks for sending and receiving
67 /** Directory entry parameters supplied to fuse_reply_entry() */
68 struct fuse_entry_param
{
69 /** Unique inode number
71 * In lookup, zero means negative entry (from version 2.5)
72 * Returning ENOENT also means negative entry, but by setting zero
73 * ino the kernel may cache negative entries for entry_timeout
78 /** Generation number for this entry.
80 * The ino/generation pair should be unique for the filesystem's
81 * lifetime. It must be non-zero, otherwise FUSE will treat it as an
84 unsigned long generation
;
88 * Even if attr_timeout == 0, attr must be correct. For example,
89 * for open(), FUSE uses attr.st_size from lookup() to determine
90 * how many bytes to request. If this value is not correct,
91 * incorrect data will be returned.
95 /** Validity timeout (in seconds) for the attributes */
98 /** Validity timeout (in seconds) for the name */
102 /** Additional context associated with requests */
104 /** User ID of the calling process */
107 /** Group ID of the calling process */
110 /** Thread ID of the calling process */
113 /** Umask of the calling process (introduced in version 2.8) */
117 struct fuse_forget_data
{
122 /* 'to_set' flags in setattr */
123 #define FUSE_SET_ATTR_MODE (1 << 0)
124 #define FUSE_SET_ATTR_UID (1 << 1)
125 #define FUSE_SET_ATTR_GID (1 << 2)
126 #define FUSE_SET_ATTR_SIZE (1 << 3)
127 #define FUSE_SET_ATTR_ATIME (1 << 4)
128 #define FUSE_SET_ATTR_MTIME (1 << 5)
129 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
130 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
132 /* ----------------------------------------------------------- *
133 * Request methods and replies *
134 * ----------------------------------------------------------- */
137 * Low level filesystem operations
139 * Most of the methods (with the exception of init and destroy)
140 * receive a request handle (fuse_req_t) as their first argument.
141 * This handle must be passed to one of the specified reply functions.
143 * This may be done inside the method invocation, or after the call
144 * has returned. The request handle is valid until one of the reply
145 * functions is called.
147 * Other pointer arguments (name, fuse_file_info, etc) are not valid
148 * after the call has returned, so if they are needed later, their
149 * contents have to be copied.
151 * The filesystem sometimes needs to handle a return value of -ENOENT
152 * from the reply function, which means, that the request was
153 * interrupted, and the reply discarded. For example if
154 * fuse_reply_open() return -ENOENT means, that the release method for
155 * this file will not be called.
157 struct fuse_lowlevel_ops
{
159 * Initialize filesystem
161 * Called before any other filesystem method
163 * There's no reply to this function
165 * @param userdata the user data passed to fuse_lowlevel_new()
167 void (*init
) (void *userdata
, struct fuse_conn_info
*conn
);
170 * Clean up filesystem
172 * Called on filesystem exit
174 * There's no reply to this function
176 * @param userdata the user data passed to fuse_lowlevel_new()
178 void (*destroy
) (void *userdata
);
181 * Look up a directory entry by name and get its attributes.
187 * @param req request handle
188 * @param parent inode number of the parent directory
189 * @param name the name to look up
191 void (*lookup
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
194 * Forget about an inode
196 * The nlookup parameter indicates the number of lookups
197 * previously performed on this inode.
199 * If the filesystem implements inode lifetimes, it is recommended
200 * that inodes acquire a single reference on each lookup, and lose
201 * nlookup references on each forget.
203 * The filesystem may ignore forget calls, if the inodes don't
204 * need to have a limited lifetime.
206 * On unmount it is not guaranteed, that all referenced inodes
207 * will receive a forget message.
212 * @param req request handle
213 * @param ino the inode number
214 * @param nlookup the number of lookups to forget
216 void (*forget
) (fuse_req_t req
, fuse_ino_t ino
, unsigned long nlookup
);
219 * Get file attributes
225 * @param req request handle
226 * @param ino the inode number
227 * @param fi for future use, currently always NULL
229 void (*getattr
) (fuse_req_t req
, fuse_ino_t ino
,
230 struct fuse_file_info
*fi
);
233 * Set file attributes
235 * In the 'attr' argument only members indicated by the 'to_set'
236 * bitmask contain valid values. Other members contain undefined
239 * If the setattr was invoked from the ftruncate() system call
240 * under Linux kernel versions 2.6.15 or later, the fi->fh will
241 * contain the value set by the open method or will be undefined
242 * if the open method didn't set any value. Otherwise (not
243 * ftruncate call, or kernel version earlier than 2.6.15) the fi
244 * parameter will be NULL.
250 * @param req request handle
251 * @param ino the inode number
252 * @param attr the attributes
253 * @param to_set bit mask of attributes which should be set
254 * @param fi file information, or NULL
256 * Changed in version 2.5:
257 * file information filled in for ftruncate
259 void (*setattr
) (fuse_req_t req
, fuse_ino_t ino
, struct stat
*attr
,
260 int to_set
, struct fuse_file_info
*fi
);
266 * fuse_reply_readlink
269 * @param req request handle
270 * @param ino the inode number
272 void (*readlink
) (fuse_req_t req
, fuse_ino_t ino
);
277 * Create a regular file, character device, block device, fifo or
284 * @param req request handle
285 * @param parent inode number of the parent directory
286 * @param name to create
287 * @param mode file type and mode with which to create the new file
288 * @param rdev the device number (only valid if created file is a device)
290 void (*mknod
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
291 mode_t mode
, dev_t rdev
);
300 * @param req request handle
301 * @param parent inode number of the parent directory
302 * @param name to create
303 * @param mode with which to create the new file
305 void (*mkdir
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
314 * @param req request handle
315 * @param parent inode number of the parent directory
316 * @param name to remove
318 void (*unlink
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
326 * @param req request handle
327 * @param parent inode number of the parent directory
328 * @param name to remove
330 void (*rmdir
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
333 * Create a symbolic link
339 * @param req request handle
340 * @param link the contents of the symbolic link
341 * @param parent inode number of the parent directory
342 * @param name to create
344 void (*symlink
) (fuse_req_t req
, const char *link
, fuse_ino_t parent
,
352 * @param req request handle
353 * @param parent inode number of the old parent directory
354 * @param name old name
355 * @param newparent inode number of the new parent directory
356 * @param newname new name
358 void (*rename
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
359 fuse_ino_t newparent
, const char *newname
);
368 * @param req request handle
369 * @param ino the old inode number
370 * @param newparent inode number of the new parent directory
371 * @param newname new name to create
373 void (*link
) (fuse_req_t req
, fuse_ino_t ino
, fuse_ino_t newparent
,
374 const char *newname
);
379 * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
380 * O_TRUNC) are available in fi->flags.
382 * Filesystem may store an arbitrary file handle (pointer, index,
383 * etc) in fi->fh, and use this in other all other file operations
384 * (read, write, flush, release, fsync).
386 * Filesystem may also implement stateless file I/O and not store
387 * anything in fi->fh.
389 * There are also some flags (direct_io, keep_cache) which the
390 * filesystem may set in fi, to change the way the file is opened.
391 * See fuse_file_info structure in <fuse_common.h> for more details.
397 * @param req request handle
398 * @param ino the inode number
399 * @param fi file information
401 void (*open
) (fuse_req_t req
, fuse_ino_t ino
,
402 struct fuse_file_info
*fi
);
407 * Read should send exactly the number of bytes requested except
408 * on EOF or error, otherwise the rest of the data will be
409 * substituted with zeroes. An exception to this is when the file
410 * has been opened in 'direct_io' mode, in which case the return
411 * value of the read system call will reflect the return value of
414 * fi->fh will contain the value set by the open method, or will
415 * be undefined if the open method didn't set any value.
423 * @param req request handle
424 * @param ino the inode number
425 * @param size number of bytes to read
426 * @param off offset to read from
427 * @param fi file information
429 void (*read
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
, off_t off
,
430 struct fuse_file_info
*fi
);
435 * Write should return exactly the number of bytes requested
436 * except on error. An exception to this is when the file has
437 * been opened in 'direct_io' mode, in which case the return value
438 * of the write system call will reflect the return value of this
441 * fi->fh will contain the value set by the open method, or will
442 * be undefined if the open method didn't set any value.
448 * @param req request handle
449 * @param ino the inode number
450 * @param buf data to write
451 * @param size number of bytes to write
452 * @param off offset to write to
453 * @param fi file information
455 void (*write
) (fuse_req_t req
, fuse_ino_t ino
, const char *buf
,
456 size_t size
, off_t off
, struct fuse_file_info
*fi
);
461 * This is called on each close() of the opened file.
463 * Since file descriptors can be duplicated (dup, dup2, fork), for
464 * one open call there may be many flush calls.
466 * Filesystems shouldn't assume that flush will always be called
467 * after some writes, or that if will be called at all.
469 * fi->fh will contain the value set by the open method, or will
470 * be undefined if the open method didn't set any value.
472 * NOTE: the name of the method is misleading, since (unlike
473 * fsync) the filesystem is not forced to flush pending writes.
474 * One reason to flush data, is if the filesystem wants to return
477 * If the filesystem supports file locking operations (setlk,
478 * getlk) it should remove all locks belonging to 'fi->owner'.
483 * @param req request handle
484 * @param ino the inode number
485 * @param fi file information
487 void (*flush
) (fuse_req_t req
, fuse_ino_t ino
,
488 struct fuse_file_info
*fi
);
491 * Release an open file
493 * Release is called when there are no more references to an open
494 * file: all file descriptors are closed and all memory mappings
497 * For every open call there will be exactly one release call.
499 * The filesystem may reply with an error, but error values are
500 * not returned to close() or munmap() which triggered the
503 * fi->fh will contain the value set by the open method, or will
504 * be undefined if the open method didn't set any value.
505 * fi->flags will contain the same flags as for open.
510 * @param req request handle
511 * @param ino the inode number
512 * @param fi file information
514 void (*release
) (fuse_req_t req
, fuse_ino_t ino
,
515 struct fuse_file_info
*fi
);
518 * Synchronize file contents
520 * If the datasync parameter is non-zero, then only the user data
521 * should be flushed, not the meta data.
526 * @param req request handle
527 * @param ino the inode number
528 * @param datasync flag indicating if only data should be flushed
529 * @param fi file information
531 void (*fsync
) (fuse_req_t req
, fuse_ino_t ino
, int datasync
,
532 struct fuse_file_info
*fi
);
537 * Filesystem may store an arbitrary file handle (pointer, index,
538 * etc) in fi->fh, and use this in other all other directory
539 * stream operations (readdir, releasedir, fsyncdir).
541 * Filesystem may also implement stateless directory I/O and not
542 * store anything in fi->fh, though that makes it impossible to
543 * implement standard conforming directory stream operations in
544 * case the contents of the directory can change between opendir
551 * @param req request handle
552 * @param ino the inode number
553 * @param fi file information
555 void (*opendir
) (fuse_req_t req
, fuse_ino_t ino
,
556 struct fuse_file_info
*fi
);
561 * Send a buffer filled using fuse_add_direntry(), with size not
562 * exceeding the requested size. Send an empty buffer on end of
565 * fi->fh will contain the value set by the opendir method, or
566 * will be undefined if the opendir method didn't set any value.
573 * @param req request handle
574 * @param ino the inode number
575 * @param size maximum number of bytes to send
576 * @param off offset to continue reading the directory stream
577 * @param fi file information
579 void (*readdir
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
, off_t off
,
580 struct fuse_file_info
*fi
);
583 * Release an open directory
585 * For every opendir call there will be exactly one releasedir
588 * fi->fh will contain the value set by the opendir method, or
589 * will be undefined if the opendir method didn't set any value.
594 * @param req request handle
595 * @param ino the inode number
596 * @param fi file information
598 void (*releasedir
) (fuse_req_t req
, fuse_ino_t ino
,
599 struct fuse_file_info
*fi
);
602 * Synchronize directory contents
604 * If the datasync parameter is non-zero, then only the directory
605 * contents should be flushed, not the meta data.
607 * fi->fh will contain the value set by the opendir method, or
608 * will be undefined if the opendir method didn't set any value.
613 * @param req request handle
614 * @param ino the inode number
615 * @param datasync flag indicating if only data should be flushed
616 * @param fi file information
618 void (*fsyncdir
) (fuse_req_t req
, fuse_ino_t ino
, int datasync
,
619 struct fuse_file_info
*fi
);
622 * Get file system statistics
628 * @param req request handle
629 * @param ino the inode number, zero means "undefined"
631 void (*statfs
) (fuse_req_t req
, fuse_ino_t ino
);
634 * Set an extended attribute
639 void (*setxattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
,
640 const char *value
, size_t size
, int flags
);
643 * Get an extended attribute
645 * If size is zero, the size of the value should be sent with
648 * If the size is non-zero, and the value fits in the buffer, the
649 * value should be sent with fuse_reply_buf.
651 * If the size is too small for the value, the ERANGE error should
660 * @param req request handle
661 * @param ino the inode number
662 * @param name of the extended attribute
663 * @param size maximum size of the value to send
665 void (*getxattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
,
669 * List extended attribute names
671 * If size is zero, the total size of the attribute list should be
672 * sent with fuse_reply_xattr.
674 * If the size is non-zero, and the null character separated
675 * attribute list fits in the buffer, the list should be sent with
678 * If the size is too small for the list, the ERANGE error should
687 * @param req request handle
688 * @param ino the inode number
689 * @param size maximum size of the list to send
691 void (*listxattr
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
);
694 * Remove an extended attribute
699 * @param req request handle
700 * @param ino the inode number
701 * @param name of the extended attribute
703 void (*removexattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
);
706 * Check file access permissions
708 * This will be called for the access() system call. If the
709 * 'default_permissions' mount option is given, this method is not
712 * This method is not called under Linux kernel versions 2.4.x
714 * Introduced in version 2.5
719 * @param req request handle
720 * @param ino the inode number
721 * @param mask requested access mode
723 void (*access
) (fuse_req_t req
, fuse_ino_t ino
, int mask
);
726 * Create and open a file
728 * If the file does not exist, first create it with the specified
729 * mode, and then open it.
731 * Open flags (with the exception of O_NOCTTY) are available in
734 * Filesystem may store an arbitrary file handle (pointer, index,
735 * etc) in fi->fh, and use this in other all other file operations
736 * (read, write, flush, release, fsync).
738 * There are also some flags (direct_io, keep_cache) which the
739 * filesystem may set in fi, to change the way the file is opened.
740 * See fuse_file_info structure in <fuse_common.h> for more details.
742 * If this method is not implemented or under Linux kernel
743 * versions earlier than 2.6.15, the mknod() and open() methods
744 * will be called instead.
746 * Introduced in version 2.5
752 * @param req request handle
753 * @param parent inode number of the parent directory
754 * @param name to create
755 * @param mode file type and mode with which to create the new file
756 * @param fi file information
758 void (*create
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
759 mode_t mode
, struct fuse_file_info
*fi
);
762 * Test for a POSIX file lock
764 * Introduced in version 2.6
770 * @param req request handle
771 * @param ino the inode number
772 * @param fi file information
773 * @param lock the region/type to test
775 void (*getlk
) (fuse_req_t req
, fuse_ino_t ino
,
776 struct fuse_file_info
*fi
, struct flock
*lock
);
779 * Acquire, modify or release a POSIX file lock
781 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
782 * owner, but otherwise this is not always the case. For checking
783 * lock ownership, 'fi->owner' must be used. The l_pid field in
784 * 'struct flock' should only be used to fill in this field in
787 * Note: if the locking methods are not implemented, the kernel
788 * will still allow file locking to work locally. Hence these are
789 * only interesting for network filesystems and similar.
791 * Introduced in version 2.6
796 * @param req request handle
797 * @param ino the inode number
798 * @param fi file information
799 * @param lock the region/type to set
800 * @param sleep locking operation may sleep
802 void (*setlk
) (fuse_req_t req
, fuse_ino_t ino
,
803 struct fuse_file_info
*fi
,
804 struct flock
*lock
, int sleep
);
807 * Map block index within file to block index within device
809 * Note: This makes sense only for block device backed filesystems
810 * mounted with the 'blkdev' option
812 * Introduced in version 2.6
818 * @param req request handle
819 * @param ino the inode number
820 * @param blocksize unit of block index
821 * @param idx block index within file
823 void (*bmap
) (fuse_req_t req
, fuse_ino_t ino
, size_t blocksize
,
829 * Note: For unrestricted ioctls (not allowed for FUSE
830 * servers), data in and out areas can be discovered by giving
831 * iovs and setting FUSE_IOCTL_RETRY in @flags. For
832 * restricted ioctls, kernel prepares in/out data area
833 * according to the information encoded in cmd.
835 * Introduced in version 2.8
838 * fuse_reply_ioctl_retry
840 * fuse_reply_ioctl_iov
843 * @param req request handle
844 * @param ino the inode number
845 * @param cmd ioctl command
846 * @param arg ioctl argument
847 * @param fi file information
848 * @param flags for FUSE_IOCTL_* flags
849 * @param in_buf data fetched from the caller
850 * @param in_bufsz number of fetched bytes
851 * @param out_bufsz maximum size of output data
853 void (*ioctl
) (fuse_req_t req
, fuse_ino_t ino
, int cmd
, void *arg
,
854 struct fuse_file_info
*fi
, unsigned flags
,
855 const void *in_buf
, size_t in_bufsz
, size_t out_bufsz
);
858 * Poll for IO readiness
860 * Introduced in version 2.8
862 * Note: If ph is non-NULL, the client should notify
863 * when IO readiness events occur by calling
864 * fuse_lowelevel_notify_poll() with the specified ph.
866 * Regardless of the number of times poll with a non-NULL ph
867 * is received, single notification is enough to clear all.
868 * Notifying more times incurs overhead but doesn't harm
871 * The callee is responsible for destroying ph with
872 * fuse_pollhandle_destroy() when no longer in use.
878 * @param req request handle
879 * @param ino the inode number
880 * @param fi file information
881 * @param ph poll handle to be used for notification
883 void (*poll
) (fuse_req_t req
, fuse_ino_t ino
, struct fuse_file_info
*fi
,
884 struct fuse_pollhandle
*ph
);
887 * Write data made available in a buffer
889 * This is a more generic version of the ->write() method. If
890 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
891 * kernel supports splicing from the fuse device, then the
892 * data will be made available in pipe for supporting zero
893 * copy data transfer.
895 * Introduced in version 2.9
901 * @param req request handle
902 * @param ino the inode number
903 * @param bufv buffer containing the data
904 * @param off offset to write to
905 * @param fi file information
907 void (*write_buf
) (fuse_req_t req
, fuse_ino_t ino
,
908 struct fuse_bufvec
*bufv
, off_t off
,
909 struct fuse_file_info
*fi
);
912 * Callback function for the retrieve request
914 * Introduced in version 2.9
919 * @param req request handle
920 * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
921 * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
922 * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
923 * @param bufv the buffer containing the returned data
925 void (*retrieve_reply
) (fuse_req_t req
, void *cookie
, fuse_ino_t ino
,
926 off_t offset
, struct fuse_bufvec
*bufv
);
929 * Forget about multiple inodes
931 * Introduced in version 2.9
936 * @param req request handle
938 void (*forget_multi
) (fuse_req_t req
, size_t count
,
939 struct fuse_forget_data
*forgets
);
942 * Acquire, modify or release a BSD file lock
944 * Note: if the locking methods are not implemented, the kernel
945 * will still allow file locking to work locally. Hence these are
946 * only interesting for network filesystems and similar.
948 * Introduced in version 2.9
953 * @param req request handle
954 * @param ino the inode number
955 * @param fi file information
956 * @param op the locking operation, see flock(2)
958 void (*flock
) (fuse_req_t req
, fuse_ino_t ino
,
959 struct fuse_file_info
*fi
, int op
);
962 * Direct mmap (CUSE only for now)
964 * @param req request handle
965 * @param ino the inode number
966 * @param addr starting address (in clients address space)
967 * @param length length of the mapping
968 * @param prot desired memory protection of the mapping
969 * @param flags mmap flags
970 * @param fi file information
972 * Introduced in version 2.9
974 void (*mmap
) (fuse_req_t req
, fuse_ino_t ino
, uint64_t addr
,
975 size_t length
, int prot
, int flags
, off_t offset
,
976 struct fuse_file_info
*fi
);
979 * Direct munmap (CUSE only for now)
981 * @param req request handle
982 * @param ino the inode number
983 * @param map_id identifies the mapping
984 * @param length length of the mapping
985 * @param fi file information
987 * Introduced in version 2.9
989 void (*munmap
) (fuse_req_t req
, fuse_ino_t ino
, uint64_t map_id
,
990 size_t length
, struct fuse_file_info
*fi
);
994 * Reply with an error code or success
999 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1000 * removexattr and setlk may send a zero code
1002 * @param req request handle
1003 * @param err the positive error value, or zero for success
1004 * @return zero for success, -errno for failure to send reply
1006 int fuse_reply_err(fuse_req_t req
, int err
);
1011 * Possible requests:
1014 * @param req request handle
1016 void fuse_reply_none(fuse_req_t req
);
1019 * Reply with a directory entry
1021 * Possible requests:
1022 * lookup, mknod, mkdir, symlink, link
1024 * @param req request handle
1025 * @param e the entry parameters
1026 * @return zero for success, -errno for failure to send reply
1028 int fuse_reply_entry(fuse_req_t req
, const struct fuse_entry_param
*e
);
1031 * Reply with a directory entry and open parameters
1033 * currently the following members of 'fi' are used:
1034 * fh, direct_io, keep_cache
1036 * Possible requests:
1039 * @param req request handle
1040 * @param e the entry parameters
1041 * @param fi file information
1042 * @return zero for success, -errno for failure to send reply
1044 int fuse_reply_create(fuse_req_t req
, const struct fuse_entry_param
*e
,
1045 const struct fuse_file_info
*fi
);
1048 * Reply with attributes
1050 * Possible requests:
1053 * @param req request handle
1054 * @param attr the attributes
1055 * @param attr_timeout validity timeout (in seconds) for the attributes
1056 * @return zero for success, -errno for failure to send reply
1058 int fuse_reply_attr(fuse_req_t req
, const struct stat
*attr
,
1059 double attr_timeout
);
1062 * Reply with the contents of a symbolic link
1064 * Possible requests:
1067 * @param req request handle
1068 * @param link symbolic link contents
1069 * @return zero for success, -errno for failure to send reply
1071 int fuse_reply_readlink(fuse_req_t req
, const char *link
);
1074 * Reply with open parameters
1076 * currently the following members of 'fi' are used:
1077 * fh, direct_io, keep_cache
1079 * Possible requests:
1082 * @param req request handle
1083 * @param fi file information
1084 * @return zero for success, -errno for failure to send reply
1086 int fuse_reply_open(fuse_req_t req
, const struct fuse_file_info
*fi
);
1089 * Reply with number of bytes written
1091 * Possible requests:
1094 * @param req request handle
1095 * @param count the number of bytes written
1096 * @return zero for success, -errno for failure to send reply
1098 int fuse_reply_write(fuse_req_t req
, size_t count
);
1103 * Possible requests:
1104 * read, readdir, getxattr, listxattr
1106 * @param req request handle
1107 * @param buf buffer containing data
1108 * @param size the size of data in bytes
1109 * @return zero for success, -errno for failure to send reply
1111 int fuse_reply_buf(fuse_req_t req
, const char *buf
, size_t size
);
1114 * Reply with data copied/moved from buffer(s)
1116 * Possible requests:
1117 * read, readdir, getxattr, listxattr
1119 * @param req request handle
1120 * @param bufv buffer vector
1121 * @param flags flags controlling the copy
1122 * @return zero for success, -errno for failure to send reply
1124 int fuse_reply_data(fuse_req_t req
, struct fuse_bufvec
*bufv
,
1125 enum fuse_buf_copy_flags flags
);
1128 * Reply with data vector
1130 * Possible requests:
1131 * read, readdir, getxattr, listxattr
1133 * @param req request handle
1134 * @param iov the vector containing the data
1135 * @param count the size of vector
1136 * @return zero for success, -errno for failure to send reply
1138 int fuse_reply_iov(fuse_req_t req
, const struct iovec
*iov
, int count
);
1141 * Reply with filesystem statistics
1143 * Possible requests:
1146 * @param req request handle
1147 * @param stbuf filesystem statistics
1148 * @return zero for success, -errno for failure to send reply
1150 int fuse_reply_statfs(fuse_req_t req
, const struct statvfs
*stbuf
);
1153 * Reply with needed buffer size
1155 * Possible requests:
1156 * getxattr, listxattr
1158 * @param req request handle
1159 * @param count the buffer size needed in bytes
1160 * @return zero for success, -errno for failure to send reply
1162 int fuse_reply_xattr(fuse_req_t req
, size_t count
);
1165 * Reply with file lock information
1167 * Possible requests:
1170 * @param req request handle
1171 * @param lock the lock information
1172 * @return zero for success, -errno for failure to send reply
1174 int fuse_reply_lock(fuse_req_t req
, const struct flock
*lock
);
1177 * Reply with block index
1179 * Possible requests:
1182 * @param req request handle
1183 * @param idx block index within device
1184 * @return zero for success, -errno for failure to send reply
1186 int fuse_reply_bmap(fuse_req_t req
, uint64_t idx
);
1188 /* ----------------------------------------------------------- *
1189 * Filling a buffer in readdir *
1190 * ----------------------------------------------------------- */
1193 * Add a directory entry to the buffer
1195 * Buffer needs to be large enough to hold the entry. If it's not,
1196 * then the entry is not filled in but the size of the entry is still
1197 * returned. The caller can check this by comparing the bufsize
1198 * parameter with the returned entry size. If the entry size is
1199 * larger than the buffer size, the operation failed.
1201 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1202 * st_mode field are used. The other fields are ignored.
1204 * Note: offsets do not necessarily represent physical offsets, and
1205 * could be any marker, that enables the implementation to find a
1206 * specific point in the directory stream.
1208 * @param req request handle
1209 * @param buf the point where the new entry will be added to the buffer
1210 * @param bufsize remaining size of the buffer
1211 * @param name the name of the entry
1212 * @param stbuf the file attributes
1213 * @param off the offset of the next entry
1214 * @return the space needed for the entry
1216 size_t fuse_add_direntry(fuse_req_t req
, char *buf
, size_t bufsize
,
1217 const char *name
, const struct stat
*stbuf
,
1221 * Reply to ask for data fetch and output buffer preparation. ioctl
1222 * will be retried with the specified input data fetched and output
1225 * Possible requests:
1228 * @param req request handle
1229 * @param in_iov iovec specifying data to fetch from the caller
1230 * @param in_count number of entries in in_iov
1231 * @param out_iov iovec specifying addresses to write output to
1232 * @param out_count number of entries in out_iov
1233 * @return zero for success, -errno for failure to send reply
1235 int fuse_reply_ioctl_retry(fuse_req_t req
,
1236 const struct iovec
*in_iov
, size_t in_count
,
1237 const struct iovec
*out_iov
, size_t out_count
);
1240 * Reply to finish ioctl
1242 * Possible requests:
1245 * @param req request handle
1246 * @param result result to be passed to the caller
1247 * @param buf buffer containing output data
1248 * @param size length of output data
1250 int fuse_reply_ioctl(fuse_req_t req
, int result
, const void *buf
, size_t size
);
1253 * Reply to finish ioctl with iov buffer
1255 * Possible requests:
1258 * @param req request handle
1259 * @param result result to be passed to the caller
1260 * @param iov the vector containing the data
1261 * @param count the size of vector
1263 int fuse_reply_ioctl_iov(fuse_req_t req
, int result
, const struct iovec
*iov
,
1267 * Reply with poll result event mask
1269 * @param req request handle
1270 * @param revents poll result event mask
1272 int fuse_reply_poll(fuse_req_t req
, unsigned revents
);
1275 * Reply to an mmap request
1277 * Possible requests:
1280 * @param req request handle
1281 * @param map_id identifies the mapping
1282 * @param length length of the mapping (from zero offset)
1284 int fuse_reply_mmap(fuse_req_t req
, uint64_t map_id
, size_t length
);
1286 /* ----------------------------------------------------------- *
1288 * ----------------------------------------------------------- */
1291 * Notify IO readiness event
1293 * For more information, please read comment for poll operation.
1295 * @param ph poll handle to notify IO readiness event for
1297 int fuse_lowlevel_notify_poll(struct fuse_pollhandle
*ph
);
1300 * Notify to invalidate cache for an inode
1302 * @param ch the channel through which to send the invalidation
1303 * @param ino the inode number
1304 * @param off the offset in the inode where to start invalidating
1305 * or negative to invalidate attributes only
1306 * @param len the amount of cache to invalidate or 0 for all
1307 * @return zero for success, -errno for failure
1309 int fuse_lowlevel_notify_inval_inode(struct fuse_chan
*ch
, fuse_ino_t ino
,
1310 off_t off
, off_t len
);
1313 * Notify to invalidate parent attributes and the dentry matching
1316 * @param ch the channel through which to send the invalidation
1317 * @param parent inode number
1318 * @param name file name
1319 * @param namelen strlen() of file name
1320 * @return zero for success, -errno for failure
1322 int fuse_lowlevel_notify_inval_entry(struct fuse_chan
*ch
, fuse_ino_t parent
,
1323 const char *name
, size_t namelen
);
1326 * Notify to invalidate parent attributes and delete the dentry matching
1327 * parent/name if the dentry's inode number matches child (otherwise it
1328 * will invalidate the matching dentry).
1330 * @param ch the channel through which to send the notification
1331 * @param parent inode number
1332 * @param child inode number
1333 * @param name file name
1334 * @param namelen strlen() of file name
1335 * @return zero for success, -errno for failure
1337 int fuse_lowlevel_notify_delete(struct fuse_chan
*ch
,
1338 fuse_ino_t parent
, fuse_ino_t child
,
1339 const char *name
, size_t namelen
);
1342 * Store data to the kernel buffers
1344 * Synchronously store data in the kernel buffers belonging to the
1345 * given inode. The stored data is marked up-to-date (no read will be
1346 * performed against it, unless it's invalidated or evicted from the
1349 * If the stored data overflows the current file size, then the size
1350 * is extended, similarly to a write(2) on the filesystem.
1352 * If this function returns an error, then the store wasn't fully
1353 * completed, but it may have been partially completed.
1355 * @param ch the channel through which to send the invalidation
1356 * @param ino the inode number
1357 * @param offset the starting offset into the file to store to
1358 * @param bufv buffer vector
1359 * @param flags flags controlling the copy
1360 * @return zero for success, -errno for failure
1362 int fuse_lowlevel_notify_store(struct fuse_chan
*ch
, fuse_ino_t ino
,
1363 off_t offset
, struct fuse_bufvec
*bufv
,
1364 enum fuse_buf_copy_flags flags
);
1366 * Retrieve data from the kernel buffers
1368 * Retrieve data in the kernel buffers belonging to the given inode.
1369 * If successful then the retrieve_reply() method will be called with
1370 * the returned data.
1372 * Only present pages are returned in the retrieve reply. Retrieving
1373 * stops when it finds a non-present page and only data prior to that is
1376 * If this function returns an error, then the retrieve will not be
1377 * completed and no reply will be sent.
1379 * This function doesn't change the dirty state of pages in the kernel
1380 * buffer. For dirty pages the write() method will be called
1381 * regardless of having been retrieved previously.
1383 * @param ch the channel through which to send the invalidation
1384 * @param ino the inode number
1385 * @param size the number of bytes to retrieve
1386 * @param offset the starting offset into the file to retrieve from
1387 * @param cookie user data to supply to the reply callback
1388 * @return zero for success, -errno for failure
1390 int fuse_lowlevel_notify_retrieve(struct fuse_chan
*ch
, fuse_ino_t ino
,
1391 size_t size
, off_t offset
, void *cookie
);
1394 /* ----------------------------------------------------------- *
1395 * Utility functions *
1396 * ----------------------------------------------------------- */
1399 * Get the userdata from the request
1401 * @param req request handle
1402 * @return the user data passed to fuse_lowlevel_new()
1404 void *fuse_req_userdata(fuse_req_t req
);
1407 * Get the context from the request
1409 * The pointer returned by this function will only be valid for the
1410 * request's lifetime
1412 * @param req request handle
1413 * @return the context structure
1415 const struct fuse_ctx
*fuse_req_ctx(fuse_req_t req
);
1418 * Get the current supplementary group IDs for the specified request
1420 * Similar to the getgroups(2) system call, except the return value is
1421 * always the total number of group IDs, even if it is larger than the
1424 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1425 * the group list to userspace, hence this function needs to parse
1426 * "/proc/$TID/task/$TID/status" to get the group IDs.
1428 * This feature may not be supported on all operating systems. In
1429 * such a case this function will return -ENOSYS.
1431 * @param req request handle
1432 * @param size size of given array
1433 * @param list array of group IDs to be filled in
1434 * @return the total number of supplementary group IDs or -errno on failure
1436 int fuse_req_getgroups(fuse_req_t req
, int size
, gid_t list
[]);
1439 * Callback function for an interrupt
1441 * @param req interrupted request
1442 * @param data user data
1444 typedef void (*fuse_interrupt_func_t
)(fuse_req_t req
, void *data
);
1447 * Register/unregister callback for an interrupt
1449 * If an interrupt has already happened, then the callback function is
1450 * called from within this function, hence it's not possible for
1451 * interrupts to be lost.
1453 * @param req request handle
1454 * @param func the callback function or NULL for unregister
1455 * @param data user data passed to the callback function
1457 void fuse_req_interrupt_func(fuse_req_t req
, fuse_interrupt_func_t func
,
1461 * Check if a request has already been interrupted
1463 * @param req request handle
1464 * @return 1 if the request has been interrupted, 0 otherwise
1466 int fuse_req_interrupted(fuse_req_t req
);
1468 /* ----------------------------------------------------------- *
1469 * Filesystem setup *
1470 * ----------------------------------------------------------- */
1472 /* Deprecated, don't use */
1473 int fuse_lowlevel_is_lib_option(const char *opt
);
1476 * Create a low level session
1478 * @param args argument vector
1479 * @param op the low level filesystem operations
1480 * @param op_size sizeof(struct fuse_lowlevel_ops)
1481 * @param userdata user data
1482 * @return the created session object, or NULL on failure
1484 struct fuse_session
*fuse_lowlevel_new(struct fuse_args
*args
,
1485 const struct fuse_lowlevel_ops
*op
,
1486 size_t op_size
, void *userdata
);
1488 /* ----------------------------------------------------------- *
1489 * Session interface *
1490 * ----------------------------------------------------------- */
1493 * Session operations
1495 * This is used in session creation
1497 struct fuse_session_ops
{
1499 * Hook to process a request (mandatory)
1501 * @param data user data passed to fuse_session_new()
1502 * @param buf buffer containing the raw request
1503 * @param len request length
1504 * @param ch channel on which the request was received
1506 void (*process
) (void *data
, const char *buf
, size_t len
,
1507 struct fuse_chan
*ch
);
1510 * Hook for session exit and reset (optional)
1512 * @param data user data passed to fuse_session_new()
1513 * @param val exited status (1 - exited, 0 - not exited)
1515 void (*exit
) (void *data
, int val
);
1518 * Hook for querying the current exited status (optional)
1520 * @param data user data passed to fuse_session_new()
1521 * @return 1 if exited, 0 if not exited
1523 int (*exited
) (void *data
);
1526 * Hook for cleaning up the channel on destroy (optional)
1528 * @param data user data passed to fuse_session_new()
1530 void (*destroy
) (void *data
);
1534 * Create a new session
1536 * @param op session operations
1537 * @param data user data
1538 * @return new session object, or NULL on failure
1540 struct fuse_session
*fuse_session_new(struct fuse_session_ops
*op
, void *data
);
1543 * Assign a channel to a session
1545 * Note: currently only a single channel may be assigned. This may
1546 * change in the future
1548 * If a session is destroyed, the assigned channel is also destroyed
1550 * @param se the session
1551 * @param ch the channel
1553 void fuse_session_add_chan(struct fuse_session
*se
, struct fuse_chan
*ch
);
1556 * Remove a channel from a session
1558 * If the channel is not assigned to a session, then this is a no-op
1560 * @param ch the channel to remove
1562 void fuse_session_remove_chan(struct fuse_chan
*ch
);
1565 * Iterate over the channels assigned to a session
1567 * The iterating function needs to start with a NULL channel, and
1568 * after that needs to pass the previously returned channel to the
1571 * @param se the session
1572 * @param ch the previous channel, or NULL
1573 * @return the next channel, or NULL if no more channels exist
1575 struct fuse_chan
*fuse_session_next_chan(struct fuse_session
*se
,
1576 struct fuse_chan
*ch
);
1579 * Process a raw request
1581 * @param se the session
1582 * @param buf buffer containing the raw request
1583 * @param len request length
1584 * @param ch channel on which the request was received
1586 void fuse_session_process(struct fuse_session
*se
, const char *buf
, size_t len
,
1587 struct fuse_chan
*ch
);
1590 * Process a raw request supplied in a generic buffer
1592 * This is a more generic version of fuse_session_process(). The
1593 * fuse_buf may contain a memory buffer or a pipe file descriptor.
1595 * @param se the session
1596 * @param buf the fuse_buf containing the request
1597 * @param ch channel on which the request was received
1599 void fuse_session_process_buf(struct fuse_session
*se
,
1600 const struct fuse_buf
*buf
, struct fuse_chan
*ch
);
1603 * Receive a raw request supplied in a generic buffer
1605 * This is a more generic version of fuse_chan_recv(). The fuse_buf
1606 * supplied to this function contains a suitably allocated memory
1607 * buffer. This may be overwritten with a file descriptor buffer.
1609 * @param se the session
1610 * @param buf the fuse_buf to store the request in
1611 * @param chp pointer to the channel
1612 * @return the actual size of the raw request, or -errno on error
1614 int fuse_session_receive_buf(struct fuse_session
*se
, struct fuse_buf
*buf
,
1615 struct fuse_chan
**chp
);
1620 * @param se the session
1622 void fuse_session_destroy(struct fuse_session
*se
);
1627 * @param se the session
1629 void fuse_session_exit(struct fuse_session
*se
);
1632 * Reset the exited status of a session
1634 * @param se the session
1636 void fuse_session_reset(struct fuse_session
*se
);
1639 * Query the exited status of a session
1641 * @param se the session
1642 * @return 1 if exited, 0 if not exited
1644 int fuse_session_exited(struct fuse_session
*se
);
1647 * Get the user data provided to the session
1649 * @param se the session
1650 * @return the user data
1652 void *fuse_session_data(struct fuse_session
*se
);
1655 * Enter a single threaded event loop
1657 * @param se the session
1658 * @return 0 on success, -1 on error
1660 int fuse_session_loop(struct fuse_session
*se
);
1663 * Enter a multi-threaded event loop
1665 * @param se the session
1666 * @return 0 on success, -1 on error
1668 int fuse_session_loop_mt(struct fuse_session
*se
);
1670 /* ----------------------------------------------------------- *
1671 * Channel interface *
1672 * ----------------------------------------------------------- */
1675 * Channel operations
1677 * This is used in channel creation
1679 struct fuse_chan_ops
{
1681 * Hook for receiving a raw request
1683 * @param ch pointer to the channel
1684 * @param buf the buffer to store the request in
1685 * @param size the size of the buffer
1686 * @return the actual size of the raw request, or -1 on error
1688 int (*receive
)(struct fuse_chan
**chp
, char *buf
, size_t size
);
1691 * Hook for sending a raw reply
1693 * A return value of -ENOENT means, that the request was
1694 * interrupted, and the reply was discarded
1696 * @param ch the channel
1697 * @param iov vector of blocks
1698 * @param count the number of blocks in vector
1699 * @return zero on success, -errno on failure
1701 int (*send
)(struct fuse_chan
*ch
, const struct iovec iov
[],
1705 * Destroy the channel
1707 * @param ch the channel
1709 void (*destroy
)(struct fuse_chan
*ch
);
1713 * Create a new channel
1715 * @param op channel operations
1716 * @param fd file descriptor of the channel
1717 * @param bufsize the minimal receive buffer size
1718 * @param data user data
1719 * @return the new channel object, or NULL on failure
1721 struct fuse_chan
*fuse_chan_new(struct fuse_chan_ops
*op
, int fd
,
1722 size_t bufsize
, void *data
);
1725 * Query the file descriptor of the channel
1727 * @param ch the channel
1728 * @return the file descriptor passed to fuse_chan_new()
1730 int fuse_chan_fd(struct fuse_chan
*ch
);
1733 * Query the minimal receive buffer size
1735 * @param ch the channel
1736 * @return the buffer size passed to fuse_chan_new()
1738 size_t fuse_chan_bufsize(struct fuse_chan
*ch
);
1741 * Query the user data
1743 * @param ch the channel
1744 * @return the user data passed to fuse_chan_new()
1746 void *fuse_chan_data(struct fuse_chan
*ch
);
1749 * Query the session to which this channel is assigned
1751 * @param ch the channel
1752 * @return the session, or NULL if the channel is not assigned
1754 struct fuse_session
*fuse_chan_session(struct fuse_chan
*ch
);
1757 * Receive a raw request
1759 * A return value of -ENODEV means, that the filesystem was unmounted
1761 * @param ch pointer to the channel
1762 * @param buf the buffer to store the request in
1763 * @param size the size of the buffer
1764 * @return the actual size of the raw request, or -errno on error
1766 int fuse_chan_recv(struct fuse_chan
**ch
, char *buf
, size_t size
);
1771 * A return value of -ENOENT means, that the request was
1772 * interrupted, and the reply was discarded
1774 * @param ch the channel
1775 * @param iov vector of blocks
1776 * @param count the number of blocks in vector
1777 * @return zero on success, -errno on failure
1779 int fuse_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[],
1785 * @param ch the channel
1787 void fuse_chan_destroy(struct fuse_chan
*ch
);
1789 /* ----------------------------------------------------------- *
1790 * Compatibility stuff *
1791 * ----------------------------------------------------------- */
1793 #if FUSE_USE_VERSION < 26
1794 # include "fuse_lowlevel_compat.h"
1795 # define fuse_chan_ops fuse_chan_ops_compat24
1796 # define fuse_chan_new fuse_chan_new_compat24
1797 # if FUSE_USE_VERSION == 25
1798 # define fuse_lowlevel_ops fuse_lowlevel_ops_compat25
1799 # define fuse_lowlevel_new fuse_lowlevel_new_compat25
1800 # elif FUSE_USE_VERSION == 24
1801 # define fuse_lowlevel_ops fuse_lowlevel_ops_compat
1802 # define fuse_lowlevel_new fuse_lowlevel_new_compat
1803 # define fuse_file_info fuse_file_info_compat
1804 # define fuse_reply_statfs fuse_reply_statfs_compat
1805 # define fuse_reply_open fuse_reply_open_compat
1807 # error Compatibility with low-level API version < 24 not supported
1815 #endif /* _FUSE_LOWLEVEL_H_ */