void ttytype(struct tty *tty, const char *name, int type, int number, int indir) { struct tty *tp; int ntty; struct tty **ttyaddr; if (tty == NULL) return; KGET(number, ntty); printf("%d %s %s\n", ntty, name, (ntty == 1) ? "line" : "lines"); if (ntty > ttyspace) { ttyspace = ntty; if ((tty = realloc(tty, ttyspace * sizeof(*tty))) == NULL) errx(1, "realloc"); } if (indir) { KGET(type, ttyaddr); KGET2(ttyaddr, tty, (ssize_t)(ntty * sizeof(struct tty)), "tty structs"); } else { KGET1(type, tty, (ssize_t)(ntty * sizeof(struct tty)), "tty structs"); } printf("%s", hdr); for (tp = tty; tp < &tty[ntty]; tp++) ttyprt(tp, tp - tty); }
/* * simulate what a running kernel does in in kinfo_vnode */ struct e_vnode * kinfo_vnodes(int *avnodes) { struct mntlist mountlist; struct mount *mp, mounth, *mp_next; struct vnode *vp, vnode, *vp_next; char *vbuf, *evbuf, *bp; int num, numvnodes; #define VPTRSZ sizeof(struct vnode *) #define VNODESZ sizeof(struct vnode) KGET(NL_NUMVNODES, numvnodes); if ((vbuf = malloc((numvnodes + 20) * (VPTRSZ + VNODESZ))) == NULL) errx(1, "malloc"); bp = vbuf; evbuf = vbuf + (numvnodes + 20) * (VPTRSZ + VNODESZ); KGET(NL_MOUNTLIST, mountlist); for (num = 0, mp = TAILQ_FIRST(&mountlist); ; mp = mp_next) { KGET2(mp, &mounth, sizeof(mounth), "mount entry"); mp_next = TAILQ_NEXT(&mounth, mnt_list); for (vp = TAILQ_FIRST(&mounth.mnt_nvnodelist); vp != NULL; vp = vp_next) { KGET2(vp, &vnode, sizeof(vnode), "vnode"); vp_next = TAILQ_NEXT(&vnode, v_nmntvnodes); if ((bp + VPTRSZ + VNODESZ) > evbuf) /* XXX - should realloc */ errx(1, "no more room for vnodes"); memmove(bp, &vp, VPTRSZ); bp += VPTRSZ; memmove(bp, &vnode, VNODESZ); bp += VNODESZ; num++; } if (mp == TAILQ_LAST(&mountlist, mntlist)) break; } *avnodes = num; return ((struct e_vnode *)vbuf); }
void ttyprt(struct tty *tp, int line) { int i, j; pid_t pgid; char *name, state[20]; dev_t dev; dev = (uintptr_t)tp->t_dev & 0xffff; /* XXX t_dev is really dev_t */ if (usenumflag || dev == 0 || (name = devname(dev, S_IFCHR)) == NULL) printf("%7d ", line); else printf("%7s ", name); printf("%2d %3d ", tp->t_rawq.c_cc, tp->t_canq.c_cc); printf("%3d %5d %5d %4d %3d %7d ", tp->t_outq.c_cc, tp->t_ihiwat, tp->t_ilowat, tp->t_ohiwat, tp->t_olowat, tp->t_column); for (i = j = 0; ttystates[i].flag; i++) if (tp->t_state&ttystates[i].flag) state[j++] = ttystates[i].val; if (j == 0) state[j++] = '-'; state[j] = '\0'; printf("%-6s %8lx", state, (u_long)(void *)tp->t_session); pgid = 0; if (tp->t_pgrp != NULL) KGET2(&tp->t_pgrp->pg_id, &pgid, sizeof(pid_t), "pgid"); printf("%6d ", pgid); switch (tp->t_line) { case TTYDISC: printf("term\n"); break; case NTTYDISC: printf("ntty\n"); break; case SLIPDISC: printf("slip\n"); break; case PPPDISC: printf("ppp\n"); break; default: printf("%d\n", tp->t_line); break; } }
int kvm_getswapinfo_kvm(kvm_t *kd, struct kvm_swap *swap_ary, int swap_max, int flags) { int i, ttl; TAILQ_HEAD(, swdevt) swtailq; struct swdevt *sp, swinfo; struct kvm_swap tot; if (!nlist_init(kd)) return (-1); bzero(&tot, sizeof(tot)); KGET(NL_SWTAILQ, &swtailq); sp = TAILQ_FIRST(&swtailq); for (i = 0; sp != NULL; i++) { KGET2(sp, &swinfo, "swinfo"); ttl = swinfo.sw_nblks - dmmax; if (i < swap_max - 1) { bzero(&swap_ary[i], sizeof(swap_ary[i])); swap_ary[i].ksw_total = ttl; swap_ary[i].ksw_used = swinfo.sw_used; swap_ary[i].ksw_flags = swinfo.sw_flags; GETSWDEVNAME(swinfo.sw_dev, swap_ary[i].ksw_devname, flags); } tot.ksw_total += ttl; tot.ksw_used += swinfo.sw_used; sp = TAILQ_NEXT(&swinfo, sw_list); } if (i >= swap_max) i = swap_max - 1; if (i >= 0) swap_ary[i] = tot; return(i); }