summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPino Toscano <toscano.pino@tiscali.it>2013-03-22 17:55:16 +0100
committerPino Toscano <toscano.pino@tiscali.it>2013-03-22 17:55:16 +0100
commit6ff1c4ce7e024833263a2cddba424bf5cb48ed42 (patch)
tree16c27a02f610c418acb6f9e144b4e5f2f6edb6ce /src/main.c
parentb1f475196174db8bc750b545f23449dd5859d965 (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.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c44
1 files changed, 29 insertions, 15 deletions
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,