[PATCH] losetup: canonicalize loopfile name

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

 



When setting up a loop device, canonicalize the loop file
name. This simplifies a later identification of loop file names
when querying the loop devices.

Signed-off-by: Matthias Koenig <mkoenig@xxxxxxx>
---
 mount/Makefile.am |    2 +-
 mount/lomount.c   |   26 ++++++--------------------
 2 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/mount/Makefile.am b/mount/Makefile.am
index f40bdd7..25c55d5 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -25,7 +25,7 @@ umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
 
 swapon_SOURCES = swapon.c swap_constants.h $(utils_common)
 
-losetup_SOURCES = lomount.c loop.h lomount.h
+losetup_SOURCES = lomount.c loop.h lomount.h realpath.c xmalloc.c
 losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
 
 mount_LDADD = $(LDADD_common)
diff --git a/mount/lomount.c b/mount/lomount.c
index ace474c..e039e68 100644
--- a/mount/lomount.c
+++ b/mount/lomount.c
@@ -22,10 +22,11 @@
 #include "lomount.h"
 #include "xstrncpy.h"
 #include "nls.h"
+#include "realpath.h"
+#include "xmalloc.h"
 
 extern int verbose;
 extern char *progname;
-extern char *xstrdup (const char *s);	/* not: #include "sundries.h" */
 extern void error (const char *fmt, ...);	/* idem */
 
 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
@@ -279,6 +280,7 @@ set_loop(const char *device, const char *file, unsigned long long offset,
 	struct loop_info64 loopinfo64;
 	int fd, ffd, mode, i;
 	char *pass;
+ 	char res_file[PATH_MAX+1];
 
 	mode = (*loopro ? O_RDONLY : O_RDWR);
 	if ((ffd = open(file, mode)) < 0) {
@@ -297,7 +299,8 @@ set_loop(const char *device, const char *file, unsigned long long offset,
 
 	memset(&loopinfo64, 0, sizeof(loopinfo64));
 
-	xstrncpy(loopinfo64.lo_file_name, file, LO_NAME_SIZE);
+ 	myrealpath(file, res_file, PATH_MAX);
+ 	xstrncpy(loopinfo64.lo_file_name, res_file, LO_NAME_SIZE);
 
 	if (encryption && *encryption) {
 		if (digits_only(encryption)) {
@@ -382,7 +385,7 @@ set_loop(const char *device, const char *file, unsigned long long offset,
 
 	if (verbose > 1)
 		printf(_("set_loop(%s,%s,%llu): success\n"),
-		       device, file, offset);
+		       device, res_file, offset);
 	return 0;
 }
 
@@ -466,23 +469,6 @@ usage(void) {
 	exit(1);
  }
 
-char *
-xstrdup (const char *s) {
-	char *t;
-
-	if (s == NULL)
-		return NULL;
-
-	t = strdup (s);
-
-	if (t == NULL) {
-		fprintf(stderr, _("not enough memory"));
-		exit(1);
-	}
-
-	return t;
-}
-
 void
 error (const char *fmt, ...) {
 	va_list args;
-- 
1.5.2.4

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" 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