From cd87e8ac76d60f786dbbdb92169e1ef7ed32d729 Mon Sep 17 00:00:00 2001 From: justinian Date: Sun, 29 Mar 2026 17:03:04 +0100 Subject: [PATCH] fs: expose frsize field in statfs results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- doc/api/fs.md | 20 ++++++++++++++++++-- lib/internal/fs/utils.js | 4 +++- src/node_file-inl.h | 1 + src/node_file.h | 1 + test/parallel/test-fs-promises.js | 1 + test/parallel/test-fs-statfs.js | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 6330a921732f46..4adbad564b3acf 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -7899,7 +7899,8 @@ StatFs { bfree: 61058895, bavail: 61058895, files: 999, - ffree: 1000000 + ffree: 1000000, + frsize: 4096 } ``` @@ -7913,7 +7914,8 @@ StatFs { bfree: 61058895n, bavail: 61058895n, files: 999n, - ffree: 1000000n + ffree: 1000000n, + frsize: 4096n } ``` @@ -7989,6 +7991,20 @@ added: Total file nodes in file system. +#### `statfs.frsize` + + + +* Type: {number|bigint} + +Fundamental file system block size. This is the unit in which `blocks`, +`bfree`, and `bavail` are counted. On most file systems this equals `bsize`, +but on FUSE mounts (e.g. Docker Desktop on macOS using VirtioFS) they can +differ. Use `frsize` (not `bsize`) when calculating disk space from block +counts. + #### `statfs.type`