LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 3709|回复: 3

statfs获得硬盘使用情况

[复制链接]
发表于 2007-8-25 08:28:29 | 显示全部楼层 |阅读模式
我在http://bbs.chinaunix.net/viewthr ... 了这段代码:

  1. #include <stdio.h>;
  2. #include <sys/vfs.h>;
  3. #include <error.h>;

  4. #define Gsize (1024.00*1024.00*1024.00)
  5. #define Msize (1024.00*1024.00)

  6. #ifndef EXT2_SUPER_MAGIC
  7. #define EXT2_SUPER_MAGIC 0xef53
  8. #endif

  9. int main()
  10. {
  11.         long long blocks,bfree;
  12.         struct statfs fs;
  13.         if(statfs("/",&fs)<0)
  14.         {
  15.                 perror("statfs");
  16.                 exit(0);
  17.         }

  18. //      printf("%x\n",fs.f_type);      /* type of filesystem (see below) */
  19. //      printf("%ld\n",fs.f_bsize);    /* optimal transfer block size */
  20. //      printf("%ld\n",fs.f_blocks);   /* total data blocks in file system */
  21. //      printf("%ld\n",fs.f_bfree);    /* free blocks in fs */
  22. //      printf("%ld\n",fs.f_bavail);   /* free blocks avail to non-superuser */
  23. //      printf("%ld\n",fs.f_files);    /* total file nodes in file system */
  24. //      printf("%ld\n",fs.f_ffree);    /* free file nodes in fs */
  25. //      printf("%d\n",fs.f_fsid);     /* file system id */
  26. //      printf("%ld\n",fs.f_namelen);  /* maximum length of filenames */

  27.         blocks=fs.f_blocks;
  28.         bfree=fs.f_bfree;
  29. //      printf(" %lld\n",blocks);
  30.         if(fs.f_type==EXT2_SUPER_MAGIC)
  31.         {
  32.                 printf("Total size of / is %f G\n",blocks*fs.f_bsize/Gsize);
  33.                 printf("Free size of / is %f G\n",bfree*fs.f_bsize/Gsize);
  34.         }
  35. }
复制代码


说是可以查看硬盘的一些使用情况,我用的是AIX系统,我编译运行
[sdb@SDB lxy]xlc -g -o statfs statfs.c
[sdb@SDB lxy]./statfs
Total size of / is 0.125000G
Free size of / is 0.098507G
[sdb@SDB lxy]df -g
Filesystem    GB ブロック      Free %Used    Iused %Iused Mounted on
/dev/hd4                 0.12      0.10   22%     1941     3% /
/dev/hd2                 3.50      0.27   93%    67043     8% /usr
/dev/hd9var              0.12      0.09   29%      626     2% /var
/dev/hd3                 3.75      2.99   21%      195     1% /tmp
/dev/fwdump              0.12      0.12    4%       18     1% /var/adm/ras/platform
/dev/hd1                 0.50      0.11   78%     1089     1% /home
/proc                       -         -    -         -     -  /proc
/dev/hd10opt             1.25      0.49   62%     9371     3% /opt
/dev/loglv               5.00      4.77    5%      147     1% /log
/dev/dblv               15.00     13.28   12%      523     1% /db
/dev/srclv              10.00      8.99   11%     5352     1% /src
/dev/imglv              24.50     23.57    4%     2189     1% /img
bficmdb:/home/ccm_wa          914.18    828.46   10%   324927     1% /home/ccm_wa

它得到的只是/这个目录的大小和剩余空间,怎样才可以获得整个硬盘的信息呢,还有如果有多个硬盘那又如何得到他们的情况呢,哪位仁兄知道给我说一下,谢谢了。
 楼主| 发表于 2007-8-25 14:14:49 | 显示全部楼层
顺便问一下AIXz中想得到某个硬盘在剩余空间的命令是什么啊?我的机子有两个硬盘:
[sdb@SDB ~]lspv
hdisk0          00c62acffa0b82bd                    rootvg          active
hdisk1          00c62acfc0cd3ab5                    rootvg          active
想得到hdisk0剩余空间大小用什么命令啊?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-8-25 16:38:34 | 显示全部楼层
再问个问题:
[sdb@SDB lxy]lspv hdisk0
PHYSICAL VOLUME:    hdisk0                   VOLUME GROUP:     rootvg
PV IDENTIFIER:      00c62acffa0b82bd VG IDENTIFIER     00c62acf00004c0000000111fa0b9a3a
PV STATE:           active                                    
STALE PARTITIONS:   0                        ALLOCATABLE:      yes
PP SIZE:            128 megabyte(s)          LOGICAL VOLUMES:  15
TOTAL PPs:          546 (69888 megabytes)    VG DESCRIPTORS:   2
FREE PPs:           0 (0 megabytes)          HOT SPARE:        no
USED PPs:           546 (69888 megabytes)    MAX REQUEST:      256 kilobytes
FREE DISTRIBUTION:  00..00..00..00..00                        
USED DISTRIBUTION:  110..109..109..109..109     

总大小是不是546 * 128啊,还有FREE PPs:怎么是0呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-8-25 16:59:54 | 显示全部楼层
怎么没人回答我在问题啊,郁闷。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表