summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
diff options
context:
space:
mode:
authorKarel Zak2019-01-18 12:13:12 +0100
committerKarel Zak2019-01-18 12:13:12 +0100
commit6daf185c3cc2b7c4b85f8dd39c9caaab5caea434 (patch)
tree8b4e1b0c65d55c093d8e68448ec13a42e0dd6d1f /sys-utils/losetup.c
parentlibfdisk: add comment to fdisk_set_first_lba() (diff)
downloadkernel-qcow2-util-linux-6daf185c3cc2b7c4b85f8dd39c9caaab5caea434.tar.gz
kernel-qcow2-util-linux-6daf185c3cc2b7c4b85f8dd39c9caaab5caea434.tar.xz
kernel-qcow2-util-linux-6daf185c3cc2b7c4b85f8dd39c9caaab5caea434.zip
losetup: use offset in warn_size() calculation
# dd if=/dev/urandom of=dummy bs=513 count=1 2>/dev/null # losetup -f --show --offset 1 dummy /dev/loop0 losetup: dummy: Warning: file does not fit into a 512-byte sector; the end of the file will be ignore The warning is bogus as with offset the size of the file fits into 512-byte sector. Simple test that all is right: # dd if=dummy bs=1 skip=1 2>/dev/null | sha256sum - /dev/loop0 da2ed0ade6ea518a802cd8a7a3c01c408ad8699ef6856b0b01f92b867d4ba9b5 - da2ed0ade6ea518a802cd8a7a3c01c408ad8699ef6856b0b01f92b867d4ba9b5 /dev/loop0 Addresses: https://github.com/karelzak/util-linux/issues/722 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r--sys-utils/losetup.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 7d14f566c..db7b68deb 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -447,7 +447,7 @@ static void __attribute__((__noreturn__)) usage(void)
exit(EXIT_SUCCESS);
}
-static void warn_size(const char *filename, uint64_t size)
+static void warn_size(const char *filename, uint64_t size, uint64_t offset, int flags)
{
struct stat st;
@@ -455,6 +455,9 @@ static void warn_size(const char *filename, uint64_t size)
if (stat(filename, &st) || S_ISBLK(st.st_mode))
return;
size = st.st_size;
+
+ if (flags & LOOPDEV_FL_OFFSET)
+ size -= offset;
}
if (size < 512)
@@ -835,7 +838,7 @@ int main(int argc, char **argv)
if (res == 0) {
if (showdev)
printf("%s\n", loopcxt_get_device(&lc));
- warn_size(file, sizelimit);
+ warn_size(file, sizelimit, offset, flags);
if (set_dio || set_blocksize)
goto lo_set_post;
}