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_
17 #include "fuse_common.h"
21 #include <sys/types.h>
23 #include <sys/statvfs.h>
30 /* ----------------------------------------------------------- *
31 * Miscellaneous definitions *
32 * ----------------------------------------------------------- */
34 /** The node ID of the root inode */
35 #define FUSE_ROOT_ID 1
37 /** Inode number type */
38 typedef unsigned long fuse_ino_t
;
40 /** Request pointer type */
41 typedef struct fuse_req
*fuse_req_t
;
46 * This provides hooks for processing requests, and exiting
53 * A communication channel, providing hooks for sending and receiving
58 /** Directory entry parameters supplied to fuse_reply_entry() */
59 struct fuse_entry_param
{
60 /** Unique inode number
62 * In lookup, zero means negative entry (from version 2.5)
63 * Returning ENOENT also means negative entry, but by setting zero
64 * ino the kernel may cache negative entries for entry_timeout
69 /** Generation number for this entry.
71 * The ino/generation pair should be unique for the filesystem's
72 * lifetime. It must be non-zero, otherwise FUSE will treat it as an
75 unsigned long generation
;
79 * Even if attr_timeout == 0, attr must be correct. For example,
80 * for open(), FUSE uses attr.st_size from lookup() to determine
81 * how many bytes to request. If this value is not correct,
82 * incorrect data will be returned.
86 /** Validity timeout (in seconds) for the attributes */
89 /** Validity timeout (in seconds) for the name */
93 /** Additional context associated with requests */
95 /** User ID of the calling process */
98 /** Group ID of the calling process */
101 /** Thread ID of the calling process */
105 /** Umask of the calling process (introduced in version 2.8) */
110 /* 'to_set' flags in setattr */
111 #define FUSE_SET_ATTR_MODE (1 << 0)
112 #define FUSE_SET_ATTR_UID (1 << 1)
113 #define FUSE_SET_ATTR_GID (1 << 2)
114 #define FUSE_SET_ATTR_SIZE (1 << 3)
115 #define FUSE_SET_ATTR_ATIME (1 << 4)
116 #define FUSE_SET_ATTR_MTIME (1 << 5)
118 /* ----------------------------------------------------------- *
119 * Request methods and replies *
120 * ----------------------------------------------------------- */
123 * Low level filesystem operations
125 * Most of the methods (with the exception of init and destroy)
126 * receive a request handle (fuse_req_t) as their first argument.
127 * This handle must be passed to one of the specified reply functions.
129 * This may be done inside the method invocation, or after the call
130 * has returned. The request handle is valid until one of the reply
131 * functions is called.
133 * Other pointer arguments (name, fuse_file_info, etc) are not valid
134 * after the call has returned, so if they are needed later, their
135 * contents have to be copied.
137 * The filesystem sometimes needs to handle a return value of -ENOENT
138 * from the reply function, which means, that the request was
139 * interrupted, and the reply discarded. For example if
140 * fuse_reply_open() return -ENOENT means, that the release method for
141 * this file will not be called.
143 struct fuse_lowlevel_ops
{
145 * Initialize filesystem
147 * Called before any other filesystem method
149 * There's no reply to this function
151 * @param userdata the user data passed to fuse_lowlevel_new()
153 void (*init
) (void *userdata
, struct fuse_conn_info
*conn
);
156 * Clean up filesystem
158 * Called on filesystem exit
160 * There's no reply to this function
162 * @param userdata the user data passed to fuse_lowlevel_new()
164 void (*destroy
) (void *userdata
);
167 * Look up a directory entry by name and get its attributes.
173 * @param req request handle
174 * @param parent inode number of the parent directory
175 * @param name the name to look up
177 void (*lookup
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
180 * Forget about an inode
182 * The nlookup parameter indicates the number of lookups
183 * previously performed on this inode.
185 * If the filesystem implements inode lifetimes, it is recommended
186 * that inodes acquire a single reference on each lookup, and lose
187 * nlookup references on each forget.
189 * The filesystem may ignore forget calls, if the inodes don't
190 * need to have a limited lifetime.
192 * On unmount it is not guaranteed, that all referenced inodes
193 * will receive a forget message.
198 * @param req request handle
199 * @param ino the inode number
200 * @param nlookup the number of lookups to forget
202 void (*forget
) (fuse_req_t req
, fuse_ino_t ino
, unsigned long nlookup
);
205 * Get file attributes
211 * @param req request handle
212 * @param ino the inode number
213 * @param fi for future use, currently always NULL
215 void (*getattr
) (fuse_req_t req
, fuse_ino_t ino
,
216 struct fuse_file_info
*fi
);
219 * Set file attributes
221 * In the 'attr' argument only members indicated by the 'to_set'
222 * bitmask contain valid values. Other members contain undefined
225 * If the setattr was invoked from the ftruncate() system call
226 * under Linux kernel versions 2.6.15 or later, the fi->fh will
227 * contain the value set by the open method or will be undefined
228 * if the open method didn't set any value. Otherwise (not
229 * ftruncate call, or kernel version earlier than 2.6.15) the fi
230 * parameter will be NULL.
236 * @param req request handle
237 * @param ino the inode number
238 * @param attr the attributes
239 * @param to_set bit mask of attributes which should be set
240 * @param fi file information, or NULL
242 * Changed in version 2.5:
243 * file information filled in for ftruncate
245 void (*setattr
) (fuse_req_t req
, fuse_ino_t ino
, struct stat
*attr
,
246 int to_set
, struct fuse_file_info
*fi
);
252 * fuse_reply_readlink
255 * @param req request handle
256 * @param ino the inode number
258 void (*readlink
) (fuse_req_t req
, fuse_ino_t ino
);
263 * Create a regular file, character device, block device, fifo or
270 * @param req request handle
271 * @param parent inode number of the parent directory
272 * @param name to create
273 * @param mode file type and mode with which to create the new file
274 * @param rdev the device number (only valid if created file is a device)
276 void (*mknod
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
277 mode_t mode
, dev_t rdev
);
286 * @param req request handle
287 * @param parent inode number of the parent directory
288 * @param name to create
289 * @param mode with which to create the new file
291 void (*mkdir
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
300 * @param req request handle
301 * @param parent inode number of the parent directory
302 * @param name to remove
304 void (*unlink
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
312 * @param req request handle
313 * @param parent inode number of the parent directory
314 * @param name to remove
316 void (*rmdir
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
319 * Create a symbolic link
325 * @param req request handle
326 * @param link the contents of the symbolic link
327 * @param parent inode number of the parent directory
328 * @param name to create
330 void (*symlink
) (fuse_req_t req
, const char *link
, fuse_ino_t parent
,
338 * @param req request handle
339 * @param parent inode number of the old parent directory
340 * @param name old name
341 * @param newparent inode number of the new parent directory
342 * @param newname new name
344 void (*rename
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
345 fuse_ino_t newparent
, const char *newname
);
354 * @param req request handle
355 * @param ino the old inode number
356 * @param newparent inode number of the new parent directory
357 * @param newname new name to create
359 void (*link
) (fuse_req_t req
, fuse_ino_t ino
, fuse_ino_t newparent
,
360 const char *newname
);
365 * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
366 * O_TRUNC) are available in fi->flags.
368 * Filesystem may store an arbitrary file handle (pointer, index,
369 * etc) in fi->fh, and use this in other all other file operations
370 * (read, write, flush, release, fsync).
372 * Filesystem may also implement stateless file I/O and not store
373 * anything in fi->fh.
375 * There are also some flags (direct_io, keep_cache) which the
376 * filesystem may set in fi, to change the way the file is opened.
377 * See fuse_file_info structure in <fuse_common.h> for more details.
383 * @param req request handle
384 * @param ino the inode number
385 * @param fi file information
387 void (*open
) (fuse_req_t req
, fuse_ino_t ino
,
388 struct fuse_file_info
*fi
);
393 * Read should send exactly the number of bytes requested except
394 * on EOF or error, otherwise the rest of the data will be
395 * substituted with zeroes. An exception to this is when the file
396 * has been opened in 'direct_io' mode, in which case the return
397 * value of the read system call will reflect the return value of
400 * fi->fh will contain the value set by the open method, or will
401 * be undefined if the open method didn't set any value.
407 * @param req request handle
408 * @param ino the inode number
409 * @param size number of bytes to read
410 * @param off offset to read from
411 * @param fi file information
413 void (*read
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
, off_t off
,
414 struct fuse_file_info
*fi
);
419 * Write should return exactly the number of bytes requested
420 * except on error. An exception to this is when the file has
421 * been opened in 'direct_io' mode, in which case the return value
422 * of the write system call will reflect the return value of this
425 * fi->fh will contain the value set by the open method, or will
426 * be undefined if the open method didn't set any value.
432 * @param req request handle
433 * @param ino the inode number
434 * @param buf data to write
435 * @param size number of bytes to write
436 * @param off offset to write to
437 * @param fi file information
439 void (*write
) (fuse_req_t req
, fuse_ino_t ino
, const char *buf
,
440 size_t size
, off_t off
, struct fuse_file_info
*fi
);
445 * This is called on each close() of the opened file.
447 * Since file descriptors can be duplicated (dup, dup2, fork), for
448 * one open call there may be many flush calls.
450 * Filesystems shouldn't assume that flush will always be called
451 * after some writes, or that if will be called at all.
453 * fi->fh will contain the value set by the open method, or will
454 * be undefined if the open method didn't set any value.
456 * NOTE: the name of the method is misleading, since (unlike
457 * fsync) the filesystem is not forced to flush pending writes.
458 * One reason to flush data, is if the filesystem wants to return
461 * If the filesystem supports file locking operations (setlk,
462 * getlk) it should remove all locks belonging to 'fi->owner'.
467 * @param req request handle
468 * @param ino the inode number
469 * @param fi file information
471 void (*flush
) (fuse_req_t req
, fuse_ino_t ino
,
472 struct fuse_file_info
*fi
);
475 * Release an open file
477 * Release is called when there are no more references to an open
478 * file: all file descriptors are closed and all memory mappings
481 * For every open call there will be exactly one release call.
483 * The filesystem may reply with an error, but error values are
484 * not returned to close() or munmap() which triggered the
487 * fi->fh will contain the value set by the open method, or will
488 * be undefined if the open method didn't set any value.
489 * fi->flags will contain the same flags as for open.
494 * @param req request handle
495 * @param ino the inode number
496 * @param fi file information
498 void (*release
) (fuse_req_t req
, fuse_ino_t ino
,
499 struct fuse_file_info
*fi
);
502 * Synchronize file contents
504 * If the datasync parameter is non-zero, then only the user data
505 * should be flushed, not the meta data.
510 * @param req request handle
511 * @param ino the inode number
512 * @param datasync flag indicating if only data should be flushed
513 * @param fi file information
515 void (*fsync
) (fuse_req_t req
, fuse_ino_t ino
, int datasync
,
516 struct fuse_file_info
*fi
);
521 * Filesystem may store an arbitrary file handle (pointer, index,
522 * etc) in fi->fh, and use this in other all other directory
523 * stream operations (readdir, releasedir, fsyncdir).
525 * Filesystem may also implement stateless directory I/O and not
526 * store anything in fi->fh, though that makes it impossible to
527 * implement standard conforming directory stream operations in
528 * case the contents of the directory can change between opendir
535 * @param req request handle
536 * @param ino the inode number
537 * @param fi file information
539 void (*opendir
) (fuse_req_t req
, fuse_ino_t ino
,
540 struct fuse_file_info
*fi
);
545 * Send a buffer filled using fuse_add_direntry(), with size not
546 * exceeding the requested size. Send an empty buffer on end of
549 * fi->fh will contain the value set by the opendir method, or
550 * will be undefined if the opendir method didn't set any value.
556 * @param req request handle
557 * @param ino the inode number
558 * @param size maximum number of bytes to send
559 * @param off offset to continue reading the directory stream
560 * @param fi file information
562 void (*readdir
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
, off_t off
,
563 struct fuse_file_info
*fi
);
566 * Release an open directory
568 * For every opendir call there will be exactly one releasedir
571 * fi->fh will contain the value set by the opendir method, or
572 * will be undefined if the opendir method didn't set any value.
577 * @param req request handle
578 * @param ino the inode number
579 * @param fi file information
581 void (*releasedir
) (fuse_req_t req
, fuse_ino_t ino
,
582 struct fuse_file_info
*fi
);
585 * Synchronize directory contents
587 * If the datasync parameter is non-zero, then only the directory
588 * contents should be flushed, not the meta data.
590 * fi->fh will contain the value set by the opendir method, or
591 * will be undefined if the opendir method didn't set any value.
596 * @param req request handle
597 * @param ino the inode number
598 * @param datasync flag indicating if only data should be flushed
599 * @param fi file information
601 void (*fsyncdir
) (fuse_req_t req
, fuse_ino_t ino
, int datasync
,
602 struct fuse_file_info
*fi
);
605 * Get file system statistics
611 * @param req request handle
612 * @param ino the inode number, zero means "undefined"
614 void (*statfs
) (fuse_req_t req
, fuse_ino_t ino
);
617 * Set an extended attribute
622 void (*setxattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
,
623 const char *value
, size_t size
, int flags
);
626 * Get an extended attribute
628 * If size is zero, the size of the value should be sent with
631 * If the size is non-zero, and the value fits in the buffer, the
632 * value should be sent with fuse_reply_buf.
634 * If the size is too small for the value, the ERANGE error should
642 * @param req request handle
643 * @param ino the inode number
644 * @param name of the extended attribute
645 * @param size maximum size of the value to send
647 void (*getxattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
,
651 * List extended attribute names
653 * If size is zero, the total size of the attribute list should be
654 * sent with fuse_reply_xattr.
656 * If the size is non-zero, and the null character separated
657 * attribute list fits in the buffer, the list should be sent with
660 * If the size is too small for the list, the ERANGE error should
668 * @param req request handle
669 * @param ino the inode number
670 * @param size maximum size of the list to send
672 void (*listxattr
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
);
675 * Remove an extended attribute
680 * @param req request handle
681 * @param ino the inode number
682 * @param name of the extended attribute
684 void (*removexattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
);
687 * Check file access permissions
689 * This will be called for the access() system call. If the
690 * 'default_permissions' mount option is given, this method is not
693 * This method is not called under Linux kernel versions 2.4.x
695 * Introduced in version 2.5
700 * @param req request handle
701 * @param ino the inode number
702 * @param mask requested access mode
704 void (*access
) (fuse_req_t req
, fuse_ino_t ino
, int mask
);
707 * Create and open a file
709 * If the file does not exist, first create it with the specified
710 * mode, and then open it.
712 * Open flags (with the exception of O_NOCTTY) are available in
715 * Filesystem may store an arbitrary file handle (pointer, index,
716 * etc) in fi->fh, and use this in other all other file operations
717 * (read, write, flush, release, fsync).
719 * There are also some flags (direct_io, keep_cache) which the
720 * filesystem may set in fi, to change the way the file is opened.
721 * See fuse_file_info structure in <fuse_common.h> for more details.
723 * If this method is not implemented or under Linux kernel
724 * versions earlier than 2.6.15, the mknod() and open() methods
725 * will be called instead.
727 * Introduced in version 2.5
733 * @param req request handle
734 * @param parent inode number of the parent directory
735 * @param name to create
736 * @param mode file type and mode with which to create the new file
737 * @param fi file information
739 void (*create
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
740 mode_t mode
, struct fuse_file_info
*fi
);
743 * Test for a POSIX file lock
745 * Introduced in version 2.6
751 * @param req request handle
752 * @param ino the inode number
753 * @param fi file information
754 * @param lock the region/type to test
756 void (*getlk
) (fuse_req_t req
, fuse_ino_t ino
,
757 struct fuse_file_info
*fi
, struct flock
*lock
);
760 * Acquire, modify or release a POSIX file lock
762 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
763 * owner, but otherwise this is not always the case. For checking
764 * lock ownership, 'fi->owner' must be used. The l_pid field in
765 * 'struct flock' should only be used to fill in this field in
768 * Note: if the locking methods are not implemented, the kernel
769 * will still allow file locking to work locally. Hence these are
770 * only interesting for network filesystems and similar.
772 * Introduced in version 2.6
777 * @param req request handle
778 * @param ino the inode number
779 * @param fi file information
780 * @param lock the region/type to test
781 * @param sleep locking operation may sleep
783 void (*setlk
) (fuse_req_t req
, fuse_ino_t ino
,
784 struct fuse_file_info
*fi
,
785 struct flock
*lock
, int sleep
);
788 * Map block index within file to block index within device
790 * Note: This makes sense only for block device backed filesystems
791 * mounted with the 'blkdev' option
793 * Introduced in version 2.6
799 * @param req request handle
800 * @param ino the inode number
801 * @param blocksize unit of block index
802 * @param idx block index within file
804 void (*bmap
) (fuse_req_t req
, fuse_ino_t ino
, size_t blocksize
,
809 * Reply with an error code or success
814 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
815 * removexattr and setlk may send a zero code
817 * @param req request handle
818 * @param err the positive error value, or zero for success
819 * @return zero for success, -errno for failure to send reply
821 int fuse_reply_err(fuse_req_t req
, int err
);
829 * @param req request handle
831 void fuse_reply_none(fuse_req_t req
);
834 * Reply with a directory entry
837 * lookup, mknod, mkdir, symlink, link
839 * @param req request handle
840 * @param e the entry parameters
841 * @return zero for success, -errno for failure to send reply
843 int fuse_reply_entry(fuse_req_t req
, const struct fuse_entry_param
*e
);
846 * Reply with a directory entry and open parameters
848 * currently the following members of 'fi' are used:
849 * fh, direct_io, keep_cache
854 * @param req request handle
855 * @param e the entry parameters
856 * @param fi file information
857 * @return zero for success, -errno for failure to send reply
859 int fuse_reply_create(fuse_req_t req
, const struct fuse_entry_param
*e
,
860 const struct fuse_file_info
*fi
);
863 * Reply with attributes
868 * @param req request handle
869 * @param the attributes
870 * @param attr_timeout validity timeout (in seconds) for the attributes
871 * @return zero for success, -errno for failure to send reply
873 int fuse_reply_attr(fuse_req_t req
, const struct stat
*attr
,
874 double attr_timeout
);
877 * Reply with the contents of a symbolic link
882 * @param req request handle
883 * @param link symbolic link contents
884 * @return zero for success, -errno for failure to send reply
886 int fuse_reply_readlink(fuse_req_t req
, const char *link
);
889 * Reply with open parameters
891 * currently the following members of 'fi' are used:
892 * fh, direct_io, keep_cache
897 * @param req request handle
898 * @param fi file information
899 * @return zero for success, -errno for failure to send reply
901 int fuse_reply_open(fuse_req_t req
, const struct fuse_file_info
*fi
);
904 * Reply with number of bytes written
909 * @param req request handle
910 * @param count the number of bytes written
911 * @return zero for success, -errno for failure to send reply
913 int fuse_reply_write(fuse_req_t req
, size_t count
);
919 * read, readdir, getxattr, listxattr
921 * @param req request handle
922 * @param buf buffer containing data
923 * @param size the size of data in bytes
924 * @return zero for success, -errno for failure to send reply
926 int fuse_reply_buf(fuse_req_t req
, const char *buf
, size_t size
);
930 * Reply with data vector
933 * read, readdir, getxattr, listxattr
935 * @param req request handle
936 * @param iov the vector containing the data
937 * @param count the size of vector
938 * @return zero for success, -errno for failure to send reply
940 int fuse_reply_iov(fuse_req_t req
, const struct iovec
*iov
, int count
);
944 * Reply with filesystem statistics
949 * @param req request handle
950 * @param stbuf filesystem statistics
951 * @return zero for success, -errno for failure to send reply
953 int fuse_reply_statfs(fuse_req_t req
, const struct statvfs
*stbuf
);
956 * Reply with needed buffer size
959 * getxattr, listxattr
961 * @param req request handle
962 * @param count the buffer size needed in bytes
963 * @return zero for success, -errno for failure to send reply
965 int fuse_reply_xattr(fuse_req_t req
, size_t count
);
968 * Reply with file lock information
973 * @param req request handle
974 * @param lock the lock information
975 * @return zero for success, -errno for failure to send reply
977 int fuse_reply_lock(fuse_req_t req
, struct flock
*lock
);
980 * Reply with block index
985 * @param req request handle
986 * @param idx block index within device
987 * @return zero for success, -errno for failure to send reply
989 int fuse_reply_bmap(fuse_req_t req
, uint64_t idx
);
991 /* ----------------------------------------------------------- *
992 * Filling a buffer in readdir *
993 * ----------------------------------------------------------- */
996 * Add a directory entry to the buffer
998 * Buffer needs to be large enough to hold the entry. Of it's not,
999 * then the entry is not filled in but the size of the entry is still
1000 * returned. The caller can check this by comparing the bufsize
1001 * parameter with the returned entry size. If the entry size is
1002 * larger than the buffer size, the operation failed.
1004 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1005 * st_mode field are used. The other fields are ignored.
1007 * Note: offsets do not necessarily represent physical offsets, and
1008 * could be any marker, that enables the implementation to find a
1009 * specific point in the directory stream.
1011 * @param req request handle
1012 * @param buf the point where the new entry will be added to the buffer
1013 * @param bufsize remaining size of the buffer
1014 * @param the name of the entry
1015 * @param stbuf the file attributes
1016 * @param off the offset of the next entry
1017 * @return the space needed for the entry
1019 size_t fuse_add_direntry(fuse_req_t req
, char *buf
, size_t bufsize
,
1020 const char *name
, const struct stat
*stbuf
,
1023 /* ----------------------------------------------------------- *
1024 * Utility functions *
1025 * ----------------------------------------------------------- */
1028 * Get the userdata from the request
1030 * @param req request handle
1031 * @return the user data passed to fuse_lowlevel_new()
1033 void *fuse_req_userdata(fuse_req_t req
);
1036 * Get the context from the request
1038 * The pointer returned by this function will only be valid for the
1039 * request's lifetime
1041 * @param req request handle
1042 * @return the context structure
1044 const struct fuse_ctx
*fuse_req_ctx(fuse_req_t req
);
1047 * Callback function for an interrupt
1049 * @param req interrupted request
1050 * @param data user data
1052 typedef void (*fuse_interrupt_func_t
)(fuse_req_t req
, void *data
);
1055 * Register/unregister callback for an interrupt
1057 * If an interrupt has already happened, then the callback function is
1058 * called from within this function, hence it's not possible for
1059 * interrupts to be lost.
1061 * @param req request handle
1062 * @param func the callback function or NULL for unregister
1063 * @parm data user data passed to the callback function
1065 void fuse_req_interrupt_func(fuse_req_t req
, fuse_interrupt_func_t func
,
1069 * Check if a request has already been interrupted
1071 * @param req request handle
1072 * @return 1 if the request has been interrupted, 0 otherwise
1074 int fuse_req_interrupted(fuse_req_t req
);
1076 /* ----------------------------------------------------------- *
1077 * Filesystem setup *
1078 * ----------------------------------------------------------- */
1081 * Create a low level session
1083 * @param args argument vector
1084 * @param op the low level filesystem operations
1085 * @param op_size sizeof(struct fuse_lowlevel_ops)
1086 * @param userdata user data
1087 * @return the created session object, or NULL on failure
1089 struct fuse_session
*fuse_lowlevel_new(struct fuse_args
*args
,
1090 const struct fuse_lowlevel_ops
*op
,
1091 size_t op_size
, void *userdata
);
1093 /* ----------------------------------------------------------- *
1094 * Session interface *
1095 * ----------------------------------------------------------- */
1098 * Session operations
1100 * This is used in session creation
1102 struct fuse_session_ops
{
1104 * Hook to process a request (mandatory)
1106 * @param data user data passed to fuse_session_new()
1107 * @param buf buffer containing the raw request
1108 * @param len request length
1109 * @param ch channel on which the request was received
1111 void (*process
) (void *data
, const char *buf
, size_t len
,
1112 struct fuse_chan
*ch
);
1115 * Hook for session exit and reset (optional)
1117 * @param data user data passed to fuse_session_new()
1118 * @param val exited status (1 - exited, 0 - not exited)
1120 void (*exit
) (void *data
, int val
);
1123 * Hook for querying the current exited status (optional)
1125 * @param data user data passed to fuse_session_new()
1126 * @return 1 if exited, 0 if not exited
1128 int (*exited
) (void *data
);
1131 * Hook for cleaning up the channel on destroy (optional)
1133 * @param data user data passed to fuse_session_new()
1135 void (*destroy
) (void *data
);
1139 * Create a new session
1141 * @param op session operations
1142 * @param data user data
1143 * @return new session object, or NULL on failure
1145 struct fuse_session
*fuse_session_new(struct fuse_session_ops
*op
, void *data
);
1148 * Assign a channel to a session
1150 * Note: currently only a single channel may be assigned. This may
1151 * change in the future
1153 * If a session is destroyed, the assigned channel is also destroyed
1155 * @param se the session
1156 * @param ch the channel
1158 void fuse_session_add_chan(struct fuse_session
*se
, struct fuse_chan
*ch
);
1161 * Remove a channel from a session
1163 * If the channel is not assigned to a session, then this is a no-op
1165 * @param ch the channel to remove
1167 void fuse_session_remove_chan(struct fuse_chan
*ch
);
1170 * Iterate over the channels assigned to a session
1172 * The iterating function needs to start with a NULL channel, and
1173 * after that needs to pass the previously returned channel to the
1176 * @param se the session
1177 * @param ch the previous channel, or NULL
1178 * @return the next channel, or NULL if no more channels exist
1180 struct fuse_chan
*fuse_session_next_chan(struct fuse_session
*se
,
1181 struct fuse_chan
*ch
);
1184 * Process a raw request
1186 * @param se the session
1187 * @param buf buffer containing the raw request
1188 * @param len request length
1189 * @param ch channel on which the request was received
1191 void fuse_session_process(struct fuse_session
*se
, const char *buf
, size_t len
,
1192 struct fuse_chan
*ch
);
1197 * @param se the session
1199 void fuse_session_destroy(struct fuse_session
*se
);
1204 * @param se the session
1206 void fuse_session_exit(struct fuse_session
*se
);
1209 * Reset the exited status of a session
1211 * @param se the session
1213 void fuse_session_reset(struct fuse_session
*se
);
1216 * Query the exited status of a session
1218 * @param se the session
1219 * @return 1 if exited, 0 if not exited
1221 int fuse_session_exited(struct fuse_session
*se
);
1224 * Enter a single threaded event loop
1226 * @param se the session
1227 * @return 0 on success, -1 on error
1229 int fuse_session_loop(struct fuse_session
*se
);
1232 * Enter a multi-threaded event loop
1234 * @param se the session
1235 * @return 0 on success, -1 on error
1237 int fuse_session_loop_mt(struct fuse_session
*se
);
1239 /* ----------------------------------------------------------- *
1240 * Channel interface *
1241 * ----------------------------------------------------------- */
1244 * Channel operations
1246 * This is used in channel creation
1248 struct fuse_chan_ops
{
1250 * Hook for receiving a raw request
1252 * @param ch pointer to the channel
1253 * @param buf the buffer to store the request in
1254 * @param size the size of the buffer
1255 * @return the actual size of the raw request, or -1 on error
1257 int (*receive
)(struct fuse_chan
**chp
, char *buf
, size_t size
);
1260 * Hook for sending a raw reply
1262 * A return value of -ENOENT means, that the request was
1263 * interrupted, and the reply was discarded
1265 * @param ch the channel
1266 * @param iov vector of blocks
1267 * @param count the number of blocks in vector
1268 * @return zero on success, -errno on failure
1270 int (*send
)(struct fuse_chan
*ch
, const struct iovec iov
[],
1274 * Destroy the channel
1276 * @param ch the channel
1278 void (*destroy
)(struct fuse_chan
*ch
);
1282 * Create a new channel
1284 * @param op channel operations
1285 * @param fd file descriptor of the channel
1286 * @param bufsize the minimal receive buffer size
1287 * @param data user data
1288 * @return the new channel object, or NULL on failure
1290 struct fuse_chan
*fuse_chan_new(struct fuse_chan_ops
*op
, int fd
,
1291 size_t bufsize
, void *data
);
1294 * Query the file descriptor of the channel
1296 * @param ch the channel
1297 * @return the file descriptor passed to fuse_chan_new()
1299 int fuse_chan_fd(struct fuse_chan
*ch
);
1302 * Query the minimal receive buffer size
1304 * @param ch the channel
1305 * @return the buffer size passed to fuse_chan_new()
1307 size_t fuse_chan_bufsize(struct fuse_chan
*ch
);
1310 * Query the user data
1312 * @param ch the channel
1313 * @return the user data passed to fuse_chan_new()
1315 void *fuse_chan_data(struct fuse_chan
*ch
);
1318 * Query the session to which this channel is assigned
1320 * @param ch the channel
1321 * @return the session, or NULL if the channel is not assigned
1323 struct fuse_session
*fuse_chan_session(struct fuse_chan
*ch
);
1326 * Receive a raw request
1328 * A return value of -ENODEV means, that the filesystem was unmounted
1330 * @param ch pointer to the channel
1331 * @param buf the buffer to store the request in
1332 * @param size the size of the buffer
1333 * @return the actual size of the raw request, or -errno on error
1335 int fuse_chan_recv(struct fuse_chan
**ch
, char *buf
, size_t size
);
1340 * A return value of -ENOENT means, that the request was
1341 * interrupted, and the reply was discarded
1343 * @param ch the channel
1344 * @param iov vector of blocks
1345 * @param count the number of blocks in vector
1346 * @return zero on success, -errno on failure
1348 int fuse_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[],
1354 * @param ch the channel
1356 void fuse_chan_destroy(struct fuse_chan
*ch
);
1362 #endif /* _FUSE_LOWLEVEL_H_ */