[PATCH 3/8] losetup: Check for loop device conflicts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To prevent data loss, check for conflicting loop devices.

Return error if a conflicting loop device exists. This behavior can be overridden
by --force.

Signed-off-by: Stanislav Brabec <sbrabec@xxxxxxx>
---
 sys-utils/losetup.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index ef6f52b..28cde2b 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -732,6 +732,30 @@ int main(int argc, char **argv)
 		do {
 			const char *errpre;
 
+			if (!force) {
+				struct loopdev_cxt lc2;
+
+				if (loopcxt_init(&lc2, 0)) {
+					loopcxt_deinit(&lc);
+					err(EXIT_FAILURE, _("failed to initialize loopcxt"));
+				}
+				res = loopcxt_check_conflict(&lc2, file,
+					offset, sizelimit);
+				if (res < 0) {
+					loopcxt_deinit(&lc2);
+					loopcxt_deinit(&lc);
+					err(EXIT_FAILURE, _("failed to check for conflicting loop devices"));
+				}
+				if (res == 0) {
+					loopcxt_deinit(&lc2);
+					loopcxt_deinit(&lc);
+					errx(EXIT_FAILURE, _("%s: overlapping loop device exists; use --force to ignore"),
+						file);
+				}
+				res = 0;
+				loopcxt_deinit(&lc2);
+			}
+
 			/* Note that loopcxt_{find_unused,set_device}() resets
 			 * loopcxt struct.
 			 */
-- 
2.9.2

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@xxxxxxxx
Křižíkova 148/34 (Corso IIa)                  tel: +49 911 7405384547
186 00 Praha 8-Karlín                          fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux