diff options
author | Karel Zak | 2007-10-25 12:29:51 +0200 |
---|---|---|
committer | Karel Zak | 2007-10-26 01:02:12 +0200 |
commit | bfdb8be5c49d8fadb25118fb4416ab2a68fc3a16 (patch) | |
tree | a8502661b829ef0f5db2f28f43eca3cf799c7b5e /mount | |
parent | losetup: fix errno usage (diff) | |
download | kernel-qcow2-util-linux-bfdb8be5c49d8fadb25118fb4416ab2a68fc3a16.tar.gz kernel-qcow2-util-linux-bfdb8be5c49d8fadb25118fb4416ab2a68fc3a16.tar.xz kernel-qcow2-util-linux-bfdb8be5c49d8fadb25118fb4416ab2a68fc3a16.zip |
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 <mkoenig@suse.de>
Signed-off-by: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount')
-rw-r--r-- | mount/Makefile.am | 4 | ||||
-rw-r--r-- | mount/lomount.c | 14 |
2 files changed, 14 insertions, 4 deletions
diff --git a/mount/Makefile.am b/mount/Makefile.am index 57a5af8d1..46bcb5abe 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 cea3aed44..b3c16fb6b 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; } |