util-linux.vger.kernel.org archive mirror
 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 3/5] lomount: rewrite find_unused_loop_devices()
Date: Mon, 26 Sep 2011 16:50:05 -0300	[thread overview]
Message-ID: <1317066605.2896.3.camel@offbook> (raw)
In-Reply-To: <1317066156.3401.1.camel@offbook>

From: Davidlohr Bueso <dave@gnu.org>
Date: Mon, 26 Sep 2011 14:57:58 -0300

Use lib/loopdev instead.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 mount/lomount.c |   38 ++++++++++++--------------------------
 1 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/mount/lomount.c b/mount/lomount.c
index 74a8749..781cdd1 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -18,6 +18,7 @@
 
 #include "loop.h"
 #include "lomount.h"
+#include "loopdev.h"
 #include "strutils.h"
 #include "nls.h"
 #include "sundries.h"
@@ -699,35 +700,20 @@ loopfile_used_with(char *devname, const char *filename, unsigned long long offse
 
 char *
 find_unused_loop_device (void) {
-	struct looplist ll;
-	char *devname = NULL;
-	int fd;
+	struct loopdev_cxt lc;
+	char *dev;
+	int rc;
 
-	if (looplist_open(&ll, LLFLG_FREEONLY) == -1) {
-		error(_("%s: /dev directory does not exist."), progname);
-		return NULL;
-	}
+	loopcxt_init(&lc, 0);
 
-	if ((fd = looplist_next(&ll)) != -1) {
-		close(fd);
-		devname = xstrdup(ll.name);
-	}
-	looplist_close(&ll);
-	if (devname)
-		return devname;
+	rc = loopcxt_find_unused(&lc);
+	if (rc)
+		err(EXIT_FAILURE, "loopdevs scanning failed");
+	
+	dev = xstrdup(loopcxt_get_device(&lc));
+	loopcxt_deinit(&lc);
 
-	if (!ll.ct_succ && ll.ct_perm)
-		error(_("%s: no permission to look at /dev/loop%s<N>"), progname,
-				(ll.flag & LLFLG_SUBDIR) ? "/" : "");
-	else if (ll.ct_succ)
-		error(_("%s: could not find any free loop device"), progname);
-	else
-		error(_(
-		    "%s: Could not find any loop device. Maybe this kernel "
-		    "does not know\n"
-		    "       about the loop device? (If so, recompile or "
-		    "`modprobe loop'.)"), progname);
-	return NULL;
+	return dev;
 }
 
 /*
-- 
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 ` Davidlohr Bueso [this message]
2011-09-26 19:50 ` [PATCH 4/5] mount: remove is_loop_device() Davidlohr Bueso
2011-09-26 19:50 ` [PATCH 5/5] lomount: rewrite del_loop() Davidlohr Bueso

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=1317066605.2896.3.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;
as well as URLs for NNTP newsgroup(s).