#include
#include
#include
#include
#include
#include
int get_blk_size(unsigned int *blksize,unsigned int *blkuse){
unsigned int blkfree = 0;
FILE *fp = fopen("/etc/mtab","rb");
if (NULL == fp){
return 0;
}
while(1){
struct mntent *mt = getmntent(fp);
if(NULL==mt){
break;
}
printf("fs_name:[%s]\n",mt->mnt_fsname);
if (NULL != strstr(mt->mnt_fsname,"/dev/")){
struct statfs buf;
// printf("fsname:[%s]\n",mt->mnt_fsname);
statfs(mt->mnt_dir,&buf);
*blksize+= (buf.f_bsize/1024*buf.f_blocks);
blkfree+=(buf.f_bsize/1024*buf.f_bfree);
}
}
*blkuse = *blksize - blkfree;
fclose(fp);
return 0;
}
int main(){
int blksize =0 ;
int blkuse = 0;
get_blk_size(&blksize,&blkuse) ;
printf("blk_size:[%d] blkuse:[%d]\n",blksize,blkuse);
return 0;
}
阅读(1228) | 评论(1) | 转发(0) |