linux 编程 文件夹大小,Linux C程序实现文件夹大小提取

下面的程序使用statfs函数实现硬盘大小数据提取,及剩余空间大小的提取,并把硬盘大小及剩余空间打印出来。

#include ;

#include ;

#include ;

#define Gsize (1024.00*1024.00*1024.00)

#define Msize (1024.00*1024.00)

#ifndef EXT2_SUPER_MAGIC

#define EXT2_SUPER_MAGIC 0xef53

#endif

int main()

{

long long blocks,bfree;

struct statfs fs;

if(statfs("/",&fs)<0)

{

perror("statfs");

exit(0);

}

printf("%x\n",fs.f_type);      /* type of filesystem (see below) */

printf("%ld\n",fs.f_bsize);    /* optimal transfer block size */

printf("%ld\n",fs.f_blocks);   /* total data blocks in file system */

printf("%ld\n",fs.f_bfree);    /* free blocks in fs */

printf("%ld\n",fs.f_bavail);   /* free blocks avail to non-superuser */

printf("%ld\n",fs.f_files);    /* total file nodes in file system */

printf("%ld\n",fs.f_ffree);    /* free file nodes in fs */

printf("%d\n",fs.f_fsid);     /* file system id */

printf("%ld\n",fs.f_namelen);  /* maximum length of filenames */

blocks=fs.f_blocks;

bfree=fs.f_bfree;

printf(" %lld\n",blocks);

if(fs.f_type==EXT2_SUPER_MAGIC)

{

printf("Total size of / is %f G\n",blocks*fs.f_bsize/Gsize);

printf("Free size of / is %f G\n",bfree*fs.f_bsize/Gsize);

}

}0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值