summaryrefslogtreecommitdiffstats
path: root/mount/lomount.c
diff options
context:
space:
mode:
authorKarel Zak2007-10-25 12:29:51 +0200
committerKarel Zak2007-10-26 01:02:12 +0200
commitbfdb8be5c49d8fadb25118fb4416ab2a68fc3a16 (patch)
treea8502661b829ef0f5db2f28f43eca3cf799c7b5e /mount/lomount.c
parentlosetup: fix errno usage (diff)
downloadkernel-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/lomount.c')
-rw-r--r--mount/lomount.c14
1 files changed, 12 insertions, 2 deletions
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;
}