I spoke too soon that it was working on linux as well I guess ... I just compared the output (with the same filesystem) on linux and on macos ...
Code: Select all
#!/usr/bin/env python3
from ctypes import CDLL, Structure, c_uint32, c_int64, c_uint64, c_char, create_string_buffer, byref, c_ubyte, c_int16, c_int64, c_int32, util
import sys
# when _DARWIN_FEATURE_64_BIT_INODE is not defined
class statfs32(Structure):
_fields_ = [
("f_otype", c_int16),
("f_oflags", c_int16),
("f_bsize", c_int64),
("f_iosize", c_int64),
("f_blocks", c_int64),
("f_bfree", c_int64),
("f_bavail", c_int64),
("f_files", c_int64),
("f_ffree", c_int64),
("f_fsid", c_uint64),
("f_owner", c_uint32),
("f_reserved1", c_int16),
("f_type", c_int16),
("f_flags", c_int64),
("f_reserved2", c_int64*2),
("f_fstypename", c_char*15),
("f_mntonname", c_char*90),
("f_mntfromname", c_char*90),
("f_reserved3", c_char),
("f_reserved4", c_int64*4),
]
# when _DARWIN_FEATURE_64_BIT_INODE is defined
class statfs64(Structure):
_fields_ = [
("f_bsize", c_uint32),
("f_iosize", c_int32),
("f_blocks", c_uint64),
("f_bfree", c_uint64),
("f_bavail", c_uint64),
("f_files", c_uint64),
("f_ffree", c_uint64),
("f_fsid", c_uint64),
("f_owner", c_uint32),
("f_type", c_uint32),
("f_flags", c_uint32),
("f_fssubtype", c_uint32),
("f_fstypename", c_char*16),
("f_mntonname", c_char*1024),
("f_mntfromname", c_char*1024),
("f_reserved", c_uint32*8),
]
print("args", str(sys.argv))
if (len(sys.argv) < 2):
print("pass path")
exit()
kern = CDLL(util.find_library('c'), use_errno=True)
fs_info = statfs32()
fs_info64 = statfs64()
# put the path to any file on the mounted file system here
root_volume = create_string_buffer(str.encode(sys.argv[1]))
result = kern.statfs(root_volume, byref(fs_info))
print('statfs result', result)
print("f_blocks", fs_info.f_blocks)
print("f_bsize", fs_info.f_bsize)
print("f_bavail", fs_info.f_bavail)
print("Total Space KB", fs_info.f_blocks * fs_info.f_bsize / 1024)
print("Total Free Space KB", fs_info.f_bfree * fs_info.f_bsize / 1024)
result64 = kern.statfs64(root_volume, byref(fs_info64))
print('statfs64 result', result64)
print("f_blocks", fs_info64.f_blocks)
print("f_bsize", fs_info64.f_bsize)
print("f_bavail", fs_info64.f_bavail)
print("Total Space KB", fs_info64.f_blocks * fs_info64.f_bsize / 1024)
print("Total Free Space KB", fs_info64.f_bfree * fs_info64.f_bsize / 1024)
so, maybe we should just use stat64 and only on macos ... leave the statvfs alone for linux ... it has something to do with the ctypes being used for the class's in python ... if i change the f_blocks to a c_long it actually reports the correct size in linux, but incorrect on macos ...