From 4a93c6295ede957930be19d780d8d9f5c66a85b2 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 31 Jan 2003 15:16:52 +0000 Subject: - Modernize the format of the open file showing mode output: . Print the column headers centered (except for the left-aligned TYPE header) using a different header for architectures where sizeof(uintptr_t) is not four. . Consistently do not print a '0x' prefix for hexadecimal values. . Separate columns by a single space character. . Pad the columns presenting an address or offset enough to hold their respective largest value. . Do not restrict the output to unknown file types, inodes and sockets; allow displaying of pipes, fifos, kqueues and crypto file descriptors too. - Shorten an overly long line by removing a cast of printf's return value to void. PR: alpha/45240 Tested on: i386, sparc64, alpha --- usr.sbin/pstat/pstat.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'usr.sbin/pstat/pstat.c') diff --git a/usr.sbin/pstat/pstat.c b/usr.sbin/pstat/pstat.c index e6a3f2b..a147aae 100644 --- a/usr.sbin/pstat/pstat.c +++ b/usr.sbin/pstat/pstat.c @@ -199,6 +199,14 @@ usage(void) exit (1); } +static const char fhdr32[] = + " LOC TYPE FLG CNT MSG DATA OFFSET\n"; +/* c0000000 ------ RWAI 123 123 c0000000 1000000000000000 */ + +static const char fhdr64[] = + " LOC TYPE FLG CNT MSG DATA OFFSET\n"; +/* c000000000000000 ------ RWAI 123 123 c000000000000000 1000000000000000 */ + static const char hdr[] = " LINE RAW CAN OUT IHIWT ILOWT OHWT LWT COL STATE SESS PGID DISC\n"; @@ -334,7 +342,7 @@ ttyprt(struct xtty *xt) errx(1, "struct xtty size mismatch"); if (usenumflag || xt->xt_dev == 0 || (name = devname(xt->xt_dev, S_IFCHR)) == NULL) - (void)printf(" %2d,%-2d", major(xt->xt_dev), minor(xt->xt_dev)); + printf(" %2d,%-2d", major(xt->xt_dev), minor(xt->xt_dev)); else (void)printf("%7s ", name); (void)printf("%2ld %3ld ", xt->xt_rawcc, xt->xt_cancc); @@ -376,8 +384,10 @@ filemode(void) char *buf, flagbuf[16], *fbp; int maxf, openf; size_t len; - static char *dtypes[] = { "???", "inode", "socket" }; + static char *dtypes[] = { "???", "inode", "socket", "pipe", + "fifo", "kqueue", "crypto" }; int i; + int wid; if (kd != NULL) { if (kvm_read(kd, nl[NL_MAXFILES].n_value, @@ -399,13 +409,15 @@ filemode(void) if (getfiles(&buf, &len) == -1) return; openf = len / sizeof *fp; + (void)printf("%d/%d open files\n", openf, maxf); - (void)printf(" LOC TYPE FLG CNT MSG DATA OFFSET\n"); + printf(sizeof(uintptr_t) == 4 ? fhdr32 : fhdr64); + wid = (int)sizeof(uintptr_t) * 2; for (fp = (struct xfile *)buf, i = 0; i < openf; ++fp, ++i) { - if ((unsigned)fp->xf_type > DTYPE_SOCKET) + if ((size_t)fp->xf_type >= sizeof(dtypes) / sizeof(dtypes[0])) continue; - (void)printf("%8jx ", (uintmax_t)(uintptr_t)fp->xf_file); - (void)printf("%-8.8s", dtypes[fp->xf_type]); + (void)printf("%*jx", wid, (uintmax_t)(uintptr_t)fp->xf_file); + (void)printf(" %-6.6s", dtypes[fp->xf_type]); fbp = flagbuf; if (fp->xf_flag & FREAD) *fbp++ = 'R'; @@ -416,10 +428,11 @@ filemode(void) if (fp->xf_flag & FASYNC) *fbp++ = 'I'; *fbp = '\0'; - (void)printf("%6s %3d", flagbuf, fp->xf_count); - (void)printf(" %3d", fp->xf_msgcount); - (void)printf(" %p", fp->xf_data); - (void)printf(" %jx\n", (uintmax_t)fp->xf_offset); + (void)printf(" %4s %3d", flagbuf, fp->xf_count); + (void)printf(" %3d", fp->xf_msgcount); + (void)printf(" %*jx", wid, (uintmax_t)(uintptr_t)fp->xf_data); + (void)printf(" %*jx\n", (int)sizeof(fp->xf_offset) * 2, + (uintmax_t)fp->xf_offset); } free(buf); } -- cgit v1.1