changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > ventivac / module/vac.m

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