diff options
author | Karel Zak | 2012-10-24 23:44:11 +0200 |
---|---|---|
committer | Karel Zak | 2012-10-24 23:44:11 +0200 |
commit | b2cbe99f3317bcc98fa4ff0f9ad5772aad828457 (patch) | |
tree | 53aee22ad880df15c6343f6197721a8b4e6d526e /libmount/src/tab.c | |
parent | libmount: tiny refactoring in mnt_table_is_fs_mounted() (diff) | |
download | kernel-qcow2-util-linux-b2cbe99f3317bcc98fa4ff0f9ad5772aad828457.tar.gz kernel-qcow2-util-linux-b2cbe99f3317bcc98fa4ff0f9ad5772aad828457.tar.xz kernel-qcow2-util-linux-b2cbe99f3317bcc98fa4ff0f9ad5772aad828457.zip |
libmount: support loopdevs in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r-- | libmount/src/tab.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c index 5b286538e..e5eb1063e 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -45,6 +45,7 @@ #include "mountP.h" #include "strutils.h" +#include "loopdev.h" /** * mnt_new_table: @@ -948,8 +949,31 @@ 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)) - continue; + if (!mnt_fs_streq_srcpath(fs, src)) { + /* The source does not match. Maybe the source is a loop + * device backing file. + */ + uint64_t offset = 0; + char *val; + size_t len; + int flags; + + if (!mnt_fs_is_kernel(fs) || + !mnt_fs_get_srcpath(fs) || + !startswith(mnt_fs_get_srcpath(fs), "/dev/loop")) + continue; /* does not look like loopdev */ + + if (mnt_fs_get_option(fstab_fs, "offset", &val, &len) == 0 && + mnt_parse_offset(val, len, &offset)) { + DBG(FS, mnt_debug_h(fstab_fs, "failed to parse offset=")); + continue; + } else + flags = LOOPDEV_FL_OFFSET; + + if (loopdev_is_used(mnt_fs_get_srcpath(fs), src, offset, flags)) + break; + } + if (root) { const char *r = mnt_fs_get_root(fs); if (!r || strcmp(r, root) != 0) @@ -975,6 +999,8 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) rc = 1; /* success */ done: free(root); + + DBG(TAB, mnt_debug_h(tb, "mnt_table_is_fs_mounted: %s [rc=%d]", src, rc)); return rc; } |