6 /* XXX should be own library? */
15 typedef struct Packet Packet;
16 Packet *packetalloc(void);
17 void packetfree(Packet*);
18 Packet *packetforeign(uchar *buf, int n, void (*free)(void *a), void *a);
19 Packet *packetdup(Packet*, int offset, int n);
20 Packet *packetsplit(Packet*, int n);
21 int packetconsume(Packet*, uchar *buf, int n);
22 int packettrim(Packet*, int offset, int n);
23 uchar *packetheader(Packet*, int n);
24 uchar *packettrailer(Packet*, int n);
25 void packetprefix(Packet*, uchar *buf, int n);
26 void packetappend(Packet*, uchar *buf, int n);
27 void packetconcat(Packet*, Packet*);
28 uchar *packetpeek(Packet*, uchar *buf, int offset, int n);
29 int packetcopy(Packet*, uchar *buf, int offset, int n);
30 int packetfragments(Packet*, IOchunk*, int nio, int offset);
31 uint packetsize(Packet*);
32 uint packetasize(Packet*);
33 int packetcompact(Packet*);
34 int packetcmp(Packet*, Packet*);
35 void packetstats(void);
36 void packetsha1(Packet*, uchar sha1[20]);
38 /* XXX begin actual venti.h */
41 #pragma lib "libventi.a"
42 #pragma src "/sys/src/libventi"
45 typedef struct VtFcall VtFcall;
46 typedef struct VtConn VtConn;
47 typedef struct VtEntry VtEntry;
48 typedef struct VtRoot VtRoot;
51 * Fundamental constants.
56 VtMaxStringSize = 1024,
57 VtMaxLumpSize = 56*1024,
60 #define VtMaxFileSize ((1ULL<<48)-1)
66 int vtputstring(Packet*, char*);
67 int vtgetstring(Packet*, char**);
72 * The initial Venti protocol had a much
73 * less regular list of block types.
74 * VtToDiskType converts from new to old.
79 /* VtDataType+1, ... */
81 /* VtDirType+1, ... */
87 VtTypeBaseMask = ~VtTypeDepthMask,
90 /* convert to/from on-disk type numbers */
91 uint vttodisktype(uint);
92 uint vtfromdisktype(uint);
95 * VtEntry describes a Venti stream
97 * The _ enums are only used on the wire.
98 * They are not present in the VtEntry structure
99 * and should not be used by client programs.
100 * (The info is in the type field.)
104 VtEntryActive = 1<<0, /* entry is in use */
105 _VtEntryDir = 1<<1, /* a directory */
106 _VtEntryDepthShift = 2, /* shift for pointer depth */
107 _VtEntryDepthMask = 7<<2, /* mask for pointer depth */
108 VtEntryLocal = 1<<5, /* for local storage only */
116 ulong gen; /* generation number */
117 ushort psize; /* pointer block size */
118 ushort dsize; /* data block size */
122 uchar score[VtScoreSize];
125 void vtentrypack(VtEntry*, uchar*, int index);
126 int vtentryunpack(VtEntry*, uchar*, int index);
132 uchar score[VtScoreSize]; /* to a Dir block */
133 ushort blocksize; /* maximum block size */
134 uchar prev[VtScoreSize]; /* last root block */
143 void vtrootpack(VtRoot*, uchar*);
144 int vtrootunpack(VtRoot*, uchar*);
147 * score of zero length block
149 extern uchar vtzeroscore[VtScoreSize];
152 * zero extend and truncate blocks
154 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
155 uint vtzerotruncate(int type, uchar *buf, uint n);
158 * parse score: mungs s
160 int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]);
164 * other than noted, these formats all ignore
165 * the width and precision arguments, and all flags
170 #pragma varargck type "V" uchar*
171 #pragma varargck type "F" VtFcall*
174 int vtscorefmt(Fmt*);
177 * error-checking malloc et al.
181 void *vtmallocz(int);
182 void *vtrealloc(void *p, int);
184 char *vtstrdup(char *);
195 VtCryptoStrengthNone,
196 VtCryptoStrengthAuth,
197 VtCryptoStrengthWeak,
198 VtCryptoStrengthStrong,
231 VtRgoodbye, /* not used */
251 char *error; /* Rerror */
253 char *version; /* Thello */
254 char *uid; /* Thello */
255 uchar strength; /* Thello */
256 uchar *crypto; /* Thello */
257 uint ncrypto; /* Thello */
258 uchar *codec; /* Thello */
259 uint ncodec; /* Thello */
260 char *sid; /* Rhello */
261 uchar rcrypto; /* Rhello */
262 uchar rcodec; /* Rhello */
263 uchar *auth; /* TauthX, RauthX */
264 uint nauth; /* TauthX, RauthX */
265 uchar score[VtScoreSize]; /* Tread, Rwrite */
266 uchar dtype; /* Tread, Twrite */
267 ushort count; /* Tread */
268 Packet *data; /* Rread, Twrite */
271 Packet *vtfcallpack(VtFcall*);
272 int vtfcallunpack(VtFcall*, Packet*);
273 void vtfcallclear(VtFcall*);
274 int vtfcallfmt(Fmt*);
306 VtConn *vtconn(int infd, int outfd);
307 VtConn *vtdial(char*);
308 void vtfreeconn(VtConn*);
309 int vtsend(VtConn*, Packet*);
310 Packet *vtrecv(VtConn*);
311 int vtversion(VtConn *z);
312 void vtdebug(VtConn *z, char*, ...);
313 void vthangup(VtConn *z);
314 /* #pragma varargck argpos vtdebug 2 */
317 typedef struct VtSrv VtSrv;
318 typedef struct VtReq VtReq;
328 int vtsrvhello(VtConn*);
329 VtSrv *vtlisten(char *addr);
330 VtReq *vtgetreq(VtSrv*);
331 void vtrespond(VtReq*);
334 Packet *vtrpc(VtConn*, Packet*);
335 void vtrecvproc(void*); /* VtConn* */
336 void vtsendproc(void*); /* VtConn* */
338 int vtconnect(VtConn*);
339 int vthello(VtConn*);
340 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
341 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
342 Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
343 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
348 * Data blocks and block cache.
355 typedef struct VtBlock VtBlock;
356 typedef struct VtCache VtCache;
364 uchar score[VtScoreSize];
365 uchar type; /* BtXXX */
367 /* internal to cache */
378 /* internal to efile (HACK) */
382 u32int vtglobaltolocal(uchar[VtScoreSize]);
383 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
385 VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
386 void vtcachefree(VtCache*);
387 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
388 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
389 VtBlock *vtcacheallocblock(VtCache*, int type);
390 void vtcachesetwrite(VtCache*, int(*)(VtConn*,uchar[VtScoreSize],uint,uchar*,int));
391 void vtblockput(VtBlock*);
392 u32int vtcacheblocksize(VtCache*);
393 int vtblockwrite(VtBlock*);
394 VtBlock *vtblockcopy(VtBlock*);
395 void vtblockduplock(VtBlock*);
396 int vtblockdirty(VtBlock*);
399 * Hash tree file tree.
401 typedef struct VtFile VtFile;
407 VtBlock *b; /* block containing this file */
408 uchar score[VtScoreSize]; /* score of block containing this file */
417 int epb; /* entries per block in parent */
418 u32int offset; /* entry offset in parent */
429 VtFile *vtfileopenroot(VtCache*, VtEntry*);
430 VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
431 VtFile *vtfileopen(VtFile*, u32int, int);
432 VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
433 VtBlock *vtfileblock(VtFile*, u32int, int mode);
434 long vtfileread(VtFile*, void*, long, vlong);
435 long vtfilewrite(VtFile*, void*, long, vlong);
436 int vtfileflush(VtFile*);
437 void vtfileincref(VtFile*);
438 void vtfileclose(VtFile*);
439 int vtfilegetentry(VtFile*, VtEntry*);
440 int vtfilesetentry(VtFile*, VtEntry*);
441 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
442 u32int vtfilegetdirsize(VtFile*);
443 int vtfilesetdirsize(VtFile*, u32int);
444 void vtfileunlock(VtFile*);
445 int vtfilelock(VtFile*, int);
446 int vtfilelock2(VtFile*, VtFile*, int);
447 int vtfileflushbefore(VtFile*, u64int);
448 int vtfiletruncate(VtFile*);
449 uvlong vtfilegetsize(VtFile*);
450 int vtfilesetsize(VtFile*, uvlong);
451 int vtfileremove(VtFile*);
453 extern int chattyventi;
454 extern int ventidoublechecksha1;