9 /* XXX should be own library? */
18 typedef struct Packet Packet;
19 Packet *packetalloc(void);
20 void packetfree(Packet*);
21 Packet *packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
22 Packet *packetdup(Packet*, int offset, int n);
23 Packet *packetsplit(Packet*, int n);
24 int packetconsume(Packet*, uchar *buf, int n);
25 int packettrim(Packet*, int offset, int n);
26 uchar *packetheader(Packet*, int n);
27 uchar *packettrailer(Packet*, int n);
28 void packetprefix(Packet*, uchar *buf, int n);
29 void packetappend(Packet*, uchar *buf, int n);
30 void packetconcat(Packet*, Packet*);
31 uchar *packetpeek(Packet*, uchar *buf, int offset, int n);
32 int packetcopy(Packet*, uchar *buf, int offset, int n);
33 int packetfragments(Packet*, IOchunk*, int nio, int offset);
34 uint packetsize(Packet*);
35 uint packetasize(Packet*);
36 int packetcompact(Packet*);
37 int packetcmp(Packet*, Packet*);
38 void packetstats(void);
39 void packetsha1(Packet*, uchar sha1[20]);
41 /* XXX begin actual venti.h */
44 #pragma lib "libventi.a"
45 #pragma src "/sys/src/libventi"
48 typedef struct VtFcall VtFcall;
49 typedef struct VtConn VtConn;
50 typedef struct VtEntry VtEntry;
51 typedef struct VtRoot VtRoot;
54 * Fundamental constants.
59 VtMaxStringSize = 1024,
60 VtMaxLumpSize = 56*1024,
63 #define VtMaxFileSize ((1ULL<<48)-1)
69 int vtputstring(Packet*, char*);
70 int vtgetstring(Packet*, char**);
75 * The initial Venti protocol had a much
76 * less regular list of block types.
77 * VtToDiskType converts from new to old.
82 /* VtDataType+1, ... */
84 /* VtDirType+1, ... */
90 VtTypeBaseMask = ~VtTypeDepthMask,
93 /* convert to/from on-disk type numbers */
94 uint vttodisktype(uint);
95 uint vtfromdisktype(uint);
98 * VtEntry describes a Venti stream
100 * The _ enums are only used on the wire.
101 * They are not present in the VtEntry structure
102 * and should not be used by client programs.
103 * (The info is in the type field.)
107 VtEntryActive = 1<<0, /* entry is in use */
108 _VtEntryDir = 1<<1, /* a directory */
109 _VtEntryDepthShift = 2, /* shift for pointer depth */
110 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
111 VtEntryLocal = 1<<5, /* for local storage only */
119 ulong gen; /* generation number */
120 ushort psize; /* pointer block size */
121 ushort dsize; /* data block size */
125 uchar score[VtScoreSize];
128 void vtentrypack(VtEntry*, uchar*, int index);
129 int vtentryunpack(VtEntry*, uchar*, int index);
135 uchar score[VtScoreSize]; /* to a Dir block */
136 ushort blocksize; /* maximum block size */
137 uchar prev[VtScoreSize]; /* last root block */
146 void vtrootpack(VtRoot*, uchar*);
147 int vtrootunpack(VtRoot*, uchar*);
150 * score of zero length block
152 extern uchar vtzeroscore[VtScoreSize];
155 * zero extend and truncate blocks
157 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
158 uint vtzerotruncate(int type, uchar *buf, uint n);
161 * parse score: mungs s
163 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
167 * other than noted, these formats all ignore
168 * the width and precision arguments, and all flags
173 #pragma varargck type "V" uchar*
174 #pragma varargck type "F" VtFcall*
177 int vtscorefmt(Fmt*);
180 * error-checking malloc et al.
184 void *vtmallocz(int);
185 void *vtrealloc(void *p, int);
187 char *vtstrdup(char *);
198 VtCryptoStrengthNone,
199 VtCryptoStrengthAuth,
200 VtCryptoStrengthWeak,
201 VtCryptoStrengthStrong,
234 VtRgoodbye, /* not used */
254 char *error; /* Rerror */
256 char *version; /* Thello */
257 char *uid; /* Thello */
258 uchar strength; /* Thello */
259 uchar *crypto; /* Thello */
260 uint ncrypto; /* Thello */
261 uchar *codec; /* Thello */
262 uint ncodec; /* Thello */
263 char *sid; /* Rhello */
264 uchar rcrypto; /* Rhello */
265 uchar rcodec; /* Rhello */
266 uchar *auth; /* TauthX, RauthX */
267 uint nauth; /* TauthX, RauthX */
268 uchar score[VtScoreSize]; /* Tread, Rwrite */
269 uchar dtype; /* Tread, Twrite */
270 ushort count; /* Tread */
271 Packet *data; /* Rread, Twrite */
274 Packet *vtfcallpack(VtFcall*);
275 int vtfcallunpack(VtFcall*, Packet*);
276 void vtfcallclear(VtFcall*);
277 int vtfcallfmt(Fmt*);
309 VtConn *vtconn(int infd, int outfd);
310 VtConn *vtdial(char*);
311 void vtfreeconn(VtConn*);
312 int vtsend(VtConn*, Packet*);
313 Packet *vtrecv(VtConn*);
314 int vtversion(VtConn *z);
315 void vtdebug(VtConn *z, char*, ...);
316 void vthangup(VtConn *z);
317 /* #pragma varargck argpos vtdebug 2 */
320 typedef struct VtSrv VtSrv;
321 typedef struct VtReq VtReq;
331 int vtsrvhello(VtConn*);
332 VtSrv *vtlisten(char *addr);
333 VtReq *vtgetreq(VtSrv*);
334 void vtrespond(VtReq*);
337 Packet *vtrpc(VtConn*, Packet*);
338 void vtrecvproc(void*); /* VtConn* */
339 void vtsendproc(void*); /* VtConn* */
341 int vtconnect(VtConn*);
342 int vthello(VtConn*);
343 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
344 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
345 Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
346 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
351 * Data blocks and block cache.
358 typedef struct VtBlock VtBlock;
359 typedef struct VtCache VtCache;
367 uchar score[VtScoreSize];
368 uchar type; /* BtXXX */
370 /* internal to cache */
381 /* internal to efile (HACK) */
385 u32int vtglobaltolocal(uchar[VtScoreSize]);
386 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
388 VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
389 void vtcachefree(VtCache*);
390 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
391 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
392 VtBlock *vtcacheallocblock(VtCache*, int type);
393 void vtcachesetwrite(VtCache*, int(*)(VtConn*,uchar[VtScoreSize],uint,uchar*,int));
394 void vtblockput(VtBlock*);
395 u32int vtcacheblocksize(VtCache*);
396 int vtblockwrite(VtBlock*);
397 VtBlock *vtblockcopy(VtBlock*);
398 void vtblockduplock(VtBlock*);
399 int vtblockdirty(VtBlock*);
402 * Hash tree file tree.
404 typedef struct VtFile VtFile;
410 VtBlock *b; /* block containing this file */
411 uchar score[VtScoreSize]; /* score of block containing this file */
420 int epb; /* entries per block in parent */
421 u32int offset; /* entry offset in parent */
432 VtFile *vtfileopenroot(VtCache*, VtEntry*);
433 VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
434 VtFile *vtfileopen(VtFile*, u32int, int);
435 VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
436 VtBlock *vtfileblock(VtFile*, u32int, int mode);
437 long vtfileread(VtFile*, void*, long, vlong);
438 long vtfilewrite(VtFile*, void*, long, vlong);
439 int vtfileflush(VtFile*);
440 void vtfileincref(VtFile*);
441 void vtfileclose(VtFile*);
442 int vtfilegetentry(VtFile*, VtEntry*);
443 int vtfilesetentry(VtFile*, VtEntry*);
444 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
445 u32int vtfilegetdirsize(VtFile*);
446 int vtfilesetdirsize(VtFile*, u32int);
447 void vtfileunlock(VtFile*);
448 int vtfilelock(VtFile*, int);
449 int vtfilelock2(VtFile*, VtFile*, int);
450 int vtfileflushbefore(VtFile*, u64int);
451 int vtfiletruncate(VtFile*);
452 uvlong vtfilegetsize(VtFile*);
453 int vtfilesetsize(VtFile*, uvlong);
454 int vtfileremove(VtFile*);
456 extern int chattyventi;
457 extern int ventidoublechecksha1;