Oder man verwendet ein einfaches C-Progamm:
C
#include <stdio.h>
#include <sys/vfs.h>
#include <libgen.h>
#define FAIL 1
void usage(char *argv[]);
int main(int argc, char *argv[]) {
int retval;
struct statfs s;
long total_blocks = 0;
long free_blocks = 0;
double percent_free = 0.0;
if (argc < 2) {
usage(argv);
return(FAIL);
}
/* Get file system statistics */
retval = statfs(argv[1], &s);
if (retval == 0) {
total_blocks = s.f_blocks;
free_blocks = s.f_bfree;
if (total_blocks == 0) {
printf("Error: Total number of blocks returned zero.\n");
return(FAIL);
}
percent_free = (double) free_blocks / total_blocks * 100;
printf("%.1f%%\n", percent_free);
} else {
printf("Error: Couldn't retrieve file system statistics for \"%s\".\n", argv[1]);
}
return(retval);
}
void usage(char *argv[]) {
printf("Usage: %s path\n", basename(argv[0]));
printf("\n");
printf(" Displays usage of a mounted file system (in percent).\n");
printf("\n");
printf(" Path must be any path or file (e. g. the mount point itself)\n");
printf(" of the file system for which the usage should be displayed.\n");
printf("\n");
printf(" If you specify a device file (e. g. /dev/hda1), you won't get\n");
printf(" the usage of the file system on /dev/hda1, but the usage of the\n");
printf(" file system in which the device node /dev/hda1 resides.\n");
}
Alles anzeigen