[PATCH 5/5] lomount: rewrite del_loop()

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

 



From: Davidlohr Bueso <dave@xxxxxxx>
Date: Mon, 26 Sep 2011 16:33:51 -0300

Use lib/loopdev's for this.

Signed-off-by: Davidlohr Bueso <dave@xxxxxxx>
---
 mount/lomount.c |   33 ++++++++++++++-------------------
 1 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/mount/lomount.c b/mount/lomount.c
index 9605bd1..55fb7ba 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -918,27 +918,22 @@ set_loop(const char *device, const char *file, unsigned long long offset,
 
 int
 del_loop (const char *device) {
-	int fd, errsv;
+	struct loopdev_cxt lc;
+	int rc;
 
-	if ((fd = open (device, O_RDONLY)) < 0) {
-		errsv = errno;
-		goto error;
-	}
-	if (ioctl (fd, LOOP_CLR_FD, 0) < 0) {
-		errsv = errno;
-		goto error;
-	}
-	close (fd);
-	if (verbose > 1)
-		printf(_("del_loop(%s): success\n"), device);
-	return 0;
+	loopcxt_init(&lc, 0);
+	rc = loopcxt_set_device(&lc, device);
+	if (rc)
+		err(EXIT_FAILURE, "failed to set device: %s", device);
 
-error:
-	fprintf(stderr, _("loop: can't delete device %s: %s\n"),
-		 device, strerror(errsv));
-	if (fd >= 0)
-		close(fd);
-	return 1;
+	rc = loopcxt_delete_device(&lc);
+	if (rc)
+		warnx(_("loop: can't delete device %s"), device);
+	if (verbose && !rc)
+		printf(_("del_loop(%s): success\n"), device);
+	
+	loopcxt_deinit(&lc);
+	return rc;
 }
 
 #else /* no LOOP_SET_FD defined */
-- 
1.7.4.1




--
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