1 a58f193d 2008-07-09 rsc #include <u.h>
2 a58f193d 2008-07-09 rsc #include <libc.h>
3 a58f193d 2008-07-09 rsc #include <bio.h>
4 a58f193d 2008-07-09 rsc #include <venti.h>
5 a58f193d 2008-07-09 rsc #include <libsec.h>
6 a58f193d 2008-07-09 rsc #include <thread.h>
14 a58f193d 2008-07-09 rsc fprint(2, "usage: venti/dump [-h host] score\n");
15 a58f193d 2008-07-09 rsc threadexitsall("usage");
19 a58f193d 2008-07-09 rsc char spaces[256];
22 a58f193d 2008-07-09 rsc dump(int indent, uchar *score, int type)
29 a58f193d 2008-07-09 rsc if(spaces[0] == 0)
30 a58f193d 2008-07-09 rsc memset(spaces, ' ', sizeof spaces-1);
32 a58f193d 2008-07-09 rsc buf = vtmallocz(VtMaxLumpSize);
33 a58f193d 2008-07-09 rsc if(memcmp(score, vtzeroscore, VtScoreSize) == 0)
36 a58f193d 2008-07-09 rsc n = vtread(z, score, type, buf, VtMaxLumpSize);
38 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*serror reading %V: %r\n", indent*4, spaces, score);
41 a58f193d 2008-07-09 rsc switch(type){
42 a58f193d 2008-07-09 rsc case VtRootType:
43 a58f193d 2008-07-09 rsc if(vtrootunpack(&root, buf) < 0){
44 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*serror unpacking root %V: %r\n", indent*4, spaces, score);
47 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V root name=%s type=%s prev=%V bsize=%d\n",
48 a58f193d 2008-07-09 rsc indent*4, spaces, score, root.name, root.type, root.prev, root.blocksize);
49 a58f193d 2008-07-09 rsc dump(indent+1, root.score, VtDirType);
52 a58f193d 2008-07-09 rsc case VtDirType:
53 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V dir n=%d\n", indent*4, spaces, score, n);
54 a58f193d 2008-07-09 rsc for(i=0; i*VtEntrySize<n; i++){
55 a58f193d 2008-07-09 rsc if(vtentryunpack(&e, buf, i) < 0){
56 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%d: cannot unpack\n", indent+1, spaces, i);
59 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%d: gen=%#lux psize=%d dsize=%d type=%d flags=%#x size=%llud score=%V\n",
60 a58f193d 2008-07-09 rsc (indent+1)*4, spaces, i, e.gen, e.psize, e.dsize, e.type, e.flags, e.size, e.score);
61 a58f193d 2008-07-09 rsc dump(indent+2, e.score, e.type);
65 a58f193d 2008-07-09 rsc case VtDataType:
66 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V data n=%d", indent*4, spaces, score, n);
67 a58f193d 2008-07-09 rsc for(i=0; i<n; i++){
68 a58f193d 2008-07-09 rsc if(i%16 == 0)
69 a58f193d 2008-07-09 rsc Bprint(&bout, "\n%.*s", (indent+1)*4, spaces);
70 a58f193d 2008-07-09 rsc Bprint(&bout, " %02x", buf[i]);
72 a58f193d 2008-07-09 rsc Bprint(&bout, "\n");
76 a58f193d 2008-07-09 rsc if(type >= VtDirType)
77 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V dir+%d\n", indent*4, spaces, score, type-VtDirType);
79 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V data+%d\n", indent*4, spaces, score, type-VtDirType);
80 a58f193d 2008-07-09 rsc for(i=0; i<n; i+=VtScoreSize)
81 a58f193d 2008-07-09 rsc dump(indent+1, buf+i, type-1);
90 a58f193d 2008-07-09 rsc threadmain(int argc, char *argv[])
93 a58f193d 2008-07-09 rsc uchar score[VtScoreSize];
95 a58f193d 2008-07-09 rsc char *prefix;
97 a58f193d 2008-07-09 rsc fmtinstall('F', vtfcallfmt);
98 a58f193d 2008-07-09 rsc fmtinstall('V', vtscorefmt);
103 a58f193d 2008-07-09 rsc host = EARGF(usage());
109 a58f193d 2008-07-09 rsc if(argc != 1)
112 a58f193d 2008-07-09 rsc if(vtparsescore(argv[0], &prefix, score) < 0)
113 a58f193d 2008-07-09 rsc sysfatal("could not parse score: %r");
115 a58f193d 2008-07-09 rsc buf = vtmallocz(VtMaxLumpSize);
116 a58f193d 2008-07-09 rsc z = vtdial(host);
117 a58f193d 2008-07-09 rsc if(z == nil)
118 a58f193d 2008-07-09 rsc sysfatal("dialing venti: %r");
119 a58f193d 2008-07-09 rsc if(vtconnect(z) < 0)
120 a58f193d 2008-07-09 rsc sysfatal("vtconnect src: %r");
122 a58f193d 2008-07-09 rsc for(type=0; type<VtMaxType; type++){
123 a58f193d 2008-07-09 rsc n = vtread(z, score, type, buf, VtMaxLumpSize);
125 a58f193d 2008-07-09 rsc goto havetype;
127 a58f193d 2008-07-09 rsc sysfatal("cannot find block %V", score);
130 a58f193d 2008-07-09 rsc Binit(&bout, 1, OWRITE);
131 a58f193d 2008-07-09 rsc dump(0, score, type);
132 a58f193d 2008-07-09 rsc Bflush(&bout);
133 a58f193d 2008-07-09 rsc threadexitsall(nil);