summaryrefslogtreecommitdiffstats
path: root/disk-utils/fsck.c
diff options
context:
space:
mode:
authorKarel Zak2012-08-24 18:41:50 +0200
committerKarel Zak2012-08-24 19:20:33 +0200
commit7a4f98854283a5b98e76902b12685ad1999b2802 (patch)
tree8b2afecd06f6595d79145e7c60561709bd0fa76e /disk-utils/fsck.c
parentlibmount: rewrite mnt_table_is_fs_mounted() to be less aggressive (diff)
downloadkernel-qcow2-util-linux-7a4f98854283a5b98e76902b12685ad1999b2802.tar.gz
kernel-qcow2-util-linux-7a4f98854283a5b98e76902b12685ad1999b2802.tar.xz
kernel-qcow2-util-linux-7a4f98854283a5b98e76902b12685ad1999b2802.zip
fsck: use less aggressive method to detect mounted devices
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>
Diffstat (limited to 'disk-utils/fsck.c')
-rw-r--r--disk-utils/fsck.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c
index 71263a273..28a1d706b 100644
--- a/disk-utils/fsck.c
+++ b/disk-utils/fsck.c
@@ -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;
}