From ad005978f76c3f5f6d533c4e3f13b5ed39e43173 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Sat, 7 Jan 2006 10:14:34 +0000 Subject: [PATCH] fix --- ChangeLog | 4 +++ lib/fuse.c | 42 +++++++++++++++++++++-- lib/fuse_lowlevel.c | 33 +++++++++++++++--- lib/helper.c | 82 ++++++++++++++++++++++++--------------------- lib/mount.c | 41 +++++++++++++++++++++++ util/fusermount.c | 10 +++--- 6 files changed, 161 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89610fc..a82a139 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-01-07 Miklos Szeredi + + * Improved help reporting and added version reporting to library + 2006-01-06 Miklos Szeredi * Change working directory to "/" even if running in the diff --git a/lib/fuse.c b/lib/fuse.c index d68ca5d..7d66a7d 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -1806,11 +1806,18 @@ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)) fuse_getcontext = func; } +enum { + KEY_HELP, + KEY_KEEP +}; + #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } static const struct fuse_opt fuse_lib_opts[] = { - FUSE_OPT_KEY("debug", 0), - FUSE_OPT_KEY("-d", 0), + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("debug", KEY_KEEP), + FUSE_OPT_KEY("-d", KEY_KEEP), FUSE_LIB_OPT("debug", debug, 1), FUSE_LIB_OPT("-d", debug, 1), FUSE_LIB_OPT("hard_remove", hard_remove, 1), @@ -1830,6 +1837,35 @@ static const struct fuse_opt fuse_lib_opts[] = { FUSE_OPT_END }; +static void fuse_lib_help(void) +{ + fprintf(stderr, + " -o hard_remove immediate removal (don't hide files)\n" + " -o use_ino let filesystem set inode numbers\n" + " -o readdir_ino try to fill in d_ino in readdir\n" + " -o direct_io use direct I/O\n" + " -o kernel_cache cache files in kernel\n" + " -o umask=M set file permissions (octal)\n" + " -o uid=N set file owner\n" + " -o gid=N set file group\n" + " -o entry_timeout=T cache timeout for names (1.0s)\n" + " -o negative_timeout=T cache timeout for deleted names (0.0s)\n" + " -o attr_timeout=T cache timeout for attributes (1.0s)\n" + "\n"); +} + +static int fuse_lib_opt_proc(void *data, const char *arg, int key, + struct fuse_args *outargs) +{ + (void) data; (void) arg; (void) outargs; + + if (key == KEY_HELP) + fuse_lib_help(); + + return 1; +} + + int fuse_is_lib_option(const char *opt) { return fuse_lowlevel_is_lib_option(opt) || @@ -1859,7 +1895,7 @@ struct fuse *fuse_new_common(int fd, struct fuse_args *args, f->conf.attr_timeout = 1.0; f->conf.negative_timeout = 0.0; - if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, NULL) == -1) + if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, fuse_lib_opt_proc) == -1) goto out_free; #ifdef __FreeBSD__ diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index d1b4b36..2018c94 100644 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -893,20 +893,45 @@ static void fuse_ll_process(void *data, const char *buf, size_t len, } } +enum { + KEY_HELP, + KEY_VERSION, +}; + static struct fuse_opt fuse_ll_opts[] = { { "debug", offsetof(struct fuse_ll, debug), 1 }, { "-d", offsetof(struct fuse_ll, debug), 1 }, { "allow_root", offsetof(struct fuse_ll, allow_root), 1 }, + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), FUSE_OPT_END }; +static void fuse_ll_version(void) +{ + fprintf(stderr, "using FUSE kernel interface version %i.%i\n", + FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); +} + static int fuse_ll_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { - (void) data; - (void) key; - (void) outargs; - fprintf(stderr, "fuse: unknown option `%s'\n", arg); + (void) data; (void) outargs; + + switch (key) { + case KEY_HELP: + break; + + case KEY_VERSION: + fuse_ll_version(); + break; + + default: + fprintf(stderr, "fuse: unknown option `%s'\n", arg); + } + return -1; } diff --git a/lib/helper.c b/lib/helper.c index 0387dc7..b7f77be 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -6,6 +6,7 @@ See the file COPYING.LIB. */ +#include "config.h" #include "fuse_i.h" #include "fuse_opt.h" #include "fuse_lowlevel.h" @@ -17,44 +18,10 @@ #include #include -static void usage(const char *progname) -{ - if (progname) - fprintf(stderr, - "usage: %s mountpoint [FUSE options]\n\n", progname); - - fprintf(stderr, - "FUSE options:\n" - " -d enable debug output (implies -f)\n" - " -f foreground operation\n" - " -s disable multi-threaded operation\n" - " -r mount read only (equivalent to '-o ro')\n" - " -o opt,[opt...] mount options\n" - " -h print help\n" - "\n" - "Mount options:\n" - " default_permissions enable permission checking\n" - " allow_other allow access to other users\n" - " allow_root allow access to root\n" - " kernel_cache cache files in kernel\n" - " large_read issue large read requests (2.4 only)\n" - " direct_io use direct I/O\n" - " max_read=N set maximum size of read requests\n" - " hard_remove immediate removal (don't hide files)\n" - " debug enable debug output\n" - " fsname=NAME set filesystem name in mtab\n" - " use_ino let filesystem set inode numbers\n" - " readdir_ino try to fill in d_ino in readdir\n" - " nonempty allow mounts over non-empty file/dir\n" - " umask=M set file permissions (octal)\n" - " uid=N set file owner\n" - " gid=N set file group\n" - ); -} - enum { KEY_HELP, KEY_HELP_NOHEADER, + KEY_VERSION, KEY_KEEP, }; @@ -70,18 +37,48 @@ struct helper_opts { static const struct fuse_opt fuse_helper_opts[] = { FUSE_HELPER_OPT("-d", foreground), FUSE_HELPER_OPT("debug", foreground), - FUSE_HELPER_OPT("-f", foreground), - FUSE_HELPER_OPT("-s", singlethread), + FUSE_HELPER_OPT("-f", foreground), + FUSE_HELPER_OPT("-s", singlethread), FUSE_HELPER_OPT("fsname=", fsname), FUSE_OPT_KEY("-h", KEY_HELP), FUSE_OPT_KEY("--help", KEY_HELP), FUSE_OPT_KEY("-ho", KEY_HELP_NOHEADER), + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), FUSE_OPT_KEY("-d", KEY_KEEP), FUSE_OPT_KEY("debug", KEY_KEEP), FUSE_OPT_END }; +static void usage(const char *progname) +{ + fprintf(stderr, + "usage: %s mountpoint [options]\n\n", progname); + fprintf(stderr, + "general options:\n" + " -o opt,[opt...] mount options\n" + " -h --help print help\n" + " -V --version print version\n" + "\n"); +} + +static void helper_help(void) +{ + fprintf(stderr, + "FUSE options:\n" + " -d -o debug enable debug output (implies -f)\n" + " -f foreground operation\n" + " -s disable multi-threaded operation\n" + "\n" + ); +} + +static void helper_version(void) +{ + fprintf(stderr, "FUSE library version: %s\n", PACKAGE_VERSION); +} + static int fuse_helper_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { @@ -89,9 +86,16 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key, switch (key) { case KEY_HELP: + usage(outargs->argv[0]); + /* fall through */ + case KEY_HELP_NOHEADER: - usage(key == KEY_HELP ? outargs->argv[0] : NULL); - exit(1); + helper_help(); + return fuse_opt_add_arg(outargs, "-h"); + + case KEY_VERSION: + helper_version(); + return 1; case FUSE_OPT_KEY_NONOPT: if (!hopts->mountpoint) diff --git a/lib/mount.c b/lib/mount.c index b53889d..91d96f4 100644 --- a/lib/mount.c +++ b/lib/mount.c @@ -27,11 +27,14 @@ enum { KEY_KERN, KEY_ALLOW_ROOT, KEY_RO, + KEY_HELP, + KEY_VERSION, }; struct mount_opts { int allow_other; int allow_root; + int ishelp; char *kernel_opts; }; @@ -58,9 +61,32 @@ static const struct fuse_opt fuse_mount_opts[] = { FUSE_OPT_KEY("sync", KEY_KERN), FUSE_OPT_KEY("atime", KEY_KERN), FUSE_OPT_KEY("noatime", KEY_KERN), + FUSE_OPT_KEY("-h", KEY_HELP), + FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_OPT_KEY("-V", KEY_VERSION), + FUSE_OPT_KEY("--version", KEY_VERSION), FUSE_OPT_END }; +static void mount_help(void) +{ + fprintf(stderr, + " -o allow_other allow access to other users\n" + " -o allow_root allow access to root\n" + " -o nonempty allow mounts over non-empty file/dir\n" + " -o default_permissions enable permission checking by kernel\n" + " -o fsname=NAME set filesystem name\n" + " -o large_read issue large read requests (2.4 only)\n" + " -o max_read=N set maximum size of read requests\n" + "\n" + ); +} + +static void mount_version(void) +{ + system(FUSERMOUNT_PROG " --version"); +} + static int fuse_mount_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { @@ -79,6 +105,16 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key, case KEY_KERN: return fuse_opt_add_opt(&mo->kernel_opts, arg); + + case KEY_HELP: + mount_help(); + mo->ishelp = 1; + break; + + case KEY_VERSION: + mount_version(); + mo->ishelp = 1; + break; } return 1; } @@ -133,6 +169,9 @@ void fuse_unmount(const char *mountpoint) const char *mountprog = FUSERMOUNT_PROG; int pid; + if (!mountpoint) + return; + #ifdef HAVE_FORK pid = fork(); #else @@ -235,6 +274,8 @@ int fuse_mount(const char *mountpoint, struct fuse_args *args) fprintf(stderr, "fuse: 'allow_other' and 'allow_root' options are mutually exclusive\n"); goto out; } + if (mo.ishelp) + return 0; res = fuse_mount_compat22(mountpoint, mo.kernel_opts); out: diff --git a/util/fusermount.c b/util/fusermount.c index 63a6068..abe78b9 100644 --- a/util/fusermount.c +++ b/util/fusermount.c @@ -1018,7 +1018,7 @@ static void usage(void) "%s: [options] mountpoint\n" "Options:\n" " -h print help\n" - " -v print version\n" + " -V print version\n" " -o opt[,opt...] mount options\n" " -u unmount\n" " -q quiet\n" @@ -1029,7 +1029,7 @@ static void usage(void) static void show_version(void) { - printf("%s\n", PACKAGE_STRING); + printf("fusermount version: %s\n", PACKAGE_VERSION); exit(0); } @@ -1052,7 +1052,7 @@ int main(int argc, char *argv[]) {"lazy", no_argument, NULL, 'z'}, {"quiet", no_argument, NULL, 'q'}, {"help", no_argument, NULL, 'h'}, - {"version", no_argument, NULL, 'v'}, + {"version", no_argument, NULL, 'V'}, {0, 0, 0, 0}}; progname = strdup(argv[0]); @@ -1061,13 +1061,13 @@ int main(int argc, char *argv[]) exit(1); } - while ((ch = getopt_long(argc, argv, "hvo:uzq", long_opts, NULL)) != -1) { + while ((ch = getopt_long(argc, argv, "hVo:uzq", long_opts, NULL)) != -1) { switch (ch) { case 'h': usage(); break; - case 'v': + case 'V': show_version(); break; -- 2.30.2