@@ -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,9 @@ 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. Use
7967+ ` statfs .bavail * statfs .bsize ` to get the available space in bytes.
79407968
79417969#### ` statfs .bfree `
79427970
@@ -7948,7 +7976,10 @@ added:
79487976
79497977* Type: {number|bigint}
79507978
7951- Free blocks in file system.
7979+ Free blocks in file system, including reserved blocks that are not
7980+ available to unprivileged users. See [` statfs .bavail ` ][] for the
7981+ unreserved count. Use ` statfs .bfree * statfs .bsize ` to get the free
7982+ space in bytes.
79527983
79537984#### ` statfs .blocks `
79547985
@@ -7960,7 +7991,8 @@ added:
79607991
79617992* Type: {number|bigint}
79627993
7963- Total data blocks in file system.
7994+ Total data blocks in file system. Use ` statfs .blocks * statfs .bsize `
7995+ to get the total size in bytes.
79647996
79657997#### ` statfs .bsize `
79667998
@@ -7972,7 +8004,9 @@ added:
79728004
79738005* Type: {number|bigint}
79748006
7975- Optimal transfer block size.
8007+ Optimal transfer block size, in bytes. This value can be used to convert
8008+ block count properties (such as [` statfs .blocks ` ][], [` statfs .bfree ` ][],
8009+ and [` statfs .bavail ` ][]) to bytes.
79768010
79778011#### ` statfs .frsize `
79788012
@@ -7982,7 +8016,7 @@ added: REPLACEME
79828016
79838017* Type: {number|bigint}
79848018
7985- Fundamental file system block size.
8019+ Fundamental file system block size, in bytes .
79868020
79878021#### ` statfs .ffree `
79888022
@@ -7994,7 +8028,7 @@ added:
79948028
79958029* Type: {number|bigint}
79968030
7997- Free file nodes in file system.
8031+ Free file nodes (inodes) in file system.
79988032
79998033#### ` statfs .files `
80008034
@@ -8006,7 +8040,7 @@ added:
80068040
80078041* Type: {number|bigint}
80088042
8009- Total file nodes in file system.
8043+ Total file nodes (inodes) in file system.
80108044
80118045#### ` statfs .type `
80128046
@@ -8018,7 +8052,9 @@ added:
80188052
80198053* Type: {number|bigint}
80208054
8021- Type of file system.
8055+ Type of file system. On Linux this is a filesystem magic number (for
8056+ example, ` 0xEF53 ` for ext2/ext3/ext4). The value is platform-dependent
8057+ and may be ` 0 ` on systems where libuv does not report it.
80228058
80238059### Class: ` fs .Utf8Stream `
80248060
@@ -9052,6 +9088,10 @@ the file contents.
90529088[` fs .rmdir ()` ]: #fsrmdirpath-options-callback
90539089[` fs .stat ()` ]: #fsstatpath-options-callback
90549090[` fs .statfs ()` ]: #fsstatfspath-options-callback
9091+ [` statfs .bavail ` ]: #statfsbavail
9092+ [` statfs .bfree ` ]: #statfsbfree
9093+ [` statfs .blocks ` ]: #statfsblocks
9094+ [` statfs .bsize ` ]: #statfsbsize
90559095[` fs .symlink ()` ]: #fssymlinktarget-path-type-callback
90569096[` fs .utimes ()` ]: #fsutimespath-atime-mtime-callback
90579097[` fs .watch ()` ]: #fswatchfilename-options-listener
0 commit comments