rsc | f701258 | 2003-11-25 01:40:27 +0000 | [diff] [blame] | 1 | #ifndef _VENTI_H_ |
| 2 | #define _VENTI_H_ 1 |
rsc | 819822c | 2004-06-16 16:45:22 +0000 | [diff] [blame] | 3 | #ifdef __cplusplus |
rsc | f701258 | 2003-11-25 01:40:27 +0000 | [diff] [blame] | 4 | extern "C" { |
| 5 | #endif |
rsc | 1a0954a | 2005-01-04 21:18:08 +0000 | [diff] [blame] | 6 | |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 7 | #ifndef PLAN9PORT |
| 8 | #pragma lib "libventi.a" |
| 9 | #pragma src "/sys/src/libventi" |
| 10 | #endif |
| 11 | |
rsc | 1a0954a | 2005-01-04 21:18:08 +0000 | [diff] [blame] | 12 | AUTOLIB(venti) |
| 13 | |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 14 | /* XXX should be own library? */ |
| 15 | /* |
| 16 | * Packets |
| 17 | */ |
| 18 | enum |
| 19 | { |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 20 | MaxFragSize = 9*1024 |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 21 | }; |
| 22 | |
| 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); |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 33 | void packetprefix(Packet*, uchar *buf, int n); |
| 34 | void packetappend(Packet*, uchar *buf, int n); |
| 35 | void packetconcat(Packet*, Packet*); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 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]); |
| 45 | |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 46 | /* XXX should be own library? */ |
| 47 | /* |
| 48 | * Logging |
| 49 | */ |
| 50 | typedef struct VtLog VtLog; |
| 51 | typedef struct VtLogChunk VtLogChunk; |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 52 | |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 53 | struct VtLog |
| 54 | { |
| 55 | VtLog *next; /* in hash table */ |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 56 | char *name; |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 57 | VtLogChunk *chunk; |
| 58 | uint nchunk; |
| 59 | VtLogChunk *w; |
| 60 | QLock lk; |
| 61 | int ref; |
| 62 | }; |
| 63 | |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 64 | struct VtLogChunk |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 65 | { |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 66 | char *p; |
| 67 | char *ep; |
| 68 | char *wp; |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | VtLog *vtlogopen(char *name, uint size); |
| 72 | void vtlogprint(VtLog *log, char *fmt, ...); |
| 73 | void vtlog(char *name, char *fmt, ...); |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 74 | void vtlogclose(VtLog*); |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 75 | void vtlogremove(char *name); |
rsc | 1c485da | 2005-05-12 14:03:16 +0000 | [diff] [blame] | 76 | char **vtlognames(int*); |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 77 | void vtlogdump(int fd, VtLog*); |
rsc | 6c0209f | 2005-02-11 20:32:41 +0000 | [diff] [blame] | 78 | |
| 79 | /* XXX begin actual venti.h */ |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 80 | |
| 81 | typedef struct VtFcall VtFcall; |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 82 | typedef struct VtConn VtConn; |
| 83 | typedef struct VtEntry VtEntry; |
| 84 | typedef struct VtRoot VtRoot; |
| 85 | |
| 86 | /* |
| 87 | * Fundamental constants. |
| 88 | */ |
| 89 | enum |
| 90 | { |
| 91 | VtScoreSize = 20, |
| 92 | VtMaxStringSize = 1024, |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 93 | VtMaxLumpSize = 56*1024, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 94 | VtPointerDepth = 7 |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 95 | }; |
rsc | 2db9e48 | 2003-11-24 20:16:30 +0000 | [diff] [blame] | 96 | #define VtMaxFileSize ((1ULL<<48)-1) |
| 97 | |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Strings in packets. |
| 101 | */ |
| 102 | int vtputstring(Packet*, char*); |
| 103 | int vtgetstring(Packet*, char**); |
| 104 | |
| 105 | /* |
| 106 | * Block types. |
| 107 | * |
| 108 | * The initial Venti protocol had a much |
| 109 | * less regular list of block types. |
| 110 | * VtToDiskType converts from new to old. |
| 111 | */ |
| 112 | enum |
| 113 | { |
| 114 | VtDataType = 0<<3, |
| 115 | /* VtDataType+1, ... */ |
| 116 | VtDirType = 1<<3, |
| 117 | /* VtDirType+1, ... */ |
| 118 | VtRootType = 2<<3, |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 119 | VtMaxType, |
rsc | d3232ca | 2004-06-14 21:43:32 +0000 | [diff] [blame] | 120 | VtCorruptType = 0xFF, |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 121 | |
| 122 | VtTypeDepthMask = 7, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 123 | VtTypeBaseMask = ~VtTypeDepthMask |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /* convert to/from on-disk type numbers */ |
| 127 | uint vttodisktype(uint); |
| 128 | uint vtfromdisktype(uint); |
| 129 | |
| 130 | /* |
| 131 | * VtEntry describes a Venti stream |
rsc | eacbfb2 | 2004-03-15 01:58:31 +0000 | [diff] [blame] | 132 | * |
| 133 | * The _ enums are only used on the wire. |
| 134 | * They are not present in the VtEntry structure |
| 135 | * and should not be used by client programs. |
| 136 | * (The info is in the type field.) |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 137 | */ |
| 138 | enum |
| 139 | { |
| 140 | VtEntryActive = 1<<0, /* entry is in use */ |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 141 | _VtEntryDir = 1<<1, /* a directory */ |
| 142 | _VtEntryDepthShift = 2, /* shift for pointer depth */ |
| 143 | _VtEntryDepthMask = 7<<2, /* mask for pointer depth */ |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 144 | VtEntryLocal = 1<<5 /* for local storage only */ |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 145 | }; |
| 146 | enum |
| 147 | { |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 148 | VtEntrySize = 40 |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 149 | }; |
| 150 | struct VtEntry |
| 151 | { |
| 152 | ulong gen; /* generation number */ |
| 153 | ushort psize; /* pointer block size */ |
| 154 | ushort dsize; /* data block size */ |
| 155 | uchar type; |
| 156 | uchar flags; |
| 157 | uvlong size; |
| 158 | uchar score[VtScoreSize]; |
| 159 | }; |
| 160 | |
| 161 | void vtentrypack(VtEntry*, uchar*, int index); |
| 162 | int vtentryunpack(VtEntry*, uchar*, int index); |
| 163 | |
| 164 | struct VtRoot |
| 165 | { |
| 166 | char name[128]; |
| 167 | char type[128]; |
| 168 | uchar score[VtScoreSize]; /* to a Dir block */ |
| 169 | ushort blocksize; /* maximum block size */ |
| 170 | uchar prev[VtScoreSize]; /* last root block */ |
| 171 | }; |
| 172 | |
| 173 | enum |
| 174 | { |
| 175 | VtRootSize = 300, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 176 | VtRootVersion = 2 |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | void vtrootpack(VtRoot*, uchar*); |
| 180 | int vtrootunpack(VtRoot*, uchar*); |
| 181 | |
| 182 | /* |
| 183 | * score of zero length block |
| 184 | */ |
| 185 | extern uchar vtzeroscore[VtScoreSize]; |
| 186 | |
| 187 | /* |
| 188 | * zero extend and truncate blocks |
| 189 | */ |
| 190 | void vtzeroextend(int type, uchar *buf, uint n, uint nn); |
| 191 | uint vtzerotruncate(int type, uchar *buf, uint n); |
| 192 | |
| 193 | /* |
| 194 | * parse score: mungs s |
| 195 | */ |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 196 | int vtparsescore(char *s, char **prefix, uchar[VtScoreSize]); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * formatting |
| 200 | * other than noted, these formats all ignore |
| 201 | * the width and precision arguments, and all flags |
| 202 | * |
| 203 | * V a venti score |
| 204 | */ |
rsc | 819822c | 2004-06-16 16:45:22 +0000 | [diff] [blame] | 205 | #ifndef PLAN9PORT |
| 206 | #pragma varargck type "V" uchar* |
| 207 | #pragma varargck type "F" VtFcall* |
| 208 | #endif |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 209 | |
| 210 | int vtscorefmt(Fmt*); |
| 211 | |
| 212 | /* |
| 213 | * error-checking malloc et al. |
| 214 | */ |
| 215 | void vtfree(void *); |
| 216 | void *vtmalloc(int); |
| 217 | void *vtmallocz(int); |
| 218 | void *vtrealloc(void *p, int); |
| 219 | void *vtbrk(int n); |
| 220 | char *vtstrdup(char *); |
| 221 | |
| 222 | /* |
| 223 | * Venti protocol |
| 224 | */ |
| 225 | |
| 226 | /* |
| 227 | * Crypto strengths |
| 228 | */ |
| 229 | enum |
| 230 | { |
| 231 | VtCryptoStrengthNone, |
| 232 | VtCryptoStrengthAuth, |
| 233 | VtCryptoStrengthWeak, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 234 | VtCryptoStrengthStrong |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | /* |
| 238 | * Crypto suites |
| 239 | */ |
| 240 | enum |
| 241 | { |
| 242 | VtCryptoNone, |
| 243 | VtCryptoSSL3, |
| 244 | VtCryptoTLS1, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 245 | VtCryptoMax |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | /* |
| 249 | * Codecs |
| 250 | */ |
| 251 | enum |
| 252 | { |
| 253 | VtCodecNone, |
| 254 | VtCodecDeflate, |
| 255 | VtCodecThwack, |
| 256 | VtCodecMax |
| 257 | }; |
| 258 | |
| 259 | enum |
| 260 | { |
| 261 | VtRerror = 1, |
| 262 | VtTping = 2, |
| 263 | VtRping, |
| 264 | VtThello = 4, |
| 265 | VtRhello, |
| 266 | VtTgoodbye = 6, |
| 267 | VtRgoodbye, /* not used */ |
| 268 | VtTauth0 = 8, |
| 269 | VtRauth0, |
| 270 | VtTauth1 = 10, |
| 271 | VtRauth1, |
| 272 | VtTread = 12, |
| 273 | VtRread, |
| 274 | VtTwrite = 14, |
| 275 | VtRwrite, |
| 276 | VtTsync = 16, |
| 277 | VtRsync, |
| 278 | |
| 279 | VtTmax |
| 280 | }; |
| 281 | |
| 282 | struct VtFcall |
| 283 | { |
rsc | 7e6f40b | 2005-07-13 10:46:26 +0000 | [diff] [blame] | 284 | uchar msgtype; |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 285 | uchar tag; |
| 286 | |
| 287 | char *error; /* Rerror */ |
| 288 | |
| 289 | char *version; /* Thello */ |
| 290 | char *uid; /* Thello */ |
| 291 | uchar strength; /* Thello */ |
| 292 | uchar *crypto; /* Thello */ |
| 293 | uint ncrypto; /* Thello */ |
| 294 | uchar *codec; /* Thello */ |
| 295 | uint ncodec; /* Thello */ |
| 296 | char *sid; /* Rhello */ |
| 297 | uchar rcrypto; /* Rhello */ |
| 298 | uchar rcodec; /* Rhello */ |
| 299 | uchar *auth; /* TauthX, RauthX */ |
| 300 | uint nauth; /* TauthX, RauthX */ |
| 301 | uchar score[VtScoreSize]; /* Tread, Rwrite */ |
rsc | 7e6f40b | 2005-07-13 10:46:26 +0000 | [diff] [blame] | 302 | uchar blocktype; /* Tread, Twrite */ |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 303 | ushort count; /* Tread */ |
| 304 | Packet *data; /* Rread, Twrite */ |
| 305 | }; |
| 306 | |
| 307 | Packet *vtfcallpack(VtFcall*); |
| 308 | int vtfcallunpack(VtFcall*, Packet*); |
| 309 | void vtfcallclear(VtFcall*); |
| 310 | int vtfcallfmt(Fmt*); |
| 311 | |
| 312 | enum |
| 313 | { |
| 314 | VtStateAlloc, |
| 315 | VtStateConnected, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 316 | VtStateClosed |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | struct VtConn |
| 320 | { |
| 321 | QLock lk; |
| 322 | QLock inlk; |
| 323 | QLock outlk; |
| 324 | int debug; |
| 325 | int infd; |
| 326 | int outfd; |
| 327 | int muxer; |
| 328 | void *writeq; |
| 329 | void *readq; |
| 330 | int state; |
| 331 | void *wait[256]; |
| 332 | uint ntag; |
| 333 | uint nsleep; |
| 334 | Packet *part; |
| 335 | Rendez tagrend; |
| 336 | Rendez rpcfork; |
| 337 | char *version; |
| 338 | char *uid; |
| 339 | char *sid; |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 340 | char addr[256]; /* address of other side */ |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | VtConn *vtconn(int infd, int outfd); |
| 344 | VtConn *vtdial(char*); |
| 345 | void vtfreeconn(VtConn*); |
| 346 | int vtsend(VtConn*, Packet*); |
| 347 | Packet *vtrecv(VtConn*); |
| 348 | int vtversion(VtConn *z); |
| 349 | void vtdebug(VtConn *z, char*, ...); |
| 350 | void vthangup(VtConn *z); |
rsc | 6fc7da3 | 2006-10-19 21:58:59 +0000 | [diff] [blame] | 351 | int vtgoodbye(VtConn *z); |
| 352 | |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 353 | /* #pragma varargck argpos vtdebug 2 */ |
| 354 | |
| 355 | /* server */ |
| 356 | typedef struct VtSrv VtSrv; |
| 357 | typedef struct VtReq VtReq; |
| 358 | struct VtReq |
| 359 | { |
| 360 | VtFcall tx; |
| 361 | VtFcall rx; |
| 362 | /* private */ |
| 363 | VtSrv *srv; |
| 364 | void *sc; |
| 365 | }; |
| 366 | |
| 367 | int vtsrvhello(VtConn*); |
| 368 | VtSrv *vtlisten(char *addr); |
| 369 | VtReq *vtgetreq(VtSrv*); |
| 370 | void vtrespond(VtReq*); |
| 371 | |
| 372 | /* client */ |
| 373 | Packet *vtrpc(VtConn*, Packet*); |
rsc | 7252036 | 2005-11-02 19:08:43 +0000 | [diff] [blame] | 374 | Packet *_vtrpc(VtConn*, Packet*, VtFcall*); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 375 | void vtrecvproc(void*); /* VtConn* */ |
| 376 | void vtsendproc(void*); /* VtConn* */ |
| 377 | |
| 378 | int vtconnect(VtConn*); |
| 379 | int vthello(VtConn*); |
| 380 | int vtread(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n); |
| 381 | int vtwrite(VtConn*, uchar score[VtScoreSize], uint type, uchar *buf, int n); |
| 382 | Packet *vtreadpacket(VtConn*, uchar score[VtScoreSize], uint type, int n); |
| 383 | int vtwritepacket(VtConn*, uchar score[VtScoreSize], uint type, Packet *p); |
| 384 | int vtsync(VtConn*); |
| 385 | int vtping(VtConn*); |
| 386 | |
| 387 | /* |
| 388 | * Data blocks and block cache. |
| 389 | */ |
| 390 | enum |
| 391 | { |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 392 | NilBlock = ~0 |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | typedef struct VtBlock VtBlock; |
| 396 | typedef struct VtCache VtCache; |
| 397 | |
| 398 | struct VtBlock |
| 399 | { |
| 400 | VtCache *c; |
| 401 | QLock lk; |
| 402 | |
| 403 | uchar *data; |
| 404 | uchar score[VtScoreSize]; |
| 405 | uchar type; /* BtXXX */ |
| 406 | |
| 407 | /* internal to cache */ |
| 408 | int nlock; |
| 409 | int iostate; |
| 410 | int ref; |
| 411 | u32int heap; |
| 412 | VtBlock *next; |
| 413 | VtBlock **prev; |
| 414 | u32int used; |
| 415 | u32int used2; |
| 416 | u32int addr; |
rsc | 6fc7da3 | 2006-10-19 21:58:59 +0000 | [diff] [blame] | 417 | uintptr pc; |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | u32int vtglobaltolocal(uchar[VtScoreSize]); |
| 421 | void vtlocaltoglobal(u32int, uchar[VtScoreSize]); |
| 422 | |
rsc | 88dc23a | 2005-07-13 13:34:57 +0000 | [diff] [blame] | 423 | VtCache *vtcachealloc(VtConn*, int blocksize, ulong nblocks); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 424 | void vtcachefree(VtCache*); |
| 425 | VtBlock *vtcachelocal(VtCache*, u32int addr, int type); |
| 426 | VtBlock *vtcacheglobal(VtCache*, uchar[VtScoreSize], int type); |
| 427 | VtBlock *vtcacheallocblock(VtCache*, int type); |
rsc | b98ae9b | 2004-06-17 19:18:31 +0000 | [diff] [blame] | 428 | void vtcachesetwrite(VtCache*, int(*)(VtConn*,uchar[VtScoreSize],uint,uchar*,int)); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 429 | void vtblockput(VtBlock*); |
| 430 | u32int vtcacheblocksize(VtCache*); |
| 431 | int vtblockwrite(VtBlock*); |
| 432 | VtBlock *vtblockcopy(VtBlock*); |
| 433 | void vtblockduplock(VtBlock*); |
| 434 | |
rsc | 7252036 | 2005-11-02 19:08:43 +0000 | [diff] [blame] | 435 | extern int vtcachencopy, vtcachenread, vtcachenwrite; |
rsc | 11b0772 | 2006-05-05 02:42:57 +0000 | [diff] [blame] | 436 | extern int vttracelevel; |
rsc | 7252036 | 2005-11-02 19:08:43 +0000 | [diff] [blame] | 437 | |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 438 | /* |
| 439 | * Hash tree file tree. |
| 440 | */ |
| 441 | typedef struct VtFile VtFile; |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 442 | struct VtFile |
| 443 | { |
| 444 | QLock lk; |
| 445 | int ref; |
| 446 | int local; |
| 447 | VtBlock *b; /* block containing this file */ |
| 448 | uchar score[VtScoreSize]; /* score of block containing this file */ |
| 449 | |
| 450 | /* immutable */ |
| 451 | VtCache *c; |
| 452 | int mode; |
| 453 | u32int gen; |
| 454 | int dsize; |
rsc | 2e3b809 | 2005-07-13 14:00:00 +0000 | [diff] [blame] | 455 | int psize; |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 456 | int dir; |
| 457 | VtFile *parent; |
| 458 | int epb; /* entries per block in parent */ |
| 459 | u32int offset; /* entry offset in parent */ |
| 460 | }; |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 461 | |
| 462 | enum |
| 463 | { |
| 464 | VtOREAD, |
| 465 | VtOWRITE, |
rsc | cbeb0b2 | 2006-04-01 19:24:03 +0000 | [diff] [blame] | 466 | VtORDWR |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 467 | }; |
| 468 | |
| 469 | VtFile *vtfileopenroot(VtCache*, VtEntry*); |
| 470 | VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type); |
| 471 | VtFile *vtfileopen(VtFile*, u32int, int); |
| 472 | VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir); |
rsc | 23fb2ed | 2005-07-24 20:15:44 +0000 | [diff] [blame] | 473 | VtFile *_vtfilecreate(VtFile*, int offset, int psize, int dsize, int dir); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 474 | VtBlock *vtfileblock(VtFile*, u32int, int mode); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 475 | long vtfileread(VtFile*, void*, long, vlong); |
| 476 | long vtfilewrite(VtFile*, void*, long, vlong); |
| 477 | int vtfileflush(VtFile*); |
| 478 | void vtfileincref(VtFile*); |
| 479 | void vtfileclose(VtFile*); |
| 480 | int vtfilegetentry(VtFile*, VtEntry*); |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 481 | int vtfilesetentry(VtFile*, VtEntry*); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 482 | int vtfileblockscore(VtFile*, u32int, uchar[VtScoreSize]); |
| 483 | u32int vtfilegetdirsize(VtFile*); |
| 484 | int vtfilesetdirsize(VtFile*, u32int); |
| 485 | void vtfileunlock(VtFile*); |
| 486 | int vtfilelock(VtFile*, int); |
| 487 | int vtfilelock2(VtFile*, VtFile*, int); |
rsc | 3f6a501 | 2005-12-30 02:06:05 +0000 | [diff] [blame] | 488 | int vtfileflushbefore(VtFile*, u64int); |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 489 | int vtfiletruncate(VtFile*); |
| 490 | uvlong vtfilegetsize(VtFile*); |
rsc | 3f6a501 | 2005-12-30 02:06:05 +0000 | [diff] [blame] | 491 | int vtfilesetsize(VtFile*, u64int); |
rsc | d23a617 | 2004-03-15 01:57:29 +0000 | [diff] [blame] | 492 | int vtfileremove(VtFile*); |
rsc | 97a5e5f | 2003-11-23 18:25:35 +0000 | [diff] [blame] | 493 | |
rsc | d20564a | 2006-07-18 15:23:58 +0000 | [diff] [blame] | 494 | extern int vttimefmt(Fmt*); |
| 495 | |
rsc | a09e80f | 2004-05-23 00:59:17 +0000 | [diff] [blame] | 496 | extern int chattyventi; |
| 497 | extern int ventidoublechecksha1; |
rsc | 5810cad | 2005-02-15 05:03:44 +0000 | [diff] [blame] | 498 | extern int ventilogging; |
rsc | a09e80f | 2004-05-23 00:59:17 +0000 | [diff] [blame] | 499 | |
rsc | 587f8f4 | 2005-02-13 18:32:06 +0000 | [diff] [blame] | 500 | extern char *VtServerLog; |
| 501 | |
rsc | 819822c | 2004-06-16 16:45:22 +0000 | [diff] [blame] | 502 | #ifdef __cplusplus |
rsc | f701258 | 2003-11-25 01:40:27 +0000 | [diff] [blame] | 503 | } |
| 504 | #endif |
| 505 | #endif |