From: Miklos Szeredi Date: Thu, 19 Jan 2006 16:07:48 +0000 (+0000) Subject: fix X-Git-Tag: fuse_2_5_2~9 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=e309ba9463c512ca0295b1127824cb6504385661;p=qemu-gpiodev%2Flibfuse.git fix --- diff --git a/ChangeLog b/ChangeLog index ffa36f0..bdd1ec2 100644 --- 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 * kernel: fix detection of case when fuse is not configured into diff --git a/include/fuse_opt.h b/include/fuse_opt.h index 2988902..a46b920 100644 --- a/include/fuse_opt.h +++ b/include/fuse_opt.h @@ -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 * diff --git a/lib/fuse_opt.c b/lib/fuse_opt.c index 65ff1ec..5485e0a 100644 --- a/lib/fuse_opt.c +++ b/lib/fuse_opt.c @@ -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) diff --git a/lib/helper.c b/lib/helper.c index 8322fd1..c4a7b3a 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -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: