From 449a7646d01a2cadc5dfb5268eb28bb9537d5c4e Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 Oct 2012 15:45:50 +0200 Subject: libmount: tiny refactoring in mnt_table_is_fs_mounted() Signed-off-by: Karel Zak --- libmount/src/tab.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'libmount/src/tab.c') 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; } -- cgit v1.2.3-55-g7522