diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fuse.c | 37 | ||||
-rw-r--r-- | lib/fuse_i.h | 2 | ||||
-rw-r--r-- | lib/fuse_mt.c | 3 | ||||
-rw-r--r-- | lib/helper.c | 43 |
4 files changed, 50 insertions, 35 deletions
@@ -1106,6 +1106,9 @@ struct fuse_cmd *__fuse_read_cmd(struct fuse *f) void fuse_loop(struct fuse *f) { + if(f == NULL) + return; + while(1) { struct fuse_cmd *cmd; @@ -1133,6 +1136,35 @@ struct fuse_context *fuse_get_context(struct fuse *f) return &f->context; } +static int check_version(struct fuse *f) +{ + int res; + FILE *vf = fopen(FUSE_VERSION_FILE, "r"); + if(vf == NULL) { + fprintf(stderr, "fuse: kernel interface too old, need >= %i.%i\n", + FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); + return -1; + } + res = fscanf(vf, "%i.%i", &f->majorver, &f->minorver); + fclose(vf); + if(res != 2) { + fprintf(stderr, "fuse: error reading %s\n", FUSE_VERSION_FILE); + return -1; + } + if(f->majorver != FUSE_KERNEL_VERSION) { + fprintf(stderr, "fuse: bad kernel interface major version: needs %i\n", + FUSE_KERNEL_VERSION); + return -1; + } + if(f->minorver < FUSE_KERNEL_MINOR_VERSION) { + fprintf(stderr, "fuse: kernel interface too old: need >= %i.%i", + FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); + return -1; + } + + return 0; +} + struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op) { struct fuse *f; @@ -1140,6 +1172,11 @@ struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op) f = (struct fuse *) calloc(1, sizeof(struct fuse)); + if(check_version(f) == -1) { + free(f); + return NULL; + } + f->flags = flags; f->fd = fd; f->ctr = 0; diff --git a/lib/fuse_i.h b/lib/fuse_i.h index 4eaa5ba..ce81604 100644 --- a/lib/fuse_i.h +++ b/lib/fuse_i.h @@ -41,6 +41,8 @@ struct fuse { struct fuse_context context; pthread_key_t context_key; volatile int exited; + int majorver; + int minorver; }; struct fuse_dirhandle { diff --git a/lib/fuse_mt.c b/lib/fuse_mt.c index f1a2e5c..40da6ed 100644 --- a/lib/fuse_mt.c +++ b/lib/fuse_mt.c @@ -114,5 +114,8 @@ void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data) void fuse_loop_mt(struct fuse *f) { + if(f == NULL) + return; + __fuse_loop_mt(f, (fuse_processor_t) __fuse_process_cmd, NULL); } diff --git a/lib/helper.c b/lib/helper.c index d417d90..7cbb9eb 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -15,9 +15,6 @@ #include <limits.h> #include <signal.h> -#define FUSE_MOUNTED_ENV "_FUSE_MOUNTED" -#define FUSE_UMOUNT_CMD_ENV "_FUSE_UNMOUNT_CMD" - static struct fuse *fuse; static void usage(char *progname) @@ -73,21 +70,14 @@ static void set_signal_handlers() void fuse_main(int argc, char *argv[], const struct fuse_operations *op) { - int argctr = 1; + int argctr = 2; int flags; int multithreaded; - char *isreexec = getenv(FUSE_MOUNTED_ENV); int fuse_fd; char *fuse_mountpoint = NULL; char umount_cmd[1024] = ""; char **fusermount_args = NULL; - if(!isreexec) { - if(argc < 2 || argv[1][0] == '-') - usage(argv[0]); - argctr ++; - } - flags = 0; multithreaded = 1; for(; argctr < argc && !fusermount_args; argctr ++) { @@ -106,10 +96,7 @@ void fuse_main(int argc, char *argv[], const struct fuse_operations *op) break; case '-': - if(!isreexec) - fusermount_args = &argv[argctr+1]; - else - invalid_option(argv, argctr); + fusermount_args = &argv[argctr+1]; break; default: @@ -119,30 +106,16 @@ void fuse_main(int argc, char *argv[], const struct fuse_operations *op) invalid_option(argv, argctr); } - if(!isreexec) { - fuse_mountpoint = strdup(argv[1]); - fuse_fd = fuse_mount(fuse_mountpoint, (const char **) fusermount_args); - if(fuse_fd == -1) - exit(1); - } else { - char *tmpstr; - - /* Old (obsolescent) way of doing the mount: - - fusermount [options] mountpoint [program [args ...]] - - fusermount execs this program and passes the control file - descriptor dup()-ed to stdin */ - fuse_fd = 0; - - tmpstr = getenv(FUSE_UMOUNT_CMD_ENV); - if(tmpstr != NULL) - strncpy(umount_cmd, tmpstr, sizeof(umount_cmd) - 1); - } + fuse_mountpoint = strdup(argv[1]); + fuse_fd = fuse_mount(fuse_mountpoint, (const char **) fusermount_args); + if(fuse_fd == -1) + exit(1); set_signal_handlers(); fuse = fuse_new(fuse_fd, flags, op); + if(fuse == NULL) + exit(1); if(multithreaded) fuse_loop_mt(fuse); |