如何在Linux中以编程方式获取目录的可用磁盘空间

如何在Linux中以编程方式获取目录的可用磁盘空间,第1张

如何在Linux中以编程方式获取目录的可用磁盘空间

校验

man statvfs(2)

我相信您可以将“可用空间”计算为

f_bsize * f_bfree

NAME       statvfs, fstatvfs - get file system statisticsSYNOPSIS       #include <sys/statvfs.h>       int statvfs(const char *path, struct statvfs *buf);       int fstatvfs(int fd, struct statvfs *buf);DEscriptION       The function statvfs() returns information about a mounted file system.       path is the pathname of any file within the mounted file  system.   buf       is a pointer to a statvfs structure defined approximately as follows:struct statvfs {    unsigned long  f_bsize;        unsigned long  f_frsize;       fsblkcnt_t     f_blocks;       fsblkcnt_t     f_bfree;        fsblkcnt_t     f_bavail;       fsfilcnt_t     f_files;        fsfilcnt_t     f_ffree;        fsfilcnt_t     f_favail;       unsigned long  f_fsid;         unsigned long  f_flag;         unsigned long  f_namemax;  };


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5012250.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存