From: Karel Zak Date: Mon, 8 Jul 2013 12:21:03 +0000 (+0200) Subject: lsblk: use devno to check if the filesystem is mounted X-Git-Tag: v2.24-rc1~455 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d828dfdfb258367c58819411b2f226da6533b92d;p=thirdparty%2Futil-linux.git lsblk: use devno to check if the filesystem is mounted The device (for example LVM logical volume) could be renamed and then the device name from /proc/self/mountinfo does not match with reality. So, we also need to check devno. Unfortunately we cannot completely rely on devno, because for example btrfs uses psudo device numbers. References: https://bugzilla.redhat.com/show_bug.cgi?id=980463 Signed-off-by: Karel Zak --- diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 5ac252ce19..20028a6418 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -1117,6 +1117,7 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) const char *src = NULL, *tgt = NULL; char *xtgt = NULL; int rc = 0; + dev_t devno = 0; assert(tb); assert(fstab_fs); @@ -1148,6 +1149,14 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) if (src && tb->cache && !mnt_fs_is_pseudofs(fstab_fs)) src = mnt_resolve_spec(src, tb->cache); + if (src && root) { + struct stat st; + + devno = mnt_fs_get_devno(fstab_fs); + if (!devno && stat(src, &st) == 0 && S_ISBLK(st.st_mode)) + devno = st.st_rdev; + } + tgt = mnt_fs_get_target(fstab_fs); if (!tgt || !src) { @@ -1158,7 +1167,12 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) while (mnt_table_next_fs(tb, &itr, &fs) == 0) { - if (!mnt_fs_streq_srcpath(fs, src)) { + int eq = mnt_fs_streq_srcpath(fs, src); + + if (!eq && devno && mnt_fs_get_devno(fs) == devno) + eq = 1; + + if (!eq) { /* The source does not match. Maybe the source is a loop * device backing file. */