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 int packetprefix(Packet*, uchar *buf, int n);
26 int packetappend(Packet*, uchar *buf, int n);
27 int 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 VtSha1 VtSha1;
47 typedef struct VtConn VtConn;
48 typedef struct VtEntry VtEntry;
49 typedef struct VtRoot VtRoot;
52 * Fundamental constants.
57 VtMaxStringSize = 1024,
58 VtMaxLumpSize = 56*1024,
61 #define VtMaxFileSize ((1ULL<<48)-1)
67 int vtputstring(Packet*, char*);
68 int vtgetstring(Packet*, char**);
73 * The initial Venti protocol had a much
74 * less regular list of block types.
75 * VtToDiskType converts from new to old.
80 /* VtDataType+1, ... */
82 /* VtDirType+1, ... */
90 /* convert to/from on-disk type numbers */
91 uint vttodisktype(uint);
92 uint vtfromdisktype(uint);
95 * VtEntry describes a Venti stream
99 VtEntryActive = 1<<0, /* entry is in use */
100 VtEntryDir = 1<<1, /* a directory */
101 VtEntryDepthShift = 2, /* shift for pointer depth */
102 VtEntryDepthMask = 7<<2, /* mask for pointer depth */
103 VtEntryLocal = 1<<5, /* for local storage only */
111 ulong gen; /* generation number */
112 ushort psize; /* pointer block size */
113 ushort dsize; /* data block size */
117 uchar score[VtScoreSize];
120 void vtentrypack(VtEntry*, uchar*, int index);
121 int vtentryunpack(VtEntry*, uchar*, int index);
127 uchar score[VtScoreSize]; /* to a Dir block */
128 ushort blocksize; /* maximum block size */
129 uchar prev[VtScoreSize]; /* last root block */
138 void vtrootpack(VtRoot*, uchar*);
139 int vtrootunpack(VtRoot*, uchar*);
142 * score of zero length block
144 extern uchar vtzeroscore[VtScoreSize];
147 * zero extend and truncate blocks
149 void vtzeroextend(int type, uchar *buf, uint n, uint nn);
150 uint vtzerotruncate(int type, uchar *buf, uint n);
153 * parse score: mungs s
155 int vtparsescore(char *s, uint len, char **prefix, uchar[VtScoreSize]);
159 * other than noted, these formats all ignore
160 * the width and precision arguments, and all flags
164 /* #pragma varargck type "V" uchar* */
166 int vtscorefmt(Fmt*);
169 * error-checking malloc et al.
173 void *vtmallocz(int);
174 void *vtrealloc(void *p, int);
176 char *vtstrdup(char *);
187 VtCryptoStrengthNone,
188 VtCryptoStrengthAuth,
189 VtCryptoStrengthWeak,
190 VtCryptoStrengthStrong,
223 VtRgoodbye, /* not used */
243 char *error; /* Rerror */
245 char *version; /* Thello */
246 char *uid; /* Thello */
247 uchar strength; /* Thello */
248 uchar *crypto; /* Thello */
249 uint ncrypto; /* Thello */
250 uchar *codec; /* Thello */
251 uint ncodec; /* Thello */
252 char *sid; /* Rhello */
253 uchar rcrypto; /* Rhello */
254 uchar rcodec; /* Rhello */
255 uchar *auth; /* TauthX, RauthX */
256 uint nauth; /* TauthX, RauthX */
257 uchar score[VtScoreSize]; /* Tread, Rwrite */
258 uchar dtype; /* Tread, Twrite */
259 ushort count; /* Tread */
260 Packet *data; /* Rread, Twrite */
263 Packet *vtfcallpack(VtFcall*);
264 int vtfcallunpack(VtFcall*, Packet*);
265 void vtfcallclear(VtFcall*);
266 int vtfcallfmt(Fmt*);
298 VtConn *vtconn(int infd, int outfd);
299 VtConn *vtdial(char*);
300 void vtfreeconn(VtConn*);
301 int vtsend(VtConn*, Packet*);
302 Packet *vtrecv(VtConn*);
303 int vtversion(VtConn *z);
304 void vtdebug(VtConn *z, char*, ...);
305 void vthangup(VtConn *z);
306 /* #pragma varargck argpos vtdebug 2 */
309 typedef struct VtSrv VtSrv;
310 typedef struct VtReq VtReq;
320 int vtsrvhello(VtConn*);
321 VtSrv *vtlisten(char *addr);
322 VtReq *vtgetreq(VtSrv*);
323 void vtrespond(VtReq*);
326 Packet *vtrpc(VtConn*, Packet*);
327 void vtrecvproc(void*); /* VtConn* */
328 void vtsendproc(void*); /* VtConn* */
330 int vtconnect(VtConn*);
331 int vthello(VtConn*);
332 int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
333 int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n);
334 Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n);
335 int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p);
340 * Data blocks and block cache.
347 typedef struct VtBlock VtBlock;
348 typedef struct VtCache VtCache;
356 uchar score[VtScoreSize];
357 uchar type; /* BtXXX */
359 /* internal to cache */
370 /* internal to efile (HACK) */
374 u32int vtglobaltolocal(uchar[VtScoreSize]);
375 void vtlocaltoglobal(u32int, uchar[VtScoreSize]);
377 VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks, int mode);
378 void vtcachefree(VtCache*);
379 VtBlock *vtcachelocal(VtCache*, u32int addr, int type);
380 VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type);
381 VtBlock *vtcacheallocblock(VtCache*, int type);
382 void vtblockput(VtBlock*);
383 u32int vtcacheblocksize(VtCache*);
384 int vtblockwrite(VtBlock*);
385 VtBlock *vtblockcopy(VtBlock*);
386 void vtblockduplock(VtBlock*);
389 * Hash tree file tree.
391 typedef struct VtFile VtFile;
401 VtFile *vtfileopenroot(VtCache*, VtEntry*);
402 VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
403 VtFile *vtfileopen(VtFile*, u32int, int);
404 VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
405 VtBlock *vtfileblock(VtFile*, u32int, int mode);
406 int vtfileblockhash(VtFile*, u32int, uchar[VtScoreSize]);
407 long vtfileread(VtFile*, void*, long, vlong);
408 long vtfilewrite(VtFile*, void*, long, vlong);
409 int vtfileflush(VtFile*);
410 void vtfileincref(VtFile*);
411 void vtfileclose(VtFile*);
412 int vtfilegetentry(VtFile*, VtEntry*);
413 int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]);
414 u32int vtfilegetdirsize(VtFile*);
415 int vtfilesetdirsize(VtFile*, u32int);
416 void vtfileunlock(VtFile*);
417 int vtfilelock(VtFile*, int);
418 int vtfilelock2(VtFile*, VtFile*, int);
419 int vtfileflushbefore(VtFile*, u64int);
421 #if defined(__cplusplus)