10 /* XXX should be own library? */
19 typedef struct Packet Packet;
21 Packet* packetalloc(void);
22 void packetappend(Packet*, uchar *buf, int n);
23 uint packetasize(Packet*);
24 int packetcmp(Packet*, Packet*);
25 int packetcompact(Packet*);
26 void packetconcat(Packet*, Packet*);
27 int packetconsume(Packet*, uchar *buf, int n);
28 int packetcopy(Packet*, uchar *buf, int offset, int n);
29 Packet* packetdup(Packet*, int offset, int n);
30 Packet* packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
31 int packetfragments(Packet*, IOchunk*, int nio, int offset);
32 void packetfree(Packet*);
33 uchar* packetheader(Packet*, int n);
34 uchar* packetpeek(Packet*, uchar *buf, int offset, int n);
35 void packetprefix(Packet*, uchar *buf, int n);
36 void packetsha1(Packet*, uchar sha1[20]);
37 uint packetsize(Packet*);
38 Packet* packetsplit(Packet*, int n);
39 void packetstats(void);
40 uchar* packettrailer(Packet*, int n);
41 int packettrim(Packet*, int offset, int n);
43 /* XXX should be own library? */
47 typedef struct VtLog VtLog;
48 typedef struct VtLogChunk VtLogChunk;
52 VtLog *next; /* in hash table */
68 VtLog* vtlogopen(char *name, uint size);
69 void vtlogprint(VtLog *log, char *fmt, ...);
70 void vtlog(char *name, char *fmt, ...);
71 void vtlogclose(VtLog*);
72 void vtlogremove(char *name);
73 char** vtlognames(int*);
74 void vtlogdump(int fd, VtLog*);
76 /* XXX begin actual venti.h */
78 typedef struct VtFcall VtFcall;
79 typedef struct VtConn VtConn;
80 typedef struct VtEntry VtEntry;
81 typedef struct VtRoot VtRoot;
84 * Fundamental constants.
89 VtMaxStringSize = 1024,
92 #define VtMaxFileSize ((1ULL<<48)-1)
98 int vtputstring(Packet*, char*);
99 int vtgetstring(Packet*, char**);
104 * The initial Venti protocol had a much
105 * less regular list of block types.
106 * VtToDiskType converts from new to old.
111 /* VtDataType+1, ... */
113 /* VtDirType+1, ... */
116 VtCorruptType = 0xFF,
119 VtTypeBaseMask = ~VtTypeDepthMask
122 /* convert to/from on-disk type numbers */
123 uint vttodisktype(uint);
124 uint vtfromdisktype(uint);
127 * VtEntry describes a Venti stream
129 * The _ enums are only used on the wire.
130 * They are not present in the VtEntry structure
131 * and should not be used by client programs.
132 * (The info is in the type field.)
136 VtEntryActive = 1<<0, /* entry is in use */
137 _VtEntryDir = 1<<1, /* a directory */
138 _VtEntryDepthShift = 2, /* shift for pointer depth */
139 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
140 VtEntryLocal = 1<<5, /* for local storage only */
149 ulong gen; /* generation number */
150 ulong psize; /* pointer block size */
151 ulong dsize; /* data block size */
155 uchar score[VtScoreSize];
158 void vtentrypack(VtEntry*, uchar*, int index);
159 int vtentryunpack(VtEntry*, uchar*, int index);
165 uchar score[VtScoreSize]; /* to a Dir block */
166 ulong blocksize; /* maximum block size */
167 uchar prev[VtScoreSize]; /* last root block */
174 _VtRootVersionBig = 1<<15,
177 void vtrootpack(VtRoot*, uchar*);
178 int vtrootunpack(VtRoot*, uchar*);
181 * score of zero length block
183 extern uchar vtzeroscore[VtScoreSize];
186 * zero extend and truncate blocks
188 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
189 uint vtzerotruncate(int type, uchar *buf, uint n);
192 * parse score: mungs s
194 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
198 * other than noted, these formats all ignore
199 * the width and precision arguments, and all flags
204 int vtscorefmt(Fmt*);
207 * error-checking malloc et al.
211 void* vtmallocz(int);
212 void* vtrealloc(void *p, int);
214 char* vtstrdup(char *);
225 VtCryptoStrengthNone,
226 VtCryptoStrengthAuth,
227 VtCryptoStrengthWeak,
228 VtCryptoStrengthStrong
261 VtRgoodbye, /* not used */
281 char *error; /* Rerror */
283 char *version; /* Thello */
284 char *uid; /* Thello */
285 uchar strength; /* Thello */
286 uchar *crypto; /* Thello */
287 uint ncrypto; /* Thello */
288 uchar *codec; /* Thello */
289 uint ncodec; /* Thello */
290 char *sid; /* Rhello */
291 uchar rcrypto; /* Rhello */
292 uchar rcodec; /* Rhello */
293 uchar *auth; /* TauthX, RauthX */
294 uint nauth; /* TauthX, RauthX */
295 uchar score[VtScoreSize]; /* Tread, Rwrite */
296 uchar blocktype; /* Tread, Twrite */
297 uint count; /* Tread */
298 Packet *data; /* Rread, Twrite */
301 Packet* vtfcallpack(VtFcall*);
302 int vtfcallunpack(VtFcall*, Packet*);
303 void vtfcallclear(VtFcall*);
304 int vtfcallfmt(Fmt*);
334 char addr[256]; /* address of other side */
337 VtConn* vtconn(int infd, int outfd);
338 VtConn* vtdial(char*);
339 void vtfreeconn(VtConn*);
340 int vtsend(VtConn*, Packet*);
341 Packet* vtrecv(VtConn*);
342 int vtversion(VtConn* z);
343 void vtdebug(VtConn* z, char*, ...);
344 void vthangup(VtConn* z);
345 int vtgoodbye(VtConn* z);
347 /* #pragma varargck argpos vtdebug 2 */
350 typedef struct VtSrv VtSrv;
351 typedef struct VtReq VtReq;
361 int vtsrvhello(VtConn*);
362 VtSrv* vtlisten(char *addr);
363 VtReq* vtgetreq(VtSrv*);
364 void vtrespond(VtReq*);
367 Packet* vtrpc(VtConn*, Packet*);
368 Packet* _vtrpc(VtConn*, Packet*, VtFcall*);
369 void vtrecvproc(void*); /* VtConn */
370 void vtsendproc(void*); /* VtConn */
372 int vtconnect(VtConn*);
373 int vthello(VtConn*);
374 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
375 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
376 Packet* vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
377 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
382 * Data blocks and block cache.
389 typedef struct VtBlock VtBlock;
390 typedef struct VtCache VtCache;
398 uchar score[VtScoreSize];
399 uchar type; /* VtXXX */
402 /* internal to cache */
415 u32int vtglobaltolocal(uchar[VtScoreSize]);
416 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
418 VtCache*vtcachealloc(VtConn*, ulong maxmem);
419 void vtcachefree(VtCache*);
420 VtBlock*vtcachelocal(VtCache*, u32int addr, int type);
421 VtBlock*vtcacheglobal(VtCache*, uchar[VtScoreSize], int type, ulong size);
422 VtBlock*vtcacheallocblock(VtCache*, int type, ulong size);
423 void vtcachesetwrite(VtCache*,
424 int(*)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
425 void vtblockput(VtBlock*);
426 int vtblockwrite(VtBlock*);
427 VtBlock*vtblockcopy(VtBlock*);
428 void vtblockduplock(VtBlock*);
430 extern int vtcachencopy, vtcachenread, vtcachenwrite;
431 extern int vttracelevel;
434 * Hash tree file tree.
436 typedef struct VtFile VtFile;
442 VtBlock *b; /* block containing this file */
443 uchar score[VtScoreSize]; /* score of block containing this file */
444 int bsize; /* size of block */
454 int epb; /* entries per block in parent */
455 u32int offset; /* entry offset in parent */
465 VtBlock*vtfileblock(VtFile*, u32int, int mode);
466 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
467 void vtfileclose(VtFile*);
468 VtFile* _vtfilecreate(VtFile*, int offset, int psize, int dsize, int dir);
469 VtFile* vtfilecreate(VtFile*, int psize, int dsize, int dir);
470 VtFile* vtfilecreateroot(VtCache*, int psize, int dsize, int type);
471 int vtfileflush(VtFile*);
472 int vtfileflushbefore(VtFile*, u64int);
473 u32int vtfilegetdirsize(VtFile*);
474 int vtfilegetentry(VtFile*, VtEntry*);
475 uvlong vtfilegetsize(VtFile*);
476 void vtfileincref(VtFile*);
477 int vtfilelock2(VtFile*, VtFile*, int);
478 int vtfilelock(VtFile*, int);
479 VtFile* vtfileopen(VtFile*, u32int, int);
480 VtFile* vtfileopenroot(VtCache*, VtEntry*);
481 long vtfileread(VtFile*, void*, long, vlong);
482 int vtfileremove(VtFile*);
483 int vtfilesetdirsize(VtFile*, u32int);
484 int vtfilesetentry(VtFile*, VtEntry*);
485 int vtfilesetsize(VtFile*, u64int);
486 int vtfiletruncate(VtFile*);
487 void vtfileunlock(VtFile*);
488 long vtfilewrite(VtFile*, void*, long, vlong);
492 extern int chattyventi;
493 extern int ventidoublechecksha1;
494 extern int ventilogging;
496 extern char *VtServerLog;