aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2004-02-20 16:38:45 +0000
committerMiklos Szeredi <miklos@szeredi.hu>2004-02-20 16:38:45 +0000
commitc40748abd7f911b3c622600bd23b8517bd8f09c4 (patch)
tree3921bd77bcb57f36365cff93fb2bbe54af19b1d1 /lib
parentb59586199b5c53fa7002e9e1e6accc08a515f420 (diff)
downloadlibfuse-c40748abd7f911b3c622600bd23b8517bd8f09c4.tar.gz
fix
Diffstat (limited to 'lib')
-rw-r--r--lib/fuse.c37
-rw-r--r--lib/fuse_i.h2
-rw-r--r--lib/fuse_mt.c3
-rw-r--r--lib/helper.c43
4 files changed, 50 insertions, 35 deletions
diff --git a/lib/fuse.c b/lib/fuse.c
index 2e6950d..9d0783d 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -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);