summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstas <stas@FreeBSD.org>2009-08-15 14:39:33 +0000
committerstas <stas@FreeBSD.org>2009-08-15 14:39:33 +0000
commite69f9c07d3e5812c91bab7ade24283b199e40acd (patch)
treef7ce5b6f33918da49c9b99299898471db75e3f83
parentcea5ba6716a1bfe7964659c07bb5745bdaa178c1 (diff)
downloadFreeBSD-src-e69f9c07d3e5812c91bab7ade24283b199e40acd.zip
FreeBSD-src-e69f9c07d3e5812c91bab7ade24283b199e40acd.tar.gz
- Avoid overflowing the swap size counters in human-readable mode
by introducing the new CONVERT_BLOCKS macro which operates on sizes already converted to number of blocks. With this macro it is not longer needed to perform needless multiplication by blocksize just to divide on it later in CONVERT macro. Approved by: re (kib) MFC after: 1 week
-rw-r--r--usr.sbin/pstat/pstat.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c
index bf297f5..5435166 100644
--- a/usr.sbin/pstat/pstat.c
+++ b/usr.sbin/pstat/pstat.c
@@ -460,6 +460,7 @@ getfiles(struct xfile **abuf, size_t *alen)
*/
#define CONVERT(v) ((int64_t)(v) * pagesize / blocksize)
+#define CONVERT_BLOCKS(v) ((int64_t)(v) * pagesize)
static struct kvm_swap swtot;
static int nswdev;
@@ -492,10 +493,10 @@ print_swap_line(const char *swdevname, intmax_t nblks, intmax_t bused,
printf("%-15s %*jd ", swdevname, hlen, CONVERT(nblks));
if (humanflag) {
humanize_number(usedbuf, sizeof(usedbuf),
- CONVERT(blocksize * bused), "",
+ CONVERT_BLOCKS(bused), "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
humanize_number(availbuf, sizeof(availbuf),
- CONVERT(blocksize * bavail), "",
+ CONVERT_BLOCKS(bavail), "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent);
} else {
OpenPOWER on IntegriCloud