diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/fuse.h | 234 | ||||
-rw-r--r-- | include/fuse_common.h | 117 | ||||
-rw-r--r-- | include/fuse_compat.h | 64 | ||||
-rw-r--r-- | include/fuse_opt.h | 227 |
4 files changed, 553 insertions, 89 deletions
diff --git a/include/fuse.h b/include/fuse.h index fb1c2d6df..eb41c75ec 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -1,6 +1,6 @@ /* FUSE: Filesystem in Userspace - Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu> + Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> This program can be distributed under the terms of the GNU LGPL. See the file COPYING.LIB. @@ -12,28 +12,19 @@ /* This file defines the library interface of FUSE */ /* IMPORTANT: you should define FUSE_USE_VERSION before including this - header. To use the new API define it to 22 (recommended for any - new application), to use the old API define it to 21 (this is the - default), to use the even older 1.X API define it to 11. */ + header. To use the newest API define it to 25 (recommended for any + new application), to use the old API define it to 21 (default) or + 22, to use the even older 1.X API define it to 11. */ #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 21 #endif -/** Major version of FUSE library interface */ -#define FUSE_MAJOR_VERSION 2 - -/** Minor version of FUSE library interface */ -#define FUSE_MINOR_VERSION 3 - -/* This interface uses 64 bit off_t */ -#if _FILE_OFFSET_BITS != 64 -#error Please add -D_FILE_OFFSET_BITS=64 to your compile flags! -#endif +#include "fuse_common.h" #include <sys/types.h> #include <sys/stat.h> -#include <sys/statfs.h> +#include <sys/statvfs.h> #include <utime.h> #ifdef __cplusplus @@ -47,6 +38,9 @@ extern "C" { /** Handle for a FUSE filesystem */ struct fuse; +/** Structure containing a raw command */ +struct fuse_cmd; + /** Function to add an entry in a readdir() operation * * @param buf the buffer passed to the readdir() operation @@ -56,27 +50,13 @@ struct fuse; * @return 1 if buffer is full, zero otherwise */ typedef int (*fuse_fill_dir_t) (void *buf, const char *name, - const struct stat *stat, off_t off); + const struct stat *stbuf, off_t off); /* Used by deprecated getdir() method */ typedef struct fuse_dirhandle *fuse_dirh_t; typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type, ino_t ino); -/** Information about open files */ -struct fuse_file_info { - /** Open flags. Available in open() and release() */ - int flags; - - /** File handle. May be filled in by filesystem in open(). - Available in all other file operations */ - unsigned long fh; - - /** In case of a write operation indicates if this was caused by a - writepage */ - int writepage; -}; - /** * The file system operations: * @@ -86,10 +66,10 @@ struct fuse_file_info { * negated error value (-errno) directly. * * All methods are optional, but some are essential for a useful - * filesystem (e.g. getattr). Flush, release, fsync, opendir, - * releasedir, fsyncdir, init and destroy are special purpose - * methods, without which a full featured filesystem can still be - * implemented. + * filesystem (e.g. getattr). Open, flush, release, fsync, opendir, + * releasedir, fsyncdir, access, create, ftruncate, fgetattr, init and + * destroy are special purpose methods, without which a full featured + * filesystem can still be implemented. */ struct fuse_operations { /** Get file attributes. @@ -152,11 +132,13 @@ struct fuse_operations { /** File open operation * - * No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) + * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC) * will be passed to open(). Open should check if the operation * is permitted for the given flags. Optionally open may also - * return an arbitary filehandle in the fuse_file_info structure, + * return an arbitrary filehandle in the fuse_file_info structure, * which will be passed to all file operations. + * + * Changed in version 2.2 */ int (*open) (const char *, struct fuse_file_info *); @@ -168,6 +150,8 @@ struct fuse_operations { * 'direct_io' mount option is specified, in which case the return * value of the read system call will reflect the return value of * this operation. + * + * Changed in version 2.2 */ int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *); @@ -176,15 +160,21 @@ struct fuse_operations { * Write should return exactly the number of bytes requested * except on error. An exception to this is when the 'direct_io' * mount option is specified (see read operation). + * + * Changed in version 2.2 */ int (*write) (const char *, const char *, size_t, off_t, struct fuse_file_info *); + /** Just a placeholder, don't set */ /** Get file system statistics * - * The 'f_type' and 'f_fsid' fields are ignored + * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored + * + * Replaced 'struct statfs' parameter with 'struct statvfs' in + * version 2.5 */ - int (*statfs) (const char *, struct statfs *); + int (*statfs) (const char *, struct statvfs *); /** Possibly flush cached data * @@ -203,6 +193,11 @@ struct fuse_operations { * not possible to determine if a flush is final, so each flush * should be treated equally. Multiple write-flush sequences are * relatively rare, so this shouldn't be a problem. + * + * Filesystems shouldn't assume that flush will always be called + * after some writes, or that if will be called at all. + * + * Changed in version 2.2 */ int (*flush) (const char *, struct fuse_file_info *); @@ -217,6 +212,8 @@ struct fuse_operations { * have a file opened more than once, in which case only the last * release will mean, that no more reads/writes will happen on the * file. The return value of release is ignored. + * + * Changed in version 2.2 */ int (*release) (const char *, struct fuse_file_info *); @@ -224,6 +221,8 @@ struct fuse_operations { * * If the datasync parameter is non-zero, then only the user data * should be flushed, not the meta data. + * + * Changed in version 2.2 */ int (*fsync) (const char *, int, struct fuse_file_info *); @@ -239,10 +238,12 @@ struct fuse_operations { /** Remove extended attributes */ int (*removexattr) (const char *, const char *); - /** Open direcory + /** Open directory * * This method should check if the open operation is permitted for * this directory + * + * Introduced in version 2.3 */ int (*opendir) (const char *, struct fuse_file_info *); @@ -264,17 +265,24 @@ struct fuse_operations { * passes non-zero offset to the filler function. When the buffer * is full (or an error happens) the filler function will return * '1'. + * + * Introduced in version 2.3 */ int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *); - /** Release directory */ + /** Release directory + * + * Introduced in version 2.3 + */ int (*releasedir) (const char *, struct fuse_file_info *); /** Synchronize directory contents * * If the datasync parameter is non-zero, then only the user data * should be flushed, not the meta data + * + * Introduced in version 2.3 */ int (*fsyncdir) (const char *, int, struct fuse_file_info *); @@ -284,6 +292,8 @@ struct fuse_operations { * The return value will passed in the private_data field of * fuse_context to all file operations and as a parameter to the * destroy() method. + * + * Introduced in version 2.3 */ void *(*init) (void); @@ -291,8 +301,65 @@ struct fuse_operations { * Clean up filesystem * * Called on filesystem exit. + * + * Introduced in version 2.3 */ void (*destroy) (void *); + + /** + * Check file access permissions + * + * This will be called for the access() system call. If the + * 'default_permissions' mount option is given, this method is not + * called. + * + * This method is not called under Linux kernel versions 2.4.x + * + * Introduced in version 2.5 + */ + int (*access) (const char *, int); + + /** + * Create and open a file + * + * If the file does not exist, first create it with the specified + * mode, and then open it. + * + * If this method is not implemented or under Linux kernel + * versions earlier than 2.6.15, the mknod() and open() methods + * will be called instead. + * + * Introduced in version 2.5 + */ + int (*create) (const char *, mode_t, struct fuse_file_info *); + + /** + * Change the size of an open file + * + * This method is called instead of the truncate() method if the + * truncation was invoked from an ftruncate() system call. + * + * If this method is not implemented or under Linux kernel + * versions earlier than 2.6.15, the truncate() method will be + * called instead. + * + * Introduced in version 2.5 + */ + int (*ftruncate) (const char *, off_t, struct fuse_file_info *); + + /** + * Get attributes from an open file + * + * This method is called instead of the getattr() method if the + * file information is available. + * + * Currently this is only called after the create() method if that + * is implemented (see above). Later it may be called for + * invocations of fstat() too. + * + * Introduced in version 2.5 + */ + int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *); }; /** Extra context that may be needed by some filesystems @@ -349,35 +416,16 @@ int fuse_main(int argc, char *argv[], const struct fuse_operations *op); * More detailed API * * ----------------------------------------------------------- */ -/* - * Create a FUSE mountpoint - * - * Returns a control file descriptor suitable for passing to - * fuse_new() - * - * @param mountpoint the mount point path - * @param opts a comma separated list of mount options. Can be NULL. - * @return the control file descriptor on success, -1 on failure - */ -int fuse_mount(const char *mountpoint, const char *opts); - -/* - * Umount a FUSE mountpoint - * - * @param mountpoint the mount point path - */ -void fuse_unmount(const char *mountpoint); - /** * Create a new FUSE filesystem. * * @param fd the control file descriptor - * @param opts mount options to be used by the library + * @param args argument vector * @param op the operations * @param op_size the size of the fuse_operations structure * @return the created FUSE handle */ -struct fuse *fuse_new(int fd, const char *opts, +struct fuse *fuse_new(int fd, struct fuse_args *args, const struct fuse_operations *op, size_t op_size); /** @@ -392,11 +440,11 @@ void fuse_destroy(struct fuse *f); /** * FUSE event loop. * - * Requests from the kernel are processed, and the apropriate + * Requests from the kernel are processed, and the appropriate * operations are called. * * @param f the FUSE handle - * @return 0 if no error occured, -1 otherwise + * @return 0 if no error occurred, -1 otherwise */ int fuse_loop(struct fuse *f); @@ -410,7 +458,7 @@ void fuse_exit(struct fuse *f); /** * FUSE event loop with multiple threads * - * Requests from the kernel are processed, and the apropriate + * Requests from the kernel are processed, and the appropriate * operations are called. Request are processed in parallel by * distributing them between multiple threads. * @@ -418,7 +466,7 @@ void fuse_exit(struct fuse *f); * the application. * * @param f the FUSE handle - * @return 0 if no error occured, -1 otherwise + * @return 0 if no error occurred, -1 otherwise */ int fuse_loop_mt(struct fuse *f); @@ -434,22 +482,13 @@ int fuse_loop_mt(struct fuse *f); struct fuse_context *fuse_get_context(void); /** - * Invalidate cached data of a file. - * - * Useful if the 'kernel_cache' mount option is given, since in that - * case the cache is not invalidated on file open. + * Obsolete, doesn't do anything * - * @return 0 on success or -errno on failure + * @return -EINVAL */ int fuse_invalidate(struct fuse *f, const char *path); -/** - * Check whether a mount option should be passed to the kernel or the - * library - * - * @param opt the option to check - * @return 1 if it is a library option, 0 otherwise - */ +/* Deprecated, don't use */ int fuse_is_lib_option(const char *opt); /** @@ -464,9 +503,6 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, * Advanced API for event handling, don't worry about this... * * ----------------------------------------------------------- */ -/** Structure containing a raw command */ -struct fuse_cmd; - /** Function type used to process commands */ typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *); @@ -490,7 +526,7 @@ int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data); /** Return the exited flag, which indicates if fuse_exit() has been called */ -int fuse_exited(struct fuse* f); +int fuse_exited(struct fuse *f); /** Set function which can be used to get the current context */ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); @@ -499,17 +535,27 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); * Compatibility stuff * * ----------------------------------------------------------- */ -#if FUSE_USE_VERSION == 21 || FUSE_USE_VERSION == 11 +#ifndef __FreeBSD__ + +#if FUSE_USE_VERSION == 22 || FUSE_USE_VERSION == 21 || FUSE_USE_VERSION == 11 # include "fuse_compat.h" +# undef FUSE_MINOR_VERSION +# undef fuse_main +# if FUSE_USE_VERSION == 22 +# define FUSE_MINOR_VERSION 4 +# define fuse_main(argc, argv, op) \ + fuse_main_real_compat22(argc, argv, op, sizeof(*(op))) +# define fuse_new fuse_new_compat22 +# define fuse_setup fuse_setup_compat22 +# define fuse_operations fuse_operations_compat22 +# define fuse_file_info fuse_file_info_compat22 +# define fuse_mount fuse_mount_compat22 +# else # define fuse_dirfil_t fuse_dirfil_t_compat # define __fuse_read_cmd fuse_read_cmd # define __fuse_process_cmd fuse_process_cmd # define __fuse_loop_mt fuse_loop_mt_proc -# undef fuse_main -# undef FUSE_MINOR_VERSION -# undef FUSE_MAJOR_VERSION # if FUSE_USE_VERSION == 21 -# define FUSE_MAJOR_VERSION 2 # define FUSE_MINOR_VERSION 1 # define fuse_operations fuse_operations_compat2 # define fuse_main fuse_main_compat2 @@ -518,7 +564,10 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); # define __fuse_teardown fuse_teardown # define __fuse_exited fuse_exited # define __fuse_set_getcontext_func fuse_set_getcontext_func +# define fuse_mount fuse_mount_compat22 # else +# warning Compatibility with API version 11 is deprecated +# undef FUSE_MAJOR_VERSION # define FUSE_MAJOR_VERSION 1 # define FUSE_MINOR_VERSION 1 # define fuse_statfs fuse_statfs_compat1 @@ -528,10 +577,19 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); # define fuse_mount fuse_mount_compat1 # define FUSE_DEBUG FUSE_DEBUG_COMPAT1 # endif -#elif FUSE_USE_VERSION < 22 -# error Compatibility with API version other than 21 and 11 not supported +# endif +#elif FUSE_USE_VERSION < 25 +# error Compatibility with API version other than 21, 22 and 11 not supported #endif +#else /* __FreeBSD__ */ + +#if FUSE_USE_VERSION < 25 +# error On FreeBSD API version 25 or greater must be used +#endif + +#endif /* __FreeBSD__ */ + #ifdef __cplusplus } #endif diff --git a/include/fuse_common.h b/include/fuse_common.h new file mode 100644 index 000000000..0f35ea62b --- /dev/null +++ b/include/fuse_common.h @@ -0,0 +1,117 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> + + This program can be distributed under the terms of the GNU LGPL. + See the file COPYING.LIB. +*/ + +#if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_) +#error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h instead." +#endif + +#ifndef _FUSE_COMMON_H_ +#define _FUSE_COMMON_H_ + +#include "fuse_opt.h" +#include <stdint.h> + +/** Major version of FUSE library interface */ +#define FUSE_MAJOR_VERSION 2 + +/** Minor version of FUSE library interface */ +#define FUSE_MINOR_VERSION 5 + +#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min)) +#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION) + +/* This interface uses 64 bit off_t */ +#if _FILE_OFFSET_BITS != 64 +#error Please add -D_FILE_OFFSET_BITS=64 to your compile flags! +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Information about open files + * + * Changed in version 2.5 + */ +struct fuse_file_info { + /** Open flags. Available in open() and release() */ + int flags; + + /** Old file handle, don't use */ + unsigned long fh_old; + + /** In case of a write operation indicates if this was caused by a + writepage */ + int writepage; + + /** Can be filled in by open, to use direct I/O on this file. + Introduced in version 2.4 */ + unsigned int direct_io : 1; + + /** Can be filled in by open, to indicate, that cached file data + need not be invalidated. Introduced in version 2.4 */ + unsigned int keep_cache : 1; + + /** Padding. Do not use*/ + unsigned int padding : 30; + + /** File handle. May be filled in by filesystem in open(). + Available in all other file operations */ + uint64_t fh; +}; + +/** + * Create a FUSE mountpoint + * + * Returns a control file descriptor suitable for passing to + * fuse_new() + * + * @param mountpoint the mount point path + * @param args argument vector + * @return the control file descriptor on success, -1 on failure + */ +int fuse_mount(const char *mountpoint, struct fuse_args *args); + +/** + * Umount a FUSE mountpoint + * + * @param mountpoint the mount point path + */ +void fuse_unmount(const char *mountpoint); + +/** + * Parse common options + * + * The following options are parsed: + * + * '-f' foreground + * '-d' '-odebug' foreground, but keep the debug option + * '-s' single threaded + * '-h' '--help' help + * '-ho' help without header + * '-ofsname=..' file system name, if not present, then set to the program + * name + * + * All parameters may be NULL + * + * @param args argument vector + * @param mountpoint the returned mountpoint, should be freed after use + * @param multithreaded set to 1 unless the '-s' option is present + * @param foreground set to 1 if one of the relevant options is present + * @return 0 on success, -1 on failure + */ +int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint, + int *multithreaded, int *foreground); + + +#ifdef __cplusplus +} +#endif + +#endif /* _FUSE_COMMON_H_ */ diff --git a/include/fuse_compat.h b/include/fuse_compat.h index af7aecf7d..220ef0752 100644 --- a/include/fuse_compat.h +++ b/include/fuse_compat.h @@ -1,6 +1,6 @@ /* FUSE: Filesystem in Userspace - Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu> + Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> This program can be distributed under the terms of the GNU LGPL. See the file COPYING.LIB. @@ -9,6 +9,68 @@ /* these definitions provide source compatibility to prior versions. Do not include this file directly! */ +#include <sys/statfs.h> + +struct fuse_file_info_compat22 { + int flags; + unsigned long fh; + int writepage; + unsigned int direct_io : 1; + unsigned int keep_cache : 1; +}; + +struct fuse_operations_compat22 { + int (*getattr) (const char *, struct stat *); + int (*readlink) (const char *, char *, size_t); + int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t); + int (*mknod) (const char *, mode_t, dev_t); + int (*mkdir) (const char *, mode_t); + int (*unlink) (const char *); + int (*rmdir) (const char *); + int (*symlink) (const char *, const char *); + int (*rename) (const char *, const char *); + int (*link) (const char *, const char *); + int (*chmod) (const char *, mode_t); + int (*chown) (const char *, uid_t, gid_t); + int (*truncate) (const char *, off_t); + int (*utime) (const char *, struct utimbuf *); + int (*open) (const char *, struct fuse_file_info_compat22 *); + int (*read) (const char *, char *, size_t, off_t, + struct fuse_file_info_compat22 *); + int (*write) (const char *, const char *, size_t, off_t, + struct fuse_file_info_compat22 *); + int (*statfs) (const char *, struct statfs *); + int (*flush) (const char *, struct fuse_file_info_compat22 *); + int (*release) (const char *, struct fuse_file_info_compat22 *); + int (*fsync) (const char *, int, struct fuse_file_info_compat22 *); + int (*setxattr) (const char *, const char *, const char *, size_t, int); + int (*getxattr) (const char *, const char *, char *, size_t); + int (*listxattr) (const char *, char *, size_t); + int (*removexattr) (const char *, const char *); + int (*opendir) (const char *, struct fuse_file_info_compat22 *); + int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, + struct fuse_file_info_compat22 *); + int (*releasedir) (const char *, struct fuse_file_info_compat22 *); + int (*fsyncdir) (const char *, int, struct fuse_file_info_compat22 *); + void *(*init) (void); + void (*destroy) (void *); +}; + +struct fuse *fuse_new_compat22(int fd, const char *opts, + const struct fuse_operations_compat22 *op, + size_t op_size); + +struct fuse *fuse_setup_compat22(int argc, char *argv[], + const struct fuse_operations_compat22 *op, + size_t op_size, char **mountpoint, + int *multithreaded, int *fd); + +int fuse_main_real_compat22(int argc, char *argv[], + const struct fuse_operations_compat22 *op, + size_t op_size); + +int fuse_mount_compat22(const char *mountpoint, const char *opts); + typedef int (*fuse_dirfil_t_compat) (fuse_dirh_t h, const char *name, int type); struct fuse_operations_compat2 { int (*getattr) (const char *, struct stat *); diff --git a/include/fuse_opt.h b/include/fuse_opt.h new file mode 100644 index 000000000..2988902f2 --- /dev/null +++ b/include/fuse_opt.h @@ -0,0 +1,227 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> + + This program can be distributed under the terms of the GNU GPL. + See the file COPYING. +*/ + +#ifndef _FUSE_OPT_H_ +#define _FUSE_OPT_H_ + +/* This file defines the option parsing interface of FUSE */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Option description + * + * This structure describes a single option, and and action associated + * with it, in case it matches. + * + * More than one such match may occur, in which case the action for + * each match is executed. + * + * There are three possible actions in case of a match: + * + * i) An integer (int or unsigned) variable determined by 'offset' is + * set to 'value' + * + * ii) The processing function is called, with 'value' as the key + * + * iii) An integer (any) or string (char *) variable determined by + * 'offset' is set to the value of an option parameter + * + * 'offset' should normally be either set to + * + * - 'offsetof(struct foo, member)' actions i) and iii) + * + * - -1 action ii) + * + * The 'offsetof()' macro is defined in the <stddef.h> header. + * + * The template determines which options match, and also have an + * effect on the action. Normally the action is either i) or ii), but + * if a format is present in the template, then action iii) is + * performed. + * + * The types of templates are: + * + * 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only + * themselves. Invalid values are "--" and anything beginning + * with "-o" + * + * 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or + * the relevant option in a comma separated option list + * + * 3) "bar=", "--foo=", etc. These are variations of 1) and 2) + * which have a parameter + * + * 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform + * action iii). + * + * 5) "-x ", etc. Matches either "-xparam" or "-x param" as + * two separate arguments + * + * 6) "-x %s", etc. Combination of 4) and 5) + * + * If the format is "%s", memory is allocated for the string unlike + * with scanf(). + */ +struct fuse_opt { + /** Matching template and optional parameter formatting */ + const char *templ; + + /** + * Offset of variable within 'data' parameter of fuse_opt_parse() + * or -1 + */ + unsigned long offset; + + /** + * Value to set the variable to, or to be passed as 'key' to the + * processing function. Ignored if template has a format + */ + int value; +}; + +/** + * Key option. In case of a match, the processing function will be + * called with the specified key. + */ +#define FUSE_OPT_KEY(templ, key) { templ, -1U, key } + +/** + * Last option. An array of 'struct fuse_opt' must end with a NULL + * template value + */ +#define FUSE_OPT_END { .templ = NULL } + +/** + * Argument list + */ +struct fuse_args { + /** Argument count */ + int argc; + + /** Argument vector. NULL terminated */ + char **argv; + + /** Is 'argv' allocated? */ + int allocated; +}; + +/** + * Initializer for 'struct fuse_args' + */ +#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 } + +/** + * Key value passed to the processing function if an option did not + * match any template + */ +#define FUSE_OPT_KEY_OPT -1 + +/** + * Key value passed to the processing function for all non-options + * + * Non-options are the arguments beginning with a charater other than + * '-' or all arguments after the special '--' option + */ +#define FUSE_OPT_KEY_NONOPT -2 + +/** + * Processing function + * + * This function is called if + * - option did not match any 'struct fuse_opt' + * - argument is a non-option + * - option did match and offset was set to -1 + * + * The 'arg' parameter will always contain the whole argument or + * option including the parameter if exists. A two-argument option + * ("-x foo") is always converted to single arguemnt option of the + * form "-xfoo" before this function is called. + * + * Options of the form '-ofoo' are passed to this function without the + * '-o' prefix. + * + * The return value of this function determines whether this argument + * is to be inserted into the output argument vector, or discarded. + * + * @param data is the user data passed to the fuse_opt_parse() function + * @param arg is the whole argument or option + * @param key determines why the processing function was called + * @param outargs the current output argument list + * @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept + */ +typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key, + struct fuse_args *outargs); + +/** + * Option parsing function + * + * If 'args' was returned from a previous call to fuse_opt_parse() or + * it was constructed from + * + * A NULL 'args' is equivalent to an empty argument vector + * + * A NULL 'opts' is equivalent to an 'opts' array containing a single + * end marker + * + * A NULL 'proc' is equivalent to a processing function always + * returning '1' + * + * @param args is the input and output argument list + * @param data is the user data + * @param opts is the option description array + * @param proc is the processing function + * @return -1 on error, 0 on success + */ +int fuse_opt_parse(struct fuse_args *args, void *data, + const struct fuse_opt opts[], fuse_opt_proc_t proc); + +/** + * Add an option to a comma separated option list + * + * @param opts is a pointer to an option list, may point to a NULL value + * @param opt is the option to add + * @return -1 on allocation error, 0 on success + */ +int fuse_opt_add_opt(char **opts, const char *opt); + +/** + * Add an argument to a NULL terminated argument vector + * + * @param args is the structure containing the current argument list + * @param arg is the new argument to add + * @return -1 on allocation error, 0 on success + */ +int fuse_opt_add_arg(struct fuse_args *args, const char *arg); + +/** + * Free the contents of argument list + * + * The structure itself is not freed + * + * @param args is the structure containing the argument list + */ +void fuse_opt_free_args(struct fuse_args *args); + + +/** + * Check if an option matches + * + * @param opts is the option description array + * @param opt is the option to match + * @return 1 if a match is found, 0 if not + */ +int fuse_opt_match(const struct fuse_opt opts[], const char *opt); + +#ifdef __cplusplus +} +#endif + +#endif /* _FUSE_OPT_H_ */ |