diff options
author | Karel Zak | 2013-10-01 15:52:11 +0200 |
---|---|---|
committer | Karel Zak | 2013-10-01 15:52:11 +0200 |
commit | a7d5202b5e49b7e33336818e00d240b8badddbb7 (patch) | |
tree | ba623d9681b3d566dd022f033e207930fbfcc7b3 /lib/loopdev.c | |
parent | Merge branch 'master' of https://github.com/yurchor/util-linux (diff) | |
download | kernel-qcow2-util-linux-a7d5202b5e49b7e33336818e00d240b8badddbb7.tar.gz kernel-qcow2-util-linux-a7d5202b5e49b7e33336818e00d240b8badddbb7.tar.xz kernel-qcow2-util-linux-a7d5202b5e49b7e33336818e00d240b8badddbb7.zip |
losetup: don't require 512-byte aligned offsets
Kernel aligns the device size, but the offset where the device starts
is not required to be aligned.
# losetup --offset 32 -f file.img
is just fine, the final size of the look device will be (in sectors)
(backing_file_size - offset) >> 9
so we have to do the same in userspace when we check for successful
set capacity ioctl.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/loopdev.c')
-rw-r--r-- | lib/loopdev.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/loopdev.c b/lib/loopdev.c index 27276bfab..a636a89c8 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -1129,6 +1129,12 @@ static int loopcxt_check_size(struct loopdev_cxt *lc, int file_fd) return -errno; } + /* It's block device, so, align to 512-byte sectors */ + if (expected_size % 512) { + DBG(lc, loopdev_debug("expected size misaligned to 512-byte sectors")); + expected_size = (expected_size >> 9) << 9; + } + if (expected_size != size) { DBG(lc, loopdev_debug("warning: loopdev and expected " "size dismatch (%ju/%ju)", |