From 293714c0d157ae04d08bb587e800c70f05cc4a29 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Tue, 9 Apr 2013 14:32:50 +0200 Subject: 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 (), offset 32768, sizelimit 102400000 /dev/loop1: [0089]:2 (), 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 Signed-off-by: Karel Zak --- lib/Makemodule.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Makemodule.am') diff --git a/lib/Makemodule.am b/lib/Makemodule.am index a118958c5..afc2156c7 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -70,7 +70,7 @@ test_ttyutils_CFLAGS = -DTEST_PROGRAM test_ttyutils_LDADD = libcommon.la test_blkdev_SOURCES = lib/blkdev.c -test_blkdev_CFLAGS = -DTEST_PROGRAM +test_blkdev_CFLAGS = -DTEST_PROGRAM_BLKDEV test_blkdev_LDADD = libcommon.la test_ismounted_SOURCES = lib/ismounted.c -- cgit v1.2.3-55-g7522