Merge branch 'clone_fd'
[fuse.git] / include / fuse_lowlevel.h
blob3cc9db574518fe4c4e34fb2bd39d1ad8ed8104a8
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 /** @file
14 * Low level API
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
19 * 25
22 #ifndef FUSE_USE_VERSION
23 #define FUSE_USE_VERSION 24
24 #endif
26 #include "fuse_common.h"
28 #include <utime.h>
29 #include <fcntl.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <sys/statvfs.h>
33 #include <sys/uio.h>
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
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 uint64_t fuse_ino_t;
49 /** Request pointer type */
50 typedef struct fuse_req *fuse_req_t;
52 /**
53 * Session
55 * This provides hooks for processing requests, and exiting
57 struct fuse_session;
59 /**
60 * Channel
62 * A communication channel, providing hooks for sending and receiving
63 * messages
65 struct fuse_chan;
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
74 * seconds.
76 fuse_ino_t ino;
78 /** Generation number for this entry.
80 * If the file system will be exported over NFS, the
81 * ino/generation pairs need to be unique over the file
82 * system's lifetime (rather than just the mount time). So if
83 * the file system reuses an inode after it has been deleted,
84 * it must assign a new, previously unused generation number
85 * to the inode at the same time.
87 * The generation must be non-zero, otherwise FUSE will treat
88 * it as an error.
91 uint64_t generation;
93 /** Inode attributes.
95 * Even if attr_timeout == 0, attr must be correct. For example,
96 * for open(), FUSE uses attr.st_size from lookup() to determine
97 * how many bytes to request. If this value is not correct,
98 * incorrect data will be returned.
100 struct stat attr;
102 /** Validity timeout (in seconds) for the attributes */
103 double attr_timeout;
105 /** Validity timeout (in seconds) for the name */
106 double entry_timeout;
109 /** Additional context associated with requests */
110 struct fuse_ctx {
111 /** User ID of the calling process */
112 uid_t uid;
114 /** Group ID of the calling process */
115 gid_t gid;
117 /** Thread ID of the calling process */
118 pid_t pid;
120 /** Umask of the calling process (introduced in version 2.8) */
121 mode_t umask;
124 struct fuse_forget_data {
125 fuse_ino_t ino;
126 uint64_t nlookup;
129 /* 'to_set' flags in setattr */
130 #define FUSE_SET_ATTR_MODE (1 << 0)
131 #define FUSE_SET_ATTR_UID (1 << 1)
132 #define FUSE_SET_ATTR_GID (1 << 2)
133 #define FUSE_SET_ATTR_SIZE (1 << 3)
134 #define FUSE_SET_ATTR_ATIME (1 << 4)
135 #define FUSE_SET_ATTR_MTIME (1 << 5)
136 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
137 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
138 #define FUSE_SET_ATTR_CTIME (1 << 10)
140 /* ----------------------------------------------------------- *
141 * Request methods and replies *
142 * ----------------------------------------------------------- */
145 * Low level filesystem operations
147 * Most of the methods (with the exception of init and destroy)
148 * receive a request handle (fuse_req_t) as their first argument.
149 * This handle must be passed to one of the specified reply functions.
151 * This may be done inside the method invocation, or after the call
152 * has returned. The request handle is valid until one of the reply
153 * functions is called.
155 * Other pointer arguments (name, fuse_file_info, etc) are not valid
156 * after the call has returned, so if they are needed later, their
157 * contents have to be copied.
159 * The filesystem sometimes needs to handle a return value of -ENOENT
160 * from the reply function, which means, that the request was
161 * interrupted, and the reply discarded. For example if
162 * fuse_reply_open() return -ENOENT means, that the release method for
163 * this file will not be called.
165 struct fuse_lowlevel_ops {
167 * Initialize filesystem
169 * Called before any other filesystem method
171 * There's no reply to this function
173 * @param userdata the user data passed to fuse_lowlevel_new()
175 void (*init) (void *userdata, struct fuse_conn_info *conn);
178 * Clean up filesystem
180 * Called on filesystem exit
182 * There's no reply to this function
184 * @param userdata the user data passed to fuse_lowlevel_new()
186 void (*destroy) (void *userdata);
189 * Look up a directory entry by name and get its attributes.
191 * Valid replies:
192 * fuse_reply_entry
193 * fuse_reply_err
195 * @param req request handle
196 * @param parent inode number of the parent directory
197 * @param name the name to look up
199 void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
202 * Forget about an inode
204 * This function is called when the kernel removes an inode
205 * from its internal caches.
207 * The inode's lookup count increases by one for every call to
208 * fuse_reply_entry and fuse_reply_create. The nlookup parameter
209 * indicates by how much the lookup count should be decreased.
211 * Inodes with a non-zero lookup count may receive request from
212 * the kernel even after calls to unlink, rmdir or (when
213 * overwriting an existing file) rename. Filesystems must handle
214 * such requests properly and it is recommended to defer removal
215 * of the inode until the lookup count reaches zero. Calls to
216 * unlink, remdir or rename will be followed closely by forget
217 * unless the file or directory is open, in which case the
218 * kernel issues forget only after the release or releasedir
219 * calls.
221 * Note that if a file system will be exported over NFS the
222 * inodes lifetime must extend even beyond forget. See the
223 * generation field in struct fuse_entry_param above.
225 * On unmount the lookup count for all inodes implicitly drops
226 * to zero. It is not guaranteed that the file system will
227 * receive corresponding forget messages for the affected
228 * inodes.
230 * Valid replies:
231 * fuse_reply_none
233 * @param req request handle
234 * @param ino the inode number
235 * @param nlookup the number of lookups to forget
237 void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
240 * Get file attributes
242 * Valid replies:
243 * fuse_reply_attr
244 * fuse_reply_err
246 * @param req request handle
247 * @param ino the inode number
248 * @param fi for future use, currently always NULL
250 void (*getattr) (fuse_req_t req, fuse_ino_t ino,
251 struct fuse_file_info *fi);
254 * Set file attributes
256 * In the 'attr' argument only members indicated by the 'to_set'
257 * bitmask contain valid values. Other members contain undefined
258 * values.
260 * If the setattr was invoked from the ftruncate() system call
261 * under Linux kernel versions 2.6.15 or later, the fi->fh will
262 * contain the value set by the open method or will be undefined
263 * if the open method didn't set any value. Otherwise (not
264 * ftruncate call, or kernel version earlier than 2.6.15) the fi
265 * parameter will be NULL.
267 * Valid replies:
268 * fuse_reply_attr
269 * fuse_reply_err
271 * @param req request handle
272 * @param ino the inode number
273 * @param attr the attributes
274 * @param to_set bit mask of attributes which should be set
275 * @param fi file information, or NULL
277 * Changed in version 2.5:
278 * file information filled in for ftruncate
280 void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
281 int to_set, struct fuse_file_info *fi);
284 * Read symbolic link
286 * Valid replies:
287 * fuse_reply_readlink
288 * fuse_reply_err
290 * @param req request handle
291 * @param ino the inode number
293 void (*readlink) (fuse_req_t req, fuse_ino_t ino);
296 * Create file node
298 * Create a regular file, character device, block device, fifo or
299 * socket node.
301 * Valid replies:
302 * fuse_reply_entry
303 * fuse_reply_err
305 * @param req request handle
306 * @param parent inode number of the parent directory
307 * @param name to create
308 * @param mode file type and mode with which to create the new file
309 * @param rdev the device number (only valid if created file is a device)
311 void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
312 mode_t mode, dev_t rdev);
315 * Create a directory
317 * Valid replies:
318 * fuse_reply_entry
319 * fuse_reply_err
321 * @param req request handle
322 * @param parent inode number of the parent directory
323 * @param name to create
324 * @param mode with which to create the new file
326 void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
327 mode_t mode);
330 * Remove a file
332 * If the file's inode's lookup count is non-zero, the file
333 * system is expected to postpone any removal of the inode
334 * until the lookup count reaches zero (see description of the
335 * forget function).
337 * Valid replies:
338 * fuse_reply_err
340 * @param req request handle
341 * @param parent inode number of the parent directory
342 * @param name to remove
344 void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
347 * Remove a directory
349 * If the directory's inode's lookup count is non-zero, the
350 * file system is expected to postpone any removal of the
351 * inode until the lookup count reaches zero (see description
352 * of the forget function).
354 * Valid replies:
355 * fuse_reply_err
357 * @param req request handle
358 * @param parent inode number of the parent directory
359 * @param name to remove
361 void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
364 * Create a symbolic link
366 * Valid replies:
367 * fuse_reply_entry
368 * fuse_reply_err
370 * @param req request handle
371 * @param link the contents of the symbolic link
372 * @param parent inode number of the parent directory
373 * @param name to create
375 void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
376 const char *name);
378 /** Rename a file
380 * If the target exists it should be atomically replaced. If
381 * the target's inode's lookup count is non-zero, the file
382 * system is expected to postpone any removal of the inode
383 * until the lookup count reaches zero (see description of the
384 * forget function).
386 * Valid replies:
387 * fuse_reply_err
389 * @param req request handle
390 * @param parent inode number of the old parent directory
391 * @param name old name
392 * @param newparent inode number of the new parent directory
393 * @param newname new name
395 void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
396 fuse_ino_t newparent, const char *newname,
397 unsigned int flags);
400 * Create a hard link
402 * Valid replies:
403 * fuse_reply_entry
404 * fuse_reply_err
406 * @param req request handle
407 * @param ino the old inode number
408 * @param newparent inode number of the new parent directory
409 * @param newname new name to create
411 void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
412 const char *newname);
415 * Open a file
417 * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
418 * O_TRUNC) are available in fi->flags.
420 * Filesystem may store an arbitrary file handle (pointer, index,
421 * etc) in fi->fh, and use this in other all other file operations
422 * (read, write, flush, release, fsync).
424 * Filesystem may also implement stateless file I/O and not store
425 * anything in fi->fh.
427 * There are also some flags (direct_io, keep_cache) which the
428 * filesystem may set in fi, to change the way the file is opened.
429 * See fuse_file_info structure in <fuse_common.h> for more details.
431 * Valid replies:
432 * fuse_reply_open
433 * fuse_reply_err
435 * @param req request handle
436 * @param ino the inode number
437 * @param fi file information
439 void (*open) (fuse_req_t req, fuse_ino_t ino,
440 struct fuse_file_info *fi);
443 * Read data
445 * Read should send exactly the number of bytes requested except
446 * on EOF or error, otherwise the rest of the data will be
447 * substituted with zeroes. An exception to this is when the file
448 * has been opened in 'direct_io' mode, in which case the return
449 * value of the read system call will reflect the return value of
450 * this operation.
452 * fi->fh will contain the value set by the open method, or will
453 * be undefined if the open method didn't set any value.
455 * Valid replies:
456 * fuse_reply_buf
457 * fuse_reply_iov
458 * fuse_reply_data
459 * fuse_reply_err
461 * @param req request handle
462 * @param ino the inode number
463 * @param size number of bytes to read
464 * @param off offset to read from
465 * @param fi file information
467 void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
468 struct fuse_file_info *fi);
471 * Write data
473 * Write should return exactly the number of bytes requested
474 * except on error. An exception to this is when the file has
475 * been opened in 'direct_io' mode, in which case the return value
476 * of the write system call will reflect the return value of this
477 * operation.
479 * fi->fh will contain the value set by the open method, or will
480 * be undefined if the open method didn't set any value.
482 * Valid replies:
483 * fuse_reply_write
484 * fuse_reply_err
486 * @param req request handle
487 * @param ino the inode number
488 * @param buf data to write
489 * @param size number of bytes to write
490 * @param off offset to write to
491 * @param fi file information
493 void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
494 size_t size, off_t off, struct fuse_file_info *fi);
497 * Flush method
499 * This is called on each close() of the opened file.
501 * Since file descriptors can be duplicated (dup, dup2, fork), for
502 * one open call there may be many flush calls.
504 * Filesystems shouldn't assume that flush will always be called
505 * after some writes, or that if will be called at all.
507 * fi->fh will contain the value set by the open method, or will
508 * be undefined if the open method didn't set any value.
510 * NOTE: the name of the method is misleading, since (unlike
511 * fsync) the filesystem is not forced to flush pending writes.
512 * One reason to flush data, is if the filesystem wants to return
513 * write errors.
515 * If the filesystem supports file locking operations (setlk,
516 * getlk) it should remove all locks belonging to 'fi->owner'.
518 * Valid replies:
519 * fuse_reply_err
521 * @param req request handle
522 * @param ino the inode number
523 * @param fi file information
525 void (*flush) (fuse_req_t req, fuse_ino_t ino,
526 struct fuse_file_info *fi);
529 * Release an open file
531 * Release is called when there are no more references to an open
532 * file: all file descriptors are closed and all memory mappings
533 * are unmapped.
535 * For every open call there will be exactly one release call.
537 * The filesystem may reply with an error, but error values are
538 * not returned to close() or munmap() which triggered the
539 * release.
541 * fi->fh will contain the value set by the open method, or will
542 * be undefined if the open method didn't set any value.
543 * fi->flags will contain the same flags as for open.
545 * Valid replies:
546 * fuse_reply_err
548 * @param req request handle
549 * @param ino the inode number
550 * @param fi file information
552 void (*release) (fuse_req_t req, fuse_ino_t ino,
553 struct fuse_file_info *fi);
556 * Synchronize file contents
558 * If the datasync parameter is non-zero, then only the user data
559 * should be flushed, not the meta data.
561 * Valid replies:
562 * fuse_reply_err
564 * @param req request handle
565 * @param ino the inode number
566 * @param datasync flag indicating if only data should be flushed
567 * @param fi file information
569 void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
570 struct fuse_file_info *fi);
573 * Open a directory
575 * Filesystem may store an arbitrary file handle (pointer, index,
576 * etc) in fi->fh, and use this in other all other directory
577 * stream operations (readdir, releasedir, fsyncdir).
579 * Filesystem may also implement stateless directory I/O and not
580 * store anything in fi->fh, though that makes it impossible to
581 * implement standard conforming directory stream operations in
582 * case the contents of the directory can change between opendir
583 * and releasedir.
585 * Valid replies:
586 * fuse_reply_open
587 * fuse_reply_err
589 * @param req request handle
590 * @param ino the inode number
591 * @param fi file information
593 void (*opendir) (fuse_req_t req, fuse_ino_t ino,
594 struct fuse_file_info *fi);
597 * Read directory
599 * Send a buffer filled using fuse_add_direntry(), with size not
600 * exceeding the requested size. Send an empty buffer on end of
601 * stream.
603 * fi->fh will contain the value set by the opendir method, or
604 * will be undefined if the opendir method didn't set any value.
606 * Returning a directory entry from readdir() does not affect
607 * its lookup count.
609 * Valid replies:
610 * fuse_reply_buf
611 * fuse_reply_data
612 * fuse_reply_err
614 * @param req request handle
615 * @param ino the inode number
616 * @param size maximum number of bytes to send
617 * @param off offset to continue reading the directory stream
618 * @param fi file information
620 void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
621 struct fuse_file_info *fi);
624 * Release an open directory
626 * For every opendir call there will be exactly one releasedir
627 * call.
629 * fi->fh will contain the value set by the opendir method, or
630 * will be undefined if the opendir method didn't set any value.
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 (*releasedir) (fuse_req_t req, fuse_ino_t ino,
640 struct fuse_file_info *fi);
643 * Synchronize directory contents
645 * If the datasync parameter is non-zero, then only the directory
646 * contents should be flushed, not the meta data.
648 * fi->fh will contain the value set by the opendir method, or
649 * will be undefined if the opendir method didn't set any value.
651 * Valid replies:
652 * fuse_reply_err
654 * @param req request handle
655 * @param ino the inode number
656 * @param datasync flag indicating if only data should be flushed
657 * @param fi file information
659 void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
660 struct fuse_file_info *fi);
663 * Get file system statistics
665 * Valid replies:
666 * fuse_reply_statfs
667 * fuse_reply_err
669 * @param req request handle
670 * @param ino the inode number, zero means "undefined"
672 void (*statfs) (fuse_req_t req, fuse_ino_t ino);
675 * Set an extended attribute
677 * Valid replies:
678 * fuse_reply_err
680 void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
681 const char *value, size_t size, int flags);
684 * Get an extended attribute
686 * If size is zero, the size of the value should be sent with
687 * fuse_reply_xattr.
689 * If the size is non-zero, and the value fits in the buffer, the
690 * value should be sent with fuse_reply_buf.
692 * If the size is too small for the value, the ERANGE error should
693 * be sent.
695 * Valid replies:
696 * fuse_reply_buf
697 * fuse_reply_data
698 * fuse_reply_xattr
699 * fuse_reply_err
701 * @param req request handle
702 * @param ino the inode number
703 * @param name of the extended attribute
704 * @param size maximum size of the value to send
706 void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
707 size_t size);
710 * List extended attribute names
712 * If size is zero, the total size of the attribute list should be
713 * sent with fuse_reply_xattr.
715 * If the size is non-zero, and the null character separated
716 * attribute list fits in the buffer, the list should be sent with
717 * fuse_reply_buf.
719 * If the size is too small for the list, the ERANGE error should
720 * be sent.
722 * Valid replies:
723 * fuse_reply_buf
724 * fuse_reply_data
725 * fuse_reply_xattr
726 * fuse_reply_err
728 * @param req request handle
729 * @param ino the inode number
730 * @param size maximum size of the list to send
732 void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
735 * Remove an extended attribute
737 * Valid replies:
738 * fuse_reply_err
740 * @param req request handle
741 * @param ino the inode number
742 * @param name of the extended attribute
744 void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
747 * Check file access permissions
749 * This will be called for the access() system call. If the
750 * 'default_permissions' mount option is given, this method is not
751 * called.
753 * This method is not called under Linux kernel versions 2.4.x
755 * Introduced in version 2.5
757 * Valid replies:
758 * fuse_reply_err
760 * @param req request handle
761 * @param ino the inode number
762 * @param mask requested access mode
764 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
767 * Create and open a file
769 * If the file does not exist, first create it with the specified
770 * mode, and then open it.
772 * Open flags (with the exception of O_NOCTTY) are available in
773 * fi->flags.
775 * Filesystem may store an arbitrary file handle (pointer, index,
776 * etc) in fi->fh, and use this in other all other file operations
777 * (read, write, flush, release, fsync).
779 * There are also some flags (direct_io, keep_cache) which the
780 * filesystem may set in fi, to change the way the file is opened.
781 * See fuse_file_info structure in <fuse_common.h> for more details.
783 * If this method is not implemented or under Linux kernel
784 * versions earlier than 2.6.15, the mknod() and open() methods
785 * will be called instead.
787 * Introduced in version 2.5
789 * Valid replies:
790 * fuse_reply_create
791 * fuse_reply_err
793 * @param req request handle
794 * @param parent inode number of the parent directory
795 * @param name to create
796 * @param mode file type and mode with which to create the new file
797 * @param fi file information
799 void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
800 mode_t mode, struct fuse_file_info *fi);
803 * Test for a POSIX file lock
805 * Introduced in version 2.6
807 * Valid replies:
808 * fuse_reply_lock
809 * fuse_reply_err
811 * @param req request handle
812 * @param ino the inode number
813 * @param fi file information
814 * @param lock the region/type to test
816 void (*getlk) (fuse_req_t req, fuse_ino_t ino,
817 struct fuse_file_info *fi, struct flock *lock);
820 * Acquire, modify or release a POSIX file lock
822 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
823 * owner, but otherwise this is not always the case. For checking
824 * lock ownership, 'fi->owner' must be used. The l_pid field in
825 * 'struct flock' should only be used to fill in this field in
826 * getlk().
828 * Note: if the locking methods are not implemented, the kernel
829 * will still allow file locking to work locally. Hence these are
830 * only interesting for network filesystems and similar.
832 * Introduced in version 2.6
834 * Valid replies:
835 * fuse_reply_err
837 * @param req request handle
838 * @param ino the inode number
839 * @param fi file information
840 * @param lock the region/type to set
841 * @param sleep locking operation may sleep
843 void (*setlk) (fuse_req_t req, fuse_ino_t ino,
844 struct fuse_file_info *fi,
845 struct flock *lock, int sleep);
848 * Map block index within file to block index within device
850 * Note: This makes sense only for block device backed filesystems
851 * mounted with the 'blkdev' option
853 * Introduced in version 2.6
855 * Valid replies:
856 * fuse_reply_bmap
857 * fuse_reply_err
859 * @param req request handle
860 * @param ino the inode number
861 * @param blocksize unit of block index
862 * @param idx block index within file
864 void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
865 uint64_t idx);
868 * Ioctl
870 * Note: For unrestricted ioctls (not allowed for FUSE
871 * servers), data in and out areas can be discovered by giving
872 * iovs and setting FUSE_IOCTL_RETRY in @flags. For
873 * restricted ioctls, kernel prepares in/out data area
874 * according to the information encoded in cmd.
876 * Introduced in version 2.8
878 * Valid replies:
879 * fuse_reply_ioctl_retry
880 * fuse_reply_ioctl
881 * fuse_reply_ioctl_iov
882 * fuse_reply_err
884 * @param req request handle
885 * @param ino the inode number
886 * @param cmd ioctl command
887 * @param arg ioctl argument
888 * @param fi file information
889 * @param flags for FUSE_IOCTL_* flags
890 * @param in_buf data fetched from the caller
891 * @param in_bufsz number of fetched bytes
892 * @param out_bufsz maximum size of output data
894 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg,
895 struct fuse_file_info *fi, unsigned flags,
896 const void *in_buf, size_t in_bufsz, size_t out_bufsz);
899 * Poll for IO readiness
901 * Introduced in version 2.8
903 * Note: If ph is non-NULL, the client should notify
904 * when IO readiness events occur by calling
905 * fuse_lowelevel_notify_poll() with the specified ph.
907 * Regardless of the number of times poll with a non-NULL ph
908 * is received, single notification is enough to clear all.
909 * Notifying more times incurs overhead but doesn't harm
910 * correctness.
912 * The callee is responsible for destroying ph with
913 * fuse_pollhandle_destroy() when no longer in use.
915 * Valid replies:
916 * fuse_reply_poll
917 * fuse_reply_err
919 * @param req request handle
920 * @param ino the inode number
921 * @param fi file information
922 * @param ph poll handle to be used for notification
924 void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
925 struct fuse_pollhandle *ph);
928 * Write data made available in a buffer
930 * This is a more generic version of the ->write() method. If
931 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
932 * kernel supports splicing from the fuse device, then the
933 * data will be made available in pipe for supporting zero
934 * copy data transfer.
936 * Introduced in version 2.9
938 * Valid replies:
939 * fuse_reply_write
940 * fuse_reply_err
942 * @param req request handle
943 * @param ino the inode number
944 * @param bufv buffer containing the data
945 * @param off offset to write to
946 * @param fi file information
948 void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
949 struct fuse_bufvec *bufv, off_t off,
950 struct fuse_file_info *fi);
953 * Callback function for the retrieve request
955 * Introduced in version 2.9
957 * Valid replies:
958 * fuse_reply_none
960 * @param req request handle
961 * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
962 * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
963 * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
964 * @param bufv the buffer containing the returned data
966 void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
967 off_t offset, struct fuse_bufvec *bufv);
970 * Forget about multiple inodes
972 * See description of the forget function for more
973 * information.
975 * Introduced in version 2.9
977 * Valid replies:
978 * fuse_reply_none
980 * @param req request handle
982 void (*forget_multi) (fuse_req_t req, size_t count,
983 struct fuse_forget_data *forgets);
986 * Acquire, modify or release a BSD file lock
988 * Note: if the locking methods are not implemented, the kernel
989 * will still allow file locking to work locally. Hence these are
990 * only interesting for network filesystems and similar.
992 * Introduced in version 2.9
994 * Valid replies:
995 * fuse_reply_err
997 * @param req request handle
998 * @param ino the inode number
999 * @param fi file information
1000 * @param op the locking operation, see flock(2)
1002 void (*flock) (fuse_req_t req, fuse_ino_t ino,
1003 struct fuse_file_info *fi, int op);
1006 * Allocate requested space. If this function returns success then
1007 * subsequent writes to the specified range shall not fail due to the lack
1008 * of free space on the file system storage media.
1010 * Introduced in version 2.9
1012 * Valid replies:
1013 * fuse_reply_err
1015 * @param req request handle
1016 * @param ino the inode number
1017 * @param offset starting point for allocated region
1018 * @param length size of allocated region
1019 * @param mode determines the operation to be performed on the given range,
1020 * see fallocate(2)
1022 void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
1023 off_t offset, off_t length, struct fuse_file_info *fi);
1026 * Read directory with attributes
1028 * Send a buffer filled using fuse_add_direntry_plus(), with size not
1029 * exceeding the requested size. Send an empty buffer on end of
1030 * stream.
1032 * fi->fh will contain the value set by the opendir method, or
1033 * will be undefined if the opendir method didn't set any value.
1035 * In contrast to readdir() (which does not affect the lookup counts),
1036 * the lookup count of every entry returned by readdirplus(), except "."
1037 * and "..", is incremented by one.
1039 * Introduced in version 3.0
1041 * Valid replies:
1042 * fuse_reply_buf
1043 * fuse_reply_data
1044 * fuse_reply_err
1046 * @param req request handle
1047 * @param ino the inode number
1048 * @param size maximum number of bytes to send
1049 * @param off offset to continue reading the directory stream
1050 * @param fi file information
1052 void (*readdirplus) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1053 struct fuse_file_info *fi);
1057 * Reply with an error code or success
1059 * Possible requests:
1060 * all except forget
1062 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
1063 * removexattr and setlk may send a zero code
1065 * @param req request handle
1066 * @param err the positive error value, or zero for success
1067 * @return zero for success, -errno for failure to send reply
1069 int fuse_reply_err(fuse_req_t req, int err);
1072 * Don't send reply
1074 * Possible requests:
1075 * forget
1077 * @param req request handle
1079 void fuse_reply_none(fuse_req_t req);
1082 * Reply with a directory entry
1084 * Possible requests:
1085 * lookup, mknod, mkdir, symlink, link
1087 * Side effects:
1088 * increments the lookup count on success
1090 * @param req request handle
1091 * @param e the entry parameters
1092 * @return zero for success, -errno for failure to send reply
1094 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
1097 * Reply with a directory entry and open parameters
1099 * currently the following members of 'fi' are used:
1100 * fh, direct_io, keep_cache
1102 * Possible requests:
1103 * create
1105 * Side effects:
1106 * increments the lookup count on success
1108 * @param req request handle
1109 * @param e the entry parameters
1110 * @param fi file information
1111 * @return zero for success, -errno for failure to send reply
1113 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
1114 const struct fuse_file_info *fi);
1117 * Reply with attributes
1119 * Possible requests:
1120 * getattr, setattr
1122 * @param req request handle
1123 * @param attr the attributes
1124 * @param attr_timeout validity timeout (in seconds) for the attributes
1125 * @return zero for success, -errno for failure to send reply
1127 int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
1128 double attr_timeout);
1131 * Reply with the contents of a symbolic link
1133 * Possible requests:
1134 * readlink
1136 * @param req request handle
1137 * @param link symbolic link contents
1138 * @return zero for success, -errno for failure to send reply
1140 int fuse_reply_readlink(fuse_req_t req, const char *link);
1143 * Reply with open parameters
1145 * currently the following members of 'fi' are used:
1146 * fh, direct_io, keep_cache
1148 * Possible requests:
1149 * open, opendir
1151 * @param req request handle
1152 * @param fi file information
1153 * @return zero for success, -errno for failure to send reply
1155 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
1158 * Reply with number of bytes written
1160 * Possible requests:
1161 * write
1163 * @param req request handle
1164 * @param count the number of bytes written
1165 * @return zero for success, -errno for failure to send reply
1167 int fuse_reply_write(fuse_req_t req, size_t count);
1170 * Reply with data
1172 * Possible requests:
1173 * read, readdir, getxattr, listxattr
1175 * @param req request handle
1176 * @param buf buffer containing data
1177 * @param size the size of data in bytes
1178 * @return zero for success, -errno for failure to send reply
1180 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
1183 * Reply with data copied/moved from buffer(s)
1185 * Possible requests:
1186 * read, readdir, getxattr, listxattr
1188 * Side effects:
1189 * when used to return data from a readdirplus() (but not readdir())
1190 * call, increments the lookup count of each returned entry by one
1191 * on success.
1193 * @param req request handle
1194 * @param bufv buffer vector
1195 * @param flags flags controlling the copy
1196 * @return zero for success, -errno for failure to send reply
1198 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
1199 enum fuse_buf_copy_flags flags);
1202 * Reply with data vector
1204 * Possible requests:
1205 * read, readdir, getxattr, listxattr
1207 * @param req request handle
1208 * @param iov the vector containing the data
1209 * @param count the size of vector
1210 * @return zero for success, -errno for failure to send reply
1212 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
1215 * Reply with filesystem statistics
1217 * Possible requests:
1218 * statfs
1220 * @param req request handle
1221 * @param stbuf filesystem statistics
1222 * @return zero for success, -errno for failure to send reply
1224 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
1227 * Reply with needed buffer size
1229 * Possible requests:
1230 * getxattr, listxattr
1232 * @param req request handle
1233 * @param count the buffer size needed in bytes
1234 * @return zero for success, -errno for failure to send reply
1236 int fuse_reply_xattr(fuse_req_t req, size_t count);
1239 * Reply with file lock information
1241 * Possible requests:
1242 * getlk
1244 * @param req request handle
1245 * @param lock the lock information
1246 * @return zero for success, -errno for failure to send reply
1248 int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
1251 * Reply with block index
1253 * Possible requests:
1254 * bmap
1256 * @param req request handle
1257 * @param idx block index within device
1258 * @return zero for success, -errno for failure to send reply
1260 int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
1262 /* ----------------------------------------------------------- *
1263 * Filling a buffer in readdir *
1264 * ----------------------------------------------------------- */
1267 * Add a directory entry to the buffer
1269 * Buffer needs to be large enough to hold the entry. If it's not,
1270 * then the entry is not filled in but the size of the entry is still
1271 * returned. The caller can check this by comparing the bufsize
1272 * parameter with the returned entry size. If the entry size is
1273 * larger than the buffer size, the operation failed.
1275 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1276 * st_mode field are used. The other fields are ignored.
1278 * Note: offsets do not necessarily represent physical offsets, and
1279 * could be any marker, that enables the implementation to find a
1280 * specific point in the directory stream.
1282 * @param req request handle
1283 * @param buf the point where the new entry will be added to the buffer
1284 * @param bufsize remaining size of the buffer
1285 * @param name the name of the entry
1286 * @param stbuf the file attributes
1287 * @param off the offset of the next entry
1288 * @return the space needed for the entry
1290 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
1291 const char *name, const struct stat *stbuf,
1292 off_t off);
1295 * Add a directory entry to the buffer with the attributes
1297 * Buffer needs to be large enough to hold the entry. If it's not,
1298 * then the entry is not filled in but the size of the entry is still
1299 * returned. The caller can check this by comparing the bufsize
1300 * parameter with the returned entry size. If the entry size is
1301 * larger than the buffer size, the operation failed.
1303 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1304 * st_mode field are used. The other fields are ignored.
1306 * Note: offsets do not necessarily represent physical offsets, and
1307 * could be any marker, that enables the implementation to find a
1308 * specific point in the directory stream.
1310 * @param req request handle
1311 * @param buf the point where the new entry will be added to the buffer
1312 * @param bufsize remaining size of the buffer
1313 * @param name the name of the entry
1314 * @param e the directory entry
1315 * @param off the offset of the next entry
1316 * @return the space needed for the entry
1318 size_t fuse_add_direntry_plus(fuse_req_t req, char *buf, size_t bufsize,
1319 const char *name,
1320 const struct fuse_entry_param *e, off_t off);
1323 * Reply to ask for data fetch and output buffer preparation. ioctl
1324 * will be retried with the specified input data fetched and output
1325 * buffer prepared.
1327 * Possible requests:
1328 * ioctl
1330 * @param req request handle
1331 * @param in_iov iovec specifying data to fetch from the caller
1332 * @param in_count number of entries in in_iov
1333 * @param out_iov iovec specifying addresses to write output to
1334 * @param out_count number of entries in out_iov
1335 * @return zero for success, -errno for failure to send reply
1337 int fuse_reply_ioctl_retry(fuse_req_t req,
1338 const struct iovec *in_iov, size_t in_count,
1339 const struct iovec *out_iov, size_t out_count);
1342 * Reply to finish ioctl
1344 * Possible requests:
1345 * ioctl
1347 * @param req request handle
1348 * @param result result to be passed to the caller
1349 * @param buf buffer containing output data
1350 * @param size length of output data
1352 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
1355 * Reply to finish ioctl with iov buffer
1357 * Possible requests:
1358 * ioctl
1360 * @param req request handle
1361 * @param result result to be passed to the caller
1362 * @param iov the vector containing the data
1363 * @param count the size of vector
1365 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
1366 int count);
1369 * Reply with poll result event mask
1371 * @param req request handle
1372 * @param revents poll result event mask
1374 int fuse_reply_poll(fuse_req_t req, unsigned revents);
1376 /* ----------------------------------------------------------- *
1377 * Notification *
1378 * ----------------------------------------------------------- */
1381 * Notify IO readiness event
1383 * For more information, please read comment for poll operation.
1385 * @param ph poll handle to notify IO readiness event for
1387 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
1390 * Notify to invalidate cache for an inode
1392 * @param ch the channel through which to send the invalidation
1393 * @param ino the inode number
1394 * @param off the offset in the inode where to start invalidating
1395 * or negative to invalidate attributes only
1396 * @param len the amount of cache to invalidate or 0 for all
1397 * @return zero for success, -errno for failure
1399 int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino,
1400 off_t off, off_t len);
1403 * Notify to invalidate parent attributes and the dentry matching
1404 * parent/name
1406 * To avoid a deadlock don't call this function from a filesystem operation and
1407 * don't call it with a lock held that can also be held by a filesystem
1408 * operation.
1410 * @param ch the channel through which to send the invalidation
1411 * @param parent inode number
1412 * @param name file name
1413 * @param namelen strlen() of file name
1414 * @return zero for success, -errno for failure
1416 int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
1417 const char *name, size_t namelen);
1420 * Notify to invalidate parent attributes and delete the dentry matching
1421 * parent/name if the dentry's inode number matches child (otherwise it
1422 * will invalidate the matching dentry).
1424 * To avoid a deadlock don't call this function from a filesystem operation and
1425 * don't call it with a lock held that can also be held by a filesystem
1426 * operation.
1428 * @param ch the channel through which to send the notification
1429 * @param parent inode number
1430 * @param child inode number
1431 * @param name file name
1432 * @param namelen strlen() of file name
1433 * @return zero for success, -errno for failure
1435 int fuse_lowlevel_notify_delete(struct fuse_chan *ch,
1436 fuse_ino_t parent, fuse_ino_t child,
1437 const char *name, size_t namelen);
1440 * Store data to the kernel buffers
1442 * Synchronously store data in the kernel buffers belonging to the
1443 * given inode. The stored data is marked up-to-date (no read will be
1444 * performed against it, unless it's invalidated or evicted from the
1445 * cache).
1447 * If the stored data overflows the current file size, then the size
1448 * is extended, similarly to a write(2) on the filesystem.
1450 * If this function returns an error, then the store wasn't fully
1451 * completed, but it may have been partially completed.
1453 * @param ch the channel through which to send the invalidation
1454 * @param ino the inode number
1455 * @param offset the starting offset into the file to store to
1456 * @param bufv buffer vector
1457 * @param flags flags controlling the copy
1458 * @return zero for success, -errno for failure
1460 int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino,
1461 off_t offset, struct fuse_bufvec *bufv,
1462 enum fuse_buf_copy_flags flags);
1464 * Retrieve data from the kernel buffers
1466 * Retrieve data in the kernel buffers belonging to the given inode.
1467 * If successful then the retrieve_reply() method will be called with
1468 * the returned data.
1470 * Only present pages are returned in the retrieve reply. Retrieving
1471 * stops when it finds a non-present page and only data prior to that is
1472 * returned.
1474 * If this function returns an error, then the retrieve will not be
1475 * completed and no reply will be sent.
1477 * This function doesn't change the dirty state of pages in the kernel
1478 * buffer. For dirty pages the write() method will be called
1479 * regardless of having been retrieved previously.
1481 * @param ch the channel through which to send the invalidation
1482 * @param ino the inode number
1483 * @param size the number of bytes to retrieve
1484 * @param offset the starting offset into the file to retrieve from
1485 * @param cookie user data to supply to the reply callback
1486 * @return zero for success, -errno for failure
1488 int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino,
1489 size_t size, off_t offset, void *cookie);
1492 /* ----------------------------------------------------------- *
1493 * Utility functions *
1494 * ----------------------------------------------------------- */
1497 * Get the userdata from the request
1499 * @param req request handle
1500 * @return the user data passed to fuse_lowlevel_new()
1502 void *fuse_req_userdata(fuse_req_t req);
1505 * Get the context from the request
1507 * The pointer returned by this function will only be valid for the
1508 * request's lifetime
1510 * @param req request handle
1511 * @return the context structure
1513 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
1516 * Get the current supplementary group IDs for the specified request
1518 * Similar to the getgroups(2) system call, except the return value is
1519 * always the total number of group IDs, even if it is larger than the
1520 * specified size.
1522 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
1523 * the group list to userspace, hence this function needs to parse
1524 * "/proc/$TID/task/$TID/status" to get the group IDs.
1526 * This feature may not be supported on all operating systems. In
1527 * such a case this function will return -ENOSYS.
1529 * @param req request handle
1530 * @param size size of given array
1531 * @param list array of group IDs to be filled in
1532 * @return the total number of supplementary group IDs or -errno on failure
1534 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
1537 * Callback function for an interrupt
1539 * @param req interrupted request
1540 * @param data user data
1542 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
1545 * Register/unregister callback for an interrupt
1547 * If an interrupt has already happened, then the callback function is
1548 * called from within this function, hence it's not possible for
1549 * interrupts to be lost.
1551 * @param req request handle
1552 * @param func the callback function or NULL for unregister
1553 * @param data user data passed to the callback function
1555 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
1556 void *data);
1559 * Check if a request has already been interrupted
1561 * @param req request handle
1562 * @return 1 if the request has been interrupted, 0 otherwise
1564 int fuse_req_interrupted(fuse_req_t req);
1566 /* ----------------------------------------------------------- *
1567 * Filesystem setup *
1568 * ----------------------------------------------------------- */
1571 * Create a low level session
1573 * @param args argument vector
1574 * @param op the low level filesystem operations
1575 * @param op_size sizeof(struct fuse_lowlevel_ops)
1576 * @param userdata user data
1577 * @return the created session object, or NULL on failure
1579 * Example: See hello_ll.c:
1580 * \snippet hello_ll.c doxygen_fuse_lowlevel_usage
1582 struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
1583 const struct fuse_lowlevel_ops *op,
1584 size_t op_size, void *userdata);
1586 /* ----------------------------------------------------------- *
1587 * Session interface *
1588 * ----------------------------------------------------------- */
1591 * Assign a channel to a session
1593 * If a session is destroyed, the assigned channel is also destroyed
1595 * @param se the session
1596 * @param ch the channel
1598 void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch);
1601 * Remove the channel from a session
1603 * If the channel is not assigned to a session, then this is a no-op
1605 * @param ch the channel to remove
1607 void fuse_session_remove_chan(struct fuse_chan *ch);
1610 * Return channel assigned to the session
1612 * @param se the session
1613 * @return the channel
1615 struct fuse_chan *fuse_session_chan(struct fuse_session *se);
1618 * Process a raw request supplied in a generic buffer
1620 * The fuse_buf may contain a memory buffer or a pipe file descriptor.
1622 * @param se the session
1623 * @param buf the fuse_buf containing the request
1624 * @param ch channel on which the request was received
1626 void fuse_session_process_buf(struct fuse_session *se,
1627 const struct fuse_buf *buf, struct fuse_chan *ch);
1630 * Receive a raw request supplied in a generic buffer
1632 * The fuse_buf supplied to this function contains a suitably allocated memory
1633 * buffer. This may be overwritten with a file descriptor buffer.
1635 * @param se the session
1636 * @param buf the fuse_buf to store the request in
1637 * @param ch the channel
1638 * @return the actual size of the raw request, or -errno on error
1640 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
1641 struct fuse_chan *ch);
1644 * Destroy a session
1646 * @param se the session
1648 void fuse_session_destroy(struct fuse_session *se);
1651 * Exit a session.
1653 * This function is invoked by the POSIX signal handlers, when registered using:
1654 * * fuse_set_signal_handlers()
1656 * @param se the session
1658 void fuse_session_exit(struct fuse_session *se);
1661 * Reset the exited status of a session
1663 * @param se the session
1665 void fuse_session_reset(struct fuse_session *se);
1668 * Query the exited status of a session
1670 * @param se the session
1671 * @return 1 if exited, 0 if not exited
1673 int fuse_session_exited(struct fuse_session *se);
1676 * Enter a single threaded, blocking event loop.
1678 * Using POSIX signals this event loop can be exited but the session
1679 * needs to be configued by issuing:
1680 * fuse_set_signal_handlers() first.
1682 * @param se the session
1683 * @return 0 on success, -1 on error
1685 int fuse_session_loop(struct fuse_session *se);
1688 * Enter a multi-threaded event loop
1690 * @param se the session
1691 * @return 0 on success, -1 on error
1693 int fuse_session_loop_mt(struct fuse_session *se);
1695 /* ----------------------------------------------------------- *
1696 * Channel interface *
1697 * ----------------------------------------------------------- */
1700 * Query the file descriptor of the channel
1702 * @param ch the channel
1703 * @return the file descriptor passed to fuse_chan_new()
1705 int fuse_chan_fd(struct fuse_chan *ch);
1708 * Obtain counted reference to the channel
1710 * @param ch the channel
1711 * @return the channel
1713 struct fuse_chan *fuse_chan_get(struct fuse_chan *ch);
1716 * Drop counted reference to a channel
1718 * @param ch the channel
1720 void fuse_chan_put(struct fuse_chan *ch);
1722 #ifdef __cplusplus
1724 #endif
1726 #endif /* _FUSE_LOWLEVEL_H_ */