Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7899,7 +7899,8 @@ StatFs {
bfree: 61058895,
bavail: 61058895,
files: 999,
ffree: 1000000
ffree: 1000000,
frsize: 4096
}
```

Expand All @@ -7913,7 +7914,8 @@ StatFs {
bfree: 61058895n,
bavail: 61058895n,
files: 999n,
ffree: 1000000n
ffree: 1000000n,
frsize: 4096n
}
```

Expand Down Expand Up @@ -7989,6 +7991,20 @@ added:

Total file nodes in file system.

#### `statfs.frsize`

<!-- YAML
added: REPLACEME
-->

* 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`

<!-- YAML
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,22 @@ function getStatsFromBinding(stats, offset = 0) {
}

class StatFs {
constructor(type, bsize, blocks, bfree, bavail, files, ffree) {
constructor(type, bsize, blocks, bfree, bavail, files, ffree, frsize) {
this.type = type;
this.bsize = bsize;
this.blocks = blocks;
this.bfree = bfree;
this.bavail = bavail;
this.files = files;
this.ffree = ffree;
this.frsize = frsize;
}
}

function getStatFsFromBinding(stats) {
return new StatFs(
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6],
stats[7],
);
}

Expand Down
1 change: 1 addition & 0 deletions src/node_file-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void FillStatFsArray(AliasedBufferBase<NativeT, V8T>* fields,
SET_FIELD(kBAvail, s->f_bavail);
SET_FIELD(kFiles, s->f_files);
SET_FIELD(kFFree, s->f_ffree);
SET_FIELD(kFrSize, s->f_frsize);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like GHA is complaining about this on some platforms.


#undef SET_FIELD
}
Expand Down
1 change: 1 addition & 0 deletions src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class FsStatFsOffset {
kBAvail,
kFiles,
kFFree,
kFrSize,
kFsStatFsFieldsNumber
};

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function verifyStatFsObject(stat, isBigint = false) {
assert.strictEqual(typeof stat.bavail, valueType);
assert.strictEqual(typeof stat.files, valueType);
assert.strictEqual(typeof stat.ffree, valueType);
assert.strictEqual(typeof stat.frsize, valueType);
}

async function getHandle(dest) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-statfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function verifyStatFsObject(statfs, isBigint = false) {
const valueType = isBigint ? 'bigint' : 'number';

[
'type', 'bsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
'type', 'bsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree', 'frsize',
].forEach((k) => {
assert.ok(Object.hasOwn(statfs, k));
assert.strictEqual(typeof statfs[k], valueType,
Expand Down
Loading