From c40748abd7f911b3c622600bd23b8517bd8f09c4 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Fri, 20 Feb 2004 16:38:45 +0000 Subject: fix --- lib/fuse.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/fuse.c') 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; -- cgit v1.2.3