Skip to content

Commit

Permalink
doc: add missing examples and information to fs
Browse files Browse the repository at this point in the history
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: nodejs#50749
  • Loading branch information
shrenisc committed Oct 11, 2024
1 parent 1f4396a commit a9bddf6
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7510,13 +7510,19 @@ added:
Free blocks available to unprivileged users.
Example:
```js
const fs = require('fs');
// Calculate available space in bytes
fs.statfs('.', (err,stats) => {
const fs = require('fs');
// Calculate available space in bytes
fs.statfs('.', (err,stats) => {
const availableSpace = stats.bavail * stats.bsize;
console.log(`Available space for unprivileged users: ${availableSpace} bytes`);
});
```
```mjs
import { statfs } from 'fs';
// Calculate available space in bytes
statfs('.', (err, stats) => {
const availableSpace = stats.bavail * stats.bsize;

console.log(`Available space for unprivileged users: ${availableSpace} bytes`);
});
```
Expand All @@ -7533,13 +7539,19 @@ added:
Free blocks in file system.
Example:
```js
const fs = require('fs');
// Calculate total free space in bytes using bfree and bsize
fs.statfs('.', (err,stats) => {
const fs = require('fs');
// Calculate total free space in bytes using bfree and bsize
fs.statfs('.', (err,stats) => {
const totalFreeSpace = stats.bfree * stats.bsize;
console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
});
```
```mjs
import { statfs } from 'fs';
// Calculate total free space in bytes using bfree and bsize
statfs('.', (err, stats) => {
const totalFreeSpace = stats.bfree * stats.bsize;

console.log(`Total free space (including reserved blocks): ${totalFreeSpace} bytes`);
});
```
Expand All @@ -7556,13 +7568,19 @@ added:
Total data blocks in file system.
Example:
```js
const fs = require('fs');
// Get the total number of blocks
fs.statfs('.', (err,stats) => {
const fs = require('fs');
// Get the total number of blocks
fs.statfs('.', (err,stats) => {
const totalBlocks = stats.blocks;
console.log(`Total number of blocks on the filesystem: ${totalBlocks}`);
});
```
```mjs
import { statfs } from 'fs';
// Get the total number of blocks
statfs('.', (err, stats) => {
const totalBlocks = stats.blocks;

console.log(`Total number of blocks on the filesystem: ${totalBlocks}`);
});
```
Expand Down Expand Up @@ -7603,14 +7621,20 @@ added:
Total file nodes in file system.
Example:
```js
const fs = require('fs');
fs.statfs('.', (err, stats) => {
// 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`);
const fs = require('fs');
//Calculate total file nodes in file system
fs.statfs('.', (err, stats) => {
const totalInodes = stats.files;
console.log(`Total number of inodes (files) on filesystem: ${totalInodes}`);
});
```
```mjs
import { statfs } from 'fs';
//Calculate total file nodes in file system
statfs('.', (err, stats) => {
const totalInodes = stats.files;
console.log(`Total number of inodes (files) on filesystem: ${totalInodes}`);
});
```
Expand Down

0 comments on commit a9bddf6

Please sign in to comment.