4 * cc -I/usr/src/sys ttyinfo.c -o /usr/local/bin/ttyinfo -lkvm
9 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
11 * This code is derived from software contributed to The DragonFly Project
12 * by Matthew Dillon <dillon@backplane.com>
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
24 * 3. Neither the name of The DragonFly Project nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific, prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * $DragonFly: src/test/debug/ttyinfo.c,v 1.2 2004/10/08 18:32:58 dillon Exp $
44 #define _KERNEL_STRUCTURES_
45 #include <sys/param.h>
47 #include <sys/malloc.h>
48 #include <sys/signalvar.h>
49 #include <sys/vnode.h>
50 #include <sys/namecache.h>
52 #include <sys/clist.h>
55 #include <vm/vm_page.h>
56 #include <vm/vm_kern.h>
57 #include <vm/swap_pager.h>
58 #include <vm/vnode_pager.h>
76 static void kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
);
77 static int scanfree(kvm_t
*kd
, struct cblock
*cfree
);
80 main(int ac
, char **av
)
89 const char *corefile
= NULL
;
90 const char *sysfile
= NULL
;
92 while ((ch
= getopt(ac
, av
, "M:N:")) != -1) {
101 fprintf(stderr
, "%s [-M core] [-N system]\n", av
[0]);
106 if ((kd
= kvm_open(sysfile
, corefile
, NULL
, O_RDONLY
, "kvm:")) == NULL
) {
110 if (kvm_nlist(kd
, Nl
) != 0) {
114 kkread(kd
, Nl
[0].n_value
, &cfree
, sizeof(cfree
));
115 kkread(kd
, Nl
[1].n_value
, &cbytes
, sizeof(cbytes
));
116 kkread(kd
, Nl
[2].n_value
, &slush
, sizeof(slush
));
117 kkread(kd
, Nl
[3].n_value
, &totalcnt
, sizeof(totalcnt
));
118 count
= scanfree(kd
, cfree
);
119 printf("blksize %zd, freespc %d bytes, %zd blks (%d total), %d slush",
120 CBSIZE
, cbytes
, cbytes
/ CBSIZE
, totalcnt
, slush
);
122 printf(" [unaligned]\n");
124 printf(" [aligned]\n");
125 printf("freelist found to have %d blocks\n", count
);
130 scanfree(kvm_t
*kd
, struct cblock
*cfree
)
136 kkread(kd
, (u_long
)cfree
, &cb
, sizeof(cb
));
137 cfree
= cb
.c_head
.ch_next
;
144 kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
)
146 if (kvm_read(kd
, addr
, buf
, nbytes
) != nbytes
) {