]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: special treatment for auto in fstype pattern
authorKarel Zak <kzak@redhat.com>
Mon, 23 Jun 2014 10:42:33 +0000 (12:42 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jun 2014 10:42:33 +0000 (12:42 +0200)
Let's support

  mount -t ext2,auto /dev/sde /media/stick

Reported-by: Andreas Henriksson <andreas@fatal.se>
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=506695
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c
libmount/src/mountP.h

index 65171eceb4b29dc17bc6b3ed9cbeea6ed743193e..7d2b9e40fc0d1f821f23252860f60d1da9233a97 100644 (file)
@@ -1601,6 +1601,40 @@ int mnt_context_prepare_target(struct libmnt_context *cxt)
        return 0;
 }
 
+/* Guess type, but not set to cxt->fs, use free() for the result. It's no error
+ * when we're not able to guess a filesystem type.
+ */
+int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type)
+{
+       int rc = 0;
+       const char *dev = mnt_fs_get_srcpath(cxt->fs);
+
+       *type = NULL;
+
+       if (!dev)
+               goto done;
+
+       if (access(dev, F_OK) == 0) {
+               struct libmnt_cache *cache = mnt_context_get_cache(cxt);
+               int ambi = 0;
+
+               *type = mnt_get_fstype(dev, &ambi, cache);
+               if (cache && *type)
+                       *type = strdup(*type);
+               if (ambi)
+                       rc = -MNT_ERR_AMBIFS;
+       } else {
+               DBG(CXT, ul_debugobj(cxt, "access(%s) failed [%m]", dev));
+               if (strchr(dev, ':') != NULL)
+                       *type = strdup("nfs");
+               else if (!strncmp(dev, "//", 2))
+                       *type = strdup("cifs");
+       }
+
+done:
+       return rc;
+}
+
 /*
  * It's usually no error when we're not able to detect the filesystem type -- we
  * will try to use the types from /{etc,proc}/filesystems.
@@ -1608,7 +1642,6 @@ int mnt_context_prepare_target(struct libmnt_context *cxt)
 int mnt_context_guess_fstype(struct libmnt_context *cxt)
 {
        char *type;
-       const char *dev;
        int rc = 0;
 
        assert(cxt);
@@ -1635,30 +1668,11 @@ int mnt_context_guess_fstype(struct libmnt_context *cxt)
        if (cxt->fstype_pattern)
                goto done;
 
-       dev = mnt_fs_get_srcpath(cxt->fs);
-       if (!dev)
-               goto done;
-
-       if (access(dev, F_OK) == 0) {
-               struct libmnt_cache *cache = mnt_context_get_cache(cxt);
-               int ambi = 0;
-
-               type = mnt_get_fstype(dev, &ambi, cache);
-               if (type) {
-                       rc = mnt_fs_set_fstype(cxt->fs, type);
-                       if (!cache)
-                               free(type);     /* type is not cached */
-               }
-               if (ambi)
-                       rc = -MNT_ERR_AMBIFS;
-       } else {
-               DBG(CXT, ul_debugobj(cxt, "access(%s) failed [%m]", dev));
-               if (strchr(dev, ':') != NULL)
-                       rc = mnt_fs_set_fstype(cxt->fs, "nfs");
-               else if (!strncmp(dev, "//", 2))
-                       rc = mnt_fs_set_fstype(cxt->fs, "cifs");
-       }
-
+       rc = mnt_context_guess_srcpath_fstype(cxt, &type);
+       if (rc == 0 && type)
+               __mnt_fs_set_fstype_ptr(cxt->fs, type);
+       else
+               free(type);
 done:
        DBG(CXT, ul_debugobj(cxt, "FS type: %s [rc=%d]",
                                mnt_fs_get_fstype(cxt->fs), rc));
index dcfdabfd220a523d65d18ed06b0eaa24547d7c19..14ae65254c9ec72e00463e0cc1484e228e16c41c 100644 (file)
@@ -773,18 +773,36 @@ static int do_mount_by_pattern(struct libmnt_context *cxt, const char *pattern)
                 */
                char *p, *p0;
 
-               DBG(CXT, ul_debugobj(cxt, "trying to mount by FS pattern list"));
+               DBG(CXT, ul_debugobj(cxt, "trying to mount by FS pattern list '%s'", pattern));
 
                p0 = p = strdup(pattern);
                if (!p)
                        return -ENOMEM;
                do {
+                       char *autotype = NULL;
                        char *end = strchr(p, ',');
+
                        if (end)
                                *end = '\0';
-                       rc = do_mount(cxt, p);
-                       p = end ? end + 1 : NULL;
 
+                       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);
 
                free(p0);
index f2660e057459fa43de8cdbdcf6e0d28af045927c..f2d0a57681108cd16002dd01906d72bf54d709a1 100644 (file)
@@ -378,6 +378,7 @@ extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt);
 
 extern int mnt_context_prepare_srcpath(struct libmnt_context *cxt);
 extern int mnt_context_prepare_target(struct libmnt_context *cxt);
+extern int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type);
 extern int mnt_context_guess_fstype(struct libmnt_context *cxt);
 extern int mnt_context_prepare_helper(struct libmnt_context *cxt,
                                      const char *name, const char *type);