Created
April 15, 2014 01:29
-
-
Save sqbing/10694719 to your computer and use it in GitHub Desktop.
Get Partition Size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <sys/vfs.h> | |
| #include <string.h> | |
| #include <errno.h> | |
| int main(int argc, const char *argv[]) | |
| { | |
| if(argc < 2){ | |
| printf("%s PATH\n", *argv); | |
| return 0; | |
| } | |
| const char *path = argv[1]; | |
| struct statfs buf; | |
| int ret = statfs(path, &buf); | |
| if(ret){ | |
| printf("Failed to stat fs, %s\n", strerror(errno)); | |
| } | |
| else{ | |
| long long blocks, bsize, bfree; | |
| blocks = buf.f_blocks; | |
| bsize = buf.f_bsize; | |
| bfree = buf.f_bfree; | |
| printf("f_type: %4x\n", buf.f_type); | |
| printf("f_bsize: %4x\n", buf.f_bsize); | |
| printf("f_blocks: %lld %.2fGB\n", (long long)buf.f_blocks, ((double)(blocks*bsize)/(1024*1024*1024))); | |
| printf("f_bfree: %lld %.2fGB\n", (long long)buf.f_bfree, ((double)(bfree*bsize)/(1024*1024*1024))); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment