changelog shortlog tags branches changeset files revisions annotate raw help

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