Add support for -o XXX or -oXXX options in libfuse.
authorsyl <syl@openbsd.org>
Tue, 20 May 2014 13:22:06 +0000 (13:22 +0000)
committersyl <syl@openbsd.org>
Tue, 20 May 2014 13:22:06 +0000 (13:22 +0000)
inputs from tedu@, ok tedu@

lib/libfuse/fuse.c
lib/libfuse/fuse_opt.c
lib/libfuse/fuse_opt.h

index 16d9376..b726b88 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse.c,v 1.22 2014/05/19 13:43:30 tedu Exp $ */
+/* $OpenBSD: fuse.c,v 1.23 2014/05/20 13:22:06 syl Exp $ */
 /*
  * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
  *
 
 static struct fuse_session *sigse;
 static struct fuse_context *ictx = NULL;
+static int max_read = FUSEBUFMAXSIZE;
 
 enum {
        KEY_HELP,
        KEY_HELP_WITHOUT_HEADER,
        KEY_VERSION,
-       KEY_DEBUG
+       KEY_MAXREAD,
+       KEY_STUB
 };
 
 static struct fuse_opt fuse_core_opts[] = {
-       FUSE_OPT_KEY("-h",              KEY_HELP),
-       FUSE_OPT_KEY("--help",          KEY_HELP),
-       FUSE_OPT_KEY("-ho",             KEY_HELP_WITHOUT_HEADER),
-       FUSE_OPT_KEY("-V",              KEY_VERSION),
-       FUSE_OPT_KEY("--version",       KEY_VERSION),
-       FUSE_OPT_KEY("debug",           KEY_DEBUG),
-       FUSE_OPT_KEY("-d",              KEY_DEBUG),
-       FUSE_OPT_KEY("-f",              KEY_DEBUG),
-       FUSE_OPT_KEY("-s",              KEY_DEBUG),
+       FUSE_OPT_KEY("-h",                      KEY_HELP),
+       FUSE_OPT_KEY("--help",                  KEY_HELP),
+       FUSE_OPT_KEY("-ho",                     KEY_HELP_WITHOUT_HEADER),
+       FUSE_OPT_KEY("-V",                      KEY_VERSION),
+       FUSE_OPT_KEY("--version",               KEY_VERSION),
+       FUSE_OPT_KEY("max_read=",               KEY_MAXREAD),
+       FUSE_OPT_KEY("debug",                   KEY_STUB),
+       FUSE_OPT_KEY("-d",                      KEY_STUB),
+       FUSE_OPT_KEY("-f",                      KEY_STUB),
+       FUSE_OPT_KEY("-s",                      KEY_STUB),
+       FUSE_OPT_KEY("use_ino",                 KEY_STUB),
+       FUSE_OPT_KEY("default_permissions",     KEY_STUB),
+       FUSE_OPT_KEY("fsname=",                 KEY_STUB),
        FUSE_OPT_END
 };
 
@@ -342,10 +348,11 @@ ifuse_process_opt(void *data, const char *arg, int key,
 {
        struct fuse_core_opt *opt = data;
        struct stat st;
+       const char *err;
        int res;
 
        switch (key) {
-               case KEY_DEBUG:
+               case KEY_STUB:
                        return (0);
                case KEY_HELP:
                case KEY_HELP_WITHOUT_HEADER:
@@ -354,6 +361,14 @@ ifuse_process_opt(void *data, const char *arg, int key,
                case KEY_VERSION:
                        dump_version();
                        return (1);
+               case KEY_MAXREAD:
+                       res = strtonum(arg, 0, FUSEBUFMAXSIZE, &err);
+                       if (err) {
+                               fprintf(stderr, "fuse: max_read %s\n", err);
+                               return (-1);
+                       }
+                       max_read = res;
+                       break;
                case FUSE_OPT_KEY_NONOPT:
                        if (opt->mp == NULL) {
                                opt->mp = realpath(arg, opt->mp);
index cc3e34b..c08cbf1 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse_opt.c,v 1.9 2014/04/15 08:48:11 syl Exp $ */
+/* $OpenBSD: fuse_opt.c,v 1.10 2014/05/20 13:22:06 syl Exp $ */
 /*
  * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
  * Copyright (c) 2013 Stefan Sperling <stsp@openbsd.org>
@@ -221,15 +221,32 @@ static int
 parse_opt(const struct fuse_opt *o, const char *val, void *data,
     fuse_opt_proc_t f, struct fuse_args *arg)
 {
-       int ret;
-       int found = 0;
+       int found, ret, keyval;
+       size_t idx;
+
+       ret = 0;
+       found = 0;
+       keyval = 0;
+
+       /* check if it is a key=value entry */
+       idx = strcspn(val, "=");
+       if (idx != strlen(val)) {
+               idx++;
+               keyval = 1;
+       }
 
        for(; o->templ; o++) {
-               if (strcmp(val, o->templ) == 0) {
+               if ((keyval && strncmp(val, o->templ, idx) == 0) ||
+                   (!keyval && strcmp(val, o->templ) == 0)) {
                        if (o->val == FUSE_OPT_KEY_DISCARD)
                                return (1);
 
-                       ret = f(data, val, o->val, arg);
+                       if (FUSE_OPT_IS_OPT_KEY(o)) {
+                               if (keyval)
+                                       ret = f(data, &val[idx], o->val, arg);
+                               else
+                                       ret = f(data, val, o->val, arg);
+                       }
 
                        if (ret == -1)
                                return (ret);
@@ -245,7 +262,7 @@ parse_opt(const struct fuse_opt *o, const char *val, void *data,
                return (-1);
        }
 
-       return (0);
+       return (ret);
 }
 
 /*
@@ -285,9 +302,12 @@ fuse_opt_parse(struct fuse_args *args, void *data,
                        if (arg[2])
                                arg += 2;       /* -ofoo,bar */
                        else
-                               i++;            /* -o foo,bar*/
-                       if (ret != 0)
-                               return (ret);
+                               arg = args->argv[++i];
+
+                       ret = parse_opt(opt, arg, data, f, &outargs);
+
+                       if (ret == -1)
+                               goto err;
                } else {
                        ret = parse_opt(opt, arg, data, f, &outargs);
 
index a6030ea..a042ef8 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse_opt.h,v 1.3 2014/01/21 22:26:11 jca Exp $ */
+/* $OpenBSD: fuse_opt.h,v 1.4 2014/05/20 13:22:06 syl Exp $ */
 /*
  * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
  *
@@ -46,6 +46,8 @@ int fuse_opt_parse(struct fuse_args *, void *, const struct fuse_opt *,
 
 #define FUSE_ARGS_INIT(ac, av) { ac, av, 0 }
 
+#define FUSE_OPT_IS_OPT_KEY(t) (t->off == (unsigned long)-1)
+
 #define FUSE_OPT_KEY(t, k)     { t, -1, k }
 #define FUSE_OPT_END           { NULL, 0, 0 }
 #define FUSE_OPT_KEY_OPT       -1