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)
117 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
118 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
120 /* ----------------------------------------------------------- *
121 * Request methods and replies *
122 * ----------------------------------------------------------- */
125 * Low level filesystem operations
127 * Most of the methods (with the exception of init and destroy)
128 * receive a request handle (fuse_req_t) as their first argument.
129 * This handle must be passed to one of the specified reply functions.
131 * This may be done inside the method invocation, or after the call
132 * has returned. The request handle is valid until one of the reply
133 * functions is called.
135 * Other pointer arguments (name, fuse_file_info, etc) are not valid
136 * after the call has returned, so if they are needed later, their
137 * contents have to be copied.
139 * The filesystem sometimes needs to handle a return value of -ENOENT
140 * from the reply function, which means, that the request was
141 * interrupted, and the reply discarded. For example if
142 * fuse_reply_open() return -ENOENT means, that the release method for
143 * this file will not be called.
145 struct fuse_lowlevel_ops
{
147 * Initialize filesystem
149 * Called before any other filesystem method
151 * There's no reply to this function
153 * @param userdata the user data passed to fuse_lowlevel_new()
155 void (*init
) (void *userdata
, struct fuse_conn_info
*conn
);
158 * Clean up filesystem
160 * Called on filesystem exit
162 * There's no reply to this function
164 * @param userdata the user data passed to fuse_lowlevel_new()
166 void (*destroy
) (void *userdata
);
169 * Look up a directory entry by name and get its attributes.
175 * @param req request handle
176 * @param parent inode number of the parent directory
177 * @param name the name to look up
179 void (*lookup
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
182 * Forget about an inode
184 * The nlookup parameter indicates the number of lookups
185 * previously performed on this inode.
187 * If the filesystem implements inode lifetimes, it is recommended
188 * that inodes acquire a single reference on each lookup, and lose
189 * nlookup references on each forget.
191 * The filesystem may ignore forget calls, if the inodes don't
192 * need to have a limited lifetime.
194 * On unmount it is not guaranteed, that all referenced inodes
195 * will receive a forget message.
200 * @param req request handle
201 * @param ino the inode number
202 * @param nlookup the number of lookups to forget
204 void (*forget
) (fuse_req_t req
, fuse_ino_t ino
, unsigned long nlookup
);
207 * Get file attributes
213 * @param req request handle
214 * @param ino the inode number
215 * @param fi for future use, currently always NULL
217 void (*getattr
) (fuse_req_t req
, fuse_ino_t ino
,
218 struct fuse_file_info
*fi
);
221 * Set file attributes
223 * In the 'attr' argument only members indicated by the 'to_set'
224 * bitmask contain valid values. Other members contain undefined
227 * If the setattr was invoked from the ftruncate() system call
228 * under Linux kernel versions 2.6.15 or later, the fi->fh will
229 * contain the value set by the open method or will be undefined
230 * if the open method didn't set any value. Otherwise (not
231 * ftruncate call, or kernel version earlier than 2.6.15) the fi
232 * parameter will be NULL.
238 * @param req request handle
239 * @param ino the inode number
240 * @param attr the attributes
241 * @param to_set bit mask of attributes which should be set
242 * @param fi file information, or NULL
244 * Changed in version 2.5:
245 * file information filled in for ftruncate
247 void (*setattr
) (fuse_req_t req
, fuse_ino_t ino
, struct stat
*attr
,
248 int to_set
, struct fuse_file_info
*fi
);
254 * fuse_reply_readlink
257 * @param req request handle
258 * @param ino the inode number
260 void (*readlink
) (fuse_req_t req
, fuse_ino_t ino
);
265 * Create a regular file, character device, block device, fifo or
272 * @param req request handle
273 * @param parent inode number of the parent directory
274 * @param name to create
275 * @param mode file type and mode with which to create the new file
276 * @param rdev the device number (only valid if created file is a device)
278 void (*mknod
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
279 mode_t mode
, dev_t rdev
);
288 * @param req request handle
289 * @param parent inode number of the parent directory
290 * @param name to create
291 * @param mode with which to create the new file
293 void (*mkdir
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
302 * @param req request handle
303 * @param parent inode number of the parent directory
304 * @param name to remove
306 void (*unlink
) (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 (*rmdir
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
);
321 * Create a symbolic link
327 * @param req request handle
328 * @param link the contents of the symbolic link
329 * @param parent inode number of the parent directory
330 * @param name to create
332 void (*symlink
) (fuse_req_t req
, const char *link
, fuse_ino_t parent
,
340 * @param req request handle
341 * @param parent inode number of the old parent directory
342 * @param name old name
343 * @param newparent inode number of the new parent directory
344 * @param newname new name
346 void (*rename
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
347 fuse_ino_t newparent
, const char *newname
);
356 * @param req request handle
357 * @param ino the old inode number
358 * @param newparent inode number of the new parent directory
359 * @param newname new name to create
361 void (*link
) (fuse_req_t req
, fuse_ino_t ino
, fuse_ino_t newparent
,
362 const char *newname
);
367 * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
368 * O_TRUNC) are available in fi->flags.
370 * Filesystem may store an arbitrary file handle (pointer, index,
371 * etc) in fi->fh, and use this in other all other file operations
372 * (read, write, flush, release, fsync).
374 * Filesystem may also implement stateless file I/O and not store
375 * anything in fi->fh.
377 * There are also some flags (direct_io, keep_cache) which the
378 * filesystem may set in fi, to change the way the file is opened.
379 * See fuse_file_info structure in <fuse_common.h> for more details.
385 * @param req request handle
386 * @param ino the inode number
387 * @param fi file information
389 void (*open
) (fuse_req_t req
, fuse_ino_t ino
,
390 struct fuse_file_info
*fi
);
395 * Read should send exactly the number of bytes requested except
396 * on EOF or error, otherwise the rest of the data will be
397 * substituted with zeroes. An exception to this is when the file
398 * has been opened in 'direct_io' mode, in which case the return
399 * value of the read system call will reflect the return value of
402 * fi->fh will contain the value set by the open method, or will
403 * be undefined if the open method didn't set any value.
409 * @param req request handle
410 * @param ino the inode number
411 * @param size number of bytes to read
412 * @param off offset to read from
413 * @param fi file information
415 void (*read
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
, off_t off
,
416 struct fuse_file_info
*fi
);
421 * Write should return exactly the number of bytes requested
422 * except on error. An exception to this is when the file has
423 * been opened in 'direct_io' mode, in which case the return value
424 * of the write system call will reflect the return value of this
427 * fi->fh will contain the value set by the open method, or will
428 * be undefined if the open method didn't set any value.
434 * @param req request handle
435 * @param ino the inode number
436 * @param buf data to write
437 * @param size number of bytes to write
438 * @param off offset to write to
439 * @param fi file information
441 void (*write
) (fuse_req_t req
, fuse_ino_t ino
, const char *buf
,
442 size_t size
, off_t off
, struct fuse_file_info
*fi
);
447 * This is called on each close() of the opened file.
449 * Since file descriptors can be duplicated (dup, dup2, fork), for
450 * one open call there may be many flush calls.
452 * Filesystems shouldn't assume that flush will always be called
453 * after some writes, or that if will be called at all.
455 * fi->fh will contain the value set by the open method, or will
456 * be undefined if the open method didn't set any value.
458 * NOTE: the name of the method is misleading, since (unlike
459 * fsync) the filesystem is not forced to flush pending writes.
460 * One reason to flush data, is if the filesystem wants to return
463 * If the filesystem supports file locking operations (setlk,
464 * getlk) it should remove all locks belonging to 'fi->owner'.
469 * @param req request handle
470 * @param ino the inode number
471 * @param fi file information
473 void (*flush
) (fuse_req_t req
, fuse_ino_t ino
,
474 struct fuse_file_info
*fi
);
477 * Release an open file
479 * Release is called when there are no more references to an open
480 * file: all file descriptors are closed and all memory mappings
483 * For every open call there will be exactly one release call.
485 * The filesystem may reply with an error, but error values are
486 * not returned to close() or munmap() which triggered the
489 * fi->fh will contain the value set by the open method, or will
490 * be undefined if the open method didn't set any value.
491 * fi->flags will contain the same flags as for open.
496 * @param req request handle
497 * @param ino the inode number
498 * @param fi file information
500 void (*release
) (fuse_req_t req
, fuse_ino_t ino
,
501 struct fuse_file_info
*fi
);
504 * Synchronize file contents
506 * If the datasync parameter is non-zero, then only the user data
507 * should be flushed, not the meta data.
512 * @param req request handle
513 * @param ino the inode number
514 * @param datasync flag indicating if only data should be flushed
515 * @param fi file information
517 void (*fsync
) (fuse_req_t req
, fuse_ino_t ino
, int datasync
,
518 struct fuse_file_info
*fi
);
523 * Filesystem may store an arbitrary file handle (pointer, index,
524 * etc) in fi->fh, and use this in other all other directory
525 * stream operations (readdir, releasedir, fsyncdir).
527 * Filesystem may also implement stateless directory I/O and not
528 * store anything in fi->fh, though that makes it impossible to
529 * implement standard conforming directory stream operations in
530 * case the contents of the directory can change between opendir
537 * @param req request handle
538 * @param ino the inode number
539 * @param fi file information
541 void (*opendir
) (fuse_req_t req
, fuse_ino_t ino
,
542 struct fuse_file_info
*fi
);
547 * Send a buffer filled using fuse_add_direntry(), with size not
548 * exceeding the requested size. Send an empty buffer on end of
551 * fi->fh will contain the value set by the opendir method, or
552 * will be undefined if the opendir method didn't set any value.
558 * @param req request handle
559 * @param ino the inode number
560 * @param size maximum number of bytes to send
561 * @param off offset to continue reading the directory stream
562 * @param fi file information
564 void (*readdir
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
, off_t off
,
565 struct fuse_file_info
*fi
);
568 * Release an open directory
570 * For every opendir call there will be exactly one releasedir
573 * fi->fh will contain the value set by the opendir method, or
574 * will be undefined if the opendir method didn't set any value.
579 * @param req request handle
580 * @param ino the inode number
581 * @param fi file information
583 void (*releasedir
) (fuse_req_t req
, fuse_ino_t ino
,
584 struct fuse_file_info
*fi
);
587 * Synchronize directory contents
589 * If the datasync parameter is non-zero, then only the directory
590 * contents should be flushed, not the meta data.
592 * fi->fh will contain the value set by the opendir method, or
593 * will be undefined if the opendir method didn't set any value.
598 * @param req request handle
599 * @param ino the inode number
600 * @param datasync flag indicating if only data should be flushed
601 * @param fi file information
603 void (*fsyncdir
) (fuse_req_t req
, fuse_ino_t ino
, int datasync
,
604 struct fuse_file_info
*fi
);
607 * Get file system statistics
613 * @param req request handle
614 * @param ino the inode number, zero means "undefined"
616 void (*statfs
) (fuse_req_t req
, fuse_ino_t ino
);
619 * Set an extended attribute
624 void (*setxattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
,
625 const char *value
, size_t size
, int flags
);
628 * Get an extended attribute
630 * If size is zero, the size of the value should be sent with
633 * If the size is non-zero, and the value fits in the buffer, the
634 * value should be sent with fuse_reply_buf.
636 * If the size is too small for the value, the ERANGE error should
644 * @param req request handle
645 * @param ino the inode number
646 * @param name of the extended attribute
647 * @param size maximum size of the value to send
649 void (*getxattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
,
653 * List extended attribute names
655 * If size is zero, the total size of the attribute list should be
656 * sent with fuse_reply_xattr.
658 * If the size is non-zero, and the null character separated
659 * attribute list fits in the buffer, the list should be sent with
662 * If the size is too small for the list, the ERANGE error should
670 * @param req request handle
671 * @param ino the inode number
672 * @param size maximum size of the list to send
674 void (*listxattr
) (fuse_req_t req
, fuse_ino_t ino
, size_t size
);
677 * Remove an extended attribute
682 * @param req request handle
683 * @param ino the inode number
684 * @param name of the extended attribute
686 void (*removexattr
) (fuse_req_t req
, fuse_ino_t ino
, const char *name
);
689 * Check file access permissions
691 * This will be called for the access() system call. If the
692 * 'default_permissions' mount option is given, this method is not
695 * This method is not called under Linux kernel versions 2.4.x
697 * Introduced in version 2.5
702 * @param req request handle
703 * @param ino the inode number
704 * @param mask requested access mode
706 void (*access
) (fuse_req_t req
, fuse_ino_t ino
, int mask
);
709 * Create and open a file
711 * If the file does not exist, first create it with the specified
712 * mode, and then open it.
714 * Open flags (with the exception of O_NOCTTY) are available in
717 * Filesystem may store an arbitrary file handle (pointer, index,
718 * etc) in fi->fh, and use this in other all other file operations
719 * (read, write, flush, release, fsync).
721 * There are also some flags (direct_io, keep_cache) which the
722 * filesystem may set in fi, to change the way the file is opened.
723 * See fuse_file_info structure in <fuse_common.h> for more details.
725 * If this method is not implemented or under Linux kernel
726 * versions earlier than 2.6.15, the mknod() and open() methods
727 * will be called instead.
729 * Introduced in version 2.5
735 * @param req request handle
736 * @param parent inode number of the parent directory
737 * @param name to create
738 * @param mode file type and mode with which to create the new file
739 * @param fi file information
741 void (*create
) (fuse_req_t req
, fuse_ino_t parent
, const char *name
,
742 mode_t mode
, struct fuse_file_info
*fi
);
745 * Test for a POSIX file lock
747 * Introduced in version 2.6
753 * @param req request handle
754 * @param ino the inode number
755 * @param fi file information
756 * @param lock the region/type to test
758 void (*getlk
) (fuse_req_t req
, fuse_ino_t ino
,
759 struct fuse_file_info
*fi
, struct flock
*lock
);
762 * Acquire, modify or release a POSIX file lock
764 * For POSIX threads (NPTL) there's a 1-1 relation between pid and
765 * owner, but otherwise this is not always the case. For checking
766 * lock ownership, 'fi->owner' must be used. The l_pid field in
767 * 'struct flock' should only be used to fill in this field in
770 * Note: if the locking methods are not implemented, the kernel
771 * will still allow file locking to work locally. Hence these are
772 * only interesting for network filesystems and similar.
774 * Introduced in version 2.6
779 * @param req request handle
780 * @param ino the inode number
781 * @param fi file information
782 * @param lock the region/type to test
783 * @param sleep locking operation may sleep
785 void (*setlk
) (fuse_req_t req
, fuse_ino_t ino
,
786 struct fuse_file_info
*fi
,
787 struct flock
*lock
, int sleep
);
790 * Map block index within file to block index within device
792 * Note: This makes sense only for block device backed filesystems
793 * mounted with the 'blkdev' option
795 * Introduced in version 2.6
801 * @param req request handle
802 * @param ino the inode number
803 * @param blocksize unit of block index
804 * @param idx block index within file
806 void (*bmap
) (fuse_req_t req
, fuse_ino_t ino
, size_t blocksize
,
811 * Reply with an error code or success
816 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
817 * removexattr and setlk may send a zero code
819 * @param req request handle
820 * @param err the positive error value, or zero for success
821 * @return zero for success, -errno for failure to send reply
823 int fuse_reply_err(fuse_req_t req
, int err
);
831 * @param req request handle
833 void fuse_reply_none(fuse_req_t req
);
836 * Reply with a directory entry
839 * lookup, mknod, mkdir, symlink, link
841 * @param req request handle
842 * @param e the entry parameters
843 * @return zero for success, -errno for failure to send reply
845 int fuse_reply_entry(fuse_req_t req
, const struct fuse_entry_param
*e
);
848 * Reply with a directory entry and open parameters
850 * currently the following members of 'fi' are used:
851 * fh, direct_io, keep_cache
856 * @param req request handle
857 * @param e the entry parameters
858 * @param fi file information
859 * @return zero for success, -errno for failure to send reply
861 int fuse_reply_create(fuse_req_t req
, const struct fuse_entry_param
*e
,
862 const struct fuse_file_info
*fi
);
865 * Reply with attributes
870 * @param req request handle
871 * @param the attributes
872 * @param attr_timeout validity timeout (in seconds) for the attributes
873 * @return zero for success, -errno for failure to send reply
875 int fuse_reply_attr(fuse_req_t req
, const struct stat
*attr
,
876 double attr_timeout
);
879 * Reply with the contents of a symbolic link
884 * @param req request handle
885 * @param link symbolic link contents
886 * @return zero for success, -errno for failure to send reply
888 int fuse_reply_readlink(fuse_req_t req
, const char *link
);
891 * Reply with open parameters
893 * currently the following members of 'fi' are used:
894 * fh, direct_io, keep_cache
899 * @param req request handle
900 * @param fi file information
901 * @return zero for success, -errno for failure to send reply
903 int fuse_reply_open(fuse_req_t req
, const struct fuse_file_info
*fi
);
906 * Reply with number of bytes written
911 * @param req request handle
912 * @param count the number of bytes written
913 * @return zero for success, -errno for failure to send reply
915 int fuse_reply_write(fuse_req_t req
, size_t count
);
921 * read, readdir, getxattr, listxattr
923 * @param req request handle
924 * @param buf buffer containing data
925 * @param size the size of data in bytes
926 * @return zero for success, -errno for failure to send reply
928 int fuse_reply_buf(fuse_req_t req
, const char *buf
, size_t size
);
932 * Reply with data vector
935 * read, readdir, getxattr, listxattr
937 * @param req request handle
938 * @param iov the vector containing the data
939 * @param count the size of vector
940 * @return zero for success, -errno for failure to send reply
942 int fuse_reply_iov(fuse_req_t req
, const struct iovec
*iov
, int count
);
946 * Reply with filesystem statistics
951 * @param req request handle
952 * @param stbuf filesystem statistics
953 * @return zero for success, -errno for failure to send reply
955 int fuse_reply_statfs(fuse_req_t req
, const struct statvfs
*stbuf
);
958 * Reply with needed buffer size
961 * getxattr, listxattr
963 * @param req request handle
964 * @param count the buffer size needed in bytes
965 * @return zero for success, -errno for failure to send reply
967 int fuse_reply_xattr(fuse_req_t req
, size_t count
);
970 * Reply with file lock information
975 * @param req request handle
976 * @param lock the lock information
977 * @return zero for success, -errno for failure to send reply
979 int fuse_reply_lock(fuse_req_t req
, struct flock
*lock
);
982 * Reply with block index
987 * @param req request handle
988 * @param idx block index within device
989 * @return zero for success, -errno for failure to send reply
991 int fuse_reply_bmap(fuse_req_t req
, uint64_t idx
);
993 /* ----------------------------------------------------------- *
994 * Filling a buffer in readdir *
995 * ----------------------------------------------------------- */
998 * Add a directory entry to the buffer
1000 * Buffer needs to be large enough to hold the entry. Of it's not,
1001 * then the entry is not filled in but the size of the entry is still
1002 * returned. The caller can check this by comparing the bufsize
1003 * parameter with the returned entry size. If the entry size is
1004 * larger than the buffer size, the operation failed.
1006 * From the 'stbuf' argument the st_ino field and bits 12-15 of the
1007 * st_mode field are used. The other fields are ignored.
1009 * Note: offsets do not necessarily represent physical offsets, and
1010 * could be any marker, that enables the implementation to find a
1011 * specific point in the directory stream.
1013 * @param req request handle
1014 * @param buf the point where the new entry will be added to the buffer
1015 * @param bufsize remaining size of the buffer
1016 * @param the name of the entry
1017 * @param stbuf the file attributes
1018 * @param off the offset of the next entry
1019 * @return the space needed for the entry
1021 size_t fuse_add_direntry(fuse_req_t req
, char *buf
, size_t bufsize
,
1022 const char *name
, const struct stat
*stbuf
,
1025 /* ----------------------------------------------------------- *
1026 * Utility functions *
1027 * ----------------------------------------------------------- */
1030 * Get the userdata from the request
1032 * @param req request handle
1033 * @return the user data passed to fuse_lowlevel_new()
1035 void *fuse_req_userdata(fuse_req_t req
);
1038 * Get the context from the request
1040 * The pointer returned by this function will only be valid for the
1041 * request's lifetime
1043 * @param req request handle
1044 * @return the context structure
1046 const struct fuse_ctx
*fuse_req_ctx(fuse_req_t req
);
1049 * Callback function for an interrupt
1051 * @param req interrupted request
1052 * @param data user data
1054 typedef void (*fuse_interrupt_func_t
)(fuse_req_t req
, void *data
);
1057 * Register/unregister callback for an interrupt
1059 * If an interrupt has already happened, then the callback function is
1060 * called from within this function, hence it's not possible for
1061 * interrupts to be lost.
1063 * @param req request handle
1064 * @param func the callback function or NULL for unregister
1065 * @parm data user data passed to the callback function
1067 void fuse_req_interrupt_func(fuse_req_t req
, fuse_interrupt_func_t func
,
1071 * Check if a request has already been interrupted
1073 * @param req request handle
1074 * @return 1 if the request has been interrupted, 0 otherwise
1076 int fuse_req_interrupted(fuse_req_t req
);
1078 /* ----------------------------------------------------------- *
1079 * Filesystem setup *
1080 * ----------------------------------------------------------- */
1084 /* Deprecated, don't use */
1085 int fuse_lowlevel_is_lib_option(const char *opt
);
1087 #endif /* __SOLARIS__ */
1090 * Create a low level session
1092 * @param args argument vector
1093 * @param op the low level filesystem operations
1094 * @param op_size sizeof(struct fuse_lowlevel_ops)
1095 * @param userdata user data
1096 * @return the created session object, or NULL on failure
1098 struct fuse_session
*fuse_lowlevel_new(struct fuse_args
*args
,
1099 const struct fuse_lowlevel_ops
*op
,
1100 size_t op_size
, void *userdata
);
1102 /* ----------------------------------------------------------- *
1103 * Session interface *
1104 * ----------------------------------------------------------- */
1107 * Session operations
1109 * This is used in session creation
1111 struct fuse_session_ops
{
1113 * Hook to process a request (mandatory)
1115 * @param data user data passed to fuse_session_new()
1116 * @param buf buffer containing the raw request
1117 * @param len request length
1118 * @param ch channel on which the request was received
1120 void (*process
) (void *data
, const char *buf
, size_t len
,
1121 struct fuse_chan
*ch
);
1124 * Hook for session exit and reset (optional)
1126 * @param data user data passed to fuse_session_new()
1127 * @param val exited status (1 - exited, 0 - not exited)
1129 void (*exit
) (void *data
, int val
);
1132 * Hook for querying the current exited status (optional)
1134 * @param data user data passed to fuse_session_new()
1135 * @return 1 if exited, 0 if not exited
1137 int (*exited
) (void *data
);
1140 * Hook for cleaning up the channel on destroy (optional)
1142 * @param data user data passed to fuse_session_new()
1144 void (*destroy
) (void *data
);
1148 * Create a new session
1150 * @param op session operations
1151 * @param data user data
1152 * @return new session object, or NULL on failure
1154 struct fuse_session
*fuse_session_new(struct fuse_session_ops
*op
, void *data
);
1157 * Assign a channel to a session
1159 * Note: currently only a single channel may be assigned. This may
1160 * change in the future
1162 * If a session is destroyed, the assigned channel is also destroyed
1164 * @param se the session
1165 * @param ch the channel
1167 void fuse_session_add_chan(struct fuse_session
*se
, struct fuse_chan
*ch
);
1170 * Remove a channel from a session
1172 * If the channel is not assigned to a session, then this is a no-op
1174 * @param ch the channel to remove
1176 void fuse_session_remove_chan(struct fuse_chan
*ch
);
1179 * Iterate over the channels assigned to a session
1181 * The iterating function needs to start with a NULL channel, and
1182 * after that needs to pass the previously returned channel to the
1185 * @param se the session
1186 * @param ch the previous channel, or NULL
1187 * @return the next channel, or NULL if no more channels exist
1189 struct fuse_chan
*fuse_session_next_chan(struct fuse_session
*se
,
1190 struct fuse_chan
*ch
);
1193 * Process a raw request
1195 * @param se the session
1196 * @param buf buffer containing the raw request
1197 * @param len request length
1198 * @param ch channel on which the request was received
1200 void fuse_session_process(struct fuse_session
*se
, const char *buf
, size_t len
,
1201 struct fuse_chan
*ch
);
1206 * @param se the session
1208 void fuse_session_destroy(struct fuse_session
*se
);
1213 * @param se the session
1215 void fuse_session_exit(struct fuse_session
*se
);
1218 * Reset the exited status of a session
1220 * @param se the session
1222 void fuse_session_reset(struct fuse_session
*se
);
1225 * Query the exited status of a session
1227 * @param se the session
1228 * @return 1 if exited, 0 if not exited
1230 int fuse_session_exited(struct fuse_session
*se
);
1233 * Enter a single threaded event loop
1235 * @param se the session
1236 * @return 0 on success, -1 on error
1238 int fuse_session_loop(struct fuse_session
*se
);
1241 * Enter a multi-threaded event loop
1243 * @param se the session
1244 * @return 0 on success, -1 on error
1246 int fuse_session_loop_mt(struct fuse_session
*se
);
1248 /* ----------------------------------------------------------- *
1249 * Channel interface *
1250 * ----------------------------------------------------------- */
1253 * Channel operations
1255 * This is used in channel creation
1257 struct fuse_chan_ops
{
1259 * Hook for receiving a raw request
1261 * @param ch pointer to the channel
1262 * @param buf the buffer to store the request in
1263 * @param size the size of the buffer
1264 * @return the actual size of the raw request, or -1 on error
1266 int (*receive
)(struct fuse_chan
**chp
, char *buf
, size_t size
);
1269 * Hook for sending a raw reply
1271 * A return value of -ENOENT means, that the request was
1272 * interrupted, and the reply was discarded
1274 * @param ch the channel
1275 * @param iov vector of blocks
1276 * @param count the number of blocks in vector
1277 * @return zero on success, -errno on failure
1279 int (*send
)(struct fuse_chan
*ch
, const struct iovec iov
[],
1283 * Destroy the channel
1285 * @param ch the channel
1287 void (*destroy
)(struct fuse_chan
*ch
);
1291 * Create a new channel
1293 * @param op channel operations
1294 * @param fd file descriptor of the channel
1295 * @param bufsize the minimal receive buffer size
1296 * @param data user data
1297 * @return the new channel object, or NULL on failure
1299 struct fuse_chan
*fuse_chan_new(struct fuse_chan_ops
*op
, int fd
,
1300 size_t bufsize
, void *data
);
1303 * Query the file descriptor of the channel
1305 * @param ch the channel
1306 * @return the file descriptor passed to fuse_chan_new()
1308 int fuse_chan_fd(struct fuse_chan
*ch
);
1311 * Query the minimal receive buffer size
1313 * @param ch the channel
1314 * @return the buffer size passed to fuse_chan_new()
1316 size_t fuse_chan_bufsize(struct fuse_chan
*ch
);
1319 * Query the user data
1321 * @param ch the channel
1322 * @return the user data passed to fuse_chan_new()
1324 void *fuse_chan_data(struct fuse_chan
*ch
);
1327 * Query the session to which this channel is assigned
1329 * @param ch the channel
1330 * @return the session, or NULL if the channel is not assigned
1332 struct fuse_session
*fuse_chan_session(struct fuse_chan
*ch
);
1335 * Receive a raw request
1337 * A return value of -ENODEV means, that the filesystem was unmounted
1339 * @param ch pointer to the channel
1340 * @param buf the buffer to store the request in
1341 * @param size the size of the buffer
1342 * @return the actual size of the raw request, or -errno on error
1344 int fuse_chan_recv(struct fuse_chan
**ch
, char *buf
, size_t size
);
1349 * A return value of -ENOENT means, that the request was
1350 * interrupted, and the reply was discarded
1352 * @param ch the channel
1353 * @param iov vector of blocks
1354 * @param count the number of blocks in vector
1355 * @return zero on success, -errno on failure
1357 int fuse_chan_send(struct fuse_chan
*ch
, const struct iovec iov
[],
1363 * @param ch the channel
1365 void fuse_chan_destroy(struct fuse_chan
*ch
);
1371 #endif /* _FUSE_LOWLEVEL_H_ */