lomount: accomodate building with loopdev
A message that is not in the archive (sent off-list or not yet received): 1317066156.3401.1.camel@offbook
PATCH 1/5 lomount: accomodate building with loopdev
From: Davidlohr Bueso <[email protected]>
Date: Mon, 26 Sep 2011 14:56:45 -0300
--- mount/Makefile.am | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
mount/Makefile.am +5 -4
@@ -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 =
Signature · 1 line
1.7.4.1
PATCH 2/5 lomount: avoid data duplication
In reply to a message not in the archiveFrom: Davidlohr Bueso <[email protected]>
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
--- mount/loop.h | 23 ----------------------- 1 files changed, 0 insertions(+), 23 deletions(-)
mount/loop.h +0 -23
@@ -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 */
Signature · 1 line
1.7.4.1
PATCH 3/5 lomount: rewrite find_unused_loop_devices()
In reply to a message not in the archiveFrom: Davidlohr Bueso <[email protected]>
Date: Mon, 26 Sep 2011 14:57:58 -0300
Use lib/loopdev instead.
--- mount/lomount.c | 38 ++++++++++++-------------------------- 1 files changed, 12 insertions(+), 26 deletions(-)
mount/lomount.c +12 -26
@@ -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 offsechar *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; }/*
Signature · 1 line
1.7.4.1
PATCH 4/5 mount: remove is_loop_device()
In reply to a message not in the archiveFrom: Davidlohr Bueso <[email protected]>
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.
--- mount/lomount.c | 11 +---------- mount/lomount.h | 1 - mount/umount.c | 3 ++- 3 files changed, 3 insertions(+), 12 deletions(-)
mount/lomount.c +1 -10
@@ -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 offsestruct stat statbuf;int fd, ret; -if (!is_loop_device (devname)) +if (!is_loopdev (devname))return 0 ;if (stat (filename, &statbuf) ==-1 )
mount/lomount.h +0 -1
@@ -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 );
mount/umount.c +2 -1
@@ -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) {
Signature · 1 line
1.7.4.1
PATCH 5/5 lomount: rewrite del_loop()
In reply to a message not in the archiveFrom: Davidlohr Bueso <[email protected]>
Date: Mon, 26 Sep 2011 16:33:51 -0300
Use lib/loopdev's for this.
--- mount/lomount.c | 33 ++++++++++++++------------------- 1 files changed, 14 insertions(+), 19 deletions(-)
mount/lomount.c +14 -19
@@ -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 */
Signature · 1 line
1.7.4.1