Skip to content
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

Add fs.statvfs function to get disk size/free/available space + other info #10745

Closed
miniak opened this issue Jan 11, 2017 · 24 comments
Closed
Labels
blocked PRs that are blocked by other issues or PRs. feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. libuv Issues and PRs related to the libuv dependency or the uv binding.

Comments

@miniak
Copy link
Contributor

miniak commented Jan 11, 2017

There is no build in way to get disk space information. There are a few npm modules available:

This is such a basic API that should be built-in.

@mscdex mscdex added feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. labels Jan 11, 2017
@mscdex
Copy link
Contributor

mscdex commented Jan 11, 2017

libuv would need to add such support first, then node would add an API that uses that libuv API.

@mscdex mscdex added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Jan 11, 2017
@cjihrig
Copy link
Contributor

cjihrig commented Jan 12, 2017

From what I can tell, the modules you linked to only provide a subset of what statvfs(). libuv would also require a Windows implementation. It looks like Python rejected a Windows implementation a while back (not sure if that has since changed).

cc: @saghul

@ronkorving
Copy link
Contributor

@miniak I use https://www.npmjs.com/package/storage-device-info, which only depends on NAN. Regardless though, it would be nice to have this built-in.

@saghul
Copy link
Member

saghul commented Jan 13, 2017 via email

@Trott
Copy link
Member

Trott commented Jul 15, 2017

Given that this issue has been inactive for several months, is it sensible close this (or at least mark is at blocked) unless and until the necessary features are added to libuv?

@ronkorving
Copy link
Contributor

I think this is still valid, regardless of people having have spent time on it.

@gibfahn gibfahn added the blocked PRs that are blocked by other issues or PRs. label Jul 16, 2017
@bnoordhuis bnoordhuis added the help wanted Issues that need assistance from volunteers or PRs that need help to proceed. label Jul 17, 2017
@gengjiawen
Copy link
Member

https://github.com/jduncanator/node-diskusage now implements in C++, it also have a Windows implementation.

@refack
Copy link
Contributor

refack commented Nov 11, 2018

Put into https://github.com/nodejs/node/projects/13 backlog

@refack refack closed this as completed Nov 11, 2018
@tomasdev
Copy link

tomasdev commented Mar 9, 2019

So is this happening or not? I see it on the project dashboard but it's now closed?

@sagitsofan
Copy link
Contributor

@refack
Does integration of this package https://github.com/jduncanator/node-diskusage as another deps and expose an api statvfs will be a good solution for this use case?

@sam-github
Copy link
Contributor

@sagitsofan should be opened in libuv/libuv as a feature request, if it can be implemented portably in libuv, then node could expose it.

@sagitsofan
Copy link
Contributor

sagitsofan commented Jul 23, 2019

@sam-github But if we can integrated directly inside node the node-diskusage package we wont be dependent on libuv

@sam-github
Copy link
Contributor

@sagitsofan But we like to depend on uv! Its not a burden, its our compat layer.

@cjihrig
Copy link
Contributor

cjihrig commented Jul 23, 2019

If anyone really wants to see this in Node, I'd recommend opening an issue on the libuv issue tracker. The feature request should describe what the API would look like, taking a Windows implementation into consideration. This python issue is old, but might still be relevant.

@sagitsofan
Copy link
Contributor

sagitsofan commented Aug 3, 2019

So after this feature has been added into libuv core, when will it be available inside node js project?
I would like to create the wrapper in node.

@cjihrig
Copy link
Contributor

cjihrig commented Aug 3, 2019

I'm planning a libuv release for this week. I'll also have to expose the API in Node. It should be available in the next one or two Node 12.x releases.

@sagitsofan
Copy link
Contributor

I would be happy to expose the API in node after the libuv release.

@cjihrig
Copy link
Contributor

cjihrig commented Aug 12, 2019

@sagitsofan were you volunteering to write the fs code to expose uv_fs_statfs()? If you were volunteering, the libuv update has landed in Node.

@sagitsofan
Copy link
Contributor

Sure, i am on it.

SheikhSajid added a commit to SheikhSajid/node that referenced this issue Jan 14, 2020
Use the uv_fs_statfs() function in libuv to add support for statfs
system call to the fs module.

Refs: nodejs#10745
@SheikhSajid SheikhSajid mentioned this issue Jan 14, 2020
4 tasks
SheikhSajid added a commit to SheikhSajid/node that referenced this issue Feb 11, 2020
Add support for statfs system call to the fs module using
uv_fs_statfs() function from libuv.

Refs: nodejs#10745
@nahuel
Copy link

nahuel commented Sep 28, 2020

please reopen this issue, is not resolved yet.

@EagleLizard
Copy link

Is there any ETA for this? Stats does not show the size on disk, which is an issue because it reports file sizes of <20B on disks, when the actual minimum block size for files on a given disk may be ~4096B, so disk calcs end up with significant mismatches

cjihrig added a commit to cjihrig/node that referenced this issue Jan 26, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: nodejs#10745
Refs: nodejs#31351
cjihrig added a commit to cjihrig/node that referenced this issue Jan 26, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: nodejs#10745
Refs: nodejs#31351
nodejs-github-bot pushed a commit that referenced this issue Jan 29, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: #10745
Refs: #31351
PR-URL: #46358
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
ruyadorno pushed a commit that referenced this issue Feb 1, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: #10745
Refs: #31351
PR-URL: #46358
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
juanarbol pushed a commit that referenced this issue Mar 3, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: #10745
Refs: #31351
PR-URL: #46358
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
juanarbol pushed a commit that referenced this issue Mar 3, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: #10745
Refs: #31351
PR-URL: #46358
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
juanarbol pushed a commit that referenced this issue Mar 5, 2023
This commit adds statfs() and statfsSync() to the fs module, and
statfs() to the fsPromises module.

Co-authored-by: cjihrig <cjihrig@gmail.com>
Fixes: #10745
Refs: #31351
PR-URL: #46358
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@koplenov
Copy link

@koplenov
Copy link

For example, let's find out the free disk space as a percentage:

/*
	https://nodejs.org/api/fs.html#fspromisesstatfspath-options
*/

const fsp = require("node:fs/promises");

(async function (){
	const { bfree, blocks } = await fsp.statfs(__dirname)
	const persent = bfree/blocks*100
	console.log({persent})
})()

@RedYetiDev
Copy link
Member

This issue can been closed for years. If you're experiencing an issue, please open a new issue in nodejs/help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. libuv Issues and PRs related to the libuv dependency or the uv binding.
Projects
None yet
Development

No branches or pull requests