util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] lomount: accomodate building with loopdev
       [not found] <1317066156.3401.1.camel@offbook>
@ 2011-09-26 19:49 ` Davidlohr Bueso
  2011-09-26 19:50 ` [PATCH 2/5] lomount: avoid data duplication Davidlohr Bueso
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2011-09-26 19:49 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 mount/Makefile.am |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/mount/Makefile.am b/mount/Makefile.am
index e9237b7..f0e16d5 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -5,7 +5,9 @@ sbin_PROGRAMS = losetup swapon
 dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
 
 # generic sources for all programs (mount, umount, losetup)
-srcs_common = sundries.c $(top_srcdir)/lib/canonicalize.c sundries.h
+srcs_common = sundries.c $(top_srcdir)/lib/canonicalize.c \
+	$(top_srcdir)/lib/linux_version.c $(top_srcdir)/lib/at.c \
+	$(top_srcdir)/lib/sysfs.c $(top_srcdir)/lib/loopdev.c sundries.h
 
 # generic header for mount and umount
 hdrs_mount = fstab.h mount_mntent.h mount_constants.h \
@@ -14,7 +16,7 @@ hdrs_mount = fstab.h mount_mntent.h mount_constants.h \
 # generic sources for mount and umount
 srcs_mount = fstab.c mount_mntent.c getusername.c lomount.c devname.c devname.h \
 	$(srcs_common) $(hdrs_mount) $(top_srcdir)/lib/env.c \
-	$(top_srcdir)/lib/linux_version.c $(top_srcdir)/lib/blkdev.c \
+	$(top_srcdir)/lib/blkdev.c \
 	$(top_srcdir)/lib/fsprobe.c $(top_srcdir)/lib/mangle.c
 
 # generic flags for all programs (except losetup)
@@ -42,8 +44,7 @@ swapon_SOURCES = swapon.c swap_constants.h $(top_srcdir)/lib/linux_version.c \
 swapon_CFLAGS = $(cflags_common)
 swapon_LDADD = $(ldadd_common)
 
-losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h \
-		$(top_srcdir)/lib/strutils.c
+losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h $(top_srcdir)/lib/strutils.c 
 losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
 
 mount_static_LDADD =
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/5] lomount: avoid data duplication
       [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 ` Davidlohr Bueso
  2011-09-26 19:50 ` [PATCH 3/5] lomount: rewrite find_unused_loop_devices() Davidlohr Bueso
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2011-09-26 19:50 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

In lib/loopdev.c we already define struct loop_info64 and the LO_FLAGS_* macros, so get rid of the local ones in loop.h

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 mount/loop.h |   23 -----------------------
 1 files changed, 0 insertions(+), 23 deletions(-)

diff --git a/mount/loop.h b/mount/loop.h
index 64df339..1700983 100644
--- a/mount/loop.h
+++ b/mount/loop.h
@@ -25,13 +25,6 @@
 /* #define LOOP_CHANGE_FD	0x4C06 */
 #define LOOP_SET_CAPACITY	0x4C07
 
-/* Flags for loop_into{64,}->lo_flags */
-enum {
-	LO_FLAGS_READ_ONLY  = 1,
-	LO_FLAGS_USE_AOPS   = 2,
-	LO_FLAGS_AUTOCLEAR  = 4, /* New in 2.6.25 */
-};
-
 #define LO_NAME_SIZE	64
 #define LO_KEY_SIZE	32
 
@@ -50,20 +43,4 @@ struct loop_info {
 	char		reserved[4];
 };
 
-struct loop_info64 {
-	uint64_t	lo_device;
-	uint64_t	lo_inode;
-	uint64_t	lo_rdevice;
-	uint64_t	lo_offset;
-	uint64_t	lo_sizelimit; /* bytes, 0 == max available */
-	uint32_t	lo_number;
-	uint32_t	lo_encrypt_type;
-	uint32_t	lo_encrypt_key_size;
-	uint32_t	lo_flags;
-	uint8_t		lo_file_name[LO_NAME_SIZE];
-	uint8_t		lo_crypt_name[LO_NAME_SIZE];
-	uint8_t		lo_encrypt_key[LO_KEY_SIZE];
-	uint64_t	lo_init[2];
-};
-
 #endif /* MNT_LOOP_H */
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/5] lomount: rewrite find_unused_loop_devices()
       [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
  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
  4 siblings, 0 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2011-09-26 19:50 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/5] mount: remove is_loop_device()
       [not found] <1317066156.3401.1.camel@offbook>
                   ` (2 preceding siblings ...)
  2011-09-26 19:50 ` [PATCH 3/5] lomount: rewrite find_unused_loop_devices() Davidlohr Bueso
@ 2011-09-26 19:50 ` Davidlohr Bueso
  2011-09-26 19:50 ` [PATCH 5/5] lomount: rewrite del_loop() Davidlohr Bueso
  4 siblings, 0 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2011-09-26 19:50 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

We can use lib/loopdev.c's is_loopdev() instead; this affects umount as well as losetup.

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

diff --git a/mount/lomount.c b/mount/lomount.c
index 781cdd1..9605bd1 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -137,15 +137,6 @@ char *loopdev_get_loopfile(const char *device)
 	return res;
 }
 
-int
-is_loop_device (const char *device) {
-	struct stat st;
-
-	return (stat(device, &st) == 0 &&
-		S_ISBLK(st.st_mode) &&
-		major(st.st_rdev) == LOOPMAJOR);
-}
-
 static int
 is_loop_used(int fd)
 {
@@ -683,7 +674,7 @@ loopfile_used_with(char *devname, const char *filename, unsigned long long offse
 	struct stat statbuf;
 	int fd, ret;
 
-	if (!is_loop_device(devname))
+	if (!is_loopdev(devname))
 		return 0;
 
 	if (stat(filename, &statbuf) == -1)
diff --git a/mount/lomount.h b/mount/lomount.h
index 4acc371..eae12d9 100644
--- a/mount/lomount.h
+++ b/mount/lomount.h
@@ -4,7 +4,6 @@
 extern int set_loop(const char *, const char *, unsigned long long, unsigned long long,
 		    const char *, int, int *);
 extern int del_loop(const char *);
-extern int is_loop_device(const char *);
 extern int is_loop_autoclear(const char *device);
 extern char * find_unused_loop_device(void);
 
diff --git a/mount/umount.c b/mount/umount.c
index 5000aa5..efd3a4e 100644
--- a/mount/umount.c
+++ b/mount/umount.c
@@ -22,6 +22,7 @@
 #include "env.h"
 #include "nls.h"
 #include "strutils.h"
+#include "loopdev.h"
 
 #if defined(MNT_FORCE)
 /* Interesting ... it seems libc knows about MNT_FORCE and presumably
@@ -301,7 +302,7 @@ umount_one (const char *spec, const char *node, const char *type,
 	 * Ignore the option "-d" for non-loop devices and loop devices with
 	 * LO_FLAGS_AUTOCLEAR flag.
 	 */
-	if (delloop && is_loop_device(spec))
+	if (delloop && is_loopdev(spec))
 		myloop = 1;
 
 	if (restricted) {
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 5/5] lomount: rewrite del_loop()
       [not found] <1317066156.3401.1.camel@offbook>
                   ` (3 preceding siblings ...)
  2011-09-26 19:50 ` [PATCH 4/5] mount: remove is_loop_device() Davidlohr Bueso
@ 2011-09-26 19:50 ` Davidlohr Bueso
  4 siblings, 0 replies; 5+ messages in thread
From: Davidlohr Bueso @ 2011-09-26 19:50 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-09-26 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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 ` [PATCH 5/5] lomount: rewrite del_loop() Davidlohr Bueso

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