diff options
author | Karel Zak | 2012-10-23 15:45:50 +0200 |
---|---|---|
committer | Karel Zak | 2012-10-23 15:45:50 +0200 |
commit | 449a7646d01a2cadc5dfb5268eb28bb9537d5c4e (patch) | |
tree | 0b837db8a81be7453dfe853d31c85a0592211f01 /libmount/src | |
parent | fdisk: fix compiler warning [-Wpointer-arith] and floating point exception (diff) | |
download | kernel-qcow2-util-linux-449a7646d01a2cadc5dfb5268eb28bb9537d5c4e.tar.gz kernel-qcow2-util-linux-449a7646d01a2cadc5dfb5268eb28bb9537d5c4e.tar.xz kernel-qcow2-util-linux-449a7646d01a2cadc5dfb5268eb28bb9537d5c4e.zip |
libmount: tiny refactoring in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r-- | libmount/src/tab.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c index bac6cf87b..5b286538e 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -906,6 +906,9 @@ static int is_mountinfo(struct libmnt_table *tb) */ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) { + struct libmnt_iter itr; + struct libmnt_fs *fs; + char *root = NULL; const char *src = NULL, *tgt = NULL; char *xtgt = NULL; @@ -938,42 +941,39 @@ int mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_fs) tgt = mnt_fs_get_target(fstab_fs); - if (tgt && src) { - struct libmnt_iter itr; - struct libmnt_fs *fs; + if (!tgt || !src) + goto done; - mnt_reset_iter(&itr, MNT_ITER_FORWARD); + mnt_reset_iter(&itr, MNT_ITER_FORWARD); - while (mnt_table_next_fs(tb, &itr, &fs) == 0) { + while (mnt_table_next_fs(tb, &itr, &fs) == 0) { - if (!mnt_fs_streq_srcpath(fs, src)) + if (!mnt_fs_streq_srcpath(fs, src)) + continue; + if (root) { + const char *r = mnt_fs_get_root(fs); + if (!r || strcmp(r, root) != 0) continue; + } - if (root) { - const char *r = mnt_fs_get_root(fs); - if (!r || strcmp(r, root) != 0) - continue; - } - - /* - * Compare target, try to minimize number of situations - * when we need to canonicalize the path to avoid - * readlink() on mountpoints. - */ - if (!xtgt) { - if (mnt_fs_streq_target(fs, tgt)) - break; - if (tb->cache) - xtgt = mnt_resolve_path(tgt, tb->cache); - } - if (xtgt && mnt_fs_streq_target(fs, xtgt)) + /* + * Compare target, try to minimize number of situations when we + * need to canonicalize the path to avoid readlink() on + * mountpoints. + */ + if (!xtgt) { + if (mnt_fs_streq_target(fs, tgt)) break; - + if (tb->cache) + xtgt = mnt_resolve_path(tgt, tb->cache); } - if (fs) - rc = 1; /* success */ + if (xtgt && mnt_fs_streq_target(fs, xtgt)) + break; } + if (fs) + rc = 1; /* success */ +done: free(root); return rc; } |