Skip to content

Commit 267747e

Browse files
committed
doc: add missing examples and information to fs
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
1 parent 02ad688 commit 267747e

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

doc/api/fs.md

+46-22
Original file line numberDiff line numberDiff line change
@@ -7510,13 +7510,19 @@ added:
75107510
75117511
Free blocks available to unprivileged users.
75127512
7513-
Example:
75147513
```js
7515-
const fs = require('fs');
7516-
// Calculate available space in bytes
7517-
fs.statfs('.', (err,stats) => {
7514+
const fs = require('fs');
7515+
// Calculate available space in bytes
7516+
fs.statfs('.', (err,stats) => {
7517+
const availableSpace = stats.bavail * stats.bsize;
7518+
console.log(`Available space for unprivileged users: ${availableSpace} bytes`);
7519+
});
7520+
```
7521+
```mjs
7522+
import { statfs } from 'fs';
7523+
// Calculate available space in bytes
7524+
statfs('.', (err, stats) => {
75187525
const availableSpace = stats.bavail * stats.bsize;
7519-
75207526
console.log(`Available space for unprivileged users: ${availableSpace} bytes`);
75217527
});
75227528
```
@@ -7533,13 +7539,19 @@ added:
75337539
75347540
Free blocks in file system.
75357541
7536-
Example:
75377542
```js
7538-
const fs = require('fs');
7539-
// Calculate total free space in bytes using bfree and bsize
7540-
fs.statfs('.', (err,stats) => {
7543+
const fs = require('fs');
7544+
// Calculate total free space in bytes using bfree and bsize
7545+
fs.statfs('.', (err,stats) => {
7546+
const totalFreeSpace = stats.bfree * stats.bsize;
7547+
console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
7548+
});
7549+
```
7550+
```mjs
7551+
import { statfs } from 'fs';
7552+
// Calculate total free space in bytes using bfree and bsize
7553+
statfs('.', (err, stats) => {
75417554
const totalFreeSpace = stats.bfree * stats.bsize;
7542-
75437555
console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
75447556
});
75457557
```
@@ -7556,13 +7568,19 @@ added:
75567568
75577569
Total data blocks in file system.
75587570
7559-
Example:
75607571
```js
7561-
const fs = require('fs');
7562-
// Get the total number of blocks
7563-
fs.statfs('.', (err,stats) => {
7572+
const fs = require('fs');
7573+
// Get the total number of blocks
7574+
fs.statfs('.', (err,stats) => {
7575+
const totalBlocks = stats.blocks;
7576+
console.log(`Total number of blocks on the filesystem: ${totalBlocks}`);
7577+
});
7578+
```
7579+
```mjs
7580+
import { statfs } from 'fs';
7581+
// Get the total number of blocks
7582+
statfs('.', (err, stats) => {
75647583
const totalBlocks = stats.blocks;
7565-
75667584
console.log(`Total number of blocks on the filesystem: ${totalBlocks}`);
75677585
});
75687586
```
@@ -7603,14 +7621,20 @@ added:
76037621
76047622
Total file nodes in file system.
76057623
7606-
Example:
76077624
```js
7608-
const fs = require('fs');
7609-
fs.statfs('.', (err, stats) => {
7610-
// Calculate total free space in bytes using bfree and bsize
7611-
const totalFreeSpace = stats.bfree * stats.bsize;
7612-
7613-
console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
7625+
const fs = require('fs');
7626+
//Calculate total file nodes in file system
7627+
fs.statfs('.', (err, stats) => {
7628+
const totalInodes = stats.files;
7629+
console.log(`Total number of inodes (files) on filesystem: ${totalInodes}`);
7630+
});
7631+
```
7632+
```mjs
7633+
import { statfs } from 'fs';
7634+
//Calculate total file nodes in file system
7635+
statfs('.', (err, stats) => {
7636+
const totalInodes = stats.files;
7637+
console.log(`Total number of inodes (files) on filesystem: ${totalInodes}`);
76147638
});
76157639
```
76167640

0 commit comments

Comments
 (0)