10 #include <sys/namei.h>
11 #include <sys/param.h>
12 #include <sys/queue.h>
14 #include <sys/vnode.h>
15 /*----------------------------------*/
16 static u_int crc16_table
[16] = {
17 0x0000, 0xCC01, 0xD801, 0x1400,
18 0xF001, 0x3C00, 0x2800, 0xE401,
19 0xA001, 0x6C00, 0x7800, 0xB401,
20 0x5000, 0x9C01, 0x8801, 0x4400
23 /* XXX Taken from sys/kern/vfs_cache.c */
25 LIST_ENTRY(namecache
) nc_hash
;
26 LIST_ENTRY(namecache
) nc_src
;
27 TAILQ_ENTRY(namecache
) nc_dst
;
36 wlpsacrc(u_char
*buf
, u_int len
)
41 for (i
= 0; i
< len
; i
++, buf
++) {
43 r1
= crc16_table
[crc
& 0xF];
44 crc
= (crc
>> 4) & 0x0FFF;
45 crc
= crc
^ r1
^ crc16_table
[*buf
& 0xF];
48 r1
= crc16_table
[crc
& 0xF];
49 crc
= (crc
>> 4) & 0x0FFF;
50 crc
= crc
^ r1
^ crc16_table
[(*buf
>> 4) & 0xF];
55 /*----------------------------------*/
67 main(int argc
, char **argv
)
69 int nchash
, i
, j
, k
, kn
;
72 LIST_HEAD(nchashhead
, namecache
) *nchashtbl
;
76 kvm_t
*kvm
= kvm_open(NULL
, NULL
, NULL
, O_RDONLY
, argv
[0]);
80 printf("kvm: %p\n", kvm
);
81 printf("kvm_nlist: %d\n", kvm_nlist(kvm
, nl
));
82 kvm_read(kvm
, nl
[0].n_value
, &nchash
, sizeof nchash
);
84 nchashtbl
= malloc(nchash
* sizeof *nchashtbl
);
85 nc
= malloc(sizeof *nc
+ NAME_MAX
);
86 newbucket
= malloc(nchash
* sizeof (int));
87 memset(newbucket
, 0, nchash
* sizeof (int));
88 kvm_read(kvm
, nl
[1].n_value
, &p
, sizeof p
);
89 kvm_read(kvm
, p
, nchashtbl
, nchash
* sizeof *nchashtbl
);
90 for (i
=0; i
< nchash
; i
++) {
95 p
= (u_long
)LIST_FIRST(nchashtbl
+i
);
98 kvm_read(kvm
, p
, nc
, sizeof *nc
+ NAME_MAX
);
99 kvm_read(kvm
, (u_long
)nc
->nc_dvp
, &vn
, sizeof vn
);
100 nc
->nc_name
[nc
->nc_nlen
] = '\0';
101 for (j
=k
=kn
=0;nc
->nc_name
[j
];j
++) {
109 kn
= wlpsacrc(nc
->nc_name
,nc
->nc_nlen
);
111 /* kn += (u_long)vn.v_data >> 8; */
112 /* kn += (u_long)nc->nc_dvp >> 7; */
117 printf("%4d dvp %08x hash %08x vp %08x id %08x name <%s>\n",
118 i
,nc
->nc_dvp
, k
, nc
->nc_vp
, vn
.v_id
, nc
->nc_name
);
120 p
= (u_long
)LIST_NEXT(nc
, nc_hash
);
124 for (i
=0; i
< nchash
; i
++) {
125 histn
[newbucket
[i
]]++;
131 if (histo
[i
] || histn
[i
])
132 printf("H%02d %4d %4d / %4d %4d\n",i
,histo
[i
], p1
, histn
[i
], p2
);