6 static char EBadVacFormat[] = "bad format for vac file";
9 vacfsalloc(VtConn *z, int bsize, int ncache, int mode)
13 fs = vtmallocz(sizeof(VacFs));
17 fs->cache = vtcachealloc(z, bsize, ncache, mode);
22 readscore(int fd, uchar score[VtScoreSize])
27 n = readn(fd, buf, sizeof(buf)-1);
29 werrstr("short read");
34 if(vtparsescore(buf, &pref, score) < 0){
35 werrstr(EBadVacFormat);
38 if(pref==nil || strcmp(pref, "vac") != 0) {
39 werrstr("not a vac file");
46 vacfsopen(VtConn *z, char *file, int mode, int ncache)
49 uchar score[VtScoreSize];
51 fd = open(file, OREAD);
55 if(readscore(fd, score) < 0){
61 return vacfsopenscore(z, score, mode, ncache);
65 vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache)
70 uchar buf[VtRootSize];
75 n = vtread(z, score, VtRootType, buf, VtRootSize);
79 werrstr("vtread on root too short");
83 if(vtrootunpack(&rt, buf) < 0)
86 if(strcmp(rt.type, "vac") != 0) {
87 werrstr("not a vac root");
91 fs = vacfsalloc(z, rt.blocksize, ncache, mode);
92 memmove(fs->score, score, VtScoreSize);
95 memmove(e.score, score, VtScoreSize);
97 e.psize = (rt.blocksize/VtEntrySize)*VtEntrySize;
98 e.dsize = rt.blocksize;
100 e.flags = VtEntryActive;
101 e.size = 3*VtEntrySize;
104 if((r = vtfileopenroot(fs->cache, &e)) == nil)
107 root = _vacfileroot(fs, r);
122 vacfscreate(VtConn *z, int bsize, int ncache)
124 return vacfsalloc(z, bsize, ncache, VtORDWR);
134 vacfsgetroot(VacFs *fs)
136 return vacfileincref(fs->root);
140 vacfsgetblocksize(VacFs *fs)
146 vacfsgetscore(VacFs *fs, u8int *score)
148 memmove(score, fs->score, VtScoreSize);
153 _vacfsnextqid(VacFs *fs, uvlong *qid)
167 vacfsclose(VacFs *fs)
170 vacfiledecref(fs->root);
172 vtcachefree(fs->cache);