Skip to content

mkfs.btrfs --rootdir does not properly handle sparse files #653

Open
@crass

Description

@crass

When calculating the minimum size of filesystem mkfs.btrfs uses st.st_size from stat. But this is not necessarily the amount of bytes the file occupies. For sparse files, it should be more like st.st_blocks * block size.

This can cause mkfs.btrfs to fail when writing to a block device with the error: ERROR: unable to zero the output file. This is because mkfs.btrfs tries to extend the length of the file to be the minimum size it (incorrectly) thinks it needs to populate the new file system. However, block devices can not be extended like files, so this write beyond the end of the device fails. This error message is cryptic or non-intuitive for the user in this case, which should have the message "ERROR: block device too small to fit all data from rootdir".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmkfsChanges in mkfs.btrfs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions