From a58f193d08c370efc6b008e807563f1f678c7b69 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 9 Jul 2008 11:42:09 -0400 Subject: venti: add venti/dump program --- src/cmd/venti/dump.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/cmd/venti/mkfile | 1 + 2 files changed, 135 insertions(+) create mode 100644 src/cmd/venti/dump.c (limited to 'src') diff --git a/src/cmd/venti/dump.c b/src/cmd/venti/dump.c new file mode 100644 index 00000000..8481303a --- /dev/null +++ b/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); +} diff --git a/src/cmd/venti/mkfile b/src/cmd/venti/mkfile index eb68babf..b5cfff7e 100644 --- a/src/cmd/venti/mkfile +++ b/src/cmd/venti/mkfile @@ -7,6 +7,7 @@ TARG=\ read\ sync\ write\ + dump\ BIN=$BIN/venti -- cgit v1.2.3