mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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: https://github.com/libuv/libuv/issues/4983 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
1ccae7cce4
commit
f8ee196c15
6 files changed
+19
-3
No files matched your search
@@ -7895,6 +7895,7 @@ numeric values will be `bigint` instead of `number`.
|
||||
StatFs {
|
||||
type: 1397114950,
|
||||
bsize: 4096,
|
||||
frsize: 4096,
|
||||
blocks: 121938943,
|
||||
bfree: 61058895,
|
||||
bavail: 61058895,
|
||||
@@ -7909,6 +7910,7 @@ StatFs {
|
||||
StatFs {
|
||||
type: 1397114950n,
|
||||
bsize: 4096n,
|
||||
frsize: 4096n,
|
||||
blocks: 121938943n,
|
||||
bfree: 61058895n,
|
||||
bavail: 61058895n,
|
||||
@@ -7965,6 +7967,16 @@ added:
|
||||
|
||||
Optimal transfer block size.
|
||||
|
||||
#### `statfs.frsize`
|
||||
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
* Type: {number|bigint}
|
||||
|
||||
Fundamental file system block size.
|
||||
|
||||
#### `statfs.ffree`
|
||||
|
||||
<!-- YAML
|
||||
|
||||
@@ -571,9 +571,10 @@ function getStatsFromBinding(stats, offset = 0) {
|
||||
}
|
||||
|
||||
class StatFs {
|
||||
constructor(type, bsize, blocks, bfree, bavail, files, ffree) {
|
||||
constructor(type, bsize, frsize, blocks, bfree, bavail, files, ffree) {
|
||||
this.type = type;
|
||||
this.bsize = bsize;
|
||||
this.frsize = frsize;
|
||||
this.blocks = blocks;
|
||||
this.bfree = bfree;
|
||||
this.bavail = bavail;
|
||||
@@ -584,7 +585,7 @@ class StatFs {
|
||||
|
||||
function getStatFsFromBinding(stats) {
|
||||
return new StatFs(
|
||||
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6],
|
||||
stats[0], stats[1], stats[2], stats[3], stats[4], stats[5], stats[6], stats[7],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ void FillStatFsArray(AliasedBufferBase<NativeT, V8T>* fields,
|
||||
|
||||
SET_FIELD(kType, s->f_type);
|
||||
SET_FIELD(kBSize, s->f_bsize);
|
||||
SET_FIELD(kFrSize, s->f_frsize);
|
||||
SET_FIELD(kBlocks, s->f_blocks);
|
||||
SET_FIELD(kBFree, s->f_bfree);
|
||||
SET_FIELD(kBAvail, s->f_bavail);
|
||||
|
||||
@@ -44,6 +44,7 @@ constexpr size_t kFsStatsBufferLength =
|
||||
enum class FsStatFsOffset {
|
||||
kType = 0,
|
||||
kBSize,
|
||||
kFrSize,
|
||||
kBlocks,
|
||||
kBFree,
|
||||
kBAvail,
|
||||
|
||||
@@ -89,6 +89,7 @@ function verifyStatFsObject(stat, isBigint = false) {
|
||||
assert.strictEqual(typeof stat, 'object');
|
||||
assert.strictEqual(typeof stat.type, valueType);
|
||||
assert.strictEqual(typeof stat.bsize, valueType);
|
||||
assert.strictEqual(typeof stat.frsize, valueType);
|
||||
assert.strictEqual(typeof stat.blocks, valueType);
|
||||
assert.strictEqual(typeof stat.bfree, valueType);
|
||||
assert.strictEqual(typeof stat.bavail, valueType);
|
||||
|
||||
@@ -7,7 +7,7 @@ function verifyStatFsObject(statfs, isBigint = false) {
|
||||
const valueType = isBigint ? 'bigint' : 'number';
|
||||
|
||||
[
|
||||
'type', 'bsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
|
||||
'type', 'bsize', 'frsize', 'blocks', 'bfree', 'bavail', 'files', 'ffree',
|
||||
].forEach((k) => {
|
||||
assert.ok(Object.hasOwn(statfs, k));
|
||||
assert.strictEqual(typeof statfs[k], valueType,
|
||||
|
||||
Reference in new issue
Block a user