diff options
| author | pho <pho@NetBSD.org> | 2016-11-20 13:26:28 +0000 |
|---|---|---|
| committer | pho <pho@NetBSD.org> | 2016-11-20 13:26:28 +0000 |
| commit | 30a200eac4b13be7fbed5193342e1a19234efec0 (patch) | |
| tree | 22b3c586e045a891cad1060f01594794c85faad4 /lib/librefuse | |
| parent | ceb1ee6025ad3407c5cad7aac7e1c464bb577df6 (diff) | |
fuse_lowlevel.h: new file, currently only contains fuse_parse_cmdline(3) and struct fuse_cmdline_opts
Diffstat (limited to 'lib/librefuse')
| -rw-r--r-- | lib/librefuse/Makefile | 8 | ||||
| -rw-r--r-- | lib/librefuse/fuse_lowlevel.h | 59 | ||||
| -rw-r--r-- | lib/librefuse/refuse_lowlevel.c | 147 |
3 files changed, 210 insertions, 4 deletions
diff --git a/lib/librefuse/Makefile b/lib/librefuse/Makefile index a9e55e3a688..7784f25f506 100644 --- a/lib/librefuse/Makefile +++ b/lib/librefuse/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.10 2016/01/23 21:22:46 christos Exp $ +# $NetBSD: Makefile,v 1.11 2016/11/20 13:26:28 pho Exp $ USE_FORT?= yes # data driven bugs? @@ -11,11 +11,11 @@ FUSE_OPT_DEBUG_FLAGS= -g -DFUSE_OPT_DEBUG .endif CFLAGS+= ${FUSE_OPT_DEBUG_FLAGS} -CPPFLAGS+= -D_KERNTYPES -SRCS= refuse.c refuse_opt.c +CPPFLAGS+= -I${.CURDIR} -D_KERNTYPES +SRCS= refuse.c refuse_opt.c refuse_lowlevel.c MAN= refuse.3 WARNS?= 5 -INCS= fuse.h fuse_opt.h +INCS= fuse.h fuse_opt.h fuse_lowlevel.h INCSDIR= /usr/include .include <bsd.lib.mk> diff --git a/lib/librefuse/fuse_lowlevel.h b/lib/librefuse/fuse_lowlevel.h new file mode 100644 index 00000000000..e53c267687f --- /dev/null +++ b/lib/librefuse/fuse_lowlevel.h @@ -0,0 +1,59 @@ +/* $NetBSD: fuse_lowlevel.h,v 1.1 2016/11/20 13:26:28 pho Exp $ */ + +/* + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _FUSE_LOWLEVEL_H_ +#define _FUSE_LOWLEVEL_H_ + +#include <fuse.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct fuse_cmdline_opts { + int singlethread; + int foreground; + int debug; + int nodefault_fsname; + char *mountpoint; + int show_version; + int show_help; +}; + +int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts); +void fuse_lowlevel_version(void); +void fuse_cmdline_help(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _FUSE_LOWLEVEL_H_ */ diff --git a/lib/librefuse/refuse_lowlevel.c b/lib/librefuse/refuse_lowlevel.c new file mode 100644 index 00000000000..f4e3529428c --- /dev/null +++ b/lib/librefuse/refuse_lowlevel.c @@ -0,0 +1,147 @@ +/* $NetBSD: refuse_lowlevel.c,v 1.1 2016/11/20 13:26:28 pho Exp $ */ + +/* + * Copyright (c) 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +#if !defined(lint) +__RCSID("$NetBSD: refuse_lowlevel.c,v 1.1 2016/11/20 13:26:28 pho Exp $"); +#endif /* !lint */ + +#include <fuse_lowlevel.h> +#include <fuse_opt.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define REFUSE_LOWLEVEL_OPT(t, p, v) \ + { t, offsetof(struct fuse_cmdline_opts, p), v } + +static struct fuse_opt fuse_lowlevel_opts[] = { + REFUSE_LOWLEVEL_OPT("-h" , show_help , 1), + REFUSE_LOWLEVEL_OPT("--help" , show_help , 1), + REFUSE_LOWLEVEL_OPT("-V" , show_version , 1), + REFUSE_LOWLEVEL_OPT("--version", show_version , 1), + REFUSE_LOWLEVEL_OPT("-d" , debug , 1), + REFUSE_LOWLEVEL_OPT("debug" , debug , 1), + REFUSE_LOWLEVEL_OPT("-d" , foreground , 1), + REFUSE_LOWLEVEL_OPT("debug" , foreground , 1), + REFUSE_LOWLEVEL_OPT("-f" , foreground , 1), + REFUSE_LOWLEVEL_OPT("-s" , singlethread , 1), + REFUSE_LOWLEVEL_OPT("fsname=" , nodefault_fsname, 1), + FUSE_OPT_KEY ("fsname=" , FUSE_OPT_KEY_KEEP ), + FUSE_OPT_END +}; + +void fuse_lowlevel_version(void) +{ + /* XXX: Print something */ +} + +void fuse_cmdline_help(void) +{ + printf("refuse options:\n" + " -d, -o debug enable debug output, implies -f\n" + " -f foreground mode\n" + " -s single threaded mode (always enabled for now)\n" + " -o fsname=NAME explicitly set the name of the file system\n"); +} + +static int refuse_lowlevel_opt_proc(void* data, const char *arg, int key, + struct fuse_args *outargs) +{ + struct fuse_cmdline_opts *opts = data; + + switch (key) { + case FUSE_OPT_KEY_NONOPT: + if (opts->mountpoint == NULL) { + return fuse_opt_add_opt(&opts->mountpoint, arg); + } + else { + (void)fprintf(stderr, "fuse: invalid argument: %s\n", arg); + return -1; + } + + default: + return 1; /* keep the argument */ + } +} + +static int add_default_fsname(struct fuse_args *args) +{ + const char *arg0 = args->argv[0]; + const char *slash; + + if (arg0 == NULL || arg0[0] == '\0') { + return fuse_opt_add_arg(args, "-ofsname=refuse"); + } else { + char *arg; + int rv; + + if ((slash = strrchr(arg0, '/')) == NULL) { + slash = arg0; + } else { + slash += 1; + } + + if (asprintf(&arg, "-ofsname=refuse:%s", slash) == -1) + return -1; + + rv = fuse_opt_add_arg(args, arg); + free(arg); + return rv; + } +} + +int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts) +{ + memset(opts, 0, sizeof(*opts)); + + /* + * XXX: The single threaded mode is always enabled and cannot be + * disabled. This is because puffs currently does not support + * multithreaded operation. + */ + opts->singlethread = 1; + + if (fuse_opt_parse(args, opts, fuse_lowlevel_opts, + refuse_lowlevel_opt_proc) == -1) + return -1; + + if (!opts->nodefault_fsname) { + /* -o fsname=%s is not specified so add a default fsname + * generated from the program basename. + */ + if (add_default_fsname(args) == -1) + return -1; + } + + return 0; +} |
