commit - 7ba8aa0c7083415ad69c2f8e591425f3c6ebf952
commit + 23fb2edb22703ad10aae02295e654b3de68617c5
blob - acb255d24c3159e6e05ee5de92bf62b8d2449b01
blob + e1bb23259c244b912f555d4cb74bf0576762fc29
--- include/venti.h
+++ include/venti.h
VtFile *vtfilecreateroot(VtCache*, int psize, int dsize, int type);
VtFile *vtfileopen(VtFile*, u32int, int);
VtFile *vtfilecreate(VtFile*, int psize, int dsize, int dir);
+VtFile *_vtfilecreate(VtFile*, int offset, int psize, int dsize, int dir);
VtBlock *vtfileblock(VtFile*, u32int, int mode);
long vtfileread(VtFile*, void*, long, vlong);
long vtfilewrite(VtFile*, void*, long, vlong);
blob - bb0bb03d3bbf4ed3f4a3b2c090fcdaae6e7e5a36
blob + 10c632c977d107904f49209b5e0f7e5ef98fe1aa
--- src/cmd/vac/file.c
+++ src/cmd/vac/file.c
#include "fns.h"
#include "error.h"
+#define debug 0
+
/*
* locking order is upwards. A thread can hold the lock for a VacFile
* and then acquire the lock of its parent
VacFile*
_vacfileroot(VacFs *fs, VtFile *r)
{
+ int redirected;
+ char err[ERRMAX];
VtBlock *b;
VtFile *r0, *r1, *r2;
MetaBlock mb;
MetaEntry me;
VacFile *root, *mr;
+ redirected = 0;
+Top:
b = nil;
root = nil;
mr = nil;
if(vtfilelock(r, -1) < 0)
return nil;
r0 = vtfileopen(r, 0, fs->mode);
+ if(debug)
+ fprint(2, "r0 %p\n", r0);
if(r0 == nil)
goto Err;
+ r2 = vtfileopen(r, 2, fs->mode);
+ if(debug)
+ fprint(2, "r2 %p\n", r2);
+ if(r2 == nil){
+ /*
+ * some vac files (e.g., from fossil)
+ * have an extra layer of indirection.
+ */
+ rerrstr(err, sizeof err);
+ if(!redirected && strstr(err, "not active")){
+ vtfileunlock(r);
+ r = r0;
+ goto Top;
+ }
+ goto Err;
+ }
r1 = vtfileopen(r, 1, fs->mode);
+ if(debug)
+ fprint(2, "r1 %p\n", r1);
if(r1 == nil)
goto Err;
- r2 = vtfileopen(r, 2, fs->mode);
- if(r2 == nil)
- goto Err;
mr = filealloc(fs);
mr->msource = r2;
blob - f635d5d1147f11ccf99ecab3d8646d8d8a3dea29
blob + d9ab258cb88a5fdf846d163a626f8bba904f52ed
--- src/cmd/vac/fs.c
+++ src/cmd/vac/fs.c
#include "dat.h"
#include "fns.h"
+#define debug 0
+
static char EBadVacFormat[] = "bad format for vac file";
static VacFs *
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)
blob - dfc0e1a5a5dca31c9d18aa2f679b3bc55e163751
blob + 1f8d99958612cb60b242510aa39e3603cb9879a1
--- src/cmd/vac/mkfile
+++ src/cmd/vac/mkfile
fs\
pack\
-LIB=${LIBFILES:%=%.$O}
+LIB=${LIBFILES:%=%.$O} $PLAN9/lib/libventi.a
HFILES=\
$PLAN9/include/venti.h\
blob - 0b4f818ae4d07e844e21804293ac04bda036662c
blob + bcb9b57e22665e1ab95eccfd12cc5a22244d72a6
--- src/cmd/vac/vac.c
+++ src/cmd/vac/vac.c
/* build meta information for the root */
ms = metasinkalloc(z, bsize, bsize);
/* fake into a directory */
- dir->mode |= (dir->mode&0444)>>2;
+ dir->mode = DMDIR|0555;
dir->qid.type |= QTDIR;
- dir->mode |= DMDIR;
plan9tovacdir(&vd, dir, 0, fileid++);
if(strcmp(vd.elem, "/") == 0){
vtfree(vd.elem);
blob - 6720919cab84e2f0027278819fde2a92eb01b3c6
blob + 4064cfa9d5cc02d4eec2327053ba7093cdef9a28
--- src/cmd/vac/vacfs.c
+++ src/cmd/vac/vacfs.c
long ncache = 1000;
int readOnly = 1;
+ fmtinstall('H', encodefmt);
+ fmtinstall('V', vtscorefmt);
+ fmtinstall('F', vtfcallfmt);
+
defsrv = nil;
ARGBEGIN{
case 'd':
case 'p':
noperm = 1;
break;
+ case 'V':
+ chattyventi = 1;
+ break;
default:
usage();
}ARGEND
if(post9pservice(p[1], defsrv) != 0)
sysfatal("post9pservice");
-
threadexits(0);
}
notify(notifyf);
user = getuser();
- fmtinstall('V', vtscorefmt);
-// fmtinstall('R', vtErrFmt);
-
conn = vtdial(host);
if(conn == nil)
sysfatal("could not connect to server: %r");
blob - 3f3441e731ae4a9e22a575002c5de2964d625a19
blob + a48e62e6a9c6183f6e252b65655367f1fa06dd48
--- src/cmd/venti/read.c
+++ src/cmd/venti/read.c
host = EARGF(usage());
break;
case 't':
- type = atoi(argv[1]);
+ type = atoi(EARGF(usage()));
break;
default:
usage();
break;
}
}
- }else{
- type = atoi(argv[1]);
+ }else
n = vtread(z, score, type, buf, VtMaxLumpSize);
- }
+
vthangup(z);
if(n < 0)
sysfatal("could not read block: %r");
blob - 4cf6029335741688f83b9bd9ef2746447406599d
blob + 640b190684fa76fff63a8a62794fef80cc24d1d1
--- src/cmd/venti/srv/buildindex.c
+++ src/cmd/venti/srv/buildindex.c
zero = 1;
bcmem = 0;
+ ventifmtinstall();
ARGBEGIN{
case 'B':
bcmem = unittoull(ARGF());
blob - 4b8358ca261de4035620a1fc79a4d9ef25a68694
blob + 7563faef2cdff349417a216bc6fa862f1502e600
--- src/cmd/venti/srv/wrarena.c
+++ src/cmd/venti/srv/wrarena.c
if(arena == nil)
sysfatal("initarena: %r");
- if(host && strcmp(host, "/dev/null") != 0){
+ z = nil;
+ if(host==nil || strcmp(host, "/dev/null") != 0){
z = vtdial(host);
if(z == nil)
sysfatal("could not connect to server: %r");
if(vtconnect(z) < 0)
sysfatal("vtconnect: %r");
- }else
- z = nil;
+ }
c = chancreate(sizeof(ZClump), 0);
for(i=0; i<12; i++)
blob - /dev/null
blob + 5d67ad316f1e66696d87fd3e9b5f54ec2821582d (mode 644)
--- /dev/null
+++ src/cmd/venti/root.c
+#include <u.h>
+#include <libc.h>
+#include <venti.h>
+#include <libsec.h>
+#include <thread.h>
+
+void
+usage(void)
+{
+ fprint(2, "usage: root [-h host] score\n");
+ threadexitsall("usage");
+}
+
+void
+threadmain(int argc, char *argv[])
+{
+ int i, n;
+ uchar score[VtScoreSize];
+ uchar *buf;
+ VtConn *z;
+ char *host;
+ VtRoot root;
+
+ fmtinstall('F', vtfcallfmt);
+ fmtinstall('V', vtscorefmt);
+ quotefmtinstall();
+
+ host = nil;
+ ARGBEGIN{
+ case 'h':
+ host = EARGF(usage());
+ break;
+ default:
+ usage();
+ break;
+ }ARGEND
+
+ if(argc == 0)
+ usage();
+
+ buf = vtmallocz(VtMaxLumpSize);
+
+ z = vtdial(host);
+ if(z == nil)
+ sysfatal("could not connect to server: %r");
+
+ if(vtconnect(z) < 0)
+ sysfatal("vtconnect: %r");
+
+ for(i=0; i<argc; i++){
+ if(vtparsescore(argv[i], nil, score) < 0){
+ fprint(2, "cannot parse score '%s': %r\n", argv[i]);
+ continue;
+ }
+ n = vtread(z, score, VtRootType, buf, VtMaxLumpSize);
+ if(n < 0){
+ fprint(2, "could not read block %V: %r\n", score);
+ continue;
+ }
+ if(n != VtRootSize){
+ fprint(2, "block %V is wrong size %d != 300\n", score, n);
+ continue;
+ }
+ if(vtrootunpack(&root, buf) < 0){
+ fprint(2, "unpacking block %V: %r\n", score);
+ continue;
+ }
+ print("%V: %q %q %V %d %V\n", score, root.name, root.type, root.score, root.blocksize, root.prev);
+ }
+ vthangup(z);
+ threadexitsall(0);
+}
blob - 09ca5ea837a5c53c46b3f04133163c1f7f045b2d
blob + 71bdb62c84a5b3b6e5a1eb9687ca3f9f5a23b934
--- src/libventi/cache.c
+++ src/libventi/cache.c
{
VtBlock *b;
- if(addr >= c->nblock)
- sysfatal("vtcachelocal: asked for block #%ud; only %d blocks\n",
+ if(addr == 0)
+ sysfatal("vtcachelocal: asked for nonexistent block 0");
+ if(addr > c->nblock)
+ sysfatal("vtcachelocal: asked for block #%ud; only %d blocks",
addr, c->nblock);
- b = &c->block[addr];
+ b = &c->block[addr-1];
if(b->addr == NilBlock || b->iostate != BioLocal)
sysfatal("vtcachelocal: block is not local");
b = vtcachebumpblock(c);
b->iostate = BioLocal;
b->type = type;
- b->addr = b - c->block;
+ b->addr = (b - c->block)+1;
vtzeroextend(type, b->data, 0, c->blocksize);
vtlocaltoglobal(b->addr, b->score);
qunlock(&c->lk);
blob - ca1d200926bd4e2c87f15fc8bd87156aea2b4c03
blob + aeb8dada34e85b03f6cb5d76dd8495ddeba82b74
--- src/libventi/entry.c
+++ src/libventi/entry.c
checksize(int n)
{
if(n < 256 || n > VtMaxLumpSize) {
- werrstr("bad block size");
+ werrstr("bad block size %#ux", n);
return -1;
}
return 0;
if(!(e->flags & VtEntryActive))
return 0;
+ /*
+ * Some old vac files use psize==0 and dsize==0 when the
+ * file itself has size 0 or is zeros. Just to make programs not
+ * have to figure out what block sizes of 0 means, rewrite them.
+ */
+ if(e->psize == 0 && e->dsize == 0
+ && memcmp(e->score, vtzeroscore, VtScoreSize) == 0){
+ e->psize = 4096;
+ e->dsize = 4096;
+ }
if(checksize(e->psize) < 0 || checksize(e->dsize) < 0)
return -1;
blob - 89b307c6a3d91e083674c500c8caa0fa58499c6d
blob + 9b250114b042d84e621bddf051248bd5c037dbfb
--- src/libventi/file.c
+++ src/libventi/file.c
#define MaxBlock (1UL<<31)
-static char EBadEntry[] = "bad VtEntry";
static char ENotDir[] = "walk in non-directory";
static char ETooBig[] = "file too big";
/* static char EBadAddr[] = "bad address"; */
}else
epb = p->dsize / VtEntrySize;
- if(b->type != VtDirType)
- goto Bad;
+ if(b->type != VtDirType){
+ werrstr("bad block type %#uo", b->type);
+ return nil;
+ }
/*
* a non-active entry is the only thing that
* get prints.
*/
if(vtentryunpack(&e, b->data, offset % epb) < 0){
- fprint(2, "vtentryunpack failed\n");
- goto Bad;
+ fprint(2, "vtentryunpack failed: %r (%.*H)\n", VtEntrySize, b->data+VtEntrySize*(offset%epb));
+ return nil;
}
if(!(e.flags & VtEntryActive)){
- if(0)fprint(2, "not active\n");
- goto Bad;
+ werrstr("entry not active");
+ return nil;
}
- if(e.psize < 256 || e.dsize < 256){
- fprint(2, "psize %ud dsize %ud\n", e.psize, e.dsize);
- goto Bad;
- }
if(DEPTH(e.type) < sizetodepth(e.size, e.psize, e.dsize)){
fprint(2, "depth %ud size %llud psize %ud dsize %ud\n",
DEPTH(e.type), e.size, e.psize, e.dsize);
- goto Bad;
+ werrstr("bad depth");
+ return nil;
}
size = vtcacheblocksize(c);
if(e.dsize > size || e.psize > size){
- fprint(2, "psize %ud dsize %ud blocksize %ud\n", e.psize, e.dsize, size);
- goto Bad;
+ werrstr("block sizes %ud, %ud bigger than cache block size %ud",
+ e.psize, e.dsize, size);
+ return nil;
}
r = vtmallocz(sizeof(VtFile));
r->epb = epb;
return r;
-Bad:
- werrstr(EBadEntry);
- return nil;
-
}
VtFile *
return r;
}
-VtFile *
+VtFile*
vtfilecreate(VtFile *r, int psize, int dsize, int type)
{
+ return _vtfilecreate(r, -1, psize, dsize, type);
+}
+
+VtFile*
+_vtfilecreate(VtFile *r, int o, int psize, int dsize, int type)
+{
int i;
VtBlock *b;
u32int bn, size;
VtEntry e;
int epb;
VtFile *rr;
- u32int offset;
-
+ u32int offset;
+
assert(ISLOCKED(r));
assert(psize <= VtMaxLumpSize);
assert(dsize <= VtMaxLumpSize);
/*
* look at a random block to see if we can find an empty entry
*/
- offset = lnrand(size+1);
- offset -= offset % epb;
+ if(o == -1){
+ offset = lnrand(size+1);
+ offset -= offset % epb;
+ }else
+ offset = o;
/* try the given block and then try the last block */
for(;;){