fix
authorMiklos Szeredi <miklos@szeredi.hu>
Thu, 19 Jan 2006 16:07:48 +0000 (16:07 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Thu, 19 Jan 2006 16:07:48 +0000 (16:07 +0000)
ChangeLog
include/fuse_opt.h
lib/fuse_opt.c
lib/helper.c

index ffa36f01f85f59038649d8f8fbd6092fd6166780..bdd1ec2a8446c5f8e4fcceb13bdb578b4ae00815 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
        * lib: if "fsname=" option was given, pass it to fusermount
 
+       * fuse_opt: add new fuse_opt_insert_arg() function, which is
+       needed by filesystems to implement some argument manipulations
+       correctly
+
 2006-01-18  Miklos Szeredi <miklos@szeredi.hu>
 
        * kernel: fix detection of case when fuse is not configured into
index 2988902f2f0cdc9cae31e79b77f1f2d37f55c805..a46b9206dbb0326a1efc0ccd18751a05f191b757 100644 (file)
@@ -201,6 +201,21 @@ int fuse_opt_add_opt(char **opts, const char *opt);
  */
 int fuse_opt_add_arg(struct fuse_args *args, const char *arg);
 
+/**
+ * Add an argument at the specified position in a NULL terminated
+ * argument vector
+ *
+ * Adds the argument to the N-th position.  This is useful for adding
+ * options at the beggining of the array which must not come after the
+ * special '--' option.
+ *
+ * @param args is the structure containing the current argument list
+ * @param pos is the position at which to add the argument
+ * @param arg is the new argument to add
+ * @return -1 on allocation error, 0 on success
+ */
+int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg);
+
 /**
  * Free the contents of argument list
  *
index 65ff1ec97e2a17b75b9075fc3970fd0b6cc77de8..5485e0a9d78a933054d927ab3b444b1368342d26 100644 (file)
@@ -62,6 +62,21 @@ int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
     return 0;
 }
 
+int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg)
+{
+    assert(pos <= args->argc);
+    if (fuse_opt_add_arg(args, arg) == -1)
+        return -1;
+
+    if (pos != args->argc - 1) {
+        char *newarg = args->argv[args->argc - 1];
+        memmove(&args->argv[pos + 1], &args->argv[pos],
+                sizeof(char *) * (args->argc - pos - 1));
+        args->argv[pos] = newarg;
+    }
+    return 0;
+}
+
 static int next_arg(struct fuse_opt_context *ctx, const char *opt)
 {
     if (ctx->argctr + 1 >= ctx->argc) {
@@ -102,20 +117,6 @@ static int add_opt(struct fuse_opt_context *ctx, const char *opt)
     return fuse_opt_add_opt(&ctx->opts, opt);
 }
 
-static int insert_arg(struct fuse_opt_context *ctx, int pos, const char *arg)
-{
-    assert(pos <= ctx->outargs.argc);
-    if (add_arg(ctx, arg) == -1)
-        return -1;
-
-    if (pos != ctx->outargs.argc - 1) {
-        char *newarg = ctx->outargs.argv[ctx->outargs.argc - 1];
-        memmove(&ctx->outargs.argv[pos + 1], &ctx->outargs.argv[pos],
-                sizeof(char *) * (ctx->outargs.argc - pos - 1));
-        ctx->outargs.argv[pos] = newarg;
-    }
-    return 0;
-}
 
 static int call_proc(struct fuse_opt_context *ctx, const char *arg, int key,
                      int iso)
@@ -321,8 +322,8 @@ static int opt_parse(struct fuse_opt_context *ctx)
             return -1;
 
     if (ctx->opts) {
-        if (insert_arg(ctx, 1, "-o") == -1 ||
-            insert_arg(ctx, 2, ctx->opts) == -1)
+        if (fuse_opt_insert_arg(&ctx->outargs, 1, "-o") == -1 ||
+            fuse_opt_insert_arg(&ctx->outargs, 2, ctx->opts) == -1)
             return -1;
     }
     if (ctx->nonopt && ctx->nonopt == ctx->outargs.argc)
index 8322fd15b49ef9c147b46dc66f60b97458aed8ec..c4a7b3a1eef2d5f8fde1c492e0859ab9473a96a4 100644 (file)
@@ -101,8 +101,10 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key,
     case FUSE_OPT_KEY_NONOPT:
         if (!hopts->mountpoint)
             return fuse_opt_add_opt(&hopts->mountpoint, arg);
-
-        /* fall through */
+        else {
+            fprintf(stderr, "fuse: invalid argument `%s'\n", arg);
+            return -1;
+        }
 
     default:
     case KEY_KEEP: