Skip to content

Fix #1547, Use statvfs f_frsize for reported block size#1554

Open
sg20180546 wants to merge 1 commit into
nasa:devfrom
sg20180546:fix-1547-statvfs-block-size
Open

Fix #1547, Use statvfs f_frsize for reported block size#1554
sg20180546 wants to merge 1 commit into
nasa:devfrom
sg20180546:fix-1547-statvfs-block-size

Conversation

@sg20180546

Copy link
Copy Markdown

Fix #1547

Describe the contribution

OS_FileSysStatVolume_Impl() on the posix, qnx, and rtems implementations reads volume statistics via statvfs(). Per POSIX, 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 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_size from f_frsize, making it consistent with the block counts. A short comment is added at each site to prevent regressions.

The vxworks implementation uses statfs() (whose f_bsize is the fundamental block size that the counts are based on) and is intentionally left unchanged.

Testing performed

  • Builds cleanly.
  • No behavior change on filesystems where f_bsize == f_frsize (the common case, e.g. typical Linux dev hosts), so existing functional tests are unaffected.
  • The fix corrects the reported size on filesystems where f_frsize > f_bsize (the condition described in the issue, observed on large drives).

Expected behavior changes

OS_FileSysStatVolume() (and derived OS_fsBytesFree() / OS_fsBlocksFree()) report correct sizes on filesystems where f_frsize differs from f_bsize. No change otherwise.

System the issue was observed on

  • OS: Oracle Linux 8 (per reporter), large-capacity drives
  • cFS: Draco 2.4

Additional context

Files changed:

  • src/os/posix/src/os-impl-filesys.c
  • src/os/qnx/src/os-impl-filesys.c
  • src/os/rtems/src/os-impl-filesys.c

Contributor Info

GitHub: @sg20180546

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
sg20180546 marked this pull request as ready for review June 23, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OS_FileSysStatVolume_Impl() for posix, qnx, and rterms returns the wrong variable.

2 participants