File util-linux-loop-reuse-18.patch of Package util-linux.7828

From d8ba61fcb43effb310f9d59627125118a453ef74 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Wed, 17 Aug 2016 13:52:22 +0200
Subject: [PATCH 18/20] losetup: allow to use --nooverlap when device specified

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 sys-utils/losetup.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 606789c..9083a13 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;
-- 
2.9.2

openSUSE Build Service is sponsored by