#include <mntent.h>
#include <sys/vfs.h>
int main(void){
struct mntent *m;
FILE *f;
f = setmntent("/etc/mtab", "r");
while((m = getmntent(f)))
getstatfs(m->mnt_dir);
endmntent(f);
}
int getstatfs(char *path)
{
struct statfs fs;
int percentbfree=0;
int percentnfree=0;
if(statfs(path, &fs) != 0)
return(-1);
if((fs.f_bfree == 0)||(fs.f_ffree == 0))
return(-1);
percentbfree = (int)(100*fs.f_bfree)/fs.f_blocks;
percentnfree = (int)(100*fs.f_ffree)/fs.f_files;
int ffree = fs.f_ffree/1024;
int blocks = fs.f_blocks/1024;
printf("file system for %s has %dM free blocks out of a total of %dM - %d. Total of %d%% FREE \n",path,ffree,blocks,percentbfree,percentnfree);
return(0);
}
mntent例子
最新推荐文章于 2023-06-02 14:03:30 发布