changelog shortlog tags branches changeset files file revisions raw help

Mercurial > hg > ventivac / annotate module/vac.m

changeset 121: 7fd24f62e50a
parent: 6830611f5d66
child: 84abb5444a76
author: Mechiel Lukkien <mechiel@ueber.net>
date: Fri, 17 Aug 2007 22:25:28 +0200
permissions: -rw-r--r--
description: move default rabin parameters to vac.m
mjl@0 1
 Vac: module {
mjl@0 2
 	PATH:	con "/dis/lib/vac.dis";
mechiel@6 3
 	init:	fn();
mjl@0 4
 
mjl@0 5
 	dflag:	int;
mechiel@75 6
 	blocksread, blockswritten, bytesread, byteswritten: big;
mjl@0 7
 
mjl@0 8
 	# taken from venti.m, merge back later
mjl@0 9
 	# some of this needs to be removed from venti.m since it does not belong there
mjl@0 10
 
mjl@0 11
 	# mode bits
mjl@0 12
 	Modeperm: con 8r777;
mjl@0 13
 	Modesticky,
mjl@0 14
 	Modesetuid,
mjl@0 15
 	Modesetgid,
mjl@0 16
 	Modeappend,
mjl@0 17
 	Modeexcl,
mjl@0 18
 	Modesymlink,
mjl@0 19
 	Modedir,
mjl@0 20
 	Modehidden,
mjl@0 21
 	Modesystem,
mjl@0 22
 	Modearchive,
mjl@0 23
 	Modetemp,
mjl@0 24
 	Modesnapshot,
mjl@0 25
 	Modedev,
mjl@0 26
 	Modenamedpipe: con 1<<(9+iota);
mjl@0 27
 
mjl@0 28
 	Entrysize:	con 40;
mjl@0 29
 	Rootsize:	con 300;
mjl@0 30
 	Metablocksize:	con 12;
mjl@0 31
 	Metaentrysize:	con 4;
mjl@0 32
 
mechiel@61 33
 	Rootversionvar:	con 3;	# xxx move to venti.m
mechiel@80 34
 	Pointervarmask:	con (1<<4);	# xxx move to venti.m
mechiel@61 35
 
mjl@0 36
 	Dsize:	con 8*1024;
mjl@0 37
 
mjl@0 38
 	Entryactive:	con (1<<0);	# entry is in use
mjl@0 39
 	Entrydir:	con (1<<1);	# a directory
mjl@0 40
 	Entrydepthshift:	con 2;	# shift for pointer depth
mjl@0 41
 	Entrydepthmask:	con (16r7<<2);	# mask for pointer depth
mjl@0 42
 	Entrylocal:	con (1<<5);	# used for local storage: should not be set for venti blocks
mechiel@60 43
 	Entryvarblocks:	con (1<<7);	# variable block size, e.g. for rabin fingerprinting
mjl@0 44
 
mechiel@94 45
 	Direntrymagic:	con 16r1c4d9072;
mechiel@94 46
 	Metablockmagic:	con 16r5656fc79;
mechiel@94 47
 
mechiel@121 48
 	# parameters for writing rabin fingerprinted archives
mechiel@121 49
 	Rabinprime:	con 269;
mechiel@121 50
 	Rabinmod:	con 8*1024;
mechiel@121 51
 	Rabinwidth:	con 31;
mechiel@121 52
 	Rabinblockmin:	con 1024;
mechiel@121 53
 	Rabinblockmax:	con 32*1024;
mechiel@121 54
 
mjl@0 55
 	Root: adt {
mjl@0 56
 		version:	int;
mjl@0 57
 		name:	string;
mjl@0 58
 		rtype:	string;
mjl@0 59
 		score:	Venti->Score;		# to a Dir block
mjl@0 60
 		blocksize:	int;				# maximum block size
mjl@0 61
 		prev:		ref Venti->Score;		# last root block
mjl@0 62
 
mjl@0 63
 		new:	fn(name, rtype: string, score: Venti->Score, blocksize: int, prev: ref Venti->Score): ref Root;
mjl@0 64
 		unpack:	fn(d: array of byte): ref Root;
mjl@0 65
 		pack:	fn(r: self ref Root): array of byte;
mjl@0 66
 	};
mjl@0 67
 
mjl@0 68
 	Entry: adt {
mjl@0 69
 		gen:		int;		# generation number (XXX should be unsigned)
mjl@0 70
 		psize:	int;		# pointer block size
mjl@0 71
 		dsize:	int;		# data block size
mjl@0 72
 		depth:	int;		# unpacked from flags
mjl@0 73
 		flags:	int;
mjl@0 74
 		size:		big;		# (XXX should be unsigned)
mjl@0 75
 		score:	Venti->Score;
mjl@0 76
 
mjl@0 77
 		new:	fn(psize, dsize, flags: int, size: big, score: Venti->Score): ref Entry;
mjl@0 78
 		pack:	fn(e: self ref Entry): array of byte;
mjl@0 79
 		unpack:	fn(d: array of byte): ref Entry;
mjl@0 80
 	};
mjl@0 81
 
mjl@0 82
 	Direntry: adt {
mjl@0 83
 		version:	int;
mjl@0 84
 		elem:	string;
mjl@0 85
 		entry, gen:	int;
mjl@0 86
 		mentry, mgen:	int;
mjl@0 87
 		qid:	big;
mjl@0 88
 		uid, gid, mid:	string;
mjl@0 89
 		mtime, mcount, ctime, atime, mode, emode: int;
mjl@0 90
 
mjl@0 91
 		new:	fn(): ref Direntry;
mjl@0 92
 		mk:	fn(d: Sys->Dir): ref Direntry;
mjl@0 93
 		mkdir:	fn(de: self ref Direntry): ref Sys->Dir;
mjl@0 94
 		pack:	fn(de: self ref Direntry): array of byte;
mjl@0 95
 		unpack:	fn(d: array of byte): ref Direntry;
mjl@0 96
 	};
mjl@0 97
 
mjl@0 98
 	Metablock: adt {
mjl@0 99
 		size, free, maxindex, nindex:	int;
mjl@0 100
 
mjl@0 101
 		new:	fn(): ref Metablock;
mjl@0 102
 		pack:	fn(mb: self ref Metablock, d: array of byte);
mjl@0 103
 		unpack:	fn(d: array of byte): ref Metablock;
mjl@0 104
 	};
mjl@0 105
 
mjl@0 106
 	Metaentry: adt {
mjl@0 107
 		offset, size:	int;
mjl@0 108
 
mjl@0 109
 		pack:	fn(me: self ref Metaentry, d: array of byte);
mjl@0 110
 		unpack:	fn(d: array of byte, i: int): ref Metaentry;
mjl@0 111
 	};
mjl@0 112
 
mjl@0 113
 	# single block
mjl@0 114
 	Page: adt {
mjl@0 115
 		d:	array of byte;
mjl@0 116
 		o:	int;
mechiel@57 117
 		esize:	int;
mechiel@57 118
 		treesize:	big;
mjl@0 119
 
mechiel@96 120
 		new:	fn(dsize: int, varblocks: int): ref Page;
mechiel@57 121
 		npointers:	fn(p: self ref Page): int;
mechiel@57 122
 		add:	fn(p: self ref Page, s: Venti->Score, size: big);
mjl@0 123
 		full:	fn(p: self ref Page): int;
mjl@0 124
 		data:	fn(p: self ref Page): array of byte;
mjl@0 125
 	};
mjl@0 126
 
mechiel@74 127
 	# for writing a hash tree file
mjl@0 128
 	File: adt {
mjl@0 129
 		p:	array of ref Page;
mjl@0 130
 		dtype, dsize:	int;
mjl@0 131
 		size:	big;
mjl@0 132
 		s:	ref Venti->Session;
mechiel@96 133
 		varblocks:	int;
mjl@0 134
 
mechiel@96 135
 		new:	fn(s: ref Venti->Session, dtype, dsize, varblocks: int): ref File;
mjl@0 136
 		write:	fn(f: self ref File, d: array of byte): int;
mjl@0 137
 		finish:	fn(f: self ref File): ref Entry;
mechiel@96 138
 		mkstate:	fn(session: ref Venti->Session, e: ref Entry, varblocks: int): ref File;
mjl@0 139
 	};
mjl@0 140
 
mechiel@74 141
 	# for writing venti directories (entries)
mjl@0 142
 	Sink: adt {
mjl@0 143
 		f:	ref File;
mjl@0 144
 		d:	array of byte;
mjl@0 145
 		nd, ne:	int;
mjl@0 146
 
mjl@0 147
 		new:	fn(s: ref Venti->Session, dsize: int): ref Sink;
mjl@0 148
 		add:	fn(m: self ref Sink, e: ref Entry): int;
mjl@0 149
 		finish:	fn(m: self ref Sink): ref Entry;
mjl@0 150
 	};
mjl@0 151
 
mjl@0 152
 	Mentry: adt {
mjl@0 153
 		elem:	string;
mjl@0 154
 		me:	ref Metaentry;
mjl@0 155
 
mjl@0 156
 		cmp:	fn(a, b: ref Mentry): int;
mjl@0 157
 	};
mjl@0 158
 
mjl@0 159
 	# for writing directory entries (meta blocks, meta entries, direntries)
mjl@0 160
 	MSink: adt {
mjl@0 161
 		f: 	ref File;
mjl@0 162
 		de:	array of byte;
mjl@0 163
 		nde:	int;
mjl@0 164
 		l:	list of ref Mentry;
mjl@0 165
 
mjl@0 166
 		new:	fn(s: ref Venti->Session, dsize: int): ref MSink;
mjl@0 167
 		add:	fn(m: self ref MSink, de: ref Direntry): int;
mjl@0 168
 		finish:	fn(m: self ref MSink): ref Entry;
mjl@0 169
 	};
mjl@0 170
 
mjl@0 171
 	# for reading pages from a hash tree referenced by an entry
mjl@0 172
 	Source: adt {
mjl@0 173
 		session:	ref Venti->Session;
mjl@0 174
 		e:	ref Entry;
mjl@0 175
 
mjl@0 176
 		new:	fn(s: ref Venti->Session, e: ref Entry): ref Source;
mjl@0 177
 		get:	fn(s: self ref Source, i: big, d: array of byte): int;
mechiel@57 178
 		oget:	fn(s: self ref Source, offset: big): array of byte;
mjl@0 179
 	};
mjl@0 180
 
mjl@0 181
 	# for reading from a hash tree while keeping offset
mjl@0 182
 	Vacfile: adt {
mjl@0 183
 		s:	ref Source;
mjl@0 184
 		o:	big;
mjl@0 185
 
mjl@0 186
 		mk:	fn(s: ref Source): ref Vacfile;
mjl@0 187
 		new:	fn(session: ref Venti->Session, e: ref Entry): ref Vacfile;
mjl@0 188
 		read:	fn(v: self ref Vacfile, d: array of byte, n: int): int;
mjl@0 189
 		seek:	fn(v: self ref Vacfile, offset: big): big;
mjl@0 190
 		pread:	fn(v: self ref Vacfile, d: array of byte, n: int, offset: big): int;
mjl@0 191
 	};
mjl@0 192
 
mjl@0 193
 	# for listing contents of a vac directory and walking to path elements
mjl@0 194
 	Vacdir: adt {
mjl@0 195
 		vf:	ref Vacfile;
mjl@0 196
 		ms:	ref Source;
mjl@0 197
 		p:	big;
mjl@0 198
 		i:	int;
mjl@0 199
 
mjl@0 200
 		mk:	fn(vf: ref Vacfile, ms: ref Source): ref Vacdir;
mjl@0 201
 		new:	fn(session: ref Venti->Session, e, me: ref Entry): ref Vacdir;
mjl@0 202
 		walk:	fn(v: self ref Vacdir, elem: string): ref Direntry;
mjl@0 203
 		open:	fn(v: self ref Vacdir, de: ref Direntry): (ref Entry, ref Entry);
mjl@0 204
 		readdir:	fn(v: self ref Vacdir): (int, ref Direntry);
mjl@0 205
 		rewind:		fn(v: self ref Vacdir);
mjl@0 206
 	};
mjl@0 207
 
mjl@0 208
 	vdroot:	fn(session: ref Venti->Session, score: Venti->Score): (ref Vacdir, ref Direntry, string);
mechiel@77 209
 	readscore:	fn(path: string): (string, ref Venti->Score, string);
mjl@0 210
 };