Created
January 30, 2012 18:00
-
-
Save moschlar/1705690 to your computer and use it in GitHub Desktop.
get filesystem usage under linux
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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/statvfs.h> | |
#include "pstatvfs.h" | |
#define ARGLEN 255 | |
int main (int argc, char* argv[]) { | |
struct statvfs stat; | |
long int blocksize, bfree, bavail, free, avail; | |
char path[ARGLEN] = "/local"; | |
if (argc == 2) { | |
strncpy(path, argv[1], ARGLEN); | |
path[ARGLEN] = '\0'; | |
} | |
if (statvfs(path, &stat) < 0) { | |
perror("Error in statvfs"); | |
exit(EXIT_FAILURE); | |
} | |
pstatvfs(&stat); | |
blocksize = stat.f_bsize; | |
bfree = stat.f_bfree; | |
bavail = stat.f_bavail; | |
free = bfree * (blocksize / 1024); | |
avail = bavail * (blocksize / 1024); | |
printf("blocksize: %ld\n", blocksize); | |
printf("bfree: %ld\n", bfree); | |
printf("bavail: %ld\n", bavail); | |
printf("\nConversion to KB:\n"); | |
printf("free: %ld\n", free); | |
printf("avail: %ld\n", avail); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment