1 | #include <sys/vfs.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include <strings.h> |
---|
4 | |
---|
5 | int main(int argc, char **argv) { |
---|
6 | struct statfs statbuf; |
---|
7 | long long total; |
---|
8 | long long free; |
---|
9 | |
---|
10 | if (argc > 1) { |
---|
11 | bzero(&statbuf, sizeof(statbuf)); |
---|
12 | if (statfs(argv[1], &statbuf) == 0) { |
---|
13 | printf( "Info for : %s\n", argv[1] ); |
---|
14 | printf( "FS Type : 0x%x\n", |
---|
15 | statbuf.f_type ); |
---|
16 | printf( "Tot Blks : %ld\n", statbuf.f_blocks); |
---|
17 | printf( "Free Blks : %ld\n", statbuf.f_bavail); |
---|
18 | printf( "Block Size: %ld\n", statbuf.f_bsize); |
---|
19 | |
---|
20 | total = statbuf.f_blocks; |
---|
21 | total *= statbuf.f_bsize; |
---|
22 | total = total >> 10; |
---|
23 | printf( "TotalKB : %8lld KB ((%ld * %ld) >> 10)\n", |
---|
24 | total, statbuf.f_blocks, statbuf.f_bsize); |
---|
25 | |
---|
26 | free = statbuf.f_bavail; |
---|
27 | free *= statbuf.f_bsize; |
---|
28 | free = free >> 10; |
---|
29 | printf( "FreeKB : %8lld KB ((%ld * %ld) >> 10)\n", |
---|
30 | free, statbuf.f_bavail, statbuf.f_bsize); |
---|
31 | |
---|
32 | printf( "UsedKB : %8lld KB (calculated from TotalKB - FreeKB)\n", |
---|
33 | total - free); |
---|
34 | } else { |
---|
35 | printf( "ERROR: statfs() returned non-zero\n" ); |
---|
36 | perror("statfs()"); |
---|
37 | return( -1 ); |
---|
38 | } |
---|
39 | } else { |
---|
40 | printf( "USAGE: %s DIRECTORY\n", argv[0] ); |
---|
41 | return( -1 ); |
---|
42 | } |
---|
43 | |
---|
44 | return( 0 ); |
---|
45 | } |
---|