4 * cc -I/usr/src/sys h2dio.c -o ~/bin/h2dio -lkvm
8 * Copyright (c) 2018 The DragonFly Project. All rights reserved.
10 * This code is derived from software contributed to The DragonFly Project
11 * by Matthew Dillon <dillon@backplane.com>
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/types.h>
40 #include <vfs/hammer2/hammer2.h>
43 #include <vm/vm_page.h>
44 #include <vm/vm_kern.h>
45 #include <vm/swap_pager.h>
46 #include <vm/vnode_pager.h>
56 static void h2dioscan(kvm_t
*kd
, int tab
, uintptr_t cp
);
57 static void kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
);
68 main(int ac
, char **av
)
71 const char *corefile
= NULL
;
72 const char *sysfile
= NULL
;
78 while ((ch
= getopt(ac
, av
, "M:N:")) != -1) {
87 fprintf(stderr
, "%s [-M core] [-N system]\n", av
[0]);
94 if ((kd
= kvm_open(sysfile
, corefile
, NULL
, O_RDONLY
, "kvm:")) == NULL
) {
99 if (kvm_nlist(kd
, Nl
) != 0) {
103 kkread(kd
, Nl
[0].n_value
, &nch
, sizeof(nch
));
104 kkread(kd
, Nl
[1].n_value
, &list
, sizeof(list
));
107 base
= strtoul(av
[0], NULL
, 0);
109 kkread(kd
, base
, &hmp
, sizeof(hmp
));
110 cp
= (uintptr_t)hmp
.iotree
.rbh_root
;
112 h2dioscan(kd
, 4, cp
);
119 h2dioscan(kvm_t
*kd
, int tab
, uintptr_t cp
)
123 kkread(kd
, cp
, &dio
, sizeof(dio
));
124 if (dio
.rbnode
.rbe_left
)
125 h2dioscan(kd
, tab
, (uintptr_t)dio
.rbnode
.rbe_left
);
126 printf("%*.*s dio %p pbase=%016lx refs=%08x "
127 "bp=%p psize=%d ticks=%d err=%d\n",
128 tab
, tab
, "", (void *)cp
, dio
.pbase
, dio
.refs
,
129 dio
.bp
, dio
.psize
, dio
.ticks
, dio
.error
);
130 if (dio
.rbnode
.rbe_right
)
131 h2dioscan(kd
, tab
, (uintptr_t)dio
.rbnode
.rbe_right
);
135 kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
)
137 if (kvm_read(kd
, addr
, buf
, nbytes
) != nbytes
) {