@@ -7654,6 +7654,39 @@ StatFs {
76547654}
76557655` ` `
76567656
7657+ The following example shows how to calculate disk space information from a
7658+ ` StatFs` object. The total, free, and available space in bytes can be
7659+ calculated by multiplying the respective block counts by the block size
7660+ (` bsize` ).
7661+
7662+ ` ` ` mjs
7663+ import { statfs } from ' node:fs/promises' ;
7664+
7665+ const stats = await statfs (' /' );
7666+ const totalSpace = stats .blocks * stats .bsize ;
7667+ const freeSpace = stats .bfree * stats .bsize ;
7668+ const availableSpace = stats .bavail * stats .bsize ;
7669+
7670+ console .log (` Total: ${ totalSpace / (1024 ** 3 )} GiB` );
7671+ console .log (` Free: ${ freeSpace / (1024 ** 3 )} GiB` );
7672+ console .log (` Available: ${ availableSpace / (1024 ** 3 )} GiB` );
7673+ ` ` `
7674+
7675+ ` ` ` cjs
7676+ const { statfs } = require (' node:fs' );
7677+
7678+ statfs (' /' , (err , stats ) => {
7679+ if (err) throw err;
7680+ const totalSpace = stats .blocks * stats .bsize ;
7681+ const freeSpace = stats .bfree * stats .bsize ;
7682+ const availableSpace = stats .bavail * stats .bsize ;
7683+
7684+ console .log (` Total: ${ totalSpace / (1024 ** 3 )} GiB` );
7685+ console .log (` Free: ${ freeSpace / (1024 ** 3 )} GiB` );
7686+ console .log (` Available: ${ availableSpace / (1024 ** 3 )} GiB` );
7687+ });
7688+ ` ` `
7689+
76577690#### ` statfs .bavail `
76587691
76597692<!-- YAML
@@ -7664,7 +7697,10 @@ added:
76647697
76657698* Type: {number|bigint}
76667699
7667- Free blocks available to unprivileged users.
7700+ The number of free blocks available to unprivileged users. The available disk
7701+ space in bytes can be calculated as ` statfs .bavail * statfs .bsize ` . This value
7702+ may be less than ` statfs .bfree ` because the file system may reserve blocks for
7703+ the superuser.
76687704
76697705#### ` statfs .bfree `
76707706
@@ -7676,7 +7712,9 @@ added:
76767712
76777713* Type: {number|bigint}
76787714
7679- Free blocks in file system.
7715+ The total number of free blocks in the file system, including reserved blocks
7716+ that are not available to unprivileged users. The total free disk space in
7717+ bytes can be calculated as ` statfs .bfree * statfs .bsize ` .
76807718
76817719#### ` statfs .blocks `
76827720
@@ -7688,7 +7726,8 @@ added:
76887726
76897727* Type: {number|bigint}
76907728
7691- Total data blocks in file system.
7729+ The total number of data blocks in the file system. The total file system size
7730+ in bytes can be calculated as ` statfs .blocks * statfs .bsize ` .
76927731
76937732#### ` statfs .bsize `
76947733
@@ -7700,7 +7739,8 @@ added:
77007739
77017740* Type: {number|bigint}
77027741
7703- Optimal transfer block size.
7742+ The optimal transfer block size in bytes. This value represents the fundamental
7743+ block size used by the file system for allocating and transferring data.
77047744
77057745#### ` statfs .ffree `
77067746
@@ -7712,7 +7752,10 @@ added:
77127752
77137753* Type: {number|bigint}
77147754
7715- Free file nodes in file system.
7755+ The number of free file nodes (inodes) in the file system. An inode is a data
7756+ structure used by the file system to store information about a file or
7757+ directory. A lack of free inodes can prevent the creation of new files even
7758+ when disk space is available.
77167759
77177760#### ` statfs .files `
77187761
@@ -7724,7 +7767,8 @@ added:
77247767
77257768* Type: {number|bigint}
77267769
7727- Total file nodes in file system.
7770+ The total number of file nodes (inodes) in the file system. This represents the
7771+ maximum number of files and directories the file system can hold.
77287772
77297773#### ` statfs .type `
77307774
@@ -7736,7 +7780,9 @@ added:
77367780
77377781* Type: {number|bigint}
77387782
7739- Type of file system.
7783+ A numeric identifier for the file system type. This value is a filesystem magic
7784+ number set by the operating system kernel, such as ` 0xEF53 ` for ext4 or
7785+ ` 0x01021994 ` for tmpfs on Linux. On Windows, this value is ` 0 ` .
77407786
77417787### Class: ` fs .Utf8Stream `
77427788
0 commit comments