1 #pragma lib "libventi.a"
2 #pragma src "/sys/src/libventi"
5 /* XXX should be own library? */
14 typedef struct Packet Packet;
15 #pragma incomplete Packet
17 Packet* packetalloc(void);
18 void packetappend(Packet*, uchar *buf, int n);
19 uint packetasize(Packet*);
20 int packetcmp(Packet*, Packet*);
21 int packetcompact(Packet*);
22 void packetconcat(Packet*, Packet*);
23 int packetconsume(Packet*, uchar *buf, int n);
24 int packetcopy(Packet*, uchar *buf, int offset, int n);
25 Packet* packetdup(Packet*, int offset, int n);
26 Packet* packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
27 int packetfragments(Packet*, IOchunk*, int nio, int offset);
28 void packetfree(Packet*);
29 uchar* packetheader(Packet*, int n);
30 uchar* packetpeek(Packet*, uchar *buf, int offset, int n);
31 void packetprefix(Packet*, uchar *buf, int n);
32 void packetsha1(Packet*, uchar sha1[20]);
33 uint packetsize(Packet*);
34 Packet* packetsplit(Packet*, int n);
35 void packetstats(void);
36 uchar* packettrailer(Packet*, int n);
37 int packettrim(Packet*, int offset, int n);
39 /* XXX should be own library? */
43 typedef struct VtLog VtLog;
44 typedef struct VtLogChunk VtLogChunk;
48 VtLog *next; /* in hash table */
64 VtLog* vtlogopen(char *name, uint size);
65 void vtlogprint(VtLog *log, char *fmt, ...);
66 void vtlog(char *name, char *fmt, ...);
67 void vtlogclose(VtLog*);
68 void vtlogremove(char *name);
69 char** vtlognames(int*);
70 void vtlogdump(int fd, VtLog*);
72 /* XXX begin actual venti.h */
74 typedef struct VtFcall VtFcall;
75 typedef struct VtConn VtConn;
76 typedef struct VtEntry VtEntry;
77 typedef struct VtRoot VtRoot;
80 * Fundamental constants.
85 VtMaxStringSize = 1024,
86 VtMaxLumpSize = 56*1024,
89 #define VtMaxFileSize ((1ULL<<48)-1)
95 int vtputstring(Packet*, char*);
96 int vtgetstring(Packet*, char**);
101 * The initial Venti protocol had a much
102 * less regular list of block types.
103 * VtToDiskType converts from new to old.
108 /* VtDataType+1, ... */
110 /* VtDirType+1, ... */
113 VtCorruptType = 0xFF,
116 VtTypeBaseMask = ~VtTypeDepthMask
119 /* convert to/from on-disk type numbers */
120 uint vttodisktype(uint);
121 uint vtfromdisktype(uint);
124 * VtEntry describes a Venti stream
126 * The _ enums are only used on the wire.
127 * They are not present in the VtEntry structure
128 * and should not be used by client programs.
129 * (The info is in the type field.)
133 VtEntryActive = 1<<0, /* entry is in use */
134 _VtEntryDir = 1<<1, /* a directory */
135 _VtEntryDepthShift = 2, /* shift for pointer depth */
136 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
137 VtEntryLocal = 1<<5, /* for local storage only */
138 VtEntryNoArchive = 1<<6 /* for local storage only */
146 ulong gen; /* generation number */
147 ushort psize; /* pointer block size */
148 ushort dsize; /* data block size */
152 uchar score[VtScoreSize];
155 void vtentrypack(VtEntry*, uchar*, int index);
156 int vtentryunpack(VtEntry*, uchar*, int index);
162 uchar score[VtScoreSize]; /* to a Dir block */
163 ushort blocksize; /* maximum block size */
164 uchar prev[VtScoreSize]; /* last root block */
173 void vtrootpack(VtRoot*, uchar*);
174 int vtrootunpack(VtRoot*, uchar*);
177 * score of zero length block
179 extern uchar vtzeroscore[VtScoreSize];
182 * zero extend and truncate blocks
184 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
185 uint vtzerotruncate(int type, uchar *buf, uint n);
188 * parse score: mungs s
190 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
194 * other than noted, these formats all ignore
195 * the width and precision arguments, and all flags
199 #pragma varargck type "V" uchar*
200 #pragma varargck type "F" VtFcall*
201 #pragma varargck type "T" void
202 #pragma varargck type "lT" void
204 int vtscorefmt(Fmt*);
207 * error-checking malloc et al.
210 void* vtmalloc(ulong);
211 void* vtmallocz(ulong);
212 void* vtrealloc(void *p, ulong);
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 ushort 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 int vtreconn(VtConn*, int, int);
339 VtConn* vtdial(char*);
340 int vtredial(VtConn*, char*);
341 void vtfreeconn(VtConn*);
342 int vtsend(VtConn*, Packet*);
343 Packet* vtrecv(VtConn*);
344 int vtversion(VtConn* z);
345 void vtdebug(VtConn* z, char*, ...);
346 void vthangup(VtConn* z);
347 int vtgoodbye(VtConn* z);
349 /* #pragma varargck argpos vtdebug 2 */
352 typedef struct VtSrv VtSrv;
353 #pragma incomplete 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 void vtsha1(uchar score[VtScoreSize], uchar*, int);
386 int vtsha1check(uchar score[VtScoreSize], uchar*, int);
389 * Data blocks and block cache.
396 typedef struct VtBlock VtBlock;
397 typedef struct VtCache VtCache;
398 #pragma incomplete VtCache
406 uchar score[VtScoreSize];
407 uchar type; /* BtXXX */
409 /* internal to cache */
422 u32int vtglobaltolocal(uchar[VtScoreSize]);
423 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
425 VtCache*vtcachealloc(VtConn*, int blocksize, ulong nblocks);
426 void vtcachefree(VtCache*);
427 VtBlock*vtcachelocal(VtCache*, u32int addr, int type);
428 VtBlock*vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
429 VtBlock*vtcacheallocblock(VtCache*, int type);
430 void vtcachesetwrite(VtCache*,
431 int(*)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
432 void vtblockput(VtBlock*);
433 u32int vtcacheblocksize(VtCache*);
434 int vtblockwrite(VtBlock*);
435 VtBlock*vtblockcopy(VtBlock*);
436 void vtblockduplock(VtBlock*);
438 extern int vtcachencopy, vtcachenread, vtcachenwrite;
439 extern int vttracelevel;
442 * Hash tree file tree.
444 typedef struct VtFile VtFile;
450 VtBlock *b; /* block containing this file */
451 uchar score[VtScoreSize]; /* score of block containing this file */
461 int epb; /* entries per block in parent */
462 u32int offset; /* entry offset in parent */
472 VtBlock*vtfileblock(VtFile*, u32int, int mode);
473 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
474 void vtfileclose(VtFile*);
475 VtFile* _vtfilecreate(VtFile*, int offset, int psize, int dsize, int dir);
476 VtFile* vtfilecreate(VtFile*, int psize, int dsize, int dir);
477 VtFile* vtfilecreateroot(VtCache*, int psize, int dsize, int type);
478 int vtfileflush(VtFile*);
479 int vtfileflushbefore(VtFile*, u64int);
480 u32int vtfilegetdirsize(VtFile*);
481 int vtfilegetentry(VtFile*, VtEntry*);
482 uvlong vtfilegetsize(VtFile*);
483 void vtfileincref(VtFile*);
484 int vtfilelock2(VtFile*, VtFile*, int);
485 int vtfilelock(VtFile*, int);
486 VtFile* vtfileopen(VtFile*, u32int, int);
487 VtFile* vtfileopenroot(VtCache*, VtEntry*);
488 long vtfileread(VtFile*, void*, long, vlong);
489 int vtfileremove(VtFile*);
490 int vtfilesetdirsize(VtFile*, u32int);
491 int vtfilesetentry(VtFile*, VtEntry*);
492 int vtfilesetsize(VtFile*, u64int);
493 int vtfiletruncate(VtFile*);
494 void vtfileunlock(VtFile*);
495 long vtfilewrite(VtFile*, void*, long, vlong);
499 extern int chattyventi;
500 extern int ventidoublechecksha1;
501 extern int ventilogging;
503 extern char *VtServerLog;