Bug 789441 - net-snmp reports incorrect used disk space for large filesystems From upstream git: commit 76ff25d9bf97579e7213102065fd5096f049a4c5 Author: Bart Van Assche Date: Fri Oct 7 14:13:18 2011 +0200 CHANGES: snmpd: HOST-RESOURCES-MIB::hrStorageTable: fix bug in handling large filesystems, where large means above 8 TB (= 2**31 * 4096 bytes). This patch fixes a bug introduced in commit 71d8293f387a6cd66bb0dbb13c0f50174d2e678b. For the original bug report, see also https://sourceforge.net/tracker/?func=detail&atid=112694&aid=3419825&group_id=12694. diff --git a/agent/mibgroup/hardware/fsys/hw_fsys.c b/agent/mibgroup/hardware/fsys/hw_fsys.c index c96284e..be698b2 100644 --- a/agent/mibgroup/hardware/fsys/hw_fsys.c +++ b/agent/mibgroup/hardware/fsys/hw_fsys.c @@ -321,19 +321,23 @@ netsnmp_fsys_avail( netsnmp_fsys_info *f) { /* recalculate f->size_32, used_32, avail_32 and units_32 from f->size & comp.*/ void -netsnmp_fsys_calculate32( netsnmp_fsys_info *f) +netsnmp_fsys_calculate32(netsnmp_fsys_info *f) { unsigned long long s = f->size; - unsigned long long u = f->units; - int factor = 0; + unsigned shift = 0; + while (s > INT32_MAX) { s = s >> 1; - u = u << 1; - factor++; + shift++; } f->size_32 = s; - f->units_32 = u; - f->avail_32 = f->avail << factor; - f->used_32 = f->used << factor; + f->units_32 = f->units << shift; + f->avail_32 = f->avail >> shift; + f->used_32 = f->used >> shift; + + DEBUGMSGTL(("fsys", "Results of 32-bit conversion: size %llu -> %lu;" + " units %llu -> %lu; avail %llu -> %lu; used %llu -> %lu\n", + f->size, f->size_32, f->units, f->units_32, + f->avail, f->avail_32, f->used, f->used_32)); }