Blob


1 #include "stdinc.h"
2 #include "dat.h"
3 #include "fns.h"
5 char *host;
7 void
8 usage(void)
9 {
10 fprint(2, "usage: mkroot [-h host] name type score blocksize prev\n");
11 threadexitsall("usage");
12 }
14 void
15 threadmain(int argc, char *argv[])
16 {
17 uchar score[VtScoreSize];
18 uchar buf[VtRootSize];
19 VtConn *z;
20 VtRoot root;
22 ARGBEGIN{
23 case 'h':
24 host = EARGF(usage());
25 break;
26 default:
27 usage();
28 break;
29 }ARGEND
31 if(argc != 5)
32 usage();
34 ventifmtinstall();
36 strecpy(root.name, root.name+sizeof root.name, argv[0]);
37 strecpy(root.type, root.type+sizeof root.type, argv[1]);
38 if(vtparsescore(argv[2], strlen(argv[2]), nil, root.score) < 0)
39 sysfatal("bad score '%s'", argv[2]);
40 root.blocksize = atoi(argv[3]);
41 if(vtparsescore(argv[4], strlen(argv[4]), nil, root.prev) < 0)
42 sysfatal("bad score '%s'", argv[4]);
43 vtrootpack(&root, buf);
45 z = vtdial(host);
46 if(z == nil)
47 sysfatal("could not connect to server: %r");
49 if(vtconnect(z) < 0)
50 sysfatal("vtconnect: %r");
52 if(vtwrite(z, score, VtRootType, buf, VtRootSize) < 0)
53 sysfatal("vtwrite: %r");
54 if(vtsync(z) < 0)
55 sysfatal("vtsync: %r");
56 vthangup(z);
57 print("%V\n", score);
58 threadexitsall(0);
59 }