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);
45 _vtfileblock(VtCache *c, VtEntry *e, u32int bn)
48 int i, d, index[VtPointerDepth+1], t;
50 i = vtfileindices(e, bn, index);
53 d = (e->type&VtTypeDepthMask);
55 werrstr("bad address %d > %d (%x %x)", i, d, e->type, e->flags);
59 //fprint(2, "vtread %V\n", e->score);
60 b = vtcacheglobal(c, e->score, e->type);
64 for(i=d-1; i>=0; i--){
66 //fprint(2, "vtread %V\n", b->data+index[i]*VtScoreSize);
67 bb = vtcacheglobal(c, b->data+index[i]*VtScoreSize, t);
77 diskventiblockput(Block *b)
84 diskventiread(Disk *dd, u32int len, u64int offset)
86 DiskVenti *d = (DiskVenti*)dd;
92 vb = _vtfileblock(d->c, &d->e, offset/d->e.dsize);
96 b = mallocz(sizeof(Block), 1);
103 b->_close = diskventiblockput;
104 frag = offset%d->e.dsize;
105 b->data = (uchar*)vb->data + frag;
106 b->len = d->e.dsize - frag;
113 diskventiclose(Disk *dd)
115 DiskVenti *d = (DiskVenti*)dd;
120 diskopenventi(VtCache *c, uchar score[VtScoreSize])
127 if((b = vtcacheglobal(c, score, VtRootType)) == nil)
129 if(vtrootunpack(&root, b->data) < 0)
131 if(root.blocksize < 512 || (root.blocksize&(root.blocksize-1))){
132 werrstr("bad blocksize %d", root.blocksize);
137 if((b = vtcacheglobal(c, root.score, VtDirType)) == nil)
139 if(vtentryunpack(&e, b->data, 0) < 0)
143 if((e.type&VtTypeBaseMask) != VtDataType){
144 werrstr("not a single file");
148 d = mallocz(sizeof(DiskVenti), 1);
152 d->disk._read = diskventiread;
153 d->disk._close = diskventiclose;