8 #pragma lib "libventi.a"
9 #pragma src "/sys/src/libventi"
14 /* XXX should be own library? */
23 typedef struct Packet Packet;
24 Packet *packetalloc(void);
25 void packetfree(Packet*);
26 Packet *packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
27 Packet *packetdup(Packet*, int offset, int n);
28 Packet *packetsplit(Packet*, int n);
29 int packetconsume(Packet*, uchar *buf, int n);
30 int packettrim(Packet*, int offset, int n);
31 uchar *packetheader(Packet*, int n);
32 uchar *packettrailer(Packet*, int n);
33 void packetprefix(Packet*, uchar *buf, int n);
34 void packetappend(Packet*, uchar *buf, int n);
35 void packetconcat(Packet*, Packet*);
36 uchar *packetpeek(Packet*, uchar *buf, int offset, int n);
37 int packetcopy(Packet*, uchar *buf, int offset, int n);
38 int packetfragments(Packet*, IOchunk*, int nio, int offset);
39 uint packetsize(Packet*);
40 uint packetasize(Packet*);
41 int packetcompact(Packet*);
42 int packetcmp(Packet*, Packet*);
43 void packetstats(void);
44 void packetsha1(Packet*, uchar sha1[20]);
46 /* XXX should be own library? */
50 typedef struct VtLog VtLog;
51 typedef struct VtLogChunk VtLogChunk;
55 VtLog *next; /* in hash table */
71 VtLog *vtlogopen(char *name, uint size);
72 void vtlogprint(VtLog *log, char *fmt, ...);
73 void vtlog(char *name, char *fmt, ...);
74 void vtlogclose(VtLog*);
75 void vtlogremove(char *name);
76 int vtlognames(char***);
77 void vtlogdump(int fd, VtLog*);
79 /* XXX begin actual venti.h */
81 typedef struct VtFcall VtFcall;
82 typedef struct VtConn VtConn;
83 typedef struct VtEntry VtEntry;
84 typedef struct VtRoot VtRoot;
87 * Fundamental constants.
92 VtMaxStringSize = 1024,
93 VtMaxLumpSize = 56*1024,
96 #define VtMaxFileSize ((1ULL<<48)-1)
100 * Strings in packets.
102 int vtputstring(Packet*, char*);
103 int vtgetstring(Packet*, char**);
108 * The initial Venti protocol had a much
109 * less regular list of block types.
110 * VtToDiskType converts from new to old.
115 /* VtDataType+1, ... */
117 /* VtDirType+1, ... */
120 VtCorruptType = 0xFF,
123 VtTypeBaseMask = ~VtTypeDepthMask,
126 /* convert to/from on-disk type numbers */
127 uint vttodisktype(uint);
128 uint vtfromdisktype(uint);
131 * VtEntry describes a Venti stream
133 * The _ enums are only used on the wire.
134 * They are not present in the VtEntry structure
135 * and should not be used by client programs.
136 * (The info is in the type field.)
140 VtEntryActive = 1<<0, /* entry is in use */
141 _VtEntryDir = 1<<1, /* a directory */
142 _VtEntryDepthShift = 2, /* shift for pointer depth */
143 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
144 VtEntryLocal = 1<<5, /* for local storage only */
152 ulong gen; /* generation number */
153 ushort psize; /* pointer block size */
154 ushort dsize; /* data block size */
158 uchar score[VtScoreSize];
161 void vtentrypack(VtEntry*, uchar*, int index);
162 int vtentryunpack(VtEntry*, uchar*, int index);
168 uchar score[VtScoreSize]; /* to a Dir block */
169 ushort blocksize; /* maximum block size */
170 uchar prev[VtScoreSize]; /* last root block */
179 void vtrootpack(VtRoot*, uchar*);
180 int vtrootunpack(VtRoot*, uchar*);
183 * score of zero length block
185 extern uchar vtzeroscore[VtScoreSize];
188 * zero extend and truncate blocks
190 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
191 uint vtzerotruncate(int type, uchar *buf, uint n);
194 * parse score: mungs s
196 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
200 * other than noted, these formats all ignore
201 * the width and precision arguments, and all flags
206 #pragma varargck type "V" uchar*
207 #pragma varargck type "F" VtFcall*
210 int vtscorefmt(Fmt*);
213 * error-checking malloc et al.
217 void *vtmallocz(int);
218 void *vtrealloc(void *p, int);
220 char *vtstrdup(char *);
231 VtCryptoStrengthNone,
232 VtCryptoStrengthAuth,
233 VtCryptoStrengthWeak,
234 VtCryptoStrengthStrong,
267 VtRgoodbye, /* not used */
287 char *error; /* Rerror */
289 char *version; /* Thello */
290 char *uid; /* Thello */
291 uchar strength; /* Thello */
292 uchar *crypto; /* Thello */
293 uint ncrypto; /* Thello */
294 uchar *codec; /* Thello */
295 uint ncodec; /* Thello */
296 char *sid; /* Rhello */
297 uchar rcrypto; /* Rhello */
298 uchar rcodec; /* Rhello */
299 uchar *auth; /* TauthX, RauthX */
300 uint nauth; /* TauthX, RauthX */
301 uchar score[VtScoreSize]; /* Tread, Rwrite */
302 uchar dtype; /* Tread, Twrite */
303 ushort count; /* Tread */
304 Packet *data; /* Rread, Twrite */
307 Packet *vtfcallpack(VtFcall*);
308 int vtfcallunpack(VtFcall*, Packet*);
309 void vtfcallclear(VtFcall*);
310 int vtfcallfmt(Fmt*);
340 char addr[256]; /* address of other side */
343 VtConn *vtconn(int infd, int outfd);
344 VtConn *vtdial(char*);
345 void vtfreeconn(VtConn*);
346 int vtsend(VtConn*, Packet*);
347 Packet *vtrecv(VtConn*);
348 int vtversion(VtConn *z);
349 void vtdebug(VtConn *z, char*, ...);
350 void vthangup(VtConn *z);
351 /* #pragma varargck argpos vtdebug 2 */
354 typedef struct VtSrv VtSrv;
355 typedef struct VtReq VtReq;
365 int vtsrvhello(VtConn*);
366 VtSrv *vtlisten(char *addr);
367 VtReq *vtgetreq(VtSrv*);
368 void vtrespond(VtReq*);
371 Packet *vtrpc(VtConn*, Packet*);
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; /* BtXXX */
404 /* internal to cache */
415 /* internal to efile (HACK) */
419 u32int vtglobaltolocal(uchar[VtScoreSize]);
420 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
422 VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
423 void vtcachefree(VtCache*);
424 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
425 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
426 VtBlock *vtcacheallocblock(VtCache*, int type);
427 void vtcachesetwrite(VtCache*, int(*)(VtConn*,uchar[VtScoreSize],uint,uchar*,int));
428 void vtblockput(VtBlock*);
429 u32int vtcacheblocksize(VtCache*);
430 int vtblockwrite(VtBlock*);
431 VtBlock *vtblockcopy(VtBlock*);
432 void vtblockduplock(VtBlock*);
433 int vtblockdirty(VtBlock*);
436 * Hash tree file tree.
438 typedef struct VtFile VtFile;
444 VtBlock *b; /* block containing this file */
445 uchar score[VtScoreSize]; /* score of block containing this file */
454 int epb; /* entries per block in parent */
455 u32int offset; /* entry offset in parent */
466 VtFile *vtfileopenroot(VtCache*, VtEntry*);
467 VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
468 VtFile *vtfileopen(VtFile*, u32int, int);
469 VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
470 VtBlock *vtfileblock(VtFile*, u32int, int mode);
471 long vtfileread(VtFile*, void*, long, vlong);
472 long vtfilewrite(VtFile*, void*, long, vlong);
473 int vtfileflush(VtFile*);
474 void vtfileincref(VtFile*);
475 void vtfileclose(VtFile*);
476 int vtfilegetentry(VtFile*, VtEntry*);
477 int vtfilesetentry(VtFile*, VtEntry*);
478 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
479 u32int vtfilegetdirsize(VtFile*);
480 int vtfilesetdirsize(VtFile*, u32int);
481 void vtfileunlock(VtFile*);
482 int vtfilelock(VtFile*, int);
483 int vtfilelock2(VtFile*, VtFile*, int);
484 int vtfileflushbefore(VtFile*, u64int);
485 int vtfiletruncate(VtFile*);
486 uvlong vtfilegetsize(VtFile*);
487 int vtfilesetsize(VtFile*, uvlong);
488 int vtfileremove(VtFile*);
490 extern int chattyventi;
491 extern int ventidoublechecksha1;
492 extern int ventilogging;
494 extern char *VtServerLog;