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 */
145 ulong gen; /* generation number */
146 ushort psize; /* pointer block size */
147 ushort dsize; /* data block size */
151 uchar score[VtScoreSize];
154 void vtentrypack(VtEntry*, uchar*, int index);
155 int vtentryunpack(VtEntry*, uchar*, int index);
161 uchar score[VtScoreSize]; /* to a Dir block */
162 ushort blocksize; /* maximum block size */
163 uchar prev[VtScoreSize]; /* last root block */
172 void vtrootpack(VtRoot*, uchar*);
173 int vtrootunpack(VtRoot*, uchar*);
176 * score of zero length block
178 extern uchar vtzeroscore[VtScoreSize];
181 * zero extend and truncate blocks
183 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
184 uint vtzerotruncate(int type, uchar *buf, uint n);
187 * parse score: mungs s
189 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
193 * other than noted, these formats all ignore
194 * the width and precision arguments, and all flags
198 #pragma varargck type "V" uchar*
199 #pragma varargck type "F" VtFcall*
200 #pragma varargck type "T" void
201 #pragma varargck type "lT" void
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 ushort 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 #pragma incomplete 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;
391 #pragma incomplete VtCache
399 uchar score[VtScoreSize];
400 uchar type; /* BtXXX */
402 /* internal to cache */
415 u32int vtglobaltolocal(uchar[VtScoreSize]);
416 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
418 VtCache*vtcachealloc(VtConn*, int blocksize, ulong nblocks);
419 void vtcachefree(VtCache*);
420 VtBlock*vtcachelocal(VtCache*, u32int addr, int type);
421 VtBlock*vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
422 VtBlock*vtcacheallocblock(VtCache*, int type);
423 void vtcachesetwrite(VtCache*,
424 int(*)(VtConn*, uchar[VtScoreSize], uint, uchar*, int));
425 void vtblockput(VtBlock*);
426 u32int vtcacheblocksize(VtCache*);
427 int vtblockwrite(VtBlock*);
428 VtBlock*vtblockcopy(VtBlock*);
429 void vtblockduplock(VtBlock*);
431 extern int vtcachencopy, vtcachenread, vtcachenwrite;
432 extern int vttracelevel;
435 * Hash tree file tree.
437 typedef struct VtFile VtFile;
443 VtBlock *b; /* block containing this file */
444 uchar score[VtScoreSize]; /* score of block containing this file */
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;