diff options
author | Karel Zak | 2016-08-17 13:52:22 +0200 |
---|---|---|
committer | Karel Zak | 2016-08-17 13:52:22 +0200 |
commit | d8ba61fcb43effb310f9d59627125118a453ef74 (patch) | |
tree | 9593794037accfb37c452c706b56a389b9ad4e8f /sys-utils/losetup.c | |
parent | tests: Add losetup-loop test suite (diff) | |
download | kernel-qcow2-util-linux-d8ba61fcb43effb310f9d59627125118a453ef74.tar.gz kernel-qcow2-util-linux-d8ba61fcb43effb310f9d59627125118a453ef74.tar.xz kernel-qcow2-util-linux-d8ba61fcb43effb310f9d59627125118a453ef74.zip |
losetup: allow to use --nooverlap when device specified
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r-- | sys-utils/losetup.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 606789c42..9083a1372 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -452,7 +452,7 @@ static int create_loop(struct loopdev_cxt *lc, int hasdev = loopcxt_has_device(lc); int rc = 0; - /* Check for conflicts and re-user loop device if possible */ + /* losetup --find --noverlap file.img */ if (!hasdev && nooverlap) { rc = loopcxt_find_overlap(lc, file, offset, sizelimit); switch (rc) { @@ -499,6 +499,25 @@ static int create_loop(struct loopdev_cxt *lc, if (hasdev && !is_loopdev(loopcxt_get_device(lc))) loopcxt_add_device(lc); + /* losetup --noverlap /dev/loopN file.img */ + if (hasdev && nooverlap) { + struct loopdev_cxt lc2; + + if (loopcxt_init(&lc2, 0)) { + loopcxt_deinit(lc); + err(EXIT_FAILURE, _("failed to initialize loopcxt")); + } + rc = loopcxt_find_overlap(&lc2, file, offset, sizelimit); + loopcxt_deinit(&lc2); + + if (rc) { + loopcxt_deinit(lc); + if (rc > 0) + errx(EXIT_FAILURE, _("%s: overlapping loop device exists"), file); + err(EXIT_FAILURE, _("%s: failed to check for conflicting loop devices"), file); + } + } + /* Create a new device */ do { const char *errpre; |