aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fossil/flchk.c
blob: c003f70693886c64e35dd14447649feb23285de8 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "stdinc.h"
#include <bio.h>
#include "dat.h"
#include "fns.h"

Biobuf bout;
Fsck fsck;

static void
usage(void)
{
	fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
	threadexitsall("usage");
}

#pragma	varargck	argpos	flprint	1

static int
flprint(char *fmt, ...)
{
	int n;
	va_list arg;

	va_start(arg, fmt);
	n = Bvprint(&bout, fmt, arg);
	va_end(arg);
	return n;
}

static void
flclre(Fsck *chk, Block *b, int o)
{
	USED(chk);
	Bprint(&bout, "# clre 0x%ux %d\n", b->addr, o);
}

static void
flclrp(Fsck *chk, Block *b, int o)
{
	USED(chk);
	Bprint(&bout, "# clrp 0x%ux %d\n", b->addr, o);
}

static void
flclri(Fsck *chk, char *name, MetaBlock *mb, int i, Block *b)
{
	USED(chk);
	USED(mb);
	USED(i);
	USED(b);
	Bprint(&bout, "# clri %s\n", name);
}

static void
flclose(Fsck *chk, Block *b, u32int epoch)
{
	USED(chk);
	Bprint(&bout, "# bclose 0x%ux %ud\n", b->addr, epoch);
}

void
threadmain(int argc, char *argv[])
{
	int csize = 1000;
	VtConn *z;
	char *host = nil;
	
	fsck.useventi = 1;
	Binit(&bout, 1, OWRITE);
	ARGBEGIN{
	default:
		usage();
	case 'c':
		csize = atoi(ARGF());
		if(csize <= 0)
			usage();
		break;
	case 'f':
		fsck.useventi = 0;
		break;
	case 'h':
		host = ARGF();
		break;
	case 'v':
		fsck.printdirs = 1;
		break;
	}ARGEND;

	if(argc != 1)
		usage();

	fmtinstall('L', labelFmt);
	fmtinstall('V', scoreFmt);

	/*
	 * Connect to Venti.
	 */
	z = vtdial(host);
	if(z == nil){
		if(fsck.useventi)
			sysfatal("could not connect to server: %r");
	}else if(vtconnect(z) < 0)
		sysfatal("vtconnect: %r");

	/*
	 * Initialize file system.
	 */
	fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
	if(fsck.fs == nil)
		sysfatal("could not open file system: %r");

	fsck.print = flprint;
	fsck.clre = flclre;
	fsck.clrp = flclrp;
	fsck.close = flclose;
	fsck.clri = flclri;

	fsCheck(&fsck);

	threadexitsall(0);
}