yes, I didn't define the entire struct ... but this works for linux:
Code: Select all
def linux_disk_free_clib_statfs(directory):
class statfs(Structure):
_fields_ = [
("f_type", c_int64),
("f_bsize", c_int64),
("f_blocks", c_ulong),
("f_bfree", c_ulong),
("f_bavail", c_ulong),
("f_files", c_ulonglong),
("f_ffree", c_ulonglong),
("f_frsize", c_ulong),
]
kern = CDLL(util.find_library('c'), use_errno=True)
root_volume = create_string_buffer(str.encode(directory))
fs_info = statfs()
result = kern.statfs(root_volume, byref(fs_info)) # you have to call this to get fs_info filled out
disk_size_MB = fs_info.f_blocks * fs_info.f_bsize / 1024**2
free_size_MB = fs_info.f_bavail * fs_info.f_bsize / 1024**2
return disk_size_MB, free_size_MB
Code: Select all
dir is /media/psf/Big_One/
df is always right, so: Disk size, and free (in MB): (38149816, 35697196)
python's os.statvfs() says (38149816, 35697195)
clib statfs32 says (8158310.44921875, 18201800055525.207)
clib linux statfs says (38149815.9609375, 35697195.234375)