Blob


1 #include "stdinc.h"
2 #include "dat.h"
3 #include "fns.h"
4 #include <bio.h>
6 Biobuf bout;
8 static void
9 pie(IEntry *ie)
10 {
11 Bprint(&bout, "%22lld %V %3d %5d\n",
12 ie->ia.addr, ie->score, ie->ia.type, ie->ia.size);
13 }
15 void
16 usage(void)
17 {
18 fprint(2, "usage: printindex [-B blockcachesize] config [isectname...]\n");
19 threadexitsall(0);
20 }
22 Config conf;
24 int
25 shoulddump(char *name, int argc, char **argv)
26 {
27 int i;
29 if(argc == 0)
30 return 1;
31 for(i=0; i<argc; i++)
32 if(strcmp(name, argv[i]) == 0)
33 return 1;
34 return 0;
35 }
37 void
38 dumpisect(ISect *is)
39 {
40 int j;
41 uchar *buf;
42 u32int i;
43 u64int off;
44 IBucket ib;
45 IEntry ie;
47 buf = emalloc(is->blocksize);
48 for(i=0; i<is->blocks; i++){
49 off = is->blockbase+(u64int)is->blocksize*i;
50 if(readpart(is->part, off, buf, is->blocksize) < 0)
51 fprint(2, "read %s at 0x%llux: %r\n", is->part->name, off);
52 else{
53 unpackibucket(&ib, buf, is->bucketmagic);
54 for(j=0; j<ib.n; j++){
55 unpackientry(&ie, &ib.data[j*IEntrySize]);
56 pie(&ie);
57 }
58 }
59 }
60 }
62 void
63 threadmain(int argc, char *argv[])
64 {
65 int i;
66 Index *ix;
67 u32int bcmem;
69 bcmem = 0;
70 ARGBEGIN{
71 case 'B':
72 bcmem = unittoull(ARGF());
73 break;
74 default:
75 usage();
76 break;
77 }ARGEND
79 if(argc < 1)
80 usage();
82 fmtinstall('H', encodefmt);
84 if(initventi(argv[0], &conf) < 0)
85 sysfatal("can't init venti: %r");
87 if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
88 bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
89 if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
90 initdcache(bcmem);
92 ix = mainindex;
93 Binit(&bout, 1, OWRITE);
94 for(i=0; i<ix->nsects; i++)
95 if(shoulddump(ix->sects[i]->name, argc-1, argv+1))
96 dumpisect(ix->sects[i]);
97 Bterm(&bout);
98 threadexitsall(0);
99 }