fix
authorMiklos Szeredi <miklos@szeredi.hu>
Thu, 18 Nov 2004 10:16:14 +0000 (10:16 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Thu, 18 Nov 2004 10:16:14 +0000 (10:16 +0000)
ChangeLog
util/fusermount.c

index 38a2d9473e56c5bff40818c82fcdeec938248878..0235fbf1ad13d33c7858240da128eb3091498714 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,8 @@
        is '.' or '..'.  This new path resolvation is now done on mount as
        well as unmount.  This enables relative paths to work on unmount.
 
+       * fusermount: parse common mount options like "ro", "rw", etc...
+
        * Allow module params to be changed through sysfs
 
 2004-11-14  Miklos Szeredi <miklos@szeredi.hu>
index c8bfa5b83725dafd8951fd80141d35ae21719b7b..a25eccf2a527403dfb9564b3d9c7527e687d19df 100644 (file)
@@ -309,6 +309,49 @@ static int begins_with(const char *s, const char *beg)
         return 0;
 }
 
+struct mount_flags {
+    const char *opt;
+    unsigned long flag;
+    int on;
+    int safe;
+};
+
+static struct mount_flags mount_flags[] = {
+    {"rw",      MS_RDONLY,      0, 1},
+    {"ro",      MS_RDONLY,      1, 1},
+    {"suid",    MS_NOSUID,      0, 0},
+    {"nosuid",  MS_NOSUID,      1, 1},
+    {"dev",     MS_NODEV,       0, 0},
+    {"nodev",   MS_NODEV,       1, 1},
+    {"exec",    MS_NOEXEC,      0, 1},
+    {"noexec",  MS_NOEXEC,      1, 1},
+    {"async",   MS_SYNCHRONOUS, 0, 1},
+    {"sync",    MS_SYNCHRONOUS, 1, 1},
+    {"atime",   MS_NOATIME,     0, 1},
+    {"noatime", MS_NOATIME,     1, 1},
+    {NULL,      0,              0, 0}
+};
+
+static int find_mount_flag(const char *s, unsigned len, int *on, int *flag)
+{
+    int i;
+            
+    for (i = 0; mount_flags[i].opt != NULL; i++) {
+        const char *opt = mount_flags[i].opt;
+        if (strlen(opt) == len && strncmp(opt, s, len) == 0) {
+            *on = mount_flags[i].on;
+            *flag = mount_flags[i].flag;
+            if (!mount_flags[i].safe && getuid() != 0) {
+                *flag = 0;
+                fprintf(stderr, "%s: unsafe option %s ignored\n",
+                        progname, opt);
+            }
+            return 1;
+        }
+    }
+    return 0;
+}
+
 static int do_mount(const char *mnt, const char *type, mode_t rootmode,
                     int fd, const char *opts, char **fsnamep)
 {
@@ -344,9 +387,18 @@ static int do_mount(const char *mnt, const char *type, mode_t rootmode,
         } else if (!begins_with(s, "fd=") &&
                    !begins_with(s, "rootmode=") &&
                    !begins_with(s, "uid=")) {
-            memcpy(d, s, len);
-            d += len;
-            *d++ = ',';
+            int on;
+            int flag;
+            if (find_mount_flag(s, len, &on, &flag)) {
+                if (on)
+                    flags |= flag;
+                else
+                    flags  &= ~flag;
+            } else {
+                memcpy(d, s, len);
+                d += len;
+                *d++ = ',';
+            }
         }
         s += len;
         if (*s)