Util-Linux package development
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@gnu.org>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux <util-linux@vger.kernel.org>
Subject: [PATCH 5/5] lomount: rewrite del_loop()
Date: Mon, 26 Sep 2011 16:50:10 -0300	[thread overview]
Message-ID: <1317066610.2896.5.camel@offbook> (raw)
In-Reply-To: <1317066156.3401.1.camel@offbook>

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

Use lib/loopdev's for this.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 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

      parent reply	other threads:[~2011-09-26 19:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1317066156.3401.1.camel@offbook>
2011-09-26 19:49 ` [PATCH 1/5] lomount: accomodate building with loopdev Davidlohr Bueso
2011-09-26 19:50 ` [PATCH 2/5] lomount: avoid data duplication Davidlohr Bueso
2011-09-26 19:50 ` [PATCH 3/5] lomount: rewrite find_unused_loop_devices() Davidlohr Bueso
2011-09-26 19:50 ` [PATCH 4/5] mount: remove is_loop_device() Davidlohr Bueso
2011-09-26 19:50 ` Davidlohr Bueso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317066610.2896.5.camel@offbook \
    --to=dave@gnu.org \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox