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
17 * header. To use the newest API define it to 26 (recommended for any
18 * new application), to use the old API define it to 21 (default) 22
19 * or 25, to use the even older 1.X API define it to 11.
22 #ifndef FUSE_USE_VERSION
23 #define FUSE_USE_VERSION 21
26 #include "fuse_common.h"
31 #include <sys/types.h>
33 #include <sys/statvfs.h>
40 /* ----------------------------------------------------------- *
42 * ----------------------------------------------------------- */
44 /** Handle for a FUSE filesystem */
47 /** Structure containing a raw command */
50 /** Function to add an entry in a readdir() operation
52 * @param buf the buffer passed to the readdir() operation
53 * @param name the file name of the directory entry
54 * @param stat file attributes, can be NULL
55 * @param off offset of the next entry or zero
56 * @return 1 if buffer is full, zero otherwise
58 typedef int (*fuse_fill_dir_t
) (void *buf
, const char *name
,
59 const struct stat
*stbuf
, off_t off
);
61 /* Used by deprecated getdir() method */
62 typedef struct fuse_dirhandle
*fuse_dirh_t
;
63 typedef int (*fuse_dirfil_t
) (fuse_dirh_t h
, const char *name
, int type
,
67 * The file system operations:
69 * Most of these should work very similarly to the well known UNIX
70 * file system operations. A major exception is that instead of
71 * returning an error in 'errno', the operation should return the
72 * negated error value (-errno) directly.
74 * All methods are optional, but some are essential for a useful
75 * filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
76 * releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock,
77 * init and destroy are special purpose methods, without which a full
78 * featured filesystem can still be implemented.
80 * Almost all operations take a path which can be of any length.
82 * Changed in fuse 2.8.0 (regardless of API version)
83 * Previously, paths were limited to a length of PATH_MAX.
85 * See http://fuse.sourceforge.net/wiki/ for more information. There
86 * is also a snapshot of the relevant wiki pages in the doc/ folder.
88 struct fuse_operations
{
89 /** Get file attributes.
91 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
92 * ignored. The 'st_ino' field is ignored except if the 'use_ino'
93 * mount option is given.
95 int (*getattr
) (const char *, struct stat
*);
97 /** Read the target of a symbolic link
99 * The buffer should be filled with a null terminated string. The
100 * buffer size argument includes the space for the terminating
101 * null character. If the linkname is too long to fit in the
102 * buffer, it should be truncated. The return value should be 0
105 int (*readlink
) (const char *, char *, size_t);
107 /* Deprecated, use readdir() instead */
108 int (*getdir
) (const char *, fuse_dirh_t
, fuse_dirfil_t
);
110 /** Create a file node
112 * This is called for creation of all non-directory, non-symlink
113 * nodes. If the filesystem defines a create() method, then for
114 * regular files that will be called instead.
116 int (*mknod
) (const char *, mode_t
, dev_t
);
118 /** Create a directory
120 * Note that the mode argument may not have the type specification
121 * bits set, i.e. S_ISDIR(mode) can be false. To obtain the
122 * correct directory type bits use mode|S_IFDIR
124 int (*mkdir
) (const char *, mode_t
);
127 int (*unlink
) (const char *);
129 /** Remove a directory */
130 int (*rmdir
) (const char *);
132 /** Create a symbolic link */
133 int (*symlink
) (const char *, const char *);
136 int (*rename
) (const char *, const char *);
138 /** Create a hard link to a file */
139 int (*link
) (const char *, const char *);
141 /** Change the permission bits of a file */
142 int (*chmod
) (const char *, mode_t
);
144 /** Change the owner and group of a file */
145 int (*chown
) (const char *, uid_t
, gid_t
);
147 /** Change the size of a file */
148 int (*truncate
) (const char *, off_t
);
150 /** Change the access and/or modification times of a file
152 * Deprecated, use utimens() instead.
154 int (*utime
) (const char *, struct utimbuf
*);
156 /** File open operation
158 * No creation (O_CREAT, O_EXCL) and by default also no
159 * truncation (O_TRUNC) flags will be passed to open(). If an
160 * application specifies O_TRUNC, fuse first calls truncate()
161 * and then open(). Only if 'atomic_o_trunc' has been
162 * specified and kernel version is 2.6.24 or later, O_TRUNC is
165 * Unless the 'default_permissions' mount option is given,
166 * open should check if the operation is permitted for the
167 * given flags. Optionally open may also return an arbitrary
168 * filehandle in the fuse_file_info structure, which will be
169 * passed to all file operations.
171 * Changed in version 2.2
173 int (*open
) (const char *, struct fuse_file_info
*);
175 /** Read data from an open file
177 * Read should return exactly the number of bytes requested except
178 * on EOF or error, otherwise the rest of the data will be
179 * substituted with zeroes. An exception to this is when the
180 * 'direct_io' mount option is specified, in which case the return
181 * value of the read system call will reflect the return value of
184 * Changed in version 2.2
186 int (*read
) (const char *, char *, size_t, off_t
,
187 struct fuse_file_info
*);
189 /** Write data to an open file
191 * Write should return exactly the number of bytes requested
192 * except on error. An exception to this is when the 'direct_io'
193 * mount option is specified (see read operation).
195 * Changed in version 2.2
197 int (*write
) (const char *, const char *, size_t, off_t
,
198 struct fuse_file_info
*);
200 /** Get file system statistics
202 * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
204 * Replaced 'struct statfs' parameter with 'struct statvfs' in
207 int (*statfs
) (const char *, struct statvfs
*);
209 /** Possibly flush cached data
211 * BIG NOTE: This is not equivalent to fsync(). It's not a
212 * request to sync dirty data.
214 * Flush is called on each close() of a file descriptor. So if a
215 * filesystem wants to return write errors in close() and the file
216 * has cached dirty data, this is a good place to write back data
217 * and return any errors. Since many applications ignore close()
218 * errors this is not always useful.
220 * NOTE: The flush() method may be called more than once for each
221 * open(). This happens if more than one file descriptor refers
222 * to an opened file due to dup(), dup2() or fork() calls. It is
223 * not possible to determine if a flush is final, so each flush
224 * should be treated equally. Multiple write-flush sequences are
225 * relatively rare, so this shouldn't be a problem.
227 * Filesystems shouldn't assume that flush will always be called
228 * after some writes, or that if will be called at all.
230 * Changed in version 2.2
232 int (*flush
) (const char *, struct fuse_file_info
*);
234 /** Release an open file
236 * Release is called when there are no more references to an open
237 * file: all file descriptors are closed and all memory mappings
240 * For every open() call there will be exactly one release() call
241 * with the same flags and file descriptor. It is possible to
242 * have a file opened more than once, in which case only the last
243 * release will mean, that no more reads/writes will happen on the
244 * file. The return value of release is ignored.
246 * Changed in version 2.2
248 int (*release
) (const char *, struct fuse_file_info
*);
250 /** Synchronize file contents
252 * If the datasync parameter is non-zero, then only the user data
253 * should be flushed, not the meta data.
255 * Changed in version 2.2
257 int (*fsync
) (const char *, int, struct fuse_file_info
*);
259 /** Set extended attributes */
260 int (*setxattr
) (const char *, const char *, const char *, size_t, int);
262 /** Get extended attributes */
263 int (*getxattr
) (const char *, const char *, char *, size_t);
265 /** List extended attributes */
266 int (*listxattr
) (const char *, char *, size_t);
268 /** Remove extended attributes */
269 int (*removexattr
) (const char *, const char *);
273 * Unless the 'default_permissions' mount option is given,
274 * this method should check if opendir is permitted for this
275 * directory. Optionally opendir may also return an arbitrary
276 * filehandle in the fuse_file_info structure, which will be
277 * passed to readdir, closedir and fsyncdir.
279 * Introduced in version 2.3
281 int (*opendir
) (const char *, struct fuse_file_info
*);
285 * This supersedes the old getdir() interface. New applications
288 * The filesystem may choose between two modes of operation:
290 * 1) The readdir implementation ignores the offset parameter, and
291 * passes zero to the filler function's offset. The filler
292 * function will not return '1' (unless an error happens), so the
293 * whole directory is read in a single readdir operation. This
294 * works just like the old getdir() method.
296 * 2) The readdir implementation keeps track of the offsets of the
297 * directory entries. It uses the offset parameter and always
298 * passes non-zero offset to the filler function. When the buffer
299 * is full (or an error happens) the filler function will return
302 * Introduced in version 2.3
304 int (*readdir
) (const char *, void *, fuse_fill_dir_t
, off_t
,
305 struct fuse_file_info
*);
307 /** Release directory
309 * Introduced in version 2.3
311 int (*releasedir
) (const char *, struct fuse_file_info
*);
313 /** Synchronize directory contents
315 * If the datasync parameter is non-zero, then only the user data
316 * should be flushed, not the meta data
318 * Introduced in version 2.3
320 int (*fsyncdir
) (const char *, int, struct fuse_file_info
*);
323 * Initialize filesystem
325 * The return value will passed in the private_data field of
326 * fuse_context to all file operations and as a parameter to the
329 * Introduced in version 2.3
330 * Changed in version 2.6
332 void *(*init
) (struct fuse_conn_info
*conn
);
335 * Clean up filesystem
337 * Called on filesystem exit.
339 * Introduced in version 2.3
341 void (*destroy
) (void *);
344 * Check file access permissions
346 * This will be called for the access() system call. If the
347 * 'default_permissions' mount option is given, this method is not
350 * This method is not called under Linux kernel versions 2.4.x
352 * Introduced in version 2.5
354 int (*access
) (const char *, int);
357 * Create and open a file
359 * If the file does not exist, first create it with the specified
360 * mode, and then open it.
362 * If this method is not implemented or under Linux kernel
363 * versions earlier than 2.6.15, the mknod() and open() methods
364 * will be called instead.
366 * Introduced in version 2.5
368 int (*create
) (const char *, mode_t
, struct fuse_file_info
*);
371 * Change the size of an open file
373 * This method is called instead of the truncate() method if the
374 * truncation was invoked from an ftruncate() system call.
376 * If this method is not implemented or under Linux kernel
377 * versions earlier than 2.6.15, the truncate() method will be
380 * Introduced in version 2.5
382 int (*ftruncate
) (const char *, off_t
, struct fuse_file_info
*);
385 * Get attributes from an open file
387 * This method is called instead of the getattr() method if the
388 * file information is available.
390 * Currently this is only called after the create() method if that
391 * is implemented (see above). Later it may be called for
392 * invocations of fstat() too.
394 * Introduced in version 2.5
396 int (*fgetattr
) (const char *, struct stat
*, struct fuse_file_info
*);
399 * Perform POSIX file locking operation
401 * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
403 * For the meaning of fields in 'struct flock' see the man page
404 * for fcntl(2). The l_whence field will always be set to
407 * For checking lock ownership, the 'fuse_file_info->owner'
408 * argument must be used.
410 * For F_GETLK operation, the library will first check currently
411 * held locks, and if a conflicting lock is found it will return
412 * information without calling this method. This ensures, that
413 * for local locks the l_pid field is correctly filled in. The
414 * results may not be accurate in case of race conditions and in
415 * the presence of hard links, but it's unlikly that an
416 * application would rely on accurate GETLK results in these
417 * cases. If a conflicting lock is not found, this method will be
418 * called, and the filesystem may fill out l_pid by a meaningful
419 * value, or it may leave this field zero.
421 * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
422 * of the process performing the locking operation.
424 * Note: if this method is not implemented, the kernel will still
425 * allow file locking to work locally. Hence it is only
426 * interesting for network filesystems and similar.
428 * Introduced in version 2.6
430 int (*lock
) (const char *, struct fuse_file_info
*, int cmd
,
434 * Change the access and modification times of a file with
435 * nanosecond resolution
437 * Introduced in version 2.6
439 int (*utimens
) (const char *, const struct timespec tv
[2]);
442 * Map block index within file to block index within device
444 * Note: This makes sense only for block device backed filesystems
445 * mounted with the 'blkdev' option
447 * Introduced in version 2.6
449 int (*bmap
) (const char *, size_t blocksize
, uint64_t *idx
);
452 * Flag indicating that the filesystem can accept a NULL path
453 * as the first argument for the following operations:
455 * read, write, flush, release, fsync, readdir, releasedir,
456 * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll
458 * If this flag is set these operations continue to work on
459 * unlinked files even if "-ohard_remove" option was specified.
461 unsigned int flag_nullpath_ok
:1;
464 * Flag indicating that the path need not be calculated for
465 * the following operations:
467 * read, write, flush, release, fsync, readdir, releasedir,
468 * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll
470 * Closely related to flag_nullpath_ok, but if this flag is
471 * set then the path will not be calculaged even if the file
472 * wasn't unlinked. However the path can still be non-NULL if
473 * it needs to be calculated for some other reason.
475 unsigned int flag_nopath
:1;
478 * Reserved flags, don't set
480 unsigned int flag_reserved
:30;
485 * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in
486 * 64bit environment. The size and direction of data is
487 * determined by _IOC_*() decoding of cmd. For _IOC_NONE,
488 * data will be NULL, for _IOC_WRITE data is out area, for
489 * _IOC_READ in area and if both are set in/out area. In all
490 * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes.
492 * Introduced in version 2.8
494 int (*ioctl
) (const char *, int cmd
, void *arg
,
495 struct fuse_file_info
*, unsigned int flags
, void *data
);
498 * Poll for IO readiness events
500 * Note: If ph is non-NULL, the client should notify
501 * when IO readiness events occur by calling
502 * fuse_notify_poll() with the specified ph.
504 * Regardless of the number of times poll with a non-NULL ph
505 * is received, single notification is enough to clear all.
506 * Notifying more times incurs overhead but doesn't harm
509 * The callee is responsible for destroying ph with
510 * fuse_pollhandle_destroy() when no longer in use.
512 * Introduced in version 2.8
514 int (*poll
) (const char *, struct fuse_file_info
*,
515 struct fuse_pollhandle
*ph
, unsigned *reventsp
);
517 /** Write contents of buffer to an open file
519 * Similar to the write() method, but data is supplied in a
520 * generic buffer. Use fuse_buf_copy() to transfer data to
523 * Introduced in version 2.9
525 int (*write_buf
) (const char *, struct fuse_bufvec
*buf
, off_t off
,
526 struct fuse_file_info
*);
529 /** Extra context that may be needed by some filesystems
531 * The uid, gid and pid fields are not filled in case of a writepage
534 struct fuse_context
{
535 /** Pointer to the fuse object */
538 /** User ID of the calling process */
541 /** Group ID of the calling process */
544 /** Thread ID of the calling process */
547 /** Private filesystem data */
550 /** Umask of the calling process (introduced in version 2.8) */
555 * Main function of FUSE.
557 * This is for the lazy. This is all that has to be called from the
560 * This function does the following:
561 * - parses command line options (-d -s and -h)
562 * - passes relevant mount options to the fuse_mount()
563 * - installs signal handlers for INT, HUP, TERM and PIPE
564 * - registers an exit handler to unmount the filesystem on program exit
565 * - creates a fuse handle
566 * - registers the operations
567 * - calls either the single-threaded or the multi-threaded event loop
569 * Note: this is currently implemented as a macro.
571 * @param argc the argument counter passed to the main() function
572 * @param argv the argument vector passed to the main() function
573 * @param op the file system operation
574 * @param user_data user data supplied in the context during the init() method
575 * @return 0 on success, nonzero on failure
578 int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
581 #define fuse_main(argc, argv, op, user_data) \
582 fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
584 /* ----------------------------------------------------------- *
585 * More detailed API *
586 * ----------------------------------------------------------- */
589 * Create a new FUSE filesystem.
591 * @param ch the communication channel
592 * @param args argument vector
593 * @param op the filesystem operations
594 * @param op_size the size of the fuse_operations structure
595 * @param user_data user data supplied in the context during the init() method
596 * @return the created FUSE handle
598 struct fuse
*fuse_new(struct fuse_chan
*ch
, struct fuse_args
*args
,
599 const struct fuse_operations
*op
, size_t op_size
,
603 * Destroy the FUSE handle.
605 * The communication channel attached to the handle is also destroyed.
607 * NOTE: This function does not unmount the filesystem. If this is
608 * needed, call fuse_unmount() before calling this function.
610 * @param f the FUSE handle
612 void fuse_destroy(struct fuse
*f
);
617 * Requests from the kernel are processed, and the appropriate
618 * operations are called.
620 * @param f the FUSE handle
621 * @return 0 if no error occurred, -1 otherwise
623 int fuse_loop(struct fuse
*f
);
626 * Exit from event loop
628 * @param f the FUSE handle
630 void fuse_exit(struct fuse
*f
);
633 * FUSE event loop with multiple threads
635 * Requests from the kernel are processed, and the appropriate
636 * operations are called. Request are processed in parallel by
637 * distributing them between multiple threads.
639 * Calling this function requires the pthreads library to be linked to
642 * @param f the FUSE handle
643 * @return 0 if no error occurred, -1 otherwise
645 int fuse_loop_mt(struct fuse
*f
);
648 * Get the current context
650 * The context is only valid for the duration of a filesystem
651 * operation, and thus must not be stored and used later.
653 * @return the context
655 struct fuse_context
*fuse_get_context(void);
658 * Get the current supplementary group IDs for the current request
660 * Similar to the getgroups(2) system call, except the return value is
661 * always the total number of group IDs, even if it is larger than the
664 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
665 * the group list to userspace, hence this function needs to parse
666 * "/proc/$TID/task/$TID/status" to get the group IDs.
668 * This feature may not be supported on all operating systems. In
669 * such a case this function will return -ENOSYS.
671 * @param size size of given array
672 * @param list array of group IDs to be filled in
673 * @return the total number of supplementary group IDs or -errno on failure
675 int fuse_getgroups(int size
, gid_t list
[]);
678 * Check if the current request has already been interrupted
680 * @return 1 if the request has been interrupted, 0 otherwise
682 int fuse_interrupted(void);
685 * Obsolete, doesn't do anything
689 int fuse_invalidate(struct fuse
*f
, const char *path
);
691 /* Deprecated, don't use */
692 int fuse_is_lib_option(const char *opt
);
695 * The real main function
697 * Do not call this directly, use fuse_main()
699 int fuse_main_real(int argc
, char *argv
[], const struct fuse_operations
*op
,
700 size_t op_size
, void *user_data
);
707 * Fuse filesystem object
709 * This is opaque object represents a filesystem layer
714 * These functions call the relevant filesystem operation, and return
717 * If the operation is not defined, they return -ENOSYS, with the
718 * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
719 * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
722 int fuse_fs_getattr(struct fuse_fs
*fs
, const char *path
, struct stat
*buf
);
723 int fuse_fs_fgetattr(struct fuse_fs
*fs
, const char *path
, struct stat
*buf
,
724 struct fuse_file_info
*fi
);
725 int fuse_fs_rename(struct fuse_fs
*fs
, const char *oldpath
,
726 const char *newpath
);
727 int fuse_fs_unlink(struct fuse_fs
*fs
, const char *path
);
728 int fuse_fs_rmdir(struct fuse_fs
*fs
, const char *path
);
729 int fuse_fs_symlink(struct fuse_fs
*fs
, const char *linkname
,
731 int fuse_fs_link(struct fuse_fs
*fs
, const char *oldpath
, const char *newpath
);
732 int fuse_fs_release(struct fuse_fs
*fs
, const char *path
,
733 struct fuse_file_info
*fi
);
734 int fuse_fs_open(struct fuse_fs
*fs
, const char *path
,
735 struct fuse_file_info
*fi
);
736 int fuse_fs_read(struct fuse_fs
*fs
, const char *path
, char *buf
, size_t size
,
737 off_t off
, struct fuse_file_info
*fi
);
738 int fuse_fs_write(struct fuse_fs
*fs
, const char *path
, const char *buf
,
739 size_t size
, off_t off
, struct fuse_file_info
*fi
);
740 int fuse_fs_write_buf(struct fuse_fs
*fs
, const char *path
,
741 struct fuse_bufvec
*buf
, off_t off
,
742 struct fuse_file_info
*fi
);
743 int fuse_fs_fsync(struct fuse_fs
*fs
, const char *path
, int datasync
,
744 struct fuse_file_info
*fi
);
745 int fuse_fs_flush(struct fuse_fs
*fs
, const char *path
,
746 struct fuse_file_info
*fi
);
747 int fuse_fs_statfs(struct fuse_fs
*fs
, const char *path
, struct statvfs
*buf
);
748 int fuse_fs_opendir(struct fuse_fs
*fs
, const char *path
,
749 struct fuse_file_info
*fi
);
750 int fuse_fs_readdir(struct fuse_fs
*fs
, const char *path
, void *buf
,
751 fuse_fill_dir_t filler
, off_t off
,
752 struct fuse_file_info
*fi
);
753 int fuse_fs_fsyncdir(struct fuse_fs
*fs
, const char *path
, int datasync
,
754 struct fuse_file_info
*fi
);
755 int fuse_fs_releasedir(struct fuse_fs
*fs
, const char *path
,
756 struct fuse_file_info
*fi
);
757 int fuse_fs_create(struct fuse_fs
*fs
, const char *path
, mode_t mode
,
758 struct fuse_file_info
*fi
);
759 int fuse_fs_lock(struct fuse_fs
*fs
, const char *path
,
760 struct fuse_file_info
*fi
, int cmd
, struct flock
*lock
);
761 int fuse_fs_chmod(struct fuse_fs
*fs
, const char *path
, mode_t mode
);
762 int fuse_fs_chown(struct fuse_fs
*fs
, const char *path
, uid_t uid
, gid_t gid
);
763 int fuse_fs_truncate(struct fuse_fs
*fs
, const char *path
, off_t size
);
764 int fuse_fs_ftruncate(struct fuse_fs
*fs
, const char *path
, off_t size
,
765 struct fuse_file_info
*fi
);
766 int fuse_fs_utimens(struct fuse_fs
*fs
, const char *path
,
767 const struct timespec tv
[2]);
768 int fuse_fs_access(struct fuse_fs
*fs
, const char *path
, int mask
);
769 int fuse_fs_readlink(struct fuse_fs
*fs
, const char *path
, char *buf
,
771 int fuse_fs_mknod(struct fuse_fs
*fs
, const char *path
, mode_t mode
,
773 int fuse_fs_mkdir(struct fuse_fs
*fs
, const char *path
, mode_t mode
);
774 int fuse_fs_setxattr(struct fuse_fs
*fs
, const char *path
, const char *name
,
775 const char *value
, size_t size
, int flags
);
776 int fuse_fs_getxattr(struct fuse_fs
*fs
, const char *path
, const char *name
,
777 char *value
, size_t size
);
778 int fuse_fs_listxattr(struct fuse_fs
*fs
, const char *path
, char *list
,
780 int fuse_fs_removexattr(struct fuse_fs
*fs
, const char *path
,
782 int fuse_fs_bmap(struct fuse_fs
*fs
, const char *path
, size_t blocksize
,
784 int fuse_fs_ioctl(struct fuse_fs
*fs
, const char *path
, int cmd
, void *arg
,
785 struct fuse_file_info
*fi
, unsigned int flags
, void *data
);
786 int fuse_fs_poll(struct fuse_fs
*fs
, const char *path
,
787 struct fuse_file_info
*fi
, struct fuse_pollhandle
*ph
,
789 void fuse_fs_init(struct fuse_fs
*fs
, struct fuse_conn_info
*conn
);
790 void fuse_fs_destroy(struct fuse_fs
*fs
);
792 int fuse_notify_poll(struct fuse_pollhandle
*ph
);
795 * Create a new fuse filesystem object
797 * This is usually called from the factory of a fuse module to create
798 * a new instance of a filesystem.
800 * @param op the filesystem operations
801 * @param op_size the size of the fuse_operations structure
802 * @param user_data user data supplied in the context during the init() method
803 * @return a new filesystem object
805 struct fuse_fs
*fuse_fs_new(const struct fuse_operations
*op
, size_t op_size
,
811 * Filesystem modules are registered with the FUSE_REGISTER_MODULE()
814 * If the "-omodules=modname:..." option is present, filesystem
815 * objects are created and pushed onto the stack with the 'factory'
825 * Factory for creating filesystem objects
827 * The function may use and remove options from 'args' that belong
830 * For now the 'fs' vector always contains exactly one filesystem.
831 * This is the filesystem which will be below the newly created
832 * filesystem in the stack.
834 * @param args the command line arguments
835 * @param fs NULL terminated filesystem object vector
836 * @return the new filesystem object
838 struct fuse_fs
*(*factory
)(struct fuse_args
*args
,
839 struct fuse_fs
*fs
[]);
841 struct fuse_module
*next
;
842 struct fusemod_so
*so
;
847 * Register a filesystem module
849 * This function is used by FUSE_REGISTER_MODULE and there's usually
850 * no need to call it directly
852 void fuse_register_module(struct fuse_module
*mod
);
855 * Register filesystem module
857 * For the parameters, see description of the fields in 'struct
860 #define FUSE_REGISTER_MODULE(name_, factory_) \
861 static __attribute__((constructor)) void name_ ## _register(void) \
863 static struct fuse_module mod = \
864 { #name_, factory_, NULL, NULL, 0 }; \
865 fuse_register_module(&mod); \
869 /* ----------------------------------------------------------- *
870 * Advanced API for event handling, don't worry about this... *
871 * ----------------------------------------------------------- */
873 /* NOTE: the following functions are deprecated, and will be removed
874 from the 3.0 API. Use the lowlevel session functions instead */
876 /** Function type used to process commands */
877 typedef void (*fuse_processor_t
)(struct fuse
*, struct fuse_cmd
*, void *);
879 /** This is the part of fuse_main() before the event loop */
880 struct fuse
*fuse_setup(int argc
, char *argv
[],
881 const struct fuse_operations
*op
, size_t op_size
,
882 char **mountpoint
, int *multithreaded
,
885 /** This is the part of fuse_main() after the event loop */
886 void fuse_teardown(struct fuse
*fuse
, char *mountpoint
);
888 /** Read a single command. If none are read, return NULL */
889 struct fuse_cmd
*fuse_read_cmd(struct fuse
*f
);
891 /** Process a single command */
892 void fuse_process_cmd(struct fuse
*f
, struct fuse_cmd
*cmd
);
894 /** Multi threaded event loop, which calls the custom command
895 processor function */
896 int fuse_loop_mt_proc(struct fuse
*f
, fuse_processor_t proc
, void *data
);
898 /** Return the exited flag, which indicates if fuse_exit() has been
900 int fuse_exited(struct fuse
*f
);
902 /** This function is obsolete and implemented as a no-op */
903 void fuse_set_getcontext_func(struct fuse_context
*(*func
)(void));
905 /** Get session from fuse object */
906 struct fuse_session
*fuse_get_session(struct fuse
*f
);
908 /* ----------------------------------------------------------- *
909 * Compatibility stuff *
910 * ----------------------------------------------------------- */
912 #if FUSE_USE_VERSION < 26
913 # include "fuse_compat.h"
915 # if FUSE_USE_VERSION == 25
916 # define fuse_main(argc, argv, op) \
917 fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
918 # define fuse_new fuse_new_compat25
919 # define fuse_setup fuse_setup_compat25
920 # define fuse_teardown fuse_teardown_compat22
921 # define fuse_operations fuse_operations_compat25
922 # elif FUSE_USE_VERSION == 22
923 # define fuse_main(argc, argv, op) \
924 fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
925 # define fuse_new fuse_new_compat22
926 # define fuse_setup fuse_setup_compat22
927 # define fuse_teardown fuse_teardown_compat22
928 # define fuse_operations fuse_operations_compat22
929 # define fuse_file_info fuse_file_info_compat
930 # elif FUSE_USE_VERSION == 24
931 # error Compatibility with high-level API version 24 not supported
933 # define fuse_dirfil_t fuse_dirfil_t_compat
934 # define __fuse_read_cmd fuse_read_cmd
935 # define __fuse_process_cmd fuse_process_cmd
936 # define __fuse_loop_mt fuse_loop_mt_proc
937 # if FUSE_USE_VERSION == 21
938 # define fuse_operations fuse_operations_compat2
939 # define fuse_main fuse_main_compat2
940 # define fuse_new fuse_new_compat2
941 # define __fuse_setup fuse_setup_compat2
942 # define __fuse_teardown fuse_teardown_compat22
943 # define __fuse_exited fuse_exited
944 # define __fuse_set_getcontext_func fuse_set_getcontext_func
946 # define fuse_statfs fuse_statfs_compat1
947 # define fuse_operations fuse_operations_compat1
948 # define fuse_main fuse_main_compat1
949 # define fuse_new fuse_new_compat1
950 # define FUSE_DEBUG FUSE_DEBUG_COMPAT1
959 #endif /* _FUSE_H_ */