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
);
79 main(int ac
, char **av
)
88 const char *corefile
= NULL
;
89 const char *sysfile
= NULL
;
91 while ((ch
= getopt(ac
, av
, "M:N:")) != -1) {
100 fprintf(stderr
, "%s [-M core] [-N system]\n", av
[0]);
105 if ((kd
= kvm_open(sysfile
, corefile
, NULL
, O_RDONLY
, "kvm:")) == NULL
) {
109 if (kvm_nlist(kd
, Nl
) != 0) {
113 kkread(kd
, Nl
[0].n_value
, &cfree
, sizeof(cfree
));
114 kkread(kd
, Nl
[1].n_value
, &cbytes
, sizeof(cbytes
));
115 kkread(kd
, Nl
[2].n_value
, &slush
, sizeof(slush
));
116 kkread(kd
, Nl
[3].n_value
, &totalcnt
, sizeof(totalcnt
));
117 count
= scanfree(kd
, cfree
);
118 printf("blksize %d, freespc %d bytes, %d blks (%d total), %d slush",
119 CBSIZE
, cbytes
, cbytes
/ CBSIZE
, totalcnt
, slush
);
121 printf(" [unaligned]\n");
123 printf(" [aligned]\n");
124 printf("freelist found to have %d blocks\n", count
);
129 scanfree(kvm_t
*kd
, struct cblock
*cfree
)
135 kkread(kd
, (u_long
)cfree
, &cb
, sizeof(cb
));
136 cfree
= cb
.c_head
.ch_next
;
143 kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
)
145 if (kvm_read(kd
, addr
, buf
, nbytes
) != nbytes
) {