Index: head/bin/stty/print.c =================================================================== --- head/bin/stty/print.c (revision 180558) +++ head/bin/stty/print.c (revision 180559) @@ -1,279 +1,274 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include "stty.h" #include "extern.h" -#include /* XXX NTTYDISC is too well hidden */ - static void binit(const char *); static void bput(const char *); static const char *ccval(struct cchar *, int); void print(struct termios *tp, struct winsize *wp, int ldisc, enum FMT fmt) { struct cchar *p; long tmp; u_char *cc; int cnt, ispeed, ospeed; char buf1[100], buf2[100]; cnt = 0; /* Line discipline. */ if (ldisc != TTYDISC) { switch(ldisc) { - case NTTYDISC: - cnt += printf("new tty disc; "); - break; case SLIPDISC: cnt += printf("slip disc; "); break; case PPPDISC: cnt += printf("ppp disc; "); break; default: cnt += printf("#%d disc; ", ldisc); break; } } /* Line speed. */ ispeed = cfgetispeed(tp); ospeed = cfgetospeed(tp); if (ispeed != ospeed) cnt += printf("ispeed %d baud; ospeed %d baud;", ispeed, ospeed); else cnt += printf("speed %d baud;", ispeed); if (fmt >= BSD) cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col); if (cnt) (void)printf("\n"); #define on(f) ((tmp & (f)) != 0) #define put(n, f, d) \ if (fmt >= BSD || on(f) != (d)) \ bput((n) + on(f)); /* "local" flags */ tmp = tp->c_lflag; binit("lflags"); put("-icanon", ICANON, 1); put("-isig", ISIG, 1); put("-iexten", IEXTEN, 1); put("-echo", ECHO, 1); put("-echoe", ECHOE, 0); put("-echok", ECHOK, 0); put("-echoke", ECHOKE, 0); put("-echonl", ECHONL, 0); put("-echoctl", ECHOCTL, 0); put("-echoprt", ECHOPRT, 0); put("-altwerase", ALTWERASE, 0); put("-noflsh", NOFLSH, 0); put("-tostop", TOSTOP, 0); put("-flusho", FLUSHO, 0); put("-pendin", PENDIN, 0); put("-nokerninfo", NOKERNINFO, 0); put("-extproc", EXTPROC, 0); /* input flags */ tmp = tp->c_iflag; binit("iflags"); put("-istrip", ISTRIP, 0); put("-icrnl", ICRNL, 1); put("-inlcr", INLCR, 0); put("-igncr", IGNCR, 0); put("-ixon", IXON, 1); put("-ixoff", IXOFF, 0); put("-ixany", IXANY, 1); put("-imaxbel", IMAXBEL, 1); put("-ignbrk", IGNBRK, 0); put("-brkint", BRKINT, 1); put("-inpck", INPCK, 0); put("-ignpar", IGNPAR, 0); put("-parmrk", PARMRK, 0); /* output flags */ tmp = tp->c_oflag; binit("oflags"); put("-opost", OPOST, 1); put("-onlcr", ONLCR, 1); put("-ocrnl", OCRNL, 0); put("-oxtabs", OXTABS, 1); put("-onocr", ONOCR, 0); put("-onlret", ONLRET, 0); /* control flags (hardware state) */ tmp = tp->c_cflag; binit("cflags"); put("-cread", CREAD, 1); switch(tmp&CSIZE) { case CS5: bput("cs5"); break; case CS6: bput("cs6"); break; case CS7: bput("cs7"); break; case CS8: bput("cs8"); break; } bput("-parenb" + on(PARENB)); put("-parodd", PARODD, 0); put("-hupcl", HUPCL, 1); put("-clocal", CLOCAL, 0); put("-cstopb", CSTOPB, 0); switch(tmp & (CCTS_OFLOW | CRTS_IFLOW)) { case CCTS_OFLOW: bput("ctsflow"); break; case CRTS_IFLOW: bput("rtsflow"); break; default: put("-crtscts", CCTS_OFLOW | CRTS_IFLOW, 0); break; } put("-dsrflow", CDSR_OFLOW, 0); put("-dtrflow", CDTR_IFLOW, 0); put("-mdmbuf", MDMBUF, 0); /* XXX mdmbuf == dtrflow */ /* special control characters */ cc = tp->c_cc; if (fmt == POSIX) { binit("cchars"); for (p = cchars1; p->name; ++p) { (void)snprintf(buf1, sizeof(buf1), "%s = %s;", p->name, ccval(p, cc[p->sub])); bput(buf1); } binit(NULL); } else { binit(NULL); for (p = cchars1, cnt = 0; p->name; ++p) { if (fmt != BSD && cc[p->sub] == p->def) continue; #define WD "%-8s" (void)snprintf(buf1 + cnt * 8, sizeof(buf1) - cnt * 8, WD, p->name); (void)snprintf(buf2 + cnt * 8, sizeof(buf2) - cnt * 8, WD, ccval(p, cc[p->sub])); if (++cnt == LINELENGTH / 8) { cnt = 0; (void)printf("%s\n", buf1); (void)printf("%s\n", buf2); } } if (cnt) { (void)printf("%s\n", buf1); (void)printf("%s\n", buf2); } } } static int col; static const char *label; static void binit(const char *lb) { if (col) { (void)printf("\n"); col = 0; } label = lb; } static void bput(const char *s) { if (col == 0) { col = printf("%s: %s", label, s); return; } if ((col + strlen(s)) > LINELENGTH) { (void)printf("\n\t"); col = printf("%s", s) + 8; return; } col += printf(" %s", s); } static const char * ccval(struct cchar *p, int c) { static char buf[5]; char *bp; if (p->sub == VMIN || p->sub == VTIME) { (void)snprintf(buf, sizeof(buf), "%d", c); return (buf); } if (c == _POSIX_VDISABLE) return (""); bp = buf; if (c & 0200) { *bp++ = 'M'; *bp++ = '-'; c &= 0177; } if (c == 0177) { *bp++ = '^'; *bp++ = '?'; } else if (c < 040) { *bp++ = '^'; *bp++ = c + '@'; } else *bp++ = c; *bp = '\0'; return (buf); } Index: head/sys/sys/ioctl_compat.h =================================================================== --- head/sys/sys/ioctl_compat.h (revision 180558) +++ head/sys/sys/ioctl_compat.h (revision 180559) @@ -1,160 +1,152 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)ioctl_compat.h 8.4 (Berkeley) 1/21/94 * $FreeBSD$ */ #ifndef _SYS_IOCTL_COMPAT_H_ #define _SYS_IOCTL_COMPAT_H_ #ifdef _KERNEL struct tchars { char t_intrc; /* interrupt */ char t_quitc; /* quit */ char t_startc; /* start output */ char t_stopc; /* stop output */ char t_eofc; /* end-of-file */ char t_brkc; /* input delimiter (like nl) */ }; struct ltchars { char t_suspc; /* stop process signal */ char t_dsuspc; /* delayed stop process signal */ char t_rprntc; /* reprint line */ char t_flushc; /* flush output (toggles) */ char t_werasc; /* word erase */ char t_lnextc; /* literal next character */ }; /* * Structure for TIOCGETP and TIOCSETP ioctls. */ -#ifndef _SGTTYB_ -#define _SGTTYB_ struct sgttyb { char sg_ispeed; /* input speed */ char sg_ospeed; /* output speed */ char sg_erase; /* erase character */ char sg_kill; /* kill character */ short sg_flags; /* mode flags */ }; -#endif #define OTIOCGETD _IOR('t', 0, int) /* get line discipline */ #define OTIOCSETD _IOW('t', 1, int) /* set line discipline */ #define TIOCHPCL _IO('t', 2) /* hang up on last close */ #define TIOCGETP _IOR('t', 8,struct sgttyb)/* get parameters -- gtty */ #define TIOCSETP _IOW('t', 9,struct sgttyb)/* set parameters -- stty */ #define TIOCSETN _IOW('t',10,struct sgttyb)/* as above, but no flushtty*/ #define TIOCSETC _IOW('t',17,struct tchars)/* set special characters */ #define TIOCGETC _IOR('t',18,struct tchars)/* get special characters */ #define TANDEM 0x00000001 /* send stopc on out q full */ #define CBREAK 0x00000002 /* half-cooked mode */ #define LCASE 0x00000004 /* simulate lower case */ #define ECHO 0x00000008 /* echo input */ #define CRMOD 0x00000010 /* map \r to \r\n on output */ #define RAW 0x00000020 /* no i/o processing */ #define ODDP 0x00000040 /* get/send odd parity */ #define EVENP 0x00000080 /* get/send even parity */ #define ANYP 0x000000c0 /* get any parity/send none */ #define NLDELAY 0x00000300 /* \n delay */ #define NL0 0x00000000 #define NL1 0x00000100 /* tty 37 */ #define NL2 0x00000200 /* vt05 */ #define NL3 0x00000300 #define TBDELAY 0x00000c00 /* horizontal tab delay */ #define TAB0 0x00000000 #define TAB1 0x00000400 /* tty 37 */ #define TAB2 0x00000800 #define XTABS 0x00000c00 /* expand tabs on output */ #define CRDELAY 0x00003000 /* \r delay */ #define CR0 0x00000000 #define CR1 0x00001000 /* tn 300 */ #define CR2 0x00002000 /* tty 37 */ #define CR3 0x00003000 /* concept 100 */ #define VTDELAY 0x00004000 /* vertical tab delay */ #define FF0 0x00000000 #define FF1 0x00004000 /* tty 37 */ #define BSDELAY 0x00008000 /* \b delay */ #define BS0 0x00000000 #define BS1 0x00008000 #define ALLDELAY (NLDELAY|TBDELAY|CRDELAY|VTDELAY|BSDELAY) #define CRTBS 0x00010000 /* do backspacing for crt */ #define PRTERA 0x00020000 /* \ ... / erase */ #define CRTERA 0x00040000 /* " \b " to wipe out char */ #define TILDE 0x00080000 /* hazeltine tilde kludge */ #define MDMBUF 0x00100000 /*start/stop output on carrier*/ #define LITOUT 0x00200000 /* literal output */ #define TOSTOP 0x00400000 /*SIGSTOP on background output*/ #define FLUSHO 0x00800000 /* flush output to terminal */ #define NOHANG 0x01000000 /* (no-op) was no SIGHUP on carrier drop */ #define L001000 0x02000000 #define CRTKIL 0x04000000 /* kill line with " \b " */ #define PASS8 0x08000000 #define CTLECH 0x10000000 /* echo control chars as ^X */ #define PENDIN 0x20000000 /* tp->t_rawq needs reread */ #define DECCTQ 0x40000000 /* only ^Q starts after ^S */ #define NOFLSH 0x80000000 /* no output flush on signal */ #define TIOCLBIS _IOW('t', 127, int) /* bis local mode bits */ #define TIOCLBIC _IOW('t', 126, int) /* bic local mode bits */ #define TIOCLSET _IOW('t', 125, int) /* set entire local mode word */ #define TIOCLGET _IOR('t', 124, int) /* get local modes */ #define LCRTBS (CRTBS>>16) #define LPRTERA (PRTERA>>16) #define LCRTERA (CRTERA>>16) #define LTILDE (TILDE>>16) #define LMDMBUF (MDMBUF>>16) #define LLITOUT (LITOUT>>16) #define LTOSTOP (TOSTOP>>16) #define LFLUSHO (FLUSHO>>16) #define LNOHANG (NOHANG>>16) #define LCRTKIL (CRTKIL>>16) #define LPASS8 (PASS8>>16) #define LCTLECH (CTLECH>>16) #define LPENDIN (PENDIN>>16) #define LDECCTQ (DECCTQ>>16) #define LNOFLSH (NOFLSH>>16) #define TIOCSLTC _IOW('t',117,struct ltchars)/* set local special chars*/ #define TIOCGLTC _IOR('t',116,struct ltchars)/* get local special chars*/ #define OTIOCCONS _IO('t', 98) /* for hp300 -- sans int arg */ #endif /* _KERNEL */ - -/* XXX publish these so stty(1) can still report them */ -#define OTTYDISC 0 -#define NETLDISC 1 -#define NTTYDISC 2 #endif /* !_SYS_IOCTL_COMPAT_H_ */ Index: head/usr.sbin/pstat/pstat.c =================================================================== --- head/usr.sbin/pstat/pstat.c (revision 180558) +++ head/usr.sbin/pstat/pstat.c (revision 180559) @@ -1,615 +1,611 @@ /*- * Copyright (c) 1980, 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * Copyright (c) 2002 Networks Associates Technologies, Inc. * All rights reserved. * * Portions of this software were developed for the FreeBSD Project by * ThinkSec AS and NAI Labs, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 * ("CBOSS"), as part of the DARPA CHATS research program. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static const char copyright[] = "@(#) Copyright (c) 1980, 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include -#include /* XXX NTTYDISC is too well hidden */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include enum { NL_CONSTTY, NL_MAXFILES, NL_NFILES, NL_TTY_LIST }; static struct nlist nl[] = { { .n_name = "_constty" }, { .n_name = "_maxfiles" }, { .n_name = "_openfiles" }, { .n_name = "_tty_list" }, { .n_name = "" } }; static int humanflag; static int usenumflag; static int totalflag; static int swapflag; static char *nlistf; static char *memf; static kvm_t *kd; static char *usagestr; static void filemode(void); static int getfiles(char **, size_t *); static void swapmode(void); static void ttymode(void); static void ttyprt(struct xtty *); static void usage(void); int main(int argc, char *argv[]) { int ch, i, quit, ret; int fileflag, ttyflag; char buf[_POSIX2_LINE_MAX],*opts; fileflag = swapflag = ttyflag = 0; /* We will behave like good old swapinfo if thus invoked */ opts = strrchr(argv[0], '/'); if (opts) opts++; else opts = argv[0]; if (!strcmp(opts, "swapinfo")) { swapflag = 1; opts = "ghkmM:N:"; usagestr = "swapinfo [-ghkm] [-M core [-N system]]"; } else { opts = "TM:N:fghkmnst"; usagestr = "pstat [-Tfghkmnst] [-M core [-N system]]"; } while ((ch = getopt(argc, argv, opts)) != -1) switch (ch) { case 'f': fileflag = 1; break; case 'g': setenv("BLOCKSIZE", "1G", 1); break; case 'h': humanflag = 1; break; case 'k': setenv("BLOCKSIZE", "1K", 1); break; case 'm': setenv("BLOCKSIZE", "1M", 1); break; case 'M': memf = optarg; break; case 'N': nlistf = optarg; break; case 'n': usenumflag = 1; break; case 's': ++swapflag; break; case 'T': totalflag = 1; break; case 't': ttyflag = 1; break; default: usage(); } argc -= optind; argv += optind; if (memf != NULL) { kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf); if (kd == NULL) errx(1, "kvm_openfiles: %s", buf); if ((ret = kvm_nlist(kd, nl)) != 0) { if (ret == -1) errx(1, "kvm_nlist: %s", kvm_geterr(kd)); quit = 0; for (i = 0; nl[i].n_name[0] != '\0'; ++i) if (nl[i].n_value == 0) { quit = 1; warnx("undefined symbol: %s", nl[i].n_name); } if (quit) exit(1); } } if (!(fileflag | ttyflag | swapflag | totalflag)) usage(); if (fileflag || totalflag) filemode(); if (ttyflag) ttymode(); if (swapflag || totalflag) swapmode(); exit (0); } static void usage(void) { fprintf(stderr, "usage: %s\n", usagestr); 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"; static void ttymode_kvm(void) { TAILQ_HEAD(, tty) tl; struct tty *tp, tty; struct xtty xt; (void)printf("%s", hdr); bzero(&xt, sizeof xt); xt.xt_size = sizeof xt; if (kvm_read(kd, nl[NL_TTY_LIST].n_value, &tl, sizeof tl) != sizeof tl) errx(1, "kvm_read(): %s", kvm_geterr(kd)); tp = TAILQ_FIRST(&tl); while (tp != NULL) { if (kvm_read(kd, (u_long)tp, &tty, sizeof tty) != sizeof tty) errx(1, "kvm_read(): %s", kvm_geterr(kd)); xt.xt_rawcc = tty.t_rawq.c_cc; xt.xt_cancc = tty.t_canq.c_cc; xt.xt_outcc = tty.t_outq.c_cc; #define XT_COPY(field) xt.xt_##field = tty.t_##field XT_COPY(line); XT_COPY(state); XT_COPY(column); XT_COPY(ihiwat); XT_COPY(ilowat); XT_COPY(ohiwat); XT_COPY(olowat); #undef XT_COPY ttyprt(&xt); tp = TAILQ_NEXT(&tty, t_list); } } static void ttymode_sysctl(void) { struct xtty *xt, *end; void *xttys; size_t len; (void)printf("%s", hdr); if ((xttys = malloc(len = sizeof *xt)) == NULL) err(1, "malloc()"); while (sysctlbyname("kern.ttys", xttys, &len, 0, 0) == -1) { if (errno != ENOMEM) err(1, "sysctlbyname()"); len *= 2; if ((xttys = realloc(xttys, len)) == NULL) err(1, "realloc()"); } if (len > 0) { end = (struct xtty *)((char *)xttys + len); for (xt = xttys; xt < end; xt++) ttyprt(xt); } } static void ttymode(void) { if (kd != NULL) ttymode_kvm(); else ttymode_sysctl(); } static struct { int flag; char val; } ttystates[] = { #ifdef TS_WOPEN { TS_WOPEN, 'W'}, #endif { TS_ISOPEN, 'O'}, { TS_CARR_ON, 'C'}, #ifdef TS_CONNECTED { TS_CONNECTED, 'c'}, #endif { TS_TIMEOUT, 'T'}, { TS_FLUSH, 'F'}, { TS_BUSY, 'B'}, #ifdef TS_ASLEEP { TS_ASLEEP, 'A'}, #endif #ifdef TS_SO_OLOWAT { TS_SO_OLOWAT, 'A'}, #endif #ifdef TS_SO_OCOMPLETE { TS_SO_OCOMPLETE, 'a'}, #endif { TS_XCLUDE, 'X'}, { TS_TTSTOP, 'S'}, #ifdef TS_CAR_OFLOW { TS_CAR_OFLOW, 'm'}, #endif #ifdef TS_CTS_OFLOW { TS_CTS_OFLOW, 'o'}, #endif #ifdef TS_DSR_OFLOW { TS_DSR_OFLOW, 'd'}, #endif { TS_TBLOCK, 'K'}, { TS_ASYNC, 'Y'}, { TS_BKSL, 'D'}, { TS_ERASE, 'E'}, { TS_LNCH, 'L'}, { TS_TYPEN, 'P'}, { TS_CNTTB, 'N'}, #ifdef TS_CAN_BYPASS_L_RINT { TS_CAN_BYPASS_L_RINT, 'l'}, #endif #ifdef TS_SNOOP { TS_SNOOP, 's'}, #endif #ifdef TS_ZOMBIE { TS_ZOMBIE, 'Z'}, #endif { 0, '\0'}, }; static void ttyprt(struct xtty *xt) { int i, j; char *name, state[20]; if (xt->xt_size != sizeof *xt) errx(1, "struct xtty size mismatch"); if (usenumflag || xt->xt_dev == 0 || (name = devname(xt->xt_dev, S_IFCHR)) == NULL) 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); (void)printf("%3ld %5d %5d %4d %3d %7d ", xt->xt_outcc, xt->xt_ihiwat, xt->xt_ilowat, xt->xt_ohiwat, xt->xt_olowat, xt->xt_column); for (i = j = 0; ttystates[i].flag; i++) if (xt->xt_state & ttystates[i].flag) state[j++] = ttystates[i].val; if (j == 0) state[j++] = '-'; state[j] = '\0'; (void)printf("%-6s %8d", state, xt->xt_sid); (void)printf("%6d ", xt->xt_pgid); switch (xt->xt_line) { case TTYDISC: (void)printf("term\n"); - break; - case NTTYDISC: - (void)printf("ntty\n"); break; case SLIPDISC: (void)printf("slip\n"); break; case PPPDISC: (void)printf("ppp\n"); break; default: (void)printf("%d\n", xt->xt_line); break; } } static void filemode(void) { struct xfile *fp; char *buf, flagbuf[16], *fbp; int maxf, openf; size_t len; 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, &maxf, sizeof maxf) != sizeof maxf || kvm_read(kd, nl[NL_NFILES].n_value, &openf, sizeof openf) != sizeof openf) errx(1, "kvm_read(): %s", kvm_geterr(kd)); } else { len = sizeof(int); if (sysctlbyname("kern.maxfiles", &maxf, &len, 0, 0) == -1 || sysctlbyname("kern.openfiles", &openf, &len, 0, 0) == -1) err(1, "sysctlbyname()"); } if (totalflag) { (void)printf("%3d/%3d files\n", openf, maxf); return; } if (getfiles(&buf, &len) == -1) return; openf = len / sizeof *fp; (void)printf("%d/%d open files\n", openf, maxf); 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 ((size_t)fp->xf_type >= sizeof(dtypes) / sizeof(dtypes[0])) continue; (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'; if (fp->xf_flag & FWRITE) *fbp++ = 'W'; if (fp->xf_flag & FAPPEND) *fbp++ = 'A'; if (fp->xf_flag & FASYNC) *fbp++ = 'I'; *fbp = '\0'; (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); } static int getfiles(char **abuf, size_t *alen) { size_t len; int mib[2]; char *buf; /* * XXX * Add emulation of KINFO_FILE here. */ if (kd != NULL) errx(1, "files on dead kernel, not implemented"); mib[0] = CTL_KERN; mib[1] = KERN_FILE; if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) { warn("sysctl: KERN_FILE"); return (-1); } if ((buf = malloc(len)) == NULL) errx(1, "malloc"); if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) { warn("sysctl: KERN_FILE"); return (-1); } *abuf = buf; *alen = len; return (0); } /* * swapmode is based on a program called swapinfo written * by Kevin Lahey . */ #define CONVERT(v) ((int64_t)(v) * pagesize / blocksize) static struct kvm_swap swtot; static int nswdev; static void print_swap_header(void) { int hlen; long blocksize; const char *header; header = getbsize(&hlen, &blocksize); if (totalflag == 0) (void)printf("%-15s %*s %8s %8s %8s\n", "Device", hlen, header, "Used", "Avail", "Capacity"); } static void print_swap_line(const char *devname, intmax_t nblks, intmax_t bused, intmax_t bavail, float bpercent) { char usedbuf[5]; char availbuf[5]; int hlen, pagesize; long blocksize; pagesize = getpagesize(); getbsize(&hlen, &blocksize); printf("%-15s %*jd ", devname, hlen, CONVERT(nblks)); if (humanflag) { humanize_number(usedbuf, sizeof(usedbuf), CONVERT(blocksize * bused), "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); humanize_number(availbuf, sizeof(availbuf), CONVERT(blocksize * bavail), "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent); } else { printf("%8jd %8jd %5.0f%%\n", (intmax_t)CONVERT(bused), (intmax_t)CONVERT(bavail), bpercent); } } static void print_swap(struct kvm_swap *ksw) { swtot.ksw_total += ksw->ksw_total; swtot.ksw_used += ksw->ksw_used; ++nswdev; if (totalflag == 0) print_swap_line(ksw->ksw_devname, ksw->ksw_total, ksw->ksw_used, ksw->ksw_total - ksw->ksw_used, (ksw->ksw_used * 100.0) / ksw->ksw_total); } static void print_swap_total(void) { int hlen, pagesize; long blocksize; pagesize = getpagesize(); getbsize(&hlen, &blocksize); if (totalflag) { blocksize = 1024 * 1024; (void)printf("%jdM/%jdM swap space\n", CONVERT(swtot.ksw_used), CONVERT(swtot.ksw_total)); } else if (nswdev > 1) { print_swap_line("Total", swtot.ksw_total, swtot.ksw_used, swtot.ksw_total - swtot.ksw_used, (swtot.ksw_used * 100.0) / swtot.ksw_total); } } static void swapmode_kvm(void) { struct kvm_swap kswap[16]; int i, n; n = kvm_getswapinfo(kd, kswap, sizeof kswap / sizeof kswap[0], SWIF_DEV_PREFIX); print_swap_header(); for (i = 0; i < n; ++i) print_swap(&kswap[i]); print_swap_total(); } static void swapmode_sysctl(void) { struct kvm_swap ksw; struct xswdev xsw; size_t mibsize, size; int mib[16], n; print_swap_header(); mibsize = sizeof mib / sizeof mib[0]; if (sysctlnametomib("vm.swap_info", mib, &mibsize) == -1) err(1, "sysctlnametomib()"); for (n = 0; ; ++n) { mib[mibsize] = n; size = sizeof xsw; if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, 0) == -1) break; if (xsw.xsw_version != XSWDEV_VERSION) errx(1, "xswdev version mismatch"); if (xsw.xsw_dev == NODEV) snprintf(ksw.ksw_devname, sizeof ksw.ksw_devname, ""); else snprintf(ksw.ksw_devname, sizeof ksw.ksw_devname, "/dev/%s", devname(xsw.xsw_dev, S_IFCHR)); ksw.ksw_used = xsw.xsw_used; ksw.ksw_total = xsw.xsw_nblks; ksw.ksw_flags = xsw.xsw_flags; print_swap(&ksw); } if (errno != ENOENT) err(1, "sysctl()"); print_swap_total(); } static void swapmode(void) { if (kd != NULL) swapmode_kvm(); else swapmode_sysctl(); }