繁体   English   中英

如何使用在Linux上运行的C语言程序获取驱动器的确切总空间?

[英]How can I get exact total space of a drive using C language program running on Linux?

如何使用在Linux上运行的C语言程序获取驱动器的确切总空间? 我不想使用外壳脚本。 有什么建议么?

statfs/statfs64

#include <sys/vfs.h>    /* or <sys/statfs.h> */
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);

从手册页:

  The function statfs() 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 statfs structure defined approximately as follows: struct statfs { long f_type; /* type of file system (see below) */ long f_bsize; /* optimal transfer block size */ long f_blocks; /* total data blocks in file system */ long f_bfree; /* free blocks in fs */ long f_bavail; /* free blocks avail to non-superuser */ long f_files; /* total file nodes in file system */ long f_ffree; /* free file nodes in fs */ fsid_t f_fsid; /* file system id */ long f_namelen; /* maximum length of filenames */ }; 

您可以像这样使用它:

struct statfs buf;
statfs("/", &buf);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM