8 static char EBadVacFormat[] = "bad format for vac file";
11 vacfsalloc(VtConn *z, int bsize, int ncache, int mode)
15 fs = vtmallocz(sizeof(VacFs));
19 fs->cache = vtcachealloc(z, bsize, ncache);
24 readscore(int fd, uchar score[VtScoreSize])
29 n = readn(fd, buf, sizeof(buf)-1);
30 if(n < sizeof(buf)-1) {
31 werrstr("short read");
36 if(vtparsescore(buf, &pref, score) < 0){
37 werrstr(EBadVacFormat);
40 if(pref==nil || strcmp(pref, "vac") != 0) {
41 werrstr("not a vac file");
48 vacfsopen(VtConn *z, char *file, int mode, int ncache)
51 uchar score[VtScoreSize];
53 fd = open(file, OREAD);
57 if(readscore(fd, score) < 0){
63 return vacfsopenscore(z, score, mode, ncache);
67 vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache)
72 uchar buf[VtRootSize];
77 n = vtread(z, score, VtRootType, buf, VtRootSize);
81 werrstr("vtread on root too short");
85 if(vtrootunpack(&rt, buf) < 0)
88 if(strcmp(rt.type, "vac") != 0) {
89 werrstr("not a vac root");
93 fs = vacfsalloc(z, rt.blocksize, ncache, mode);
94 memmove(fs->score, score, VtScoreSize);
97 memmove(e.score, rt.score, VtScoreSize);
99 e.psize = (rt.blocksize/VtEntrySize)*VtEntrySize;
100 e.dsize = rt.blocksize;
102 e.flags = VtEntryActive;
103 e.size = 3*VtEntrySize;
106 if((r = vtfileopenroot(fs->cache, &e)) == nil)
109 fprint(2, "r %p\n", r);
110 root = _vacfileroot(fs, r);
112 fprint(2, "root %p\n", root);
126 vacfscreate(VtConn *z, int bsize, int ncache)
128 return vacfsalloc(z, bsize, ncache, VtORDWR);
138 vacfsgetroot(VacFs *fs)
140 return vacfileincref(fs->root);
144 vacfsgetblocksize(VacFs *fs)
150 vacfsgetscore(VacFs *fs, u8int *score)
152 memmove(score, fs->score, VtScoreSize);
157 _vacfsnextqid(VacFs *fs, uvlong *qid)
171 vacfsclose(VacFs *fs)
174 vacfiledecref(fs->root);
176 vtcachefree(fs->cache);