From a0d146edd7a7de6236a0d60baafeeb59f8452aae Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 12 Jul 2005 15:23:36 +0000 Subject: return of venti --- src/cmd/venti/copy.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 src/cmd/venti/copy.c (limited to 'src/cmd/venti/copy.c') diff --git a/src/cmd/venti/copy.c b/src/cmd/venti/copy.c new file mode 100644 index 00000000..89fbbac9 --- /dev/null +++ b/src/cmd/venti/copy.c @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#include + +int changes; +int rewrite; +int ignoreerrors; +int fast; +int verbose; +VtConn *zsrc, *zdst; + +void +usage(void) +{ + fprint(2, "usage: copy [-fir] [-t type] srchost dsthost score\n"); + threadexitsall("usage"); +} + +void +walk(uchar score[VtScoreSize], uint type, int base) +{ + int i, n; + uchar *buf; + VtEntry e; + VtRoot root; + + if(memcmp(score, vtzeroscore, VtScoreSize) == 0) + return; + + buf = vtmallocz(VtMaxLumpSize); + if(fast && vtread(zdst, score, type, buf, VtMaxLumpSize) >= 0){ + if(verbose) + fprint(2, "skip %V\n", score); + free(buf); + return; + } + + n = vtread(zsrc, score, type, buf, VtMaxLumpSize); + if(n < 0){ + if(rewrite){ + changes++; + memmove(score, vtzeroscore, VtScoreSize); + }else if(!ignoreerrors) + sysfatal("reading block %V (type %d): %r", type, score); + return; + } + + switch(type){ + case VtRootType: + if(vtrootunpack(&root, buf) < 0){ + fprint(2, "warning: could not unpack root in %V %d\n", score, type); + break; + } + walk(root.score, VtDirType, 0); + walk(root.prev, VtRootType, 0); + vtrootpack(&root, buf); /* walk might have changed score */ + break; + + case VtDirType: + for(i=0; i= 0) + break; + } + if(type == VtMaxType) + sysfatal("could not find block %V of any type", score); + } + + walk(score, type, VtDirType); + if(changes) + print("%s:%V (%d pointers rewritten)\n", prefix, score, changes); + + if(vtsync(zdst) < 0) + sysfatal("could not sync dst server: %r"); + + threadexitsall(0); +} -- cgit v1.2.3