]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: use offset in warn_size() calculation
authorKarel Zak <kzak@redhat.com>
Fri, 18 Jan 2019 11:13:12 +0000 (12:13 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 2 Apr 2019 10:15:12 +0000 (12:15 +0200)
 # 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>
sys-utils/losetup.c

index 7d14f566cf8c9f41ecaab0153fa19a305d018201..db7b68deba63cbf75baae6ce88fc37cf4e93600c 100644 (file)
@@ -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;
                }