fuse_lowlevel.h: new file, currently only contains fuse_parse_cmdline(3) and struct fuse_cmdline_opts
This commit is contained in:
parent
ac36483cc7
commit
0e4f248f77
@ -1,4 +1,4 @@
|
||||
# $NetBSD: mi,v 1.2068 2016/10/29 17:12:20 kamil Exp $
|
||||
# $NetBSD: mi,v 1.2069 2016/11/20 13:26:28 pho Exp $
|
||||
#
|
||||
# Note: don't delete entries from here - mark them as "obsolete" instead.
|
||||
./etc/mtree/set.comp comp-sys-root
|
||||
@ -839,6 +839,7 @@
|
||||
./usr/include/fts.h comp-c-include
|
||||
./usr/include/ftw.h comp-c-include
|
||||
./usr/include/fuse.h comp-refuse-include
|
||||
./usr/include/fuse_lowlevel.h comp-refuse-include
|
||||
./usr/include/fuse_opt.h comp-refuse-include
|
||||
./usr/include/g++/ACG.h comp-obsolete obsolete
|
||||
./usr/include/g++/AllocRing.h comp-obsolete obsolete
|
||||
|
@ -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>
|
||||
|
59
lib/librefuse/fuse_lowlevel.h
Normal file
59
lib/librefuse/fuse_lowlevel.h
Normal file
@ -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_ */
|
147
lib/librefuse/refuse_lowlevel.c
Normal file
147
lib/librefuse/refuse_lowlevel.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user