I used Python's shutil.disk_usage function using "/" as the parameter to determine my computer's total, used, and free space (I have a Mac using macOS Catalina). The results I got did not match up with the actual results.
Results from shutil.disk_usage("/"):
total = 121.12 GB
used = 11.3 GB
free = 19.79 GB
Actual results by inspecting my computer's storage:
total = 121.12 GB
used = 97.78 GB {Docs (35.34GB) + Apps (20.19GB) + System (11.3GB) + Other (30.95GB)}
free = 22.64 GB
The total value is correct for both, but the used and free space values are off.
The system is using 11.3 GB, which is the exact amount that shutil.disk_usage("/") calculated, but when I look at the code for calculating this amount it is reported as:
used = (f_blocks - f_bfree) * f_frsize
Which I read as "total blocks minus free blocks (used blocks) times block size is equal to the amount of used space". I do not understand why this value is reported as 11.3 GB, and not the total amount of used space.
Similarly I do not understand why the value for free space:
free = f_bavail * f_frsize
Which I read as "number of blocks available to non-super user (I think this means free blocks available to anyone who does not have sudo access, so free blocks available to the guest account) times block size is equal to the amount of free space". I do not understand why this value is reported as 19.79 GB when I have 22.64 GB of free space.
I expected that total = used + free but this is clearly not the case.
How come the calculated values for used and free space using shutil.disk_usage("/") are different from the actual values.