Skip to content

fs: expose frsize field in statfs#62277

Open
verycosy wants to merge 1 commit intonodejs:mainfrom
verycosy:fs-statfs-frsize
Open

fs: expose frsize field in statfs#62277
verycosy wants to merge 1 commit intonodejs:mainfrom
verycosy:fs-statfs-frsize

Conversation

@verycosy
Copy link

Expose f_frsize from libuv's uv_statfs_t as statfs.frsize.

libuv 1.52.0 added f_frsize to uv_statfs_t, and this dependency update has already landed in Node.js (5bebd7e),
so users can now compute accurate disk usage on every filesystem type.

Per POSIX, f_blocks, f_bfree, and f_bavail are in units of f_frsize, not f_bsize. On most filesystems the two values happen to be equal, so blocks * bsize gives a correct result. However, some filesystem drivers report a larger bsize as the I/O transfer size while frsize remains at the actual block size, producing a significant overestimation.

I hit this on a Docker container using virtiofs with a bind-mounted host directory:

$ node -e "console.log(fs.statfsSync('/data'))"
StatFs {
  bsize: 1048576,   // 1 MiB — I/O transfer size
  frsize: 4096,     // 4 KiB — actual block size
  blocks: 120699413,
  ...
}
Calculation Result
blocks × frsize ~460 GB correct
blocks × bsize ~117,870 GB 256× overestimation

Without frsize exposed, there is no way to work around this using the Node.js API alone.

See also libuv/libuv#4983 where the same problem was discussed.

Expose `f_frsize` from libuv's `uv_statfs_t` as `statfs.frsize`.

Per POSIX, `f_blocks`, `f_bfree`, and `f_bavail` are expressed in
units of `f_frsize`, not `f_bsize`. On most filesystems the two
values are typically equal, but some filesystem drivers report a
different `f_bsize`, making it impossible to compute accurate disk
usage without `frsize`.

Refs: libuv/libuv#4983
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 16, 2026
@addaleax addaleax added fs Issues and PRs related to the fs subsystem / file system. semver-minor PRs that contain new features and should be released in the next minor version. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Mar 16, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 16, 2026
@nodejs-github-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.67%. Comparing base (4579957) to head (c848da3).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #62277   +/-   ##
=======================================
  Coverage   89.67%   89.67%           
=======================================
  Files         676      676           
  Lines      206555   206557    +2     
  Branches    39554    39546    -8     
=======================================
+ Hits       185230   185236    +6     
+ Misses      13461    13444   -17     
- Partials     7864     7877   +13     
Files with missing lines Coverage Δ
lib/internal/fs/utils.js 99.68% <100.00%> (+<0.01%) ⬆️
src/node_file-inl.h 87.71% <100.00%> (+0.05%) ⬆️
src/node_file.h 78.43% <ø> (ø)

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants