-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
0750024
20d8b85
dd678e4
e9a872b
78ee107
9b0a16d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7510,6 +7510,24 @@ added: | |
Free blocks available to unprivileged users. | ||
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`); | ||
}); | ||
``` | ||
Comment on lines
+7513
to
+7529
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO for the sake of the example, error handling isn't needed. |
||
#### `statfs.bfree` | ||
<!-- YAML | ||
|
@@ -7522,6 +7540,24 @@ added: | |
Free blocks in file system. | ||
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`); | ||
}); | ||
``` | ||
Comment on lines
+7561
to
+7577
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
#### `statfs.blocks` | ||
<!-- YAML | ||
|
@@ -7534,6 +7570,24 @@ added: | |
Total data blocks in file system. | ||
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}`); | ||
}); | ||
``` | ||
Comment on lines
+7591
to
+7608
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
#### `statfs.bsize` | ||
<!-- YAML | ||
|
@@ -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). | ||
shrenisc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#### `statfs.ffree` | ||
|
@@ -7570,6 +7624,24 @@ added: | |
Total file nodes in file system. | ||
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`); | ||
}); | ||
``` | ||
Comment on lines
+7645
to
+7662
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
#### `statfs.type` | ||
<!-- YAML | ||
|
@@ -7581,6 +7653,99 @@ added: | |
* {number|bigint} | ||
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. | ||
shrenisc marked this conversation as resolved.
Show resolved
Hide resolved
shrenisc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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> | ||
Comment on lines
+7675
to
+7763
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found a Linux Manual page which lists these filesystems but I am unsure whether we can link it here. Also, they only list Linux filesystems and miss out on the popular NTFS, NFS etc. |
||
### Class: `fs.WriteStream` | ||
|
There was a problem hiding this comment.
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