Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <venti.h>
4 #include <thread.h>
6 char *host;
8 void
9 usage(void)
10 {
11 fprint(2, "usage: mkroot [-h host] name type score blocksize prev\n");
12 threadexitsall("usage");
13 }
15 void
16 threadmain(int argc, char *argv[])
17 {
18 uchar score[VtScoreSize];
19 uchar buf[VtRootSize];
20 VtConn *z;
21 VtRoot root;
23 ARGBEGIN{
24 case 'h':
25 host = EARGF(usage());
26 break;
27 default:
28 usage();
29 break;
30 }ARGEND
32 if(argc != 5)
33 usage();
35 fmtinstall('V', vtscorefmt);
36 fmtinstall('F', vtfcallfmt);
38 strecpy(root.name, root.name+sizeof root.name, argv[0]);
39 strecpy(root.type, root.type+sizeof root.type, argv[1]);
40 if(vtparsescore(argv[2], nil, root.score) < 0)
41 sysfatal("bad score '%s'", argv[2]);
42 root.blocksize = atoi(argv[3]);
43 if(vtparsescore(argv[4], nil, root.prev) < 0)
44 sysfatal("bad score '%s'", argv[4]);
45 vtrootpack(&root, buf);
47 z = vtdial(host);
48 if(z == nil)
49 sysfatal("could not connect to server: %r");
51 if(vtconnect(z) < 0)
52 sysfatal("vtconnect: %r");
54 if(vtwrite(z, score, VtRootType, buf, VtRootSize) < 0)
55 sysfatal("vtwrite: %r");
56 if(vtsync(z) < 0)
57 sysfatal("vtsync: %r");
58 vthangup(z);
59 print("%V\n", score);
60 threadexitsall(0);
61 }