Skip to content

doc: improve fs.StatFs field descriptions and add usage examples#61965

Open
turanalmammadov wants to merge 1 commit intonodejs:mainfrom
turanalmammadov:docs/fix-statfs-documentation
Open

doc: improve fs.StatFs field descriptions and add usage examples#61965
turanalmammadov wants to merge 1 commit intonodejs:mainfrom
turanalmammadov:docs/fix-statfs-documentation

Conversation

@turanalmammadov
Copy link

Fixes #50749

What is improved?

The fs.StatFs documentation was sparse and left several questions unanswered for users:

statfs.bsize

  • Before: "Optimal transfer block size."
  • After: Explicitly states the unit is bytes and explains that all bXxx fields are block counts that must be multiplied by bsize to obtain byte values. Includes a short code snippet.

statfs.bavail / statfs.bfree

  • Before: One-sentence descriptions that don't explain the difference between the two.
  • After: Explains that bfree includes superuser-reserved blocks while bavail is what unprivileged processes can actually use. Adds a bavail * bsize example showing how to compute available space in GB.

statfs.blocks

  • After: Adds a three-line example computing total, used, and available space in GB from the three block-count fields — the most common reason a developer reaches for statfs.

statfs.files / statfs.ffree

  • After: Explains that these measure inodes (one per file/directory/symlink), not bytes. Notes the edge case where disk space is available but no new files can be created. Adds an inode-usage-percentage example.

statfs.type

  • Before: "Type of file system." (not useful at all)
  • After: Explains the value is the OS-level numeric identifier from f_type in the POSIX statvfs structure. Points to the canonical headers for each OS (<linux/magic.h>, <sys/mount.h>), notes the Windows behaviour (always 0), and adds a hex-printing code example.

Code examples

All examples are included in both ESM (import) and CJS (require) variants where the length warrants it, following the existing style in the fs documentation.

Made with Cursor

Addresses the gaps reported in nodejs#50749:

*  - explicitly state the unit is bytes, which is
  non-obvious because the other fields are measured in *blocks*.

*  /  - explain the difference between
  the two (superuser-reserved blocks), and add a code example showing
  how to multiply by bsize to get available bytes.

*  - add a code example that computes total, used, and
  available space in gigabytes from the three block-count fields.

*  /  - explain that these measure inodes,
  not bytes; add a code example showing how to calculate inode usage.

*  - explain that the value is a numeric OS-level file
  system identifier; point to the canonical header files for Linux
  (<linux/magic.h>) and macOS (<sys/mount.h>); note that the value is
  platform-specific and always 0 on Windows; add a code snippet that
  prints the value in hex for easier cross-referencing.

All examples are provided in both ESM and CJS variants where applicable.

Fixes: nodejs#50749
Co-authored-by: Cursor <cursoragent@cursor.com>
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing documentation in fs.StatFs

2 participants