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.
14 * This file defines the library interface of FUSE
16 * IMPORTANT: you should define FUSE_USE_VERSION before including this header.
19 #include "fuse_common.h"
24 #include <sys/types.h>
26 #include <sys/statvfs.h>
33 /* ----------------------------------------------------------- *
35 * ----------------------------------------------------------- */
37 /** Handle for a FUSE filesystem */
40 /** Structure containing a raw command */
43 /** Function to add an entry in a readdir() operation
45 * @param buf the buffer passed to the readdir() operation
46 * @param name the file name of the directory entry
47 * @param stat file attributes, can be NULL
48 * @param off offset of the next entry or zero
49 * @return 1 if buffer is full, zero otherwise
51 typedef int (*fuse_fill_dir_t
) (void *buf
, const char *name
,
52 const struct stat
*stbuf
, off_t off
);
54 /* Used by deprecated getdir() method */
55 typedef struct fuse_dirhandle
*fuse_dirh_t
;
56 typedef int (*fuse_dirfil_t
) (fuse_dirh_t h
, const char *name
, int type
,
60 * The file system operations:
62 * Most of these should work very similarly to the well known UNIX
63 * file system operations. A major exception is that instead of
64 * returning an error in 'errno', the operation should return the
65 * negated error value (-errno) directly.
67 * All methods are optional, but some are essential for a useful
68 * filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
69 * releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock,
70 * init and destroy are special purpose methods, without which a full
71 * featured filesystem can still be implemented.
73 * Almost all operations take a path which can be of any length.
75 * Changed in fuse 2.8.0 (regardless of API version)
76 * Previously, paths were limited to a length of PATH_MAX.
78 * See http://fuse.sourceforge.net/wiki/ for more information. There
79 * is also a snapshot of the relevant wiki pages in the doc/ folder.
81 struct fuse_operations
{
82 /** Get file attributes.
84 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
85 * ignored. The 'st_ino' field is ignored except if the 'use_ino'
86 * mount option is given.
88 int (*getattr
) (const char *, struct stat
*);
90 /** Read the target of a symbolic link
92 * The buffer should be filled with a null terminated string. The
93 * buffer size argument includes the space for the terminating
94 * null character. If the linkname is too long to fit in the
95 * buffer, it should be truncated. The return value should be 0
98 int (*readlink
) (const char *, char *, size_t);
100 /* Deprecated, use readdir() instead */
101 int (*getdir
) (const char *, fuse_dirh_t
, fuse_dirfil_t
);
103 /** Create a file node
105 * This is called for creation of all non-directory, non-symlink
106 * nodes. If the filesystem defines a create() method, then for
107 * regular files that will be called instead.
109 int (*mknod
) (const char *, mode_t
, dev_t
);
111 /** Create a directory
113 * Note that the mode argument may not have the type specification
114 * bits set, i.e. S_ISDIR(mode) can be false. To obtain the
115 * correct directory type bits use mode|S_IFDIR
117 int (*mkdir
) (const char *, mode_t
);
120 int (*unlink
) (const char *);
122 /** Remove a directory */
123 int (*rmdir
) (const char *);
125 /** Create a symbolic link */
126 int (*symlink
) (const char *, const char *);
129 int (*rename
) (const char *, const char *);
131 /** Create a hard link to a file */
132 int (*link
) (const char *, const char *);
134 /** Change the permission bits of a file */
135 int (*chmod
) (const char *, mode_t
);
137 /** Change the owner and group of a file */
138 int (*chown
) (const char *, uid_t
, gid_t
);
140 /** Change the size of a file */
141 int (*truncate
) (const char *, off_t
);
143 /** Change the access and/or modification times of a file
145 * Deprecated, use utimens() instead.
147 int (*utime
) (const char *, struct utimbuf
*);
149 /** File open operation
151 * No creation (O_CREAT, O_EXCL) and by default also no
152 * truncation (O_TRUNC) flags will be passed to open(). If an
153 * application specifies O_TRUNC, fuse first calls truncate()
154 * and then open(). Only if 'atomic_o_trunc' has been
155 * specified and kernel version is 2.6.24 or later, O_TRUNC is
158 * Unless the 'default_permissions' mount option is given,
159 * open should check if the operation is permitted for the
160 * given flags. Optionally open may also return an arbitrary
161 * filehandle in the fuse_file_info structure, which will be
162 * passed to all file operations.
164 * Changed in version 2.2
166 int (*open
) (const char *, struct fuse_file_info
*);
168 /** Read data from an open file
170 * Read should return exactly the number of bytes requested except
171 * on EOF or error, otherwise the rest of the data will be
172 * substituted with zeroes. An exception to this is when the
173 * 'direct_io' mount option is specified, in which case the return
174 * value of the read system call will reflect the return value of
177 * Changed in version 2.2
179 int (*read
) (const char *, char *, size_t, off_t
,
180 struct fuse_file_info
*);
182 /** Write data to an open file
184 * Write should return exactly the number of bytes requested
185 * except on error. An exception to this is when the 'direct_io'
186 * mount option is specified (see read operation).
188 * Changed in version 2.2
190 int (*write
) (const char *, const char *, size_t, off_t
,
191 struct fuse_file_info
*);
193 /** Get file system statistics
195 * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
197 * Replaced 'struct statfs' parameter with 'struct statvfs' in
200 int (*statfs
) (const char *, struct statvfs
*);
202 /** Possibly flush cached data
204 * BIG NOTE: This is not equivalent to fsync(). It's not a
205 * request to sync dirty data.
207 * Flush is called on each close() of a file descriptor. So if a
208 * filesystem wants to return write errors in close() and the file
209 * has cached dirty data, this is a good place to write back data
210 * and return any errors. Since many applications ignore close()
211 * errors this is not always useful.
213 * NOTE: The flush() method may be called more than once for each
214 * open(). This happens if more than one file descriptor refers
215 * to an opened file due to dup(), dup2() or fork() calls. It is
216 * not possible to determine if a flush is final, so each flush
217 * should be treated equally. Multiple write-flush sequences are
218 * relatively rare, so this shouldn't be a problem.
220 * Filesystems shouldn't assume that flush will always be called
221 * after some writes, or that if will be called at all.
223 * Changed in version 2.2
225 int (*flush
) (const char *, struct fuse_file_info
*);
227 /** Release an open file
229 * Release is called when there are no more references to an open
230 * file: all file descriptors are closed and all memory mappings
233 * For every open() call there will be exactly one release() call
234 * with the same flags and file descriptor. It is possible to
235 * have a file opened more than once, in which case only the last
236 * release will mean, that no more reads/writes will happen on the
237 * file. The return value of release is ignored.
239 * Changed in version 2.2
241 int (*release
) (const char *, struct fuse_file_info
*);
243 /** Synchronize file contents
245 * If the datasync parameter is non-zero, then only the user data
246 * should be flushed, not the meta data.
248 * Changed in version 2.2
250 int (*fsync
) (const char *, int, struct fuse_file_info
*);
252 /** Set extended attributes */
253 int (*setxattr
) (const char *, const char *, const char *, size_t, int);
255 /** Get extended attributes */
256 int (*getxattr
) (const char *, const char *, char *, size_t);
258 /** List extended attributes */
259 int (*listxattr
) (const char *, char *, size_t);
261 /** Remove extended attributes */
262 int (*removexattr
) (const char *, const char *);
266 * Unless the 'default_permissions' mount option is given,
267 * this method should check if opendir is permitted for this
268 * directory. Optionally opendir may also return an arbitrary
269 * filehandle in the fuse_file_info structure, which will be
270 * passed to readdir, closedir and fsyncdir.
272 * Introduced in version 2.3
274 int (*opendir
) (const char *, struct fuse_file_info
*);
278 * This supersedes the old getdir() interface. New applications
281 * The filesystem may choose between two modes of operation:
283 * 1) The readdir implementation ignores the offset parameter, and
284 * passes zero to the filler function's offset. The filler
285 * function will not return '1' (unless an error happens), so the
286 * whole directory is read in a single readdir operation. This
287 * works just like the old getdir() method.
289 * 2) The readdir implementation keeps track of the offsets of the
290 * directory entries. It uses the offset parameter and always
291 * passes non-zero offset to the filler function. When the buffer
292 * is full (or an error happens) the filler function will return
295 * Introduced in version 2.3
297 int (*readdir
) (const char *, void *, fuse_fill_dir_t
, off_t
,
298 struct fuse_file_info
*);
300 /** Release directory
302 * Introduced in version 2.3
304 int (*releasedir
) (const char *, struct fuse_file_info
*);
306 /** Synchronize directory contents
308 * If the datasync parameter is non-zero, then only the user data
309 * should be flushed, not the meta data
311 * Introduced in version 2.3
313 int (*fsyncdir
) (const char *, int, struct fuse_file_info
*);
316 * Initialize filesystem
318 * The return value will passed in the private_data field of
319 * fuse_context to all file operations and as a parameter to the
322 * Introduced in version 2.3
323 * Changed in version 2.6
325 void *(*init
) (struct fuse_conn_info
*conn
);
328 * Clean up filesystem
330 * Called on filesystem exit.
332 * Introduced in version 2.3
334 void (*destroy
) (void *);
337 * Check file access permissions
339 * This will be called for the access() system call. If the
340 * 'default_permissions' mount option is given, this method is not
343 * This method is not called under Linux kernel versions 2.4.x
345 * Introduced in version 2.5
347 int (*access
) (const char *, int);
350 * Create and open a file
352 * If the file does not exist, first create it with the specified
353 * mode, and then open it.
355 * If this method is not implemented or under Linux kernel
356 * versions earlier than 2.6.15, the mknod() and open() methods
357 * will be called instead.
359 * Introduced in version 2.5
361 int (*create
) (const char *, mode_t
, struct fuse_file_info
*);
364 * Change the size of an open file
366 * This method is called instead of the truncate() method if the
367 * truncation was invoked from an ftruncate() system call.
369 * If this method is not implemented or under Linux kernel
370 * versions earlier than 2.6.15, the truncate() method will be
373 * Introduced in version 2.5
375 int (*ftruncate
) (const char *, off_t
, struct fuse_file_info
*);
378 * Get attributes from an open file
380 * This method is called instead of the getattr() method if the
381 * file information is available.
383 * Currently this is only called after the create() method if that
384 * is implemented (see above). Later it may be called for
385 * invocations of fstat() too.
387 * Introduced in version 2.5
389 int (*fgetattr
) (const char *, struct stat
*, struct fuse_file_info
*);
392 * Perform POSIX file locking operation
394 * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
396 * For the meaning of fields in 'struct flock' see the man page
397 * for fcntl(2). The l_whence field will always be set to
400 * For checking lock ownership, the 'fuse_file_info->owner'
401 * argument must be used.
403 * For F_GETLK operation, the library will first check currently
404 * held locks, and if a conflicting lock is found it will return
405 * information without calling this method. This ensures, that
406 * for local locks the l_pid field is correctly filled in. The
407 * results may not be accurate in case of race conditions and in
408 * the presence of hard links, but it's unlikely that an
409 * application would rely on accurate GETLK results in these
410 * cases. If a conflicting lock is not found, this method will be
411 * called, and the filesystem may fill out l_pid by a meaningful
412 * value, or it may leave this field zero.
414 * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
415 * of the process performing the locking operation.
417 * Note: if this method is not implemented, the kernel will still
418 * allow file locking to work locally. Hence it is only
419 * interesting for network filesystems and similar.
421 * Introduced in version 2.6
423 int (*lock
) (const char *, struct fuse_file_info
*, int cmd
,
427 * Change the access and modification times of a file with
428 * nanosecond resolution
430 * This supersedes the old utime() interface. New applications
433 * See the utimensat(2) man page for details.
435 * Introduced in version 2.6
437 int (*utimens
) (const char *, const struct timespec tv
[2]);
440 * Map block index within file to block index within device
442 * Note: This makes sense only for block device backed filesystems
443 * mounted with the 'blkdev' option
445 * Introduced in version 2.6
447 int (*bmap
) (const char *, size_t blocksize
, uint64_t *idx
);
450 * Flag indicating that the filesystem can accept a NULL path
451 * as the first argument for the following operations:
453 * read, write, flush, release, fsync, readdir, releasedir,
454 * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll
456 * If this flag is set these operations continue to work on
457 * unlinked files even if "-ohard_remove" option was specified.
459 unsigned int flag_nullpath_ok
:1;
462 * Flag indicating that the path need not be calculated for
463 * the following operations:
465 * read, write, flush, release, fsync, readdir, releasedir,
466 * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll
468 * Closely related to flag_nullpath_ok, but if this flag is
469 * set then the path will not be calculaged even if the file
470 * wasn't unlinked. However the path can still be non-NULL if
471 * it needs to be calculated for some other reason.
473 unsigned int flag_nopath
:1;
476 * Flag indicating that the filesystem accepts special
477 * UTIME_NOW and UTIME_OMIT values in its utimens operation.
479 unsigned int flag_utime_omit_ok
:1;
482 * Reserved flags, don't set
484 unsigned int flag_reserved
:29;
489 * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in
490 * 64bit environment. The size and direction of data is
491 * determined by _IOC_*() decoding of cmd. For _IOC_NONE,
492 * data will be NULL, for _IOC_WRITE data is out area, for
493 * _IOC_READ in area and if both are set in/out area. In all
494 * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes.
496 * Introduced in version 2.8
498 int (*ioctl
) (const char *, int cmd
, void *arg
,
499 struct fuse_file_info
*, unsigned int flags
, void *data
);
502 * Poll for IO readiness events
504 * Note: If ph is non-NULL, the client should notify
505 * when IO readiness events occur by calling
506 * fuse_notify_poll() with the specified ph.
508 * Regardless of the number of times poll with a non-NULL ph
509 * is received, single notification is enough to clear all.
510 * Notifying more times incurs overhead but doesn't harm
513 * The callee is responsible for destroying ph with
514 * fuse_pollhandle_destroy() when no longer in use.
516 * Introduced in version 2.8
518 int (*poll
) (const char *, struct fuse_file_info
*,
519 struct fuse_pollhandle
*ph
, unsigned *reventsp
);
521 /** Write contents of buffer to an open file
523 * Similar to the write() method, but data is supplied in a
524 * generic buffer. Use fuse_buf_copy() to transfer data to
527 * Introduced in version 2.9
529 int (*write_buf
) (const char *, struct fuse_bufvec
*buf
, off_t off
,
530 struct fuse_file_info
*);
532 /** Store data from an open file in a buffer
534 * Similar to the read() method, but data is stored and
535 * returned in a generic buffer.
537 * No actual copying of data has to take place, the source
538 * file descriptor may simply be stored in the buffer for
539 * later data transfer.
541 * The buffer must be allocated dynamically and stored at the
542 * location pointed to by bufp. If the buffer contains memory
543 * regions, they too must be allocated using malloc(). The
544 * allocated memory will be freed by the caller.
546 * Introduced in version 2.9
548 int (*read_buf
) (const char *, struct fuse_bufvec
**bufp
,
549 size_t size
, off_t off
, struct fuse_file_info
*);
551 * Perform BSD file locking operation
553 * The op argument will be either LOCK_SH, LOCK_EX or LOCK_UN
555 * Nonblocking requests will be indicated by ORing LOCK_NB to
556 * the above operations
558 * For more information see the flock(2) manual page.
560 * Additionally fi->owner will be set to a value unique to
561 * this open file. This same value will be supplied to
562 * ->release() when the file is released.
564 * Note: if this method is not implemented, the kernel will still
565 * allow file locking to work locally. Hence it is only
566 * interesting for network filesystems and similar.
568 * Introduced in version 2.9
570 int (*flock
) (const char *, struct fuse_file_info
*, int op
);
573 * Allocates space for an open file
575 * This function ensures that required space is allocated for specified
576 * file. If this function returns success then any subsequent write
577 * request to specified range is guaranteed not to fail because of lack
578 * of space on the file system media.
580 * Introduced in version 2.9.1
582 int (*fallocate
) (const char *, int, off_t
, off_t
,
583 struct fuse_file_info
*);
586 /** Extra context that may be needed by some filesystems
588 * The uid, gid and pid fields are not filled in case of a writepage
591 struct fuse_context
{
592 /** Pointer to the fuse object */
595 /** User ID of the calling process */
598 /** Group ID of the calling process */
601 /** Thread ID of the calling process */
604 /** Private filesystem data */
607 /** Umask of the calling process (introduced in version 2.8) */
612 * Main function of FUSE.
614 * This is for the lazy. This is all that has to be called from the
617 * This function does the following:
618 * - parses command line options (-d -s and -h)
619 * - passes relevant mount options to the fuse_mount()
620 * - installs signal handlers for INT, HUP, TERM and PIPE
621 * - registers an exit handler to unmount the filesystem on program exit
622 * - creates a fuse handle
623 * - registers the operations
624 * - calls either the single-threaded or the multi-threaded event loop
626 * Note: this is currently implemented as a macro.
628 * @param argc the argument counter passed to the main() function
629 * @param argv the argument vector passed to the main() function
630 * @param op the file system operation
631 * @param user_data user data supplied in the context during the init() method
632 * @return 0 on success, nonzero on failure
635 int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
638 #define fuse_main(argc, argv, op, user_data) \
639 fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
641 /* ----------------------------------------------------------- *
642 * More detailed API *
643 * ----------------------------------------------------------- */
646 * Create a new FUSE filesystem.
648 * @param ch the communication channel
649 * @param args argument vector
650 * @param op the filesystem operations
651 * @param op_size the size of the fuse_operations structure
652 * @param user_data user data supplied in the context during the init() method
653 * @return the created FUSE handle
655 struct fuse
*fuse_new(struct fuse_chan
*ch
, struct fuse_args
*args
,
656 const struct fuse_operations
*op
, size_t op_size
,
660 * Destroy the FUSE handle.
662 * The communication channel attached to the handle is also destroyed.
664 * NOTE: This function does not unmount the filesystem. If this is
665 * needed, call fuse_unmount() before calling this function.
667 * @param f the FUSE handle
669 void fuse_destroy(struct fuse
*f
);
674 * Requests from the kernel are processed, and the appropriate
675 * operations are called.
677 * @param f the FUSE handle
678 * @return 0 if no error occurred, -1 otherwise
680 int fuse_loop(struct fuse
*f
);
683 * Exit from event loop
685 * @param f the FUSE handle
687 void fuse_exit(struct fuse
*f
);
690 * FUSE event loop with multiple threads
692 * Requests from the kernel are processed, and the appropriate
693 * operations are called. Request are processed in parallel by
694 * distributing them between multiple threads.
696 * Calling this function requires the pthreads library to be linked to
699 * @param f the FUSE handle
700 * @return 0 if no error occurred, -1 otherwise
702 int fuse_loop_mt(struct fuse
*f
);
705 * Get the current context
707 * The context is only valid for the duration of a filesystem
708 * operation, and thus must not be stored and used later.
710 * @return the context
712 struct fuse_context
*fuse_get_context(void);
715 * Get the current supplementary group IDs for the current request
717 * Similar to the getgroups(2) system call, except the return value is
718 * always the total number of group IDs, even if it is larger than the
721 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
722 * the group list to userspace, hence this function needs to parse
723 * "/proc/$TID/task/$TID/status" to get the group IDs.
725 * This feature may not be supported on all operating systems. In
726 * such a case this function will return -ENOSYS.
728 * @param size size of given array
729 * @param list array of group IDs to be filled in
730 * @return the total number of supplementary group IDs or -errno on failure
732 int fuse_getgroups(int size
, gid_t list
[]);
735 * Check if the current request has already been interrupted
737 * @return 1 if the request has been interrupted, 0 otherwise
739 int fuse_interrupted(void);
742 * Obsolete, doesn't do anything
746 int fuse_invalidate(struct fuse
*f
, const char *path
);
748 /* Deprecated, don't use */
749 int fuse_is_lib_option(const char *opt
);
752 * The real main function
754 * Do not call this directly, use fuse_main()
756 int fuse_main_real(int argc
, char *argv
[], const struct fuse_operations
*op
,
757 size_t op_size
, void *user_data
);
760 * Start the cleanup thread when using option "remember".
762 * This is done automatically by fuse_loop_mt()
763 * @param fuse struct fuse pointer for fuse instance
764 * @return 0 on success and -1 on error
766 int fuse_start_cleanup_thread(struct fuse
*fuse
);
769 * Stop the cleanup thread when using option "remember".
771 * This is done automatically by fuse_loop_mt()
772 * @param fuse struct fuse pointer for fuse instance
774 void fuse_stop_cleanup_thread(struct fuse
*fuse
);
777 * Iterate over cache removing stale entries
778 * use in conjunction with "-oremember"
780 * NOTE: This is already done for the standard sessions
782 * @param fuse struct fuse pointer for fuse instance
783 * @return the number of seconds until the next cleanup
785 int fuse_clean_cache(struct fuse
*fuse
);
792 * Fuse filesystem object
794 * This is opaque object represents a filesystem layer
799 * These functions call the relevant filesystem operation, and return
802 * If the operation is not defined, they return -ENOSYS, with the
803 * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
804 * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
807 int fuse_fs_getattr(struct fuse_fs
*fs
, const char *path
, struct stat
*buf
);
808 int fuse_fs_fgetattr(struct fuse_fs
*fs
, const char *path
, struct stat
*buf
,
809 struct fuse_file_info
*fi
);
810 int fuse_fs_rename(struct fuse_fs
*fs
, const char *oldpath
,
811 const char *newpath
);
812 int fuse_fs_unlink(struct fuse_fs
*fs
, const char *path
);
813 int fuse_fs_rmdir(struct fuse_fs
*fs
, const char *path
);
814 int fuse_fs_symlink(struct fuse_fs
*fs
, const char *linkname
,
816 int fuse_fs_link(struct fuse_fs
*fs
, const char *oldpath
, const char *newpath
);
817 int fuse_fs_release(struct fuse_fs
*fs
, const char *path
,
818 struct fuse_file_info
*fi
);
819 int fuse_fs_open(struct fuse_fs
*fs
, const char *path
,
820 struct fuse_file_info
*fi
);
821 int fuse_fs_read(struct fuse_fs
*fs
, const char *path
, char *buf
, size_t size
,
822 off_t off
, struct fuse_file_info
*fi
);
823 int fuse_fs_read_buf(struct fuse_fs
*fs
, const char *path
,
824 struct fuse_bufvec
**bufp
, size_t size
, off_t off
,
825 struct fuse_file_info
*fi
);
826 int fuse_fs_write(struct fuse_fs
*fs
, const char *path
, const char *buf
,
827 size_t size
, off_t off
, struct fuse_file_info
*fi
);
828 int fuse_fs_write_buf(struct fuse_fs
*fs
, const char *path
,
829 struct fuse_bufvec
*buf
, off_t off
,
830 struct fuse_file_info
*fi
);
831 int fuse_fs_fsync(struct fuse_fs
*fs
, const char *path
, int datasync
,
832 struct fuse_file_info
*fi
);
833 int fuse_fs_flush(struct fuse_fs
*fs
, const char *path
,
834 struct fuse_file_info
*fi
);
835 int fuse_fs_statfs(struct fuse_fs
*fs
, const char *path
, struct statvfs
*buf
);
836 int fuse_fs_opendir(struct fuse_fs
*fs
, const char *path
,
837 struct fuse_file_info
*fi
);
838 int fuse_fs_readdir(struct fuse_fs
*fs
, const char *path
, void *buf
,
839 fuse_fill_dir_t filler
, off_t off
,
840 struct fuse_file_info
*fi
);
841 int fuse_fs_fsyncdir(struct fuse_fs
*fs
, const char *path
, int datasync
,
842 struct fuse_file_info
*fi
);
843 int fuse_fs_releasedir(struct fuse_fs
*fs
, const char *path
,
844 struct fuse_file_info
*fi
);
845 int fuse_fs_create(struct fuse_fs
*fs
, const char *path
, mode_t mode
,
846 struct fuse_file_info
*fi
);
847 int fuse_fs_lock(struct fuse_fs
*fs
, const char *path
,
848 struct fuse_file_info
*fi
, int cmd
, struct flock
*lock
);
849 int fuse_fs_flock(struct fuse_fs
*fs
, const char *path
,
850 struct fuse_file_info
*fi
, int op
);
851 int fuse_fs_chmod(struct fuse_fs
*fs
, const char *path
, mode_t mode
);
852 int fuse_fs_chown(struct fuse_fs
*fs
, const char *path
, uid_t uid
, gid_t gid
);
853 int fuse_fs_truncate(struct fuse_fs
*fs
, const char *path
, off_t size
);
854 int fuse_fs_ftruncate(struct fuse_fs
*fs
, const char *path
, off_t size
,
855 struct fuse_file_info
*fi
);
856 int fuse_fs_utimens(struct fuse_fs
*fs
, const char *path
,
857 const struct timespec tv
[2]);
858 int fuse_fs_access(struct fuse_fs
*fs
, const char *path
, int mask
);
859 int fuse_fs_readlink(struct fuse_fs
*fs
, const char *path
, char *buf
,
861 int fuse_fs_mknod(struct fuse_fs
*fs
, const char *path
, mode_t mode
,
863 int fuse_fs_mkdir(struct fuse_fs
*fs
, const char *path
, mode_t mode
);
864 int fuse_fs_setxattr(struct fuse_fs
*fs
, const char *path
, const char *name
,
865 const char *value
, size_t size
, int flags
);
866 int fuse_fs_getxattr(struct fuse_fs
*fs
, const char *path
, const char *name
,
867 char *value
, size_t size
);
868 int fuse_fs_listxattr(struct fuse_fs
*fs
, const char *path
, char *list
,
870 int fuse_fs_removexattr(struct fuse_fs
*fs
, const char *path
,
872 int fuse_fs_bmap(struct fuse_fs
*fs
, const char *path
, size_t blocksize
,
874 int fuse_fs_ioctl(struct fuse_fs
*fs
, const char *path
, int cmd
, void *arg
,
875 struct fuse_file_info
*fi
, unsigned int flags
, void *data
);
876 int fuse_fs_poll(struct fuse_fs
*fs
, const char *path
,
877 struct fuse_file_info
*fi
, struct fuse_pollhandle
*ph
,
879 int fuse_fs_fallocate(struct fuse_fs
*fs
, const char *path
, int mode
,
880 off_t offset
, off_t length
, struct fuse_file_info
*fi
);
881 void fuse_fs_init(struct fuse_fs
*fs
, struct fuse_conn_info
*conn
);
882 void fuse_fs_destroy(struct fuse_fs
*fs
);
884 int fuse_notify_poll(struct fuse_pollhandle
*ph
);
887 * Create a new fuse filesystem object
889 * This is usually called from the factory of a fuse module to create
890 * a new instance of a filesystem.
892 * @param op the filesystem operations
893 * @param op_size the size of the fuse_operations structure
894 * @param user_data user data supplied in the context during the init() method
895 * @return a new filesystem object
897 struct fuse_fs
*fuse_fs_new(const struct fuse_operations
*op
, size_t op_size
,
903 * Filesystem modules are registered with the FUSE_REGISTER_MODULE()
906 * If the "-omodules=modname:..." option is present, filesystem
907 * objects are created and pushed onto the stack with the 'factory'
917 * Factory for creating filesystem objects
919 * The function may use and remove options from 'args' that belong
922 * For now the 'fs' vector always contains exactly one filesystem.
923 * This is the filesystem which will be below the newly created
924 * filesystem in the stack.
926 * @param args the command line arguments
927 * @param fs NULL terminated filesystem object vector
928 * @return the new filesystem object
930 struct fuse_fs
*(*factory
)(struct fuse_args
*args
,
931 struct fuse_fs
*fs
[]);
933 struct fuse_module
*next
;
934 struct fusemod_so
*so
;
939 * Register a filesystem module
941 * This function is used by FUSE_REGISTER_MODULE and there's usually
942 * no need to call it directly
944 void fuse_register_module(struct fuse_module
*mod
);
947 * Register filesystem module
949 * For the parameters, see description of the fields in 'struct
952 #define FUSE_REGISTER_MODULE(name_, factory_) \
953 static __attribute__((constructor)) void name_ ## _register(void) \
955 static struct fuse_module mod = \
956 { #name_, factory_, NULL, NULL, 0 }; \
957 fuse_register_module(&mod); \
961 /* ----------------------------------------------------------- *
962 * Advanced API for event handling, don't worry about this... *
963 * ----------------------------------------------------------- */
965 /* NOTE: the following functions are deprecated, and will be removed
966 from the 3.0 API. Use the lowlevel session functions instead */
968 /** Function type used to process commands */
969 typedef void (*fuse_processor_t
)(struct fuse
*, struct fuse_cmd
*, void *);
971 /** This is the part of fuse_main() before the event loop */
972 struct fuse
*fuse_setup(int argc
, char *argv
[],
973 const struct fuse_operations
*op
, size_t op_size
,
974 char **mountpoint
, int *multithreaded
,
977 /** This is the part of fuse_main() after the event loop */
978 void fuse_teardown(struct fuse
*fuse
, char *mountpoint
);
980 /** Read a single command. If none are read, return NULL */
981 struct fuse_cmd
*fuse_read_cmd(struct fuse
*f
);
983 /** Process a single command */
984 void fuse_process_cmd(struct fuse
*f
, struct fuse_cmd
*cmd
);
986 /** Multi threaded event loop, which calls the custom command
987 processor function */
988 int fuse_loop_mt_proc(struct fuse
*f
, fuse_processor_t proc
, void *data
);
990 /** Return the exited flag, which indicates if fuse_exit() has been
992 int fuse_exited(struct fuse
*f
);
994 /** This function is obsolete and implemented as a no-op */
995 void fuse_set_getcontext_func(struct fuse_context
*(*func
)(void));
997 /** Get session from fuse object */
998 struct fuse_session
*fuse_get_session(struct fuse
*f
);
1000 /* ----------------------------------------------------------- *
1001 * Compatibility stuff *
1002 * ----------------------------------------------------------- */
1004 #if FUSE_USE_VERSION < 26
1005 # include "fuse_compat.h"
1007 # if FUSE_USE_VERSION == 25
1008 # define fuse_main(argc, argv, op) \
1009 fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
1010 # define fuse_new fuse_new_compat25
1011 # define fuse_setup fuse_setup_compat25
1012 # define fuse_teardown fuse_teardown_compat22
1013 # define fuse_operations fuse_operations_compat25
1014 # elif FUSE_USE_VERSION == 22
1015 # define fuse_main(argc, argv, op) \
1016 fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
1017 # define fuse_new fuse_new_compat22
1018 # define fuse_setup fuse_setup_compat22
1019 # define fuse_teardown fuse_teardown_compat22
1020 # define fuse_operations fuse_operations_compat22
1021 # define fuse_file_info fuse_file_info_compat
1022 # elif FUSE_USE_VERSION == 24
1023 # error Compatibility with high-level API version 24 not supported
1025 # define fuse_dirfil_t fuse_dirfil_t_compat
1026 # define __fuse_read_cmd fuse_read_cmd
1027 # define __fuse_process_cmd fuse_process_cmd
1028 # define __fuse_loop_mt fuse_loop_mt_proc
1029 # if FUSE_USE_VERSION == 21
1030 # define fuse_operations fuse_operations_compat2
1031 # define fuse_main fuse_main_compat2
1032 # define fuse_new fuse_new_compat2
1033 # define __fuse_setup fuse_setup_compat2
1034 # define __fuse_teardown fuse_teardown_compat22
1035 # define __fuse_exited fuse_exited
1036 # define __fuse_set_getcontext_func fuse_set_getcontext_func
1038 # define fuse_statfs fuse_statfs_compat1
1039 # define fuse_operations fuse_operations_compat1
1040 # define fuse_main fuse_main_compat1
1041 # define fuse_new fuse_new_compat1
1042 # define FUSE_DEBUG FUSE_DEBUG_COMPAT1
1051 #endif /* _FUSE_H_ */