How Get "% Disk Used" in Code (QNX 6.0)?

Can someone give me an idea of how to determine the percentage
of disk usage from in C code?

I know how to get the information from the shell (“df -kP”), but I need
to do it from inside an application. Source for “df” would be great!

The goal is to monitor disk usage and purge old files when the usage
exceeds a predetermined percentage of the total space. This is an
embedded system with limited space on the filesystem.


Jeff Maass jmaass@columbus.rr.com Located near Columbus Ohio
USPSA # L-1192 NROI/CRO Amateur Radio K8ND
Maass’ IPSC Resources Page: http://home.columbus.rr.com/jmaass

Jeff Maass <jmaass@columbus.rr.com> wrote:

Can someone give me an idea of how to determine the percentage
of disk usage from in C code?

statvfs(); the ratio of f_bfree to f_blocks is probably what you want.
Be sure to aim statvfs() at the filesystem (eg “/fs/hd”) and not
the disk (eg “/dev/hd0t79”) as that would tell you about the physical
composition (all blocks “used”), not the logical usage of a filesystem.