util-linux/lib
Jeff Mahoney 293714c0d1 loopdev: sync capacity after setting it
I recently tried to mount an hfsplus file system from an image file with
a partition table by using the loop offset and sizelimit options to specify
the location of the file system.

hfsplus stores some metadata at a set offset from the end of the partition,
so it's sensitive to the device size reported by the kernel.

It worked with this:

But failed with this:

/dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000

/proc/partitions shows the correct number of blocks to match the sizelimit.

But if I set a breakpoint in mount before the mount syscall, I could see:
102400000
102432768

The kernel loop driver will set the gendisk capacity of the device at
LOOP_SET_STATUS64 but won't sync it to the block device until one of two
conditions are met: All open file descriptors referring to the device are
closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl
is called to sync it. Since mount opens the device and passes it directly
to the mount syscall after LOOP_SET_STATUS64 without closing and reopening
it, the sizelimit argument is effectively ignroed. The capacity needs to
be synced immediately for it to work as expected.

This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since
the device isn't yet released to the user, so it's safe to sync the capacity
immediately.

[kzak@redhat.com: - port to the current git HEAD,
                  - use uint64_t]

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-09 14:32:50 +02:00
..
Makemodule.am loopdev: sync capacity after setting it 2013-04-09 14:32:50 +02:00
at.c include: cleanup copyright headers 2013-01-08 15:10:17 +01:00
blkdev.c loopdev: sync capacity after setting it 2013-04-09 14:32:50 +02:00
canonicalize.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
colors.c dmesg: more colors, more fun 2013-03-18 12:28:32 +01:00
cpuset.c include: cleanup copyright headers 2013-01-08 15:10:17 +01:00
crc32.c lib: add a generic crc32() 2009-09-16 16:17:41 +02:00
env.c build-sys: test for secure_getenv() too. 2013-02-06 12:03:22 +01:00
exec_shell.c unshare,nsenter: spawn shell by default 2013-02-14 14:42:35 +01:00
fileutils.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
ismounted.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
langinfo.c lib: add fallback for nl_langinfo() 2010-11-15 16:42:45 +01:00
linux_version.c lib: [linux_version.c] simplify version parsing 2011-06-20 13:48:40 +02:00
loopdev.c loopdev: sync capacity after setting it 2013-04-09 14:32:50 +02:00
mangle.c lib/mangle: remove unused variable 2012-08-13 21:57:34 +02:00
match.c lib/match: fix compiler warning [-Wmissing-prototypes] 2012-07-16 18:29:22 +02:00
mbsalign.c various: fix variable and function declarations [smatch scan] 2013-04-09 12:17:20 +02:00
md5.c md5: fix strict aliasing warnings 2012-10-10 11:23:24 +02:00
pager.c lib/pager: robust work with file descriptors [coverity scan] 2012-09-07 13:29:55 +02:00
path.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
procutils.c lib/procutils: add simple API to scan /proc/PID/* 2013-03-12 17:24:14 +01:00
randutils.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
setproctitle.c lib: cleanup setproctitle.c 2011-10-26 23:17:15 +02:00
strutils.c lib/strutils: add strtotimeval_or_err() 2013-03-13 11:51:15 +01:00
sysfs.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
tt.c lib/tty: don't truncate output on non-terminals 2013-02-19 14:10:24 +01:00
ttyutils.c include: cleanup copyright headers 2013-01-08 15:10:17 +01:00
wholedisk.c lib: use O_CLOEXEC in libcommon 2013-04-03 16:13:06 +02:00
xgetpass.c losetup: make xgetpass more robust 2012-01-17 17:02:34 +01:00