Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <venti.h>
4 #include <libsec.h>
5 #include <thread.h>
7 void
8 usage(void)
9 {
10 fprint(2, "usage: root [-h host] score\n");
11 threadexitsall("usage");
12 }
14 void
15 threadmain(int argc, char *argv[])
16 {
17 int i, n;
18 uchar score[VtScoreSize];
19 uchar *buf;
20 VtConn *z;
21 char *host;
22 VtRoot root;
24 fmtinstall('F', vtfcallfmt);
25 fmtinstall('V', vtscorefmt);
26 quotefmtinstall();
28 host = nil;
29 ARGBEGIN{
30 case 'h':
31 host = EARGF(usage());
32 break;
33 default:
34 usage();
35 break;
36 }ARGEND
38 if(argc == 0)
39 usage();
41 buf = vtmallocz(VtMaxLumpSize);
43 z = vtdial(host);
44 if(z == nil)
45 sysfatal("could not connect to server: %r");
47 if(vtconnect(z) < 0)
48 sysfatal("vtconnect: %r");
50 for(i=0; i<argc; i++){
51 if(vtparsescore(argv[i], nil, score) < 0){
52 fprint(2, "cannot parse score '%s': %r\n", argv[i]);
53 continue;
54 }
55 n = vtread(z, score, VtRootType, buf, VtMaxLumpSize);
56 if(n < 0){
57 fprint(2, "could not read block %V: %r\n", score);
58 continue;
59 }
60 if(n != VtRootSize){
61 fprint(2, "block %V is wrong size %d != 300\n", score, n);
62 continue;
63 }
64 if(vtrootunpack(&root, buf) < 0){
65 fprint(2, "unpacking block %V: %r\n", score);
66 continue;
67 }
68 print("%V: %q %q %V %d %V\n", score, root.name, root.type, root.score, root.blocksize, root.prev);
69 }
70 vthangup(z);
71 threadexitsall(0);
72 }