From 6012dfe6b9c4d69914078cc0b716bf11aac5e957 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Tue, 15 May 2012 13:41:57 +0530 Subject: fuse: reorganize mounting code Macro-driven conditional compilation was a chaos. New scheme is: contrib/fuse-lib/mount-common.c: libfuse routines used both by glusterfs and fusermount contrib/fuse-lib/mount.c: libfuse-derived but customized mounting code for glusterfs contrib/fuse-util/mount_util.c: libfuse routines used only by fusermount Change-Id: I3e0ba7f74e36556b78244cd7676eb4d379939602 BUG: 762389 Signed-off-by: Csaba Henk Reviewed-on: http://review.gluster.com/3342 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- contrib/fuse-util/Makefile.am | 6 ++-- contrib/fuse-util/mount_util.c | 64 ++++++++++++++++++++++++++++++++++++++++++ contrib/fuse-util/mount_util.h | 18 ------------ 3 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 contrib/fuse-util/mount_util.c delete mode 100644 contrib/fuse-util/mount_util.h (limited to 'contrib/fuse-util') diff --git a/contrib/fuse-util/Makefile.am b/contrib/fuse-util/Makefile.am index a72e3832b16..6e9b31c7756 100644 --- a/contrib/fuse-util/Makefile.am +++ b/contrib/fuse-util/Makefile.am @@ -1,9 +1,9 @@ bin_PROGRAMS = fusermount-glusterfs -fusermount_glusterfs_SOURCES = fusermount.c $(CONTRIBDIR)/fuse-lib/mount.c -noinst_HEADERS = mount_util.h +fusermount_glusterfs_SOURCES = fusermount.c mount_util.c $(CONTRIBDIR)/fuse-lib/mount-common.c +noinst_HEADERS = $(CONTRIBDIR)/fuse-include/mount_util.h -AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DFUSE_UTIL $(GF_CFLAGS) -D_GNU_SOURCE +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DFUSE_UTIL $(GF_CFLAGS) -D_GNU_SOURCE -I$(CONTRIBDIR)/fuse-include install-exec-hook: -chown root $(DESTDIR)$(bindir)/fusermount-glusterfs diff --git a/contrib/fuse-util/mount_util.c b/contrib/fuse-util/mount_util.c new file mode 100644 index 00000000000..911b84445e9 --- /dev/null +++ b/contrib/fuse-util/mount_util.c @@ -0,0 +1,64 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2007 Miklos Szeredi + + This program can be distributed under the terms of the GNU LGPLv2. + See the file COPYING.LIB. +*/ + +#include +#include +#include +#include +#include +#include + +int fuse_mnt_check_empty(const char *progname, const char *mnt, + mode_t rootmode, off_t rootsize) +{ + int isempty = 1; + + if (S_ISDIR(rootmode)) { + struct dirent *ent; + DIR *dp = opendir(mnt); + if (dp == NULL) { + fprintf(stderr, + "%s: failed to open mountpoint for reading: %s\n", + progname, strerror(errno)); + return -1; + } + while ((ent = readdir(dp)) != NULL) { + if (strcmp(ent->d_name, ".") != 0 && + strcmp(ent->d_name, "..") != 0) { + isempty = 0; + break; + } + } + closedir(dp); + } else if (rootsize) + isempty = 0; + + if (!isempty) { + fprintf(stderr, "%s: mountpoint is not empty\n", progname); + fprintf(stderr, "%s: if you are sure this is safe, use the 'nonempty' mount option\n", progname); + return -1; + } + return 0; +} + +int fuse_mnt_check_fuseblk(void) +{ + char buf[256]; + FILE *f = fopen("/proc/filesystems", "r"); + if (!f) + return 1; + + while (fgets(buf, sizeof(buf), f)) + if (strstr(buf, "fuseblk\n")) { + fclose(f); + return 1; + } + + fclose(f); + return 0; +} diff --git a/contrib/fuse-util/mount_util.h b/contrib/fuse-util/mount_util.h deleted file mode 100644 index f392f99f17a..00000000000 --- a/contrib/fuse-util/mount_util.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - FUSE: Filesystem in Userspace - Copyright (C) 2001-2007 Miklos Szeredi - - This program can be distributed under the terms of the GNU LGPLv2. - See the file COPYING.LIB. -*/ - -#include - -int fuse_mnt_add_mount(const char *progname, const char *fsname, - const char *mnt, const char *type, const char *opts); -int fuse_mnt_umount(const char *progname, const char *abs_mnt, - const char *rel_mnt, int lazy); -char *fuse_mnt_resolve_path(const char *progname, const char *orig); -int fuse_mnt_check_empty(const char *progname, const char *mnt, - mode_t rootmode, off_t rootsize); -int fuse_mnt_check_fuseblk(void); -- cgit