gpt4 book ai didi

C Linux 检查挂载空间

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:25:55 27 4
gpt4 key购买 nike

当我运行 df -h 时,我可以在 /dev 中看到我使用 6M,大小为 40M,可用大小为 34M。

如何使用 C 代码获取此信息?

最佳答案

来自 here :

使用statvfs API:

// header for statvfs
#include <sys/statvfs.h>

statvfs的原型(prototype)是

int statvfs(const char *path, struct statvfs *buf);

结果将填充到 buf statvfs 结构中:

struct statvfs {
unsigned long f_bsize; /* filesystem block size */
unsigned long f_frsize; /* fragment size */
fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
fsblkcnt_t f_bfree; /* # free blocks */
fsblkcnt_t f_bavail; /* # free blocks for unprivileged users */
fsfilcnt_t f_files; /* # inodes */
fsfilcnt_t f_ffree; /* # free inodes */
fsfilcnt_t f_favail; /* # free inodes for unprivileged users */
unsigned long f_fsid; /* filesystem ID */
unsigned long f_flag; /* mount flags */
unsigned long f_namemax; /* maximum filename length */
};

返回类型是:

On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

另请查看 man3 statvfs 命令的联机帮助页以获取更多详细信息。

关于C Linux 检查挂载空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com