From e20e5c9ae574bba8827310edf38ae9edca08c469 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Sat, 1 Oct 2016 11:24:46 -0700 Subject: [PATCH] Improve documentation of argument parsing. --- include/fuse.h | 7 +++++++ include/fuse_common.h | 16 +++++++++++++--- include/fuse_lowlevel.h | 7 +++++++ lib/fuse.c | 5 +++++ lib/fuse_lowlevel.c | 1 + lib/helper.c | 1 + lib/mount.c | 2 ++ lib/mount_bsd.c | 2 ++ 8 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/fuse.h b/include/fuse.h index c70d2fe..5721caa 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -640,6 +640,13 @@ struct fuse_context { /** * Create a new FUSE filesystem. * + * Known parameters in `args` are removed. If there are any unknown + * arguments, an error is printed to stderr and the function returns + * NULL. + * + * If the --help or --version parameters are specified, the function + * prints the requested information to stdout and returns NULL. + * * @param ch the communication channel * @param args argument vector * @param op the filesystem operations diff --git a/include/fuse_common.h b/include/fuse_common.h index 2fa9962..df92e8e 100644 --- a/include/fuse_common.h +++ b/include/fuse_common.h @@ -213,7 +213,13 @@ struct fuse_pollhandle; * Create a FUSE mountpoint * * Returns a control file descriptor suitable for passing to - * fuse_new() + * fuse_new(). Unknown parameters in `args` are passed through + * unchanged. Known parameters (with the exception of --help and + * --version) are removed from `args`. + * + * If the --help or --version parameters are specified, the function + * prints the requested information to stdout and returns a valid + * pointer. However, it does not actually perform the mount. * * @param mountpoint the mount point path * @param args argument vector @@ -230,7 +236,7 @@ struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args); void fuse_unmount(const char *mountpoint, struct fuse_chan *ch); /** - * Parse common options + * Utility functions for simple file systems to parse common options. * * The following options are parsed: * @@ -242,7 +248,11 @@ void fuse_unmount(const char *mountpoint, struct fuse_chan *ch); * '-ofsname=..' file system name, if not present, then set to the program * name * - * All parameters may be NULL + * Unknown parameters in `args` are passed through unchanged. Known + * parameters (with the exception of --help and --version) are removed. + * + * All parameters may be NULL (in which case they may still + * be specified on the command line, but will not be set). * * @param args argument vector * @param mountpoint the returned mountpoint, should be freed after use diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index 2022cc6..ce39906 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -1575,6 +1575,13 @@ int fuse_req_interrupted(fuse_req_t req); /** * Create a low level session * + * Known parameters in `args` are removed. If there are any unknown + * arguments, an error is printed to stderr and the function returns + * NULL. + * + * If the --help or --version parameters are specified, the function + * prints the requsted information to stdout and returns NULL. + * * @param args argument vector * @param op the low level filesystem operations * @param op_size sizeof(struct fuse_lowlevel_ops) diff --git a/lib/fuse.c b/lib/fuse.c index a879ffa..cd254f9 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -4684,6 +4684,9 @@ struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, init_list_head(&f->full_slabs); init_list_head(&f->lru_table); + /* When --help or --version are specified, we print messages + to stderr but continue for now (and keep the arguments in + `args` for use below */ if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, fuse_lib_opt_proc) == -1) goto out_free_fs; @@ -4714,6 +4717,8 @@ struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, f->conf.readdir_ino = 1; #endif + /* This function will return NULL if there is an --help + or --version argument in `args` */ f->se = fuse_lowlevel_new(args, &llop, sizeof(llop), f); if (f->se == NULL) { if (f->conf.help) diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index 9b59515..31714dd 100755 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -2674,6 +2674,7 @@ static int fuse_ll_opt_proc(void *data, const char *arg, int key, fprintf(stderr, "fuse: unknown option `%s'\n", arg); } + /* Fail */ return -1; } diff --git a/lib/helper.c b/lib/helper.c index 97577c2..6a55269 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -114,6 +114,7 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key, } default: + /* Pass through unknown options */ return 1; } } diff --git a/lib/mount.c b/lib/mount.c index 7be7b25..b2b841d 100644 --- a/lib/mount.c +++ b/lib/mount.c @@ -241,6 +241,8 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key, mo->ishelp = 1; break; } + + /* Pass through unknown options */ return 1; } diff --git a/lib/mount_bsd.c b/lib/mount_bsd.c index 3d6b12f..40ef93f 100644 --- a/lib/mount_bsd.c +++ b/lib/mount_bsd.c @@ -141,6 +141,8 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key, mo->ishelp = 1; break; } + + /* Pass through unknown options */ return 1; } -- 2.30.2