fs: expose frsize field in statfs results#62495
Open
juicecultus wants to merge 1 commit intonodejs:mainfrom
Open
fs: expose frsize field in statfs results#62495juicecultus wants to merge 1 commit intonodejs:mainfrom
juicecultus wants to merge 1 commit intonodejs:mainfrom
Conversation
Node.js statfs() exposes bsize (optimal I/O block size) but not frsize (fundamental filesystem block size). Per POSIX, block counts (blocks, bfree, bavail) are in units of frsize, not bsize. libuv already reads f_frsize from the kernel β it was simply not mapped to JavaScript. On most native filesystems bsize == frsize, so the omission was harmless. However, on FUSE mounts (e.g. Docker Desktop on macOS with VirtioFS or gRPC FUSE), they can differ by orders of magnitude (bsize=2MiB vs frsize=16KiB), causing applications that compute disk space as bsize*blocks to report wildly inflated values. This commit adds the frsize property to the StatFs object returned by fs.statfs(), fs.statfsSync(), and fsPromises.statfs(), in both normal and bigint modes.
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.
Description
fs.statfs()exposesbsize(optimal I/O block size) but notfrsize(fundamental filesystem block size). Per POSIX, block counts (blocks,bfree,bavail) are in units offrsize, notbsize. libuv already readsf_frsizefrom the kernel and stores it inuv_statfs_tβ it was simply never mapped to JavaScript.On most native filesystems
bsize == frsize, so the omission was harmless. However, on FUSE mounts (e.g. Docker Desktop on macOS with VirtioFS or gRPC FUSE), they can diverge by orders of magnitude:* blocksresultbsizefrsizeThis causes any application computing disk space as
bsize * blocksto report wildly inflated values. Real-world example: Immich photo manager shows "602 TiB of 1.8 PiB" on a 15 TB disk when running in Docker on macOS.Changes
Adds the
frsizeproperty to theStatFsobject returned byfs.statfs(),fs.statfsSync(), andfsPromises.statfs(), in both normal and bigint modes.Files changed:
src/node_file.hβ addkFrSizetoFsStatFsOffsetenumsrc/node_file-inl.hβ maps->f_frsizeinFillStatFsArray()lib/internal/fs/utils.jsβ addfrsizetoStatFsclass and bindingdoc/api/fs.mdβ document the new fieldtest/parallel/test-fs-statfs.jsβ includefrsizein property checkstest/parallel/test-fs-promises.jsβ includefrsizein type assertionsNotes
f_frsizefrom the kernel'sstatfs.f_frsizef_frsize = f_bsize, so this is always populated