3 #if defined(__cplusplus)
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 "libnventi.a"
42 #pragma src "/sys/src/libnventi"
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
169 /* #pragma varargck type "V" uchar* */
171 int vtscorefmt(Fmt*);
174 * error-checking malloc et al.
178 void *vtmallocz(int);
179 void *vtrealloc(void *p, int);
181 char *vtstrdup(char *);
192 VtCryptoStrengthNone,
193 VtCryptoStrengthAuth,
194 VtCryptoStrengthWeak,
195 VtCryptoStrengthStrong,
228 VtRgoodbye, /* not used */
248 char *error; /* Rerror */
250 char *version; /* Thello */
251 char *uid; /* Thello */
252 uchar strength; /* Thello */
253 uchar *crypto; /* Thello */
254 uint ncrypto; /* Thello */
255 uchar *codec; /* Thello */
256 uint ncodec; /* Thello */
257 char *sid; /* Rhello */
258 uchar rcrypto; /* Rhello */
259 uchar rcodec; /* Rhello */
260 uchar *auth; /* TauthX, RauthX */
261 uint nauth; /* TauthX, RauthX */
262 uchar score[VtScoreSize]; /* Tread, Rwrite */
263 uchar dtype; /* Tread, Twrite */
264 ushort count; /* Tread */
265 Packet *data; /* Rread, Twrite */
268 Packet *vtfcallpack(VtFcall*);
269 int vtfcallunpack(VtFcall*, Packet*);
270 void vtfcallclear(VtFcall*);
271 int vtfcallfmt(Fmt*);
303 VtConn *vtconn(int infd, int outfd);
304 VtConn *vtdial(char*);
305 void vtfreeconn(VtConn*);
306 int vtsend(VtConn*, Packet*);
307 Packet *vtrecv(VtConn*);
308 int vtversion(VtConn *z);
309 void vtdebug(VtConn *z, char*, ...);
310 void vthangup(VtConn *z);
311 /* #pragma varargck argpos vtdebug 2 */
314 typedef struct VtSrv VtSrv;
315 typedef struct VtReq VtReq;
325 int vtsrvhello(VtConn*);
326 VtSrv *vtlisten(char *addr);
327 VtReq *vtgetreq(VtSrv*);
328 void vtrespond(VtReq*);
331 Packet *vtrpc(VtConn*, Packet*);
332 void vtrecvproc(void*); /* VtConn* */
333 void vtsendproc(void*); /* VtConn* */
335 int vtconnect(VtConn*);
336 int vthello(VtConn*);
337 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
338 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
339 Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
340 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
345 * Data blocks and block cache.
352 typedef struct VtBlock VtBlock;
353 typedef struct VtCache VtCache;
361 uchar score[VtScoreSize];
362 uchar type; /* BtXXX */
364 /* internal to cache */
375 /* internal to efile (HACK) */
379 u32int vtglobaltolocal(uchar[VtScoreSize]);
380 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
382 VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
383 void vtcachefree(VtCache*);
384 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
385 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
386 VtBlock *vtcacheallocblock(VtCache*, int type);
387 void vtblockput(VtBlock*);
388 u32int vtcacheblocksize(VtCache*);
389 int vtblockwrite(VtBlock*);
390 VtBlock *vtblockcopy(VtBlock*);
391 void vtblockduplock(VtBlock*);
392 int vtblockdirty(VtBlock*);
395 * Hash tree file tree.
397 typedef struct VtFile VtFile;
403 VtBlock *b; /* block containing this file */
404 uchar score[VtScoreSize]; /* score of block containing this file */
413 int epb; /* entries per block in parent */
414 u32int offset; /* entry offset in parent */
425 VtFile *vtfileopenroot(VtCache*, VtEntry*);
426 VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
427 VtFile *vtfileopen(VtFile*, u32int, int);
428 VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
429 VtBlock *vtfileblock(VtFile*, u32int, int mode);
430 long vtfileread(VtFile*, void*, long, vlong);
431 long vtfilewrite(VtFile*, void*, long, vlong);
432 int vtfileflush(VtFile*);
433 void vtfileincref(VtFile*);
434 void vtfileclose(VtFile*);
435 int vtfilegetentry(VtFile*, VtEntry*);
436 int vtfilesetentry(VtFile*, VtEntry*);
437 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
438 u32int vtfilegetdirsize(VtFile*);
439 int vtfilesetdirsize(VtFile*, u32int);
440 void vtfileunlock(VtFile*);
441 int vtfilelock(VtFile*, int);
442 int vtfilelock2(VtFile*, VtFile*, int);
443 int vtfileflushbefore(VtFile*, u64int);
444 int vtfiletruncate(VtFile*);
445 uvlong vtfilegetsize(VtFile*);
446 int vtfilesetsize(VtFile*, uvlong);
447 int vtfileremove(VtFile*);
449 extern int chattyventi;
450 extern int ventidoublechecksha1;
452 #if defined(__cplusplus)