Revert the most recent changes I made - they weren't ready for primetime.

This commit is contained in:
agc 2007-03-13 22:47:03 +00:00
parent a43c9c728d
commit 950c7ae274
3 changed files with 89 additions and 210 deletions

View File

@ -26,7 +26,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FUSE_H_
#define FUSE_H_ 20070312
#define FUSE_H_ 20070123
#include <sys/types.h>
@ -38,6 +38,7 @@ extern "C" {
#endif
struct fuse;
struct fuse_args; /* XXXsupportme */
struct fuse_file_info {
int32_t flags;
@ -154,9 +155,6 @@ void fuse_destroy(struct fuse *);
void fuse_unmount(const char *, struct fuse_chan *);
int __fuse_debug(int);
void __fuse_pargs(const char *, int, char **);
#if FUSE_USE_VERSION == 22
#define fuse_unmount fuse_unmount_compat22
#endif
@ -170,6 +168,4 @@ void fuse_unmount_compat22(const char *);
}
#endif
#include <fuse_opt.h>
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: refuse.c,v 1.42 2007/03/13 22:25:32 agc Exp $ */
/* $NetBSD: refuse.c,v 1.43 2007/03/13 22:47:04 agc Exp $ */
/*
* Copyright © 2007 Alistair Crooks. All rights reserved.
@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: refuse.c,v 1.42 2007/03/13 22:25:32 agc Exp $");
__RCSID("$NetBSD: refuse.c,v 1.43 2007/03/13 22:47:04 agc Exp $");
#endif /* !lint */
#include <assert.h>
@ -41,20 +41,6 @@ __RCSID("$NetBSD: refuse.c,v 1.42 2007/03/13 22:25:32 agc Exp $");
#include "defs.h"
/*
This module implements refuse, a re-implementation of the FUSE model,
using puffs and libpuffs. It is intended to be source code compatible
with FUSE. Specifically, it implements FUSE versions 2.5 and 2.6,
although some effort was put in to make it backwards compatible (by
Antti, not me).
The error codes returned from refuse require some explanation. Linux
error codes in the kernel are negative, whereas traditional NetBSD
error codes are positive. For this reason, negative error codes are
returned from refuse, so that they are reported correctly to the
invoking application.
*/
typedef uint64_t fuse_ino_t;
struct fuse_config {
@ -80,11 +66,11 @@ struct fuse_config {
int intr_signal;
};
/* the fuse channel describes the physical attributes of the FUSE instance */
struct fuse_chan {
const char *dir; /* directory */
struct fuse_args *args; /* arguments to FUSE/puffs */
struct puffs_usermount *pu; /* puffs information */
const char *dir;
struct fuse_args *args;
struct puffs_usermount *pu;
};
/* this is the private fuse structure */
@ -107,48 +93,26 @@ struct fuse {
int intr_installed;
};
/* this struct describes a directory handle */
struct puffs_fuse_dirh {
void *dbuf; /* directory buffer */
struct dirent *d; /* pointer to its dirent */
size_t reslen; /* result length */
size_t bufsize; /* buffer size */
void *dbuf;
struct dirent *d;
size_t reslen;
size_t bufsize;
};
/* this struct describes a node in refuse land */
typedef struct refusenode {
struct fuse_file_info file_info; /* file information */
struct puffs_fuse_dirh dirh; /* directory handle */
int opencount; /* # of times opened */
int flags; /* associated flags */
} refusenode_t;
struct refusenode {
struct fuse_file_info file_info;
struct puffs_fuse_dirh dirh;
int opencount;
int flags;
};
#define RN_ROOT 0x01
#define RN_OPEN 0x02 /* XXX: could just use opencount */
/* debugging functions */
static int fuse_setattr(struct fuse *, struct puffs_node *,
const char *, const struct vattr *);
/* change the debug level by increment */
int
__fuse_debug(int incr)
{
static int __fuse_debug_level;
return __fuse_debug_level += incr;
}
/* print argv vector */
void
__fuse_pargs(const char *s, int argc, char **argv)
{
int i;
for (i = 0 ; i < argc ; i++) {
printf("%s: argv[%d] = `%s'\n", s, i, argv[i]);
}
}
/* create a new struct puffs_node and return it */
static struct puffs_node *
newrn(struct puffs_usermount *pu)
{
@ -161,7 +125,6 @@ newrn(struct puffs_usermount *pu)
return pn;
}
/* destroy a struct puffs_node */
static void
nukern(struct puffs_node *pn)
{
@ -175,7 +138,7 @@ nukern(struct puffs_node *pn)
static ino_t fakeino = 3;
/*
* XXX: do this differently if/when we grow thread support
* XXX: do this otherwise if/when we grow thread support
*
* XXX2: does not consistently supply uid, gid or pid currently
*/
@ -190,22 +153,19 @@ fill_dirbuf(struct puffs_fuse_dirh *dh, const char *name, ino_t dino,
/* initial? */
if (dh->bufsize == 0) {
dh->dbuf = malloc(DIR_CHUNKSIZE);
if (dh->dbuf == NULL) {
err(EXIT_FAILURE, "fill_dirbuf");
}
if (dh->dbuf == NULL)
err(1, "fill_dirbuf");
dh->d = dh->dbuf;
dh->reslen = dh->bufsize = DIR_CHUNKSIZE;
}
if (puffs_nextdent(&dh->d, name, dino, dtype, &dh->reslen)) {
if (puffs_nextdent(&dh->d, name, dino, dtype, &dh->reslen))
return 0;
}
/* try to increase buffer space */
dh->dbuf = realloc(dh->dbuf, dh->bufsize + DIR_CHUNKSIZE);
if (dh->dbuf == NULL) {
err(EXIT_FAILURE, "fill_dirbuf realloc");
}
if (dh->dbuf == NULL)
err(1, "fill_dirbuf realloc");
dh->d = (void *)((uint8_t *)dh->dbuf + (dh->bufsize - dh->reslen));
dh->reslen += DIR_CHUNKSIZE;
dh->bufsize += DIR_CHUNKSIZE;
@ -237,15 +197,18 @@ puffs_fuse_fill_dir(void *buf, const char *name,
static int
puffs_fuse_dirfil(fuse_dirh_t h, const char *name, int type, ino_t ino)
{
ino_t dino;
int dtype;
ino_t dino;
int dtype;
if ((dtype = type) == 0) {
if (type == 0)
dtype = DT_UNKNOWN;
}
if ((dino = ino) == 0) {
else
dtype = type;
if (ino)
dino = ino;
else
dino = fakeino++;
}
return fill_dirbuf(h, name, dino, dtype);
}
@ -474,7 +437,7 @@ puffs_fuse_node_readlink(struct puffs_cc *pcc, void *opc,
ret = (*fuse->op.readlink)(path, linkname, *linklen);
if (ret == 0) {
p = memchr(linkname, 0x0, *linklen);
p = memchr(linkname, '\0', *linklen);
if (!p)
return EINVAL;
@ -885,11 +848,11 @@ puffs_fuse_node_readdir(struct puffs_cc *pcc, void *opc,
size_t *reslen)
{
struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
struct puffs_fuse_dirh *dirh;
struct puffs_node *pn = opc;
struct refusenode *rn = pn->pn_data;
struct dirent *fromdent;
struct puffs_fuse_dirh *dirh;
struct fuse *fuse;
struct dirent *fromdent;
const char *path = PNPATH(pn);
int ret;
@ -983,14 +946,9 @@ puffs_fuse_fs_statvfs(struct puffs_cc *pcc, struct statvfs *svfsb, pid_t pid)
fuse = (struct fuse *)pu->pu_privdata;
if (fuse->op.statfs == NULL) {
#ifdef REFUSE_INHERIT_FS_CHARACTERISTICS
if ((ret = statvfs(PNPATH(pu->pu_pn_root), svfsb)) == -1) {
return errno;
}
#else
(void) memset(svfsb, 0x0, sizeof(*svfsb));
ret = 0;
#endif
} else {
ret = (*fuse->op.statfs)(PNPATH(pu->pu_pn_root), svfsb);
}
@ -1001,27 +959,40 @@ puffs_fuse_fs_statvfs(struct puffs_cc *pcc, struct statvfs *svfsb, pid_t pid)
/* End of puffs_fuse operations */
/* ARGSUSED3 */
int
fuse_main_real(int argc, char **argv, const struct fuse_operations *ops,
size_t size, void *userdata)
{
struct fuse_chan *fc;
struct fuse_args args;
struct fuse *fuse;
struct fuse_chan *fc;
char name[64];
char *slash;
int ret;
(void) memset(&args, 0x0, sizeof(args));
args.argc = argc;
args.argv = argv;
if (__fuse_debug(0)) {
__fuse_pargs("fuse_main_real", argc, argv);
/* whilst this (assigning the pu_privdata in the puffs
* usermount struct to be the fuse struct) might seem like
* we are chasing our tail here, the logic is as follows:
+ the operation wrapper gets called with the puffs
calling conventions
+ we need to fix up args first
+ then call the fuse user-supplied operation
+ then we fix up any values on return that we need to
+ and fix up any nodes, etc
* so we need to be able to get at the fuse ops from within the
* puffs_usermount struct
*/
if ((slash = strrchr(*argv, '/')) == NULL) {
slash = *argv;
} else {
slash += 1;
}
fc = fuse_mount(argv[argc - 1], &args);
(void) snprintf(name, sizeof(name), "refuse:%s", slash);
/* XXX: stuff name into fuse_args */
fuse = fuse_new(fc, fc->args, ops, size, userdata);
fc = fuse_mount(argv[argc - 1], NULL);
fuse = fuse_new(fc, NULL, ops, size, userdata);
ret = fuse_loop(fuse);
@ -1037,29 +1008,13 @@ fuse_main_real(int argc, char **argv, const struct fuse_operations *ops,
struct fuse_chan *
fuse_mount(const char *dir, struct fuse_args *args)
{
struct fuse_chan *fc;
struct fuse_chan *fc;
NEW(struct fuse_chan, fc, "fuse_mount", return NULL);
if (dir) {
fc->dir = strdup(dir);
}
if (args && args->argc > 0) {
NEW(struct fuse_args, fc->args, "fuse_mount2", return NULL);
/* yes, we do need to deep copy */
fc->args->allocated = ((args->argc / 32) + 1) * 32;
NEWARRAY(char *, fc->args->argv, fc->args->allocated, "fuse_mount3", return NULL);
for (fc->args->argc = 0 ; fc->args->argc < args->argc ; ) {
if (args->argv[fc->args->argc] != NULL) {
fc->args->argv[fc->args->argc] = strdup(args->argv[fc->args->argc]);
fc->args->argc += 1;
}
}
}
NEW(struct fuse_chan, fc, "fuse_mount", exit(EXIT_FAILURE));
fc->dir = strdup(dir);
fc->args = args; /* XXXX: do we need to deep copy? */
return fc;
}
@ -1070,13 +1025,11 @@ fuse_new(struct fuse_chan *fc, struct fuse_args *args,
{
struct puffs_usermount *pu;
struct puffs_pathobj *po_root;
struct refusenode *rn_root;
struct puffs_ops *pops;
struct refusenode *rn_root;
struct statvfs svfsb;
struct stat st;
struct fuse *fuse;
char name[64];
char *slash;
NEW(struct fuse, fuse, "fuse_new", exit(EXIT_FAILURE));
@ -1118,23 +1071,8 @@ fuse_new(struct fuse_chan *fc, struct fuse_args *args,
PUFFSOP_SET(pops, puffs_fuse, node, write);
PUFFSOP_SET(pops, puffs_fuse, node, reclaim);
/* work out what we'll call ourselves in df output */
if (args == NULL) {
args = fc->args;
}
if (args == NULL || args->argv == NULL || args->argv[0] == NULL) {
(void) strlcpy(name, "refuse", sizeof(name));
} else {
if ((slash = strrchr(*args->argv, '/')) == NULL) {
slash = *args->argv;
} else {
slash += 1;
}
(void) snprintf(name, sizeof(name), "refuse:%s", slash);
}
pu = puffs_mount(pops, fc->dir, MNT_NODEV | MNT_NOSUID,
name, NULL,
"refuse", NULL,
PUFFS_FLAG_BUILDPATH
| PUFFS_FLAG_OPDUMP
| PUFFS_KFLAG_NOCACHE,
@ -1143,18 +1081,6 @@ fuse_new(struct fuse_chan *fc, struct fuse_args *args,
err(EXIT_FAILURE, "puffs_mount");
}
fc->pu = pu;
/* whilst this (assigning the pu_privdata in the puffs
* usermount struct to be the fuse struct) might seem like
* we are chasing our tail here, the logic is as follows:
+ the operation wrapper gets called with the puffs
calling conventions
+ we need to fix up args first
+ then call the fuse user-supplied operation
+ then we fix up any values on return that we need to
+ and fix up any nodes, etc
* so we need to be able to get at the fuse ops from within the
* puffs_usermount struct
*/
pu->pu_privdata = fuse;
pu->pu_pn_root = newrn(pu);

View File

@ -1,4 +1,4 @@
/* $NetBSD: refuse_opt.c,v 1.3 2007/03/13 20:50:47 agc Exp $ */
/* $NetBSD: refuse_opt.c,v 1.4 2007/03/13 22:47:04 agc Exp $ */
/*-
* Copyright (c) 2007 Juan Romero Pardines.
@ -80,63 +80,28 @@ static int fuse_opt_popt(struct fuse_opt_option *, const struct fuse_opt *);
*
*/
#define ARGS_CHUNK 32
static int
growargs(struct fuse_args *args, const char *func)
{
if (args->allocated == 0) {
NEWARRAY(char *, args->argv, ARGS_CHUNK,
func, return 0);
args->allocated = ARGS_CHUNK;
} else if (args->argc % ARGS_CHUNK == 0) {
args->allocated += ARGS_CHUNK;
RENEW(char *, args->argv, args->allocated,
func, return 0);
}
return 1;
}
/* ARGSUSED */
int
fuse_opt_add_arg(struct fuse_args *args, const char *arg)
{
DPRINTF(("%s: arguments passed: [arg:%s]\n", __func__, arg));
if (!growargs(args, "fuse_opt_add_arg")) {
return 1;
}
args->argv[args->argc++] = strdup(arg);
return 0;
return EXIT_SUCCESS;
}
/* ARGSUSED */
void
fuse_opt_free_args(struct fuse_args *args)
{
int i;
for (i = 0 ; i < args->allocated ; i++) {
(void) free(args->argv[i]);
}
if (args->allocated > 0) {
FREE(args->argv);
}
(void) memset(args, 0x0, sizeof(*args));
/* nada */
}
/* ARGSUSED */
int
fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg)
{
int i;
__fuse_pargs("fuse_opt_insert_arg1", args->argc, args->argv);
if (!growargs(args, "fuse_opt_insert_arg")) {
return 1;
}
for (i = args->argc++ ; i > pos ; --i) {
args->argv[i] = args->argv[i - 1];
}
args->argv[pos] = strdup(arg);
__fuse_pargs("fuse_opt_insert_arg2", args->argc, args->argv);
return 0;
DPRINTF(("%s: arguments passed: [pos=%d] [arg=%s]\n",
__func__, pos, arg));
return EXIT_SUCCESS;
}
/* ARGSUSED */
@ -144,7 +109,7 @@ int fuse_opt_add_opt(char **opts, const char *opt)
{
DPRINTF(("%s: arguments passed: [opts=%s] [opt=%s]\n",
__func__, *opts, opt));
return 0;
return EXIT_SUCCESS;
}
/*
@ -156,10 +121,10 @@ fuse_opt_match(const struct fuse_opt *opts, const char *opt)
{
while (opts++) {
if (strcmp(opt, opts->templ) == 0)
return 0;
return EXIT_SUCCESS;
}
return 1;
return EXIT_FAILURE;
}
/*
@ -179,7 +144,7 @@ fuse_opt_popt(struct fuse_opt_option *foo, const struct fuse_opt *opts)
if (!foo->option) {
(void)fprintf(stderr, "fuse: missing argument after -o\n");
return 1;
return EXIT_FAILURE;
}
/*
* iterate over argv and opts to see
@ -222,11 +187,11 @@ fuse_opt_popt(struct fuse_opt_option *foo, const struct fuse_opt *opts)
if (!found) {
(void)fprintf(stderr, "fuse: '%s' is not a "
"valid option\n", match);
return 1;
return EXIT_FAILURE;
}
}
return 0;
return EXIT_SUCCESS;
}
/* ARGSUSED1 */
@ -236,18 +201,10 @@ fuse_opt_parse(struct fuse_args *args, void *data,
{
struct fuse_opt_option foo;
char *buf;
int i, rv = 0;
int i, rv = EXIT_SUCCESS;
if (!args || !args->argv || !args->argc || !proc) {
if (__fuse_debug(0)) {
printf("fuse_opt_parse: null args\n");
}
if (!args || !args->argv || !args->argc || !proc)
return 0;
}
if (__fuse_debug(0)) {
__fuse_pargs("fuse_opt_parse", args->argc, args->argv);
}
if (args->argc == 1)
return proc(foo.data, *args->argv, FUSE_OPT_KEY_OPT, args);
@ -305,7 +262,7 @@ fuse_opt_parse(struct fuse_args *args, void *data,
/* argument needs to be discarded */
if (foo.key == FUSE_OPT_KEY_DISCARD) {
rv = 1;
rv = EXIT_FAILURE;
break;
}
@ -326,7 +283,7 @@ fuse_opt_parse(struct fuse_args *args, void *data,
/* unknown option, how could that happen? */
} else {
DPRINTF(("%s: unknown option\n", __func__));
rv = 1;
rv = EXIT_FAILURE;
break;
}
}