From 7a4f98854283a5b98e76902b12685ad1999b2802 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 24 Aug 2012 18:41:50 +0200 Subject: 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 --- disk-utils/fsck.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'disk-utils/fsck.c') 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; } -- cgit v1.2.3-55-g7522