diff options
author | Colin Ihrig <cjihrig@gmail.com> | 2023-01-29 12:43:20 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-29 17:43:20 +0000 |
commit | f145766011a9b600ff7c4fea043f435f70f6d0bf (patch) | |
tree | d2a74c941f33542b13847618c0b2dab583cae40c /lib/fs.js | |
parent | 0a4610740ba5295452fc7cf3cbfc6f3caafbe3d4 (diff) | |
download | node-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.js | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -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, |