6 extern void vtlibthread(void);
8 typedef struct DiskVenti DiskVenti;
16 extern int nfilereads;
19 * This part is like file.c but doesn't require storing the root block
20 * in the cache permanently and doesn't care about locking since
21 * all the blocks are read-only. Perhaps at some point this functionality
22 * should go into libvac in some form.
25 vtfileindices(VtEntry *e, u32int bn, int *index)
29 memset(index, 0, VtPointerDepth*sizeof(int));
31 np = e->psize/VtScoreSize;
32 memset(index, 0, sizeof(index));
33 for(i=0; bn > 0; i++){
34 if(i >= VtPointerDepth){
35 werrstr("bad block number %lud", (ulong)bn);
44 VtBlock *_vtfileblock(VtCache*, VtEntry*, u32int); /* avoid auto-inline by putting later in file */
46 diskventiblockput(Block *b)
53 diskventiread(Disk *dd, u32int len, u64int offset)
55 DiskVenti *d = (DiskVenti*)dd;
61 vb = _vtfileblock(d->c, &d->e, offset/d->e.dsize);
65 b = mallocz(sizeof(Block), 1);
72 b->_close = diskventiblockput;
73 frag = offset%d->e.dsize;
74 b->data = (uchar*)vb->data + frag;
75 b->len = d->e.dsize - frag;
82 _vtfileblock(VtCache *c, VtEntry *e, u32int bn)
85 int i, d, index[VtPointerDepth+1], t;
86 uchar score[VtScoreSize];
88 i = vtfileindices(e, bn, index);
91 d = (e->type&VtTypeDepthMask);
93 werrstr("bad address %d > %d (%x %x)", i, d, e->type, e->flags);
97 /*fprint(2, "vtread %V\n", e->score); */
98 b = vtcacheglobal(c, e->score, e->type);
99 for(i=d-1; i>=0 && b; i--){
101 /*fprint(2, "vtread %V\n", b->data+index[i]*VtScoreSize); */
102 memmove(score, b->data+index[i]*VtScoreSize, VtScoreSize);
104 b = vtcacheglobal(c, score, t);
110 diskventiclose(Disk *dd)
112 DiskVenti *d = (DiskVenti*)dd;
117 diskopenventi(VtCache *c, uchar score[VtScoreSize])
124 if((b = vtcacheglobal(c, score, VtRootType)) == nil)
126 if(vtrootunpack(&root, b->data) < 0)
128 if(root.blocksize < 512 || (root.blocksize&(root.blocksize-1))){
129 werrstr("bad blocksize %d", root.blocksize);
134 if((b = vtcacheglobal(c, root.score, VtDirType)) == nil)
136 if(vtentryunpack(&e, b->data, 0) < 0)
140 if((e.type&VtTypeBaseMask) != VtDataType){
141 werrstr("not a single file");
145 d = mallocz(sizeof(DiskVenti), 1);
149 d->disk._read = diskventiread;
150 d->disk._close = diskventiclose;