aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fossil/epoch.c
blob: cce53f12de8ae7b2abc326487275653a292db29a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "stdinc.h"
#include "dat.h"
#include "fns.h"

uchar buf[65536];

void
usage(void)
{
	fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
	threadexitsall("usage");
}

void
threadmain(int argc, char **argv)
{
	int fd;
	Header h;
	Super s;

	ARGBEGIN{
	default:
		usage();
	}ARGEND

	if(argc == 0 || argc > 2)
		usage();

	if((fd = open(argv[0], argc==2 ? ORDWR : OREAD)) < 0)
		sysfatal("open %s: %r", argv[0]);

	if(pread(fd, buf, HeaderSize, HeaderOffset) != HeaderSize)
		sysfatal("reading header: %r");
	if(!headerUnpack(&h, buf))
		sysfatal("unpacking header: %r");

	if(pread(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
		sysfatal("reading super block: %r");

	if(!superUnpack(&s, buf))
		sysfatal("unpacking super block: %r");

	print("epoch %d\n", s.epochLow);
	if(argc == 2){
		s.epochLow = strtoul(argv[1], 0, 0);
		superPack(&s, buf);
		if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
			sysfatal("writing super block: %r");
	}
	threadexitsall(0);
}