4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / usr.sbin / pstat / pstat.c
index 82e4263..4b1d78f 100644 (file)
 /*-
 /*-
- * Copyright (c) 1980, 1991 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.proprietary.c%
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980, 1991 The Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1991, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)pstat.c    5.38 (Berkeley) %G%";
+static char sccsid[] = "@(#)pstat.c    8.1 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
-#include <sys/user.h>
-#include <sys/proc.h>
 #include <sys/time.h>
 #include <sys/vnode.h>
 #include <sys/map.h>
 #define KERNEL
 #include <sys/time.h>
 #include <sys/vnode.h>
 #include <sys/map.h>
 #define KERNEL
-#define NFS
 #include <sys/file.h>
 #include <sys/file.h>
-#include <sys/mount.h>
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
+#undef KERNEL
+#define NFS
+#include <sys/mount.h>
+#undef NFS
 #include <sys/stat.h>
 #include <sys/stat.h>
-#include <nfs/nfsv2.h>
-#include <nfs/nfs.h>
 #include <nfs/nfsnode.h>
 #include <sys/ioctl.h>
 #include <sys/tty.h>
 #include <nfs/nfsnode.h>
 #include <sys/ioctl.h>
 #include <sys/tty.h>
-#undef KERNEL
 #include <sys/conf.h>
 
 #include <sys/conf.h>
 
-#ifdef SPPWAIT
-#define NEWVM
-#endif
+#include <sys/sysctl.h>
 
 
-#ifndef NEWVM
-#include <sys/vm.h>
-#include <machine/pte.h>
-#include <sys/text.h>
-#endif
-#include <sys/kinfo.h>
-
-#include <nlist.h>
+#include <err.h>
 #include <kvm.h>
 #include <kvm.h>
+#include <limits.h>
+#include <nlist.h>
 #include <stdio.h>
 #include <stdio.h>
-#include "pathnames.h"
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 
-#define mask(x)                (x&0377)
-#define        clear(x)        ((int)x &~ KERNBASE)
-
-char   *nlistf = NULL;
-char   *memf   = NULL;
+#include "pathnames.h"
 
 struct nlist nl[] = {
 
 struct nlist nl[] = {
-#define        SWAPMAP 0
-       { "_swapmap" },
-#define        SNSWAPMAP 1
-       { "_nswapmap" },
-#define        SDMMIN  2
-       { "_dmmin" },
-#define        SDMMAX  3
-       { "_dmmax" },
-#define        SNSWDEV 4
-       { "_nswdev" },
-#define        SSWDEVT 5
-       { "_swdevt" },
-#define NLMANDATORY SSWDEVT    /* names up to here are mandatory */
+#define VM_SWAPMAP     0
+       { "_swapmap" }, /* list of free swap areas */
+#define VM_NSWAPMAP    1
+       { "_nswapmap" },/* size of the swap map */
+#define VM_SWDEVT      2
+       { "_swdevt" },  /* list of swap devices and sizes */
+#define VM_NSWAP       3
+       { "_nswap" },   /* size of largest swap device */
+#define VM_NSWDEV      4
+       { "_nswdev" },  /* number of swap devices */
+#define VM_DMMAX       5
+       { "_dmmax" },   /* maximum size of a swap block */
+#define V_NUMV         6
+       { "_numvnodes" },
+#define V_ROOTFS       7
+       { "_rootfs" },
+#define        FNL_NFILE       8
+       {"_nfiles"},
+#define FNL_MAXFILE    9
+       {"_maxfiles"},
+#define NLMANDATORY FNL_MAXFILE        /* names up to here are mandatory */
 #define        SCONS   NLMANDATORY + 1
        { "_cons" },
 #define        SPTY    NLMANDATORY + 2
        { "_pt_tty" },
 #define        SNPTY   NLMANDATORY + 3
        { "_npty" },
 #define        SCONS   NLMANDATORY + 1
        { "_cons" },
 #define        SPTY    NLMANDATORY + 2
        { "_pt_tty" },
 #define        SNPTY   NLMANDATORY + 3
        { "_npty" },
-#ifdef vax
-#define        SDZ     (SNPTY+1)
-       { "_dz_tty" },
-#define        SNDZ    (SNPTY+2)
-       { "_dz_cnt" },
-#define        SDMF    (SNPTY+3)
-       { "_dmf_tty" },
-#define        SNDMF   (SNPTY+4)
-       { "_ndmf" },
-#define        SDH     (SNPTY+5)
-       { "_dh11" },
-#define        SNDH    (SNPTY+6)
-       { "_ndh11" },
-#define        SDHU    (SNPTY+7)
-       { "_dhu_tty" },
-#define        SNDHU   (SNPTY+8)
-       { "_ndhu" },
-#define        SDMZ    (SNPTY+9)
-       { "_dmz_tty" },
-#define        SNDMZ   (SNPTY+10)
-       { "_ndmz" },
-#define        SQD     (SNPTY+11)
-       { "_qd_tty" },
-#define        SNQD    (SNPTY+12)
-       { "_nNQD" },
-#endif
-
-#ifdef tahoe
-#define        SVX     (SNPTY+1)
-       { "_vx_tty" },
-#define        SNVX    (SNPTY+2)
-       { "_nvx" },
-#define SMP    (SNPTY+3)
-       { "_mp_tty" },
-#define SNMP   (SNPTY+4)
-       { "_nmp" },
-#endif
 
 #ifdef hp300
 #define        SDCA    (SNPTY+1)
 
 #ifdef hp300
 #define        SDCA    (SNPTY+1)
@@ -134,132 +93,135 @@ struct nlist nl[] = {
 #define        SNITE   (SNPTY+8)
        { "_nite" },
 #endif
 #define        SNITE   (SNPTY+8)
        { "_nite" },
 #endif
+
+#ifdef mips
+#define SDC    (SNPTY+1)
+       { "_dc_tty" },
+#define SNDC   (SNPTY+2)
+       { "_dc_cnt" },
+#endif
+
        { "" }
 };
 
        { "" }
 };
 
-int    vnof;
-int    txtf;
-int    prcf;
-int    ttyf;
-int    usrf;
-int    upid;
-int    filf;
-int    swpf;
-int    totflg;
-char   partab[1];
-struct cdevsw  cdevsw[1];
-struct bdevsw  bdevsw[1];
-int    allflg;
-int    nflg;
-u_long getword();
-off_t  mkphys();
-
-#define V(x)   (void *)(x)
+int    usenumflag;
+int    totalflag;
+char   *nlistf = NULL;
+char   *memf   = NULL;
+kvm_t  *kd;
+
+#define        SVAR(var) __STRING(var) /* to force expansion */
+#define        KGET(idx, var)                                                  \
+       KGET1(idx, &var, sizeof(var), SVAR(var))
+#define        KGET1(idx, p, s, msg)                                           \
+       KGET2(nl[idx].n_value, p, s, msg)
+#define        KGET2(addr, p, s, msg)                                          \
+       if (kvm_read(kd, (u_long)(addr), p, s) != s)                    \
+               warnx("cannot read %s: %s", msg, kvm_geterr(kd))
+#define        KGETRET(addr, p, s, msg)                                        \
+       if (kvm_read(kd, (u_long)(addr), p, s) != s) {                  \
+               warnx("cannot read %s: %s", msg, kvm_geterr(kd));       \
+               return (0);                                             \
+       }
 
 
+void   filemode __P((void));
+int    getfiles __P((char **, int *));
+struct mount *
+       getmnt __P((struct mount *));
+struct e_vnode *
+       kinfo_vnodes __P((int *));
+struct e_vnode *
+       loadvnodes __P((int *));
+void   mount_print __P((struct mount *));
+void   nfs_header __P((void));
+int    nfs_print __P((struct vnode *));
+void   swapmode __P((void));
+void   ttymode __P((void));
+void   ttyprt __P((struct tty *, int));
+void   ttytype __P((struct tty *, char *, int, int));
+void   ufs_header __P((void));
+int    ufs_print __P((struct vnode *));
+void   usage __P((void));
+void   vnode_header __P((void));
+void   vnode_print __P((struct vnode *, struct vnode *));
+void   vnodemode __P((void));
+
+int
 main(argc, argv)
        int argc;
        char *argv[];
 {
        extern char *optarg;
        extern int optind;
 main(argc, argv)
        int argc;
        char *argv[];
 {
        extern char *optarg;
        extern int optind;
-       int ch, ret;
+       int ch, i, quit, ret;
+       int fileflag, swapflag, ttyflag, vnodeflag;
+       char buf[_POSIX2_LINE_MAX];
 
 
-       while ((ch = getopt(argc, argv, "TafvikptU:sxnu")) != EOF)
+       fileflag = swapflag = ttyflag = vnodeflag = 0;
+       while ((ch = getopt(argc, argv, "TM:N:finstv")) != EOF)
                switch (ch) {
                switch (ch) {
-               case 'T':
-                       totflg++;
-                       break;
-               case 'a':
-                       allflg++;
-                       /*FALLTHROUGH*/
-               case 'p':
-                       prcf++;
-                       break;
                case 'f':
                case 'f':
-                       filf++;
+                       fileflag = 1;
                        break;
                        break;
-               case 'v':
-               case 'i':
-                       vnof++;
+               case 'M':
+                       memf = optarg;
                        break;
                        break;
-               case 't':
-                       ttyf++;
+               case 'N':
+                       nlistf = optarg;
                        break;
                        break;
-               case 'U':
-                       usrf++;
-                       sscanf(optarg, "%d", &upid);
+               case 'n':
+                       usenumflag = 1;
                        break;
                case 's':
                        break;
                case 's':
-                       swpf++;
+                       swapflag = 1;
                        break;
                        break;
-               case 'x':
-                       txtf++;
+               case 'T':
+                       totalflag = 1;
                        break;
                        break;
-               case 'n':
-                       nflg++;
+               case 't':
+                       ttyflag = 1;
+                       break;
+               case 'v':
+               case 'i':               /* Backward compatibility. */
+                       vnodeflag = 1;
                        break;
                        break;
-               case 'u':
-                       fprintf(stderr, "pstat: use [ -U pid ] for -u\n");
-                       exit(1);
-               case '?':
                default:
                default:
-                       fprintf(stderr, "usage: pstat -[Tafiptsx] [-U [pid]] [system] [core]\n");
-                       exit(1);
+                       usage();
                }
        argc -= optind;
        argv += optind;
 
                }
        argc -= optind;
        argv += optind;
 
-       if (argc > 1)
-               memf = argv[1];
-       if (argc > 0)
-               nlistf = argv[0];
-
        /*
         * Discard setgid privileges if not the running kernel so that bad
         * guys can't print interesting stuff from kernel memory.
         */
        if (nlistf != NULL || memf != NULL)
        /*
         * Discard setgid privileges if not the running kernel so that bad
         * guys can't print interesting stuff from kernel memory.
         */
        if (nlistf != NULL || memf != NULL)
-               setgid(getgid());
-
-       if (kvm_openfiles(nlistf, memf, NULL) == -1) {
-               error("kvm_openfiles: %s", kvm_geterr());
-               exit(1);
-       }
-       if ((ret = kvm_nlist(nl)) != 0) {
-               int i, quit = 0;
+               (void)setgid(getgid());
 
 
-               if (ret == -1) {
-                       error("kvm_nlist: %s", kvm_geterr());
-                       exit(1);
-               }
-               for (i = 0; i <= NLMANDATORY; i++) {
+       if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == 0)
+               errx(1, "kvm_openfiles: %s", buf);
+       if ((ret = kvm_nlist(kd, nl)) != 0) {
+               if (ret == -1)
+                       errx(1, "kvm_nlist: %s", kvm_geterr(kd));
+               for (i = quit = 0; i <= NLMANDATORY; i++)
                        if (!nl[i].n_value) {
                                quit = 1;
                        if (!nl[i].n_value) {
                                quit = 1;
-                               error("undefined symbol: %s\n",
-                                       nl[i].n_name);
+                               warnx("undefined symbol: %s\n", nl[i].n_name);
                        }
                        }
-               }
                if (quit)
                        exit(1);
        }
                if (quit)
                        exit(1);
        }
-       if (!(filf | totflg | vnof | prcf | txtf | ttyf | usrf | swpf)) {
-               printf("pstat: one or more of -[aivxptfsU] is required\n");
-               exit(1);
-       }
-       if (filf||totflg)
-               dofile();
-       if (vnof||totflg)
-               dovnode();
-       if (prcf||totflg)
-               doproc();
-       if (txtf||totflg)
-               dotext();
-       if (ttyf)
-               dotty();
-       if (usrf)
-               dousr();
-       if (swpf||totflg)
-               doswap();
+       if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag))
+               usage();
+       if (fileflag || totalflag)
+               filemode();
+       if (vnodeflag || totalflag)
+               vnodemode();
+       if (ttyflag)
+               ttymode();
+       if (swapflag || totalflag)
+               swapmode();
+       exit (0);
 }
 
 struct e_vnode {
 }
 
 struct e_vnode {
@@ -267,25 +229,25 @@ struct e_vnode {
        struct vnode vnode;
 };
 
        struct vnode vnode;
 };
 
-dovnode()
+void
+vnodemode()
 {
        register struct e_vnode *e_vnodebase, *endvnode, *evp;
        register struct vnode *vp;
 {
        register struct e_vnode *e_vnodebase, *endvnode, *evp;
        register struct vnode *vp;
-       register struct mount *maddr = NULL, *mp;
+       register struct mount *maddr, *mp;
        int numvnodes;
        int numvnodes;
-       struct e_vnode *loadvnodes();
-       struct mount *getmnt();
 
        e_vnodebase = loadvnodes(&numvnodes);
 
        e_vnodebase = loadvnodes(&numvnodes);
-       if (totflg) {
-               printf("%7d vnodes\n", numvnodes);
+       if (totalflag) {
+               (void)printf("%7d vnodes\n", numvnodes);
                return;
        }
        endvnode = e_vnodebase + numvnodes;
                return;
        }
        endvnode = e_vnodebase + numvnodes;
-       printf("%d active vnodes\n", numvnodes);
+       (void)printf("%d active vnodes\n", numvnodes);
 
 
 #define ST     mp->mnt_stat
 
 
 #define ST     mp->mnt_stat
+       maddr = NULL;
        for (evp = e_vnodebase; evp < endvnode; evp++) {
                vp = &evp->vnode;
                if (vp->v_mount != maddr) {
        for (evp = e_vnodebase; evp < endvnode; evp++) {
                vp = &evp->vnode;
                if (vp->v_mount != maddr) {
@@ -310,7 +272,7 @@ dovnode()
                        default:
                                break;
                        }
                        default:
                                break;
                        }
-                       printf("\n");
+                       (void)printf("\n");
                }
                vnode_print(evp->avnode, vp);
                switch(ST.f_type) {
                }
                vnode_print(evp->avnode, vp);
                switch(ST.f_type) {
@@ -326,23 +288,25 @@ dovnode()
                default:
                        break;
                }
                default:
                        break;
                }
-               printf("\n");
+               (void)printf("\n");
        }
        free(e_vnodebase);
 }
 
        }
        free(e_vnodebase);
 }
 
+void
 vnode_header()
 {
 vnode_header()
 {
-       printf("ADDR     TYP VFLAG  USE HOLD");
+       (void)printf("ADDR     TYP VFLAG  USE HOLD");
 }
 
 }
 
+void
 vnode_print(avnode, vp)
        struct vnode *avnode;
        struct vnode *vp;
 {
        char *type, flags[16]; 
        char *fp = flags;
 vnode_print(avnode, vp)
        struct vnode *avnode;
        struct vnode *vp;
 {
        char *type, flags[16]; 
        char *fp = flags;
-       register flag;
+       register int flag;
 
        /*
         * set type
 
        /*
         * set type
@@ -390,28 +354,27 @@ vnode_print(avnode, vp)
        if (flag == 0)
                *fp++ = '-';
        *fp = '\0';
        if (flag == 0)
                *fp++ = '-';
        *fp = '\0';
-       /*
-        * print it
-        */
-       printf("%8x %s %5s %4d %4d",
-               avnode, type, flags, vp->v_usecount, vp->v_holdcnt);
+       (void)printf("%8x %s %5s %4d %4d",
+           avnode, type, flags, vp->v_usecount, vp->v_holdcnt);
 }
 
 }
 
+void
 ufs_header() 
 {
 ufs_header() 
 {
-       printf(" FILEID IFLAG RDEV|SZ");
+       (void)printf(" FILEID IFLAG RDEV|SZ");
 }
 
 }
 
+int
 ufs_print(vp) 
        struct vnode *vp;
 {
 ufs_print(vp) 
        struct vnode *vp;
 {
-       struct inode *ip = VTOI(vp);
+       register int flag;
+       struct inode inode, *ip = &inode;
        char flagbuf[16], *flags = flagbuf;
        char flagbuf[16], *flags = flagbuf;
-       register flag;
        char *name;
        mode_t type;
        char *name;
        mode_t type;
-       extern char *devname();
 
 
+       KGETRET(VTOI(vp), &inode, sizeof(struct inode), "vnode's inode");
        flag = ip->i_flag;
        if (flag & ILOCKED)
                *flags++ = 'L';
        flag = ip->i_flag;
        if (flag & ILOCKED)
                *flags++ = 'L';
@@ -437,57 +400,67 @@ ufs_print(vp)
                *flags++ = '-';
        *flags = '\0';
 
                *flags++ = '-';
        *flags = '\0';
 
-       printf(" %6d %5s", ip->i_number, flagbuf);
+       (void)printf(" %6d %5s", ip->i_number, flagbuf);
        type = ip->i_mode & S_IFMT;
        type = ip->i_mode & S_IFMT;
-       if (type == S_IFCHR || type == S_IFBLK)
-               if (nflg || ((name = devname(ip->i_rdev, type)) == NULL))
-                       printf("   %2d,%-2d", 
-                               major(ip->i_rdev), minor(ip->i_rdev));
+       if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
+               if (usenumflag || ((name = devname(ip->i_rdev, type)) == NULL))
+                       (void)printf("   %2d,%-2d", 
+                           major(ip->i_rdev), minor(ip->i_rdev));
                else
                else
-                       printf(" %7s", name);
+                       (void)printf(" %7s", name);
        else
        else
-               printf(" %7d", ip->i_size);
+               (void)printf(" %7qd", ip->i_size);
+       return (0);
 }
 
 }
 
+void
 nfs_header() 
 {
 nfs_header() 
 {
-       printf(" FILEID NFLAG RDEV|SZ");
+       (void)printf(" FILEID NFLAG RDEV|SZ");
 }
 
 }
 
+int
 nfs_print(vp) 
        struct vnode *vp;
 {
 nfs_print(vp) 
        struct vnode *vp;
 {
-       struct nfsnode *np = VTONFS(vp);
+       struct nfsnode nfsnode, *np = &nfsnode;
        char flagbuf[16], *flags = flagbuf;
        char flagbuf[16], *flags = flagbuf;
-       register flag;
+       register int flag;
        char *name;
        mode_t type;
        char *name;
        mode_t type;
-       extern char *devname();
 
 
+       KGETRET(VTONFS(vp), &nfsnode, sizeof(nfsnode), "vnode's nfsnode");
        flag = np->n_flag;
        flag = np->n_flag;
-       if (flag & NLOCKED)
-               *flags++ = 'L';
-       if (flag & NWANT)
+       if (flag & NFLUSHWANT)
                *flags++ = 'W';
                *flags++ = 'W';
+       if (flag & NFLUSHINPROG)
+               *flags++ = 'P';
        if (flag & NMODIFIED)
                *flags++ = 'M';
        if (flag & NWRITEERR)
                *flags++ = 'E';
        if (flag & NMODIFIED)
                *flags++ = 'M';
        if (flag & NWRITEERR)
                *flags++ = 'E';
+       if (flag & NQNFSNONCACHE)
+               *flags++ = 'X';
+       if (flag & NQNFSWRITE)
+               *flags++ = 'O';
+       if (flag & NQNFSEVICTED)
+               *flags++ = 'G';
        if (flag == 0)
                *flags++ = '-';
        *flags = '\0';
 
 #define VT     np->n_vattr
        if (flag == 0)
                *flags++ = '-';
        *flags = '\0';
 
 #define VT     np->n_vattr
-       printf(" %6d %5s", VT.va_fileid, flagbuf);
+       (void)printf(" %6d %5s", VT.va_fileid, flagbuf);
        type = VT.va_mode & S_IFMT;
        type = VT.va_mode & S_IFMT;
-       if (type == S_IFCHR || type == S_IFBLK)
-               if (nflg || ((name = devname(VT.va_rdev, type)) == NULL))
-                       printf("   %2d,%-2d", 
-                               major(VT.va_rdev), minor(VT.va_rdev));
+       if (S_ISCHR(VT.va_mode) || S_ISBLK(VT.va_mode))
+               if (usenumflag || ((name = devname(VT.va_rdev, type)) == NULL))
+                       (void)printf("   %2d,%-2d", 
+                           major(VT.va_rdev), minor(VT.va_rdev));
                else
                else
-                       printf(" %7s", name);
+                       (void)printf(" %7s", name);
        else
        else
-               printf(" %7d", np->n_size);
+               (void)printf(" %7qd", np->n_size);
+       return (0);
 }
        
 /*
 }
        
 /*
@@ -508,29 +481,24 @@ getmnt(maddr)
        for (mt = mhead; mt != NULL; mt = mt->next)
                if (maddr == mt->maddr)
                        return (&mt->mount);
        for (mt = mhead; mt != NULL; mt = mt->next)
                if (maddr == mt->maddr)
                        return (&mt->mount);
-       if ((mt = (struct mtab *)malloc(sizeof (struct mtab))) == NULL) {
-               error("out of memory");
-               exit(1);
-       }
-       if (kvm_read(V(maddr), &mt->mount, sizeof(struct mount)) != 
-           sizeof(struct mount)) {
-               error("can't read mount table at %x", maddr);
-               return (NULL);
-       }
+       if ((mt = malloc(sizeof(struct mtab))) == NULL)
+               err(1, NULL);
+       KGETRET(maddr, &mt->mount, sizeof(struct mount), "mount table");
        mt->maddr = maddr;
        mt->next = mhead;
        mhead = mt;
        return (&mt->mount);
 }
 
        mt->maddr = maddr;
        mt->next = mhead;
        mhead = mt;
        return (&mt->mount);
 }
 
+void
 mount_print(mp)
        struct mount *mp;
 {
 mount_print(mp)
        struct mount *mp;
 {
-       char *type = "unknown";
-       register flags;
+       register int flags;
+       char *type;
 
 #define ST     mp->mnt_stat
 
 #define ST     mp->mnt_stat
-       printf("*** MOUNT ");
+       (void)printf("*** MOUNT ");
        switch (ST.f_type) {
        case MOUNT_NONE:
                type = "none";
        switch (ST.f_type) {
        case MOUNT_NONE:
                type = "none";
@@ -547,94 +515,97 @@ mount_print(mp)
        case MOUNT_PC:
                type = "pc";
                break;
        case MOUNT_PC:
                type = "pc";
                break;
+       default:
+               type = "unknown";
+               break;
        }
        }
-       printf("%s %s on %s", type, ST.f_mntfromname, ST.f_mntonname);
+       (void)printf("%s %s on %s", type, ST.f_mntfromname, ST.f_mntonname);
        if (flags = mp->mnt_flag) {
                char *comma = "(";
 
                putchar(' ');
                /* user visable flags */
                if (flags & MNT_RDONLY) {
        if (flags = mp->mnt_flag) {
                char *comma = "(";
 
                putchar(' ');
                /* user visable flags */
                if (flags & MNT_RDONLY) {
-                       printf("%srdonly", comma);
+                       (void)printf("%srdonly", comma);
                        flags &= ~MNT_RDONLY;
                        comma = ",";
                }
                if (flags & MNT_SYNCHRONOUS) {
                        flags &= ~MNT_RDONLY;
                        comma = ",";
                }
                if (flags & MNT_SYNCHRONOUS) {
-                       printf("%ssynchronous", comma);
+                       (void)printf("%ssynchronous", comma);
                        flags &= ~MNT_SYNCHRONOUS;
                        comma = ",";
                }
                if (flags & MNT_NOEXEC) {
                        flags &= ~MNT_SYNCHRONOUS;
                        comma = ",";
                }
                if (flags & MNT_NOEXEC) {
-                       printf("%snoexec", comma);
+                       (void)printf("%snoexec", comma);
                        flags &= ~MNT_NOEXEC;
                        comma = ",";
                }
                if (flags & MNT_NOSUID) {
                        flags &= ~MNT_NOEXEC;
                        comma = ",";
                }
                if (flags & MNT_NOSUID) {
-                       printf("%snosuid", comma);
+                       (void)printf("%snosuid", comma);
                        flags &= ~MNT_NOSUID;
                        comma = ",";
                }
                if (flags & MNT_NODEV) {
                        flags &= ~MNT_NOSUID;
                        comma = ",";
                }
                if (flags & MNT_NODEV) {
-                       printf("%snodev", comma);
+                       (void)printf("%snodev", comma);
                        flags &= ~MNT_NODEV;
                        comma = ",";
                }
                if (flags & MNT_EXPORTED) {
                        flags &= ~MNT_NODEV;
                        comma = ",";
                }
                if (flags & MNT_EXPORTED) {
-                       printf("%sexport", comma);
+                       (void)printf("%sexport", comma);
                        flags &= ~MNT_EXPORTED;
                        comma = ",";
                }
                if (flags & MNT_EXRDONLY) {
                        flags &= ~MNT_EXPORTED;
                        comma = ",";
                }
                if (flags & MNT_EXRDONLY) {
-                       printf("%sexrdonly", comma);
+                       (void)printf("%sexrdonly", comma);
                        flags &= ~MNT_EXRDONLY;
                        comma = ",";
                }
                if (flags & MNT_LOCAL) {
                        flags &= ~MNT_EXRDONLY;
                        comma = ",";
                }
                if (flags & MNT_LOCAL) {
-                       printf("%slocal", comma);
+                       (void)printf("%slocal", comma);
                        flags &= ~MNT_LOCAL;
                        comma = ",";
                }
                if (flags & MNT_QUOTA) {
                        flags &= ~MNT_LOCAL;
                        comma = ",";
                }
                if (flags & MNT_QUOTA) {
-                       printf("%squota", comma);
+                       (void)printf("%squota", comma);
                        flags &= ~MNT_QUOTA;
                        comma = ",";
                }
                /* filesystem control flags */
                if (flags & MNT_UPDATE) {
                        flags &= ~MNT_QUOTA;
                        comma = ",";
                }
                /* filesystem control flags */
                if (flags & MNT_UPDATE) {
-                       printf("%supdate", comma);
+                       (void)printf("%supdate", comma);
                        flags &= ~MNT_UPDATE;
                        comma = ",";
                }
                if (flags & MNT_MLOCK) {
                        flags &= ~MNT_UPDATE;
                        comma = ",";
                }
                if (flags & MNT_MLOCK) {
-                       printf("%slock", comma);
+                       (void)printf("%slock", comma);
                        flags &= ~MNT_MLOCK;
                        comma = ",";
                }
                if (flags & MNT_MWAIT) {
                        flags &= ~MNT_MLOCK;
                        comma = ",";
                }
                if (flags & MNT_MWAIT) {
-                       printf("%swait", comma);
+                       (void)printf("%swait", comma);
                        flags &= ~MNT_MWAIT;
                        comma = ",";
                }
                if (flags & MNT_MPBUSY) {
                        flags &= ~MNT_MWAIT;
                        comma = ",";
                }
                if (flags & MNT_MPBUSY) {
-                       printf("%sbusy", comma);
+                       (void)printf("%sbusy", comma);
                        flags &= ~MNT_MPBUSY;
                        comma = ",";
                }
                if (flags & MNT_MPWANT) {
                        flags &= ~MNT_MPBUSY;
                        comma = ",";
                }
                if (flags & MNT_MPWANT) {
-                       printf("%swant", comma);
+                       (void)printf("%swant", comma);
                        flags &= ~MNT_MPWANT;
                        comma = ",";
                }
                if (flags & MNT_UNMOUNT) {
                        flags &= ~MNT_MPWANT;
                        comma = ",";
                }
                if (flags & MNT_UNMOUNT) {
-                       printf("%sunmount", comma);
+                       (void)printf("%sunmount", comma);
                        flags &= ~MNT_UNMOUNT;
                        comma = ",";
                }
                if (flags)
                        flags &= ~MNT_UNMOUNT;
                        comma = ",";
                }
                if (flags)
-                       printf("%sunknown_flags:%x", flags);
-               printf(")");
+                       (void)printf("%sunknown_flags:%x", comma, flags);
+               (void)printf(")");
        }
        }
-       printf("\n");
+       (void)printf("\n");
 #undef ST
 }
 
 #undef ST
 }
 
@@ -642,9 +613,9 @@ struct e_vnode *
 loadvnodes(avnodes)
        int *avnodes;
 {
 loadvnodes(avnodes)
        int *avnodes;
 {
-       int ret, copysize;
+       int mib[2];
+       size_t copysize;
        struct e_vnode *vnodebase;
        struct e_vnode *vnodebase;
-       struct e_vnode *kinfo_vnodes();
 
        if (memf != NULL) {
                /*
 
        if (memf != NULL) {
                /*
@@ -652,26 +623,17 @@ loadvnodes(avnodes)
                 */
                return (kinfo_vnodes(avnodes));
        }
                 */
                return (kinfo_vnodes(avnodes));
        }
-       if ((ret = getkerninfo(KINFO_VNODE, NULL, NULL, 0)) == -1) {
-               syserror("can't get estimate for kerninfo");
-               exit(1);
-       }
-       copysize = ret;
-       if ((vnodebase = (struct e_vnode *)malloc(copysize)) 
-            == NULL) {
-               error("out of memory");
-               exit(1);
-       }
-       if ((ret = getkerninfo(KINFO_VNODE, vnodebase, &copysize, 0)) 
-            == -1) {
-               syserror("can't get vnode list");
-               exit(1);
-       }
-       if (copysize % sizeof (struct e_vnode)) {
-               error("vnode size mismatch");
-               exit(1);
-       }
-       *avnodes = copysize / sizeof (struct e_vnode);
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_VNODE;
+       if (sysctl(mib, 2, NULL, &copysize, NULL, 0) == -1)
+               err(1, "sysctl: KERN_VNODE");
+       if ((vnodebase = malloc(copysize)) == NULL)
+               err(1, NULL);
+       if (sysctl(mib, 2, vnodebase, &copysize, NULL, 0) == -1)
+               err(1, "sysctl: KERN_VNODE");
+       if (copysize % sizeof(struct e_vnode))
+               errx(1, "vnode size mismatch");
+       *avnodes = copysize / sizeof(struct e_vnode);
 
        return (vnodebase);
 }
 
        return (vnodebase);
 }
@@ -683,48 +645,32 @@ struct e_vnode *
 kinfo_vnodes(avnodes)
        int *avnodes;
 {
 kinfo_vnodes(avnodes)
        int *avnodes;
 {
-       struct nlist vnl[] = {
-#define V_NUMV 0
-               { "_numvnodes" },
-#define V_ROOTFS 1
-               { "_rootfs" },
-               {""}
-       };
        int numvnodes;
        struct mount *rootfs, *mp, mount;
        char *vbuf, *evbuf, *bp;
        struct vnode *vp, vnode;
        int num;
 
        int numvnodes;
        struct mount *rootfs, *mp, mount;
        char *vbuf, *evbuf, *bp;
        struct vnode *vp, vnode;
        int num;
 
-#define VPTRSZ  sizeof (struct vnode *)
-#define VNODESZ sizeof (struct vnode)
-#define NVAL(indx)     vnl[(indx)].n_value
+#define VPTRSZ  sizeof(struct vnode *)
+#define VNODESZ sizeof(struct vnode)
 
 
-       if (kvm_nlist(vnl) != 0) {
-               error("nlist vnl: %s", kvm_geterr());
-               exit(1);
-       }
-       numvnodes = getword(NVAL(V_NUMV));
-       if ((vbuf = (char *)malloc((numvnodes + 20) * (VPTRSZ + VNODESZ))) 
-           == NULL) {
-               error("out of memory");
-               exit(1);
-       }
+       KGET(V_NUMV, numvnodes);
+       if ((vbuf = malloc((numvnodes + 20) * (VPTRSZ + VNODESZ))) == NULL)
+               err(1, NULL);
        bp = vbuf;
        evbuf = vbuf + (numvnodes + 20) * (VPTRSZ + VNODESZ);
        bp = vbuf;
        evbuf = vbuf + (numvnodes + 20) * (VPTRSZ + VNODESZ);
-       mp = rootfs = (struct mount *)getword(NVAL(V_ROOTFS));
+       KGET(V_ROOTFS, rootfs);
+       mp = rootfs;
        do {
        do {
-               kvm_read(mp, &mount, sizeof(mount));
+               KGET2(mp, &mount, sizeof(mount), "mount entry");
                for (vp = mount.mnt_mounth; vp; vp = vnode.v_mountf) {
                for (vp = mount.mnt_mounth; vp; vp = vnode.v_mountf) {
-                       kvm_read(vp, &vnode, sizeof (vnode));
-                       if ((bp + VPTRSZ + VNODESZ) > evbuf) {
+                       KGET2(vp, &vnode, sizeof(vnode), "vnode");
+                       if ((bp + VPTRSZ + VNODESZ) > evbuf)
                                /* XXX - should realloc */
                                /* XXX - should realloc */
-                               fprintf(stderr, "pstat: ran out of room for vnodes\n");
-                               exit(1);
-                       }
-                       bcopy(&vp, bp, VPTRSZ);
+                               errx(1, "no more room for vnodes");
+                       memmove(bp, &vp, VPTRSZ);
                        bp += VPTRSZ;
                        bp += VPTRSZ;
-                       bcopy(&vnode, bp, VNODESZ);
+                       memmove(bp, &vnode, VNODESZ);
                        bp += VNODESZ;
                        num++;
                }
                        bp += VNODESZ;
                        num++;
                }
@@ -734,185 +680,80 @@ kinfo_vnodes(avnodes)
        return ((struct e_vnode *)vbuf);
 }
        
        return ((struct e_vnode *)vbuf);
 }
        
-       
-u_long
-getword(loc)
-       int loc;
-{
-       u_long word;
-
-       kvm_read(V(loc), &word, sizeof (word));
-       return (word);
-}
-
-putf(v, n)
-{
-       if (v)
-               printf("%c", n);
-       else
-               printf(" ");
-}
-
-dotext()
-{
-#ifdef NEWVM
-       printf("no text table in this system\n");
-#else
-       register struct text *xp;
-       int ntext;
-       struct text *xtext, *atext;
-       int ntx, ntxca;
-
-       ntx = ntxca = 0;
-       ntext = getword(nl[SNTEXT].n_value);
-       xtext = (struct text *)calloc(ntext, sizeof (struct text));
-       atext = (struct text *)getword(nl[STEXT].n_value);
-       if (ntext < 0 || ntext > 10000) {
-               fprintf(stderr, "number of texts is preposterous (%d)\n",
-                       ntext);
-               return;
-       }
-       if (xtext == NULL) {
-               fprintf(stderr, "can't allocate memory for text table\n");
-               return;
-       }
-       kvm_read(atext, xtext, ntext * sizeof (struct text));
-       for (xp = xtext; xp < &xtext[ntext]; xp++) {
-               if (xp->x_vptr != NULL)
-                       ntxca++;
-               if (xp->x_count != 0)
-                       ntx++;
-       }
-       if (totflg) {
-               printf("%3d/%3d texts active, %3d used\n", ntx, ntext, ntxca);
-               return;
-       }
-       printf("%d/%d active texts, %d used\n", ntx, ntext, ntxca);
-       printf("\
-   LOC   FLAGS DADDR     CADDR  RSS SIZE     VPTR   CNT CCNT      FORW     BACK\n");
-       for (xp = xtext; xp < &xtext[ntext]; xp++) {
-               if (xp->x_vptr == NULL)
-                       continue;
-               printf("%8.1x", atext + (xp - xtext));
-               printf(" ");
-               putf(xp->x_flag&XPAGV, 'P');
-               putf(xp->x_flag&XTRC, 'T');
-               putf(xp->x_flag&XWRIT, 'W');
-               putf(xp->x_flag&XLOAD, 'L');
-               putf(xp->x_flag&XLOCK, 'K');
-               putf(xp->x_flag&XWANT, 'w');
-               printf("%5x", xp->x_daddr[0]);
-               printf("%10x", xp->x_caddr);
-               printf("%5d", xp->x_rssize);
-               printf("%5d", xp->x_size);
-               printf("%10.1x", xp->x_vptr);
-               printf("%5d", xp->x_count&0377);
-               printf("%5d", xp->x_ccount);
-               printf("%10x", xp->x_forw);
-               printf("%9x", xp->x_back);
-               printf("\n");
-       }
-       free(xtext);
-#endif
-}
-
-doproc()
-{
-       if (!totflg)
-               printf("pstat: -p no longer supported (use ps)\n");
-}
-
-char mesg[] = "  LINE RAW CAN OUT  HWT LWT     ADDR COL STATE  SESS  PGID DISC\n";
+char hdr[]="  LINE RAW CAN OUT  HWT LWT     ADDR COL STATE  SESS  PGID DISC\n";
 int ttyspace = 128;
 int ttyspace = 128;
-struct tty *tty;
 
 
-dotty()
+void
+ttymode()
 {
 {
+       struct tty *tty;
 
 
-       if ((tty = (struct tty *)malloc(ttyspace * sizeof(*tty))) == 0) {
-               printf("pstat: out of memory\n");
-               return;
-       }
+       if ((tty = malloc(ttyspace * sizeof(*tty))) == NULL)
+               err(1, NULL);
 #ifndef hp300
 #ifndef hp300
-       printf("1 cons\n");
-       kvm_read(V(nl[SCONS].n_value), tty, sizeof(*tty));
-       printf(mesg);
+       (void)printf("1 console\n");
+       KGET(SCONS, *tty);
+       (void)printf(hdr);
        ttyprt(&tty[0], 0);
 #endif
 #ifdef vax
        if (nl[SNQD].n_type != 0) 
        ttyprt(&tty[0], 0);
 #endif
 #ifdef vax
        if (nl[SNQD].n_type != 0) 
-               doqdss();
+               qdss();
        if (nl[SNDZ].n_type != 0)
        if (nl[SNDZ].n_type != 0)
-               dottytype("dz", SDZ, SNDZ);
+               ttytype(tty, "dz", SDZ, SNDZ);
        if (nl[SNDH].n_type != 0)
        if (nl[SNDH].n_type != 0)
-               dottytype("dh", SDH, SNDH);
+               ttytype(tty, "dh", SDH, SNDH);
        if (nl[SNDMF].n_type != 0)
        if (nl[SNDMF].n_type != 0)
-               dottytype("dmf", SDMF, SNDMF);
+               ttytype(tty, "dmf", SDMF, SNDMF);
        if (nl[SNDHU].n_type != 0)
        if (nl[SNDHU].n_type != 0)
-               dottytype("dhu", SDHU, SNDHU);
+               ttytype(tty, "dhu", SDHU, SNDHU);
        if (nl[SNDMZ].n_type != 0)
        if (nl[SNDMZ].n_type != 0)
-               dottytype("dmz", SDMZ, SNDMZ);
+               ttytype(tty, "dmz", SDMZ, SNDMZ);
 #endif
 #ifdef tahoe
        if (nl[SNVX].n_type != 0)
 #endif
 #ifdef tahoe
        if (nl[SNVX].n_type != 0)
-               dottytype("vx", SVX, SNVX);
+               ttytype(tty, "vx", SVX, SNVX);
        if (nl[SNMP].n_type != 0)
        if (nl[SNMP].n_type != 0)
-               dottytype("mp", SMP, SNMP);
+               ttytype(tty, "mp", SMP, SNMP);
 #endif
 #ifdef hp300
        if (nl[SNITE].n_type != 0)
 #endif
 #ifdef hp300
        if (nl[SNITE].n_type != 0)
-               dottytype("ite", SITE, SNITE);
+               ttytype(tty, "ite", SITE, SNITE);
        if (nl[SNDCA].n_type != 0)
        if (nl[SNDCA].n_type != 0)
-               dottytype("dca", SDCA, SNDCA);
+               ttytype(tty, "dca", SDCA, SNDCA);
        if (nl[SNDCM].n_type != 0)
        if (nl[SNDCM].n_type != 0)
-               dottytype("dcm", SDCM, SNDCM);
+               ttytype(tty, "dcm", SDCM, SNDCM);
        if (nl[SNDCL].n_type != 0)
        if (nl[SNDCL].n_type != 0)
-               dottytype("dcl", SDCL, SNDCL);
+               ttytype(tty, "dcl", SDCL, SNDCL);
+#endif
+#ifdef mips
+       if (nl[SNDC].n_type != 0)
+               ttytype(tty, "dc", SDC, SNDC);
 #endif
        if (nl[SNPTY].n_type != 0)
 #endif
        if (nl[SNPTY].n_type != 0)
-               dottytype("pty", SPTY, SNPTY);
+               ttytype(tty, "pty", SPTY, SNPTY);
 }
 
 }
 
-/* 
- * Special case the qdss: there are 4 ttys per qdss,
- * but only the first of each is used as a tty.  
- */
-#ifdef vax
-doqdss()
+void
+ttytype(tty, name, type, number)
+       register struct tty *tty;
+       char *name;
+       int type, number;
 {
 {
-       int nqd;
        register struct tty *tp;
        register struct tty *tp;
-
-       kvm_read(V(nl[SNQD].n_value), &nqd, sizeof(nqd));
-       printf("%d qd\n", nqd);
-       kvm_read(V(nl[SQD].n_value), tty, nqd * sizeof(struct tty) * 4);
-       printf(mesg);
-       for (tp = tty; tp < &tty[nqd * 4]; tp += 4)
-               ttyprt(tp, tp - tty);
-}
-#endif
-
-dottytype(name, type, number)
-char *name;
-{
        int ntty;
        int ntty;
-       register struct tty *tp;
-       extern char *realloc();
 
 
-       if (tty == (struct tty *)0) 
+       if (tty == NULL)
                return;
                return;
-       kvm_read(V(nl[number].n_value), &ntty, sizeof(ntty));
-       printf("%d %s %s\n", ntty, name, (ntty == 1) ? "line" :
-           "lines");
+       KGET(number, ntty);
+       (void)printf("%d %s %s\n", ntty, name, (ntty == 1) ? "line" : "lines");
        if (ntty > ttyspace) {
                ttyspace = ntty;
        if (ntty > ttyspace) {
                ttyspace = ntty;
-               if ((tty = (struct tty *)realloc(tty, ttyspace * sizeof(*tty))) == 0) {
-                       printf("pstat: out of memory\n");
-                       return;
-               }
+               if ((tty = realloc(tty, ttyspace * sizeof(*tty))) == 0)
+                       err(1, NULL);
        }
        }
-       kvm_read(V(nl[type].n_value), tty, ntty * sizeof(struct tty));
-       printf(mesg);
+       KGET1(type, tty, ntty * sizeof(struct tty), "tty structs");
+       (void)printf(hdr);
        for (tp = tty; tp < &tty[ntty]; tp++)
                ttyprt(tp, tp - tty);
 }
        for (tp = tty; tp < &tty[ntty]; tp++)
                ttyprt(tp, tp - tty);
 }
@@ -921,45 +762,41 @@ struct {
        int flag;
        char val;
 } ttystates[] = {
        int flag;
        char val;
 } ttystates[] = {
-       TS_WOPEN,       'W',
-       TS_ISOPEN,      'O',
-       TS_CARR_ON,     'C',
-       TS_TIMEOUT,     'T',
-       TS_FLUSH,       'F',
-       TS_BUSY,        'B',
-       TS_ASLEEP,      'A',
-       TS_XCLUDE,      'X',
-       TS_TTSTOP,      'S',
-       TS_TBLOCK,      'K',
-       TS_RCOLL,       'R',
-       TS_WCOLL,       'I',    /* running short on letters ! */
-       TS_ASYNC,       'Y',
-       TS_BKSL,        'D',
-       TS_ERASE,       'E',
-       TS_LNCH,        'L',
-       TS_TYPEN,       'P',
-       TS_CNTTB,       'N',
-       0,      0
+       { TS_WOPEN,     'W'},
+       { TS_ISOPEN,    'O'},
+       { TS_CARR_ON,   'C'},
+       { TS_TIMEOUT,   'T'},
+       { TS_FLUSH,     'F'},
+       { TS_BUSY,      'B'},
+       { TS_ASLEEP,    'A'},
+       { TS_XCLUDE,    'X'},
+       { TS_TTSTOP,    'S'},
+       { TS_TBLOCK,    'K'},
+       { TS_ASYNC,     'Y'},
+       { TS_BKSL,      'D'},
+       { TS_ERASE,     'E'},
+       { TS_LNCH,      'L'},
+       { TS_TYPEN,     'P'},
+       { TS_CNTTB,     'N'},
+       { 0,           '\0'},
 };
 
 };
 
-ttyprt(atp, line)
-struct tty *atp;
-{
+void
+ttyprt(tp, line)
        register struct tty *tp;
        register struct tty *tp;
-       char state[20];
-       register i, j;
-       char *name;
-       extern char *devname();
+       int line;
+{
+       register int i, j;
        pid_t pgid;
        pid_t pgid;
+       char *name, state[20];
 
 
-       tp = atp;
-       if (nflg || tp->t_dev == 0 ||
+       if (usenumflag || tp->t_dev == 0 ||
           (name = devname(tp->t_dev, S_IFCHR)) == NULL)
           (name = devname(tp->t_dev, S_IFCHR)) == NULL)
-               printf("%7d ", line); 
+               (void)printf("%7d ", line); 
        else
        else
-               printf("%7s ", name);
-       printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc);
-       printf("%3d %4d %3d %8x %3d ", tp->t_outq.c_cc, 
+               (void)printf("%7s ", name);
+       (void)printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc);
+       (void)printf("%3d %4d %3d %8x %3d ", tp->t_outq.c_cc, 
                tp->t_hiwat, tp->t_lowat, tp->t_addr, tp->t_col);
        for (i = j = 0; ttystates[i].flag; i++)
                if (tp->t_state&ttystates[i].flag)
                tp->t_hiwat, tp->t_lowat, tp->t_addr, tp->t_col);
        for (i = j = 0; ttystates[i].flag; i++)
                if (tp->t_state&ttystates[i].flag)
@@ -967,240 +804,113 @@ struct tty *atp;
        if (j == 0)
                state[j++] = '-';
        state[j] = '\0';
        if (j == 0)
                state[j++] = '-';
        state[j] = '\0';
-       printf("%-4s %6x", state, (u_long)tp->t_session & ~KERNBASE);
-       if (tp->t_pgrp == NULL || kvm_read(&tp->t_pgrp->pg_id, &pgid, 
-           sizeof (pid_t)) != sizeof (pid_t))
-               pgid = 0;
-       printf("%6d ", pgid);
+       (void)printf("%-4s %6x", state, (u_long)tp->t_session & ~KERNBASE);
+       pgid = 0;
+       if (tp->t_pgrp != NULL)
+               KGET2(&tp->t_pgrp->pg_id, &pgid, sizeof(pid_t), "pgid");
+       (void)printf("%6d ", pgid);
        switch (tp->t_line) {
        switch (tp->t_line) {
-
        case TTYDISC:
        case TTYDISC:
-               printf("term\n");
+               (void)printf("term\n");
                break;
                break;
-
        case TABLDISC:
        case TABLDISC:
-               printf("tab\n");
+               (void)printf("tab\n");
                break;
                break;
-
        case SLIPDISC:
        case SLIPDISC:
-               printf("slip\n");
+               (void)printf("slip\n");
                break;
                break;
-
        default:
        default:
-               printf("%d\n", tp->t_line);
-       }
-}
-
-/*
- * The user structure is going away.  What's left here won't
- * be around for long.
- */
-dousr()
-{
-#ifdef NEWVM
-       printf("nothing left in user structure in this system\n");
-#else
-       register struct user *up;
-       register i, j, *ip;
-       register struct nameidata *nd;
-       struct proc *p;
-       int ret;
-
-       if ((ret = kvm_getprocs(KINFO_PROC_PID, upid)) != 1) {
-               if (ret == -1)
-                       error("kvm_getproc: %s", kvm_geterr());
-               else
-                       error("can't locate process %d", upid);
-               return (1);
-       }
-       if ((p = kvm_nextproc()) == NULL) {
-               error("kvm_nextproc: %s", kvm_geterr());
-               return (1);
-       }
-       if ((up = kvm_getu(p)) == NULL) {
-               error("kvm_getu: %s", kvm_geterr());
-               return (1);
-       }
-       nd = &up->u_nd;
-       printf("pcb");
-       ip = (int *)&up->u_pcb;
-       i = 0;
-       while (ip < (int *)((char *)&up->u_pcb + sizeof (struct pcb))) {
-               if (i%4 == 0)
-                       putchar('\t');
-               printf("%#10x ", *ip++);
-               if (i%4 == 3)
-                       putchar('\n');
-               i++;
-       }
-       if (i%4)
-               putchar('\n');
-       printf("procp\t%#x\n", up->u_procp);
-       printf("ar0\t%#x\n", up->u_ar0);
-       printf("sizes\ttext %d data %d stack %d\n", 
-               up->u_tsize, up->u_dsize, up->u_ssize);
-       printf("ssave");
-       for (i=0; i<sizeof(label_t)/sizeof(int); i++) {
-               if (i%5==0)
-                       printf("\t");
-               printf("%#11x", up->u_ssave.val[i]);
-               if (i%5==4)
-                       printf("\n");
-       }
-       if (i%5)
-               printf("\n");
-       printf("odsize\t%#x\n", up->u_odsize);
-       printf("ossize\t%#x\n", up->u_ossize);
-       printf("outime\t%d\n", up->u_outime);
-       printf("mmap\t%#x\n", up->u_mmap);
-       printf("sigs");
-       for (i=0; i<NSIG; i++) {
-               if (i % 8 == 0)
-                       printf("\t");
-               printf("%#x ", up->u_signal[i]);
-               if (i % 8 == 7)
-                       printf("\n");
-       }
-       if (i % 8)
-               printf("\n");
-       printf("sigmask");
-       for (i=0; i<NSIG; i++) {
-               if (i % 8 == 0)
-                       printf("\t");
-               printf("%#x ", up->u_sigmask[i]);
-               if (i % 8 == 7)
-                       printf("\n");
+               (void)printf("%d\n", tp->t_line);
+               break;
        }
        }
-       if (i % 8)
-               printf("\n");
-       printf("sigonstack\t%#x\n", up->u_sigonstack);
-       printf("sigintr\t%#x\n", up->u_sigintr);
-       printf("oldmask\t%#x\n", up->u_oldmask);
-       printf("sigstack\t%#x %#x\n", 
-               up->u_sigstack.ss_sp, up->u_sigstack.ss_onstack);
-       printf("sig\t%#x\n", up->u_sig);
-       printf("code\t%#x\n", up->u_code);
-       printf("start\t%ld secs %ld usecs\n", 
-               up->u_start.tv_sec, up->u_start.tv_usec);
-       printf("acflag\t%#x\n", up->u_acflag);
-       printf("prof\t%#x %#x %#x %#x\n", up->u_prof.pr_base, up->u_prof.pr_size,
-           up->u_prof.pr_off, up->u_prof.pr_scale);
-       printf("ru\t");
-       ip = (int *)&up->u_ru;
-       for (i = 0; i < sizeof(up->u_ru)/sizeof(int); i++)
-               printf("%ld ", ip[i]);
-       printf("\n");
-       ip = (int *)&up->u_cru;
-       printf("cru\t");
-       for (i = 0; i < sizeof(up->u_cru)/sizeof(int); i++)
-               printf("%ld ", ip[i]);
-       printf("\n");
-#endif
 }
 
 }
 
-oatoi(s)
-char *s;
-{
-       register v;
-
-       v = 0;
-       while (*s)
-               v = (v<<3) + *s++ - '0';
-       return(v);
-}
-
-dofile()
+void
+filemode()
 {
        register struct file *fp;
        struct file *addr;
 {
        register struct file *fp;
        struct file *addr;
-       char *buf;
+       char *buf, flagbuf[16], *fbp;
        int len, maxfile, nfile;
        int len, maxfile, nfile;
-       struct nlist fnl[] = {
-#define        FNL_NFILE       0
-               {"_nfiles"},
-#define FNL_MAXFILE    1
-               {"_maxfiles"},
-               {""}
-       };
        static char *dtypes[] = { "???", "inode", "socket" };
 
        static char *dtypes[] = { "???", "inode", "socket" };
 
-       if (kvm_nlist(fnl) != 0) {
-               error("kvm_nlist: no _nfiles or _maxfiles: %s", 
-                       kvm_geterr());
-               return;
-       }
-       kvm_read(V(fnl[FNL_MAXFILE].n_value), &maxfile,
-               sizeof (maxfile));
-       if (totflg) {
-               kvm_read(V(fnl[FNL_NFILE].n_value), &nfile, sizeof (nfile));
-               printf("%3d/%3d files\n", nfile, maxfile);
+       KGET(FNL_MAXFILE, maxfile);
+       if (totalflag) {
+               KGET(FNL_NFILE, nfile);
+               (void)printf("%3d/%3d files\n", nfile, maxfile);
                return;
        }
        if (getfiles(&buf, &len) == -1)
                return;
        /*
                return;
        }
        if (getfiles(&buf, &len) == -1)
                return;
        /*
-        * getfiles returns in malloc'd buf a pointer to the first file
-        * structure, and then an array of file structs (whose
-        * addresses are derivable from the previous entry)
+        * Getfiles returns in malloc'd memory a pointer to the first file
+        * structure, and then an array of file structs (whose addresses are
+        * derivable from the previous entry).
         */
        addr = *((struct file **)buf);
         */
        addr = *((struct file **)buf);
-       fp = (struct file *)(buf + sizeof (struct file *));
-       nfile = (len - sizeof (struct file *)) / sizeof (struct file);
+       fp = (struct file *)(buf + sizeof(struct file *));
+       nfile = (len - sizeof(struct file *)) / sizeof(struct file);
        
        
-       printf("%d/%d open files\n", nfile, maxfile);
-       printf("   LOC   TYPE    FLG     CNT  MSG    DATA    OFFSET\n");
+       (void)printf("%d/%d open files\n", nfile, maxfile);
+       (void)printf("   LOC   TYPE    FLG     CNT  MSG    DATA    OFFSET\n");
        for (; (char *)fp < buf + len; addr = fp->f_filef, fp++) {
        for (; (char *)fp < buf + len; addr = fp->f_filef, fp++) {
-               printf("%x ", addr);
-               if (fp->f_type <= DTYPE_SOCKET)
-                       printf("%-8.8s", dtypes[fp->f_type]);
-               else
-                       printf("%8d", fp->f_type);
-               putf(fp->f_flag&FREAD, 'R');
-               putf(fp->f_flag&FWRITE, 'W');
-               putf(fp->f_flag&FAPPEND, 'A');
+               if ((unsigned)fp->f_type > DTYPE_SOCKET)
+                       continue;
+               (void)printf("%x ", addr);
+               (void)printf("%-8.8s", dtypes[fp->f_type]);
+               fbp = flagbuf;
+               if (fp->f_flag & FREAD)
+                       *fbp++ = 'R';
+               if (fp->f_flag & FWRITE)
+                       *fbp++ = 'W';
+               if (fp->f_flag & FAPPEND)
+                       *fbp++ = 'A';
 #ifdef FSHLOCK /* currently gone */
 #ifdef FSHLOCK /* currently gone */
-               putf(fp->f_flag&FSHLOCK, 'S');
-               putf(fp->f_flag&FEXLOCK, 'X');
-#else
-               putf(0, ' ');
-               putf(0, ' ');
+               if (fp->f_flag & FSHLOCK)
+                       *fbp++ = 'S';
+               if (fp->f_flag & FEXLOCK)
+                       *fbp++ = 'X';
 #endif
 #endif
-               putf(fp->f_flag&FASYNC, 'I');
-               printf("  %3d", fp->f_count);
-               printf("  %3d", fp->f_msgcount);
-               printf("  %8.1x", fp->f_data);
+               if (fp->f_flag & FASYNC)
+                       *fbp++ = 'I';
+               *fbp = '\0';
+               (void)printf("%6s  %3d", flagbuf, fp->f_count);
+               (void)printf("  %3d", fp->f_msgcount);
+               (void)printf("  %8.1x", fp->f_data);
                if (fp->f_offset < 0)
                if (fp->f_offset < 0)
-                       printf("  %x\n", fp->f_offset);
+                       (void)printf("  %qx\n", fp->f_offset);
                else
                else
-                       printf("  %ld\n", fp->f_offset);
+                       (void)printf("  %qd\n", fp->f_offset);
        }
        free(buf);
 }
 
        }
        free(buf);
 }
 
+int
 getfiles(abuf, alen)
        char **abuf;
        int *alen;
 {
 getfiles(abuf, alen)
        char **abuf;
        int *alen;
 {
+       size_t len;
+       int mib[2];
        char *buf;
        char *buf;
-       int len;
 
 
-       if (memf != NULL) {
-               /*
-                * add emulation of KINFO_FILE here
-                */
-               error("files on dead kernel, not impl\n");
-               exit(1);
-       }
-       if ((len = getkerninfo(KINFO_FILE, NULL, NULL, 0)) == -1) {
-               syserror("getkerninfo estimate");
-               return (-1);
-       }
-       if ((buf = (char *)malloc(len)) == NULL) {
-               error("out of memory");
+       /*
+        * XXX
+        * Add emulation of KINFO_FILE here.
+        */
+       if (memf != NULL)
+               errx(1, "files on dead kernel, not implemented\n");
+
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_FILE;
+       if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) {
+               warn("sysctl: KERN_FILE");
                return (-1);
        }
                return (-1);
        }
-       if ((len = getkerninfo(KINFO_FILE, buf, &len, 0)) == -1) {
-               syserror("getkerninfo");
+       if ((buf = malloc(len)) == NULL)
+               err(1, NULL);
+       if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) {
+               warn("sysctl: KERN_FILE");
                return (-1);
        }
        *abuf = buf;
                return (-1);
        }
        *abuf = buf;
@@ -1208,367 +918,126 @@ getfiles(abuf, alen)
        return (0);
 }
 
        return (0);
 }
 
-
-#ifdef NEWVM
-doswap()
-{
-       printf("swap statistics not yet supported in this system\n");
-}
-
-#else /* NEWVM */
-int dmmin, dmmax, nswdev;
-
-doswap()
-{
-       struct proc *proc;
-       int nproc;
-       struct text *xtext;
-       int ntext;
-       struct map *swapmap;
-       int nswapmap;
-       struct swdevt *swdevt, *sw;
-       register struct proc *pp;
-       int nswap, used, tused, free, waste;
-       int db, sb;
-       register struct mapent *me;
-       register struct text *xp;
-       int i, j;
-       long rmalloc();
-
-       nproc = getword(nl[SNPROC].n_value);
-       ntext = getword(nl[SNTEXT].n_value);
-       if (nproc < 0 || nproc > 10000 || ntext < 0 || ntext > 10000) {
-               fprintf(stderr, "number of procs/texts is preposterous (%d, %d)\n",
-                       nproc, ntext);
-               return;
-       }
-       proc = (struct proc *)calloc(nproc, sizeof (struct proc));
-       if (proc == NULL) {
-               fprintf(stderr, "can't allocate memory for proc table\n");
-               exit(1);
-       }
-       xtext = (struct text *)calloc(ntext, sizeof (struct text));
-       if (xtext == NULL) {
-               fprintf(stderr, "can't allocate memory for text table\n");
-               exit(1);
-       }
-       nswapmap = getword(nl[SNSWAPMAP].n_value);
-       swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));
-       if (swapmap == NULL) {
-               fprintf(stderr, "can't allocate memory for swapmap\n");
-               exit(1);
-       }
-       nswdev = getword(nl[SNSWDEV].n_value);
-       swdevt = (struct swdevt *)calloc(nswdev, sizeof (struct swdevt));
-       if (swdevt == NULL) {
-               fprintf(stderr, "can't allocate memory for swdevt table\n");
-               exit(1);
-       }
-       kvm_read(V(nl[SSWDEVT].n_value), swdevt,
-               nswdev * sizeof (struct swdevt));
-       kvm_read(V(getword(nl[SPROC].n_value)), proc,
-               nproc * sizeof (struct proc));
-       kvm_read(V(getword(nl[STEXT].n_value)), xtext,
-               ntext * sizeof (struct text));
-       kvm_read(V(getword(nl[SWAPMAP].n_value)), swapmap,
-               nswapmap * sizeof (struct map));
-
-       swapmap->m_name = "swap";
-       swapmap->m_limit = (struct mapent *)&swapmap[nswapmap];
-       dmmin = getword(nl[SDMMIN].n_value);
-       dmmax = getword(nl[SDMMAX].n_value);
-       nswap = 0;
-       for (sw = swdevt; sw < &swdevt[nswdev]; sw++)
-               if (sw->sw_freed)
-                       nswap += sw->sw_nblks;
-       free = 0;
-       for (me = (struct mapent *)(swapmap+1);
-           me < (struct mapent *)&swapmap[nswapmap]; me++)
-               free += me->m_size;
-       tused = 0;
-       for (xp = xtext; xp < &xtext[ntext]; xp++)
-               if (xp->x_vptr!=NULL) {
-                       tused += ctod(clrnd(xp->x_size));
-                       if (xp->x_flag & XPAGV)
-                               tused += ctod(clrnd(ctopt(xp->x_size)));
-               }
-       used = tused;
-       waste = 0;
-       for (pp = proc; pp < &proc[nproc]; pp++) {
-               if (pp->p_stat == 0 || pp->p_stat == SZOMB)
-                       continue;
-               if (pp->p_flag & SSYS)
-                       continue;
-               db = ctod(pp->p_dsize), sb = up(db);
-               used += sb;
-               waste += sb - db;
-               db = ctod(pp->p_ssize), sb = up(db);
-               used += sb;
-               waste += sb - db;
-               if ((pp->p_flag&SLOAD) == 0)
-                       used += ctod(vusize(pp));
-       }
-       if (totflg) {
-#define        btok(x) ((x) / (1024 / DEV_BSIZE))
-               printf("%3d/%3d 00k swap\n",
-                   btok(used/100), btok((used+free)/100));
-               return;
-       }
-       printf("%dk used (%dk text), %dk free, %dk wasted, %dk missing\n",
-           btok(used), btok(tused), btok(free), btok(waste),
-/* a dmmax/2 block goes to argmap */
-           btok(nswap - dmmax/2 - (used + free)));
-       printf("avail: ");
-       for (i = dmmax; i >= dmmin; i /= 2) {
-               j = 0;
-               while (rmalloc(swapmap, i) != 0)
-                       j++;
-               if (j) printf("%d*%dk ", j, btok(i));
-       }
-       free = 0;
-       for (me = (struct mapent *)(swapmap+1);
-           me < (struct mapent *)&swapmap[nswapmap]; me++)
-               free += me->m_size;
-       printf("%d*1k\n", btok(free));
-}
-
-up(size)
-       register int size;
-{
-       register int i, block;
-
-       i = 0;
-       block = dmmin;
-       while (i < size) {
-               i += block;
-               if (block < dmmax)
-                       block *= 2;
-       }
-       return (i);
-}
-
 /*
 /*
- * Compute number of pages to be allocated to the u. area
- * and data and stack area page tables, which are stored on the
- * disk immediately after the u. area.
+ * swapmode is based on a program called swapinfo written
+ * by Kevin Lahey <kml@rokkaku.atl.ga.us>.
  */
  */
-vusize(p)
-       register struct proc *p;
+void
+swapmode()
 {
 {
-       register int tsz = p->p_tsize / NPTEPG;
-
-       /*
-        * We do not need page table space on the disk for page
-        * table pages wholly containing text. 
-        */
-       return (clrnd(UPAGES +
-           clrnd(ctopt(p->p_tsize+p->p_dsize+p->p_ssize+UPAGES)) - tsz));
-}
+       char *header;
+       int hlen, nswap, nswdev, dmmax, nswapmap;
+       int s, e, div, i, avail, nfree, npfree, used;
+       struct swdevt *sw;
+       long blocksize, *perdev;
+       struct map *swapmap, *kswapmap;
+       struct mapent *mp;
+
+       KGET(VM_NSWAP, nswap);
+       KGET(VM_NSWDEV, nswdev);
+       KGET(VM_DMMAX, dmmax);
+       KGET(VM_NSWAPMAP, nswapmap);
+       KGET(VM_SWAPMAP, kswapmap);     /* kernel `swapmap' is a pointer */
+       if ((sw = malloc(nswdev * sizeof(*sw))) == NULL ||
+           (perdev = malloc(nswdev * sizeof(*perdev))) == NULL ||
+           (mp = malloc(nswapmap * sizeof(*mp))) == NULL)
+               err(1, "malloc");
+       KGET1(VM_SWDEVT, sw, nswdev * sizeof(*sw), "swdevt");
+       KGET2((long)kswapmap, mp, nswapmap * sizeof(*mp), "swapmap");
+
+       /* First entry in map is `struct map'; rest are mapent's. */
+       swapmap = (struct map *)mp;
+       if (nswapmap != swapmap->m_limit - (struct mapent *)kswapmap)
+               errx(1, "panic: nswapmap goof");
+
+       /* Count up swap space. */
+       nfree = 0;
+       memset(perdev, 0, nswdev * sizeof(*perdev));
+       for (mp++; mp->m_addr != 0; mp++) {
+               s = mp->m_addr;                 /* start of swap region */
+               e = mp->m_addr + mp->m_size;    /* end of region */
+               nfree += mp->m_size;
 
 
-/*
- * Allocate 'size' units from the given
- * map. Return the base of the allocated space.
- * In a map, the addresses are increasing and the
- * list is terminated by a 0 size.
- *
- * Algorithm is first-fit.
- *
- * This routine knows about the interleaving of the swapmap
- * and handles that.
- */
-long
-rmalloc(mp, size)
-       register struct map *mp;
-       long size;
-{
-       register struct mapent *ep = (struct mapent *)(mp+1);
-       register int addr;
-       register struct mapent *bp;
-       swblk_t first, rest;
+               /*
+                * Swap space is split up among the configured disks.
+                * The first dmmax blocks of swap space some from the
+                * first disk, the next dmmax blocks from the next, 
+                * and so on.  The list of free space joins adjacent
+                * free blocks, ignoring device boundries.  If we want
+                * to keep track of this information per device, we'll
+                * just have to extract it ourselves.
+                */
 
 
-       if (size <= 0 || size > dmmax)
-               return (0);
-       /*
-        * Search for a piece of the resource map which has enough
-        * free space to accomodate the request.
-        */
-       for (bp = ep; bp->m_size; bp++) {
-               if (bp->m_size >= size) {
-                       /*
-                        * If allocating from swapmap,
-                        * then have to respect interleaving
-                        * boundaries.
-                        */
-                       if (nswdev > 1 &&
-                           (first = dmmax - bp->m_addr%dmmax) < bp->m_size) {
-                               if (bp->m_size - first < size)
-                                       continue;
-                               addr = bp->m_addr + first;
-                               rest = bp->m_size - first - size;
-                               bp->m_size = first;
-                               if (rest)
-                                       rmfree(mp, rest, addr+size);
-                               return (addr);
-                       }
-                       /*
-                        * Allocate from the map.
-                        * If there is no space left of the piece
-                        * we allocated from, move the rest of
-                        * the pieces to the left.
-                        */
-                       addr = bp->m_addr;
-                       bp->m_addr += size;
-                       if ((bp->m_size -= size) == 0) {
-                               do {
-                                       bp++;
-                                       (bp-1)->m_addr = bp->m_addr;
-                               } while ((bp-1)->m_size = bp->m_size);
-                       }
-                       if (addr % CLSIZE)
-                               return (0);
-                       return (addr);
+               /* calculate first device on which this falls */
+               i = (s / dmmax) % nswdev;
+               while (s < e) {         /* XXX this is inefficient */
+                       int bound = roundup(s+1, dmmax);
+
+                       if (bound > e)
+                               bound = e;
+                       perdev[i] += bound - s;
+                       if (++i >= nswdev)
+                               i = 0;
+                       s = bound;
                }
        }
                }
        }
-       return (0);
-}
 
 
-/*
- * Free the previously allocated space at addr
- * of size units into the specified map.
- * Sort addr into map and combine on
- * one or both ends if possible.
- */
-rmfree(mp, size, addr)
-       struct map *mp;
-       long size, addr;
-{
-       struct mapent *firstbp;
-       register struct mapent *bp;
-       register int t;
+       header = getbsize(&hlen, &blocksize);
+       if (!totalflag)
+               (void)printf("%-10s %*s %10s %10s %10s\n",
+                   "Device", hlen, header, "Used", "Available", "Capacity");
+       div = blocksize / 512;
+       avail = npfree = 0;
+       for (i = 0; i < nswdev; i++) {
+               int xsize, xfree;
+
+               if (!totalflag)
+                       (void)printf("/dev/%-5s %*d ",
+                           devname(sw[i].sw_dev, S_IFBLK),
+                           hlen, sw[i].sw_nblks / div);
 
 
-       /*
-        * Both address and size must be
-        * positive, or the protocol has broken down.
-        */
-       if (addr <= 0 || size <= 0)
-               goto badrmfree;
-       /*
-        * Locate the piece of the map which starts after the
-        * returned space (or the end of the map).
-        */
-       firstbp = bp = (struct mapent *)(mp + 1);
-       for (; bp->m_addr <= addr && bp->m_size != 0; bp++)
-               continue;
-       /*
-        * If the piece on the left abuts us,
-        * then we should combine with it.
-        */
-       if (bp > firstbp && (bp-1)->m_addr+(bp-1)->m_size >= addr) {
-               /*
-                * Check no overlap (internal error).
-                */
-               if ((bp-1)->m_addr+(bp-1)->m_size > addr)
-                       goto badrmfree;
-               /*
-                * Add into piece on the left by increasing its size.
-                */
-               (bp-1)->m_size += size;
                /*
                /*
-                * If the combined piece abuts the piece on
-                * the right now, compress it in also,
-                * by shifting the remaining pieces of the map over.
+                * Don't report statistics for partitions which have not
+                * yet been activated via swapon(8).
                 */
                 */
-               if (bp->m_addr && addr+size >= bp->m_addr) {
-                       if (addr+size > bp->m_addr)
-                               goto badrmfree;
-                       (bp-1)->m_size += bp->m_size;
-                       while (bp->m_size) {
-                               bp++;
-                               (bp-1)->m_addr = bp->m_addr;
-                               (bp-1)->m_size = bp->m_size;
-                       }
+               if (!sw[i].sw_freed) {
+                       if (totalflag)
+                               continue;
+                       (void)printf(" *** not available for swapping ***\n");
+                       continue;
                }
                }
-               goto done;
+               xsize = sw[i].sw_nblks;
+               xfree = perdev[i];
+               used = xsize - xfree;
+               npfree++;
+               avail += xsize;
+               if (totalflag)
+                       continue;
+               (void)printf("%10d %10d %7.0f%%\n", 
+                   used / div, xfree / div,
+                   (double)used / (double)xsize * 100.0);
        }
        }
-       /*
-        * Don't abut on the left, check for abutting on
-        * the right.
+
+       /* 
+        * If only one partition has been set up via swapon(8), we don't
+        * need to bother with totals.
         */
         */
-       if (addr+size >= bp->m_addr && bp->m_size) {
-               if (addr+size > bp->m_addr)
-                       goto badrmfree;
-               bp->m_addr -= size;
-               bp->m_size += size;
-               goto done;
+       used = avail - nfree;
+       if (totalflag) {
+               (void)printf("%dM/%dM swap space\n", used / 2048, avail / 2048);
+               return;
        }
        }
-       /*
-        * Don't abut at all.  Make a new entry
-        * and check for map overflow.
-        */
-       do {
-               t = bp->m_addr;
-               bp->m_addr = addr;
-               addr = t;
-               t = bp->m_size;
-               bp->m_size = size;
-               bp++;
-       } while (size = t);
-       /*
-        * Segment at bp is to be the delimiter;
-        * If there is not room for it 
-        * then the table is too full
-        * and we must discard something.
-        */
-       if (bp+1 > mp->m_limit) {
-               /*
-                * Back bp up to last available segment.
-                * which contains a segment already and must
-                * be made into the delimiter.
-                * Discard second to last entry,
-                * since it is presumably smaller than the last
-                * and move the last entry back one.
-                */
-               bp--;
-               printf("%s: rmap ovflo, lost [%d,%d)\n", mp->m_name,
-                   (bp-1)->m_addr, (bp-1)->m_addr+(bp-1)->m_size);
-               bp[-1] = bp[0];
-               bp[0].m_size = bp[0].m_addr = 0;
+       if (npfree > 1) {
+               (void)printf("%-10s %*d %10d %10d %7.0f%%\n",
+                   "Total", hlen, avail / div, used / div, nfree / div,
+                   (double)used / (double)avail * 100.0);
        }
        }
-done:
-       return;
-badrmfree:
-       printf("bad rmfree\n");
-}
-#endif /* NEWVM */
-
-#include <varargs.h>
-
-error(va_alist)
-       va_dcl
-{
-       char *fmt;
-       va_list ap;
-       extern errno;
-
-       fprintf(stderr, "pstat: ");
-       va_start(ap);
-       fmt = va_arg(ap, char *);
-       (void) vfprintf(stderr, fmt, ap);
-       va_end(ap);
-       fprintf(stderr, "\n");
 }
 
 }
 
-syserror(va_alist)
-       va_dcl
+void
+usage()
 {
 {
-       char *fmt;
-       va_list ap;
-       extern errno;
-
-       fprintf(stderr, "pstat: ");
-       va_start(ap);
-       fmt = va_arg(ap, char *);
-       (void) vfprintf(stderr, fmt, ap);
-       va_end(ap);
-       fprintf(stderr, ": %s\n", strerror(errno));
+       (void)fprintf(stderr,
+           "usage: pstat -Tfnstv [system] [-M core] [-N system]\n");
+       exit(1);
 }
 }