コード例 #1
0
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);
}
コード例 #2
0
static int
nlist_init(kvm_t *kd)
{

	if (kvm_swap_nl_cached)
		return (1);

	if (kvm_nlist(kd, kvm_swap_nl) < 0)
		return (0);

	/* Required entries */
	if (kvm_swap_nl[NL_SWTAILQ].n_value == 0) {
		_kvm_err(kd, kd->program, "unable to find swtailq");
		return (0);
	}
		
	if (kvm_swap_nl[NL_DMMAX].n_value == 0) {
		_kvm_err(kd, kd->program, "unable to find dmmax");
		return (0);
	}

	/* Get globals, type of swap */
	KGET(NL_DMMAX, &dmmax);

	kvm_swap_nl_cached = 1;
	return (1);
}
コード例 #3
0
/*
 * 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);
}
コード例 #4
0
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);
}