Skip to content

Commit e916e38

Browse files
marcelsafinCopilot
andcommitted
doc: improve fs.StatFs property descriptions and add examples
Add missing information to the fs.StatFs class documentation: - Clarify that bsize and frsize values are in bytes - Add ESM and CJS examples showing how to calculate disk space - Explain the relationship between block counts and bsize - Clarify the difference between bavail (unprivileged) and bfree (total) - Document that type is a filesystem magic number with common values - Add cross-references between related properties Fixes: #50749 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4563cb3 commit e916e38

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

doc/api/fs.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7926,6 +7926,32 @@ StatFs {
79267926
}
79277927
```
79287928
7929+
To calculate disk space from a `StatFs` object, multiply the block count
7930+
properties by the block size (`statfs.bsize`) to convert them to bytes.
7931+
Pass `{ bigint: true }` to avoid loss of precision on large file systems:
7932+
7933+
```mjs
7934+
import { statfs } from 'node:fs/promises';
7935+
7936+
const stats = await statfs('/', { bigint: true });
7937+
7938+
console.log(`Total: ${stats.blocks * stats.bsize} bytes`);
7939+
console.log(`Free: ${stats.bfree * stats.bsize} bytes`);
7940+
console.log(`Available: ${stats.bavail * stats.bsize} bytes`);
7941+
```
7942+
7943+
```cjs
7944+
const { statfs } = require('node:fs');
7945+
7946+
statfs('/', { bigint: true }, (err, stats) => {
7947+
if (err) throw err;
7948+
7949+
console.log(`Total: ${stats.blocks * stats.bsize} bytes`);
7950+
console.log(`Free: ${stats.bfree * stats.bsize} bytes`);
7951+
console.log(`Available: ${stats.bavail * stats.bsize} bytes`);
7952+
});
7953+
```
7954+
79297955
#### `statfs.bavail`
79307956
79317957
<!-- YAML
@@ -7936,7 +7962,8 @@ added:
79367962
79377963
* Type: {number|bigint}
79387964
7939-
Free blocks available to unprivileged users.
7965+
Free blocks available to unprivileged users. Unlike [`statfs.bfree`][],
7966+
this value excludes blocks reserved for privileged processes.
79407967
79417968
#### `statfs.bfree`
79427969
@@ -7948,7 +7975,9 @@ added:
79487975
79497976
* Type: {number|bigint}
79507977
7951-
Free blocks in file system.
7978+
Free blocks in file system, including blocks reserved for privileged
7979+
processes. See [`statfs.bavail`][] for the count available to
7980+
unprivileged users.
79527981
79537982
#### `statfs.blocks`
79547983
@@ -7972,7 +8001,7 @@ added:
79728001
79738002
* Type: {number|bigint}
79748003
7975-
Optimal transfer block size.
8004+
Optimal transfer block size, in bytes.
79768005
79778006
#### `statfs.frsize`
79788007
@@ -7982,7 +8011,7 @@ added: REPLACEME
79828011
79838012
* Type: {number|bigint}
79848013
7985-
Fundamental file system block size.
8014+
Fundamental file system block size, in bytes.
79868015
79878016
#### `statfs.ffree`
79888017
@@ -7994,7 +8023,7 @@ added:
79948023
79958024
* Type: {number|bigint}
79968025
7997-
Free file nodes in file system.
8026+
Free file nodes (inodes) in file system.
79988027
79998028
#### `statfs.files`
80008029
@@ -8006,7 +8035,7 @@ added:
80068035
80078036
* Type: {number|bigint}
80088037
8009-
Total file nodes in file system.
8038+
Total file nodes (inodes) in file system.
80108039
80118040
#### `statfs.type`
80128041
@@ -8018,7 +8047,11 @@ added:
80188047
80198048
* Type: {number|bigint}
80208049
8021-
Type of file system.
8050+
Type of file system. On Linux this is a filesystem magic number (for
8051+
example, `0xEF53` for ext2/ext3/ext4, `0x5346544e` for NTFS,
8052+
`0x01021994` for tmpfs, and `0x6969` for NFS). The value is
8053+
platform-dependent and may be `0` on systems where libuv does not
8054+
report it.
80228055
80238056
### Class: `fs.Utf8Stream`
80248057
@@ -9052,6 +9085,8 @@ the file contents.
90529085
[`fs.rmdir()`]: #fsrmdirpath-options-callback
90539086
[`fs.stat()`]: #fsstatpath-options-callback
90549087
[`fs.statfs()`]: #fsstatfspath-options-callback
9088+
[`statfs.bavail`]: #statfsbavail
9089+
[`statfs.bfree`]: #statfsbfree
90559090
[`fs.symlink()`]: #fssymlinktarget-path-type-callback
90569091
[`fs.utimes()`]: #fsutimespath-atime-mtime-callback
90579092
[`fs.watch()`]: #fswatchfilename-options-listener

0 commit comments

Comments
 (0)