|
我在http://bbs.chinaunix.net/viewthr ... 了这段代码:
- #include <stdio.h>;
- #include <sys/vfs.h>;
- #include <error.h>;
- #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);
- }
- }
复制代码
说是可以查看硬盘的一些使用情况,我用的是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
它得到的只是/这个目录的大小和剩余空间,怎样才可以获得整个硬盘的信息呢,还有如果有多个硬盘那又如何得到他们的情况呢,哪位仁兄知道给我说一下,谢谢了。 |
|