Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <venti.h>
4
#include <thread.h>
5
 
6
char *host;
7
 
8
void
9
usage(void)
10
{
11
	fprint(2, "usage: mkroot [-h host] name type score blocksize prev\n");
12
	threadexitsall("usage");
13
}
14
 
15
void
16
threadmain(int argc, char *argv[])
17
{
18
	uchar score[VtScoreSize];
19
	uchar buf[VtRootSize];
20
	VtConn *z;
21
	VtRoot root;
22
 
23
	ARGBEGIN{
24
	case 'h':
25
		host = EARGF(usage());
26
		break;
27
	default:
28
		usage();
29
		break;
30
	}ARGEND
31
 
32
	if(argc != 5)
33
		usage();
34
 
35
	fmtinstall('V', vtscorefmt);
36
	fmtinstall('F', vtfcallfmt);
37
 
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);
46
 
47
	z = vtdial(host);
48
	if(z == nil)
49
		sysfatal("could not connect to server: %r");
50
 
51
	if(vtconnect(z) < 0)
52
		sysfatal("vtconnect: %r");
53
 
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
}