From bfdb8be5c49d8fadb25118fb4416ab2a68fc3a16 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 25 Oct 2007 12:29:51 +0200 Subject: [PATCH] losetup: canonicalize loopfile name 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. Co-Author: Matthias Koenig Signed-off-by: Matthias Koenig Signed-off-by: Karel Zak --- mount/Makefile.am | 4 ++-- mount/lomount.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mount/Makefile.am b/mount/Makefile.am index 57a5af8d..46bcb5ab 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -25,8 +25,8 @@ umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS) swapon_SOURCES = swapon.c swap_constants.h $(utils_common) -losetup_SOURCES = lomount.c sundries.c xmalloc.c loop.h lomount.h xmalloc.h \ - sundries.h +losetup_SOURCES = lomount.c sundries.c xmalloc.c realpath.c \ + loop.h lomount.h xmalloc.h sundries.h realpath.h losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS) mount_LDADD = $(LDADD_common) diff --git a/mount/lomount.c b/mount/lomount.c index cea3aed4..b3c16fb6 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -24,6 +24,7 @@ #include "nls.h" #include "sundries.h" #include "xmalloc.h" +#include "realpath.h" #define SIZE(a) (sizeof(a)/sizeof(a[0])) @@ -276,6 +277,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 *filename; mode = (*loopro ? O_RDONLY : O_RDWR); if ((ffd = open(file, mode)) < 0) { @@ -294,7 +296,9 @@ set_loop(const char *device, const char *file, unsigned long long offset, memset(&loopinfo64, 0, sizeof(loopinfo64)); - xstrncpy((char *)loopinfo64.lo_file_name, file, LO_NAME_SIZE); + if (!(filename = canonicalize(file))) + filename = (char *) file; + xstrncpy((char *)loopinfo64.lo_file_name, filename, LO_NAME_SIZE); if (encryption && *encryption) { if (digits_only(encryption)) { @@ -351,6 +355,8 @@ set_loop(const char *device, const char *file, unsigned long long offset, close(fd); close(ffd); + if (file != filename) + free(filename); return rc; } close (ffd); @@ -376,13 +382,17 @@ set_loop(const char *device, const char *file, unsigned long long offset, if (i) { ioctl (fd, LOOP_CLR_FD, 0); close (fd); + if (file != filename) + free(filename); return 1; } close (fd); if (verbose > 1) printf(_("set_loop(%s,%s,%llu): success\n"), - device, file, offset); + device, filename, offset); + if (file != filename) + free(filename); return 0; } -- 2.39.5