]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fsck: use less aggressive method to detect mounted devices
authorKarel Zak <kzak@redhat.com>
Fri, 24 Aug 2012 16:41:50 +0000 (18:41 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 24 Aug 2012 17:20:33 +0000 (19:20 +0200)
We should not care about mountpoints in fsck if a device name
specified on command line, just check if the device is used somewhere
in /proc/self/mountinfo file.

Crazy people who use

fsck /mountpoint

have to specify the mountpoint by the same format as in their fstab --
symlinks canonicalization is not supported.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=850965
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fsck.c

index 71263a27361e97f272ffe0f1220f112fe812c13f..28a1d706b302870fd4c658dfd0d719ef4ca4abb7 100644 (file)
@@ -170,23 +170,27 @@ static int string_to_int(const char *s)
 static int is_mounted(struct libmnt_fs *fs)
 {
        int rc;
+       const char *src;
 
+       src = mnt_fs_get_source(fs);
+       if (!src)
+               return 0;
+       if (!mntcache)
+               mntcache = mnt_new_cache();
        if (!mtab) {
                mtab = mnt_new_table();
                if (!mtab)
                        err(FSCK_EX_ERROR, ("failed to initialize libmount table"));
-               if (!mntcache)
-                       mntcache = mnt_new_cache();
                mnt_table_set_cache(mtab, mntcache);
                mnt_table_parse_mtab(mtab, NULL);
        }
 
-       rc = mnt_table_is_fs_mounted(mtab, fs);
+       rc = mnt_table_find_source(mtab, src, MNT_ITER_BACKWARD) ? 1 : 0;
        if (verbose) {
                if (rc)
-                       printf(_("%s is mounted\n"), mnt_fs_get_target(fs));
+                       printf(_("%s is mounted\n"), src);
                else
-                       printf(_("%s is not mounted\n"), mnt_fs_get_target(fs));
+                       printf(_("%s is not mounted\n"), src);
        }
        return rc;
 }
@@ -452,9 +456,22 @@ static struct libmnt_fs *lookup(char *path)
                return NULL;
 
        fs = mnt_table_find_srcpath(fstab, path, MNT_ITER_FORWARD);
-       if (!fs)
+       if (!fs) {
+               /*
+                * Maybe mountpoint has been specified on fsck command line.
+                * Yeah, crazy feature...
+                *
+                * Note that mnt_table_find_target() may canonicalize paths in
+                * the fstab to support symlinks. This is really unwanted,
+                * because readlink() on mountpoints may trigger automounts.
+                *
+                * So, disable the cache and compare the paths as strings
+                * without care about symlinks...
+                */
+               mnt_table_set_cache(fstab, NULL);
                fs = mnt_table_find_target(fstab, path, MNT_ITER_FORWARD);
-
+               mnt_table_set_cache(fstab, mntcache);
+       }
        return fs;
 }