From: Jeff Layton Date: Mon, 23 Jun 2008 11:21:52 +0000 (-0400) Subject: The nfsstat program reads /proc/net/rpc/* files to gets info about X-Git-Tag: nfs-utils-1-1-3~36 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=commitdiff_plain;h=5be04020788598cb811e51c4b1342cf0796cbb65;hp=c6acce67dce1cf89742a6bc4635c1eeda82e9591 The nfsstat program reads /proc/net/rpc/* files to gets info about calls. This info is output as unsigned numbers (at least on any relatively recent kernel). When nfsstat prints these numbers, they are printed as signed integers. When the call counters reach 2^31, things start being printed as negative numbers. This patch changes nfsstat to read and print all counters as unsigned integers. Tested by hacking up a kernel to initialize call counters to 2^31+1. Thanks to Takafumi Miki for the initial version of this patch. Signed-off-by: Jeff Layton Signed-off-by: Steve Dickson --- diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c index d2cca8d..1517414 100644 --- a/utils/nfsstat/nfsstat.c +++ b/utils/nfsstat/nfsstat.c @@ -539,7 +539,7 @@ print_numbers(const char *hdr, unsigned int *info, unsigned int nr) fputs(hdr, stdout); for (i = 0; i < nr; i++) - printf("%s%-8d", i? " " : "", info[i]); + printf("%s%-8u", i? " " : "", info[i]); printf("\n"); } @@ -562,7 +562,7 @@ print_callstats(const char *hdr, const char **names, printf("\n"); for (j = 0; j < 6 && i + j < nr; j++) { pct = ((unsigned long long) info[i+j]*100)/total; - printf("%-8d%3llu%% ", info[i+j], pct); + printf("%-8u%3llu%% ", info[i+j], pct); } printf("\n"); } @@ -604,7 +604,7 @@ parse_raw_statfile(const char *name, struct statinfo *statp) for (i = 0; i < cnt; i++) { if (!(sp = strtok(NULL, " \t"))) break; - ip->valptr[i] = atoi(sp); + ip->valptr[i] = (unsigned int) strtoul(sp, NULL, 0); total += ip->valptr[i]; } ip->valptr[cnt - 1] = total; @@ -618,7 +618,8 @@ parse_raw_statfile(const char *name, struct statinfo *statp) static int parse_pretty_statfile(const char *filename, struct statinfo *info) { - int numvals, curindex, numconsumed, n, sum, err = 1; + int numvals, curindex, numconsumed, n, err = 1; + unsigned int sum; char buf[4096], *bufp, *fmt, is_proc; FILE *fp = NULL; struct statinfo *ip;