6 static char EBadVacFormat[] = "bad format for vac file";
9 vfsAlloc(VtSession *z, int bsize, long ncache)
13 fs = vtMemAllocZ(sizeof(VacFS));
17 fs->cache = cacheAlloc(z, bsize, ncache);
22 readScore(int fd, uchar score[VtScoreSize])
27 n = readn(fd, buf, sizeof(buf));
29 vtSetError("short read");
32 if(strncmp(buf, "vac:", 4) != 0) {
33 vtSetError("not a vac file");
36 memset(score, 0, VtScoreSize);
37 for(i=4; i<sizeof(buf); i++) {
38 if(buf[i] >= '0' && buf[i] <= '9')
40 else if(buf[i] >= 'a' && buf[i] <= 'f')
41 c = buf[i] - 'a' + 10;
42 else if(buf[i] >= 'A' && buf[i] <= 'F')
43 c = buf[i] - 'A' + 10;
45 vtSetError("bad format for venti score");
57 vfsOpen(VtSession *z, char *file, int readOnly, long ncache)
62 uchar score[VtScoreSize], buf[VtRootSize];
65 fd = open(file, OREAD);
71 if(!readScore(fd, score)) {
77 n = vtRead(z, score, VtRootType, buf, VtRootSize);
81 vtSetError("vtRead on root too short");
85 if(!vtSha1Check(score, buf, VtRootSize)) {
86 vtSetError("vtSha1Check failed on root block");
90 if(!vtRootUnpack(&rt, buf))
93 if(strcmp(rt.type, "vac") != 0) {
94 vtSetError("not a vac root");
98 fs = vfsAlloc(z, rt.blockSize, ncache);
99 memmove(fs->score, score, VtScoreSize);
100 fs->readOnly = readOnly;
101 root = vfRoot(fs, rt.score);
115 vacFsCreate(VtSession *z, int bsize, long ncache)
119 fs = vfsAlloc(z, bsize, ncache);
124 vfsIsReadOnly(VacFS *fs)
126 return fs->readOnly != 0;
130 vfsGetRoot(VacFS *fs)
132 return vfIncRef(fs->root);
136 vfsGetBlockSize(VacFS *fs)
142 vfsGetScore(VacFS *fs, uchar score[VtScoreSize])
144 memmove(fs, score, VtScoreSize);
149 vfsGetCacheSize(VacFS *fs)
151 return cacheGetSize(fs->cache);
155 vfsSetCacheSize(VacFS *fs, long size)
157 return cacheSetSize(fs->cache, size);
161 vfsSnapshot(VacFS *fs, char *src, char *dst)
181 cacheCheck(fs->cache);
182 cacheFree(fs->cache);
183 memset(fs, 0, sizeof(VacFS));