cal free disk space
I all,
i'm trying to calculate the disk usage and free space using statvfs. I' using this code but when I execute th "df ." the values dont match Can anyone help me?? Best regards /* Any file on the filesystem in question */ char *filename = "/home/nesto/test/test.cpp"; struct statvfs buf; if (!statvfs(filename, &buf)) { unsigned long blksize, blocks, freeblks, disk_size, used, free; blksize = buf.f_bsize; blocks = buf.f_blocks; freeblks = buf.f_bfree; disk_size = blocks * blksize; free = freeblks * blksize; used = disk_size - free; printf("Disk usage : %lu \t Free space %lu\n", used, free); } else { printf("Couldn't get file system statistics\n"); } return 0; |
df . prints values in 1K size, so you need to multiply by 4, not by blksize.
|
All times are GMT -5. The time now is 07:25 AM. |