summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
diff options
context:
space:
mode:
authorKarel Zak2013-08-05 15:24:30 +0200
committerKarel Zak2013-08-05 15:35:26 +0200
commit6d62bc0f9b01ef4c58a3e8e3585385045bd10854 (patch)
tree9e693eb430b18e36e1ea01b4e9483c7ff2dcc484 /sys-utils/losetup.c
parentlibmount: canonicalize for conversion from loopdev backing file (diff)
downloadkernel-qcow2-util-linux-6d62bc0f9b01ef4c58a3e8e3585385045bd10854.tar.gz
kernel-qcow2-util-linux-6d62bc0f9b01ef4c58a3e8e3585385045bd10854.tar.xz
kernel-qcow2-util-linux-6d62bc0f9b01ef4c58a3e8e3585385045bd10854.zip
losetup: make -j <path> more robust
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>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r--sys-utils/losetup.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 1bd1f41a4..217cf9c18 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -160,6 +160,7 @@ static int show_all_loops(struct loopdev_cxt *lc, const char *file,
uint64_t offset, int flags)
{
struct stat sbuf, *st = &sbuf;
+ char *cn_file = NULL;
if (loopcxt_init_iterator(lc, LOOPITER_FL_USED))
return -1;
@@ -168,18 +169,23 @@ static int show_all_loops(struct loopdev_cxt *lc, const char *file,
st = NULL;
while (loopcxt_next(lc) == 0) {
- if (file && !loopcxt_is_used(lc, st, file, offset, flags)) {
- char *canonized;
- int ret;
- canonized = canonicalize_path(file);
- ret = loopcxt_is_used(lc, st, canonized, offset, flags);
- free(canonized);
- if (!ret)
+ if (file) {
+ int used;
+ const char *bf = cn_file ? cn_file : file;
+
+ used = loopcxt_is_used(lc, st, bf, offset, flags);
+ if (!used && !cn_file) {
+ bf = cn_file = canonicalize_path(file);
+ used = loopcxt_is_used(lc, st, bf, offset, flags);
+ }
+ if (!used)
continue;
}
printf_loopdev(lc);
}
loopcxt_deinit_iterator(lc);
+ if (cn_file)
+ free(cn_file);
return 0;
}
@@ -298,6 +304,7 @@ static int make_table(struct loopdev_cxt *lc,
{
struct stat sbuf, *st = &sbuf;
struct tt_line *ln;
+ char *cn_file = NULL;
int i;
if (!(tt = tt_new_table(tt_flags)))
@@ -325,9 +332,18 @@ static int make_table(struct loopdev_cxt *lc,
st = NULL;
while (loopcxt_next(lc) == 0) {
- if (file && !loopcxt_is_used(lc, st, file, offset, flags))
- continue;
-
+ if (file) {
+ int used;
+ const char *bf = cn_file ? cn_file : file;
+
+ used = loopcxt_is_used(lc, st, bf, offset, flags);
+ if (!used && !cn_file) {
+ bf = cn_file = canonicalize_path(file);
+ used = loopcxt_is_used(lc, st, bf, offset, flags);
+ }
+ if (!used)
+ continue;
+ }
ln = tt_add_line(tt, NULL);
if (set_tt_data(lc, ln))
@@ -335,6 +351,8 @@ static int make_table(struct loopdev_cxt *lc,
}
loopcxt_deinit_iterator(lc);
+ if (cn_file)
+ free(cn_file);
return 0;
}