Repository navigation
libfile: fix free space reporting and 32-bit block count truncation - #294
Merged
Merged
Conversation
On macOS, statvfs(3) is a wrapper around statfs(2) that casts the 64-bit block counts of struct statfs to 32-bit fsblkcnt_t. On file systems with 512-byte blocks such as exFAT, free space of 2 TiB or more overflows 32 bits in get_free_blocks(), causing f3write to stop writing early. This commit fixes the truncation by: 1. Calling statfs(2) in get_block_order() and get_free_blocks() on macOS. 2. Defining _FILE_OFFSET_BITS to 64 in libfile.c so statvfs(3) uses 64-bit block counts on 32-bit architectures. 3. Removing the unused #include <sys/statvfs.h> directive from f3write.c. This commit addresses issue #231.
File systems such as ext4 reserve a percentage of blocks for root. Because get_free_blocks() always returned f_bfree, running f3write as an unprivileged user overestimated the initial writable space and reported the reserved blocks as remaining free space after hitting ENOSPC. This commit makes get_free_blocks() return f_bavail when geteuid(2) is non-zero, and f_bfree when running as root. This commit closes #231
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request addresses the two issues reported in #231:
statvfs(3)32-bit block count truncation: On macOS,statvfs(3)casts 64-bit block counts fromstatfs(2)into 32-bitfsblkcnt_t. On file systems with 512-byte blocks such as exFAT, free space of 2 TiB or more wraps modulof3writeto stop writing early. Callingstatfs(2)directly on macOS and defining_FILE_OFFSET_BITS 64insrc/libfile.censures 64-bit block counts are used.f_bfreevs.f_bavail): File systems such asext4reserve a percentage of blocks (5% by default) forroot. Returningfs.f_bavailinget_free_blocks()when running as an unprivileged user (geteuid() != 0) avoids overestimating writable space and avoids reporting root-reserved blocks as remaining free space after hittingENOSPC.This pull request closes #231.