12 fprint(2, "usage: copy src-host dst-host score [type]\n");
13 threadexitsall("usage");
17 parsescore(uchar *score, char *buf, int n)
21 memset(score, 0, VtScoreSize);
25 for(i=0; i<VtScoreSize*2; i++) {
26 if(buf[i] >= '0' && buf[i] <= '9')
28 else if(buf[i] >= 'a' && buf[i] <= 'f')
29 c = buf[i] - 'a' + 10;
30 else if(buf[i] >= 'A' && buf[i] <= 'F')
31 c = buf[i] - 'A' + 10;
45 walk(uchar score[VtScoreSize], uint type, int base)
52 if(memcmp(score, vtzeroscore, VtScoreSize) == 0)
55 buf = vtmallocz(VtMaxLumpSize);
56 if(fast && vtread(zdst, score, type, buf, VtMaxLumpSize) >= 0){
57 fprint(2, "skip %V\n", score);
62 n = vtread(zsrc, score, type, buf, VtMaxLumpSize);
64 fprint(2, "warning: could not read block %V %d: %r", score, type);
70 if(vtrootunpack(&root, buf) < 0){
71 fprint(2, "warning: could not unpack root in %V %d\n", score, type);
74 walk(root.score, VtDirType, 0);
75 walk(root.prev, VtRootType, 0);
79 for(i=0; i<n/VtEntrySize; i++){
80 if(vtentryunpack(&e, buf, i) < 0){
81 fprint(2, "warning: could not unpack entry #%d in %V %d\n", i, score, type);
84 if(!(e.flags & VtEntryActive))
86 if(e.flags&VtEntryDir)
90 sub = base | ((e.flags&VtEntryDepthMask)>>VtEntryDepthShift);
91 walk(e.score, sub, base);
98 default: /* pointers */
99 for(i=0; i<n; i+=VtScoreSize)
100 if(memcmp(buf+i, vtzeroscore, VtScoreSize) != 0)
101 walk(buf+i, type-1, base);
105 if(vtwrite(zdst, score, type, buf, n) < 0)
106 fprint(2, "warning: could not write block %V %d: %r", score, type);
111 threadmain(int argc, char *argv[])
114 uchar score[VtScoreSize];
126 if(argc != 3 && argc != 4)
129 fmtinstall('V', vtscorefmt);
131 if(parsescore(score, argv[2], strlen(argv[2]) < 0))
132 sysfatal("could not parse score: %r");
134 buf = vtmallocz(VtMaxLumpSize);
136 zsrc = vtdial(argv[0]);
138 sysfatal("could not dial src server: %r");
139 if(vtconnect(zsrc) < 0)
140 sysfatal("vtconnect src: %r");
142 zdst = vtdial(argv[1]);
144 sysfatal("could not dial dst server: %r");
145 if(vtconnect(zdst) < 0)
146 sysfatal("vtconnect dst: %r");
149 type = atoi(argv[3]);
150 n = vtread(zsrc, score, type, buf, VtMaxLumpSize);
152 sysfatal("could not read block: %r");
154 for(type=0; type<VtMaxType; type++){
155 n = vtread(zsrc, score, type, buf, VtMaxLumpSize);
159 if(type == VtMaxType)
160 sysfatal("could not find block %V of any type", score);
163 walk(score, type, VtDirType);
166 sysfatal("could not sync dst server: %r");