Skip to content

doc: clarify fs.StatFs field descriptions#62262

Open
AkaHarshit wants to merge 2 commits intonodejs:mainfrom
AkaHarshit:docs/fs-statfs-clarify-field-descriptions
Open

doc: clarify fs.StatFs field descriptions#62262
AkaHarshit wants to merge 2 commits intonodejs:mainfrom
AkaHarshit:docs/fs-statfs-clarify-field-descriptions

Conversation

@AkaHarshit
Copy link

Problem

The documentation for the fs.StatFs class fields is minimal and lacks important details:

  • statfs.bsize does not mention whether the value is in bits or bytes.
  • statfs.bavail, statfs.bfree, and statfs.blocks do not explain how to use these values to calculate actual disk space.
  • statfs.files and statfs.ffree do not explain what "file nodes" (inodes) are or why they matter.
  • statfs.type does not explain what the numeric value represents.

Solution

  • Clarified all seven fs.StatFs field descriptions with proper units, context, and practical guidance.
  • Added ESM and CJS usage examples showing how to calculate total, free, and available disk space from the StatFs object.
  • Explained the relationship between bavail and bfree (reserved blocks for superuser).
  • Documented that statfs.type is a filesystem magic number and returns 0 on Windows.

Why it matters

The fs.StatFs class is used for disk space monitoring and system health checks. Without clear documentation, users must guess at units, relationships between fields, or consult external sources. These improvements make the API self-documenting and reduce the learning curve for new users.

Testing

This is a documentation-only change. The code examples have been manually verified for correctness.

Linked Issue

Refs: #50749

Improve documentation for the fs.StatFs class fields:

- statfs.bsize: clarify that the block size is in bytes
- statfs.bavail: explain it returns free blocks for unprivileged users
  and how to calculate available space in bytes
- statfs.bfree: explain it includes reserved blocks and how to
  calculate total free space in bytes
- statfs.blocks: explain how to calculate total filesystem size
- statfs.files and statfs.ffree: explain inodes and their importance
- statfs.type: explain filesystem magic numbers and Windows behavior

Add ESM and CJS usage examples showing how to calculate total, free,
and available disk space from the StatFs object.

Refs: nodejs#50749
@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 Mar 15, 2026
Copy link
Member

@mertcanaltin mertcanaltin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

doc/api/fs.md Outdated
* Type: {number|bigint}

Optimal transfer block size.
The optimal transfer block size in bytes. This value represents the fundamental
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bsize POSIX defines the optimal transfer block size, not the allocation block size. Just appending "in bytes"

doc/api/fs.md Outdated
Type of file system.
A numeric identifier for the file system type. This value is a filesystem magic
number set by the operating system kernel, such as `0xEF53` for ext4 or
`0x01021994` for tmpfs on Linux. On Windows, this value is `0`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only Windows return 0 , libuv also returns 0 on Solaris, OpenBSD, NetBSD, Haiku, and QNX, consider changing "On Windows" to "On some platforms"

Suggested change
`0x01021994` for tmpfs on Linux. On Windows, this value is `0`.
`0x01021994` for tmpfs on Linux. On some platforms (e.g., Windows, Solaris), this value is `0`.

- Simplify bsize description per POSIX definition (optimal transfer
  block size, in bytes)
- Change 'On Windows' to 'On some platforms' for statfs.type since
  libuv also returns 0 on Solaris, OpenBSD, NetBSD, Haiku, and QNX
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.

3 participants