PDA

View Full Version : get free harddisk space in c program



monkeyking
February 5th, 2009, 02:52 AM
If I want system info about my memory I can simply read the

/proc/mem_info
If I want system info about my cpu usage I can simply read the first line in

/proc/stat

Are there no simple way to get the information about the harddisk usage.
Similar to the first line in the output of df

thanks in advance

stroyan
February 5th, 2009, 04:27 AM
You can find the mounted file systems by reading /etc/mtab.

You can find the free and used space of each file system by calling statfs() for each mount point.

monkeyking
February 11th, 2009, 06:10 PM
Hey, thanks for your reply, but I ended up doing something like this.



#include <sys/statvfs.h>
...
float perc = (100*(1-(float)diskinfo.f_bavail/diskinfo.f_blocks));

perc will then be a number between 0-100 with the current percentage of diskusage.