Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Percent usage of a filesystem using statvfs()

807578Jan 18 2005 — edited Jan 25 2005
Hi,

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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2005
Added on Jan 18 2005
2 comments
396 views