summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2013-08-05 15:24:30 +0200
committerKarel Zak <kzak@redhat.com>2013-08-05 15:35:39 +0200
commit68c41a5f5f2649f49d6eb2aecba7fb248b57e91e (patch)
treeb863f762b44f2175d101e070adb37fd0ba91d368
parent6d62bc0f9b01ef4c58a3e8e3585385045bd10854 (diff)
downloadutil-linux-68c41a5f5f2649f49d6eb2aecba7fb248b57e91e.tar.gz
libmount: be robust when work with loopdev backing file paths
It's usually unnecessary as we compare devno and ino, but let's use absolute paths for situations when it's necessary to compare paths as strings. Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libmount/src/context_loopdev.c25
-rw-r--r--libmount/src/context_umount.c10
2 files changed, 17 insertions, 18 deletions
diff --git a/libmount/src/context_loopdev.c b/libmount/src/context_loopdev.c
index 37fadb70..44a7216b 100644
--- a/libmount/src/context_loopdev.c
+++ b/libmount/src/context_loopdev.c
@@ -86,6 +86,8 @@ is_mounted_same_loopfile(struct libmnt_context *cxt,
struct libmnt_iter itr;
struct libmnt_fs *fs;
struct libmnt_cache *cache;
+ const char *bf;
+ int rc = 0;
assert(cxt);
assert(cxt->fs);
@@ -100,39 +102,36 @@ is_mounted_same_loopfile(struct libmnt_context *cxt,
cache = mnt_context_get_cache(cxt);
mnt_reset_iter(&itr, MNT_ITER_BACKWARD);
+ bf = cache ? mnt_resolve_path(backing_file, cache) : backing_file;
+
/* Search for a mountpoint node in mtab, proceed if any of these have the
* loop option set or the device is a loop device
*/
- while (mnt_table_next_fs(tb, &itr, &fs) == 0) {
+ while (rc == 0 && mnt_table_next_fs(tb, &itr, &fs) == 0) {
const char *src = mnt_fs_get_source(fs);
const char *opts = mnt_fs_get_user_options(fs);
char *val;
size_t len;
- int res = 0;
if (!src || !mnt_fs_match_target(fs, target, cache))
continue;
+ rc = 0;
+
if (strncmp(src, "/dev/loop", 9) == 0) {
- res = loopdev_is_used((char *) src, backing_file,
- offset, LOOPDEV_FL_OFFSET);
+ rc = loopdev_is_used((char *) src, bf, offset, LOOPDEV_FL_OFFSET);
} else if (opts && (cxt->user_mountflags & MNT_MS_LOOP) &&
mnt_optstr_get_option(opts, "loop", &val, &len) == 0 && val) {
val = strndup(val, len);
- res = loopdev_is_used((char *) val, backing_file,
- offset, LOOPDEV_FL_OFFSET);
+ rc = loopdev_is_used((char *) val, bf, offset, LOOPDEV_FL_OFFSET);
free(val);
}
-
- if (res) {
- DBG(CXT, mnt_debug_h(cxt, "%s already mounted", backing_file));
- return 1;
- }
}
-
- return 0;
+ if (rc)
+ DBG(CXT, mnt_debug_h(cxt, "%s already mounted", backing_file));
+ return rc;
}
int mnt_context_setup_loopdev(struct libmnt_context *cxt)
diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c
index b02902c4..2e912c0d 100644
--- a/libmount/src/context_umount.c
+++ b/libmount/src/context_umount.c
@@ -162,11 +162,9 @@ try_loopdev:
if (stat(tgt, &st) == 0 && S_ISREG(st.st_mode)) {
int count;
+ const char *bf = cache ? mnt_resolve_path(tgt, cache) : tgt;
- cn_tgt = mnt_resolve_path(tgt, cache);
- count = loopdev_count_by_backing_file(cn_tgt, &loopdev);
- if (!cache)
- free(cn_tgt);
+ count = loopdev_count_by_backing_file(bf, &loopdev);
if (count == 1) {
DBG(CXT, mnt_debug_h(cxt,
"umount: %s --> %s (retry)", tgt, loopdev));
@@ -361,7 +359,9 @@ static int evaluate_permissions(struct libmnt_context *cxt)
*/
fs = mnt_table_find_target(fstab, tgt, MNT_ITER_FORWARD);
if (fs) {
- const char *dev = mnt_fs_get_srcpath(cxt->fs); /* devname from mtab */
+ struct libmnt_cache *cache = mnt_context_get_cache(cxt);
+ const char *sp = mnt_fs_get_srcpath(cxt->fs); /* devname from mtab */
+ const char *dev = sp && cache ? mnt_resolve_path(sp, cache) : sp;
if (!dev || !is_associated_fs(dev, fs))
fs = NULL;