4f5a455d1b
[BUG] When running mkfs.btrfs with --rootdir on a block device, and the source directory contains a sparse file, whose size is larger than the block size, then mkfs.btrfs would fail: # lsblk /dev/test/test NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS test-test 253:0 0 10G 0 lvm # mkdir -p /tmp/output # truncate -s 20G /tmp/output/file # mkfs.btrfs -f --rootdir /tmp/output /dev/test/test # sudo mkfs.btrfs -f /dev/test/scratch1 --rootdir /tmp/output/ btrfs-progs v6.3.3 See https://btrfs.readthedocs.io for more information. ERROR: unable to zero the output file [CAUSE] Mkfs.btrfs would try to zero out the target file according to the total size of the directory. However the directory size is calculated using the file size, not the real bytes taken by the file, thus for such sparse file with holes only, it would still take 20G. Then we would use that 20G size to zero out the target file, but if the target file is a block device, we would fail as we can not enlarge a block device. [FIX] When zeroing the file, we only enlarge it if the target is a regular file. Otherwise we warn about the size and continue. Please note that, since "mkfs.btrfs --rootdir" doesn't handle sparse file any differently from regular file, above case would still fail due to ENOSPC, as will write zeros into the target file inside the fs. Proper handling for sparse files would need a new series of patch to address. Issue: #653 Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> |
||
---|---|---|
.. | ||
common.c | ||
common.h | ||
main.c | ||
Makefile | ||
rootdir.c | ||
rootdir.h |