commit a58f193d08c370efc6b008e807563f1f678c7b69 from: Russ Cox date: Wed Jul 09 15:42:09 2008 UTC venti: add venti/dump program commit - faf1fb6c7e14e95e54865b660db7501ed390ea9e commit + a58f193d08c370efc6b008e807563f1f678c7b69 blob - eb68babfbc63ab2b8d8a80ee6d5729dde448d0bd blob + b5cfff7e0f43842e5c72eb453aecbeb0441db1db --- src/cmd/venti/mkfile +++ src/cmd/venti/mkfile @@ -7,6 +7,7 @@ TARG=\ read\ sync\ write\ + dump\ BIN=$BIN/venti blob - /dev/null blob + 8481303a6fe49ce5122dc256d77481b929e7ae47 (mode 644) --- /dev/null +++ src/cmd/venti/dump.c @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#include + +VtConn *z; +char *host; + +void +usage(void) +{ + fprint(2, "usage: venti/dump [-h host] score\n"); + threadexitsall("usage"); +} + +Biobuf bout; +char spaces[256]; + +void +dump(int indent, uchar *score, int type) +{ + int i, n; + uchar *buf; + VtEntry e; + VtRoot root; + + if(spaces[0] == 0) + memset(spaces, ' ', sizeof spaces-1); + + buf = vtmallocz(VtMaxLumpSize); + if(memcmp(score, vtzeroscore, VtScoreSize) == 0) + n = 0; + else + n = vtread(z, score, type, buf, VtMaxLumpSize); + if(n < 0){ + Bprint(&bout, "%.*serror reading %V: %r\n", indent*4, spaces, score); + goto out; + } + switch(type){ + case VtRootType: + if(vtrootunpack(&root, buf) < 0){ + Bprint(&bout, "%.*serror unpacking root %V: %r\n", indent*4, spaces, score); + goto out; + } + Bprint(&bout, "%.*s%V root name=%s type=%s prev=%V bsize=%d\n", + indent*4, spaces, score, root.name, root.type, root.prev, root.blocksize); + dump(indent+1, root.score, VtDirType); + break; + + case VtDirType: + Bprint(&bout, "%.*s%V dir n=%d\n", indent*4, spaces, score, n); + for(i=0; i*VtEntrySize= VtDirType) + Bprint(&bout, "%.*s%V dir+%d\n", indent*4, spaces, score, type-VtDirType); + else + Bprint(&bout, "%.*s%V data+%d\n", indent*4, spaces, score, type-VtDirType); + for(i=0; i= 0) + goto havetype; + } + sysfatal("cannot find block %V", score); + +havetype: + Binit(&bout, 1, OWRITE); + dump(0, score, type); + Bflush(&bout); + threadexitsall(nil); +}