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>
10 75d04888 2009-05-25 rsc // XXX What to do here?
11 71ce470a 2012-05-29 rsc VtMaxLumpSize = 65535,
20 a58f193d 2008-07-09 rsc fprint(2, "usage: venti/dump [-h host] score\n");
21 a58f193d 2008-07-09 rsc threadexitsall("usage");
25 a58f193d 2008-07-09 rsc char spaces[256];
28 a58f193d 2008-07-09 rsc dump(int indent, uchar *score, int type)
35 a58f193d 2008-07-09 rsc if(spaces[0] == 0)
36 a58f193d 2008-07-09 rsc memset(spaces, ' ', sizeof spaces-1);
38 a58f193d 2008-07-09 rsc buf = vtmallocz(VtMaxLumpSize);
39 a58f193d 2008-07-09 rsc if(memcmp(score, vtzeroscore, VtScoreSize) == 0)
42 a58f193d 2008-07-09 rsc n = vtread(z, score, type, buf, VtMaxLumpSize);
44 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*serror reading %V: %r\n", indent*4, spaces, score);
47 a58f193d 2008-07-09 rsc switch(type){
48 a58f193d 2008-07-09 rsc case VtRootType:
49 a58f193d 2008-07-09 rsc if(vtrootunpack(&root, buf) < 0){
50 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*serror unpacking root %V: %r\n", indent*4, spaces, score);
53 36c242dd 2011-11-08 rsc Bprint(&bout, "%.*s%V root name=%s type=%s prev=%V bsize=%ld\n",
54 a58f193d 2008-07-09 rsc indent*4, spaces, score, root.name, root.type, root.prev, root.blocksize);
55 a58f193d 2008-07-09 rsc dump(indent+1, root.score, VtDirType);
58 a58f193d 2008-07-09 rsc case VtDirType:
59 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V dir n=%d\n", indent*4, spaces, score, n);
60 a58f193d 2008-07-09 rsc for(i=0; i*VtEntrySize<n; i++){
61 a58f193d 2008-07-09 rsc if(vtentryunpack(&e, buf, i) < 0){
62 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%d: cannot unpack\n", indent+1, spaces, i);
65 36c242dd 2011-11-08 rsc Bprint(&bout, "%.*s%d: gen=%#lux psize=%ld dsize=%ld type=%d flags=%#x size=%llud score=%V\n",
66 a58f193d 2008-07-09 rsc (indent+1)*4, spaces, i, e.gen, e.psize, e.dsize, e.type, e.flags, e.size, e.score);
67 a58f193d 2008-07-09 rsc dump(indent+2, e.score, e.type);
71 a58f193d 2008-07-09 rsc case VtDataType:
72 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V data n=%d", indent*4, spaces, score, n);
73 a58f193d 2008-07-09 rsc for(i=0; i<n; i++){
74 a58f193d 2008-07-09 rsc if(i%16 == 0)
75 a58f193d 2008-07-09 rsc Bprint(&bout, "\n%.*s", (indent+1)*4, spaces);
76 a58f193d 2008-07-09 rsc Bprint(&bout, " %02x", buf[i]);
78 a58f193d 2008-07-09 rsc Bprint(&bout, "\n");
82 a58f193d 2008-07-09 rsc if(type >= VtDirType)
83 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V dir+%d\n", indent*4, spaces, score, type-VtDirType);
85 a58f193d 2008-07-09 rsc Bprint(&bout, "%.*s%V data+%d\n", indent*4, spaces, score, type-VtDirType);
86 a58f193d 2008-07-09 rsc for(i=0; i<n; i+=VtScoreSize)
87 a58f193d 2008-07-09 rsc dump(indent+1, buf+i, type-1);
96 a58f193d 2008-07-09 rsc threadmain(int argc, char *argv[])
99 a58f193d 2008-07-09 rsc uchar score[VtScoreSize];
101 a58f193d 2008-07-09 rsc char *prefix;
103 a58f193d 2008-07-09 rsc fmtinstall('F', vtfcallfmt);
104 a58f193d 2008-07-09 rsc fmtinstall('V', vtscorefmt);
108 a58f193d 2008-07-09 rsc host = EARGF(usage());
114 a58f193d 2008-07-09 rsc if(argc != 1)
117 a58f193d 2008-07-09 rsc if(vtparsescore(argv[0], &prefix, score) < 0)
118 a58f193d 2008-07-09 rsc sysfatal("could not parse score: %r");
120 a58f193d 2008-07-09 rsc buf = vtmallocz(VtMaxLumpSize);
121 a58f193d 2008-07-09 rsc z = vtdial(host);
122 a58f193d 2008-07-09 rsc if(z == nil)
123 a58f193d 2008-07-09 rsc sysfatal("dialing venti: %r");
124 a58f193d 2008-07-09 rsc if(vtconnect(z) < 0)
125 a58f193d 2008-07-09 rsc sysfatal("vtconnect src: %r");
127 a58f193d 2008-07-09 rsc for(type=0; type<VtMaxType; type++){
128 a58f193d 2008-07-09 rsc n = vtread(z, score, type, buf, VtMaxLumpSize);
130 a58f193d 2008-07-09 rsc goto havetype;
132 a58f193d 2008-07-09 rsc sysfatal("cannot find block %V", score);
135 a58f193d 2008-07-09 rsc Binit(&bout, 1, OWRITE);
136 a58f193d 2008-07-09 rsc dump(0, score, type);
137 a58f193d 2008-07-09 rsc Bflush(&bout);
138 a58f193d 2008-07-09 rsc threadexitsall(nil);