Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db66a96

Browse filesBrowse files
verycosyaduh95
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 4ad07de commit db66a96
Copy full SHA for db66a96

6 files changed

+19-3Lines changed: 19 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -7895,6 +7895,7 @@ numeric values will be `bigint` instead of `number`.
78957895
StatFs {
78967896
type: 1397114950,
78977897
bsize: 4096,
7898+
frsize: 4096,
78987899
blocks: 121938943,
78997900
bfree: 61058895,
79007901
bavail: 61058895,
@@ -7909,6 +7910,7 @@ StatFs {
79097910
StatFs {
79107911
type: 1397114950n,
79117912
bsize: 4096n,
7913+
frsize: 4096n,
79127914
blocks: 121938943n,
79137915
bfree: 61058895n,
79147916
bavail: 61058895n,
@@ -7965,6 +7967,16 @@ added:
79657967
79667968
Optimal transfer block size.
79677969
7970+
#### `statfs.frsize`
7971+
7972+
<!-- YAML
7973+
added: REPLACEME
7974+
-->
7975+
7976+
* Type: {number|bigint}
7977+
7978+
Fundamental file system block size.
7979+
79687980
#### `statfs.ffree`
79697981
79707982
<!-- YAML
Collapse file

‎lib/internal/fs/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/utils.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ function getStatsFromBinding(stats, offset = 0) {
571571
}
572572

573573
class StatFs {
574-
constructor(type, bsize, blocks, bfree, bavail, files, ffree) {
574+
constructor(type, bsize, frsize, blocks, bfree, bavail, files, ffree) {
575575
this.type = type;
576576
this.bsize = bsize;
577+
this.frsize = frsize;
577578
this.blocks = blocks;
578579
this.bfree = bfree;
579580
this.bavail = bavail;
@@ -584,7 +585,7 @@ class StatFs {
584585

585586
function getStatFsFromBinding(stats) {
586587
return new StatFs(
587-
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6],
588+
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6], stats[7],
588589
);
589590
}
590591

Collapse file

‎src/node_file-inl.h‎

Copy file name to clipboardExpand all lines: src/node_file-inl.h
+1Lines 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);
Collapse file

‎src/node_file.h‎

Copy file name to clipboardExpand all lines: src/node_file.h
+1Lines 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,
Collapse file

‎test/parallel/test-fs-promises.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises.js
+1Lines 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);
Collapse file

‎test/parallel/test-fs-statfs.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-statfs.js
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.