changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > ventivac / module/vac.m

changeset 96: 6830611f5d66
parent: b9bb5133d444
child: 7fd24f62e50a
author: Mechiel Lukkien <mechiel@ueber.net>
date: Mon, 06 Aug 2007 16:42:22 +0200
permissions: -rw-r--r--
description: change occurrances of "rabin" to "varblocks", since the idea is not specific to rabin fingerprinting, but to having variable-sized blocks.
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  Root: adt {
49  version: int;
50  name: string;
51  rtype: string;
52  score: Venti->Score; # to a Dir block
53  blocksize: int; # maximum block size
54  prev: ref Venti->Score; # last root block
55 
56  new: fn(name, rtype: string, score: Venti->Score, blocksize: int, prev: ref Venti->Score): ref Root;
57  unpack: fn(d: array of byte): ref Root;
58  pack: fn(r: self ref Root): array of byte;
59  };
60 
61  Entry: adt {
62  gen: int; # generation number (XXX should be unsigned)
63  psize: int; # pointer block size
64  dsize: int; # data block size
65  depth: int; # unpacked from flags
66  flags: int;
67  size: big; # (XXX should be unsigned)
68  score: Venti->Score;
69 
70  new: fn(psize, dsize, flags: int, size: big, score: Venti->Score): ref Entry;
71  pack: fn(e: self ref Entry): array of byte;
72  unpack: fn(d: array of byte): ref Entry;
73  };
74 
75  Direntry: adt {
76  version: int;
77  elem: string;
78  entry, gen: int;
79  mentry, mgen: int;
80  qid: big;
81  uid, gid, mid: string;
82  mtime, mcount, ctime, atime, mode, emode: int;
83 
84  new: fn(): ref Direntry;
85  mk: fn(d: Sys->Dir): ref Direntry;
86  mkdir: fn(de: self ref Direntry): ref Sys->Dir;
87  pack: fn(de: self ref Direntry): array of byte;
88  unpack: fn(d: array of byte): ref Direntry;
89  };
90 
91  Metablock: adt {
92  size, free, maxindex, nindex: int;
93 
94  new: fn(): ref Metablock;
95  pack: fn(mb: self ref Metablock, d: array of byte);
96  unpack: fn(d: array of byte): ref Metablock;
97  };
98 
99  Metaentry: adt {
100  offset, size: int;
101 
102  pack: fn(me: self ref Metaentry, d: array of byte);
103  unpack: fn(d: array of byte, i: int): ref Metaentry;
104  };
105 
106  # single block
107  Page: adt {
108  d: array of byte;
109  o: int;
110  esize: int;
111  treesize: big;
112 
113  new: fn(dsize: int, varblocks: int): ref Page;
114  npointers: fn(p: self ref Page): int;
115  add: fn(p: self ref Page, s: Venti->Score, size: big);
116  full: fn(p: self ref Page): int;
117  data: fn(p: self ref Page): array of byte;
118  };
119 
120  # for writing a hash tree file
121  File: adt {
122  p: array of ref Page;
123  dtype, dsize: int;
124  size: big;
125  s: ref Venti->Session;
126  varblocks: int;
127 
128  new: fn(s: ref Venti->Session, dtype, dsize, varblocks: int): ref File;
129  write: fn(f: self ref File, d: array of byte): int;
130  finish: fn(f: self ref File): ref Entry;
131  mkstate: fn(session: ref Venti->Session, e: ref Entry, varblocks: int): ref File;
132  };
133 
134  # for writing venti directories (entries)
135  Sink: adt {
136  f: ref File;
137  d: array of byte;
138  nd, ne: int;
139 
140  new: fn(s: ref Venti->Session, dsize: int): ref Sink;
141  add: fn(m: self ref Sink, e: ref Entry): int;
142  finish: fn(m: self ref Sink): ref Entry;
143  };
144 
145  Mentry: adt {
146  elem: string;
147  me: ref Metaentry;
148 
149  cmp: fn(a, b: ref Mentry): int;
150  };
151 
152  # for writing directory entries (meta blocks, meta entries, direntries)
153  MSink: adt {
154  f: ref File;
155  de: array of byte;
156  nde: int;
157  l: list of ref Mentry;
158 
159  new: fn(s: ref Venti->Session, dsize: int): ref MSink;
160  add: fn(m: self ref MSink, de: ref Direntry): int;
161  finish: fn(m: self ref MSink): ref Entry;
162  };
163 
164  # for reading pages from a hash tree referenced by an entry
165  Source: adt {
166  session: ref Venti->Session;
167  e: ref Entry;
168 
169  new: fn(s: ref Venti->Session, e: ref Entry): ref Source;
170  get: fn(s: self ref Source, i: big, d: array of byte): int;
171  oget: fn(s: self ref Source, offset: big): array of byte;
172  };
173 
174  # for reading from a hash tree while keeping offset
175  Vacfile: adt {
176  s: ref Source;
177  o: big;
178 
179  mk: fn(s: ref Source): ref Vacfile;
180  new: fn(session: ref Venti->Session, e: ref Entry): ref Vacfile;
181  read: fn(v: self ref Vacfile, d: array of byte, n: int): int;
182  seek: fn(v: self ref Vacfile, offset: big): big;
183  pread: fn(v: self ref Vacfile, d: array of byte, n: int, offset: big): int;
184  };
185 
186  # for listing contents of a vac directory and walking to path elements
187  Vacdir: adt {
188  vf: ref Vacfile;
189  ms: ref Source;
190  p: big;
191  i: int;
192 
193  mk: fn(vf: ref Vacfile, ms: ref Source): ref Vacdir;
194  new: fn(session: ref Venti->Session, e, me: ref Entry): ref Vacdir;
195  walk: fn(v: self ref Vacdir, elem: string): ref Direntry;
196  open: fn(v: self ref Vacdir, de: ref Direntry): (ref Entry, ref Entry);
197  readdir: fn(v: self ref Vacdir): (int, ref Direntry);
198  rewind: fn(v: self ref Vacdir);
199  };
200 
201  vdroot: fn(session: ref Venti->Session, score: Venti->Score): (ref Vacdir, ref Direntry, string);
202  readscore: fn(path: string): (string, ref Venti->Score, string);
203 };