diff options
author | Pino Toscano <toscano.pino@tiscali.it> | 2013-03-22 17:55:16 +0100 |
---|---|---|
committer | Pino Toscano <toscano.pino@tiscali.it> | 2013-03-22 17:55:16 +0100 |
commit | 6ff1c4ce7e024833263a2cddba424bf5cb48ed42 (patch) | |
tree | 16c27a02f610c418acb6f9e144b4e5f2f6edb6ce | |
parent | b1f475196174db8bc750b545f23449dd5859d965 (diff) |
Create and use a fuse struct
Introduce a fuse struct and use it to hold a copy of the fuse_operation and their version,
and the private data returned by init.
* src/fuse_i.h (struct fuse): New.
(fuse_ops25): Remove.
(libfuse_fuse): New.
(FUSE_OP_HAVE, FUSE_OP_CALL): Use libfuse_fuse.
(fsys_privdata): Remove.
* src/main.c (fuse_ops25): Remove.
(libfuse_fuse): New.
(fsys_privdata): Remove.
(fuse_new): Create and fill a fuse struct.
(fuse_loop): Reject null F instead of anything but FUSE_MAGIC.
Set LIBFUSE_FUSE as F.
(fuse_loop_mt_proc): Likewise.
(fuse_demuxer): Use libfuse_fuse.
(fuse_process_cmd): Reject null F instead of anything but FUSE_MAGIC.
* src/netfs.c (refresh_context_struct): Use libfuse_fuse.
-rw-r--r-- | src/fuse_i.h | 19 | ||||
-rw-r--r-- | src/main.c | 44 | ||||
-rw-r--r-- | src/netfs.c | 4 |
3 files changed, 43 insertions, 24 deletions
diff --git a/src/fuse_i.h b/src/fuse_i.h index f4d49faca..922a64466 100644 --- a/src/fuse_i.h +++ b/src/fuse_i.h @@ -29,11 +29,19 @@ __FILE__ ":%d\nyou're welcome to put your effort to here.\n\n", \ __LINE__) -/* pointer to the fuse_operations structure of this translator process */ -extern const struct fuse_operations *fuse_ops25; +struct fuse { + int version; + union { + struct fuse_operations ops25; + } op; + void *private_data; +}; -#define FUSE_OP_HAVE(a) (fuse_ops25->a != NULL) -#define FUSE_OP_CALL(a,b...) (fuse_ops25->a(b)) +/* pointer to the fuse structure of this translator process */ +extern struct fuse *libfuse_fuse; + +#define FUSE_OP_HAVE(a) (libfuse_fuse->op.ops25.a != NULL) +#define FUSE_OP_CALL(a,b...) (libfuse_fuse->op.ops25.a(b)) #define NN_INFO(dir) ((void *) &(dir)->nn->info.info25) @@ -136,9 +144,6 @@ struct _libfuse_params { extern struct _libfuse_params libfuse_params; -/* the private data pointer returned from init() callback */ -extern void *fsys_privdata; - /* magic number, passed from fuse_mount to fuse_new */ #define FUSE_MAGIC ((int) 0x66757365) diff --git a/src/main.c b/src/main.c index d6e082f89..bb5585519 100644 --- a/src/main.c +++ b/src/main.c @@ -32,17 +32,14 @@ int netfs_maxsymlinks = 12; /* libfuse filesystem configuration */ struct _libfuse_params libfuse_params = { 0 }; -/* pointer to the fuse_operations structure of this translator process */ -const struct fuse_operations *fuse_ops25 = NULL; +/* pointer to the fuse structure of this translator process */ +struct fuse *libfuse_fuse = NULL; __thread struct fuse_context *libfuse_ctx; /* the port where to write out debug messages to, NULL to omit these */ FILE *debug_port = NULL; -/* the private data pointer returned from init() callback */ -void *fsys_privdata = NULL; - /* bootstrap fuse translator */ static int fuse_bootstrap(const char *mountpoint); @@ -274,8 +271,7 @@ struct fuse * fuse_new(int fd, struct fuse_args *args, const struct fuse_operations *op, size_t op_size) { - (void) op_size; /* FIXME, see what the real Fuse library does with - * this argument */ + struct fuse *new; if(fd != FUSE_MAGIC) return NULL; @@ -288,12 +284,26 @@ fuse_new(int fd, struct fuse_args *args, return NULL; } - fuse_ops25 = op; + new = calloc(1, sizeof *new); + if(! new) + return NULL; + + switch (op_size) + { + case sizeof(new->op.ops25): + new->version = 25; + break; + default: + fprintf(stderr, "Unhandled size of fuse_operations: %d\n", op_size); + fprintf(stderr, "libfuse will abort now\n"); + abort(); + } + memcpy(&new->op, op, op_size); - if(op->init) - fsys_privdata = op->init(); + if(new->op.ops25.init != NULL) + new->private_data = new->op.ops25.init(); - return (void *) FUSE_MAGIC; /* we don't have a fuse structure, sorry. */ + return new; } @@ -389,12 +399,14 @@ fuse_bootstrap(const char *mountpoint) int fuse_loop(struct fuse *f) { - if(f != ((void *) FUSE_MAGIC)) + if(! f) return -1; static int server_timeout = 1000 * 60 * 10; /* ten minutes, just like in * init-loop.c of libnetfs */ + libfuse_fuse = f; + ports_manage_port_operations_one_thread(netfs_port_bucket, netfs_demuxer, server_timeout); @@ -420,7 +432,7 @@ fuse_demuxer(mach_msg_header_t *inp, cmd.inp = inp; cmd.outp = outp; - fuse_proc((void *) FUSE_MAGIC, &cmd, fuse_proc_data); + fuse_proc(libfuse_fuse, &cmd, fuse_proc_data); return cmd.return_value; } @@ -428,7 +440,7 @@ fuse_demuxer(mach_msg_header_t *inp, void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) { - if(f != ((void *) FUSE_MAGIC)) + if(! f) { cmd->return_value = -1; return; @@ -458,7 +470,7 @@ fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data) static int server_timeout = 1000 * 60 * 10; /* ten minutes, just like in * init-loop.c of libnetfs */ - if(f != ((void *) FUSE_MAGIC)) + if(! f) return -1; /* copy the provided arguments to global variables to make them available @@ -466,6 +478,8 @@ fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data) fuse_proc = proc; fuse_proc_data = data; + libfuse_fuse = f; + ports_manage_port_operations_multithread(netfs_port_bucket, fuse_demuxer, thread_timeout, diff --git a/src/netfs.c b/src/netfs.c index f8d0d3973..d708b6254 100644 --- a/src/netfs.c +++ b/src/netfs.c @@ -68,8 +68,8 @@ refresh_context_struct(struct iouser *cred) libfuse_ctx = ctx; - ctx->fuse = (void *) FUSE_MAGIC; - ctx->private_data = fsys_privdata; + ctx->fuse = libfuse_fuse; + ctx->private_data = libfuse_fuse->private_data; /* FIXME, how to figure out the pid of the program asking for the * filesystem operation? */ |