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 */
70 VtLog *vtlogopen(char *name, uint size);
71 void vtlogprint(VtLog *log, char *fmt, ...);
72 void vtlog(char *name, char *fmt, ...);
73 void vtlogclose(char *name);
74 void vtlogremove(char *name);
75 int vtlogdump(int fd, VtLog*);
77 /* XXX begin actual venti.h */
79 typedef struct VtFcall VtFcall;
80 typedef struct VtConn VtConn;
81 typedef struct VtEntry VtEntry;
82 typedef struct VtRoot VtRoot;
85 * Fundamental constants.
90 VtMaxStringSize = 1024,
91 VtMaxLumpSize = 56*1024,
94 #define VtMaxFileSize ((1ULL<<48)-1)
100 int vtputstring(Packet*, char*);
101 int vtgetstring(Packet*, char**);
106 * The initial Venti protocol had a much
107 * less regular list of block types.
108 * VtToDiskType converts from new to old.
113 /* VtDataType+1, ... */
115 /* VtDirType+1, ... */
118 VtCorruptType = 0xFF,
121 VtTypeBaseMask = ~VtTypeDepthMask,
124 /* convert to/from on-disk type numbers */
125 uint vttodisktype(uint);
126 uint vtfromdisktype(uint);
129 * VtEntry describes a Venti stream
131 * The _ enums are only used on the wire.
132 * They are not present in the VtEntry structure
133 * and should not be used by client programs.
134 * (The info is in the type field.)
138 VtEntryActive = 1<<0, /* entry is in use */
139 _VtEntryDir = 1<<1, /* a directory */
140 _VtEntryDepthShift = 2, /* shift for pointer depth */
141 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
142 VtEntryLocal = 1<<5, /* for local storage only */
150 ulong gen; /* generation number */
151 ushort psize; /* pointer block size */
152 ushort 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 ushort blocksize; /* maximum block size */
168 uchar prev[VtScoreSize]; /* last root block */
177 void vtrootpack(VtRoot*, uchar*);
178 int vtrootunpack(VtRoot*, uchar*);
181 * score of zero length block
183 extern uchar vtzeroscore[VtScoreSize];
186 * zero extend and truncate blocks
188 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
189 uint vtzerotruncate(int type, uchar *buf, uint n);
192 * parse score: mungs s
194 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
198 * other than noted, these formats all ignore
199 * the width and precision arguments, and all flags
204 #pragma varargck type "V" uchar*
205 #pragma varargck type "F" VtFcall*
208 int vtscorefmt(Fmt*);
211 * error-checking malloc et al.
215 void *vtmallocz(int);
216 void *vtrealloc(void *p, int);
218 char *vtstrdup(char *);
229 VtCryptoStrengthNone,
230 VtCryptoStrengthAuth,
231 VtCryptoStrengthWeak,
232 VtCryptoStrengthStrong,
265 VtRgoodbye, /* not used */
285 char *error; /* Rerror */
287 char *version; /* Thello */
288 char *uid; /* Thello */
289 uchar strength; /* Thello */
290 uchar *crypto; /* Thello */
291 uint ncrypto; /* Thello */
292 uchar *codec; /* Thello */
293 uint ncodec; /* Thello */
294 char *sid; /* Rhello */
295 uchar rcrypto; /* Rhello */
296 uchar rcodec; /* Rhello */
297 uchar *auth; /* TauthX, RauthX */
298 uint nauth; /* TauthX, RauthX */
299 uchar score[VtScoreSize]; /* Tread, Rwrite */
300 uchar dtype; /* Tread, Twrite */
301 ushort count; /* Tread */
302 Packet *data; /* Rread, Twrite */
305 Packet *vtfcallpack(VtFcall*);
306 int vtfcallunpack(VtFcall*, Packet*);
307 void vtfcallclear(VtFcall*);
308 int vtfcallfmt(Fmt*);
340 VtConn *vtconn(int infd, int outfd);
341 VtConn *vtdial(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 /* #pragma varargck argpos vtdebug 2 */
351 typedef struct VtSrv VtSrv;
352 typedef struct VtReq VtReq;
362 int vtsrvhello(VtConn*);
363 VtSrv *vtlisten(char *addr);
364 VtReq *vtgetreq(VtSrv*);
365 void vtrespond(VtReq*);
368 Packet *vtrpc(VtConn*, Packet*);
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;
398 uchar score[VtScoreSize];
399 uchar type; /* BtXXX */
401 /* internal to cache */
412 /* internal to efile (HACK) */
416 u32int vtglobaltolocal(uchar[VtScoreSize]);
417 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
419 VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
420 void vtcachefree(VtCache*);
421 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
422 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
423 VtBlock *vtcacheallocblock(VtCache*, int type);
424 void vtcachesetwrite(VtCache*, 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*);
430 int vtblockdirty(VtBlock*);
433 * Hash tree file tree.
435 typedef struct VtFile VtFile;
441 VtBlock *b; /* block containing this file */
442 uchar score[VtScoreSize]; /* score of block containing this file */
451 int epb; /* entries per block in parent */
452 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 VtBlock *vtfileblock(VtFile*, u32int, int mode);
468 long vtfileread(VtFile*, void*, long, vlong);
469 long vtfilewrite(VtFile*, void*, long, vlong);
470 int vtfileflush(VtFile*);
471 void vtfileincref(VtFile*);
472 void vtfileclose(VtFile*);
473 int vtfilegetentry(VtFile*, VtEntry*);
474 int vtfilesetentry(VtFile*, VtEntry*);
475 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
476 u32int vtfilegetdirsize(VtFile*);
477 int vtfilesetdirsize(VtFile*, u32int);
478 void vtfileunlock(VtFile*);
479 int vtfilelock(VtFile*, int);
480 int vtfilelock2(VtFile*, VtFile*, int);
481 int vtfileflushbefore(VtFile*, u64int);
482 int vtfiletruncate(VtFile*);
483 uvlong vtfilegetsize(VtFile*);
484 int vtfilesetsize(VtFile*, uvlong);
485 int vtfileremove(VtFile*);
487 extern int chattyventi;
488 extern int ventidoublechecksha1;