diff options
Diffstat (limited to 'lib/fuse.c')
-rw-r--r-- | lib/fuse.c | 103 |
1 files changed, 57 insertions, 46 deletions
@@ -2,6 +2,9 @@ FUSE: Filesystem in Userspace Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> + Implementation of the high-level FUSE API on top of the low-level + API. + This program can be distributed under the terms of the GNU LGPLv2. See the file COPYING.LIB */ @@ -77,7 +80,7 @@ struct fuse_config { int auto_cache; int intr; int intr_signal; - int help; + int show_help; char *modules; }; @@ -4318,9 +4321,8 @@ static int fuse_session_loop_remember(struct fuse *f) int res = 0; struct timespec now; time_t next_clean; - struct fuse_chan *ch = fuse_session_chan(se); struct pollfd fds = { - .fd = ch->fd, + .fd = se->fd, .events = POLLIN }; struct fuse_buf fbuf = { @@ -4345,14 +4347,14 @@ static int fuse_session_loop_remember(struct fuse *f) else break; } else if (res > 0) { - res = fuse_session_receive_buf_int(se, &fbuf, ch); + res = fuse_session_receive_buf_int(se, &fbuf, NULL); if (res == -EINTR) continue; if (res <= 0) break; - fuse_session_process_buf_int(se, &fbuf, ch); + fuse_session_process_buf_int(se, &fbuf, NULL); } else { timeout = fuse_clean_cache(f); curr_time(&now); @@ -4376,6 +4378,20 @@ int fuse_loop(struct fuse *f) return fuse_session_loop(f->se); } +int fuse_loop_mt(struct fuse *f) +{ + if (f == NULL) + return -1; + + int res = fuse_start_cleanup_thread(f); + if (res) + return -1; + + res = fuse_session_loop_mt(fuse_get_session(f)); + fuse_stop_cleanup_thread(f); + return res; +} + void fuse_exit(struct fuse *f) { fuse_session_exit(f->se); @@ -4410,15 +4426,11 @@ int fuse_interrupted(void) return 0; } -enum { - KEY_HELP, -}; - #define FUSE_LIB_OPT(t, p, v) { t, offsetof(struct fuse_config, p), v } static const struct fuse_opt fuse_lib_opts[] = { - FUSE_OPT_KEY("-h", KEY_HELP), - FUSE_OPT_KEY("--help", KEY_HELP), + FUSE_LIB_OPT("-h", show_help, 1), + FUSE_LIB_OPT("--help", show_help, 1), FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP), FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP), FUSE_LIB_OPT("debug", debug, 1), @@ -4453,6 +4465,7 @@ static const struct fuse_opt fuse_lib_opts[] = { static void fuse_lib_help(void) { printf( +"High-level options\n" " -o hard_remove immediate removal (don't hide files)\n" " -o use_ino let filesystem set inode numbers\n" " -o readdir_ino try to fill in d_ino in readdir\n" @@ -4471,8 +4484,8 @@ static void fuse_lib_help(void) " -o nopath don't supply path if not necessary\n" " -o intr allow requests to be interrupted\n" " -o intr_signal=NUM signal to send on interrupt (%i)\n" -" -o modules=M1[:M2...] names of modules to push onto filesystem stack\n" -"\n", FUSE_DEFAULT_INTR_SIGNAL); +" -o modules=M1[:M2...] names of modules to push onto filesystem stack\n\n", + FUSE_DEFAULT_INTR_SIGNAL); } static void fuse_lib_help_modules(void) @@ -4498,14 +4511,9 @@ static void fuse_lib_help_modules(void) static int fuse_lib_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { - (void) arg; (void) outargs; - - if (key == KEY_HELP) { - struct fuse_config *conf = (struct fuse_config *) data; - fuse_lib_help(); - conf->help = 1; - } + (void) arg; (void) outargs; (void) data; (void) key; + /* Pass through unknown options */ return 1; } @@ -4640,6 +4648,25 @@ struct fuse *fuse_new(struct fuse_args *args, struct fuse_fs *fs; struct fuse_lowlevel_ops llop = fuse_path_ops; + f = (struct fuse *) calloc(1, sizeof(struct fuse)); + if (f == NULL) { + fprintf(stderr, "fuse: failed to allocate fuse object\n"); + goto out; + } + + /* Parse options */ + if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, + fuse_lib_opt_proc) == -1) + goto out_free; + + if (f->conf.show_help) { + fuse_lib_help(); + fuse_lowlevel_help(); + fuse_mount_help(); + /* Defer printing module help until modules + have been loaded */ + } + pthread_mutex_lock(&fuse_context_lock); static int builtin_modules_registered = 0; /* Have the builtin modules already been registered? */ @@ -4651,19 +4678,12 @@ struct fuse *fuse_new(struct fuse_args *args, } pthread_mutex_unlock(&fuse_context_lock); - if (fuse_create_context_key() == -1) - goto out; - - f = (struct fuse *) calloc(1, sizeof(struct fuse)); - if (f == NULL) { - fprintf(stderr, "fuse: failed to allocate fuse object\n"); - goto out_delete_context_key; - } + goto out_free; fs = fuse_fs_new(op, op_size, user_data); if (!fs) - goto out_free; + goto out_delete_context_key; f->fs = fs; f->conf.nopath = fs->op.flag_nopath; @@ -4684,13 +4704,6 @@ struct fuse *fuse_new(struct fuse_args *args, init_list_head(&f->full_slabs); init_list_head(&f->lru_table); - /* When --help or --version are specified, we print messages - to stderr but continue for now (and keep the arguments in - `args` for use below */ - if (fuse_opt_parse(args, &f->conf, fuse_lib_opts, - fuse_lib_opt_proc) == -1) - goto out_free_fs; - if (f->conf.modules) { char *module; char *next; @@ -4706,6 +4719,11 @@ struct fuse *fuse_new(struct fuse_args *args, } } + if(f->conf.show_help) { + fuse_lib_help_modules(); + goto out_free_fs; + } + if (!f->conf.ac_attr_timeout_set) f->conf.ac_attr_timeout = f->conf.attr_timeout; @@ -4717,16 +4735,9 @@ struct fuse *fuse_new(struct fuse_args *args, f->conf.readdir_ino = 1; #endif - /* This function will return NULL if there is an --help - or --version argument in `args` */ f->se = fuse_session_new(args, &llop, sizeof(llop), f); - if (f->se == NULL) { - /* If we've printed help before, add module help at - * the end */ - if (f->conf.help) - fuse_lib_help_modules(); + if (f->se == NULL) goto out_free_fs; - } if (f->conf.debug) { fprintf(stderr, "nopath: %i\n", f->conf.nopath); @@ -4782,10 +4793,10 @@ out_free_fs: fuse_put_module(f->fs->m); free(f->fs); free(f->conf.modules); -out_free: - free(f); out_delete_context_key: fuse_delete_context_key(); +out_free: + free(f); out: return NULL; } |