Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: updated the Class:fs filesystem documentation as it was missing … #55279

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shrenisc
Copy link

@shrenisc shrenisc commented Oct 5, 2024

Defined the return type for statfs.bsize. Added examples for statfs.bavail, statfs.bfree, statfs.blocks and statfs.files for clarity. Explained why statfs.type returns a int|bigint value and added a table with most commonly used magic numbers and their filesystems.

Fixes: #50749

…information and examples

Defined the return type for statfs.bsize. Added examples for statfs.bavail, statfs.bfree, statfs.blocks and statfs.files for clarity. Cleared the air on why statfs.type returns a int|bigint value.

Fixes: 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 Oct 5, 2024
Comment on lines +7513 to +7529
Example:
```mjs
const fs = require('fs');

// Specify the path you want to check (like '/' or 'C:/').
fs.statfs('.', (err, stats) => {
if (err) {
console.error('Error reading file system stats:', err);
return;
}

// Calculate available space in bytes
const availableSpace = stats.bavail * stats.bsize;

console.log(`Available space for unprivileged users: ${availableSpace} bytes`);
});
```
Copy link
Member

Choose a reason for hiding this comment

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

This is commonjs, but the mjs code block is used

Comment on lines +7513 to +7529
Example:
```mjs
const fs = require('fs');

// Specify the path you want to check (like '/' or 'C:/').
fs.statfs('.', (err, stats) => {
if (err) {
console.error('Error reading file system stats:', err);
return;
}

// Calculate available space in bytes
const availableSpace = stats.bavail * stats.bsize;

console.log(`Available space for unprivileged users: ${availableSpace} bytes`);
});
```
Copy link
Member

Choose a reason for hiding this comment

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

IMO for the sake of the example, error handling isn't needed.

Comment on lines +7543 to +7559
Example:
```mjs
const fs = require('fs');

// Specify the path of the filesystem to check (e.g., current directory).
fs.statfs('.', (err, stats) => {
if (err) {
console.error('Error reading file system stats:', err);
return;
}

// Calculate total free space in bytes using bfree and bsize
const totalFreeSpace = stats.bfree * stats.bsize;

console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
});
```
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines +7573 to +7590
Example:
```mjs
const fs = require('fs');

// Specify the path of the filesystem to check (e.g., current directory).
fs.statfs('.', (err, stats) => {
if (err) {
console.error('Error reading file system stats:', err);
return;
}

// Get the total number of blocks
const totalBlocks = stats.blocks;

console.log(`Total number of blocks on the filesystem: ${totalBlocks}`);
});
```
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines +7627 to +7644
Example:
```mjs
const fs = require('fs');

// Specify the path of the filesystem to check (e.g., current directory).
fs.statfs('.', (err, stats) => {
if (err) {
console.error('Error reading file system stats:', err);
return;
}

// Calculate total free space in bytes using bfree and bsize
const totalFreeSpace = stats.bfree * stats.bsize;

console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
});
```
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines +7656 to +7658
This value is the decimal representation of the magic number* of the filesystem. Converting this number|bigint to hexadecimal will return the magic number.
*magic number- refers to the hexadecimal numeric coding mapped to each filesystem.
Copy link
Member

Choose a reason for hiding this comment

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

No need for a footnote.

@@ -7544,7 +7598,7 @@ added:
* {number|bigint}
Optimal transfer block size.
Optimal transfer block size(this value is in bytes for POSIX-compliant or UNIX-like Operating Systems including but not limited to Windows, Linux, MacOS, FreeBSD, OpenBSD, NetBSD, Solaris/Illumos etc).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Optimal transfer block size(this value is in bytes for POSIX-compliant or UNIX-like Operating Systems including but not limited to Windows, Linux, MacOS, FreeBSD, OpenBSD, NetBSD, Solaris/Illumos etc).
Optimal transfer block size (measured in bytes)

Why is all this extra info here?

Comment on lines 7655 to +7658
Type of file system.
This value is the decimal representation of the magic number* of the filesystem. Converting this number|bigint to hexadecimal will return the magic number.
*magic number- refers to the hexadecimal numeric coding mapped to each filesystem.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Type of file system.
This value is the decimal representation of the magic number* of the filesystem. Converting this number|bigint to hexadecimal will return the magic number.
*magic number- refers to the hexadecimal numeric coding mapped to each filesystem.
Type of file system, represented by the decimal form of the file's magic number.

Comment on lines +7660 to +7748
Here are some common filesystems and their magic numbers:
<table>
<tr>
<th>Filesystem</th>
<th>Magic Number (Hexadecimal)</th>
<th>Description</th>
</tr>
<tr>
<td>ext2</td>
<td>0xEF53</td>
<td>Second Extended File System (Linux)</td>
</tr>
<tr>
<td>ext3</td>
<td>0xEF53</td>
<td>Third Extended File System (Linux)</td>
</tr>
<tr>
<td>ext4</td>
<td>0xEF53</td>
<td>Fourth Extended File System (Linux)</td>
</tr>
<tr>
<td>Btrfs</td>
<td>0x9123683E</td>
<td>B-tree File System (Linux)</td>
</tr>
<tr>
<td>XFS</td>
<td>0x58465342</td>
<td>X File System (Linux)</td>
</tr>
<tr>
<td>FAT</td>
<td>0xadf5</td>
<td>File Allocation Table (legacy FAT)</td>
</tr>
<tr>
<td>NFS</td>
<td>0x6969</td>
<td>Network File System</td>
</tr>
<tr>
<td>ISO 9660</td>
<td>0x9660</td>
<td>CD-ROM File System</td>
</tr>
<tr>
<td>SMB/CIFS</td>
<td>0xFF534D42</td>
<td>Server Message Block / Common Internet File System</td>
</tr>
<tr>
<td>JFFS2</td>
<td>0x72B6</td>
<td>Journaling Flash File System</td>
</tr>
<tr>
<td>UDF</td>
<td>0x15013346</td>
<td>Universal Disk Format</td>
</tr>
<tr>
<td>procfs</td>
<td>0x9fa0</td>
<td>Process File System</td>
</tr>
<tr>
<td>sysfs</td>
<td>0x62656572</td>
<td>System File System</td>
</tr>
<tr>
<td>tmpfs</td>
<td>0x01021994</td>
<td>Temporary File System</td>
</tr>
<tr>
<td>cgroupfs</td>
<td>0x27e0eb</td>
<td>Control Group File System</td>
</tr>
<tr>
<td>ramfs</td>
<td>0x858458f6</td>
<td>RAM File System</td>
</tr>
</table>
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a table, is there a wikipage or something that users can be referred to?

@RedYetiDev
Copy link
Member

Can you fix your commit message? Something like:

doc: add missing examples and information to fs

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
3 participants