blob: 5d67ad316f1e66696d87fd3e9b5f54ec2821582d [file] [log] [blame]
rsc23fb2ed2005-07-24 20:15:44 +00001#include <u.h>
2#include <libc.h>
3#include <venti.h>
4#include <libsec.h>
5#include <thread.h>
6
7void
8usage(void)
9{
10 fprint(2, "usage: root [-h host] score\n");
11 threadexitsall("usage");
12}
13
14void
15threadmain(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;
23
24 fmtinstall('F', vtfcallfmt);
25 fmtinstall('V', vtscorefmt);
26 quotefmtinstall();
27
28 host = nil;
29 ARGBEGIN{
30 case 'h':
31 host = EARGF(usage());
32 break;
33 default:
34 usage();
35 break;
36 }ARGEND
37
38 if(argc == 0)
39 usage();
40
41 buf = vtmallocz(VtMaxLumpSize);
42
43 z = vtdial(host);
44 if(z == nil)
45 sysfatal("could not connect to server: %r");
46
47 if(vtconnect(z) < 0)
48 sysfatal("vtconnect: %r");
49
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}