10 /* XXX should be own library? */
19 typedef struct Packet Packet;
20 Packet *packetalloc(void);
21 void packetfree(Packet*);
22 Packet *packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
23 Packet *packetdup(Packet*, int offset, int n);
24 Packet *packetsplit(Packet*, int n);
25 int packetconsume(Packet*, uchar *buf, int n);
26 int packettrim(Packet*, int offset, int n);
27 uchar *packetheader(Packet*, int n);
28 uchar *packettrailer(Packet*, int n);
29 void packetprefix(Packet*, uchar *buf, int n);
30 void packetappend(Packet*, uchar *buf, int n);
31 void packetconcat(Packet*, Packet*);
32 uchar *packetpeek(Packet*, uchar *buf, int offset, int n);
33 int packetcopy(Packet*, uchar *buf, int offset, int n);
34 int packetfragments(Packet*, IOchunk*, int nio, int offset);
35 uint packetsize(Packet*);
36 uint packetasize(Packet*);
37 int packetcompact(Packet*);
38 int packetcmp(Packet*, Packet*);
39 void packetstats(void);
40 void packetsha1(Packet*, uchar sha1[20]);
42 /* XXX should be own library? */
46 typedef struct VtLog VtLog;
47 typedef struct VtLogChunk VtLogChunk;
51 VtLog *next; /* in hash table */
67 VtLog *vtlogopen(char *name, uint size);
68 void vtlogprint(VtLog *log, char *fmt, ...);
69 void vtlog(char *name, char *fmt, ...);
70 void vtlogclose(VtLog*);
71 void vtlogremove(char *name);
72 char **vtlognames(int*);
73 void vtlogdump(int fd, VtLog*);
75 /* XXX begin actual venti.h */
77 typedef struct VtFcall VtFcall;
78 typedef struct VtConn VtConn;
79 typedef struct VtEntry VtEntry;
80 typedef struct VtRoot VtRoot;
83 * Fundamental constants.
88 VtMaxStringSize = 1024,
91 #define VtMaxFileSize ((1ULL<<48)-1)
97 int vtputstring(Packet*, char*);
98 int vtgetstring(Packet*, char**);
103 * The initial Venti protocol had a much
104 * less regular list of block types.
105 * VtToDiskType converts from new to old.
110 /* VtDataType+1, ... */
112 /* VtDirType+1, ... */
115 VtCorruptType = 0xFF,
118 VtTypeBaseMask = ~VtTypeDepthMask
121 /* convert to/from on-disk type numbers */
122 uint vttodisktype(uint);
123 uint vtfromdisktype(uint);
126 * VtEntry describes a Venti stream
128 * The _ enums are only used on the wire.
129 * They are not present in the VtEntry structure
130 * and should not be used by client programs.
131 * (The info is in the type field.)
135 VtEntryActive = 1<<0, /* entry is in use */
136 _VtEntryDir = 1<<1, /* a directory */
137 _VtEntryDepthShift = 2, /* shift for pointer depth */
138 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
139 VtEntryLocal = 1<<5, /* for local storage only */
148 ulong gen; /* generation number */
149 ulong psize; /* pointer block size */
150 ulong dsize; /* data block size */
154 uchar score[VtScoreSize];
157 void vtentrypack(VtEntry*, uchar*, int index);
158 int vtentryunpack(VtEntry*, uchar*, int index);
164 uchar score[VtScoreSize]; /* to a Dir block */
165 ulong blocksize; /* maximum block size */
166 uchar prev[VtScoreSize]; /* last root block */
173 _VtRootVersionBig = 1<<15,
176 void vtrootpack(VtRoot*, uchar*);
177 int vtrootunpack(VtRoot*, uchar*);
180 * score of zero length block
182 extern uchar vtzeroscore[VtScoreSize];
185 * zero extend and truncate blocks
187 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
188 uint vtzerotruncate(int type, uchar *buf, uint n);
191 * parse score: mungs s
193 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
197 * other than noted, these formats all ignore
198 * the width and precision arguments, and all flags
203 int vtscorefmt(Fmt*);
206 * error-checking malloc et al.
210 void *vtmallocz(int);
211 void *vtrealloc(void *p, int);
213 char *vtstrdup(char *);
224 VtCryptoStrengthNone,
225 VtCryptoStrengthAuth,
226 VtCryptoStrengthWeak,
227 VtCryptoStrengthStrong
260 VtRgoodbye, /* not used */
280 char *error; /* Rerror */
282 char *version; /* Thello */
283 char *uid; /* Thello */
284 uchar strength; /* Thello */
285 uchar *crypto; /* Thello */
286 uint ncrypto; /* Thello */
287 uchar *codec; /* Thello */
288 uint ncodec; /* Thello */
289 char *sid; /* Rhello */
290 uchar rcrypto; /* Rhello */
291 uchar rcodec; /* Rhello */
292 uchar *auth; /* TauthX, RauthX */
293 uint nauth; /* TauthX, RauthX */
294 uchar score[VtScoreSize]; /* Tread, Rwrite */
295 uchar blocktype; /* Tread, Twrite */
296 uint count; /* Tread */
297 Packet *data; /* Rread, Twrite */
300 Packet *vtfcallpack(VtFcall*);
301 int vtfcallunpack(VtFcall*, Packet*);
302 void vtfcallclear(VtFcall*);
303 int vtfcallfmt(Fmt*);
333 char addr[256]; /* address of other side */
336 VtConn *vtconn(int infd, int outfd);
337 VtConn *vtdial(char*);
338 void vtfreeconn(VtConn*);
339 int vtsend(VtConn*, Packet*);
340 Packet *vtrecv(VtConn*);
341 int vtversion(VtConn *z);
342 void vtdebug(VtConn *z, char*, ...);
343 void vthangup(VtConn *z);
344 int vtgoodbye(VtConn *z);
346 /* #pragma varargck argpos vtdebug 2 */
349 typedef struct VtSrv VtSrv;
350 typedef struct VtReq VtReq;
360 int vtsrvhello(VtConn*);
361 VtSrv *vtlisten(char *addr);
362 VtReq *vtgetreq(VtSrv*);
363 void vtrespond(VtReq*);
366 Packet *vtrpc(VtConn*, Packet*);
367 Packet *_vtrpc(VtConn*, Packet*, VtFcall*);
368 void vtrecvproc(void*); /* VtConn* */
369 void vtsendproc(void*); /* VtConn* */
371 int vtconnect(VtConn*);
372 int vthello(VtConn*);
373 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
374 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
375 Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
376 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
381 * Data blocks and block cache.
388 typedef struct VtBlock VtBlock;
389 typedef struct VtCache VtCache;
397 uchar score[VtScoreSize];
398 uchar type; /* VtXXX */
401 /* internal to cache */
414 u32int vtglobaltolocal(uchar[VtScoreSize]);
415 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
417 VtCache *vtcachealloc(VtConn*, ulong maxmem);
418 void vtcachefree(VtCache*);
419 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
420 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type, ulong size);
421 VtBlock *vtcacheallocblock(VtCache*, int type, ulong size);
422 void vtcachesetwrite(VtCache*, int(*)(VtConn*,uchar[VtScoreSize],uint,uchar*,int));
423 void vtblockput(VtBlock*);
424 int vtblockwrite(VtBlock*);
425 VtBlock *vtblockcopy(VtBlock*);
426 void vtblockduplock(VtBlock*);
428 extern int vtcachencopy, vtcachenread, vtcachenwrite;
429 extern int vttracelevel;
432 * Hash tree file tree.
434 typedef struct VtFile VtFile;
440 VtBlock *b; /* block containing this file */
441 uchar score[VtScoreSize]; /* score of block containing this file */
442 int bsize; /* size of block */
452 int epb; /* entries per block in parent */
453 u32int offset; /* entry offset in parent */
463 VtFile *vtfileopenroot(VtCache*, VtEntry*);
464 VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
465 VtFile *vtfileopen(VtFile*, u32int, int);
466 VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
467 VtFile *_vtfilecreate(VtFile*, int offset, int psize, int dsize, int dir);
468 VtBlock *vtfileblock(VtFile*, u32int, int mode);
469 long vtfileread(VtFile*, void*, long, vlong);
470 long vtfilewrite(VtFile*, void*, long, vlong);
471 int vtfileflush(VtFile*);
472 void vtfileincref(VtFile*);
473 void vtfileclose(VtFile*);
474 int vtfilegetentry(VtFile*, VtEntry*);
475 int vtfilesetentry(VtFile*, VtEntry*);
476 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
477 u32int vtfilegetdirsize(VtFile*);
478 int vtfilesetdirsize(VtFile*, u32int);
479 void vtfileunlock(VtFile*);
480 int vtfilelock(VtFile*, int);
481 int vtfilelock2(VtFile*, VtFile*, int);
482 int vtfileflushbefore(VtFile*, u64int);
483 int vtfiletruncate(VtFile*);
484 uvlong vtfilegetsize(VtFile*);
485 int vtfilesetsize(VtFile*, u64int);
486 int vtfileremove(VtFile*);
488 extern int vttimefmt(Fmt*);
490 extern int chattyventi;
491 extern int ventidoublechecksha1;
492 extern int ventilogging;
494 extern char *VtServerLog;