aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2003-12-11 14:27:57 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2003-12-11 14:27:57 +0000
commit874d95da5b55ac16daba1edf3b0651a2e6a631a8 (patch)
treef7d8012df38c561cec8af6d58e74b5e1f2a04aa8 /util
parent406bf11df0a7737104f3d1ff99c47b73cac745ae (diff)
fix
Diffstat (limited to 'util')
-rw-r--r--util/fusermount.c34
-rw-r--r--util/mount.fuse85
2 files changed, 118 insertions, 1 deletions
diff --git a/util/fusermount.c b/util/fusermount.c
index f223c5f..c451c41 100644
--- a/util/fusermount.c
+++ b/util/fusermount.c
@@ -59,6 +59,33 @@ static const char *get_user_name()
}
}
+/* use a lock file so that multiple fusermount processes don't try and
+ modify the mtab file at once! */
+static int lock_mtab()
+{
+ const char *mtab_lock = _PATH_MOUNTED ".fuselock";
+ int mtablock;
+ int res;
+
+ mtablock = open(mtab_lock, O_RDWR | O_CREAT, 0600);
+ if(mtablock >= 0) {
+ res = lockf(mtablock, F_LOCK, 0);
+ if(res < 0)
+ perror("error getting lock: %s");
+ } else
+ fprintf(stderr, "unable to open fuse lock file, continuing anyway\n");
+
+ return mtablock;
+}
+
+static void unlock_mtab(int mtablock)
+{
+ if(mtablock >= 0) {
+ lockf(mtablock, F_ULOCK, 0);
+ close(mtablock);
+ }
+}
+
static int add_mount(const char *dev, const char *mnt, const char *type)
{
int res;
@@ -343,6 +370,7 @@ static int mount_fuse(const char *mnt, int flags)
const char *dev = FUSE_DEV;
const char *type = "fuse";
struct stat stbuf;
+ int mtablock;
res = check_perm(mnt, &stbuf);
if(res == -1)
@@ -371,8 +399,10 @@ static int mount_fuse(const char *mnt, int flags)
res = do_mount(dev, mnt, type, stbuf.st_mode & S_IFMT, fd, flags);
if(res == -1)
return -1;
-
+
+ mtablock = lock_mtab();
res = add_mount(dev, mnt, type);
+ unlock_mtab(mtablock);
if(res == -1) {
umount(mnt);
return -1;
@@ -530,7 +560,9 @@ int main(int argc, char *argv[])
restore_privs();
if(unmount) {
+ int mtablock = lock_mtab();
res = remove_mount(mnt);
+ unlock_mtab(mtablock);
if(res == -1)
exit(1);
diff --git a/util/mount.fuse b/util/mount.fuse
new file mode 100644
index 0000000..4ec1409
--- /dev/null
+++ b/util/mount.fuse
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+#@+leo-ver=4
+#@+node:@file mount.fuse
+#@@first #!/usr/bin/env python
+
+"""
+This utility allows FUSE filesystems to be mounted with the regular *nix
+'mount' command, or even be listed in /etc/fstab
+
+To enable this, you need to:
+ 1. set execute-permission on this script
+ 2. symlink this script into /sbin/mount.fuse
+
+Usage:
+
+ You can use this in 3 ways:
+ 1. mount -t fuse /path/to/script/or/program /path/of/mount/point [options]
+ 2. mount -t fuse none /path/of/mount/point -o fs=/path/to/script/or/prog[,opt=val...]
+ 3. in /etc/fstab, add:
+ /path/to/script/or/prog /path/of/mount/point fuse noauto[,...]
+"""
+
+import sys, os, time
+
+progname = sys.argv[0]
+
+def usage(ret):
+ print "Usage: %s /path/to/fuse/fs /path/of/mountpoint [-o options]" % progname
+ print "or: %s none /path/of/mountpoint [-o fs=/path/to/fuse/fs[,...]]" % progname
+ sys.exit(ret)
+
+def main():
+
+ # initial sanity check
+ argc = len(sys.argv)
+ if argc < 3 or sys.argv[3] != "-o":
+ usage(1)
+
+ dev = sys.argv[1]
+ mountpoint = sys.argv[2]
+
+ # grab options, if any
+ optdict = {}
+ optlist = []
+ if argc > 4:
+ odata = sys.argv[4]
+ opts = odata.split(",")
+ #print opts
+ for o in opts:
+ try:
+ k, v = o.split("=", 1)
+ optdict[k] = v
+ except:
+ optlist.append(o)
+ else:
+ odata = ""
+
+ #print sys.argv
+ if dev == 'none':
+ if not optdict.has_key("fs"):
+ print "%s: Must specify python file with 'fs' option\n" % progname
+ usage(1)
+ pyfile = optdict['fs']
+ else:
+ pyfile = dev
+
+ if not os.path.isfile(pyfile):
+ print "%s: file %s doesn't exist, or is not a file" % (progname, pyfile)
+ sys.exit(1)
+ pypath = os.path.abspath(pyfile)
+
+ #print optdict, optlist
+
+ # all seems ok - run our fuse fs as a child
+ if os.fork() == 0:
+ os.system("fusermount -c -x %s %s %s %s" % (mountpoint, pypath, mountpoint, odata))
+ else:
+ #print "parent exiting..."
+ pass
+
+if __name__ == '__main__':
+ main()
+
+#@-node:@file mount.fuse
+#@-leo