summaryrefslogtreecommitdiff
path: root/lib/fs.js
diff options
context:
space:
mode:
authorColin Ihrig <cjihrig@gmail.com>2023-01-29 12:43:20 -0500
committerGitHub <noreply@github.com>2023-01-29 17:43:20 +0000
commitf145766011a9b600ff7c4fea043f435f70f6d0bf (patch)
treed2a74c941f33542b13847618c0b2dab583cae40c /lib/fs.js
parent0a4610740ba5295452fc7cf3cbfc6f3caafbe3d4 (diff)
downloadnode-new-f145766011a9b600ff7c4fea043f435f70f6d0bf.tar.gz
fs: add statfs() functions
This commit adds statfs() and statfsSync() to the fs module, and statfs() to the fsPromises module. Co-authored-by: cjihrig <cjihrig@gmail.com> Fixes: https://github.com/nodejs/node/issues/10745 Refs: https://github.com/nodejs/node/pull/31351 PR-URL: https://github.com/nodejs/node/pull/46358 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/fs.js')
-rw-r--r--lib/fs.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/fs.js b/lib/fs.js
index b727d1747c..1e40720512 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -102,6 +102,7 @@ const {
nullCheck,
preprocessSymlinkDestination,
Stats,
+ getStatFsFromBinding,
getStatsFromBinding,
realpathCacheKey,
stringToFlags,
@@ -1509,6 +1510,24 @@ function stat(path, options = { bigint: false }, callback) {
binding.stat(pathModule.toNamespacedPath(path), options.bigint, req);
}
+function statfs(path, options = { bigint: false }, callback) {
+ if (typeof options === 'function') {
+ callback = options;
+ options = kEmptyObject;
+ }
+ callback = maybeCallback(callback);
+ path = getValidatedPath(path);
+ const req = new FSReqCallback(options.bigint);
+ req.oncomplete = (err, stats) => {
+ if (err) {
+ return callback(err);
+ }
+
+ callback(err, getStatFsFromBinding(stats));
+ };
+ binding.statfs(pathModule.toNamespacedPath(path), options.bigint, req);
+}
+
function hasNoEntryError(ctx) {
if (ctx.errno) {
const uvErr = uvErrmapGet(ctx.errno);
@@ -1583,6 +1602,15 @@ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
return getStatsFromBinding(stats);
}
+function statfsSync(path, options = { bigint: false }) {
+ path = getValidatedPath(path);
+ const ctx = { path };
+ const stats = binding.statfs(pathModule.toNamespacedPath(path),
+ options.bigint, undefined, ctx);
+ handleErrorFromBinding(ctx);
+ return getStatFsFromBinding(stats);
+}
+
/**
* Reads the contents of a symbolic link
* referred to by `path`.
@@ -3013,7 +3041,9 @@ module.exports = fs = {
rmdir,
rmdirSync,
stat,
+ statfs,
statSync,
+ statfsSync,
symlink,
symlinkSync,
truncate,