libmount: support loopdevs in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
449a7646d0
commit
b2cbe99f33
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue