Fix #1547, Use statvfs f_frsize for reported block size#1554
Open
sg20180546 wants to merge 1 commit into
Open
Conversation
OS_FileSysStatVolume_Impl() on posix, qnx, and rtems reads the volume statistics via statvfs(). The block counts (f_blocks, f_bfree) are expressed in units of f_frsize, but the reported block_size was taken from f_bsize, which is only the preferred I/O transfer size and is not guaranteed to equal f_frsize. On filesystems where they differ, the byte calculations (e.g. blocks * block_size) were incorrect. Use f_frsize so block_size is consistent with the block counts. The vxworks implementation uses statfs() (whose f_bsize is the fundamental block size) and is intentionally left unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sg20180546
marked this pull request as ready for review
June 23, 2026 11:32
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.
Fix #1547
Describe the contribution
OS_FileSysStatVolume_Impl()on the posix, qnx, and rtems implementations reads volume statistics viastatvfs(). Per POSIX, the block counts (f_blocks,f_bfree) are expressed in units off_frsize, but the reportedblock_sizewas taken fromf_bsize, which is only the preferred I/O transfer size and is not guaranteed to equalf_frsize.On filesystems where the two differ (e.g. very large drives), byte calculations such as
OS_fsBytesFree()(blocks_free * block_size) produce incorrect results.This PR changes those three implementations to report
block_sizefromf_frsize, making it consistent with the block counts. A short comment is added at each site to prevent regressions.The vxworks implementation uses
statfs()(whosef_bsizeis the fundamental block size that the counts are based on) and is intentionally left unchanged.Testing performed
f_bsize == f_frsize(the common case, e.g. typical Linux dev hosts), so existing functional tests are unaffected.f_frsize > f_bsize(the condition described in the issue, observed on large drives).Expected behavior changes
OS_FileSysStatVolume()(and derivedOS_fsBytesFree()/OS_fsBlocksFree()) report correct sizes on filesystems wheref_frsizediffers fromf_bsize. No change otherwise.System the issue was observed on
Additional context
Files changed:
src/os/posix/src/os-impl-filesys.csrc/os/qnx/src/os-impl-filesys.csrc/os/rtems/src/os-impl-filesys.cContributor Info
GitHub: @sg20180546