diff options
author | Stefan Siegl <stesie@brokenpipe.de> | 2005-04-08 10:15:03 +0000 |
---|---|---|
committer | Stefan Siegl <stesie@brokenpipe.de> | 2005-04-08 10:15:03 +0000 |
commit | 7bb69f20bc15a2bf380de3dc8be7f941a0bef522 (patch) | |
tree | de692359306c7a0eca82c13560fd6c5af67aba93 | |
parent | a30104da1b25b3e5fa376609206843cc9eb8de87 (diff) |
Implemented fuse_new, fuse_mount and fuse_loop functions (including
compatibility ones). fuse_main adjusted accordingly.
-rw-r--r-- | main.c | 144 |
1 files changed, 122 insertions, 22 deletions
@@ -36,12 +36,17 @@ const struct fuse_operations_compat2 *fuse_ops_compat = NULL; /* the port where to write out debug messages to, NULL to omit these */ FILE *debug_port = NULL; -static int -_fuse_main(int argc, char *argv[], const struct fuse_operations *op) -{ - (void) op; /* handled by wrapper function */ +/* magic number, passed from fuse_mount to fuse_new */ +#define FUSE_MAGIC ((int) 0x66757365) - mach_port_t bootstrap, ul_node; + +/* Parse the command line arguments given to fuse_main (or _compat function). + * If --help specified, output help string and call exit. If there are any + * options that shall be passed to the file system itself, return them. + */ +static const char * +fuse_parse_argv(int argc, char *argv[]) +{ const char *translat_path = argv[0]; /* parse command line arguments */ @@ -80,9 +85,97 @@ _fuse_main(int argc, char *argv[], const struct fuse_operations *op) " -h print help\n" "\n", translat_path); - return opt_help == stdout ? 0 : 1; + exit(opt_help == stdout ? 0 : 1); } - + + return 0; +} + + + +/* Main function of FUSE. (compatibility one for old Fuse API) */ +int +fuse_main_compat2(int argc, char *argv[], + const struct fuse_operations_compat2 *op) +{ + const char *fs_opts = fuse_parse_argv(argc, argv); + int fd = fuse_mount(NULL, NULL); + return fuse_loop(fuse_new_compat2(fd, fs_opts, op)); +} + + + +/* Main function of FUSE. + * named fuse_main_real, since originial fuse.h defines a macro renaming it */ +int +fuse_main_real(int argc, char *argv[], + const struct fuse_operations *op, size_t op_size) +{ + const char *fs_opts = fuse_parse_argv(argc, argv); + int fd = fuse_mount(NULL, NULL); + return fuse_loop(fuse_new(fd, fs_opts, op, op_size)); +} + + + +/* Create a new FUSE filesystem, actually there's nothing for us to do + * on the Hurd. + * + * (Compatibility function for the old Fuse API) + */ +struct fuse * +fuse_new_compat2(int fd, const char *opts, + const struct fuse_operations_compat2 *op) +{ + if(fd != FUSE_MAGIC) + return NULL; + + if(opts) + fprintf(stderr, PACKAGE ": yet unable to parse options: %s\n", opts); + + fuse_ops_compat = op; + + return (void *) FUSE_MAGIC; /* we don't have a fuse structure, sorry. */ +} + + + +/* Create a new FUSE filesystem, actually there's nothing for us to do + * on the Hurd. + */ +struct fuse * +fuse_new(int fd, const char *opts, + const struct fuse_operations *op, size_t op_size) +{ + (void) op_size; /* FIXME, see what the real Fuse library does with + * this argument */ + + if(fd != FUSE_MAGIC) + return NULL; + + if(opts) + fprintf(stderr, PACKAGE ": yet unable to parse options: %s\n", opts); + + fuse_ops = op; + + return (void *) FUSE_MAGIC; /* we don't have a fuse structure, sorry. */ +} + + + +/* Create a new mountpoint for our fuse filesystem, i.e. do the netfs + * initialization stuff ... + */ +int +fuse_mount(const char *mountpoint, const char *opts) +{ + (void) mountpoint; /* we don't care for the specified mountpoint, as + * we need to be set up using settrans ... */ + + if(opts) + fprintf(stderr, PACKAGE ": yet unable to parse options: %s\n", opts); + + mach_port_t bootstrap, ul_node; task_get_bootstrap_port(mach_task_self(), &bootstrap); if(bootstrap == MACH_PORT_NULL) @@ -90,13 +183,14 @@ _fuse_main(int argc, char *argv[], const struct fuse_operations *op) /* no assigned bootstrap port, i.e. we got called as a * common program, not using settrans */ - fprintf(stderr, "%s: must be started as a translator.\n", translat_path); + fprintf(stderr, "program must be started as a translator.\n"); return EPERM; } /* we have got a bootstrap port, that is, we were set up * using settrans and may start with normal operation ... */ netfs_init(); + ul_node = netfs_startup(bootstrap, 0); /* create our root node */ @@ -111,27 +205,33 @@ _fuse_main(int argc, char *argv[], const struct fuse_operations *op) return -EAGAIN; } - netfs_server_loop(); - return 0; + return FUSE_MAGIC; } + int -fuse_main_compat2(int argc, char *argv[], - const struct fuse_operations_compat2 *op) +fuse_loop(struct fuse *f) { - /* initialize global fuse4hurd variables ... */ - fuse_ops_compat = op; + if(f != ((void *) FUSE_MAGIC)) + return -1; - return _fuse_main(argc, argv, (const struct fuse_operations *) op); + static int server_timeout = 1000 * 60 * 10; /* ten minutes, just like in + * init-loop.c of libnetfs */ + + ports_manage_port_operations_one_thread(netfs_port_bucket, + netfs_demuxer, + server_timeout); + return 0; } -int -fuse_main_real(int argc, char *argv[], - const struct fuse_operations *op, size_t op_size) -{ - /* initialize global fuse4hurd variables ... */ - fuse_ops = op; - return _fuse_main(argc, argv, op); +int +fuse_loop_mt(struct fuse *f) +{ + if(f != ((void *) FUSE_MAGIC)) + return -1; + + netfs_server_loop(); + return 0; } |