Hypothesis:
The multiplication overflowed, so fsStat.f_bsize * fsStat.f_blocks
produced an overflow result of -2147483648. When this was converted to unsigned long long
, it produced 18446744071562067968, which is 0xffffffff80000000, the result of wrapping -2147483648 in a 64-bit unsigned format. GDB uses different arithmetic than C, so it displayed the mathematically correct result.
To fix this, change (unsigned long long) (fsStat.f_bsize * fsStat.f_blocks)
to (unsigned long long) fsStat.f_bsize * fsStat.f_blocks
, to convert to the wider integer format before multiplication.
Better than unsigned long long
would be to use either uint64_t
(from <stdint.h>
) or a type supplied by the platform (some Linux header) for working with disk sizes.