diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 1 | ||||
-rw-r--r-- | lib/fuse.c | 18 | ||||
-rw-r--r-- | lib/fuse_i.h | 4 | ||||
-rw-r--r-- | lib/mount.c | 145 |
4 files changed, 3 insertions, 165 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 98bfedc..f970b11 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,5 +4,4 @@ lib_LIBRARIES = libfuse.a libfuse_a_SOURCES = \ fuse.c \ - mount.c \ fuse_i.h @@ -932,26 +932,15 @@ void fuse_loop(struct fuse *f) } } -struct fuse *fuse_new(int flags, mode_t rootmode) +struct fuse *fuse_new(int fd, int flags) { struct fuse *f; struct node *root; f = (struct fuse *) calloc(1, sizeof(struct fuse)); - if(!rootmode) - rootmode = S_IFDIR; - - if(!S_ISDIR(rootmode) && !S_ISREG(rootmode)) { - fprintf(stderr, "Invalid mode for root: 0%o\n", rootmode); - rootmode = S_IFDIR; - } - rootmode &= S_IFMT; - f->flags = flags; - f->rootmode = rootmode; - f->fd = -1; - f->mnt = NULL; + f->fd = fd; f->ctr = 0; f->name_table_size = 14057; f->name_table = (struct node **) @@ -962,7 +951,7 @@ struct fuse *fuse_new(int flags, mode_t rootmode) pthread_mutex_init(&f->lock, NULL); root = (struct node *) calloc(1, sizeof(struct node)); - root->mode = rootmode; + root->mode = 0; root->rdev = 0; root->name = strdup("/"); root->parent = 0; @@ -979,7 +968,6 @@ void fuse_set_operations(struct fuse *f, const struct fuse_operations *op) void fuse_destroy(struct fuse *f) { size_t i; - close(f->fd); for(i = 0; i < f->ino_table_size; i++) { struct node *node; struct node *next; diff --git a/lib/fuse_i.h b/lib/fuse_i.h index 263ebe2..4d3e042 100644 --- a/lib/fuse_i.h +++ b/lib/fuse_i.h @@ -10,8 +10,6 @@ #include <stdio.h> #include <pthread.h> -#define FUSE_DEV "/proc/fs/fuse/dev" - typedef unsigned long fino_t; struct node { @@ -27,8 +25,6 @@ struct node { struct fuse { int flags; - char *mnt; - mode_t rootmode; int fd; struct fuse_operations op; struct node **name_table; diff --git a/lib/mount.c b/lib/mount.c deleted file mode 100644 index d191a7d..0000000 --- a/lib/mount.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - FUSE: Filesystem in Userspace - Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu) - - This program can be distributed under the terms of the GNU GPL. - See the file COPYING. -*/ - -#include "fuse_i.h" -#include <linux/fuse.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <fcntl.h> -#include <sys/mount.h> -#include <mntent.h> - -static int do_mount(const char *dev, const char *dir, const char *type, - mode_t rootmode, int fd) -{ - int res; - struct fuse_mount_data data; - - data.version = FUSE_KERNEL_VERSION; - data.fd = fd; - data.rootmode = rootmode; - - res = mount(dev, dir, type, MS_MGC_VAL | MS_NOSUID | MS_NODEV, &data); - if(res == -1) { - perror("mount failed"); - return -1; - } - - return 0; -} - -static void add_mntent(const char *dev, const char *dir, const char *type) -{ - int res; - FILE *fp; - struct mntent ent; - - fp = setmntent("/etc/mtab", "a"); - if(fp == NULL) { - perror("setmntent"); - return; - } - - ent.mnt_fsname = (char *) dev; - ent.mnt_dir = (char *) dir; - ent.mnt_type = (char *) type; - ent.mnt_opts = "rw,nosuid,nodev"; - ent.mnt_freq = 0; - ent.mnt_passno = 0; - res = addmntent(fp, & ent); - if(res != 0) - perror("addmntent"); - - endmntent(fp); - -} - -static void remove_mntent(const char *dir) -{ - int res; - FILE *fdold, *fdnew; - struct mntent *entp; - - fdold = setmntent("/etc/mtab", "r"); - if(fdold == NULL) { - perror("/etc/mtab"); - return; - } - - fdnew = setmntent("/etc/mtab~", "w"); - if(fdnew == NULL) { - perror("/etc/mtab~"); - return; - } - - do { - entp = getmntent(fdold); - if(entp != NULL && strcmp(entp->mnt_dir, dir) != 0) { - res = addmntent(fdnew, entp); - if(res != 0) - perror("addmntent"); - } - } while(entp != NULL); - - endmntent(fdold); - endmntent(fdnew); - - res = rename("/etc/mtab~", "/etc/mtab"); - if(res == -1) - perror("renameing /etc/mtab~ to /etc/mtab"); -} - -int fuse_mount(struct fuse *f, const char *dir) -{ - int res; - const char *dev = FUSE_DEV; - const char *type = "fuse"; - - if(f->mnt != NULL) - return 0; - - f->fd = open(dev, O_RDWR); - if(f->fd == -1) { - perror(dev); - return -1; - } - - res = do_mount(dev, dir, type, f->rootmode, f->fd); - if(res == -1) - return -1; - - add_mntent(dev, dir, type); - f->mnt = strdup(dir); - - return 0; -} - -int fuse_unmount(struct fuse *f) -{ - int res; - - if(f->mnt == NULL) - return 0; - - close(f->fd); - f->fd = -1; - - res = umount(f->mnt); - if(res == -1) - perror("umount failed"); - else - remove_mntent(f->mnt); - - free(f->mnt); - f->mnt = NULL; - - return res; -} |