下面的代码可以得到硬盘使用情况:
#include
#include
#include
#include
#include
#include
#include
#include
static const char *ignore_fs[] = {
"none", "proc", "sysfs", "devpts", "usbfs", "usbdevfs", NULL };
int main (int argc, char **argv)
{
struct mntent *mnt;
struct statfs fsu;
FILE *fp;
char *table = MOUNTED;
long total, used, available, available_to_root;
double pct;
char **p;
int scale, flag = 0;
char buf[BUFSIZ];
memset (buf, 0, BUFSIZ);
fp = setmntent (table, "r");
if (fp == NULL)
{
return -1;
}
while ((mnt = getmntent (fp)))
{
for (p = (char **)ignore_fs; *p; p++)
{
if (strcmp (mnt->mnt_fsname, *p) == 0)
{
flag = 1;
break;;
}
}
if (flag)
{
flag = 0;
continue;
}
if (statfs (mnt->mnt_dir, &fsu) mnt_fsname, mnt->mnt_type, total*scale, used*scale,
available*scale, pct, mnt->mnt_dir);
}
}
endmntent (fp);
return 0;
}
[zhanghua@localhost ZA]$ gcc fsinfo.c -o fsinfo
[zhanghua@localhost ZA]$ ./fsinfo
/dev/sda2 ext3 5771500 5166820 311496 95% /
/dev/sda1 ext3 101089 9424 86446 10% /boot
Linux下如何检查硬盘使用情况
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/d97b390959969b1e68f49b4cc7ced919.html