说是可以查看硬盘的一些使用情况,我用的是AIX系统,我编译运行#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); } }
statfs获得分区使用情况
最新推荐文章于 2024-08-24 10:00:00 发布