6 checkbucket(Index *ix, u32int buck, IBucket *ib)
14 is = findibucket(ix, buck, &buck);
15 eb = getdblock(is->part, is->blockbase + ((u64int)buck << is->blocklog), 1);
18 unpackibucket(&eib, eb->data);
22 for(i = 0; i < ib->n; i++){
24 c = ientrycmp(&ib->data[i * IEntrySize], &eib.data[ei * IEntrySize]);
26 unpackientry(&ie, &ib->data[i * IEntrySize]);
27 unpackientry(&eie, &eib.data[ei * IEntrySize]);
28 if(iaddrcmp(&ie.ia, &eie.ia) != 0){
29 fprint(2, "bad entry in index for score=%V\n", &ib->data[i * IEntrySize]);
30 fprint(2, "\taddr=%lld type=%d size=%d blocks=%d\n",
31 ie.ia.addr, ie.ia.type, ie.ia.size, ie.ia.blocks);
32 fprint(2, "\taddr=%lld type=%d size=%d blocks=%d\n",
33 eie.ia.addr, eie.ia.type, eie.ia.size, eie.ia.blocks);
41 fprint(2, "spurious entry in index for score=%V type=%d\n",
42 &eib.data[ei * IEntrySize], eib.data[ei * IEntrySize + IEntryTypeOff]);
46 fprint(2, "missing entry in index for score=%V type=%d\n",
47 &ib->data[i * IEntrySize], ib->data[i * IEntrySize + IEntryTypeOff]);
51 for(; ei < eib.n; ei++){
52 if(1) fprint(2, "spurious entry in index for score=%V; found %d entries expected %d\n",
53 &eib.data[ei * IEntrySize], eib.n, ib->n);
62 checkindex(Index *ix, Part *part, u64int off, u64int clumps, int zero)
71 //ZZZ make buffer size configurable
72 b = alloczblock(ix->blocksize, 0);
73 z = alloczblock(ix->blocksize, 1);
74 ies = initiestream(part, off, clumps, 64*1024);
75 if(b == nil || z == nil || ies == nil){
87 buck = buildbucket(ix, ies, &ib);
90 for(; next != buck; next++){
91 if(next == ix->buckets){
93 fprint(2, "bucket out of range\n");
96 bok = checkbucket(ix, next, &zib);
98 fprint(2, "bad bucket=%d found: %r\n", next);
103 if(buck >= ix->buckets){
106 fprint(2, "bucket out of range\n");
110 bok = checkbucket(ix, buck, &ib);
112 fprint(2, "bad bucket found=%lld: %r\n", found);
118 fprint(2, "found %lld entries in sorted list\n", found);
128 fprint(2, "usage: checkindex [-f] [-B blockcachesize] config tmp\n");
133 threadmain(int argc, char *argv[])
145 bcmem = unittoull(ARGF());
164 if(initventi(argv[0]) < 0)
165 sysfatal("can't init venti: %r");
167 if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
168 bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
169 fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
172 part = initpart(argv[1], 1);
174 sysfatal("can't initialize temporary partition: %r");
176 clumps = sortrawientries(mainindex, part, &base);
178 sysfatal("can't build sorted index: %r");
179 fprint(2, "found and sorted index entries for clumps=%lld at %lld\n", clumps, base);
180 checkindex(mainindex, part, base, clumps, !skipz);