I am writing a cross-platform application and I need the full available disk space. For posix systems (Linux and Macos) I use statvfs. I created this C ++ method:
long OSSpecificPosix::getFreeDiskSpace(const char* absoluteFilePath) {
struct statvfs buf;
if (!statvfs(absoluteFilePath, &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;
return free;
}
else {
return -1;
}
}
Unfortunately, I get pretty strange values that I cannot understand. For example: f_blocks = 73242188 f_bsize = 1048576 f_bfree = 50393643 ...
Are these values bits, bytes, or something else? I read here about stackoverflow, which should be bytes, but then I would get the total number of free bytes: f_bsize * f_bfree = 1048576 * 50393643 but that means 49212.542GB ... too much ...
Am I doing something with code or something else? Thank!