Percent usage of a filesystem using statvfs()
807578Jan 18 2005 — edited Jan 25 2005Hi,
I am using statvfs() to find the percentage of available space in a filesystem. This is how I compute for the number:
struct statvfs *buf;
[1-(buf->bavail/buf->f_blocks)]*100
I use df -k to verify if the numbers match.
I noticed that my computation matches with the result of df -k when used on a remote filesystem(NFS mounted) only. The computed percentage is different from what df -k returns for local filesystems. Does anybody know why I have a mismatch for the latter? Is there a better way to do this? I do not want to use the "df -k" command in a popen() call and parse the output for the percent usage because it takes too long( about 1.5 seconds ).
My system information: Sun Ultra60, SunOS 5.6 .
Thanks.