I m currently trying to get disk space in byte en used space in byte with statfs(). I made a small function but i get really strange values. (I m working on a ubuntu 32bit system)
该守则是:
bool
CheckDiskSpace( const CLString &devPath, ulonglong &diskSize, ulonglong &totalFreeBytes )
{
bool retVal = false;
struct statfs fs;
if( ( statfs( devPath.c_str(), &fs ) ) < 0 ) {
printf( "Failed to stat %s: %s
", devPath.c_str() ,strerror( errno ) );
return false;
} else {
diskSize = fs.f_blocks * fs.f_bsize;
totalFreeBytes = fs.f_bfree * fs.f_bsize;
retVal = true;
}
return retVal;
}
int main()
{
ulonglong diskSize, totalFreeBytes;
CheckDiskSpace( "/dev/sda5", diskSize, totalFreeBytes );
printf( "Disk size: %llu Byte
", diskSize );
printf( "Free size: %llu Byte
", totalFreeBytes );
}
我得到:
Disk size: 1798447104 Byte
Free size: 1798443008 Byte
我确实不理解这一结果,因为“df”指挥我得到:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 111148848 47454952 58047832 45% /
udev 1756296 4 1756292 1% /dev
tmpfs 705324 912 704412 1% /run
none 5120 0 5120 0% /run/lock
none 1763300 1460 1761840 1% /run/shm
Any help is very appeciated !
PS:我有120英镑,我的分治在外。
EDIT: ulonglong is a predifined type:
typedef unsigned long long ulonglong;