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 */
142 VtEntryNoArchive = 1<<7, /* for local storage only */
150 ulong gen; /* generation number */
151 ulong psize; /* pointer block size */
152 ulong dsize; /* data block size */
156 uchar score[VtScoreSize];
159 void vtentrypack(VtEntry*, uchar*, int index);
160 int vtentryunpack(VtEntry*, uchar*, int index);
166 uchar score[VtScoreSize]; /* to a Dir block */
167 ulong blocksize; /* maximum block size */
168 uchar prev[VtScoreSize]; /* last root block */
175 _VtRootVersionBig = 1<<15,
178 void vtrootpack(VtRoot*, uchar*);
179 int vtrootunpack(VtRoot*, uchar*);
182 * score of zero length block
184 extern uchar vtzeroscore[VtScoreSize];
187 * zero extend and truncate blocks
189 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
190 uint vtzerotruncate(int type, uchar *buf, uint n);
193 * parse score: mungs s
195 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
199 * other than noted, these formats all ignore
200 * the width and precision arguments, and all flags
205 int vtscorefmt(Fmt*);
208 * error-checking malloc et al.
212 void* vtmallocz(int);
213 void* vtrealloc(void *p, int);
215 char* vtstrdup(char *);
226 VtCryptoStrengthNone,
227 VtCryptoStrengthAuth,
228 VtCryptoStrengthWeak,
229 VtCryptoStrengthStrong
262 VtRgoodbye, /* not used */
282 char *error; /* Rerror */
284 char *version; /* Thello */
285 char *uid; /* Thello */
286 uchar strength; /* Thello */
287 uchar *crypto; /* Thello */
288 uint ncrypto; /* Thello */
289 uchar *codec; /* Thello */
290 uint ncodec; /* Thello */
291 char *sid; /* Rhello */
292 uchar rcrypto; /* Rhello */
293 uchar rcodec; /* Rhello */
294 uchar *auth; /* TauthX, RauthX */
295 uint nauth; /* TauthX, RauthX */
296 uchar score[VtScoreSize]; /* Tread, Rwrite */
297 uchar blocktype; /* Tread, Twrite */
298 uint count; /* Tread */
299 Packet *data; /* Rread, Twrite */
302 Packet* vtfcallpack(VtFcall*);
303 int vtfcallunpack(VtFcall*, Packet*);
304 void vtfcallclear(VtFcall*);
305 int vtfcallfmt(Fmt*);
335 char addr[256]; /* address of other side */
338 VtConn* vtconn(int infd, int outfd);
339 int vtreconn(VtConn*, int, int);
340 VtConn* vtdial(char*);
341 int vtredial(VtConn*, char *);
342 void vtfreeconn(VtConn*);
343 int vtsend(VtConn*, Packet*);
344 Packet* vtrecv(VtConn*);
345 int vtversion(VtConn* z);
346 void vtdebug(VtConn* z, char*, ...);
347 void vthangup(VtConn* z);
348 int vtgoodbye(VtConn* z);
350 /* #pragma varargck argpos vtdebug 2 */
353 typedef struct VtSrv VtSrv;
354 typedef struct VtReq VtReq;
364 int vtsrvhello(VtConn*);
365 VtSrv* vtlisten(char *addr);
366 VtReq* vtgetreq(VtSrv*);
367 void vtrespond(VtReq*);
370 Packet* vtrpc(VtConn*, Packet*);
371 Packet* _vtrpc(VtConn*, Packet*, VtFcall*);
372 void vtrecvproc(void*); /* VtConn */
373 void vtsendproc(void*); /* VtConn */
375 int vtconnect(VtConn*);
376 int vthello(VtConn*);
377 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
378 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
379 Packet* vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
380 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
385 * Data blocks and block cache.
392 typedef struct VtBlock VtBlock;
393 typedef struct VtCache VtCache;
401 uchar score[VtScoreSize];
402 uchar type; /* VtXXX */
405 /* internal to cache */
418 u32int vtglobaltolocal(uchar[VtScoreSize]);
419 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
421 VtCache*vtcachealloc(VtConn*, ulong maxmem);
422 void vtcachefree(VtCache*);
423 VtBlock*vtcachelocal(VtCache*, u32int addr, int type);
424 VtBlock*vtcacheglobal(VtCache*, uchar[VtScoreSize], int type, ulong size);
425 VtBlock*vtcacheallocblock(VtCache*, int type, ulong size);
426 void vtcachesetwrite(VtCache*,
427 int(*)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
428 void vtblockput(VtBlock*);
429 int vtblockwrite(VtBlock*);
430 VtBlock*vtblockcopy(VtBlock*);
431 void vtblockduplock(VtBlock*);
433 extern int vtcachencopy, vtcachenread, vtcachenwrite;
434 extern int vttracelevel;
437 * Hash tree file tree.
439 typedef struct VtFile VtFile;
445 VtBlock *b; /* block containing this file */
446 uchar score[VtScoreSize]; /* score of block containing this file */
447 int bsize; /* size of block */
457 int epb; /* entries per block in parent */
458 u32int offset; /* entry offset in parent */
468 VtBlock*vtfileblock(VtFile*, u32int, int mode);
469 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
470 void vtfileclose(VtFile*);
471 VtFile* _vtfilecreate(VtFile*, int offset, int psize, int dsize, int dir);
472 VtFile* vtfilecreate(VtFile*, int psize, int dsize, int dir);
473 VtFile* vtfilecreateroot(VtCache*, int psize, int dsize, int type);
474 int vtfileflush(VtFile*);
475 int vtfileflushbefore(VtFile*, u64int);
476 u32int vtfilegetdirsize(VtFile*);
477 int vtfilegetentry(VtFile*, VtEntry*);
478 uvlong vtfilegetsize(VtFile*);
479 void vtfileincref(VtFile*);
480 int vtfilelock2(VtFile*, VtFile*, int);
481 int vtfilelock(VtFile*, int);
482 VtFile* vtfileopen(VtFile*, u32int, int);
483 VtFile* vtfileopenroot(VtCache*, VtEntry*);
484 long vtfileread(VtFile*, void*, long, vlong);
485 int vtfileremove(VtFile*);
486 int vtfilesetdirsize(VtFile*, u32int);
487 int vtfilesetentry(VtFile*, VtEntry*);
488 int vtfilesetsize(VtFile*, u64int);
489 int vtfiletruncate(VtFile*);
490 void vtfileunlock(VtFile*);
491 long vtfilewrite(VtFile*, void*, long, vlong);
495 extern int chattyventi;
496 extern int ventidoublechecksha1;
497 extern int ventilogging;
499 extern char *VtServerLog;