]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: don't use /{proc,ext}/filesystems when more fs types specified
authorKarel Zak <kzak@redhat.com>
Fri, 25 Jul 2014 10:28:34 +0000 (12:28 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 25 Jul 2014 10:28:34 +0000 (12:28 +0200)
 # mkfs.ext4 /dev/sda1
 # mount -t foo,bar /dev/sda1 /mnt

successfully mount the device, this is unexpected as extN is no
between wanted (by -t specified) filesystems.

Summary about -t:

 * "mount -t foo"        mount(2) with "foo" type

 * "mount -t foo,bar"    try mount(2) with "foo" or "bar"

 * "mount -t foo,auto"   try mount(2) with "foo" or ask libblkid for
                         the type

 * "mount -t nofoo,bar"  try types from /{etc,proc}/filesystems, but
                         exclude "foo" and "bar"

Note that more filesystems may be specified in fstab (as comma
delimited list). The stuff from fstab is always interpreted as list
and never as a pattern ("no" prefix makes no sense in fstab).

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c
sys-utils/mount.c

index 14ae65254c9ec72e00463e0cc1484e228e16c41c..015171e3c09183dd2d091e993e3a9fb4a3a527c0 100644 (file)
@@ -758,63 +758,75 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
        return rc;
 }
 
-static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern)
+/* try mount(2) for all items in comma separated list of the filesystem @types */
+static int do_mount_by_types(struct libmnt_context *cxt, const char *types)
 {
-       int neg = pattern && strncmp(pattern, "no", 2) == 0;
        int rc = -EINVAL;
-       char **filesystems, **fp;
+       char *p, *p0;
 
        assert(cxt);
        assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
 
-       if (!neg && pattern) {
-               /*
-                * try all types from the list
-                */
-               char *p, *p0;
-
-               DBG(CXT, ul_debugobj(cxt, "trying to mount by FS pattern list '%s'", pattern));
+       DBG(CXT, ul_debugobj(cxt, "trying to mount by FS list '%s'", types));
 
-               p0 = p = strdup(pattern);
-               if (!p)
-                       return -ENOMEM;
-               do {
-                       char *autotype = NULL;
-                       char *end = strchr(p, ',');
-
-                       if (end)
-                               *end = '\0';
-
-                       DBG(CXT, ul_debugobj(cxt, "-->trying '%s'", p));
-
-                       /* Let's support things like "udf,iso9660,auto" */
-                       if (strcmp(p, "auto") == 0) {
-                               rc = mnt_context_guess_srcpath_fstype(cxt, &autotype);
-                               if (rc) {
-                                       DBG(CXT, ul_debugobj(cxt, "failed to guess FS type"));
-                                       free(p0);
-                                       return rc;
-                               }
-                               p = autotype;
-                               DBG(CXT, ul_debugobj(cxt, "   --> '%s'", p));
+       p0 = p = strdup(types);
+       if (!p)
+               return -ENOMEM;
+       do {
+               char *autotype = NULL;
+               char *end = strchr(p, ',');
+
+               if (end)
+                       *end = '\0';
+
+               DBG(CXT, ul_debugobj(cxt, "-->trying '%s'", p));
+
+               /* Let's support things like "udf,iso9660,auto" */
+               if (strcmp(p, "auto") == 0) {
+                       rc = mnt_context_guess_srcpath_fstype(cxt, &autotype);
+                       if (rc) {
+                               DBG(CXT, ul_debugobj(cxt, "failed to guess FS type"));
+                               free(p0);
+                               return rc;
                        }
+                       p = autotype;
+                       DBG(CXT, ul_debugobj(cxt, "   --> '%s'", p));
+               }
 
-                       if (p)
-                               rc = do_mount(cxt, p);
-                       p = end ? end + 1 : NULL;
-                       free(autotype);
-               } while (!mnt_context_get_status(cxt) && p);
+               if (p)
+                       rc = do_mount(cxt, p);
+               p = end ? end + 1 : NULL;
+               free(autotype);
+       } while (!mnt_context_get_status(cxt) && p);
 
-               free(p0);
+       free(p0);
+       return rc;
+}
 
-               if (mnt_context_get_status(cxt))
-                       return rc;
+
+static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern)
+{
+       int neg = pattern && strncmp(pattern, "no", 2) == 0;
+       int rc = -EINVAL;
+       char **filesystems, **fp;
+
+       assert(cxt);
+       assert((cxt->flags & MNT_FL_MOUNTFLAGS_MERGED));
+
+
+       /*
+        * Use the pattern as list of the filesystems
+        */
+       if (!neg && pattern) {
+               DBG(CXT, ul_debugobj(cxt, "use FS pattern as FS list"));
+               return do_mount_by_types(cxt, pattern);
        }
 
+       DBG(CXT, ul_debugobj(cxt, "trying to mount by FS pattern '%s'", pattern));
+
        /*
-        * try /etc/filesystems and /proc/filesystems
+        * Apply pattern to /etc/filesystems and /proc/filesystems
         */
-       DBG(CXT, ul_debugobj(cxt, "trying to mount by filesystems lists"));
 
        rc = mnt_get_filesystems(&filesystems, neg ? pattern : NULL);
        if (rc)
@@ -930,7 +942,7 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
        if (type) {
                if (strchr(type, ','))
                        /* this only happens if fstab contains a list of filesystems */
-                       res = do_mount_by_pattern(cxt, type);
+                       res = do_mount_by_types(cxt, type);
                else
                        res = do_mount(cxt, NULL);
        } else
index 74a1a84f2bced45e39152ee2ba001682275b7d32..f7084a963a394c3d0487012fe59f4cfcfc331851 100644 (file)
@@ -572,7 +572,10 @@ try_readonly:
                break;
 
        case ENODEV:
-               warnx(_("unknown filesystem type '%s'"), mnt_context_get_fstype(cxt));
+               if (mnt_context_get_fstype(cxt))
+                       warnx(_("unknown filesystem type '%s'"), mnt_context_get_fstype(cxt));
+               else
+                       warnx(_("unknown filesystem type"));
                break;
 
        case ENOTBLK: