Chinaunix首页 | 论坛 | 博客
  • 博客访问: 441753
  • 博文数量: 70
  • 博客积分: 3170
  • 博客等级: 中校
  • 技术积分: 756
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-06 16:47
文章分类

全部博文(70)

文章存档

2011年(22)

2010年(33)

2009年(5)

2008年(10)

分类: LINUX

2010-11-23 17:02:45

#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;
}

阅读(1171) | 评论(1) | 转发(0) |
0

上一篇:DMA技术

下一篇:ping 程序

给主人留下些什么吧!~~

chinaunix网友2010-11-24 13:21:52

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com