歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下如何檢查硬盤使用情況

Linux下如何檢查硬盤使用情況

日期:2017/2/28 18:03:19   编辑:Linux教程
下面的代碼可以得到硬盤使用情況:
#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
Copyright © Linux教程網 All Rights Reserved