From 7a4ee46d253e291044bba2d0c54b818b67ac013c Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 23 Nov 2003 17:54:58 +0000 Subject: Initial stab at Venti. --- src/cmd/venti/copy.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 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..8b5bb84d --- /dev/null +++ b/src/cmd/venti/copy.c @@ -0,0 +1,169 @@ +#include "stdinc.h" +#include "dat.h" +#include "fns.h" + +int fast; + +VtConn *zsrc, *zdst; + +void +usage(void) +{ + fprint(2, "usage: copy src-host dst-host score [type]\n"); + threadexitsall("usage"); +} + +int +parsescore(uchar *score, char *buf, int n) +{ + int i, c; + + memset(score, 0, VtScoreSize); + + if(n < VtScoreSize*2) + return -1; + for(i=0; i= '0' && buf[i] <= '9') + c = buf[i] - '0'; + else if(buf[i] >= 'a' && buf[i] <= 'f') + c = buf[i] - 'a' + 10; + else if(buf[i] >= 'A' && buf[i] <= 'F') + c = buf[i] - 'A' + 10; + else { + return -1; + } + + if((i & 1) == 0) + c <<= 4; + + score[i>>1] |= c; + } + return 0; +} + +void +walk(uchar score[VtScoreSize], uint type, int base) +{ + int i, n, sub; + 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){ + fprint(2, "skip %V\n", score); + free(buf); + return; + } + + n = vtread(zsrc, score, type, buf, VtMaxLumpSize); + if(n < 0){ + fprint(2, "warning: could not read block %V %d: %r", score, type); + 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); + break; + + case VtDirType: + for(i=0; i>VtEntryDepthShift); + walk(e.score, sub, base); + } + break; + + case VtDataType: + break; + + default: /* pointers */ + for(i=0; i= 0) + break; + } + if(type == VtMaxType) + sysfatal("could not find block %V of any type", score); + } + + walk(score, type, VtDirType); + + if(vtsync(zdst) < 0) + sysfatal("could not sync dst server: %r"); + + threadexitsall(0); +} -- cgit v1.2.3