Created
May 27, 2022 06:44
-
-
Save aarmot/0e9e3cba9251650e950705d351341043 to your computer and use it in GitHub Desktop.
Get filesystem usage in C
This file contains 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 <sys/vfs.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main (int argc, char **argv) { | |
if (argc < 2) exit(EXIT_FAILURE); | |
struct statfs info; | |
if (statfs(argv[1], &info) == 0) { | |
printf("%s - block size: %ld," | |
" total data blocks: %ld," | |
" free blocks for root: %ld," | |
" free blocks for user: %ld\n ", | |
argv[1], info.f_bsize, info.f_blocks, info.f_bfree, info.f_bavail); | |
exit(EXIT_SUCCESS); | |
} else { | |
perror("statfs()"); | |
exit(EXIT_FAILURE); | |
} | |
} | |
// gcc -Wall -Wextra -O2 -o statfs statfs.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment