Linux通过c得到硬盘使用情况(转)[@more@]下面的代码可以得到硬盘使用情况:
CODE:
#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) < 0) { return -1; } else { total = fsu.f_blocks; available = fsu.f_bavail; available_to_root = fsu.f_bfree; used = total - available_to_root; scale = fsu.f_bsize / 1024; pct = 0; if (total != 0 ) pct = (used * 100) / (used + available) + ((used *100) % (used + available) != 0); fprintf (stdout, "%-15s %15s %10ld %10ld %10ld %9.0f%% %-s ", mnt->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 来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10617542/viewspace-960415/,如需转载,请注明出处,否则将追究法律责任。
上一篇:
Linux下驱动SD/MMC读卡器(转)
![]()
请登录后发表评论
登录
全部评论
<%=items[i].createtime%>
<%=items[i].content%> <%if(items[i].items.items.length) { %>
<%for(var j=0;j
<%}%> <%}%>
<%=items[i].items.items[j].createtime%>
<%=items[i].items.items[j].username%> 回复 <%=items[i].items.items[j].tousername%>: <%=items[i].items.items[j].content%>
还有<%=items[i].items.total-5%>条评论
) data-count=1 data-flag=true>点击查看
<%}%>
|
转载于:http://blog.itpub.net/10617542/viewspace-960415/