Getting disk free space with statvfs()

Hello all,

I’m trying to get the free space on my disk (in this case /dev/hd0t79) using
statvfs() (I currently get zero from both disk space feilds). I’ve read
through the archives, so I already know that if you give statvfs() the wrong
file it will return correct disk capacity, but wrong free space info.

What am I doing wrong here?

#include <stdio.h>
#include <sys/statvfs.h>


int main()
{

struct statvfs stat_fs;

if (statvfs("/dev/hd0t79", &stat_fs)!=0)
{
perror(“statvfs:”);
exit(0);
}

printf(“Disk space available %ld MB\n”,
(unsigned long) stat_fs.f_bfree * stat_fs.f_bsize);
printf(“Total disk free space %ld MB\n”,
(unsigned long) stat_fs.f_bavail * stat_fs.f_bsize);
exit(0);

}

$ getFree
Disk space available 0 MB
Total disk free space 0 MB
$