Skip to content

Commit e77dd8d

Browse files
verycosyjuanarbol
authored andcommitted
fs: expose frsize field in statfs
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 PR-URL: #62277 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent 83b594a commit e77dd8d

6 files changed

Lines changed: 19 additions & 3 deletions

File tree

doc/api/fs.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7556,6 +7556,7 @@ numeric values will be `bigint` instead of `number`.
75567556
StatFs {
75577557
type: 1397114950,
75587558
bsize: 4096,
7559+
frsize: 4096,
75597560
blocks: 121938943,
75607561
bfree: 61058895,
75617562
bavail: 61058895,
@@ -7570,6 +7571,7 @@ StatFs {
75707571
StatFs {
75717572
type: 1397114950n,
75727573
bsize: 4096n,
7574+
frsize: 4096n,
75737575
blocks: 121938943n,
75747576
bfree: 61058895n,
75757577
bavail: 61058895n,
@@ -7626,6 +7628,16 @@ added:
76267628
76277629
Optimal transfer block size.
76287630
7631+
#### `statfs.frsize`
7632+
7633+
<!-- YAML
7634+
added: REPLACEME
7635+
-->
7636+
7637+
* Type: {number|bigint}
7638+
7639+
Fundamental file system block size.
7640+
76297641
#### `statfs.ffree`
76307642
76317643
<!-- YAML

lib/internal/fs/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,10 @@ function getStatsFromBinding(stats, offset = 0) {
575575
}
576576

577577
class StatFs {
578-
constructor(type, bsize, blocks, bfree, bavail, files, ffree) {
578+
constructor(type, bsize, frsize, blocks, bfree, bavail, files, ffree) {
579579
this.type = type;
580580
this.bsize = bsize;
581+
this.frsize = frsize;
581582
this.blocks = blocks;
582583
this.bfree = bfree;
583584
this.bavail = bavail;
@@ -588,7 +589,7 @@ class StatFs {
588589

589590
function getStatFsFromBinding(stats) {
590591
return new StatFs(
591-
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6],
592+
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6], stats[7],
592593
);
593594
}
594595

src/node_file-inl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ void FillStatFsArray(AliasedBufferBase<NativeT, V8T>* fields,
153153

154154
SET_FIELD(kType, s->f_type);
155155
SET_FIELD(kBSize, s->f_bsize);
156+
SET_FIELD(kFrSize, s->f_frsize);
156157
SET_FIELD(kBlocks, s->f_blocks);
157158
SET_FIELD(kBFree, s->f_bfree);
158159
SET_FIELD(kBAvail, s->f_bavail);

src/node_file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ constexpr size_t kFsStatsBufferLength =
4444
enum class FsStatFsOffset {
4545
kType = 0,
4646
kBSize,
47+
kFrSize,
4748
kBlocks,
4849
kBFree,
4950
kBAvail,

test/parallel/test-fs-promises.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ function verifyStatFsObject(stat, isBigint = false) {
8989
assert.strictEqual(typeof stat, 'object');
9090
assert.strictEqual(typeof stat.type, valueType);
9191
assert.strictEqual(typeof stat.bsize, valueType);
92+
assert.strictEqual(typeof stat.frsize, valueType);
9293
assert.strictEqual(typeof stat.blocks, valueType);
9394
assert.strictEqual(typeof stat.bfree, valueType);
9495
assert.strictEqual(typeof stat.bavail, valueType);

test/parallel/test-fs-statfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function verifyStatFsObject(statfs, isBigint = false) {
77
const valueType = isBigint ? 'bigint' : 'number';
88

99
[
10-
'type', 'bsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
10+
'type', 'bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
1111
].forEach((k) => {
1212
assert.ok(Object.hasOwn(statfs, k));
1313
assert.strictEqual(typeof statfs[k], valueType,

0 commit comments

Comments
 (0)