#include #include #include #include #ifdef __linux__ #include #include #endif #include "statfs.h" int getstatfspath() { /* For OpenBSD */ #ifdef __OpenBSD__ int mntsize=0; int i=0; struct statfs *fs; mntsize = getmntinfo(&fs, MNT_NOWAIT); if(mntsize == 0) { return(-1); } for(i=0;imnt_dir); endmntent(f); #endif return(0); } int getstatfs(char *path) { struct statfs fs; int percentbfree=0; int percentnfree=0; if(statfs(path, &fs) != 0) return(-1); if((fs.f_bfree == 0)||(fs.f_ffree == 0)) return(-1); percentbfree = (int)(100*fs.f_bfree)/fs.f_blocks; percentnfree = (int)(100*fs.f_ffree)/fs.f_files; printf("file system for %s has %d free blocks out of a total of %d - %d. Total of %d%% FREE \n",path,fs.f_ffree,fs.f_blocks,percentbfree,percentnfree); return(0); }