vac: major cleanup and bug fixes
This commit is contained in:
parent
e9b70a5f4c
commit
ecc0a1b0e7
8 changed files with 1442 additions and 1289 deletions
|
|
@ -36,5 +36,3 @@ struct VacDirEnum
|
||||||
VacDir *buf;
|
VacDir *buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
void _mbinit(MetaBlock*, u8int*, uint, uint);
|
|
||||||
int _mbsearch(MetaBlock*, char*, int*, MetaEntry*);
|
|
||||||
|
|
|
||||||
2529
src/cmd/vac/file.c
2529
src/cmd/vac/file.c
File diff suppressed because it is too large
Load diff
|
|
@ -3,6 +3,9 @@ void mbinsert(MetaBlock *mb, int i, MetaEntry*);
|
||||||
void mbdelete(MetaBlock *mb, int i, MetaEntry*);
|
void mbdelete(MetaBlock *mb, int i, MetaEntry*);
|
||||||
void mbpack(MetaBlock *mb);
|
void mbpack(MetaBlock *mb);
|
||||||
uchar *mballoc(MetaBlock *mb, int n);
|
uchar *mballoc(MetaBlock *mb, int n);
|
||||||
|
void mbinit(MetaBlock *mb, uchar *p, int n, int entries);
|
||||||
|
int mbsearch(MetaBlock*, char*, int*, MetaEntry*);
|
||||||
|
int mbresize(MetaBlock*, MetaEntry*, int);
|
||||||
|
|
||||||
int meunpack(MetaEntry*, MetaBlock *mb, int i);
|
int meunpack(MetaEntry*, MetaBlock *mb, int i);
|
||||||
int mecmp(MetaEntry*, char *s);
|
int mecmp(MetaEntry*, char *s);
|
||||||
|
|
|
||||||
185
src/cmd/vac/fs.c
185
src/cmd/vac/fs.c
|
|
@ -1,185 +0,0 @@
|
||||||
#include "stdinc.h"
|
|
||||||
#include "vac.h"
|
|
||||||
#include "dat.h"
|
|
||||||
#include "fns.h"
|
|
||||||
|
|
||||||
#define debug 0
|
|
||||||
|
|
||||||
static char EBadVacFormat[] = "bad format for vac file";
|
|
||||||
|
|
||||||
static VacFs *
|
|
||||||
vacfsalloc(VtConn *z, int bsize, int ncache, int mode)
|
|
||||||
{
|
|
||||||
VacFs *fs;
|
|
||||||
|
|
||||||
fs = vtmallocz(sizeof(VacFs));
|
|
||||||
fs->ref = 1;
|
|
||||||
fs->z = z;
|
|
||||||
fs->bsize = bsize;
|
|
||||||
fs->cache = vtcachealloc(z, bsize, ncache);
|
|
||||||
return fs;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
readscore(int fd, uchar score[VtScoreSize])
|
|
||||||
{
|
|
||||||
char buf[45], *pref;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
n = readn(fd, buf, sizeof(buf)-1);
|
|
||||||
if(n < sizeof(buf)-1) {
|
|
||||||
werrstr("short read");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
buf[n] = 0;
|
|
||||||
|
|
||||||
if(vtparsescore(buf, &pref, score) < 0){
|
|
||||||
werrstr(EBadVacFormat);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(pref==nil || strcmp(pref, "vac") != 0) {
|
|
||||||
werrstr("not a vac file");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
VacFs*
|
|
||||||
vacfsopen(VtConn *z, char *file, int mode, int ncache)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
uchar score[VtScoreSize];
|
|
||||||
char *prefix;
|
|
||||||
|
|
||||||
if(vtparsescore(file, &prefix, score) >= 0){
|
|
||||||
if(strcmp(prefix, "vac") != 0){
|
|
||||||
werrstr("not a vac file");
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
fd = open(file, OREAD);
|
|
||||||
if(fd < 0)
|
|
||||||
return nil;
|
|
||||||
if(readscore(fd, score) < 0){
|
|
||||||
close(fd);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
return vacfsopenscore(z, score, mode, ncache);
|
|
||||||
}
|
|
||||||
|
|
||||||
VacFs*
|
|
||||||
vacfsopenscore(VtConn *z, u8int *score, int mode, int ncache)
|
|
||||||
{
|
|
||||||
VacFs *fs;
|
|
||||||
int n;
|
|
||||||
VtRoot rt;
|
|
||||||
uchar buf[VtRootSize];
|
|
||||||
VacFile *root;
|
|
||||||
VtFile *r;
|
|
||||||
VtEntry e;
|
|
||||||
|
|
||||||
n = vtread(z, score, VtRootType, buf, VtRootSize);
|
|
||||||
if(n < 0)
|
|
||||||
return nil;
|
|
||||||
if(n != VtRootSize){
|
|
||||||
werrstr("vtread on root too short");
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(vtrootunpack(&rt, buf) < 0)
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
if(strcmp(rt.type, "vac") != 0) {
|
|
||||||
werrstr("not a vac root");
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
fs = vacfsalloc(z, rt.blocksize, ncache, mode);
|
|
||||||
memmove(fs->score, score, VtScoreSize);
|
|
||||||
fs->mode = mode;
|
|
||||||
|
|
||||||
memmove(e.score, rt.score, VtScoreSize);
|
|
||||||
e.gen = 0;
|
|
||||||
e.psize = (rt.blocksize/VtEntrySize)*VtEntrySize;
|
|
||||||
e.dsize = rt.blocksize;
|
|
||||||
e.type = VtDirType;
|
|
||||||
e.flags = VtEntryActive;
|
|
||||||
e.size = 3*VtEntrySize;
|
|
||||||
|
|
||||||
root = nil;
|
|
||||||
if((r = vtfileopenroot(fs->cache, &e)) == nil)
|
|
||||||
goto Err;
|
|
||||||
if(debug)
|
|
||||||
fprint(2, "r %p\n", r);
|
|
||||||
root = _vacfileroot(fs, r);
|
|
||||||
if(debug)
|
|
||||||
fprint(2, "root %p\n", root);
|
|
||||||
vtfileclose(r);
|
|
||||||
if(root == nil)
|
|
||||||
goto Err;
|
|
||||||
fs->root = root;
|
|
||||||
return fs;
|
|
||||||
Err:
|
|
||||||
if(root)
|
|
||||||
vacfiledecref(root);
|
|
||||||
vacfsclose(fs);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
VacFs *
|
|
||||||
vacfscreate(VtConn *z, int bsize, int ncache)
|
|
||||||
{
|
|
||||||
return vacfsalloc(z, bsize, ncache, VtORDWR);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
vacfsmode(VacFs *fs)
|
|
||||||
{
|
|
||||||
return fs->mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
VacFile*
|
|
||||||
vacfsgetroot(VacFs *fs)
|
|
||||||
{
|
|
||||||
return vacfileincref(fs->root);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
vacfsgetblocksize(VacFs *fs)
|
|
||||||
{
|
|
||||||
return fs->bsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
vacfsgetscore(VacFs *fs, u8int *score)
|
|
||||||
{
|
|
||||||
memmove(score, fs->score, VtScoreSize);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
_vacfsnextqid(VacFs *fs, uvlong *qid)
|
|
||||||
{
|
|
||||||
++fs->qid;
|
|
||||||
*qid = fs->qid;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
vacfssync(VacFs *fs)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
vacfsclose(VacFs *fs)
|
|
||||||
{
|
|
||||||
if(fs->root)
|
|
||||||
vacfiledecref(fs->root);
|
|
||||||
fs->root = nil;
|
|
||||||
vtcachefree(fs->cache);
|
|
||||||
vtfree(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -694,12 +694,12 @@ mbsearch(MetaBlock *mb, char *elem, int *ri, MetaEntry *me)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mbinit(MetaBlock *mb, uchar *p, int n)
|
mbinit(MetaBlock *mb, uchar *p, int n, int entries)
|
||||||
{
|
{
|
||||||
memset(mb, 0, sizeof(MetaBlock));
|
memset(mb, 0, sizeof(MetaBlock));
|
||||||
mb->maxsize = n;
|
mb->maxsize = n;
|
||||||
mb->buf = p;
|
mb->buf = p;
|
||||||
mb->maxindex = n/100;
|
mb->maxindex = entries;
|
||||||
mb->size = MetaHeaderSize + mb->maxindex*MetaIndexSize;
|
mb->size = MetaHeaderSize + mb->maxindex*MetaIndexSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1044,7 +1044,7 @@ dirsinkwritefile(DirSink *k, VacFile *vf)
|
||||||
{
|
{
|
||||||
VtEntry dir;
|
VtEntry dir;
|
||||||
|
|
||||||
if(vacfilegetvtentry(vf, &dir) < 0)
|
if(vacfilegetentries(vf, &dir, nil) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
dirsinkwrite(k, &dir);
|
dirsinkwrite(k, &dir);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,9 @@ struct VacDir
|
||||||
uvlong qidmax; /* qid maximum */
|
uvlong qidmax; /* qid maximum */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct VacFs
|
struct VacFs
|
||||||
{
|
{
|
||||||
int ref;
|
char name[128];
|
||||||
uchar score[VtScoreSize];
|
uchar score[VtScoreSize];
|
||||||
VacFile *root;
|
VacFile *root;
|
||||||
VtConn *z;
|
VtConn *z;
|
||||||
|
|
@ -103,28 +102,28 @@ int vacfsgetscore(VacFs *fs, u8int *score);
|
||||||
|
|
||||||
VacFile *vacfsgetroot(VacFs *fs);
|
VacFile *vacfsgetroot(VacFs *fs);
|
||||||
VacFile *vacfileopen(VacFs *fs, char *path);
|
VacFile *vacfileopen(VacFs *fs, char *path);
|
||||||
VacFile *vacfilecreate(VacFile *file, char *elem, ulong perm, char *muid);
|
VacFile *vacfilecreate(VacFile *file, char *elem, ulong perm);
|
||||||
VacFile *vacfilewalk(VacFile *file, char *elem);
|
VacFile *vacfilewalk(VacFile *file, char *elem);
|
||||||
int vacfileremove(VacFile *file, char *muid);
|
int vacfileremove(VacFile *file);
|
||||||
int vacfileread(VacFile *file, void *buf, int n, vlong offset);
|
int vacfileread(VacFile *file, void *buf, int n, vlong offset);
|
||||||
int vacfileblockscore(VacFile *file, u32int, u8int*);
|
int vacfileblockscore(VacFile *file, u32int, u8int*);
|
||||||
int vacfilewrite(VacFile *file, void *buf, int n, vlong offset, char *muid);
|
int vacfilewrite(VacFile *file, void *buf, int n, vlong offset);
|
||||||
int vacfilereadpacket(VacFile *file, Packet **pp, vlong offset);
|
|
||||||
int vacfilewritepacket(VacFile *file, Packet *p, vlong offset, char *muid);
|
|
||||||
uvlong vacfilegetid(VacFile *file);
|
uvlong vacfilegetid(VacFile *file);
|
||||||
ulong vacfilegetmcount(VacFile *file);
|
ulong vacfilegetmcount(VacFile *file);
|
||||||
int vacfileisdir(VacFile *file);
|
int vacfileisdir(VacFile *file);
|
||||||
int vacfileisroot(VacFile *file);
|
int vacfileisroot(VacFile *file);
|
||||||
ulong vacfilegetmode(VacFile *file);
|
ulong vacfilegetmode(VacFile *file);
|
||||||
int vacfilegetblocksize(VacFile *file, u32int bn, u8int *score);
|
|
||||||
int vacfilegetsize(VacFile *file, uvlong *size);
|
int vacfilegetsize(VacFile *file, uvlong *size);
|
||||||
int vacfilegetdir(VacFile *file, VacDir *dir);
|
int vacfilegetdir(VacFile *file, VacDir *dir);
|
||||||
int vacfilesetdir(VacFile *file, VacDir *dir, char *muid);
|
int vacfilesetdir(VacFile *file, VacDir *dir);
|
||||||
int vacfilegetvtentry(VacFile *file, VtEntry *entry);
|
|
||||||
VacFile *vacfilegetparent(VacFile *file);
|
VacFile *vacfilegetparent(VacFile *file);
|
||||||
int vacfilesync(VacFile*);
|
int vacfileflush(VacFile*, int);
|
||||||
VacFile *vacfileincref(VacFile*);
|
VacFile *vacfileincref(VacFile*);
|
||||||
int vacfiledecref(VacFile*);
|
int vacfiledecref(VacFile*);
|
||||||
|
int vacfilesetsize(VacFile *f, uvlong size);
|
||||||
|
|
||||||
|
int vacfilegetentries(VacFile *f, VtEntry *e, VtEntry *me);
|
||||||
|
int vacfilesetentries(VacFile *f, VtEntry *e, VtEntry *me);
|
||||||
|
|
||||||
void vdcleanup(VacDir *dir);
|
void vdcleanup(VacDir *dir);
|
||||||
void vdcopy(VacDir *dst, VacDir *src);
|
void vdcopy(VacDir *dst, VacDir *src);
|
||||||
|
|
@ -134,3 +133,4 @@ VacDirEnum *vdeopen(VacFile*);
|
||||||
int vderead(VacDirEnum*, VacDir *);
|
int vderead(VacDirEnum*, VacDir *);
|
||||||
void vdeclose(VacDirEnum*);
|
void vdeclose(VacDirEnum*);
|
||||||
int vdeunread(VacDirEnum*);
|
int vdeunread(VacDirEnum*);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -445,7 +445,7 @@ rcreate(Fid* fid)
|
||||||
}
|
}
|
||||||
mode |= ModeDir;
|
mode |= ModeDir;
|
||||||
}
|
}
|
||||||
vf = vacfilecreate(vf, rhdr.name, mode, "none");
|
vf = vacfilecreate(vf, rhdr.name, mode);
|
||||||
if(vf == nil) {
|
if(vf == nil) {
|
||||||
char err[80];
|
char err[80];
|
||||||
rerrstr(err, sizeof err);
|
rerrstr(err, sizeof err);
|
||||||
|
|
@ -541,7 +541,7 @@ rremove(Fid *f)
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!vacfileremove(vf, "none")) {
|
if(!vacfileremove(vf)) {
|
||||||
rerrstr(errbuf, sizeof errbuf);
|
rerrstr(errbuf, sizeof errbuf);
|
||||||
err = errbuf;
|
err = errbuf;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue