1 f7012583 2003-11-25 devnull #ifndef _VENTI_H_
2 f7012583 2003-11-25 devnull #define _VENTI_H_ 1
3 f7012583 2003-11-25 devnull #if defined(__cplusplus)
4 f7012583 2003-11-25 devnull extern "C" {
6 97a5e5f2 2003-11-23 devnull /* XXX should be own library? */
12 97a5e5f2 2003-11-23 devnull MaxFragSize = 9*1024,
15 97a5e5f2 2003-11-23 devnull typedef struct Packet Packet;
16 97a5e5f2 2003-11-23 devnull Packet *packetalloc(void);
17 97a5e5f2 2003-11-23 devnull void packetfree(Packet*);
18 97a5e5f2 2003-11-23 devnull Packet *packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
19 97a5e5f2 2003-11-23 devnull Packet *packetdup(Packet*, int offset, int n);
20 97a5e5f2 2003-11-23 devnull Packet *packetsplit(Packet*, int n);
21 97a5e5f2 2003-11-23 devnull int packetconsume(Packet*, uchar *buf, int n);
22 97a5e5f2 2003-11-23 devnull int packettrim(Packet*, int offset, int n);
23 97a5e5f2 2003-11-23 devnull uchar *packetheader(Packet*, int n);
24 97a5e5f2 2003-11-23 devnull uchar *packettrailer(Packet*, int n);
25 97a5e5f2 2003-11-23 devnull int packetprefix(Packet*, uchar *buf, int n);
26 97a5e5f2 2003-11-23 devnull int packetappend(Packet*, uchar *buf, int n);
27 97a5e5f2 2003-11-23 devnull int packetconcat(Packet*, Packet*);
28 97a5e5f2 2003-11-23 devnull uchar *packetpeek(Packet*, uchar *buf, int offset, int n);
29 97a5e5f2 2003-11-23 devnull int packetcopy(Packet*, uchar *buf, int offset, int n);
30 97a5e5f2 2003-11-23 devnull int packetfragments(Packet*, IOchunk*, int nio, int offset);
31 97a5e5f2 2003-11-23 devnull uint packetsize(Packet*);
32 97a5e5f2 2003-11-23 devnull uint packetasize(Packet*);
33 97a5e5f2 2003-11-23 devnull int packetcompact(Packet*);
34 97a5e5f2 2003-11-23 devnull int packetcmp(Packet*, Packet*);
35 97a5e5f2 2003-11-23 devnull void packetstats(void);
36 97a5e5f2 2003-11-23 devnull void packetsha1(Packet*, uchar sha1[20]);
38 97a5e5f2 2003-11-23 devnull /* XXX begin actual venti.h */
41 97a5e5f2 2003-11-23 devnull #pragma lib "libnventi.a"
42 97a5e5f2 2003-11-23 devnull #pragma src "/sys/src/libnventi"
45 97a5e5f2 2003-11-23 devnull typedef struct VtFcall VtFcall;
46 97a5e5f2 2003-11-23 devnull typedef struct VtSha1 VtSha1;
47 97a5e5f2 2003-11-23 devnull typedef struct VtConn VtConn;
48 97a5e5f2 2003-11-23 devnull typedef struct VtEntry VtEntry;
49 97a5e5f2 2003-11-23 devnull typedef struct VtRoot VtRoot;
52 97a5e5f2 2003-11-23 devnull * Fundamental constants.
56 97a5e5f2 2003-11-23 devnull VtScoreSize = 20,
57 97a5e5f2 2003-11-23 devnull VtMaxStringSize = 1024,
58 97a5e5f2 2003-11-23 devnull VtMaxLumpSize = 56*1024,
59 97a5e5f2 2003-11-23 devnull VtPointerDepth = 7,
61 2db9e482 2003-11-24 devnull #define VtMaxFileSize ((1ULL<<48)-1)
65 97a5e5f2 2003-11-23 devnull * Strings in packets.
67 97a5e5f2 2003-11-23 devnull int vtputstring(Packet*, char*);
68 97a5e5f2 2003-11-23 devnull int vtgetstring(Packet*, char**);
71 97a5e5f2 2003-11-23 devnull * Block types.
73 97a5e5f2 2003-11-23 devnull * The initial Venti protocol had a much
74 97a5e5f2 2003-11-23 devnull * less regular list of block types.
75 97a5e5f2 2003-11-23 devnull * VtToDiskType converts from new to old.
79 97a5e5f2 2003-11-23 devnull VtDataType = 0<<3,
80 97a5e5f2 2003-11-23 devnull /* VtDataType+1, ... */
81 97a5e5f2 2003-11-23 devnull VtDirType = 1<<3,
82 97a5e5f2 2003-11-23 devnull /* VtDirType+1, ... */
83 97a5e5f2 2003-11-23 devnull VtRootType = 2<<3,
84 97a5e5f2 2003-11-23 devnull VtCorruptType,
85 97a5e5f2 2003-11-23 devnull VtMaxType,
87 97a5e5f2 2003-11-23 devnull VtTypeDepthMask = 7,
90 97a5e5f2 2003-11-23 devnull /* convert to/from on-disk type numbers */
91 97a5e5f2 2003-11-23 devnull uint vttodisktype(uint);
92 97a5e5f2 2003-11-23 devnull uint vtfromdisktype(uint);
95 97a5e5f2 2003-11-23 devnull * VtEntry describes a Venti stream
99 97a5e5f2 2003-11-23 devnull VtEntryActive = 1<<0, /* entry is in use */
100 97a5e5f2 2003-11-23 devnull VtEntryDir = 1<<1, /* a directory */
101 97a5e5f2 2003-11-23 devnull VtEntryDepthShift = 2, /* shift for pointer depth */
102 97a5e5f2 2003-11-23 devnull VtEntryDepthMask = 7<<2, /* mask for pointer depth */
103 97a5e5f2 2003-11-23 devnull VtEntryLocal = 1<<5, /* for local storage only */
107 97a5e5f2 2003-11-23 devnull VtEntrySize = 40,
109 97a5e5f2 2003-11-23 devnull struct VtEntry
111 97a5e5f2 2003-11-23 devnull ulong gen; /* generation number */
112 97a5e5f2 2003-11-23 devnull ushort psize; /* pointer block size */
113 97a5e5f2 2003-11-23 devnull ushort dsize; /* data block size */
114 97a5e5f2 2003-11-23 devnull uchar type;
115 97a5e5f2 2003-11-23 devnull uchar flags;
116 97a5e5f2 2003-11-23 devnull uvlong size;
117 97a5e5f2 2003-11-23 devnull uchar score[VtScoreSize];
120 97a5e5f2 2003-11-23 devnull void vtentrypack(VtEntry*, uchar*, int index);
121 97a5e5f2 2003-11-23 devnull int vtentryunpack(VtEntry*, uchar*, int index);
123 97a5e5f2 2003-11-23 devnull struct VtRoot
125 97a5e5f2 2003-11-23 devnull char name[128];
126 97a5e5f2 2003-11-23 devnull char type[128];
127 97a5e5f2 2003-11-23 devnull uchar score[VtScoreSize]; /* to a Dir block */
128 97a5e5f2 2003-11-23 devnull ushort blocksize; /* maximum block size */
129 97a5e5f2 2003-11-23 devnull uchar prev[VtScoreSize]; /* last root block */
134 97a5e5f2 2003-11-23 devnull VtRootSize = 300,
135 97a5e5f2 2003-11-23 devnull VtRootVersion = 2,
138 97a5e5f2 2003-11-23 devnull void vtrootpack(VtRoot*, uchar*);
139 97a5e5f2 2003-11-23 devnull int vtrootunpack(VtRoot*, uchar*);
142 97a5e5f2 2003-11-23 devnull * score of zero length block
144 97a5e5f2 2003-11-23 devnull extern uchar vtzeroscore[VtScoreSize];
147 97a5e5f2 2003-11-23 devnull * zero extend and truncate blocks
149 97a5e5f2 2003-11-23 devnull void vtzeroextend(int type, uchar *buf, uint n, uint nn);
150 97a5e5f2 2003-11-23 devnull uint vtzerotruncate(int type, uchar *buf, uint n);
153 97a5e5f2 2003-11-23 devnull * parse score: mungs s
155 97a5e5f2 2003-11-23 devnull int vtparsescore(char *s, uint len, char **prefix, uchar[VtScoreSize]);
158 97a5e5f2 2003-11-23 devnull * formatting
159 97a5e5f2 2003-11-23 devnull * other than noted, these formats all ignore
160 97a5e5f2 2003-11-23 devnull * the width and precision arguments, and all flags
162 97a5e5f2 2003-11-23 devnull * V a venti score
164 97a5e5f2 2003-11-23 devnull /* #pragma varargck type "V" uchar* */
166 97a5e5f2 2003-11-23 devnull int vtscorefmt(Fmt*);
169 97a5e5f2 2003-11-23 devnull * error-checking malloc et al.
171 97a5e5f2 2003-11-23 devnull void vtfree(void *);
172 97a5e5f2 2003-11-23 devnull void *vtmalloc(int);
173 97a5e5f2 2003-11-23 devnull void *vtmallocz(int);
174 97a5e5f2 2003-11-23 devnull void *vtrealloc(void *p, int);
175 97a5e5f2 2003-11-23 devnull void *vtbrk(int n);
176 97a5e5f2 2003-11-23 devnull char *vtstrdup(char *);
179 97a5e5f2 2003-11-23 devnull * Venti protocol
183 97a5e5f2 2003-11-23 devnull * Crypto strengths
187 97a5e5f2 2003-11-23 devnull VtCryptoStrengthNone,
188 97a5e5f2 2003-11-23 devnull VtCryptoStrengthAuth,
189 97a5e5f2 2003-11-23 devnull VtCryptoStrengthWeak,
190 97a5e5f2 2003-11-23 devnull VtCryptoStrengthStrong,
194 97a5e5f2 2003-11-23 devnull * Crypto suites
198 97a5e5f2 2003-11-23 devnull VtCryptoNone,
199 97a5e5f2 2003-11-23 devnull VtCryptoSSL3,
200 97a5e5f2 2003-11-23 devnull VtCryptoTLS1,
201 97a5e5f2 2003-11-23 devnull VtCryptoMax,
205 97a5e5f2 2003-11-23 devnull * Codecs
209 97a5e5f2 2003-11-23 devnull VtCodecNone,
210 97a5e5f2 2003-11-23 devnull VtCodecDeflate,
211 97a5e5f2 2003-11-23 devnull VtCodecThwack,
212 97a5e5f2 2003-11-23 devnull VtCodecMax
217 97a5e5f2 2003-11-23 devnull VtRerror = 1,
218 97a5e5f2 2003-11-23 devnull VtTping = 2,
219 97a5e5f2 2003-11-23 devnull VtRping,
220 97a5e5f2 2003-11-23 devnull VtThello = 4,
221 97a5e5f2 2003-11-23 devnull VtRhello,
222 97a5e5f2 2003-11-23 devnull VtTgoodbye = 6,
223 97a5e5f2 2003-11-23 devnull VtRgoodbye, /* not used */
224 97a5e5f2 2003-11-23 devnull VtTauth0 = 8,
225 97a5e5f2 2003-11-23 devnull VtRauth0,
226 97a5e5f2 2003-11-23 devnull VtTauth1 = 10,
227 97a5e5f2 2003-11-23 devnull VtRauth1,
228 97a5e5f2 2003-11-23 devnull VtTread = 12,
229 97a5e5f2 2003-11-23 devnull VtRread,
230 97a5e5f2 2003-11-23 devnull VtTwrite = 14,
231 97a5e5f2 2003-11-23 devnull VtRwrite,
232 97a5e5f2 2003-11-23 devnull VtTsync = 16,
233 97a5e5f2 2003-11-23 devnull VtRsync,
238 97a5e5f2 2003-11-23 devnull struct VtFcall
240 97a5e5f2 2003-11-23 devnull uchar type;
241 97a5e5f2 2003-11-23 devnull uchar tag;
243 97a5e5f2 2003-11-23 devnull char *error; /* Rerror */
245 97a5e5f2 2003-11-23 devnull char *version; /* Thello */
246 97a5e5f2 2003-11-23 devnull char *uid; /* Thello */
247 97a5e5f2 2003-11-23 devnull uchar strength; /* Thello */
248 97a5e5f2 2003-11-23 devnull uchar *crypto; /* Thello */
249 97a5e5f2 2003-11-23 devnull uint ncrypto; /* Thello */
250 97a5e5f2 2003-11-23 devnull uchar *codec; /* Thello */
251 97a5e5f2 2003-11-23 devnull uint ncodec; /* Thello */
252 97a5e5f2 2003-11-23 devnull char *sid; /* Rhello */
253 97a5e5f2 2003-11-23 devnull uchar rcrypto; /* Rhello */
254 97a5e5f2 2003-11-23 devnull uchar rcodec; /* Rhello */
255 97a5e5f2 2003-11-23 devnull uchar *auth; /* TauthX, RauthX */
256 97a5e5f2 2003-11-23 devnull uint nauth; /* TauthX, RauthX */
257 97a5e5f2 2003-11-23 devnull uchar score[VtScoreSize]; /* Tread, Rwrite */
258 97a5e5f2 2003-11-23 devnull uchar dtype; /* Tread, Twrite */
259 97a5e5f2 2003-11-23 devnull ushort count; /* Tread */
260 97a5e5f2 2003-11-23 devnull Packet *data; /* Rread, Twrite */
263 97a5e5f2 2003-11-23 devnull Packet *vtfcallpack(VtFcall*);
264 97a5e5f2 2003-11-23 devnull int vtfcallunpack(VtFcall*, Packet*);
265 97a5e5f2 2003-11-23 devnull void vtfcallclear(VtFcall*);
266 97a5e5f2 2003-11-23 devnull int vtfcallfmt(Fmt*);
270 97a5e5f2 2003-11-23 devnull VtStateAlloc,
271 97a5e5f2 2003-11-23 devnull VtStateConnected,
272 97a5e5f2 2003-11-23 devnull VtStateClosed,
275 97a5e5f2 2003-11-23 devnull struct VtConn
277 97a5e5f2 2003-11-23 devnull QLock lk;
278 97a5e5f2 2003-11-23 devnull QLock inlk;
279 97a5e5f2 2003-11-23 devnull QLock outlk;
280 97a5e5f2 2003-11-23 devnull int debug;
281 97a5e5f2 2003-11-23 devnull int infd;
282 97a5e5f2 2003-11-23 devnull int outfd;
283 97a5e5f2 2003-11-23 devnull int muxer;
284 97a5e5f2 2003-11-23 devnull void *writeq;
285 97a5e5f2 2003-11-23 devnull void *readq;
286 97a5e5f2 2003-11-23 devnull int state;
287 97a5e5f2 2003-11-23 devnull void *wait[256];
288 97a5e5f2 2003-11-23 devnull uint ntag;
289 97a5e5f2 2003-11-23 devnull uint nsleep;
290 97a5e5f2 2003-11-23 devnull Packet *part;
291 97a5e5f2 2003-11-23 devnull Rendez tagrend;
292 97a5e5f2 2003-11-23 devnull Rendez rpcfork;
293 97a5e5f2 2003-11-23 devnull char *version;
294 97a5e5f2 2003-11-23 devnull char *uid;
295 97a5e5f2 2003-11-23 devnull char *sid;
298 97a5e5f2 2003-11-23 devnull VtConn *vtconn(int infd, int outfd);
299 97a5e5f2 2003-11-23 devnull VtConn *vtdial(char*);
300 97a5e5f2 2003-11-23 devnull void vtfreeconn(VtConn*);
301 97a5e5f2 2003-11-23 devnull int vtsend(VtConn*, Packet*);
302 97a5e5f2 2003-11-23 devnull Packet *vtrecv(VtConn*);
303 97a5e5f2 2003-11-23 devnull int vtversion(VtConn *z);
304 97a5e5f2 2003-11-23 devnull void vtdebug(VtConn *z, char*, ...);
305 97a5e5f2 2003-11-23 devnull void vthangup(VtConn *z);
306 97a5e5f2 2003-11-23 devnull /* #pragma varargck argpos vtdebug 2 */
308 97a5e5f2 2003-11-23 devnull /* server */
309 97a5e5f2 2003-11-23 devnull typedef struct VtSrv VtSrv;
310 97a5e5f2 2003-11-23 devnull typedef struct VtReq VtReq;
311 97a5e5f2 2003-11-23 devnull struct VtReq
313 97a5e5f2 2003-11-23 devnull VtFcall tx;
314 97a5e5f2 2003-11-23 devnull VtFcall rx;
315 97a5e5f2 2003-11-23 devnull /* private */
316 97a5e5f2 2003-11-23 devnull VtSrv *srv;
317 97a5e5f2 2003-11-23 devnull void *sc;
320 97a5e5f2 2003-11-23 devnull int vtsrvhello(VtConn*);
321 97a5e5f2 2003-11-23 devnull VtSrv *vtlisten(char *addr);
322 97a5e5f2 2003-11-23 devnull VtReq *vtgetreq(VtSrv*);
323 97a5e5f2 2003-11-23 devnull void vtrespond(VtReq*);
325 97a5e5f2 2003-11-23 devnull /* client */
326 97a5e5f2 2003-11-23 devnull Packet *vtrpc(VtConn*, Packet*);
327 97a5e5f2 2003-11-23 devnull void vtrecvproc(void*); /* VtConn* */
328 97a5e5f2 2003-11-23 devnull void vtsendproc(void*); /* VtConn* */
330 97a5e5f2 2003-11-23 devnull int vtconnect(VtConn*);
331 97a5e5f2 2003-11-23 devnull int vthello(VtConn*);
332 97a5e5f2 2003-11-23 devnull int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
333 97a5e5f2 2003-11-23 devnull int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
334 97a5e5f2 2003-11-23 devnull Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
335 97a5e5f2 2003-11-23 devnull int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
336 97a5e5f2 2003-11-23 devnull int vtsync(VtConn*);
337 97a5e5f2 2003-11-23 devnull int vtping(VtConn*);
340 97a5e5f2 2003-11-23 devnull * Data blocks and block cache.
344 97a5e5f2 2003-11-23 devnull NilBlock = ~0,
347 97a5e5f2 2003-11-23 devnull typedef struct VtBlock VtBlock;
348 97a5e5f2 2003-11-23 devnull typedef struct VtCache VtCache;
350 97a5e5f2 2003-11-23 devnull struct VtBlock
352 97a5e5f2 2003-11-23 devnull VtCache *c;
353 97a5e5f2 2003-11-23 devnull QLock lk;
355 97a5e5f2 2003-11-23 devnull uchar *data;
356 97a5e5f2 2003-11-23 devnull uchar score[VtScoreSize];
357 97a5e5f2 2003-11-23 devnull uchar type; /* BtXXX */
359 97a5e5f2 2003-11-23 devnull /* internal to cache */
360 97a5e5f2 2003-11-23 devnull int nlock;
361 97a5e5f2 2003-11-23 devnull int iostate;
362 97a5e5f2 2003-11-23 devnull int ref;
363 97a5e5f2 2003-11-23 devnull u32int heap;
364 97a5e5f2 2003-11-23 devnull VtBlock *next;
365 97a5e5f2 2003-11-23 devnull VtBlock **prev;
366 97a5e5f2 2003-11-23 devnull u32int used;
367 97a5e5f2 2003-11-23 devnull u32int used2;
368 97a5e5f2 2003-11-23 devnull u32int addr;
370 97a5e5f2 2003-11-23 devnull /* internal to efile (HACK) */
371 97a5e5f2 2003-11-23 devnull int decrypted;
374 97a5e5f2 2003-11-23 devnull u32int vtglobaltolocal(uchar[VtScoreSize]);
375 97a5e5f2 2003-11-23 devnull void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
377 97a5e5f2 2003-11-23 devnull VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
378 97a5e5f2 2003-11-23 devnull void vtcachefree(VtCache*);
379 97a5e5f2 2003-11-23 devnull VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
380 97a5e5f2 2003-11-23 devnull VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
381 97a5e5f2 2003-11-23 devnull VtBlock *vtcacheallocblock(VtCache*, int type);
382 97a5e5f2 2003-11-23 devnull void vtblockput(VtBlock*);
383 97a5e5f2 2003-11-23 devnull u32int vtcacheblocksize(VtCache*);
384 97a5e5f2 2003-11-23 devnull int vtblockwrite(VtBlock*);
385 97a5e5f2 2003-11-23 devnull VtBlock *vtblockcopy(VtBlock*);
386 97a5e5f2 2003-11-23 devnull void vtblockduplock(VtBlock*);
389 97a5e5f2 2003-11-23 devnull * Hash tree file tree.
391 97a5e5f2 2003-11-23 devnull typedef struct VtFile VtFile;
395 97a5e5f2 2003-11-23 devnull VtOREAD,
396 97a5e5f2 2003-11-23 devnull VtOWRITE,
397 97a5e5f2 2003-11-23 devnull VtORDWR,
398 97a5e5f2 2003-11-23 devnull VtOCREATE = 0x100,
401 97a5e5f2 2003-11-23 devnull VtFile *vtfileopenroot(VtCache*, VtEntry*);
402 97a5e5f2 2003-11-23 devnull VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
403 97a5e5f2 2003-11-23 devnull VtFile *vtfileopen(VtFile*, u32int, int);
404 97a5e5f2 2003-11-23 devnull VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
405 97a5e5f2 2003-11-23 devnull VtBlock *vtfileblock(VtFile*, u32int, int mode);
406 97a5e5f2 2003-11-23 devnull int vtfileblockhash(VtFile*, u32int, uchar[VtScoreSize]);
407 97a5e5f2 2003-11-23 devnull long vtfileread(VtFile*, void*, long, vlong);
408 97a5e5f2 2003-11-23 devnull long vtfilewrite(VtFile*, void*, long, vlong);
409 97a5e5f2 2003-11-23 devnull int vtfileflush(VtFile*);
410 97a5e5f2 2003-11-23 devnull void vtfileincref(VtFile*);
411 97a5e5f2 2003-11-23 devnull void vtfileclose(VtFile*);
412 97a5e5f2 2003-11-23 devnull int vtfilegetentry(VtFile*, VtEntry*);
413 97a5e5f2 2003-11-23 devnull int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
414 97a5e5f2 2003-11-23 devnull u32int vtfilegetdirsize(VtFile*);
415 97a5e5f2 2003-11-23 devnull int vtfilesetdirsize(VtFile*, u32int);
416 97a5e5f2 2003-11-23 devnull void vtfileunlock(VtFile*);
417 97a5e5f2 2003-11-23 devnull int vtfilelock(VtFile*, int);
418 97a5e5f2 2003-11-23 devnull int vtfilelock2(VtFile*, VtFile*, int);
419 97a5e5f2 2003-11-23 devnull int vtfileflushbefore(VtFile*, u64int);
421 f7012583 2003-11-25 devnull #if defined(__cplusplus)