1 /* $FreeBSD: src/tools/diag/dumpvfscache/dumpvfscache.c,v 1.1.6.1 2001/03/05 12:17:00 kris Exp $ */
2 /* $DragonFly: src/tools/diag/dumpvfscache/dumpvfscache.c,v 1.2 2003/06/17 04:29:11 dillon Exp $ */
10 #include <sys/namei.h>
11 #include <sys/param.h>
13 #include <sys/vnode.h>
14 /*----------------------------------*/
15 static u_int crc16_table
[16] = {
16 0x0000, 0xCC01, 0xD801, 0x1400,
17 0xF001, 0x3C00, 0x2800, 0xE401,
18 0xA001, 0x6C00, 0x7800, 0xB401,
19 0x5000, 0x9C01, 0x8801, 0x4400
23 wlpsacrc(u_char
*buf
, u_int len
)
28 for (i
= 0; i
< len
; i
++, buf
++) {
30 r1
= crc16_table
[crc
& 0xF];
31 crc
= (crc
>> 4) & 0x0FFF;
32 crc
= crc
^ r1
^ crc16_table
[*buf
& 0xF];
35 r1
= crc16_table
[crc
& 0xF];
36 crc
= (crc
>> 4) & 0x0FFF;
37 crc
= crc
^ r1
^ crc16_table
[(*buf
>> 4) & 0xF];
42 /*----------------------------------*/
54 main(int argc
, char **argv
)
56 int nchash
, i
, j
, k
, kn
;
59 LIST_HEAD(nchashhead
, namecache
) *nchashtbl
;
63 kvm_t
*kvm
= kvm_open(0, 0, 0, O_RDONLY
, 0);
65 printf("kvm: %p\n", kvm
);
66 printf("kvm_nlist: %d\n", kvm_nlist(kvm
, nl
));
67 kvm_read(kvm
, nl
[0].n_value
, &nchash
, sizeof nchash
);
69 nchashtbl
= malloc(nchash
* sizeof *nchashtbl
);
70 nc
= malloc(sizeof *nc
+ 400);
71 newbucket
= malloc(nchash
* sizeof (int));
72 memset(newbucket
, 0, nchash
* sizeof (int));
73 kvm_read(kvm
, nl
[1].n_value
, &p
, sizeof p
);
74 kvm_read(kvm
, p
, nchashtbl
, nchash
* sizeof *nchashtbl
);
75 for (i
=0; i
< nchash
; i
++) {
80 p
= (u_long
)LIST_FIRST(nchashtbl
+i
);
83 kvm_read(kvm
, p
, nc
, sizeof *nc
+ 400);
84 kvm_read(kvm
, (u_long
)nc
->nc_dvp
, &vn
, sizeof vn
);
85 nc
->nc_name
[nc
->nc_nlen
] = '\0';
86 for (j
=k
=kn
=0;nc
->nc_name
[j
];j
++) {
94 kn
= wlpsacrc(nc
->nc_name
,nc
->nc_nlen
);
96 /* kn += (u_long)vn.v_data >> 8; */
97 /* kn += (u_long)nc->nc_dvp >> 7; */
102 printf("%4d dvp %08x hash %08x vp %08x id %08x name <%s>\n",
103 i
,nc
->nc_dvp
, k
, nc
->nc_vp
, vn
.v_id
, nc
->nc_name
);
105 p
= (u_long
)LIST_NEXT(nc
, nc_hash
);
109 for (i
=0; i
< nchash
; i
++) {
110 histn
[newbucket
[i
]]++;
116 if (histo
[i
] || histn
[i
])
117 printf("H%02d %4d %4d / %4d %4d\n",i
,histo
[i
], p1
, histn
[i
], p2
);