signedness fun
Par Benoît Dejean le lundi, 12 février 2007, 11:22 - GNOME - Lien permanent
3 years ago, i deleted code that i didn't understand in libgtop. It was a mess about bitwise shift and xor.
Then came these bugs about system-monitor displaying 17179869184.0 GiB. This is about available disk space (you know, the 10% reservation for root, etc). On *BSD, available disk space can be negative... so you can get df to reports negative capacity :
$ df -h / Filesystem Size Used Avail Capacity Mounted on /dev/ad10s1a 496M 457M -514K 100% /
(This reminds me of mfs fun with OpenBSD 
libgtop uses statvfs/statfs functions to get disk space usage : struct statvfs members' type is fsblkcnt_t which is an unsigned integer. This means that some kernels store signed values as unsigned integers. Hence the old fun code i deleted. glibtop_fsusage members are guint64 so there is not signedness mismatch between libgtop and the system.
As I was unable to get negative values with linux 2.6.20 and ext3, I dig into GNU df code and found the very same code that was in libgtop, i guess someone copy&pasted it into libgtop a long time ago. This code does funny things to handle integers with the top bit set as negative integers.
I ended to this madness by ensuring available disk space is <= to free disk space.