linux获取块设备容量信息 statfs
/*获取挂载点磁盘的容量相关新*/
int get_disk_size(char *mountpoint, unsigned long long *total_size, unsigned long long *free_size)
{
struct statfs stfs;
int rc;
if(total_size == NULL || free_size == NULL)
{
return -1;
}
*total_size = 0;
*free_size = 0;
rc = statfs(mountpoint, &stfs);
if ( rc >= 0 )
{
*total_size = (unsigned long long)stfs.f_blocks * stfs.f_bsize;
*free_size = (unsigned long long)stfs.f_bavail * stfs.f_bsize;
}
return rc;
}