xref: /DragonOS/user/apps/test_statfs/main.c (revision 4b0170bd6bb374d0e9699a0076cc23b976ad6db7)
1 #include <sys/statfs.h>
2 #include <stdio.h>
3 
4 int main(int argc,char **argv)
5 {
6     struct statfs diskInfo;
7 
8 
9     statfs("/bin/about.elf", &diskInfo);
10     unsigned long long blocksize1 = diskInfo.f_bsize;    //每个block里包含的字节数
11     unsigned long long totalsize = blocksize1 * diskInfo.f_blocks;//总的字节数,f_blocks为block的数目
12     printf("Total_size=%llu B =%llu KB =%llu MB = %llu GB\n",
13            totalsize,totalsize>>10,totalsize>>20, totalsize>>30);
14 
15     /* 2.获取一下剩余空间和可用空间的大小 */
16     unsigned long long freeDisk = diskInfo.f_bfree * blocksize1;  //剩余空间的大小
17     unsigned long long availableDisk = diskInfo.f_bavail * blocksize1; //可用空间大小
18     printf("Disk_free=%llu MB =%llu GB Disk_available=%llu MB = %llu GB\n",
19            freeDisk>>20,freeDisk>>30,availableDisk>>20, availableDisk>>30);
20 
21 
22     printf("====================\n");
23     printf("diskInfo address: %p\n", diskInfo);
24     printf("f_type= %lu\n", diskInfo.f_type);
25     printf("f_bsize = %lu\n", diskInfo.f_bsize);
26     printf("f_blocks = %d\n", diskInfo.f_blocks);
27     printf("f_bfree = %lu\n", diskInfo.f_bfree);
28     printf("b_avail = %d\n", diskInfo.f_bavail);
29     printf("f_files = %d\n", diskInfo.f_files);
30     printf("f_ffree = %lu\n", diskInfo.f_ffree);
31     printf("f_fsid = %ld\n", diskInfo.f_fsid);
32     printf("f_namelen = %ld\n", diskInfo.f_namelen);
33     printf("f_frsize = %ld\n", diskInfo.f_frsize);
34     printf("f_flags = %ld\n", diskInfo.f_flags);
35     return 0;
36 }