diff options
author | Karel Zak | 2010-12-01 23:02:17 +0100 |
---|---|---|
committer | Karel Zak | 2010-12-01 23:02:17 +0100 |
commit | db3b5b76a783ddcd247e9cf3299781167e75f9f9 (patch) | |
tree | a6a6ddf3ff6c6aac6ca67355ab88d68289bd2f4e /mount/lomount.c | |
parent | remove -ng from some files (diff) | |
download | kernel-qcow2-util-linux-db3b5b76a783ddcd247e9cf3299781167e75f9f9.tar.gz kernel-qcow2-util-linux-db3b5b76a783ddcd247e9cf3299781167e75f9f9.tar.xz kernel-qcow2-util-linux-db3b5b76a783ddcd247e9cf3299781167e75f9f9.zip |
mount: read /sys for loopdev backing file
On systems without /etc/mtab (or everywhere if kernel >= 2.6.37)
we use loop autoclear flag and then the backing file name is not
stored in /etc/mtab. mount(8) uses sysfs to get the filename (or
LOOP_GET_STATU* ioctls on old kernels).
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/lomount.c')
-rw-r--r-- | mount/lomount.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/mount/lomount.c b/mount/lomount.c index 90149536a..4d99d9f6f 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -109,6 +109,33 @@ static char *loopfile_from_sysfs(const char *device) return res; } +char *loopdev_get_loopfile(const char *device) +{ + char *res = loopfile_from_sysfs(device); + + if (!res) { + struct loop_info lo; + struct loop_info64 lo64; + int fd; + + if ((fd = open(device, O_RDONLY)) < 0) + return NULL; + + if (ioctl(fd, LOOP_GET_STATUS64, &lo64) == 0) { + lo64.lo_file_name[LO_NAME_SIZE-2] = '*'; + lo64.lo_file_name[LO_NAME_SIZE-1] = 0; + res = xstrdup((char *) lo64.lo_file_name); + + } else if (ioctl(fd, LOOP_GET_STATUS, &lo) == 0) { + lo.lo_name[LO_NAME_SIZE-2] = '*'; + lo.lo_name[LO_NAME_SIZE-1] = 0; + res = xstrdup((char *) lo.lo_name); + } + close(fd); + } + return res; +} + int is_loop_device (const char *device) { struct stat st; |