fossil: move from liboventi to libthread and libventi

R=rsc
https://codereview.appspot.com/13504049
diff --git a/src/cmd/fossil/9.h b/src/cmd/fossil/9.h
index b7bdec2..d25d151 100644
--- a/src/cmd/fossil/9.h
+++ b/src/cmd/fossil/9.h
@@ -57,31 +57,31 @@
 	int	isconsole;		/* immutable */
 	int	flags;			/* immutable */
 	char	remote[128];		/* immutable */
-	VtLock*	lock;
+	QLock	lock;
 	int	state;
 	int	fd;
 	Msg*	version;
 	u32int	msize;			/* negotiated with Tversion */
-	VtRendez* rendez;
+	Rendez	rendez;
 
 	Con*	anext;			/* alloc */
 	Con*	cnext;			/* in use */
 	Con*	cprev;
 
-	VtLock*	alock;
+	RWLock	alock;
 	int	aok;			/* authentication done */
 
-	VtLock*	mlock;
+	QLock	mlock;
 	Msg*	mhead;			/* all Msgs on this connection */
 	Msg*	mtail;
-	VtRendez* mrendez;
+	Rendez	mrendez;
 
-	VtLock*	wlock;
+	QLock	wlock;
 	Msg*	whead;			/* write queue */
 	Msg*	wtail;
-	VtRendez* wrendez;
+	Rendez	wrendez;
 
-	VtLock*	fidlock;		/* */
+	QLock	fidlock;		/* */
 	Fid*	fidhash[NFidHash];
 	Fid*	fhead;
 	Fid*	ftail;
@@ -98,7 +98,7 @@
 };
 
 struct Fid {
-	VtLock*	lock;
+	RWLock	lock;
 	Con*	con;
 	u32int	fidno;
 	int	ref;			/* inc/dec under Con.fidlock */
@@ -113,7 +113,7 @@
 	DirBuf*	db;
 	Excl*	excl;
 
-	VtLock*	alock;			/* Tauth/Tattach */
+	QLock	alock;			/* Tauth/Tattach */
 	AuthRpc* rpc;
 	char*	cuname;
 
diff --git a/src/cmd/fossil/9auth.c b/src/cmd/fossil/9auth.c
index 72b1f01..2926f91 100644
--- a/src/cmd/fossil/9auth.c
+++ b/src/cmd/fossil/9auth.c
@@ -8,44 +8,44 @@
 	AuthRpc *rpc;
 
 	if((rpc = afid->rpc) == nil){
-		vtSetError("not an auth fid");
+		werrstr("not an auth fid");
 		return -1;
 	}
 
 	switch(auth_rpc(rpc, "read", nil, 0)){
 	default:
-		vtSetError("fossil authRead: auth protocol not finished");
+		werrstr("fossil authRead: auth protocol not finished");
 		return -1;
 	case ARdone:
 		if((ai = auth_getinfo(rpc)) == nil){
-			vtSetError("%r");
+			werrstr("%r");
 			break;
 		}
 		if(ai->cuid == nil || *ai->cuid == '\0'){
-			vtSetError("auth with no cuid");
+			werrstr("auth with no cuid");
 			auth_freeAI(ai);
 			break;
 		}
 		assert(afid->cuname == nil);
-		afid->cuname = vtStrDup(ai->cuid);
+		afid->cuname = vtstrdup(ai->cuid);
 		auth_freeAI(ai);
 		if(Dflag)
 			fprint(2, "authRead cuname %s\n", afid->cuname);
 		assert(afid->uid == nil);
 		if((afid->uid = uidByUname(afid->cuname)) == nil){
-			vtSetError("unknown user %#q", afid->cuname);
+			werrstr("unknown user %#q", afid->cuname);
 			break;
 		}
 		return 0;
 	case ARok:
 		if(count < rpc->narg){
-			vtSetError("not enough data in auth read");
+			werrstr("not enough data in auth read");
 			break;
 		}
 		memmove(data, rpc->arg, rpc->narg);
 		return rpc->narg;
 	case ARphase:
-		vtSetError("%r");
+		werrstr("%r");
 		break;
 	}
 	return -1;
@@ -82,7 +82,7 @@
 		 * The console is allowed to attach without
 		 * authentication.
 		 */
-		vtRLock(con->alock);
+		rlock(&con->alock);
 		if(con->isconsole){
 			/* anything goes */
 		}else if((con->flags&ConNoneAllow) || con->aok){
@@ -91,21 +91,21 @@
 			if(noneprint++ < 10)
 				consPrint("attach %s as %s: allowing as none\n",
 					fsysGetName(fsys), fid->uname);
-			vtMemFree(fid->uname);
-			fid->uname = vtStrDup(unamenone);
+			vtfree(fid->uname);
+			fid->uname = vtstrdup(unamenone);
 		}else{
-			vtRUnlock(con->alock);
+			runlock(&con->alock);
 			consPrint("attach %s as %s: connection not authenticated, not console\n",
 				fsysGetName(fsys), fid->uname);
-			vtSetError("cannot attach as none before authentication");
+			werrstr("cannot attach as none before authentication");
 			return 0;
 		}
-		vtRUnlock(con->alock);
+		runlock(&con->alock);
 
 		if((fid->uid = uidByUname(fid->uname)) == nil){
 			consPrint("attach %s as %s: unknown uname\n",
 				fsysGetName(fsys), fid->uname);
-			vtSetError("unknown user");
+			werrstr("unknown user");
 			return 0;
 		}
 		return 1;
@@ -114,7 +114,7 @@
 	if((afid = fidGet(con, t->afid, 0)) == nil){
 		consPrint("attach %s as %s: bad afid\n",
 			fsysGetName(fsys), fid->uname);
-		vtSetError("bad authentication fid");
+		werrstr("bad authentication fid");
 		return 0;
 	}
 
@@ -126,7 +126,7 @@
 		consPrint("attach %s as %s: afid not an auth file\n",
 			fsysGetName(fsys), fid->uname);
 		fidPut(afid);
-		vtSetError("bad authentication fid");
+		werrstr("bad authentication fid");
 		return 0;
 	}
 	if(strcmp(afid->uname, fid->uname) != 0 || afid->fsys != fsys){
@@ -134,42 +134,42 @@
 			fsysGetName(fsys), fid->uname,
 			fsysGetName(afid->fsys), afid->uname);
 		fidPut(afid);
-		vtSetError("attach/auth mismatch");
+		werrstr("attach/auth mismatch");
 		return 0;
 	}
 
-	vtLock(afid->alock);
+	qlock(&afid->alock);
 	if(afid->cuname == nil){
 		if(authRead(afid, buf, 0) != 0 || afid->cuname == nil){
-			vtUnlock(afid->alock);
-			consPrint("attach %s as %s: %R\n",
+			qunlock(&afid->alock);
+			consPrint("attach %s as %s: %r\n",
 				fsysGetName(fsys), fid->uname);
 			fidPut(afid);
-			vtSetError("fossil authCheck: auth protocol not finished");
+			werrstr("fossil authCheck: auth protocol not finished");
 			return 0;
 		}
 	}
-	vtUnlock(afid->alock);
+	qunlock(&afid->alock);
 
 	assert(fid->uid == nil);
 	if((fid->uid = uidByUname(afid->cuname)) == nil){
 		consPrint("attach %s as %s: unknown cuname %s\n",
 			fsysGetName(fsys), fid->uname, afid->cuname);
 		fidPut(afid);
-		vtSetError("unknown user");
+		werrstr("unknown user");
 		return 0;
 	}
 
-	vtMemFree(fid->uname);
-	fid->uname = vtStrDup(afid->cuname);
+	vtfree(fid->uname);
+	fid->uname = vtstrdup(afid->cuname);
 	fidPut(afid);
 
 	/*
 	 * Allow "none" once the connection has been authenticated.
 	 */
-	vtLock(con->alock);
+	wlock(&con->alock);
 	con->aok = 1;
-	vtUnlock(con->alock);
+	wunlock(&con->alock);
 
 	return 1;
 }
diff --git a/src/cmd/fossil/9dir.c b/src/cmd/fossil/9dir.c
index 09b483b..fdba20d 100644
--- a/src/cmd/fossil/9dir.c
+++ b/src/cmd/fossil/9dir.c
@@ -14,11 +14,11 @@
 {
 	DirBuf *db;
 
-	db = vtMemAllocZ(sizeof(DirBuf));
+	db = vtmallocz(sizeof(DirBuf));
 	db->dee = deeOpen(file);
 	if(db->dee == nil){
 		/* can happen if dir is removed from under us */
-		vtMemFree(db);
+		vtfree(db);
 		return nil;
 	}
 	return db;
@@ -33,7 +33,7 @@
 	if(db->valid)
 		deCleanup(&db->de);
 	deeClose(db->dee);
-	vtMemFree(db);
+	vtfree(db);
 }
 
 int
@@ -82,9 +82,9 @@
 
 	n = convD2M(&dir, p, np);
 
-	vtMemFree(dir.muid);
-	vtMemFree(dir.gid);
-	vtMemFree(dir.uid);
+	vtfree(dir.muid);
+	vtfree(dir.gid);
+	vtfree(dir.uid);
 
 	return n;
 }
diff --git a/src/cmd/fossil/9excl.c b/src/cmd/fossil/9excl.c
index 6fce280..9cefe58 100644
--- a/src/cmd/fossil/9excl.c
+++ b/src/cmd/fossil/9excl.c
@@ -3,7 +3,7 @@
 #include "9.h"
 
 static struct {
-	VtLock*	lock;
+	QLock	lock;
 
 	Excl*	head;
 	Excl*	tail;
@@ -31,7 +31,7 @@
 	assert(fid->excl == nil);
 
 	t = time(0L);
-	vtLock(ebox.lock);
+	qlock(&ebox.lock);
 	for(excl = ebox.head; excl != nil; excl = excl->next){
 		if(excl->fsys != fid->fsys || excl->path != fid->qid.path)
 			continue;
@@ -44,8 +44,8 @@
 		 * a new one.
 		 */
 		if(excl->time >= t){
-			vtUnlock(ebox.lock);
-			vtSetError("exclusive lock");
+			qunlock(&ebox.lock);
+			werrstr("exclusive lock");
 			return 0;
 		}
 		excl->fsys = nil;
@@ -55,7 +55,7 @@
 	 * Not found or timed-out.
 	 * Alloc a new one and initialise.
 	 */
-	excl = vtMemAllocZ(sizeof(Excl));
+	excl = vtmallocz(sizeof(Excl));
 	excl->fsys = fid->fsys;
 	excl->path = fid->qid.path;
 	excl->time = t+LifeTime;
@@ -69,7 +69,7 @@
 	}
 	ebox.tail = excl;
 	excl->next = nil;
-	vtUnlock(ebox.lock);
+	qunlock(&ebox.lock);
 
 	fid->excl = excl;
 	return 1;
@@ -84,14 +84,14 @@
 	excl = fid->excl;
 
 	t = time(0L);
-	vtLock(ebox.lock);
+	qlock(&ebox.lock);
 	if(excl->time < t || excl->fsys != fid->fsys){
-		vtUnlock(ebox.lock);
-		vtSetError("exclusive lock broken");
+		qunlock(&ebox.lock);
+		werrstr("exclusive lock broken");
 		return 0;
 	}
 	excl->time = t+LifeTime;
-	vtUnlock(ebox.lock);
+	qunlock(&ebox.lock);
 
 	return 1;
 }
@@ -105,7 +105,7 @@
 		return;
 	fid->excl = nil;
 
-	vtLock(ebox.lock);
+	qlock(&ebox.lock);
 	if(excl->prev != nil)
 		excl->prev->next = excl->next;
 	else
@@ -114,13 +114,12 @@
 		excl->next->prev = excl->prev;
 	else
 		ebox.tail = excl->prev;
-	vtUnlock(ebox.lock);
+	qunlock(&ebox.lock);
 
-	vtMemFree(excl);
+	vtfree(excl);
 }
 
 void
 exclInit(void)
 {
-	ebox.lock = vtLockAlloc();
 }
diff --git a/src/cmd/fossil/9fid.c b/src/cmd/fossil/9fid.c
index ea7de5a..49fab0b 100644
--- a/src/cmd/fossil/9fid.c
+++ b/src/cmd/fossil/9fid.c
@@ -3,7 +3,7 @@
 #include "9.h"
 
 static struct {
-	VtLock*	lock;
+	QLock	lock;
 
 	Fid*	free;
 	int	nfree;
@@ -14,11 +14,11 @@
 fidLock(Fid* fid, int flags)
 {
 	if(flags & FidFWlock){
-		vtLock(fid->lock);
+		wlock(&fid->lock);
 		fid->flags = flags;
 	}
 	else
-		vtRLock(fid->lock);
+		rlock(&fid->lock);
 
 	/*
 	 * Callers of file* routines are expected to lock fsys->fs->elk
@@ -47,10 +47,10 @@
 		fsysFsRUnlock(fid->fsys);
 	if(fid->flags & FidFWlock){
 		fid->flags = 0;
-		vtUnlock(fid->lock);
+		wunlock(&fid->lock);
 		return;
 	}
-	vtRUnlock(fid->lock);
+	runlock(&fid->lock);
 }
 
 static Fid*
@@ -58,19 +58,17 @@
 {
 	Fid *fid;
 
-	vtLock(fbox.lock);
+	qlock(&fbox.lock);
 	if(fbox.nfree > 0){
 		fid = fbox.free;
 		fbox.free = fid->hash;
 		fbox.nfree--;
 	}
 	else{
-		fid = vtMemAllocZ(sizeof(Fid));
-		fid->lock = vtLockAlloc();
-		fid->alock = vtLockAlloc();
+		fid = vtmallocz(sizeof(Fid));
 	}
 	fbox.inuse++;
-	vtUnlock(fbox.lock);
+	qunlock(&fbox.lock);
 
 	fid->con = nil;
 	fid->fidno = NOFID;
@@ -105,11 +103,11 @@
 	fidUnlock(fid);
 
 	if(fid->uid != nil){
-		vtMemFree(fid->uid);
+		vtfree(fid->uid);
 		fid->uid = nil;
 	}
 	if(fid->uname != nil){
-		vtMemFree(fid->uname);
+		vtfree(fid->uname);
 		fid->uname = nil;
 	}
 	if(fid->excl != nil)
@@ -124,11 +122,11 @@
 		fid->fsys = nil;
 	}
 	if(fid->cuname != nil){
-		vtMemFree(fid->cuname);
+		vtfree(fid->cuname);
 		fid->cuname = nil;
 	}
 
-	vtLock(fbox.lock);
+	qlock(&fbox.lock);
 	fbox.inuse--;
 	if(fbox.nfree < 10){
 		fid->hash = fbox.free;
@@ -136,11 +134,9 @@
 		fbox.nfree++;
 	}
 	else{
-		vtLockFree(fid->alock);
-		vtLockFree(fid->lock);
-		vtMemFree(fid);
+		vtfree(fid);
 	}
-	vtUnlock(fbox.lock);
+	qunlock(&fbox.lock);
 }
 
 static void
@@ -182,7 +178,7 @@
 		return nil;
 
 	hash = &con->fidhash[fidno % NFidHash];
-	vtLock(con->fidlock);
+	qlock(&con->fidlock);
 	for(fid = *hash; fid != nil; fid = fid->hash){
 		if(fid->fidno != fidno)
 			continue;
@@ -192,17 +188,17 @@
 		 * when called from attach, clone or walk.
 		 */
 		if(flags & FidFCreate){
-			vtUnlock(con->fidlock);
-			vtSetError("%s: fid 0x%ud in use", argv0, fidno);
+			qunlock(&con->fidlock);
+			werrstr("%s: fid 0x%ud in use", argv0, fidno);
 			return nil;
 		}
 		fid->ref++;
-		vtUnlock(con->fidlock);
+		qunlock(&con->fidlock);
 
 		fidLock(fid, flags);
 		if((fid->open & FidOCreate) || fid->fidno == NOFID){
 			fidPut(fid);
-			vtSetError("%s: fid invalid", argv0);
+			werrstr("%s: fid invalid", argv0);
 			return nil;
 		}
 		return fid;
@@ -228,7 +224,7 @@
 		fid->next = nil;
 
 		con->nfid++;
-		vtUnlock(con->fidlock);
+		qunlock(&con->fidlock);
 
 		/*
 		 * The FidOCreate flag is used to prevent any
@@ -239,19 +235,19 @@
 		fid->open &= ~FidOCreate;
 		return fid;
 	}
-	vtUnlock(con->fidlock);
+	qunlock(&con->fidlock);
 
-	vtSetError("%s: fid not found", argv0);
+	werrstr("%s: fid not found", argv0);
 	return nil;
 }
 
 void
 fidPut(Fid* fid)
 {
-	vtLock(fid->con->fidlock);
+	qlock(&fid->con->fidlock);
 	assert(fid->ref > 0);
 	fid->ref--;
-	vtUnlock(fid->con->fidlock);
+	qunlock(&fid->con->fidlock);
 
 	if(fid->ref == 0 && fid->fidno == NOFID){
 		fidFree(fid);
@@ -265,12 +261,12 @@
 {
 	assert(fid->flags & FidFWlock);
 
-	vtLock(fid->con->fidlock);
+	qlock(&fid->con->fidlock);
 	assert(fid->ref > 0);
 	fid->ref--;
 	fidUnHash(fid);
 	fid->fidno = NOFID;
-	vtUnlock(fid->con->fidlock);
+	qunlock(&fid->con->fidlock);
 
 	if(fid->ref > 0){
 		/* not reached - fidUnHash requires ref == 0 */
@@ -286,19 +282,18 @@
 	Fid *fid;
 	u32int fidno;
 
-	vtLock(con->fidlock);
+	qlock(&con->fidlock);
 	while(con->fhead != nil){
 		fidno = con->fhead->fidno;
-		vtUnlock(con->fidlock);
+		qunlock(&con->fidlock);
 		if((fid = fidGet(con, fidno, FidFWlock)) != nil)
 			fidClunk(fid);
-		vtLock(con->fidlock);
+		qlock(&con->fidlock);
 	}
-	vtUnlock(con->fidlock);
+	qunlock(&con->fidlock);
 }
 
 void
 fidInit(void)
 {
-	fbox.lock = vtLockAlloc();
 }
diff --git a/src/cmd/fossil/9fsys.c b/src/cmd/fossil/9fsys.c
index 4e139f7..ac72425 100644
--- a/src/cmd/fossil/9fsys.c
+++ b/src/cmd/fossil/9fsys.c
@@ -5,14 +5,14 @@
 #include "9.h"
 
 struct Fsys {
-	VtLock* lock;
+	QLock	lock;
 
 	char*	name;		/* copy here & Fs to ease error reporting */
 	char*	dev;
 	char*	venti;
 
 	Fs*	fs;
-	VtSession* session;
+	VtConn* session;
 	int	ref;
 
 	int	noauth;
@@ -27,7 +27,7 @@
 int	fsGetBlockSize(Fs *fs);
 
 static struct {
-	VtLock*	lock;
+	RWLock	lock;
 	Fsys*	head;
 	Fsys*	tail;
 
@@ -49,10 +49,10 @@
 ventihost(char *host)
 {
 	if(host != nil)
-		return vtStrDup(host);
+		return vtstrdup(host);
 	host = getenv("venti");
 	if(host == nil)
-		host = vtStrDup("$venti");
+		host = vtstrdup("$venti");
 	return host;
 }
 
@@ -67,18 +67,18 @@
 	free(vh);
 }
 
-static VtSession *
-myDial(char *host, int canfail)
+static VtConn *
+myDial(char *host)
 {
 	prventihost(host);
-	return vtDial(host, canfail);
+	return vtdial(host);
 }
 
 static int
-myRedial(VtSession *z, char *host)
+myRedial(VtConn *z, char *host)
 {
 	prventihost(host);
-	return vtRedial(z, host);
+	return vtredial(z, host);
 }
 
 static Fsys*
@@ -89,16 +89,16 @@
 	if(name == nil || name[0] == '\0')
 		name = "main";
 
-	vtRLock(sbox.lock);
+	rlock(&sbox.lock);
 	for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
 		if(strcmp(name, fsys->name) == 0){
 			fsys->ref++;
 			break;
 		}
 	}
-	vtRUnlock(sbox.lock);
+	runlock(&sbox.lock);
 	if(fsys == nil)
-		vtSetError(EFsysNotFound, name);
+		werrstr(EFsysNotFound, name);
 	return fsys;
 }
 
@@ -116,14 +116,14 @@
 	if(argc)
 		return cliError(usage);
 
-	vtRLock(sbox.lock);
+	rlock(&sbox.lock);
 	for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
 		consPrint("\tfsys %s config %s\n", fsys->name, fsys->dev);
 		if(fsys->venti && fsys->venti[0])
 			consPrint("\tfsys %s venti %q\n", fsys->name,
 				fsys->venti);
 	}
-	vtRUnlock(sbox.lock);
+	runlock(&sbox.lock);
 	return 1;
 }
 
@@ -135,14 +135,14 @@
 	if((fsys = _fsysGet(name)) == nil)
 		return nil;
 
-	vtLock(fsys->lock);
+	qlock(&fsys->lock);
 	if(fsys->fs == nil){
-		vtSetError(EFsysNotOpen, fsys->name);
-		vtUnlock(fsys->lock);
+		werrstr(EFsysNotOpen, fsys->name);
+		qunlock(&fsys->lock);
 		fsysPut(fsys);
 		return nil;
 	}
-	vtUnlock(fsys->lock);
+	qunlock(&fsys->lock);
 
 	return fsys;
 }
@@ -156,9 +156,9 @@
 Fsys*
 fsysIncRef(Fsys* fsys)
 {
-	vtLock(sbox.lock);
+	wlock(&sbox.lock);
 	fsys->ref++;
-	vtUnlock(sbox.lock);
+	wunlock(&sbox.lock);
 
 	return fsys;
 }
@@ -166,10 +166,10 @@
 void
 fsysPut(Fsys* fsys)
 {
-	vtLock(sbox.lock);
+	wlock(&sbox.lock);
 	assert(fsys->ref > 0);
 	fsys->ref--;
-	vtUnlock(sbox.lock);
+	wunlock(&sbox.lock);
 }
 
 Fs*
@@ -183,13 +183,13 @@
 void
 fsysFsRlock(Fsys* fsys)
 {
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 }
 
 void
 fsysFsRUnlock(Fsys* fsys)
 {
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 }
 
 int
@@ -285,19 +285,18 @@
 {
 	Fsys *fsys;
 
-	vtLock(sbox.lock);
+	wlock(&sbox.lock);
 	for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
 		if(strcmp(fsys->name, name) != 0)
 			continue;
-		vtSetError(EFsysExists, name);
-		vtUnlock(sbox.lock);
+		werrstr(EFsysExists, name);
+		wunlock(&sbox.lock);
 		return nil;
 	}
 
-	fsys = vtMemAllocZ(sizeof(Fsys));
-	fsys->lock = vtLockAlloc();
-	fsys->name = vtStrDup(name);
-	fsys->dev = vtStrDup(dev);
+	fsys = vtmallocz(sizeof(Fsys));
+	fsys->name = vtstrdup(name);
+	fsys->dev = vtstrdup(dev);
 
 	fsys->ref = 1;
 
@@ -306,7 +305,7 @@
 	else
 		sbox.head = fsys;
 	sbox.tail = fsys;
-	vtUnlock(sbox.lock);
+	wunlock(&sbox.lock);
 
 	return fsys;
 }
@@ -334,7 +333,7 @@
 	 * More thought and care needed here.
 	fsClose(fsys->fs);
 	fsys->fs = nil;
-	vtClose(fsys->session);
+	vtfreeconn(fsys->session);
 	fsys->session = nil;
 
 	if(sbox.curfsys != nil && strcmp(fsys->name, sbox.curfsys) == 0){
@@ -566,19 +565,19 @@
 	if(argc == 0)
 		return cliError(usage);
 
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 	while(argc > 0){
 		if((file = fileOpen(fsys->fs, argv[0])) == nil)
-			consPrint("%s: %R\n", argv[0]);
+			consPrint("%s: %r\n", argv[0]);
 		else{
 			if(!fileRemove(file, uidadm))
-				consPrint("%s: %R\n", argv[0]);
+				consPrint("%s: %r\n", argv[0]);
 			fileDecRef(file);
 		}
 		argc--;
 		argv++;
 	}
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 
 	return 1;
 }
@@ -595,14 +594,14 @@
 	if(argc == 0)
 		return cliError(usage);
 
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 	while(argc > 0){
 		if(!fileClriPath(fsys->fs, argv[0], uidadm))
-			consPrint("clri %s: %R\n", argv[0]);
+			consPrint("clri %s: %r\n", argv[0]);
 		argc--;
 		argv++;
 	}
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 
 	return 1;
 }
@@ -628,7 +627,7 @@
 		return cliError(usage);
 
 	r = 0;
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 
 	fs = fsys->fs;
 	addr = strtoul(argv[0], 0, 0);
@@ -663,11 +662,11 @@
 			if(blockWrite(bb, Waitlock)){
 				while(bb->iostate != BioClean){
 					assert(bb->iostate == BioWriting);
-					vtSleep(bb->ioready);
+					rsleep(&bb->ioready);
 				}
 				break;
 			}
-			consPrint("blockWrite: %R\n");
+			consPrint("blockWrite: %r\n");
 			if(n++ >= 5){
 				consPrint("giving up\n");
 				break;
@@ -680,7 +679,7 @@
 Out1:
 	blockPut(b);
 Out0:
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 
 	return r;
 }
@@ -710,7 +709,7 @@
 	addr = strtoul(argv[0], 0, 0);
 	offset = strtoul(argv[1], 0, 0);
 	if(offset < 0 || offset >= fs->blockSize){
-		vtSetError("bad offset");
+		werrstr("bad offset");
 		return 0;
 	}
 	if(argc > 2)
@@ -720,12 +719,12 @@
 	if(offset+count > fs->blockSize)
 		count = fs->blockSize - count;
 
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 
 	b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
 	if(b == nil){
-		vtSetError("cacheLocal %#ux: %R", addr);
-		vtRUnlock(fs->elk);
+		werrstr("cacheLocal %#ux: %r", addr);
+		runlock(&fs->elk);
 		return 0;
 	}
 
@@ -735,10 +734,10 @@
 	if(argc == 4){
 		s = argv[3];
 		if(strlen(s) != 2*count){
-			vtSetError("bad data count");
+			werrstr("bad data count");
 			goto Out;
 		}
-		buf = vtMemAllocZ(count);
+		buf = vtmallocz(count);
 		for(i = 0; i < count*2; i++){
 			if(s[i] >= '0' && s[i] <= '9')
 				c = s[i] - '0';
@@ -747,8 +746,8 @@
 			else if(s[i] >= 'A' && s[i] <= 'F')
 				c = s[i] - 'A' + 10;
 			else{
-				vtSetError("bad hex");
-				vtMemFree(buf);
+				werrstr("bad hex");
+				vtfree(buf);
 				goto Out;
 			}
 			if((i & 1) == 0)
@@ -763,7 +762,7 @@
 
 Out:
 	blockPut(b);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 
 	return 1;
 }
@@ -789,18 +788,18 @@
 		return cliError(usage);
 
 	fs = fsys->fs;
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	while(argc > 0){
 		addr = strtoul(argv[0], &p, 0);
 		if(*p != '\0'){
 			consPrint("bad address - '%ud'\n", addr);
 			/* syntax error; let's stop */
-			vtRUnlock(fs->elk);
+			runlock(&fs->elk);
 			return 0;
 		}
 		b = cacheLocal(fs->cache, PartData, addr, OReadOnly);
 		if(b == nil){
-			consPrint("loading %#ux: %R\n", addr);
+			consPrint("loading %#ux: %r\n", addr);
 			continue;
 		}
 		l = b->l;
@@ -815,13 +814,13 @@
 			l.epoch = 0;
 			l.epochClose = 0;
 			if(!blockSetLabel(b, &l, 0))
-				consPrint("freeing %#ux: %R\n", addr);
+				consPrint("freeing %#ux: %r\n", addr);
 		}
 		blockPut(b);
 		argc--;
 		argv++;
 	}
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 
 	return 1;
 }
@@ -870,24 +869,24 @@
 		return cliError(usage, ch);
 
 	fs = fsys->fs;
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 
 	addr = strtoul(argv[0], 0, 0);
 	b = cacheLocal(fs->cache, PartData, addr, argc==4 ? OReadWrite : OReadOnly);
 	if(b == nil){
-		vtSetError("cacheLocal %#ux: %R", addr);
+		werrstr("cacheLocal %#ux: %r", addr);
 	Err:
-		vtRUnlock(fsys->fs->elk);
+		runlock(&fsys->fs->elk);
 		return 0;
 	}
 
 	switch(ch){
 	default:
-		vtSetError("clrep");
+		werrstr("clrep");
 		goto Err;
 	case 'e':
 		if(b->l.type != BtDir){
-			vtSetError("wrong block type");
+			werrstr("wrong block type");
 			goto Err;
 		}
 		sz = VtEntrySize;
@@ -896,11 +895,11 @@
 		break;
 	case 'p':
 		if(b->l.type == BtDir || b->l.type == BtData){
-			vtSetError("wrong block type");
+			werrstr("wrong block type");
 			goto Err;
 		}
 		sz = VtScoreSize;
-		memmove(zero, vtZeroScore, VtScoreSize);
+		memmove(zero, vtzeroscore, VtScoreSize);
 		break;
 	}
 	max = fs->blockSize/sz;
@@ -916,7 +915,7 @@
 	}
 	blockDirty(b);
 	blockPut(b);
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 
 	return 1;
 }
@@ -951,17 +950,17 @@
 	for(;;){
 		r = deeRead(dee, &de);
 		if(r < 0){
-			consPrint("\tdeeRead %s/%s: %R\n", s, de.elem);
+			consPrint("\tdeeRead %s/%s: %r\n", s, de.elem);
 			break;
 		}
 		if(r == 0)
 			break;
 		if(de.mode & ModeSnapshot){
 			if((ff = fileWalk(f, de.elem)) == nil)
-				consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
+				consPrint("\tcannot walk %s/%s: %r\n", s, de.elem);
 			else{
 				if(!fileGetSources(ff, &e, &ee))
-					consPrint("\tcannot get sources for %s/%s: %R\n", s, de.elem);
+					consPrint("\tcannot get sources for %s/%s: %r\n", s, de.elem);
 				else if(e.snap != 0 && e.snap < elo){
 					consPrint("\t%ud\tclri %s/%s\n", e.snap, s, de.elem);
 					n++;
@@ -971,11 +970,11 @@
 		}
 		else if(de.mode & ModeDir){
 			if((ff = fileWalk(f, de.elem)) == nil)
-				consPrint("\tcannot walk %s/%s: %R\n", s, de.elem);
+				consPrint("\tcannot walk %s/%s: %r\n", s, de.elem);
 			else{
 				t = smprint("%s/%s", s, de.elem);
 				n += fsysEsearch1(ff, t, elo);
-				vtMemFree(t);
+				vtfree(t);
 				fileDecRef(ff);
 			}
 		}
@@ -999,7 +998,7 @@
 	if(f == nil)
 		return 0;
 	if(!fileGetDir(f, &de)){
-		consPrint("\tfileGetDir %s failed: %R\n", path);
+		consPrint("\tfileGetDir %s failed: %r\n", path);
 		fileDecRef(f);
 		return 0;
 	}
@@ -1046,16 +1045,16 @@
 
 	fs = fsys->fs;
 
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	consPrint("\tlow %ud hi %ud\n", fs->elo, fs->ehi);
 	if(low == ~(u32int)0){
-		vtRUnlock(fs->elk);
+		runlock(&fs->elk);
 		return 1;
 	}
 	n = fsysEsearch(fsys->fs, "/archive", low);
 	n += fsysEsearch(fsys->fs, "/snapshot", low);
 	consPrint("\t%d snapshot%s found with epoch < %ud\n", n, n==1 ? "" : "s", low);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 
 	/*
 	 * There's a small race here -- a new snapshot with epoch < low might
@@ -1070,7 +1069,7 @@
 	}
 	old = fs->elo;
 	if(!fsEpochLow(fs, low))
-		consPrint("\tfsEpochLow: %R\n");
+		consPrint("\tfsEpochLow: %r\n");
 	else{
 		consPrint("\told: epoch%s %ud\n", force ? " -y" : "", old);
 		consPrint("\tnew: epoch%s %ud\n", force ? " -y" : "", fs->elo);
@@ -1108,8 +1107,8 @@
 	if(strcmp(argv[1], uidnoworld) == 0)
 		return cliError("permission denied");
 
-	vtRLock(fsys->fs->elk);
-	path = vtStrDup(argv[0]);
+	rlock(&fsys->fs->elk);
+	path = vtstrdup(argv[0]);
 	if((p = strrchr(path, '/')) != nil){
 		*p++ = '\0';
 		elem = p;
@@ -1129,20 +1128,20 @@
 	file = fileCreate(parent, elem, mode, argv[1]);
 	fileDecRef(parent);
 	if(file == nil){
-		vtSetError("create %s/%s: %R", p, elem);
+		werrstr("create %s/%s: %r", p, elem);
 		goto out;
 	}
 
 	if(!fileGetDir(file, &de)){
-		vtSetError("stat failed after create: %R");
+		werrstr("stat failed after create: %r");
 		goto out1;
 	}
 
 	if(strcmp(de.gid, argv[2]) != 0){
-		vtMemFree(de.gid);
-		de.gid = vtStrDup(argv[2]);
+		vtfree(de.gid);
+		de.gid = vtstrdup(argv[2]);
 		if(!fileSetDir(file, &de, argv[1])){
-			vtSetError("wstat failed after create: %R");
+			werrstr("wstat failed after create: %r");
 			goto out2;
 		}
 	}
@@ -1153,8 +1152,8 @@
 out1:
 	fileDecRef(file);
 out:
-	vtMemFree(path);
-	vtRUnlock(fsys->fs->elk);
+	vtfree(path);
+	runlock(&fsys->fs->elk);
 
 	return r;
 }
@@ -1186,14 +1185,14 @@
 	if(argc == 0)
 		return cliError(usage);
 
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 	for(i=0; i<argc; i++){
 		if((f = fileOpen(fsys->fs, argv[i])) == nil){
-			consPrint("%s: %R\n", argv[i]);
+			consPrint("%s: %r\n", argv[i]);
 			continue;
 		}
 		if(!fileGetDir(f, &de)){
-			consPrint("%s: %R\n", argv[i]);
+			consPrint("%s: %r\n", argv[i]);
 			fileDecRef(f);
 			continue;
 		}
@@ -1201,7 +1200,7 @@
 		deCleanup(&de);
 		fileDecRef(f);
 	}
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 	return 1;
 }
 
@@ -1222,79 +1221,79 @@
 	if(argc != 6)
 		return cliError(usage);
 
-	vtRLock(fsys->fs->elk);
+	rlock(&fsys->fs->elk);
 	if((f = fileOpen(fsys->fs, argv[0])) == nil){
-		vtSetError("console wstat - walk - %R");
-		vtRUnlock(fsys->fs->elk);
+		werrstr("console wstat - walk - %r");
+		runlock(&fsys->fs->elk);
 		return 0;
 	}
 	if(!fileGetDir(f, &de)){
-		vtSetError("console wstat - stat - %R");
+		werrstr("console wstat - stat - %r");
 		fileDecRef(f);
-		vtRUnlock(fsys->fs->elk);
+		runlock(&fsys->fs->elk);
 		return 0;
 	}
 	fsysPrintStat("\told: w", argv[0], &de);
 
 	if(strcmp(argv[1], "-") != 0){
 		if(!validFileName(argv[1])){
-			vtSetError("console wstat - bad elem");
+			werrstr("console wstat - bad elem");
 			goto error;
 		}
-		vtMemFree(de.elem);
-		de.elem = vtStrDup(argv[1]);
+		vtfree(de.elem);
+		de.elem = vtstrdup(argv[1]);
 	}
 	if(strcmp(argv[2], "-") != 0){
 		if(!validUserName(argv[2])){
-			vtSetError("console wstat - bad uid");
+			werrstr("console wstat - bad uid");
 			goto error;
 		}
-		vtMemFree(de.uid);
-		de.uid = vtStrDup(argv[2]);
+		vtfree(de.uid);
+		de.uid = vtstrdup(argv[2]);
 	}
 	if(strcmp(argv[3], "-") != 0){
 		if(!validUserName(argv[3])){
-			vtSetError("console wstat - bad gid");
+			werrstr("console wstat - bad gid");
 			goto error;
 		}
-		vtMemFree(de.gid);
-		de.gid = vtStrDup(argv[3]);
+		vtfree(de.gid);
+		de.gid = vtstrdup(argv[3]);
 	}
 	if(strcmp(argv[4], "-") != 0){
 		if(!fsysParseMode(argv[4], &de.mode)){
-			vtSetError("console wstat - bad mode");
+			werrstr("console wstat - bad mode");
 			goto error;
 		}
 	}
 	if(strcmp(argv[5], "-") != 0){
 		de.size = strtoull(argv[5], &p, 0);
 		if(argv[5][0] == '\0' || *p != '\0' || (vlong)de.size < 0){
-			vtSetError("console wstat - bad length");
+			werrstr("console wstat - bad length");
 			goto error;
 		}
 	}
 
 	if(!fileSetDir(f, &de, uidadm)){
-		vtSetError("console wstat - %R");
+		werrstr("console wstat - %r");
 		goto error;
 	}
 	deCleanup(&de);
 
 	if(!fileGetDir(f, &de)){
-		vtSetError("console wstat - stat2 - %R");
+		werrstr("console wstat - stat2 - %r");
 		goto error;
 	}
 	fsysPrintStat("\tnew: w", argv[0], &de);
 	deCleanup(&de);
 	fileDecRef(f);
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 
 	return 1;
 
 error:
 	deCleanup(&de);	/* okay to do this twice */
 	fileDecRef(f);
-	vtRUnlock(fsys->fs->elk);
+	runlock(&fsys->fs->elk);
 	return 0;
 }
 
@@ -1330,7 +1329,7 @@
 		l.state = BsFree;
 		
 	if(!blockSetLabel(b, &l, 0))
-		consPrint("%#ux setlabel: %R\n", b->addr);
+		consPrint("%#ux setlabel: %r\n", b->addr);
 }
 
 static void
@@ -1358,7 +1357,7 @@
 		consPrint("bad clre\n");
 		return;
 	}
-	memmove(b->data+offset*VtScoreSize, vtZeroScore, VtScoreSize);
+	memmove(b->data+offset*VtScoreSize, vtzeroscore, VtScoreSize);
 	blockDirty(b);
 }
 
@@ -1459,13 +1458,13 @@
 	if((fsys = _fsysGet(name)) == nil)
 		return 0;
 
-	vtLock(fsys->lock);
+	qlock(&fsys->lock);
 	if(host == nil)
 		host = fsys->venti;
 	else{
-		vtMemFree(fsys->venti);
+		vtfree(fsys->venti);
 		if(host[0])
-			fsys->venti = vtStrDup(host);
+			fsys->venti = vtstrdup(host);
 		else{
 			host = nil;
 			fsys->venti = nil;
@@ -1475,26 +1474,26 @@
 	/* already open: do a redial */
 	if(fsys->fs != nil){
 		if(fsys->session == nil){
-			vtSetError("file system was opened with -V");
+			werrstr("file system was opened with -V");
 			r = 0;
 			goto out;
 		}
 		r = 1;
-		if(!myRedial(fsys->session, host)
-		|| !vtConnect(fsys->session, 0))
+		if(myRedial(fsys->session, host) < 0
+		|| vtconnect(fsys->session) < 0)
 			r = 0;
 		goto out;
 	}
 
 	/* not yet open: try to dial */
 	if(fsys->session)
-		vtClose(fsys->session);
+		vtfreeconn(fsys->session);
 	r = 1;
-	if((fsys->session = myDial(host, 0)) == nil
-	|| !vtConnect(fsys->session, 0))
+	if((fsys->session = myDial(host)) == nil
+	|| vtconnect(fsys->session) < 0)
 		r = 0;
 out:
-	vtUnlock(fsys->lock);
+	qunlock(&fsys->lock);
 	fsysPut(fsys);
 	return r;
 }
@@ -1593,17 +1592,17 @@
 			ncache = 100;
 	}
 
-	vtLock(fsys->lock);
+	qlock(&fsys->lock);
 	if(fsys->fs != nil){
-		vtSetError(EFsysBusy, fsys->name);
-		vtUnlock(fsys->lock);
+		werrstr(EFsysBusy, fsys->name);
+		qunlock(&fsys->lock);
 		fsysPut(fsys);
 		return 0;
 	}
 
 	if(noventi){
 		if(fsys->session){
-			vtClose(fsys->session);
+			vtfreeconn(fsys->session);
 			fsys->session = nil;
 		}
 	}
@@ -1612,13 +1611,14 @@
 			host = fsys->venti;
 		else
 			host = nil;
-		fsys->session = myDial(host, 1);
-		if(!vtConnect(fsys->session, nil) && !noventi)
-			fprint(2, "warning: connecting to venti: %R\n");
+
+		if((fsys->session = myDial(host)) == nil
+		|| vtconnect(fsys->session) < 0 && !noventi)
+			fprint(2, "warning: connecting to venti: %r\n");
 	}
 	if((fsys->fs = fsOpen(fsys->dev, fsys->session, ncache, rflag)) == nil){
-		vtSetError("fsOpen: %R");
-		vtUnlock(fsys->lock);
+		werrstr("fsOpen: %r");
+		qunlock(&fsys->lock);
 		fsysPut(fsys);
 		return 0;
 	}
@@ -1627,7 +1627,7 @@
 	fsys->noperm = noperm;
 	fsys->wstatallow = wstatallow;
 	fsys->fs->noatimeupd = noatimeupd;
-	vtUnlock(fsys->lock);
+	qunlock(&fsys->lock);
 	fsysPut(fsys);
 
 	if(strcmp(name, "main") == 0)
@@ -1649,7 +1649,7 @@
 	if(argc)
 		return cliError(usage);
 
-	vtLock(sbox.lock);
+	wlock(&sbox.lock);
 	fp = &sbox.head;
 	for(fsys = *fp; fsys != nil; fsys = fsys->next){
 		if(strcmp(fsys->name, name) == 0)
@@ -1657,29 +1657,27 @@
 		fp = &fsys->next;
 	}
 	if(fsys == nil){
-		vtSetError(EFsysNotFound, name);
-		vtUnlock(sbox.lock);
+		werrstr(EFsysNotFound, name);
+		wunlock(&sbox.lock);
 		return 0;
 	}
 	if(fsys->ref != 0 || fsys->fs != nil){
-		vtSetError(EFsysBusy, fsys->name);
-		vtUnlock(sbox.lock);
+		werrstr(EFsysBusy, fsys->name);
+		wunlock(&sbox.lock);
 		return 0;
 	}
 	*fp = fsys->next;
-	vtUnlock(sbox.lock);
+	wunlock(&sbox.lock);
 
-	if(fsys->session != nil){
-		vtClose(fsys->session);
-		vtFree(fsys->session);
-	}
+	if(fsys->session != nil)
+		vtfreeconn(fsys->session);
 	if(fsys->venti != nil)
-		vtMemFree(fsys->venti);
+		vtfree(fsys->venti);
 	if(fsys->dev != nil)
-		vtMemFree(fsys->dev);
+		vtfree(fsys->dev);
 	if(fsys->name != nil)
-		vtMemFree(fsys->name);
-	vtMemFree(fsys);
+		vtfree(fsys->name);
+	vtfree(fsys);
 
 	return 1;
 }
@@ -1704,16 +1702,16 @@
 		part = argv[0];
 
 	if((fsys = _fsysGet(part)) != nil){
-		vtLock(fsys->lock);
+		qlock(&fsys->lock);
 		if(fsys->fs != nil){
-			vtSetError(EFsysBusy, fsys->name);
-			vtUnlock(fsys->lock);
+			werrstr(EFsysBusy, fsys->name);
+			qunlock(&fsys->lock);
 			fsysPut(fsys);
 			return 0;
 		}
-		vtMemFree(fsys->dev);
-		fsys->dev = vtStrDup(part);
-		vtUnlock(fsys->lock);
+		vtfree(fsys->dev);
+		fsys->dev = vtstrdup(part);
+		qunlock(&fsys->lock);
 	}
 	else if((fsys = fsysAlloc(name, part)) == nil)
 		return 0;
@@ -1762,22 +1760,22 @@
 {
 	int r;
 
-	vtLock(fsys->lock);
+	qlock(&fsys->lock);
 	if(fsys->fs == nil){
-		vtUnlock(fsys->lock);
-		vtSetError(EFsysNotOpen, fsys->name);
+		qunlock(&fsys->lock);
+		werrstr(EFsysNotOpen, fsys->name);
 		return 0;
 	}
 
 	if(fsys->fs->halted
 	&& fsyscmd[i].f != fsysUnhalt && fsyscmd[i].f != fsysCheck){
-		vtSetError("file system %s is halted", fsys->name);
-		vtUnlock(fsys->lock);
+		werrstr("file system %s is halted", fsys->name);
+		qunlock(&fsys->lock);
 		return 0;
 	}
 
 	r = (*fsyscmd[i].f)(fsys, argc, argv);
-	vtUnlock(fsys->lock);
+	qunlock(&fsys->lock);
 	return r;
 }
 
@@ -1793,14 +1791,14 @@
 	}
 
 	if(fsyscmd[i].cmd == nil){
-		vtSetError("unknown command - '%s'", argv[0]);
+		werrstr("unknown command - '%s'", argv[0]);
 		return 0;
 	}
 
 	/* some commands want the name... */
 	if(fsyscmd[i].f1 != nil){
 		if(strcmp(name, FsysAll) == 0){
-			vtSetError("cannot use fsys %#q with %#q command", FsysAll, argv[0]);
+			werrstr("cannot use fsys %#q with %#q command", FsysAll, argv[0]);
 			return 0;
 		}
 		return (*fsyscmd[i].f1)(name, argc, argv);
@@ -1809,13 +1807,13 @@
 	/* ... but most commands want the Fsys */
 	if(strcmp(name, FsysAll) == 0){
 		r = 1;
-		vtRLock(sbox.lock);
+		rlock(&sbox.lock);
 		for(fsys = sbox.head; fsys != nil; fsys = fsys->next){
 			fsys->ref++;
 			r = fsysXXX1(fsys, i, argc, argv) && r;
 			fsys->ref--;
 		}
-		vtRUnlock(sbox.lock);
+		runlock(&sbox.lock);
 	}else{
 		if((fsys = _fsysGet(name)) == nil)
 			return 0;
@@ -1831,7 +1829,7 @@
 	char *name;
 
 	if((name = sbox.curfsys) == nil){
-		vtSetError(EFsysNoCurrent, argv[0]);
+		werrstr(EFsysNoCurrent, argv[0]);
 		return 0;
 	}
 
@@ -1850,18 +1848,18 @@
 	}ARGEND
 
 	if(argc == 0){
-		vtRLock(sbox.lock);
+		rlock(&sbox.lock);
 		currfsysname = sbox.head->name;
 		for(fsys = sbox.head; fsys != nil; fsys = fsys->next)
 			consPrint("\t%s\n", fsys->name);
-		vtRUnlock(sbox.lock);
+		runlock(&sbox.lock);
 		return 1;
 	}
 	if(argc == 1){
 		fsys = nil;
 		if(strcmp(argv[0], FsysAll) != 0 && (fsys = fsysGet(argv[0])) == nil)
 			return 0;
-		sbox.curfsys = vtStrDup(argv[0]);
+		sbox.curfsys = vtstrdup(argv[0]);
 		consPrompt(sbox.curfsys);
 		if(fsys)
 			fsysPut(fsys);
@@ -1878,11 +1876,8 @@
 
 	fmtinstall('H', encodefmt);
 	fmtinstall('V', scoreFmt);
-	fmtinstall('R', vtErrFmt);
 	fmtinstall('L', labelFmt);
 
-	sbox.lock = vtLockAlloc();
-
 	cliAddCmd("fsys", cmdFsys);
 	for(i = 0; fsyscmd[i].cmd != nil; i++){
 		if(fsyscmd[i].f != nil)
diff --git a/src/cmd/fossil/9lstn.c b/src/cmd/fossil/9lstn.c
index 9ba508f..b4023e8 100644
--- a/src/cmd/fossil/9lstn.c
+++ b/src/cmd/fossil/9lstn.c
@@ -14,7 +14,7 @@
 };
 
 static struct {
-	VtLock*	lock;
+	RWLock	lock;
 
 	Lstn*	head;
 	Lstn*	tail;
@@ -23,7 +23,7 @@
 static void
 lstnFree(Lstn* lstn)
 {
-	vtLock(lbox.lock);
+	wlock(&lbox.lock);
 	if(lstn->prev != nil)
 		lstn->prev->next = lstn->next;
 	else
@@ -32,12 +32,12 @@
 		lstn->next->prev = lstn->prev;
 	else
 		lbox.tail = lstn->prev;
-	vtUnlock(lbox.lock);
+	wunlock(&lbox.lock);
 
 	if(lstn->afd != -1)
 		close(lstn->afd);
-	vtMemFree(lstn->address);
-	vtMemFree(lstn);
+	vtfree(lstn->address);
+	vtfree(lstn);
 }
 
 static void
@@ -47,7 +47,7 @@
 	int dfd, lfd;
 	char newdir[NETPATHLEN];
 	
- 	vtThreadSetName("listen");
+ 	threadsetname("listen");
 
 	lstn = a;
 	for(;;){
@@ -71,24 +71,24 @@
 	Lstn *lstn;
 	char dir[NETPATHLEN];
 
-	vtLock(lbox.lock);
+	wlock(&lbox.lock);
 	for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
 		if(strcmp(lstn->address, address) != 0)
 			continue;
-		vtSetError("listen: already serving '%s'", address);
-		vtUnlock(lbox.lock);
+		werrstr("listen: already serving '%s'", address);
+		wunlock(&lbox.lock);
 		return nil;
 	}
 
 	if((afd = announce(address, dir)) < 0){
-		vtSetError("listen: announce '%s': %r", address);
-		vtUnlock(lbox.lock);
+		werrstr("listen: announce '%s': %r", address);
+		wunlock(&lbox.lock);
 		return nil;
 	}
 
-	lstn = vtMemAllocZ(sizeof(Lstn));
+	lstn = vtmallocz(sizeof(Lstn));
 	lstn->afd = afd;
-	lstn->address = vtStrDup(address);
+	lstn->address = vtstrdup(address);
 	lstn->flags = flags;
 	memmove(lstn->dir, dir, NETPATHLEN);
 
@@ -101,10 +101,10 @@
 		lstn->prev = nil;
 	}
 	lbox.tail = lstn;
-	vtUnlock(lbox.lock);
+	wunlock(&lbox.lock);
 
-	if(vtThread(lstnListen, lstn) < 0){
-		vtSetError("listen: thread '%s': %r", lstn->address);
+	if(proccreate(lstnListen, lstn, STACK) < 0){
+		werrstr("listen: thread '%s': %r", lstn->address);
 		lstnFree(lstn);
 		return nil;
 	}
@@ -139,10 +139,10 @@
 	default:
 		return cliError(usage);
 	case 0:
-		vtRLock(lbox.lock);
+		rlock(&lbox.lock);
 		for(lstn = lbox.head; lstn != nil; lstn = lstn->next)
 			consPrint("\t%s\t%s\n", lstn->address, lstn->dir);
-		vtRUnlock(lbox.lock);
+		runlock(&lbox.lock);
 		break;
 	case 1:
 		if(!dflag){
@@ -151,7 +151,7 @@
 			break;
 		}
 
-		vtLock(lbox.lock);
+		wlock(&lbox.lock);
 		for(lstn = lbox.head; lstn != nil; lstn = lstn->next){
 			if(strcmp(lstn->address, argv[0]) != 0)
 				continue;
@@ -161,10 +161,10 @@
 			}
 			break;
 		}
-		vtUnlock(lbox.lock);
+		wunlock(&lbox.lock);
 
 		if(lstn == nil){
-			vtSetError("listen: '%s' not found", argv[0]);
+			werrstr("listen: '%s' not found", argv[0]);
 			return 0;
 		}
 		break;
@@ -176,8 +176,6 @@
 int
 lstnInit(void)
 {
-	lbox.lock = vtLockAlloc();
-
 	cliAddCmd("listen", cmdLstn);
 
 	return 1;
diff --git a/src/cmd/fossil/9p.c b/src/cmd/fossil/9p.c
index c3fae5a..c4c9579 100644
--- a/src/cmd/fossil/9p.c
+++ b/src/cmd/fossil/9p.c
@@ -35,11 +35,11 @@
 		 */
 		if((u = unameByUid(de.uid)) != nil){
 			if(strcmp(fid->uname, u) == 0 && ((perm<<6) & de.mode)){
-				vtMemFree(u);
+				vtfree(u);
 				deCleanup(&de);
 				return 1;
 			}
-			vtMemFree(u);
+			vtfree(u);
 		}
 		if(groupMember(de.gid, fid->uname) && ((perm<<3) & de.mode)){
 			deCleanup(&de);
@@ -60,7 +60,7 @@
 		deCleanup(&de);
 		return 1;
 	}
-	vtSetError(EPermission);
+	werrstr(EPermission);
 
 	deCleanup(&de);
 	return 0;
@@ -91,19 +91,19 @@
 	char *p;
 
 	if(name == nil || name[0] == '\0'){
-		vtSetError("no file name");
+		werrstr("no file name");
 		return 0;
 	}
 	if(name[0] == '.'){
 		if(name[1] == '\0' || (name[1] == '.' && name[2] == '\0')){
-			vtSetError(". and .. illegal as file name");
+			werrstr(". and .. illegal as file name");
 			return 0;
 		}
 	}
 
 	for(p = name; *p != '\0'; p++){
 		if((*p & 0xFF) < 040){
-			vtSetError("bad character in file name");
+			werrstr("bad character in file name");
 			return 0;
 		}
 	}
@@ -128,20 +128,20 @@
 	retval = 0;
 
 	if(strcmp(fid->uname, unamenone) == 0 || (fid->qid.type & QTAUTH)){
-		vtSetError(EPermission);
+		werrstr(EPermission);
 		goto error0;
 	}
 	if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
-		vtSetError("read-only filesystem");
+		werrstr("read-only filesystem");
 		goto error0;
 	}
 
 	if(!fileGetDir(fid->file, &de))
 		goto error0;
 
-	strs = vtMemAlloc(m->t.nstat);
+	strs = vtmalloc(m->t.nstat);
 	if(convM2D(m->t.stat, m->t.nstat, &dir, strs) == 0){
-		vtSetError("wstat -- protocol botch");
+		werrstr("wstat -- protocol botch");
 		goto error;
 	}
 
@@ -160,28 +160,28 @@
 	tsync = 1;
 	if(dir.qid.path != ~0){
 		if(dir.qid.path != de.qid){
-			vtSetError("wstat -- attempt to change qid.path");
+			werrstr("wstat -- attempt to change qid.path");
 			goto error;
 		}
 		tsync = 0;
 	}
 	if(dir.qid.vers != ~0){
 		if(dir.qid.vers != de.mcount){
-			vtSetError("wstat -- attempt to change qid.vers");
+			werrstr("wstat -- attempt to change qid.vers");
 			goto error;
 		}
 		tsync = 0;
 	}
 	if(dir.muid != nil && *dir.muid != '\0'){
 		if((uid = uidByUname(dir.muid)) == nil){
-			vtSetError("wstat -- unknown muid");
+			werrstr("wstat -- unknown muid");
 			goto error;
 		}
 		if(strcmp(uid, de.mid) != 0){
-			vtSetError("wstat -- attempt to change muid");
+			werrstr("wstat -- attempt to change muid");
 			goto error;
 		}
-		vtMemFree(uid);
+		vtfree(uid);
 		uid = nil;
 		tsync = 0;
 	}
@@ -191,7 +191,7 @@
 	 */
 	if(dir.qid.type != (uchar)~0 && dir.mode != ~0){
 		if(dir.qid.type != ((dir.mode>>24) & 0xFF)){
-			vtSetError("wstat -- qid.type/mode mismatch");
+			werrstr("wstat -- qid.type/mode mismatch");
 			goto error;
 		}
 	}
@@ -206,7 +206,7 @@
 		if(dir.mode == ~0)
 			dir.mode = (dir.qid.type<<24)|(de.mode & 0777);
 		if(dir.mode & ~(DMDIR|DMAPPEND|DMEXCL|DMTMP|0777)){
-			vtSetError("wstat -- unknown bits in qid.type/mode");
+			werrstr("wstat -- unknown bits in qid.type/mode");
 			goto error;
 		}
 
@@ -224,7 +224,7 @@
 			mode |= ModeTemporary;
 
 		if((de.mode^mode) & ModeDir){
-			vtSetError("wstat -- attempt to change directory bit");
+			werrstr("wstat -- attempt to change directory bit");
 			goto error;
 		}
 
@@ -251,11 +251,11 @@
 			 * If we're changing the append bit, it's okay.
 			 */
 			if(de.mode & oldmode & ModeAppend){
-				vtSetError("wstat -- attempt to change length of append-only file");
+				werrstr("wstat -- attempt to change length of append-only file");
 				goto error;
 			}
 			if(de.mode & ModeDir){
-				vtSetError("wstat -- attempt to change length of directory");
+				werrstr("wstat -- attempt to change length of directory");
 				goto error;
 			}
 			de.size = dir.length;
@@ -271,13 +271,13 @@
 	 */
 	if(dir.gid != nil && *dir.gid != '\0'){
 		if((gid = uidByUname(dir.gid)) == nil){
-			vtSetError("wstat -- unknown gid");
+			werrstr("wstat -- unknown gid");
 			goto error;
 		}
 		tsync = 0;
 	}
 	else
-		gid = vtStrDup(de.gid);
+		gid = vtstrdup(de.gid);
 
 	wstatallow = (fsysWstatAllow(fid->fsys) || (m->con->flags&ConWstatAllow));
 
@@ -289,7 +289,7 @@
 
 	if(op && !wstatallow){
 		if(strcmp(fid->uid, de.uid) != 0 && !gl){
-			vtSetError("wstat -- not owner or group leader");
+			werrstr("wstat -- not owner or group leader");
 			goto error;
 		}
 	}
@@ -303,10 +303,10 @@
 		if(!wstatallow
 		&& !(strcmp(fid->uid, de.uid) == 0 && groupMember(gid, fid->uname))
 		&& !(gl == 2)){
-			vtSetError("wstat -- not owner and not group leaders");
+			werrstr("wstat -- not owner and not group leaders");
 			goto error;
 		}
-		vtMemFree(de.gid);
+		vtfree(de.gid);
 		de.gid = gid;
 		gid = nil;
 		op = 1;
@@ -324,8 +324,8 @@
 		if(strcmp(dir.name, de.elem) != 0){
 			if(permParent(fid, PermW) <= 0)
 				goto error;
-			vtMemFree(de.elem);
-			de.elem = vtStrDup(dir.name);
+			vtfree(de.elem);
+			de.elem = vtstrdup(dir.name);
 			op = 1;
 		}
 		tsync = 0;
@@ -336,19 +336,19 @@
 	 */
 	if(dir.uid != nil && *dir.uid != '\0'){
 		if((uid = uidByUname(dir.uid)) == nil){
-			vtSetError("wstat -- unknown uid");
+			werrstr("wstat -- unknown uid");
 			goto error;
 		}
 		if(strcmp(uid, de.uid) != 0){
 			if(!wstatallow){
-				vtSetError("wstat -- not owner");
+				werrstr("wstat -- not owner");
 				goto error;
 			}
 			if(strcmp(uid, uidnoworld) == 0){
-				vtSetError(EPermission);
+				werrstr(EPermission);
 				goto error;
 			}
-			vtMemFree(de.uid);
+			vtfree(de.uid);
 			de.uid = uid;
 			uid = nil;
 			op = 1;
@@ -372,11 +372,11 @@
 
 error:
 	deCleanup(&de);
-	vtMemFree(strs);
+	vtfree(strs);
 	if(gid != nil)
-		vtMemFree(gid);
+		vtfree(gid);
 	if(uid != nil)
-		vtMemFree(uid);
+		vtfree(uid);
 error0:
 	fidPut(fid);
 	return retval;
@@ -404,7 +404,7 @@
 		dir.muid = fid->uname;
 
 		if((m->r.nstat = convD2M(&dir, m->data, m->con->msize)) == 0){
-			vtSetError("stat QTAUTH botch");
+			werrstr("stat QTAUTH botch");
 			fidPut(fid);
 			return 0;
 		}
@@ -479,24 +479,24 @@
 	if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
 		return 0;
 	if(!(fid->open & FidOWrite)){
-		vtSetError("fid not open for write");
+		werrstr("fid not open for write");
 		goto error;
 	}
 
 	count = m->t.count;
 	if(count < 0 || count > m->con->msize-IOHDRSZ){
-		vtSetError("write count too big");
+		werrstr("write count too big");
 		goto error;
 	}
 	if(m->t.offset < 0){
-		vtSetError("write offset negative");
+		werrstr("write offset negative");
 		goto error;
 	}
 	if(fid->excl != nil && !exclUpdate(fid))
 		goto error;
 
 	if(fid->qid.type & QTDIR){
-		vtSetError("is a directory");
+		werrstr("is a directory");
 		goto error;
 	}
 	else if(fid->qid.type & QTAUTH)
@@ -527,17 +527,17 @@
 	if((fid = fidGet(m->con, m->t.fid, 0)) == nil)
 		return 0;
 	if(!(fid->open & FidORead)){
-		vtSetError("fid not open for read");
+		werrstr("fid not open for read");
 		goto error;
 	}
 
 	count = m->t.count;
 	if(count < 0 || count > m->con->msize-IOHDRSZ){
-		vtSetError("read count too big");
+		werrstr("read count too big");
 		goto error;
 	}
 	if(m->t.offset < 0){
-		vtSetError("read offset negative");
+		werrstr("read offset negative");
 		goto error;
 	}
 	if(fid->excl != nil && !exclUpdate(fid))
@@ -579,15 +579,15 @@
 	if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
 		return 0;
 	if(fid->open){
-		vtSetError("fid open for I/O");
+		werrstr("fid open for I/O");
 		goto error;
 	}
 	if(fileIsRoFs(fid->file) || !groupWriteMember(fid->uname)){
-		vtSetError("read-only filesystem");
+		werrstr("read-only filesystem");
 		goto error;
 	}
 	if(!fileIsDir(fid->file)){
-		vtSetError("not a directory");
+		werrstr("not a directory");
 		goto error;
 	}
 	if(permFid(fid, PermW) <= 0)
@@ -595,7 +595,7 @@
 	if(!validFileName(m->t.name))
 		goto error;
 	if(strcmp(fid->uid, uidnoworld) == 0){
-		vtSetError(EPermission);
+		werrstr(EPermission);
 		goto error;
 	}
 
@@ -607,16 +607,16 @@
 	if(omode == OWRITE || omode == ORDWR)
 		open |= FidOWrite;
 	if((open & (FidOWrite|FidORead)) == 0){
-		vtSetError("unknown mode");
+		werrstr("unknown mode");
 		goto error;
 	}
 	if(m->t.perm & DMDIR){
 		if((m->t.mode & (ORCLOSE|OTRUNC)) || (open & FidOWrite)){
-			vtSetError("illegal mode");
+			werrstr("illegal mode");
 			goto error;
 		}
 		if(m->t.perm & DMAPPEND){
-			vtSetError("illegal perm");
+			werrstr("illegal perm");
 			goto error;
 		}
 	}
@@ -681,7 +681,7 @@
 	if((fid = fidGet(m->con, m->t.fid, FidFWlock)) == nil)
 		return 0;
 	if(fid->open){
-		vtSetError("fid open for I/O");
+		werrstr("fid open for I/O");
 		goto error;
 	}
 
@@ -691,11 +691,11 @@
 
 	if(m->t.mode & ORCLOSE){
 		if(isdir){
-			vtSetError("is a directory");
+			werrstr("is a directory");
 			goto error;
 		}
 		if(rofs){
-			vtSetError("read-only filesystem");
+			werrstr("read-only filesystem");
 			goto error;
 		}
 		if(permParent(fid, PermW) <= 0)
@@ -712,11 +712,11 @@
 	}
 	if(omode == OWRITE || omode == ORDWR || (m->t.mode & OTRUNC)){
 		if(isdir){
-			vtSetError("is a directory");
+			werrstr("is a directory");
 			goto error;
 		}
 		if(rofs){
-			vtSetError("read-only filesystem");
+			werrstr("read-only filesystem");
 			goto error;
 		}
 		if(permFid(fid, PermW) <= 0)
@@ -725,7 +725,7 @@
 	}
 	if(omode == OEXEC){
 		if(isdir){
-			vtSetError("is a directory");
+			werrstr("is a directory");
 			goto error;
 		}
 		if(permFid(fid, PermX) <= 0)
@@ -733,7 +733,7 @@
 		open |= FidORead;
 	}
 	if((open & (FidOWrite|FidORead)) == 0){
-		vtSetError("unknown mode");
+		werrstr("unknown mode");
 		goto error;
 	}
 
@@ -792,7 +792,7 @@
 	if((ofid = fidGet(m->con, t->fid, wlock)) == nil)
 		return 0;
 	if(ofid->open){
-		vtSetError("file open for I/O");
+		werrstr("file open for I/O");
 		fidPut(ofid);
 		return 0;
 	}
@@ -808,7 +808,7 @@
 	if(t->fid != t->newfid){
 		nfid = fidGet(m->con, t->newfid, FidFWlock|FidFCreate);
 		if(nfid == nil){
-			vtSetError("%s: walk: newfid 0x%ud in use",
+			werrstr("%s: walk: newfid 0x%ud in use",
 				argv0, t->newfid);
 			fidPut(ofid);
 			return 0;
@@ -816,8 +816,8 @@
 		nfid->open = ofid->open & ~FidORclose;
 		nfid->file = fileIncRef(ofid->file);
 		nfid->qid = ofid->qid;
-		nfid->uid = vtStrDup(ofid->uid);
-		nfid->uname = vtStrDup(ofid->uname);
+		nfid->uid = vtstrdup(ofid->uid);
+		nfid->uname = vtstrdup(ofid->uname);
 		nfid->fsys = fsysIncRef(ofid->fsys);
 		fid = nfid;
 	}
@@ -848,7 +848,7 @@
 		 * to walk out of it.
 		 */
 		if(!(qid.type & QTDIR)){
-			vtSetError("not a directory");
+			werrstr("not a directory");
 			break;
 		}
 		switch(permFile(file, fid, PermX)){
@@ -925,9 +925,9 @@
 	char *s;
 
 	if(aname && aname[0])
-		s = vtStrDup(aname);
+		s = vtstrdup(aname);
 	else
-		s = vtStrDup("main/active");
+		s = vtstrdup("main/active");
 	*fsname = s;
 	if((*path = strchr(s, '/')) != nil)
 		*(*path)++ = '\0';
@@ -949,7 +949,7 @@
 
 	if(con->flags&ConIPCheck){
 		if(con->remote[0] == 0){
-			vtSetError("cannot verify unknown remote address");
+			werrstr("cannot verify unknown remote address");
 			return 0;
 		}
 		if(access("/mnt/ipok/ok", AEXIST) < 0){
@@ -958,7 +958,7 @@
 			&& mount(fd, -1, "/mnt/ipok", MREPL, "") < 0)
 				close(fd);
 			if(access("/mnt/ipok/ok", AEXIST) < 0){
-				vtSetError("cannot verify remote address");
+				werrstr("cannot verify remote address");
 				return 0;
 			}
 		}
@@ -966,7 +966,7 @@
 		if((p = strchr(ok, '!')) != nil)
 			*p = 0;
 		if(access(ok, AEXIST) < 0){
-			vtSetError("restricted remote address");
+			werrstr("restricted remote address");
 			return 0;
 		}
 	}
@@ -986,29 +986,29 @@
 	parseAname(m->t.aname, &fsname, &path);
 	if((fsys = fsysGet(fsname)) == nil){
 		fidClunk(fid);
-		vtMemFree(fsname);
+		vtfree(fsname);
 		return 0;
 	}
 	fid->fsys = fsys;
 
 	if(m->t.uname[0] != '\0')
-		fid->uname = vtStrDup(m->t.uname);
+		fid->uname = vtstrdup(m->t.uname);
 	else
-		fid->uname = vtStrDup(unamenone);
+		fid->uname = vtstrdup(unamenone);
 
 	if((fid->con->flags&ConIPCheck) && !conIPCheck(fid->con)){
-		consPrint("reject %s from %s: %R\n", fid->uname, fid->con->remote);
+		consPrint("reject %s from %s: %r\n", fid->uname, fid->con->remote);
 		fidClunk(fid);
-		vtMemFree(fsname);
+		vtfree(fsname);
 		return 0;
 	}
 	if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
 		if((fid->uid = uidByUname(fid->uname)) == nil)
-			fid->uid = vtStrDup(unamenone);
+			fid->uid = vtstrdup(unamenone);
 	}
 	else if(!authCheck(&m->t, fid, fsys)){
 		fidClunk(fid);
-		vtMemFree(fsname);
+		vtfree(fsname);
 		return 0;
 	}
 
@@ -1016,11 +1016,11 @@
 	if((fid->file = fsysGetRoot(fsys, path)) == nil){
 		fsysFsRUnlock(fsys);
 		fidClunk(fid);
-		vtMemFree(fsname);
+		vtfree(fsname);
 		return 0;
 	}
 	fsysFsRUnlock(fsys);
-	vtMemFree(fsname);
+	vtfree(fsname);
 
 	fid->qid = (Qid){fileGetId(fid->file), 0, QTDIR};
 	m->r.qid = fid->qid;
@@ -1040,19 +1040,19 @@
 
 	parseAname(m->t.aname, &fsname, &path);
 	if((fsys = fsysGet(fsname)) == nil){
-		vtMemFree(fsname);
+		vtfree(fsname);
 		return 0;
 	}
-	vtMemFree(fsname);
+	vtfree(fsname);
 
 	if(fsysNoAuthCheck(fsys) || (m->con->flags&ConNoAuthCheck)){
 		m->con->aok = 1;
-		vtSetError("authentication disabled");
+		werrstr("authentication disabled");
 		fsysPut(fsys);
 		return 0;
 	}
 	if(strcmp(m->t.uname, unamenone) == 0){
-		vtSetError("user 'none' requires no authentication");
+		werrstr("user 'none' requires no authentication");
 		fsysPut(fsys);
 		return 0;
 	}
@@ -1065,18 +1065,18 @@
 	afid->fsys = fsys;
 
 	if((afd = open("/mnt/factotum/rpc", ORDWR)) < 0){
-		vtSetError("can't open \"/mnt/factotum/rpc\"");
+		werrstr("can't open \"/mnt/factotum/rpc\"");
 		fidClunk(afid);
 		return 0;
 	}
 	if((afid->rpc = auth_allocrpc(afd)) == nil){
 		close(afd);
-		vtSetError("can't auth_allocrpc");
+		werrstr("can't auth_allocrpc");
 		fidClunk(afid);
 		return 0;
 	}
 	if(auth_rpc(afid->rpc, "start", "proto=p9any role=server", 23) != ARok){
-		vtSetError("can't auth_rpc");
+		werrstr("can't auth_rpc");
 		fidClunk(afid);
 		return 0;
 	}
@@ -1084,7 +1084,7 @@
 	afid->open = FidOWrite|FidORead;
 	afid->qid.type = QTAUTH;
 	afid->qid.path = m->t.afid;
-	afid->uname = vtStrDup(m->t.uname);
+	afid->uname = vtstrdup(m->t.uname);
 
 	m->r.qid = afid->qid;
 
@@ -1103,10 +1103,10 @@
 	r = &m->r;
 	con = m->con;
 
-	vtLock(con->lock);
+	qlock(&con->lock);
 	if(con->state != ConInit){
-		vtUnlock(con->lock);
-		vtSetError("Tversion: down");
+		qunlock(&con->lock);
+		werrstr("Tversion: down");
 		return 0;
 	}
 	con->state = ConNew;
@@ -1119,14 +1119,14 @@
 	fidClunkAll(con);
 
 	if(t->tag != NOTAG){
-		vtUnlock(con->lock);
-		vtSetError("Tversion: invalid tag");
+		qunlock(&con->lock);
+		werrstr("Tversion: invalid tag");
 		return 0;
 	}
 
 	if(t->msize < 256){
-		vtUnlock(con->lock);
-		vtSetError("Tversion: message size too small");
+		qunlock(&con->lock);
+		werrstr("Tversion: message size too small");
 		return 0;
 	}
 	if(t->msize < con->msize)
@@ -1159,7 +1159,7 @@
 			m->state = MsgF;
 		}
 	}
-	vtUnlock(con->lock);
+	qunlock(&con->lock);
 
 	return 1;
 }
diff --git a/src/cmd/fossil/9ping.c b/src/cmd/fossil/9ping.c
index a21eea9..dbf628c 100644
--- a/src/cmd/fossil/9ping.c
+++ b/src/cmd/fossil/9ping.c
@@ -106,4 +106,3 @@
 
 	exits(0);
 }
-
diff --git a/src/cmd/fossil/9proc.c b/src/cmd/fossil/9proc.c
index bddd3ba..f87cdc4 100644
--- a/src/cmd/fossil/9proc.c
+++ b/src/cmd/fossil/9proc.c
@@ -12,18 +12,18 @@
 };
 
 static struct {
-	VtLock*	alock;			/* alloc */
+	QLock	alock;			/* alloc */
 	Msg*	ahead;
-	VtRendez* arendez;
+	Rendez	arendez;
 
 	int	maxmsg;
 	int	nmsg;
 	int	nmsgstarve;
 
-	VtLock*	rlock;			/* read */
+	QLock	rlock;			/* read */
 	Msg*	rhead;
 	Msg*	rtail;
-	VtRendez* rrendez;
+	Rendez	rrendez;
 
 	int	maxproc;
 	int	nproc;
@@ -33,11 +33,11 @@
 } mbox;
 
 static struct {
-	VtLock*	alock;			/* alloc */
+	QLock	alock;			/* alloc */
 	Con*	ahead;
-	VtRendez* arendez;
+	Rendez	arendez;
 
-	VtLock*	clock;
+	RWLock	clock;
 	Con*	chead;
 	Con*	ctail;
 
@@ -66,7 +66,7 @@
 	con->flags = 0;
 	con->isconsole = 0;
 
-	vtLock(cbox.alock);
+	qlock(&cbox.alock);
 	if(con->cprev != nil)
 		con->cprev->cnext = con->cnext;
 	else
@@ -79,25 +79,18 @@
 
 	if(cbox.ncon > cbox.maxcon){
 		if(con->name != nil)
-			vtMemFree(con->name);
-		vtLockFree(con->fidlock);
-		vtMemFree(con->data);
-		vtRendezFree(con->wrendez);
-		vtLockFree(con->wlock);
-		vtRendezFree(con->mrendez);
-		vtLockFree(con->mlock);
-		vtRendezFree(con->rendez);
-		vtLockFree(con->lock);
-		vtMemFree(con);
+			vtfree(con->name);
+		vtfree(con->data);
+		vtfree(con);
 		cbox.ncon--;
-		vtUnlock(cbox.alock);
+		qunlock(&cbox.alock);
 		return;
 	}
 	con->anext = cbox.ahead;
 	cbox.ahead = con;
 	if(con->anext == nil)
-		vtWakeup(cbox.arendez);
-	vtUnlock(cbox.alock);
+		rwakeup(&cbox.arendez);
+	qunlock(&cbox.alock);
 }
 
 static void
@@ -106,19 +99,19 @@
 	assert(m->rwnext == nil);
 	assert(m->flush == nil);
 
-	vtLock(mbox.alock);
+	qlock(&mbox.alock);
 	if(mbox.nmsg > mbox.maxmsg){
-		vtMemFree(m->data);
-		vtMemFree(m);
+		vtfree(m->data);
+		vtfree(m);
 		mbox.nmsg--;
-		vtUnlock(mbox.alock);
+		qunlock(&mbox.alock);
 		return;
 	}
 	m->anext = mbox.ahead;
 	mbox.ahead = m;
 	if(m->anext == nil)
-		vtWakeup(mbox.arendez);
-	vtUnlock(mbox.alock);
+		rwakeup(&mbox.arendez);
+	qunlock(&mbox.alock);
 }
 
 static Msg*
@@ -126,15 +119,15 @@
 {
 	Msg *m;
 
-	vtLock(mbox.alock);
+	qlock(&mbox.alock);
 	while(mbox.ahead == nil){
 		if(mbox.nmsg >= mbox.maxmsg){
 			mbox.nmsgstarve++;
-			vtSleep(mbox.arendez);
+			rsleep(&mbox.arendez);
 			continue;
 		}
-		m = vtMemAllocZ(sizeof(Msg));
-		m->data = vtMemAlloc(mbox.msize);
+		m = vtmallocz(sizeof(Msg));
+		m->data = vtmalloc(mbox.msize);
 		m->msize = mbox.msize;
 		mbox.nmsg++;
 		mbox.ahead = m;
@@ -143,7 +136,7 @@
 	m = mbox.ahead;
 	mbox.ahead = m->anext;
 	m->anext = nil;
-	vtUnlock(mbox.alock);
+	qunlock(&mbox.alock);
 
 	m->con = con;
 	m->state = MsgR;
@@ -188,9 +181,9 @@
 	 * If it's not found must assume Elvis has already
 	 * left the building and reply normally.
 	 */
-	vtLock(con->mlock);
+	qlock(&con->mlock);
 	if(m->state == MsgF){
-		vtUnlock(con->mlock);
+		qunlock(&con->mlock);
 		return;
 	}
 	for(old = con->mhead; old != nil; old = old->mnext)
@@ -199,7 +192,7 @@
 	if(old == nil){
 		if(Dflag)
 			fprint(2, "msgFlush: cannot find %d\n", m->t.oldtag);
-		vtUnlock(con->mlock);
+		qunlock(&con->mlock);
 		return;
 	}
 
@@ -253,17 +246,17 @@
 	if(Dflag)
 		fprint(2, "msgFlush: add %d to %d queue\n",
 			m->t.tag, old->t.tag);
-	vtUnlock(con->mlock);
+	qunlock(&con->mlock);
 }
 
 static void
 msgProc(void*)
 {
 	Msg *m;
-	char *e;
+	char e[ERRMAX];
 	Con *con;
 
-	vtThreadSetName("msgProc");
+	threadsetname("msgProc");
 
 	for(;;){
 		/*
@@ -271,64 +264,64 @@
 		 * If not, wait for and pull a message off
 		 * the read queue.
 		 */
-		vtLock(mbox.rlock);
+		qlock(&mbox.rlock);
 		if(mbox.nproc > mbox.maxproc){
 			mbox.nproc--;
-			vtUnlock(mbox.rlock);
+			qunlock(&mbox.rlock);
 			break;
 		}
 		while(mbox.rhead == nil)
-			vtSleep(mbox.rrendez);
+			rsleep(&mbox.rrendez);
 		m = mbox.rhead;
 		mbox.rhead = m->rwnext;
 		m->rwnext = nil;
-		vtUnlock(mbox.rlock);
+		qunlock(&mbox.rlock);
 
 		con = m->con;
-		e = nil;
+		*e = 0;
 
 		/*
 		 * If the message has been flushed before
 		 * any 9P processing has started, mark it so
 		 * none will be attempted.
 		 */
-		vtLock(con->mlock);
+		qlock(&con->mlock);
 		if(m->state == MsgF)
-			e = "flushed";
+			strcpy(e, "flushed");
 		else
 			m->state = Msg9;
-		vtUnlock(con->mlock);
+		qunlock(&con->mlock);
 
-		if(e == nil){
+		if(*e == 0){
 			/*
 			 * explain this
 			 */
-			vtLock(con->lock);
+			qlock(&con->lock);
 			if(m->t.type == Tversion){
 				con->version = m;
 				con->state = ConDown;
 				while(con->mhead != m)
-					vtSleep(con->rendez);
+					rsleep(&con->rendez);
 				assert(con->state == ConDown);
 				if(con->version == m){
 					con->version = nil;
 					con->state = ConInit;
 				}
 				else
-					e = "Tversion aborted";
+					strcpy(e, "Tversion aborted");
 			}
 			else if(con->state != ConUp)
-				e = "connection not ready";
-			vtUnlock(con->lock);
+				strcpy(e, "connection not ready");
+			qunlock(&con->lock);
 		}
 
 		/*
 		 * Dispatch if not error already.
 		 */
 		m->r.tag = m->t.tag;
-		if(e == nil && !(*rFcall[m->t.type])(m))
-			e = vtGetError();
-		if(e != nil){
+		if(*e == 0 && !(*rFcall[m->t.type])(m))
+			rerrstr(e, sizeof e);
+		if(*e != 0){
 			m->r.type = Rerror;
 			m->r.ename = e;
 		}
@@ -340,14 +333,14 @@
 		 * write queue and wakeup the write process.
 		 */
 		if(!m->nowq){
-			vtLock(con->wlock);
+			qlock(&con->wlock);
 			if(con->whead == nil)
 				con->whead = m;
 			else
 				con->wtail->rwnext = m;
 			con->wtail = m;
-			vtWakeup(con->wrendez);
-			vtUnlock(con->wlock);
+			rwakeup(&con->wrendez);
+			qunlock(&con->wlock);
 		}
 	}
 }
@@ -359,7 +352,7 @@
 	Con *con;
 	int eof, fd, n;
 
-	vtThreadSetName("msgRead");
+	threadsetname("msgRead");
 
 	con = v;
 	fd = con->fd;
@@ -388,7 +381,7 @@
 		if(Dflag)
 			fprint(2, "msgRead %p: t %F\n", con, &m->t);
 
-		vtLock(con->mlock);
+		qlock(&con->mlock);
 		if(con->mtail != nil){
 			m->mprev = con->mtail;
 			con->mtail->mnext = m;
@@ -398,14 +391,14 @@
 			m->mprev = nil;
 		}
 		con->mtail = m;
-		vtUnlock(con->mlock);
+		qunlock(&con->mlock);
 
-		vtLock(mbox.rlock);
+		qlock(&mbox.rlock);
 		if(mbox.rhead == nil){
 			mbox.rhead = m;
-			if(!vtWakeup(mbox.rrendez)){
+			if(!rwakeup(&mbox.rrendez)){
 				if(mbox.nproc < mbox.maxproc){
-					if(vtThread(msgProc, nil) > 0)
+					if(proccreate(msgProc, nil, STACK) > 0)
 						mbox.nproc++;
 				}
 				else
@@ -413,13 +406,13 @@
 			}
 			/*
 			 * don't need this surely?
-			vtWakeup(mbox.rrendez);
+			rwakeup(&mbox.rrendez);
 			 */
 		}
 		else
 			mbox.rtail->rwnext = m;
 		mbox.rtail = m;
-		vtUnlock(mbox.rlock);
+		qunlock(&mbox.rlock);
 	}
 }
 
@@ -430,10 +423,10 @@
 	int eof, n;
 	Msg *flush, *m;
 
-	vtThreadSetName("msgWrite");
+	threadsetname("msgWrite");
 
 	con = v;
-	if(vtThread(msgRead, con) < 0){
+	if(proccreate(msgRead, con, STACK) < 0){
 		conFree(con);
 		return;
 	}
@@ -442,14 +435,14 @@
 		/*
 		 * Wait for and pull a message off the write queue.
 		 */
-		vtLock(con->wlock);
+		qlock(&con->wlock);
 		while(con->whead == nil)
-			vtSleep(con->wrendez);
+			rsleep(&con->wrendez);
 		m = con->whead;
 		con->whead = m->rwnext;
 		m->rwnext = nil;
 		assert(!m->nowq);
-		vtUnlock(con->wlock);
+		qunlock(&con->wlock);
 
 		eof = 0;
 
@@ -457,7 +450,7 @@
 		 * Write each message (if it hasn't been flushed)
 		 * followed by any messages waiting for it to complete.
 		 */
-		vtLock(con->mlock);
+		qlock(&con->mlock);
 		while(m != nil){
 			msgMunlink(m);
 
@@ -467,13 +460,13 @@
 
 			if(m->state != MsgF){
 				m->state = MsgW;
-				vtUnlock(con->mlock);
+				qunlock(&con->mlock);
 
 				n = convS2M(&m->r, con->data, con->msize);
 				if(write(con->fd, con->data, n) != n)
 					eof = 1;
 
-				vtLock(con->mlock);
+				qlock(&con->mlock);
 			}
 
 			if((flush = m->flush) != nil){
@@ -483,21 +476,21 @@
 			msgFree(m);
 			m = flush;
 		}
-		vtUnlock(con->mlock);
+		qunlock(&con->mlock);
 
-		vtLock(con->lock);
+		qlock(&con->lock);
 		if(eof && con->fd >= 0){
 			close(con->fd);
 			con->fd = -1;
 		}
 		if(con->state == ConDown)
-			vtWakeup(con->rendez);
+			rwakeup(&con->rendez);
 		if(con->state == ConMoribund && con->mhead == nil){
-			vtUnlock(con->lock);
+			qunlock(&con->lock);
 			conFree(con);
 			break;
 		}
-		vtUnlock(con->lock);
+		qunlock(&con->lock);
 	}
 }
 
@@ -508,24 +501,19 @@
 	char buf[128], *p;
 	int rfd, n;
 
-	vtLock(cbox.alock);
+	qlock(&cbox.alock);
 	while(cbox.ahead == nil){
 		if(cbox.ncon >= cbox.maxcon){
 			cbox.nconstarve++;
-			vtSleep(cbox.arendez);
+			rsleep(&cbox.arendez);
 			continue;
 		}
-		con = vtMemAllocZ(sizeof(Con));
-		con->lock = vtLockAlloc();
-		con->rendez = vtRendezAlloc(con->lock);
-		con->data = vtMemAlloc(cbox.msize);
+		con = vtmallocz(sizeof(Con));
+		con->rendez.l = &con->lock;
+		con->data = vtmalloc(cbox.msize);
 		con->msize = cbox.msize;
-		con->alock = vtLockAlloc();
-		con->mlock = vtLockAlloc();
-		con->mrendez = vtRendezAlloc(con->mlock);
-		con->wlock = vtLockAlloc();
-		con->wrendez = vtRendezAlloc(con->wlock);
-		con->fidlock = vtLockAlloc();
+		con->mrendez.l = &con->mlock;
+		con->wrendez.l = &con->wlock;
 
 		cbox.ncon++;
 		cbox.ahead = con;
@@ -553,13 +541,13 @@
 	con->state = ConNew;
 	con->fd = fd;
 	if(con->name != nil){
-		vtMemFree(con->name);
+		vtfree(con->name);
 		con->name = nil;
 	}
 	if(name != nil)
-		con->name = vtStrDup(name);
+		con->name = vtstrdup(name);
 	else
-		con->name = vtStrDup("unknown");
+		con->name = vtstrdup("unknown");
 	con->remote[0] = 0;
 	snprint(buf, sizeof buf, "%s/remote", con->name);
 	if((rfd = open(buf, OREAD)) >= 0){
@@ -574,9 +562,9 @@
 	}
 	con->flags = flags;
 	con->isconsole = 0;
-	vtUnlock(cbox.alock);
+	qunlock(&cbox.alock);
 
-	if(vtThread(msgWrite, con) < 0){
+	if(proccreate(msgWrite, con, STACK) < 0){
 		conFree(con);
 		return nil;
 	}
@@ -616,21 +604,21 @@
 	if(argc)
 		return cliError(usage);
 
-	vtLock(mbox.alock);
+	qlock(&mbox.alock);
 	if(maxmsg)
 		mbox.maxmsg = maxmsg;
 	maxmsg = mbox.maxmsg;
 	nmsg = mbox.nmsg;
 	nmsgstarve = mbox.nmsgstarve;
-	vtUnlock(mbox.alock);
+	qunlock(&mbox.alock);
 
-	vtLock(mbox.rlock);
+	qlock(&mbox.rlock);
 	if(maxproc)
 		mbox.maxproc = maxproc;
 	maxproc = mbox.maxproc;
 	nproc = mbox.nproc;
 	nprocstarve = mbox.nprocstarve;
-	vtUnlock(mbox.rlock);
+	qunlock(&mbox.rlock);
 
 	consPrint("\tmsg -m %d -p %d\n", maxmsg, maxproc);
 	consPrint("\tnmsg %d nmsgstarve %d nproc %d nprocstarve %d\n",
@@ -717,7 +705,7 @@
 	if(argc > 0)
 		return cliError(usage);
 
-	vtRLock(cbox.clock);
+	rlock(&cbox.clock);
 	l1 = 0;
 	l2 = 0;
 	for(con=cbox.chead; con; con=con->cnext){
@@ -728,7 +716,7 @@
 	}
 	for(con=cbox.chead; con; con=con->cnext){
 		consPrint("\t%-*s %-*s", l1, con->name, l2, con->remote);
-		vtLock(con->fidlock);
+		qlock(&con->fidlock);
 		last = nil;
 		for(i=0; i<NFidHash; i++)
 			for(fid=con->fidhash[i]; fid; fid=fid->hash)
@@ -741,21 +729,19 @@
 		for(; fid; last=fid, fid=fid->sort)
 			if(last==nil || strcmp(fid->uname, last->uname) != 0)
 				consPrint(" %q", fid->uname);
-		vtUnlock(con->fidlock);
+		qunlock(&con->fidlock);
 		consPrint("\n");
 	}
-	vtRUnlock(cbox.clock);
+	runlock(&cbox.clock);
 	return 1;
 }
 
 void
 msgInit(void)
 {
-	mbox.alock = vtLockAlloc();
-	mbox.arendez = vtRendezAlloc(mbox.alock);
+	mbox.arendez.l = &mbox.alock;
 
-	mbox.rlock = vtLockAlloc();
-	mbox.rrendez = vtRendezAlloc(mbox.rlock);
+	mbox.rrendez.l = &mbox.rlock;
 
 	mbox.maxmsg = NMsgInit;
 	mbox.maxproc = NMsgProcInit;
@@ -789,22 +775,22 @@
 	if(argc)
 		return cliError(usage);
 
-	vtLock(cbox.clock);
+	wlock(&cbox.clock);
 	if(maxcon)
 		cbox.maxcon = maxcon;
 	maxcon = cbox.maxcon;
 	ncon = cbox.ncon;
 	nconstarve = cbox.nconstarve;
-	vtUnlock(cbox.clock);
+	wunlock(&cbox.clock);
 
 	consPrint("\tcon -m %d\n", maxcon);
 	consPrint("\tncon %d nconstarve %d\n", ncon, nconstarve);
 
-	vtRLock(cbox.clock);
+	rlock(&cbox.clock);
 	for(con = cbox.chead; con != nil; con = con->cnext){
 		consPrint("\t%s\n", con->name);
 	}
-	vtRUnlock(cbox.clock);
+	runlock(&cbox.clock);
 
 	return 1;
 }
@@ -812,10 +798,7 @@
 void
 conInit(void)
 {
-	cbox.alock = vtLockAlloc();
-	cbox.arendez = vtRendezAlloc(cbox.alock);
-
-	cbox.clock = vtLockAlloc();
+	cbox.arendez.l = &cbox.alock;
 
 	cbox.maxcon = NConInit;
 	cbox.msize = NMsizeInit;
diff --git a/src/cmd/fossil/9srv.c b/src/cmd/fossil/9srv.c
index 8469626..94e6724 100644
--- a/src/cmd/fossil/9srv.c
+++ b/src/cmd/fossil/9srv.c
@@ -14,7 +14,7 @@
 };
 
 static struct {
-	VtLock*	lock;
+	RWLock	lock;
 
 	Srv*	head;
 	Srv*	tail;
@@ -33,11 +33,11 @@
 	 */
 	p = smprint("/srv/%s", name);
 	if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
-		vtMemFree(p);
+		vtfree(p);
 		p = smprint("#s/%s", name);
 		if((srvfd = create(p, ORCLOSE|OWRITE, mode)) < 0){
-			vtSetError("create %s: %r", p);
-			vtMemFree(p);
+			werrstr("create %s: %r", p);
+			vtfree(p);
 			return -1;
 		}
 	}
@@ -45,8 +45,8 @@
 	n = snprint(buf, sizeof(buf), "%d", fd);
 	if(write(srvfd, buf, n) < 0){
 		close(srvfd);
-		vtSetError("write %s: %r", p);
-		vtMemFree(p);
+		werrstr("write %s: %r", p);
+		vtfree(p);
 		return -1;
 	}
 
@@ -69,9 +69,9 @@
 
 	if(srv->srvfd != -1)
 		close(srv->srvfd);
-	vtMemFree(srv->service);
-	vtMemFree(srv->mntpnt);
-	vtMemFree(srv);
+	vtfree(srv->service);
+	vtfree(srv->mntpnt);
+	vtfree(srv);
 }
 
 static Srv*
@@ -82,7 +82,7 @@
 	int srvfd;
 	char *mntpnt;
 
-	vtLock(sbox.lock);
+	wlock(&sbox.lock);
 	for(srv = sbox.head; srv != nil; srv = srv->next){
 		if(strcmp(srv->service, service) != 0)
 			continue;
@@ -92,8 +92,8 @@
 		 */
 		if((dir = dirfstat(srv->srvfd)) != nil){
 			free(dir);
-			vtSetError("srv: already serving '%s'", service);
-			vtUnlock(sbox.lock);
+			werrstr("srv: already serving '%s'", service);
+			wunlock(&sbox.lock);
 			return nil;
 		}
 		srvFree(srv);
@@ -101,14 +101,14 @@
 	}
 
 	if((srvfd = srvFd(service, mode, fd, &mntpnt)) < 0){
-		vtUnlock(sbox.lock);
+		wunlock(&sbox.lock);
 		return nil;
 	}
 	close(fd);
 
-	srv = vtMemAllocZ(sizeof(Srv));
+	srv = vtmallocz(sizeof(Srv));
 	srv->srvfd = srvfd;
-	srv->service = vtStrDup(service);
+	srv->service = vtstrdup(service);
 	srv->mntpnt = mntpnt;
 
 	if(sbox.tail != nil){
@@ -120,7 +120,7 @@
 		srv->prev = nil;
 	}
 	sbox.tail = srv;
-	vtUnlock(sbox.lock);
+	wunlock(&sbox.lock);
 
 	return srv;
 }
@@ -168,7 +168,7 @@
 	}ARGEND
 
 	if(pflag && (conflags&ConNoPermCheck)){
-		vtSetError("srv: cannot use -P with -p");
+		werrstr("srv: cannot use -P with -p");
 		return 0;
 	}
 
@@ -176,27 +176,27 @@
 	default:
 		return cliError(usage);
 	case 0:
-		vtRLock(sbox.lock);
+		rlock(&sbox.lock);
 		for(srv = sbox.head; srv != nil; srv = srv->next)
 			consPrint("\t%s\t%d\n", srv->service, srv->srvfd);
-		vtRUnlock(sbox.lock);
+		runlock(&sbox.lock);
 
 		return 1;
 	case 1:
 		if(!dflag)
 			break;
 
-		vtLock(sbox.lock);
+		wlock(&sbox.lock);
 		for(srv = sbox.head; srv != nil; srv = srv->next){
 			if(strcmp(srv->service, argv[0]) != 0)
 				continue;
 			srvFree(srv);
 			break;
 		}
-		vtUnlock(sbox.lock);
+		wunlock(&sbox.lock);
 
 		if(srv == nil){
-			vtSetError("srv: '%s' not found", argv[0]);
+			werrstr("srv: '%s' not found", argv[0]);
 			return 0;
 		}
 
@@ -204,7 +204,7 @@
 	}
 
 	if(pipe(fd) < 0){
-		vtSetError("srv pipe: %r");
+		werrstr("srv pipe: %r");
 		return 0;
 	}
 	if((srv = srvAlloc(argv[0], mode, fd[0])) == nil){
@@ -223,9 +223,9 @@
 	}
 	if(r == 0){
 		close(fd[1]);
-		vtLock(sbox.lock);
+		wlock(&sbox.lock);
 		srvFree(srv);
-		vtUnlock(sbox.lock);
+		wunlock(&sbox.lock);
 	}
 
 	return r;
@@ -234,8 +234,6 @@
 int
 srvInit(void)
 {
-	sbox.lock = vtLockAlloc();
-
 	cliAddCmd("srv", cmdSrv);
 
 	return 1;
diff --git a/src/cmd/fossil/9user.c b/src/cmd/fossil/9user.c
index 98203d0..f24ef4a 100644
--- a/src/cmd/fossil/9user.c
+++ b/src/cmd/fossil/9user.c
@@ -34,7 +34,7 @@
 };
 
 static struct {
-	VtLock*	lock;
+	RWLock	lock;
 
 	Ubox*	box;
 } ubox;
@@ -83,7 +83,7 @@
 				return u;
 		}
 	}
-	vtSetError("uname: uid '%s' not found", uid);
+	werrstr("uname: uid '%s' not found", uid);
 	return nil;
 }
 
@@ -93,13 +93,13 @@
 	User *u;
 	char *uname;
 
-	vtRLock(ubox.lock);
+	rlock(&ubox.lock);
 	if((u = _userByUid(ubox.box, uid)) == nil){
-		vtRUnlock(ubox.lock);
+		runlock(&ubox.lock);
 		return nil;
 	}
-	uname = vtStrDup(u->uname);
-	vtRUnlock(ubox.lock);
+	uname = vtstrdup(u->uname);
+	runlock(&ubox.lock);
 
 	return uname;
 }
@@ -115,7 +115,7 @@
 				return u;
 		}
 	}
-	vtSetError("uname: uname '%s' not found", uname);
+	werrstr("uname: uname '%s' not found", uname);
 	return nil;
 }
 
@@ -125,13 +125,13 @@
 	User *u;
 	char *uid;
 
-	vtRLock(ubox.lock);
+	rlock(&ubox.lock);
 	if((u = _userByUname(ubox.box, uname)) == nil){
-		vtRUnlock(ubox.lock);
+		runlock(&ubox.lock);
 		return nil;
 	}
-	uid = vtStrDup(u->uid);
-	vtRUnlock(ubox.lock);
+	uid = vtstrdup(u->uid);
+	runlock(&ubox.lock);
 
 	return uid;
 }
@@ -182,9 +182,9 @@
 	 * use this functionality, we could cache the write group lookup.
 	 */
 
-	vtRLock(ubox.lock);
+	rlock(&ubox.lock);
 	ret = _groupMember(ubox.box, "write", uname, 1);
-	vtRUnlock(ubox.lock);
+	runlock(&ubox.lock);
 	return ret;
 }
 
@@ -202,14 +202,14 @@
 	}
 	if(i >= g->ngroup){
 		if(strcmp(g->uname, member) == 0)
-			vtSetError("uname: '%s' always in own group", member);
+			werrstr("uname: '%s' always in own group", member);
 		else
-			vtSetError("uname: '%s' not in group '%s'",
+			werrstr("uname: '%s' not in group '%s'",
 				member, g->uname);
 		return 0;
 	}
 
-	vtMemFree(g->group[i]);
+	vtfree(g->group[i]);
 
 	box->len -= strlen(member);
 	if(g->ngroup > 1)
@@ -217,14 +217,14 @@
 	g->ngroup--;
 	switch(g->ngroup){
 	case 0:
-		vtMemFree(g->group);
+		vtfree(g->group);
 		g->group = nil;
 		break;
 	default:
 		for(; i < g->ngroup; i++)
 			g->group[i] = g->group[i+1];
 		g->group[i] = nil;		/* prevent accidents */
-		g->group = vtMemRealloc(g->group, g->ngroup * sizeof(char*));
+		g->group = vtrealloc(g->group, g->ngroup * sizeof(char*));
 		break;
 	}
 
@@ -240,15 +240,15 @@
 		return 0;
 	if(_groupMember(box, g->uid, u->uname, 0)){
 		if(strcmp(g->uname, member) == 0)
-			vtSetError("uname: '%s' always in own group", member);
+			werrstr("uname: '%s' always in own group", member);
 		else
-			vtSetError("uname: '%s' already in group '%s'",
+			werrstr("uname: '%s' already in group '%s'",
 				member, g->uname);
 		return 0;
 	}
 
-	g->group = vtMemRealloc(g->group, (g->ngroup+1)*sizeof(char*));
-	g->group[g->ngroup] = vtStrDup(member);
+	g->group = vtrealloc(g->group, (g->ngroup+1)*sizeof(char*));
+	g->group[g->ngroup] = vtstrdup(member);
 	box->len += strlen(member);
 	g->ngroup++;
 	if(g->ngroup > 1)
@@ -265,9 +265,9 @@
 	if(group == nil)
 		return 0;
 
-	vtRLock(ubox.lock);
+	rlock(&ubox.lock);
 	r = _groupMember(ubox.box, group, member, 0);
-	vtRUnlock(ubox.lock);
+	runlock(&ubox.lock);
 
 	return r;
 }
@@ -286,21 +286,21 @@
 	if(strcmp(member, unamenone) == 0 || group == nil)
 		return 0;
 
-	vtRLock(ubox.lock);
+	rlock(&ubox.lock);
 	if((g = _userByUid(ubox.box, group)) == nil){
-		vtRUnlock(ubox.lock);
+		runlock(&ubox.lock);
 		return 0;
 	}
 	if(g->leader != nil){
 		if(strcmp(g->leader, member) == 0){
-			vtRUnlock(ubox.lock);
+			runlock(&ubox.lock);
 			return 1;
 		}
 		r = 0;
 	}
 	else
 		r = _groupMember(ubox.box, group, member, 0);
-	vtRUnlock(ubox.lock);
+	runlock(&ubox.lock);
 
 	return r;
 }
@@ -310,16 +310,16 @@
 {
 	int i;
 
-	vtMemFree(u->uid);
-	vtMemFree(u->uname);
+	vtfree(u->uid);
+	vtfree(u->uname);
 	if(u->leader != nil)
-		vtMemFree(u->leader);
+		vtfree(u->leader);
 	if(u->ngroup){
 		for(i = 0; i < u->ngroup; i++)
-			vtMemFree(u->group[i]);
-		vtMemFree(u->group);
+			vtfree(u->group[i]);
+		vtfree(u->group);
 	}
-	vtMemFree(u);
+	vtfree(u);
 }
 
 static User*
@@ -327,9 +327,9 @@
 {
 	User *u;
 
-	u = vtMemAllocZ(sizeof(User));
-	u->uid = vtStrDup(uid);
-	u->uname = vtStrDup(uname);
+	u = vtmallocz(sizeof(User));
+	u->uid = vtstrdup(uid);
+	u->uname = vtstrdup(uname);
 
 	return u;
 }
@@ -404,7 +404,7 @@
 	if(!fileTruncate(file, uidadm))
 		goto tidy;
 
-	p = s = vtMemAlloc(box->len+1);
+	p = s = vtmalloc(box->len+1);
 	q = p + box->len+1;
 	for(u = box->head; u != nil; u = u->next){
 		p += snprint(p, q-p, "%s:%s:", u->uid, u->uname);
@@ -419,7 +419,7 @@
 		p += snprint(p, q-p, "\n");
 	}
 	r = fileWrite(file, s, box->len, 0, uidadm);
-	vtMemFree(s);
+	vtfree(s);
 
 tidy:
 	if(file != nil)
@@ -506,7 +506,7 @@
 		next = u->next;
 		userFree(u);
 	}
-	vtMemFree(box);
+	vtfree(box);
 }
 
 static int
@@ -525,7 +525,7 @@
 	blank = 1;
 	comment = nline = 0;
 
-	s = p = buf = vtMemAlloc(len+1);
+	s = p = buf = vtmalloc(len+1);
 	for(q = users; *q != '\0'; q++){
 		if(*q == '\r' || *q == '\t' || *q == ' ')
 			continue;
@@ -549,18 +549,18 @@
 	}
 	*p = '\0';
 
-	line = vtMemAllocZ((nline+2)*sizeof(char*));
+	line = vtmallocz((nline+2)*sizeof(char*));
 	if((i = gettokens(buf, line, nline+2, "\n")) != nline){
 		fprint(2, "nline %d (%d) botch\n", nline, i);
-		vtMemFree(line);
-		vtMemFree(buf);
+		vtfree(line);
+		vtfree(buf);
 		return 0;
 	}
 
 	/*
 	 * Everything is updated in a local Ubox until verified.
 	 */
-	box = vtMemAllocZ(sizeof(Ubox));
+	box = vtmallocz(sizeof(Ubox));
 
 	/*
 	 * First pass - check format, check for duplicates
@@ -568,35 +568,35 @@
 	 */
 	nuser = 0;
 	for(i = 0; i < nline; i++){
-		s = vtStrDup(line[i]);
+		s = vtstrdup(line[i]);
 		if(getfields(s, f, nelem(f), 0, ":") != 4){
 			fprint(2, "bad line '%s'\n", line[i]);
-			vtMemFree(s);
+			vtfree(s);
 			continue;
 		}
 		if(*f[0] == '\0' || *f[1] == '\0'){
 			fprint(2, "bad line '%s'\n", line[i]);
-			vtMemFree(s);
+			vtfree(s);
 			continue;
 		}
 		if(!validUserName(f[0])){
 			fprint(2, "invalid uid '%s'\n", f[0]);
-			vtMemFree(s);
+			vtfree(s);
 			continue;
 		}
 		if(_userByUid(box, f[0]) != nil){
 			fprint(2, "duplicate uid '%s'\n", f[0]);
-			vtMemFree(s);
+			vtfree(s);
 			continue;
 		}
 		if(!validUserName(f[1])){
 			fprint(2, "invalid uname '%s'\n", f[0]);
-			vtMemFree(s);
+			vtfree(s);
 			continue;
 		}
 		if(_userByUname(box, f[1]) != nil){
 			fprint(2, "duplicate uname '%s'\n", f[1]);
-			vtMemFree(s);
+			vtfree(s);
 			continue;
 		}
 
@@ -605,7 +605,7 @@
 		line[nuser] = line[i];
 		nuser++;
 
-		vtMemFree(s);
+		vtfree(s);
 	}
 	assert(box->nuser == nuser);
 
@@ -613,15 +613,15 @@
 	 * Second pass - fill in leader and group information.
 	 */
 	for(i = 0; i < nuser; i++){
-		s = vtStrDup(line[i]);
+		s = vtstrdup(line[i]);
 		getfields(s, f, nelem(f), 0, ":");
 
 		assert(g = _userByUname(box, f[1]));
 		if(*f[2] != '\0'){
 			if((u = _userByUname(box, f[2])) == nil)
-				g->leader = vtStrDup(g->uname);
+				g->leader = vtstrdup(g->uname);
 			else
-				g->leader = vtStrDup(u->uname);
+				g->leader = vtstrdup(u->uname);
 			box->len += strlen(g->leader);
 		}
 		for(p = f[3]; p != nil; p = q){
@@ -632,30 +632,30 @@
 			}
 		}
 
-		vtMemFree(s);
+		vtfree(s);
 	}
 
-	vtMemFree(line);
-	vtMemFree(buf);
+	vtfree(line);
+	vtfree(buf);
 
 	for(i = 0; usersMandatory[i] != nil; i++){
 		if((u = _userByUid(box, usersMandatory[i])) == nil){
-			vtSetError("user '%s' is mandatory", usersMandatory[i]);
+			werrstr("user '%s' is mandatory", usersMandatory[i]);
 			uboxFree(box);
 			return 0;
 		}
 		if(strcmp(u->uid, u->uname) != 0){
-			vtSetError("uid/uname for user '%s' must match",
+			werrstr("uid/uname for user '%s' must match",
 				usersMandatory[i]);
 			uboxFree(box);
 			return 0;
 		}
 	}
 
-	vtLock(ubox.lock);
+	wlock(&ubox.lock);
 	obox = ubox.box;
 	ubox.box = box;
-	vtUnlock(ubox.lock);
+	wunlock(&ubox.lock);
 
 	if(obox != nil)
 		uboxFree(obox);
@@ -683,7 +683,7 @@
 	if((file = fileOpen(fsysGetFs(fsys), path)) != nil){
 		if(fileGetSize(file, &size)){
 			len = size;
-			p = vtMemAlloc(size+1);
+			p = vtmalloc(size+1);
 			if(fileRead(file, p, len, 0) == len){
 				p[len] = '\0';
 				r = uboxInit(p, len);
@@ -720,9 +720,9 @@
 	if(argc < 1){
 		if(!dflag)
 			return cliError(usage);
-		vtRLock(ubox.lock);
+		rlock(&ubox.lock);
 		uboxDump(ubox.box);
-		vtRUnlock(ubox.lock);
+		runlock(&ubox.lock);
 		return 1;
 	}
 
@@ -730,37 +730,37 @@
 	argc--; argv++;
 
 	if(argc == 0){
-		vtRLock(ubox.lock);
+		rlock(&ubox.lock);
 		if((u = _userByUname(ubox.box, uname)) == nil){
-			vtRUnlock(ubox.lock);
+			runlock(&ubox.lock);
 			return 0;
 		}
 		consPrint("\t%U\n", u);
-		vtRUnlock(ubox.lock);
+		runlock(&ubox.lock);
 		return 1;
 	}
 
-	vtLock(ubox.lock);
+	wlock(&ubox.lock);
 	u = _userByUname(ubox.box, uname);
 	while(argc--){
 		if(argv[0][0] == '%'){
 			if(u == nil){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			p = &argv[0][1];
 			if((up = _userByUname(ubox.box, p)) != nil){
-				vtSetError("uname: uname '%s' already exists",
+				werrstr("uname: uname '%s' already exists",
 					up->uname);
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			for(i = 0; usersMandatory[i] != nil; i++){
 				if(strcmp(usersMandatory[i], uname) != 0)
 					continue;
-				vtSetError("uname: uname '%s' is mandatory",
+				werrstr("uname: uname '%s' is mandatory",
 					uname);
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 
@@ -768,80 +768,80 @@
 			for(up = ubox.box->head; up != nil; up = up->next){
 				if(up->leader != nil){
 					if(strcmp(up->leader, u->uname) == 0){
-						vtMemFree(up->leader);
-						up->leader = vtStrDup(p);
+						vtfree(up->leader);
+						up->leader = vtstrdup(p);
 						ubox.box->len += d;
 					}
 				}
 				for(i = 0; i < up->ngroup; i++){
 					if(strcmp(up->group[i], u->uname) != 0)
 						continue;
-					vtMemFree(up->group[i]);
-					up->group[i] = vtStrDup(p);
+					vtfree(up->group[i]);
+					up->group[i] = vtstrdup(p);
 					ubox.box->len += d;
 					break;
 				}
 			}
 
 			uboxRemUser(ubox.box, u);
-			vtMemFree(u->uname);
-			u->uname = vtStrDup(p);
+			vtfree(u->uname);
+			u->uname = vtstrdup(p);
 			uboxAddUser(ubox.box, u);
 		}
 		else if(argv[0][0] == '='){
 			if(u == nil){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
 				if(argv[0][1] != '\0'){
-					vtUnlock(ubox.lock);
+					wunlock(&ubox.lock);
 					return 0;
 				}
 			}
 			if(u->leader != nil){
 				ubox.box->len -= strlen(u->leader);
-				vtMemFree(u->leader);
+				vtfree(u->leader);
 				u->leader = nil;
 			}
 			if(up != nil){
-				u->leader = vtStrDup(up->uname);
+				u->leader = vtstrdup(up->uname);
 				ubox.box->len += strlen(u->leader);
 			}
 		}
 		else if(argv[0][0] == '+'){
 			if(u == nil){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			if(!_groupAddMember(ubox.box, u, up->uname)){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 		}
 		else if(argv[0][0] == '-'){
 			if(u == nil){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			if((up = _userByUname(ubox.box, &argv[0][1])) == nil){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 			if(!_groupRemMember(ubox.box, u, up->uname)){
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 		}
 		else{
 			if(u != nil){
-				vtSetError("uname: uname '%s' already exists",
+				werrstr("uname: uname '%s' already exists",
 					u->uname);
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 
@@ -849,9 +849,9 @@
 			if(*uid == ':')
 				uid++;
 			if((u = _userByUid(ubox.box, uid)) != nil){
-				vtSetError("uname: uid '%s' already exists",
+				werrstr("uname: uid '%s' already exists",
 					u->uid);
-				vtUnlock(ubox.lock);
+				wunlock(&ubox.lock);
 				return 0;
 			}
 
@@ -861,9 +861,9 @@
 				// should have an option for the mode and gid
 				p = smprint(createfmt, uname, uname, uname);
 				r = cliExec(p);
-				vtMemFree(p);
+				vtfree(p);
 				if(r == 0){
-					vtUnlock(ubox.lock);
+					wunlock(&ubox.lock);
 					return 0;
 				}
 			}
@@ -872,12 +872,12 @@
 	}
 
 	if(usersFileWrite(ubox.box) == 0){
-		vtUnlock(ubox.lock);
+		wunlock(&ubox.lock);
 		return 0;
 	}
 	if(dflag)
 		uboxDump(ubox.box);
-	vtUnlock(ubox.lock);
+	wunlock(&ubox.lock);
 
 	return 1;
 }
@@ -922,14 +922,14 @@
 			return 0;
 	}
 
-	vtRLock(ubox.lock);
+	rlock(&ubox.lock);
 	box = ubox.box;
 	consPrint("\tnuser %d len %d\n", box->nuser, box->len);
 
 	r = 1;
 	if(wflag)
 		r = usersFileWrite(box);
-	vtRUnlock(ubox.lock);
+	runlock(&ubox.lock);
 	return r;
 }
 
@@ -938,7 +938,6 @@
 {
 	fmtinstall('U', userFmt);
 
-	ubox.lock = vtLockAlloc();
 	uboxInit(usersDefault, sizeof(usersDefault));
 
 	cliAddCmd("users", cmdUsers);
diff --git a/src/cmd/fossil/Ccli.c b/src/cmd/fossil/Ccli.c
index 775cb62..52a9147 100644
--- a/src/cmd/fossil/Ccli.c
+++ b/src/cmd/fossil/Ccli.c
@@ -8,7 +8,7 @@
 } Cmd;
 
 static struct {
-	VtLock*	lock;
+	QLock	lock;
 	Cmd*	cmd;
 	int	ncmd;
 	int	hi;
@@ -26,7 +26,7 @@
 
 	va_start(arg, fmt);
 	p = vsmprint(fmt, arg);
-	vtSetError("%s", p);
+	werrstr("%s", p);
 	free(p);
 	va_end(arg);
 
@@ -39,32 +39,32 @@
 	int argc, i, r;
 	char *argv[20], *p;
 
-	p = vtStrDup(buf);
+	p = vtstrdup(buf);
 	if((argc = tokenize(p, argv, nelem(argv)-1)) == 0){
-		vtMemFree(p);
+		vtfree(p);
 		return 1;
 	}
 	argv[argc] = 0;
 
 	if(argv[0][0] == '#'){
-		vtMemFree(p);
+		vtfree(p);
 		return 1;
 	}
 
-	vtLock(cbox.lock);
+	qlock(&cbox.lock);
 	for(i = 0; i < cbox.hi; i++){
 		if(strcmp(cbox.cmd[i].argv0, argv[0]) == 0){
-			vtUnlock(cbox.lock);
+			qunlock(&cbox.lock);
 			if(!(r = cbox.cmd[i].cmd(argc, argv)))
-				consPrint("%s\n", vtGetError());
-			vtMemFree(p);
+				consPrint("%r\n");
+			vtfree(p);
 			return r;
 		}
 	}
-	vtUnlock(cbox.lock);
+	qunlock(&cbox.lock);
 
 	consPrint("%s: - eh?\n", argv[0]);
-	vtMemFree(p);
+	vtfree(p);
 
 	return 0;
 }
@@ -75,16 +75,16 @@
 	int i;
 	Cmd *opt;
 
-	vtLock(cbox.lock);
+	qlock(&cbox.lock);
 	for(i = 0; i < cbox.hi; i++){
 		if(strcmp(argv0, cbox.cmd[i].argv0) == 0){
-			vtUnlock(cbox.lock);
+			qunlock(&cbox.lock);
 			return 0;
 		}
 	}
 	if(i >= cbox.hi){
 		if(cbox.hi >= cbox.ncmd){
-			cbox.cmd = vtMemRealloc(cbox.cmd,
+			cbox.cmd = vtrealloc(cbox.cmd,
 					(cbox.ncmd+NCmdIncr)*sizeof(Cmd));
 			memset(&cbox.cmd[cbox.ncmd], 0, NCmdIncr*sizeof(Cmd));
 			cbox.ncmd += NCmdIncr;
@@ -95,7 +95,7 @@
 	opt->argv0 = argv0;
 	opt->cmd = cmd;
 	cbox.hi++;
-	vtUnlock(cbox.lock);
+	qunlock(&cbox.lock);
 
 	return 1;
 }
@@ -103,8 +103,7 @@
 int
 cliInit(void)
 {
-	cbox.lock = vtLockAlloc();
-	cbox.cmd = vtMemAllocZ(NCmdIncr*sizeof(Cmd));
+	cbox.cmd = vtmallocz(NCmdIncr*sizeof(Cmd));
 	cbox.ncmd = NCmdIncr;
 	cbox.hi = 0;
 
diff --git a/src/cmd/fossil/Ccmd.c b/src/cmd/fossil/Ccmd.c
index 806c62f..3e06288 100644
--- a/src/cmd/fossil/Ccmd.c
+++ b/src/cmd/fossil/Ccmd.c
@@ -3,7 +3,7 @@
 #include "9.h"
 
 static struct {
-	VtLock*	lock;
+	QLock	lock;
 
 	Con*	con;
 	int	confd[2];
@@ -53,7 +53,7 @@
 	f->stat = buf;
 	f->nstat = convD2M(&d, buf, sizeof buf);
 	if(f->nstat < BIT16SZ){
-		vtSetError("Twstat: convD2M failed (internal error)");
+		werrstr("Twstat: convD2M failed (internal error)");
 		return 0;
 	}
 
@@ -131,14 +131,14 @@
 	int i;
 
 	if(argc < 2){
-		vtSetError("usage: Twalk tag fid newfid [name...]");
+		werrstr("usage: Twalk tag fid newfid [name...]");
 		return 0;
 	}
 	f->fid = strtol(argv[0], 0, 0);
 	f->newfid = strtol(argv[1], 0, 0);
 	f->nwname = argc-2;
 	if(f->nwname > MAXWELEM){
-		vtSetError("Twalk: too many names");
+		werrstr("Twalk: too many names");
 		return 0;
 	}
 	for(i = 0; i < argc-2; i++)
@@ -181,7 +181,7 @@
 {
 	f->msize = strtoul(argv[0], 0, 0);
 	if(f->msize > cbox.con->msize){
-		vtSetError("msize too big");
+		werrstr("msize too big");
 		return 0;
 	}
 	f->version = argv[1];
@@ -242,7 +242,7 @@
 	argc--;
 	argv++;
 	if(cmd9pTmsg[i].argc && argc != cmd9pTmsg[i].argc){
-		vtSetError("usage: %s %s",
+		werrstr("usage: %s %s",
 			cmd9pTmsg[i].name, cmd9pTmsg[i].usage);
 		return 0;
 	}
@@ -256,33 +256,33 @@
 	msize = cbox.con->msize;
 	if(!cmd9pTmsg[i].f(&t, argc, argv))
 		return 0;
-	buf = vtMemAlloc(msize);
+	buf = vtmalloc(msize);
 	n = convS2M(&t, buf, msize);
 	if(n <= BIT16SZ){
-		vtSetError("%s: convS2M error", cmd9pTmsg[i].name);
-		vtMemFree(buf);
+		werrstr("%s: convS2M error", cmd9pTmsg[i].name);
+		vtfree(buf);
 		return 0;
 	}
 	if(write(cbox.confd[0], buf, n) != n){
-		vtSetError("%s: write error: %r", cmd9pTmsg[i].name);
-		vtMemFree(buf);
+		werrstr("%s: write error: %r", cmd9pTmsg[i].name);
+		vtfree(buf);
 		return 0;
 	}
 	consPrint("\t-> %F\n", &t);
 
 	if((n = read9pmsg(cbox.confd[0], buf, msize)) <= 0){
-		vtSetError("%s: read error: %r", cmd9pTmsg[i].name);
-		vtMemFree(buf);
+		werrstr("%s: read error: %r", cmd9pTmsg[i].name);
+		vtfree(buf);
 		return 0;
 	}
 	if(convM2S(buf, n, &f) == 0){
-		vtSetError("%s: convM2S error", cmd9pTmsg[i].name);
-		vtMemFree(buf);
+		werrstr("%s: convM2S error", cmd9pTmsg[i].name);
+		vtfree(buf);
 		return 0;
 	}
 	consPrint("\t<- %F\n", &f);
 
-	vtMemFree(buf);
+	vtfree(buf);
 	return 1;
 }
 
@@ -316,9 +316,9 @@
 		 */
 		if((fd = open(argv[0], OREAD)) < 0)
 			return cliError(". open %s: %r", argv[0]);
-		f = vtMemAlloc(dir->length+1);
+		f = vtmalloc(dir->length+1);
 		if((l = read(fd, f, length)) < 0){
-			vtMemFree(f);
+			vtfree(f);
 			close(fd);
 			return cliError(". read %s: %r", argv[0]);
 		}
@@ -333,16 +333,16 @@
 				*p = '\0';
 				if(cliExec(s) == 0){
 					r = 0;
-					consPrint("%s: %R\n", s);
+					consPrint("%s: %r\n", s);
 				}
 				s = p+1;
 			}
 		}
-		vtMemFree(f);
+		vtfree(f);
 	}
 
 	if(r == 0)
-		vtSetError("errors in . %#q", argv[0]);
+		werrstr("errors in . %#q", argv[0]);
 	return r;
 }
 
@@ -435,7 +435,6 @@
 int
 cmdInit(void)
 {
-	cbox.lock = vtLockAlloc();
 	cbox.confd[0] = cbox.confd[1] = -1;
 
 	cliAddCmd(".", cmdDot);
diff --git a/src/cmd/fossil/Ccons.c b/src/cmd/fossil/Ccons.c
index 65b9a40..afa0256 100644
--- a/src/cmd/fossil/Ccons.c
+++ b/src/cmd/fossil/Ccons.c
@@ -8,9 +8,9 @@
 };
 
 typedef struct Q {
-	VtLock*	lock;
-	VtRendez* full;
-	VtRendez* empty;
+	QLock	lock;
+	Rendez	full;
+	Rendez	empty;
 
 	char	q[Nq];
 	int	n;
@@ -19,7 +19,7 @@
 } Q;
 
 typedef struct Cons {
-	VtLock*	lock;
+	QLock	lock;
 	int	ref;
 	int	closed;
 	int	fd;
@@ -45,18 +45,18 @@
 static void
 consClose(Cons* cons)
 {
-	vtLock(cons->lock);
+	qlock(&cons->lock);
 	cons->closed = 1;
 
 	cons->ref--;
 	if(cons->ref > 0){
-		vtLock(cons->iq->lock);
-		vtWakeup(cons->iq->full);
-		vtUnlock(cons->iq->lock);
-		vtLock(cons->oq->lock);
-		vtWakeup(cons->oq->empty);
-		vtUnlock(cons->oq->lock);
-		vtUnlock(cons->lock);
+		qlock(&cons->iq->lock);
+		rwakeup(&cons->iq->full);
+		qunlock(&cons->iq->lock);
+		qlock(&cons->oq->lock);
+		rwakeup(&cons->oq->empty);
+		qunlock(&cons->oq->lock);
+		qunlock(&cons->lock);
 		return;
 	}
 
@@ -72,9 +72,8 @@
 		close(cons->fd);
 		cons->fd = -1;
 	}
-	vtUnlock(cons->lock);
-	vtLockFree(cons->lock);
-	vtMemFree(cons);
+	qunlock(&cons->lock);
+	vtfree(cons);
 	console.nopens--;
 }
 
@@ -86,7 +85,7 @@
 	int n, w;
 	char buf[Nq/4];
 
-	vtThreadSetName("consI");
+	threadsetname("consI");
 
 	cons = v;
 	q = cons->iq;
@@ -97,9 +96,9 @@
 		 */
 		if(cons->closed || (n = read(cons->fd, buf, Nq/4)) < 0)
 			break;
-		vtLock(q->lock);
+		qlock(&q->lock);
 		while(Nq - q->n < n && !cons->closed)
-			vtSleep(q->full);
+			rsleep(&q->full);
 		w = Nq - q->w;
 		if(w < n){
 			memmove(&q->q[q->w], buf, w);
@@ -109,8 +108,8 @@
 			memmove(&q->q[q->w], buf, n);
 		q->w = (q->w + n) % Nq;
 		q->n += n;
-		vtWakeup(q->empty);
-		vtUnlock(q->lock);
+		rwakeup(&q->empty);
+		qunlock(&q->lock);
 	}
 	consClose(cons);
 }
@@ -123,15 +122,15 @@
 	char buf[Nq];
 	int lastn, n, r;
 
-	vtThreadSetName("consO");
+	threadsetname("consO");
 
 	cons = v;
 	q = cons->oq;
-	vtLock(q->lock);
+	qlock(&q->lock);
 	lastn = 0;
 	for(;;){
 		while(lastn == q->n && !cons->closed)
-			vtSleep(q->empty);
+			rsleep(&q->empty);
 		if((n = q->n - lastn) > Nq)
 			n = Nq;
 		if(n > q->w){
@@ -142,11 +141,11 @@
 		else
 			memmove(buf, &q->q[q->w - n], n);
 		lastn = q->n;
-		vtUnlock(q->lock);
+		qunlock(&q->lock);
 		if(cons->closed || write(cons->fd, buf, n) < 0)
 			break;
-		vtLock(q->lock);
-		vtWakeup(q->empty);
+		qlock(&q->lock);
+		rwakeup(&q->empty);
 	}
 	consClose(cons);
 }
@@ -156,8 +155,7 @@
 {
 	Cons *cons;
 
-	cons = vtMemAllocZ(sizeof(Cons));
-	cons->lock = vtLockAlloc();
+	cons = vtmallocz(sizeof(Cons));
 	cons->fd = fd;
 	cons->srvfd = srvfd;
 	cons->ctlfd = ctlfd;
@@ -165,20 +163,20 @@
 	cons->oq = console.oq;
 	console.nopens++;
 
-	vtLock(cons->lock);
+	qlock(&cons->lock);
 	cons->ref = 2;
 	cons->closed = 0;
-	if(vtThread(consOProc, cons) < 0){
+	if(proccreate(consOProc, cons, STACK) < 0){
 		cons->ref--;
-		vtUnlock(cons->lock);
+		qunlock(&cons->lock);
 		consClose(cons);
 		return 0;
 	}
-	vtUnlock(cons->lock);
+	qunlock(&cons->lock);
 
 	if(ctlfd >= 0)
 		consIProc(cons);
-	else if(vtThread(consIProc, cons) < 0){
+	else if(proccreate(consIProc, cons, STACK) < 0){
 		consClose(cons);
 		return 0;
 	}
@@ -191,7 +189,7 @@
 {
 	int w;
 
-	vtLock(q->lock);
+	qlock(&q->lock);
 	if(n > Nq - q->w){
 		w = Nq - q->w;
 		memmove(&q->q[q->w], p, w);
@@ -203,8 +201,8 @@
 		q->w += n;
 	}
 	q->n += n;
-	vtWakeup(q->empty);
-	vtUnlock(q->lock);
+	rwakeup(&q->empty);
+	qunlock(&q->lock);
 
 	return n;
 }
@@ -214,10 +212,9 @@
 {
 	Q *q;
 
-	q = vtMemAllocZ(sizeof(Q));
-	q->lock = vtLockAlloc();
-	q->full = vtRendezAlloc(q->lock);
-	q->empty = vtRendezAlloc(q->lock);
+	q = vtmallocz(sizeof(Q));
+	q->full.l = &q->lock;
+	q->empty.l = &q->lock;
 	q->n = q->r = q->w = 0;
 
 	return q;
@@ -232,14 +229,14 @@
 	char procname[64];
 
 	snprint(procname, sizeof procname, "cons %s", currfsysname);
-	vtThreadSetName(procname);
+	threadsetname(procname);
 
 	q = console.iq;
 	qWrite(console.oq, console.prompt, console.np);
-	vtLock(q->lock);
+	qlock(&q->lock);
 	for(;;){
 		while((n = q->n) == 0)
-			vtSleep(q->empty);
+			rsleep(&q->empty);
 		r = Nq - q->r;
 		if(r < n){
 			memmove(buf, &q->q[q->r], r);
@@ -249,8 +246,8 @@
 			memmove(buf, &q->q[q->r], n);
 		q->r = (q->r + n) % Nq;
 		q->n -= n;
-		vtWakeup(q->full);
-		vtUnlock(q->lock);
+		rwakeup(&q->full);
+		qunlock(&q->lock);
 
 		for(i = 0; i < n; i++){
 			switch(buf[i]){
@@ -281,7 +278,7 @@
 				break;
 			case '\027':				/* ^W */
 				console.l[console.nl] = '\0';
-				wbuf = vtMemAlloc(console.nl+1);
+				wbuf = vtmalloc(console.nl+1);
 				memmove(wbuf, console.l, console.nl+1);
 				argc = tokenize(wbuf, argv, nelem(argv));
 				if(argc > 0)
@@ -291,7 +288,7 @@
 				for(i = 0; i < argc; i++)
 					lp += sprint(lp, "%q ", argv[i]);
 				console.nl = lp - console.l;
-				vtMemFree(wbuf);
+				vtfree(wbuf);
 				qWrite(console.oq, "^W\n", 3);
 				if(console.nl == 0)
 					break;
@@ -311,7 +308,7 @@
 			qWrite(console.oq, console.prompt, console.np);
 		}
 
-		vtLock(q->lock);
+		qlock(&q->lock);
 	}
 }
 
@@ -333,9 +330,9 @@
 	if(prompt == nil)
 		prompt = "prompt";
 
-	vtMemFree(console.prompt);
+	vtfree(console.prompt);
 	console.np = snprint(buf, sizeof(buf), "%s: ", prompt);
-	console.prompt = vtStrDup(buf);
+	console.prompt = vtstrdup(buf);
 
 	return console.np;
 }
@@ -350,7 +347,7 @@
 	if((fd = open(name, ORDWR)) < 0){
 		name = "#c/cons";
 		if((fd = open(name, ORDWR)) < 0){
-			vtSetError("consTTY: open %s: %r", name);
+			werrstr("consTTY: open %s: %r", name);
 			return 0;
 		}
 	}
@@ -358,14 +355,14 @@
 	p = smprint("%sctl", name);
 	if((ctl = open(p, OWRITE)) < 0){
 		close(fd);
-		vtSetError("consTTY: open %s: %r", p);
+		werrstr("consTTY: open %s: %r", p);
 		free(p);
 		return 0;
 	}
 	if(write(ctl, "rawon", 5) < 0){
 		close(ctl);
 		close(fd);
-		vtSetError("consTTY: write %s: %r", p);
+		werrstr("consTTY: write %s: %r", p);
 		free(p);
 		return 0;
 	}
@@ -389,8 +386,8 @@
 
 	consPrompt(nil);
 
-	if(vtThread(consProc, nil) < 0){
-		vtFatal("can't start console proc");
+	if(proccreate(consProc, nil, STACK) < 0){
+		sysfatal("can't start console proc");
 		return 0;
 	}
 
diff --git a/src/cmd/fossil/archive.c b/src/cmd/fossil/archive.c
index fc09e71..e862f70 100644
--- a/src/cmd/fossil/archive.c
+++ b/src/cmd/fossil/archive.c
@@ -20,29 +20,28 @@
 	uint diskSize;
 	Cache *c;
 	Fs *fs;
-	VtSession *z;
+	VtConn *z;
 
-	VtLock *lk;
-	VtRendez *starve;
-	VtRendez *die;
+	QLock lk;
+	Rendez starve;
+	Rendez die;
 };
 
 Arch *
-archInit(Cache *c, Disk *disk, Fs *fs, VtSession *z)
+archInit(Cache *c, Disk *disk, Fs *fs, VtConn *z)
 {
 	Arch *a;
 
-	a = vtMemAllocZ(sizeof(Arch));
+	a = vtmallocz(sizeof(Arch));
 
 	a->c = c;
 	a->z = z;
 	a->fs = fs;
 	a->blockSize = diskBlockSize(disk);
-	a->lk = vtLockAlloc();
-	a->starve = vtRendezAlloc(a->lk);
+	a->starve.l = &a->lk;
 
 	a->ref = 2;
-	vtThread(archThread, a);
+	proccreate(archThread, a, STACK);
 
 	return a;
 }
@@ -51,16 +50,13 @@
 archFree(Arch *a)
 {
 	/* kill slave */
-	vtLock(a->lk);
-	a->die = vtRendezAlloc(a->lk);
-	vtWakeup(a->starve);
+	qlock(&a->lk);
+	a->die.l = &a->lk;
+	rwakeup(&a->starve);
 	while(a->ref > 1)
-		vtSleep(a->die);
-	vtUnlock(a->lk);
-	vtRendezFree(a->starve);
-	vtRendezFree(a->die);
-	vtLockFree(a->lk);
-	vtMemFree(a);
+		rsleep(&a->die);
+	qunlock(&a->lk);
+	vtfree(a);
 }
 
 static int
@@ -71,21 +67,21 @@
 
 	if(DEBUG > 1)
 		fprint(2, "ventiSend: sending %#ux %L to venti\n", b->addr, &b->l);
-	n = vtZeroTruncate(vtType[b->l.type], data, a->blockSize);
+	n = vtzerotruncate(vtType[b->l.type], data, a->blockSize);
 	if(DEBUG > 1)
 		fprint(2, "ventiSend: truncate %d to %d\n", a->blockSize, n);
-	if(!vtWrite(a->z, score, vtType[b->l.type], data, n)){
-		fprint(2, "ventiSend: vtWrite block %#ux failed: %R\n", b->addr);
+	if(vtwrite(a->z, score, vtType[b->l.type], data, n) < 0){
+		fprint(2, "ventiSend: vtwrite block %#ux failed: %r\n", b->addr);
 		return 0;
 	}
-	if(!vtSha1Check(score, data, n)){
+	if(vtsha1check(score, data, n) < 0){
 		uchar score2[VtScoreSize];
-		vtSha1(score2, data, n);
-		fprint(2, "ventiSend: vtWrite block %#ux failed vtSha1Check %V %V\n",
+		vtsha1(score2, data, n);
+		fprint(2, "ventiSend: vtwrite block %#ux failed vtsha1check %V %V\n",
 			b->addr, score, score2);
 		return 0;
 	}
-	if(!vtSync(a->z))
+	if(vtsync(a->z) < 0)
 		return 0;
 	return 1;
 }
@@ -129,7 +125,7 @@
 static void
 shaBlock(uchar score[VtScoreSize], Block *b, uchar *data, uint bsize)
 {
-	vtSha1(score, data, vtZeroTruncate(vtType[b->l.type], data, bsize));
+	vtsha1(score, data, vtzerotruncate(vtType[b->l.type], data, bsize));
 }
 
 static uint
@@ -137,7 +133,7 @@
 {
 	uint t;
 
-	if(e->flags&VtEntryDir)
+	if(e->flags&_VtEntryDir)
 		t = BtDir;
 	else
 		t = BtData;
@@ -149,7 +145,7 @@
 {
 	uchar *data;
 
-	data = vtMemAlloc(blockSize);
+	data = vtmalloc(blockSize);
 	if(data == nil)
 		return nil;
 	memmove(data, b->data, blockSize);
@@ -183,15 +179,17 @@
 	Label l;
 	Entry *e;
 	WalkPtr w;
+	char err[ERRMAX];
 
 	p->nvisit++;
 
 	b = cacheLocalData(p->c, addr, type, tag, OReadWrite,0);
 	if(b == nil){
-		fprint(2, "archive(%ud, %#ux): cannot find block: %R\n", p->snapEpoch, addr);
-		if(strcmp(vtGetError(), ELabelMismatch) == 0){
+		fprint(2, "archive(%ud, %#ux): cannot find block: %r\n", p->snapEpoch, addr);
+		rerrstr(err, sizeof err);
+		if(strcmp(err, ELabelMismatch) == 0){
 			/* might as well plod on so we write _something_ to Venti */
-			memmove(p->score, vtZeroScore, VtScoreSize);
+			memmove(p->score, vtzeroscore, VtScoreSize);
 			return ArchFaked;
 		}
 		return ArchFailure;
@@ -221,7 +219,7 @@
 						}
 						w.data = data;
 					}
-					memmove(e->score, vtZeroScore, VtScoreSize);
+					memmove(e->score, vtzeroscore, VtScoreSize);
 					e->depth = 0;
 					e->size = 0;
 					e->tag = 0;
@@ -239,15 +237,15 @@
 				p->dsize= e->dsize;
 				p->psize = e->psize;
 			}
-			vtUnlock(b->lk);
+			qunlock(&b->lk);
 			x = archWalk(p, addr, type, tag);
-			vtLock(b->lk);
+			qlock(&b->lk);
 			if(e){
 				p->dsize = dsize;
 				p->psize = psize;
 			}
 			while(b->iostate != BioClean && b->iostate != BioDirty)
-				vtSleep(b->ioready);
+				rsleep(&b->ioready);
 			switch(x){
 			case ArchFailure:
 				fprint(2, "archWalk %#ux failed; ptr is in %#ux offset %d\n",
@@ -331,7 +329,7 @@
 	p->l = b->l;
 Out:
 	if(data != b->data)
-		vtMemFree(data);
+		vtfree(data);
 	p->depth--;
 	blockPut(b);
 	return ret;
@@ -349,15 +347,15 @@
 	uchar rbuf[VtRootSize];
 	VtRoot root;
 
-	vtThreadSetName("arch");
+	threadsetname("arch");
 
 	for(;;){
 		/* look for work */
-		vtLock(a->fs->elk);
+		wlock(&a->fs->elk);
 		b = superGet(a->c, &super);
 		if(b == nil){
-			vtUnlock(a->fs->elk);
-			fprint(2, "archThread: superGet: %R\n");
+			wunlock(&a->fs->elk);
+			fprint(2, "archThread: superGet: %r\n");
 			sleep(60*1000);
 			continue;
 		}
@@ -370,15 +368,15 @@
 		}else
 			addr = super.current;
 		blockPut(b);
-		vtUnlock(a->fs->elk);
+		wunlock(&a->fs->elk);
 
 		if(addr == NilBlock){
 			/* wait for work */
-			vtLock(a->lk);
-			vtSleep(a->starve);
-			if(a->die != nil)
+			qlock(&a->lk);
+			rsleep(&a->starve);
+			if(a->die.l != nil)
 				goto Done;
-			vtUnlock(a->lk);
+			qunlock(&a->lk);
 			continue;
 		}
 
@@ -396,7 +394,7 @@
 		default:
 			abort();
 		case ArchFailure:
-			fprint(2, "archiveBlock %#ux: %R\n", addr);
+			fprint(2, "archiveBlock %#ux: %r\n", addr);
 			sleep(60*1000);
 			continue;
 		case ArchSuccess:
@@ -414,26 +412,25 @@
 
 		/* tie up vac root */
 		memset(&root, 0, sizeof root);
-		root.version = VtRootVersion;
 		strecpy(root.type, root.type+sizeof root.type, "vac");
 		strecpy(root.name, root.name+sizeof root.name, "fossil");
 		memmove(root.score, p.score, VtScoreSize);
 		memmove(root.prev, super.last, VtScoreSize);
-		root.blockSize = a->blockSize;
-		vtRootPack(&root, rbuf);
-		if(!vtWrite(a->z, p.score, VtRootType, rbuf, VtRootSize)
-		|| !vtSha1Check(p.score, rbuf, VtRootSize)){
-			fprint(2, "vtWriteBlock %#ux: %R\n", addr);
+		root.blocksize = a->blockSize;
+		vtrootpack(&root, rbuf);
+		if(vtwrite(a->z, p.score, VtRootType, rbuf, VtRootSize) < 0
+		|| vtsha1check(p.score, rbuf, VtRootSize) < 0){
+			fprint(2, "vtWriteBlock %#ux: %r\n", addr);
 			sleep(60*1000);
 			continue;
 		}
 
 		/* record success */
-		vtLock(a->fs->elk);
+		wlock(&a->fs->elk);
 		b = superGet(a->c, &super);
 		if(b == nil){
-			vtUnlock(a->fs->elk);
-			fprint(2, "archThread: superGet: %R\n");
+			wunlock(&a->fs->elk);
+			fprint(2, "archThread: superGet: %r\n");
 			sleep(60*1000);
 			continue;
 		}
@@ -442,15 +439,15 @@
 		superPack(&super, b->data);
 		blockDirty(b);
 		blockPut(b);
-		vtUnlock(a->fs->elk);
+		wunlock(&a->fs->elk);
 
 		consPrint("archive vac:%V\n", p.score);
 	}
 
 Done:
 	a->ref--;
-	vtWakeup(a->die);
-	vtUnlock(a->lk);
+	rwakeup(&a->die);
+	qunlock(&a->lk);
 }
 
 void
@@ -460,7 +457,7 @@
 		fprint(2, "warning: archKick nil\n");
 		return;
 	}
-	vtLock(a->lk);
-	vtWakeup(a->starve);
-	vtUnlock(a->lk);
+	qlock(&a->lk);
+	rwakeup(&a->starve);
+	qunlock(&a->lk);
 }
diff --git a/src/cmd/fossil/bwatch.c b/src/cmd/fossil/bwatch.c
index 51deb76..8cd0956 100644
--- a/src/cmd/fossil/bwatch.c
+++ b/src/cmd/fossil/bwatch.c
@@ -44,7 +44,7 @@
 
 struct WMap
 {
-	VtLock *lk;
+	QLock lk;
 
 	WEntry *hchild[HashSize];
 	WEntry *hparent[HashSize];
@@ -84,7 +84,7 @@
 
 	w = pool;
 	if(w == nil){
-		w = vtMemAllocZ(1024*sizeof(WEntry));
+		w = vtmallocz(1024*sizeof(WEntry));
 		for(i=0; i<1024; i++)
 			freeWEntry(&w[i]);
 		w = pool;
@@ -195,16 +195,15 @@
 void
 bwatchReset(uchar score[VtScoreSize])
 {
-	vtLock(map.lk);
+	qlock(&map.lk);
 	_bwatchResetParent(score);
 	_bwatchResetChild(score);
-	vtUnlock(map.lk);
+	qunlock(&map.lk);
 }
 
 void
 bwatchInit(void)
 {
-	map.lk = vtLockAlloc();
 	wp = privalloc();
 	*wp = nil;
 }
@@ -222,7 +221,7 @@
 
 	w = *wp;
 	if(w == nil || w->pid != getpid()){
-		w = vtMemAllocZ(sizeof(WThread));
+		w = vtmallocz(sizeof(WThread));
 		*wp = w;
 		w->pid = getpid();
 	}
@@ -241,7 +240,7 @@
 	if(bwatchDisabled)
 		return;
 
-	vtLock(map.lk);
+	qlock(&map.lk);
 	_bwatchResetParent(b->score);
 
 	switch(b->l.type){
@@ -264,7 +263,7 @@
 			addChild(b->score, b->data+i*VtScoreSize, i);
 		break;
 	}
-	vtUnlock(map.lk);
+	qunlock(&map.lk);
 }
 
 static int
@@ -376,7 +375,7 @@
 	if(b->part != PartData)
 		return;
 
-	vtLock(map.lk);
+	qlock(&map.lk);
 	w = getWThread();
 	for(i=0; i<w->nb; i++){
 		if(lockConflicts(w->b[i]->score, b->score)){
@@ -385,7 +384,7 @@
 			stop();
 		}
 	}
-	vtUnlock(map.lk);
+	qunlock(&map.lk);
 	if(w->nb >= MaxLock){
 		fprint(2, "%d: too many blocks held\n", w->pid);
 		stop();
diff --git a/src/cmd/fossil/cache.c b/src/cmd/fossil/cache.c
index e812f6b..f473d21 100644
--- a/src/cmd/fossil/cache.c
+++ b/src/cmd/fossil/cache.c
@@ -21,14 +21,14 @@
 
 struct Cache
 {
-	VtLock	*lk;
+	QLock	lk;
 	int 	ref;
 	int	mode;
 
 	Disk 	*disk;
 	int	size;			/* block size */
 	int	ndmap;		/* size of per-block dirty pointer map used in blockWrite */
-	VtSession *z;
+	VtConn *z;
 	u32int	now;			/* ticks for usage timestamps */
 	Block	**heads;		/* hash table for finding address */
 	int	nheap;			/* number of available victims */
@@ -38,7 +38,7 @@
 	u8int	*mem;			/* memory for all block data & blists */
 
 	BList	*blfree;
-	VtRendez *blrend;
+	Rendez	blrend;
 
 	int 	ndirty;			/* number of dirty blocks in the cache */
 	int 	maxdirty;		/* max number of dirty blocks */
@@ -48,11 +48,11 @@
 
 	FreeList *fl;
 
-	VtRendez *die;			/* daemon threads should die when != nil */
+	Rendez die;			/* daemon threads should die when QLock != nil */
 
-	VtRendez *flush;
-	VtRendez *flushwait;
-	VtRendez *heapwait;
+	Rendez flush;
+	Rendez flushwait;
+	Rendez heapwait;
 	BAddr *baddr;
 	int bw, br, be;
 	int nflush;
@@ -62,7 +62,7 @@
 	/* unlink daemon */
 	BList *uhead;
 	BList *utail;
-	VtRendez *unlink;
+	Rendez unlink;
 
 	/* block counts */
 	int nused;
@@ -95,7 +95,7 @@
 };
 
 struct FreeList {
-	VtLock *lk;
+	QLock lk;
 	u32int last;		/* last block allocated */
 	u32int end;		/* end of data partition */
 	u32int nused;		/* number of used blocks */
@@ -123,28 +123,28 @@
  */
 int vtType[BtMax] = {
 	VtDataType,		/* BtData | 0  */
-	VtPointerType0,		/* BtData | 1  */
-	VtPointerType1,		/* BtData | 2  */
-	VtPointerType2,		/* BtData | 3  */
-	VtPointerType3,		/* BtData | 4  */
-	VtPointerType4,		/* BtData | 5  */
-	VtPointerType5,		/* BtData | 6  */
-	VtPointerType6,		/* BtData | 7  */
+	VtDataType+1,		/* BtData | 1  */
+	VtDataType+2,		/* BtData | 2  */
+	VtDataType+3,		/* BtData | 3  */
+	VtDataType+4,		/* BtData | 4  */
+	VtDataType+5,		/* BtData | 5  */
+	VtDataType+6,		/* BtData | 6  */
+	VtDataType+7,		/* BtData | 7  */
 	VtDirType,		/* BtDir | 0  */
-	VtPointerType0,		/* BtDir | 1  */
-	VtPointerType1,		/* BtDir | 2  */
-	VtPointerType2,		/* BtDir | 3  */
-	VtPointerType3,		/* BtDir | 4  */
-	VtPointerType4,		/* BtDir | 5  */
-	VtPointerType5,		/* BtDir | 6  */
-	VtPointerType6,		/* BtDir | 7  */
+	VtDirType+1,		/* BtDir | 1  */
+	VtDirType+2,		/* BtDir | 2  */
+	VtDirType+3,		/* BtDir | 3  */
+	VtDirType+4,		/* BtDir | 4  */
+	VtDirType+5,		/* BtDir | 5  */
+	VtDirType+6,		/* BtDir | 6  */
+	VtDirType+7,		/* BtDir | 7  */
 };
 
 /*
  * Allocate the memory cache.
  */
 Cache *
-cacheAlloc(Disk *disk, VtSession *z, ulong nblocks, int mode)
+cacheAlloc(Disk *disk, VtConn *z, ulong nblocks, int mode)
 {
 	int i;
 	Cache *c;
@@ -153,12 +153,11 @@
 	u8int *p;
 	int nbl;
 
-	c = vtMemAllocZ(sizeof(Cache));
+	c = vtmallocz(sizeof(Cache));
 
 	/* reasonable number of BList elements */
 	nbl = nblocks * 4;
 
-	c->lk = vtLockAlloc();
 	c->ref = 1;
 	c->disk = disk;
 	c->z = z;
@@ -169,21 +168,20 @@
 	c->ndmap = (c->size/20 + 7) / 8;
 	c->nblocks = nblocks;
 	c->hashSize = nblocks;
-	c->heads = vtMemAllocZ(c->hashSize*sizeof(Block*));
-	c->heap = vtMemAllocZ(nblocks*sizeof(Block*));
-	c->blocks = vtMemAllocZ(nblocks*sizeof(Block));
-	c->mem = vtMemAllocZ(nblocks * (c->size + c->ndmap) + nbl * sizeof(BList));
-	c->baddr = vtMemAllocZ(nblocks * sizeof(BAddr));
+	c->heads = vtmallocz(c->hashSize*sizeof(Block*));
+	c->heap = vtmallocz(nblocks*sizeof(Block*));
+	c->blocks = vtmallocz(nblocks*sizeof(Block));
+	c->mem = vtmallocz(nblocks * (c->size + c->ndmap) + nbl * sizeof(BList));
+	c->baddr = vtmallocz(nblocks * sizeof(BAddr));
 	c->mode = mode;
 	c->vers++;
 	p = c->mem;
 	for(i = 0; i < nblocks; i++){
 		b = &c->blocks[i];
-		b->lk = vtLockAlloc();
 		b->c = c;
 		b->data = p;
 		b->heap = i;
-		b->ioready = vtRendezAlloc(b->lk);
+		b->ioready.l = &b->lk;
 		c->heap[i] = b;
 		p += c->size;
 	}
@@ -201,22 +199,22 @@
 		p += c->ndmap;
 	}
 
-	c->blrend = vtRendezAlloc(c->lk);
+	c->blrend.l = &c->lk;
 
 	c->maxdirty = nblocks*(DirtyPercentage*0.01);
 
 	c->fl = flAlloc(diskSize(disk, PartData));
 
-	c->unlink = vtRendezAlloc(c->lk);
-	c->flush = vtRendezAlloc(c->lk);
-	c->flushwait = vtRendezAlloc(c->lk);
-	c->heapwait = vtRendezAlloc(c->lk);
+	c->unlink.l = &c->lk;
+	c->flush.l = &c->lk;
+	c->flushwait.l = &c->lk;
+	c->heapwait.l = &c->lk;
 	c->sync = periodicAlloc(cacheSync, c, 30*1000);
 
 	if(mode == OReadWrite){
 		c->ref += 2;
-		vtThread(unlinkThread, c);
-		vtThread(flushThread, c);
+		proccreate(unlinkThread, c, STACK);
+		proccreate(flushThread, c, STACK);
 	}
 	cacheCheck(c);
 
@@ -232,42 +230,38 @@
 	int i;
 
 	/* kill off daemon threads */
-	vtLock(c->lk);
-	c->die = vtRendezAlloc(c->lk);
+	qlock(&c->lk);
+	c->die.l = &c->lk;
 	periodicKill(c->sync);
-	vtWakeup(c->flush);
-	vtWakeup(c->unlink);
+	rwakeup(&c->flush);
+	rwakeup(&c->unlink);
 	while(c->ref > 1)
-		vtSleep(c->die);
+		rsleep(&c->die);
 
 	/* flush everything out */
 	do {
 		unlinkBody(c);
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		while(cacheFlushBlock(c))
 			;
 		diskFlush(c->disk);
-		vtLock(c->lk);
+		qlock(&c->lk);
 	} while(c->uhead || c->ndirty);
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 
 	cacheCheck(c);
 
 	for(i = 0; i < c->nblocks; i++){
 		assert(c->blocks[i].ref == 0);
-		vtRendezFree(c->blocks[i].ioready);
-		vtLockFree(c->blocks[i].lk);
 	}
 	flFree(c->fl);
-	vtMemFree(c->baddr);
-	vtMemFree(c->heads);
-	vtMemFree(c->blocks);
-	vtMemFree(c->mem);
-	vtLockFree(c->lk);
+	vtfree(c->baddr);
+	vtfree(c->heads);
+	vtfree(c->blocks);
+	vtfree(c->mem);
 	diskFree(c->disk);
-	vtRendezFree(c->blrend);
 	/* don't close vtSession */
-	vtMemFree(c);
+	vtfree(c);
 }
 
 static void
@@ -297,22 +291,22 @@
 
 	for(i = 0; i < c->nheap; i++){
 		if(c->heap[i]->heap != i)
-			vtFatal("mis-heaped at %d: %d", i, c->heap[i]->heap);
+			sysfatal("mis-heaped at %d: %d", i, c->heap[i]->heap);
 		if(i > 0 && c->heap[(i - 1) >> 1]->used - now > c->heap[i]->used - now)
-			vtFatal("bad heap ordering");
+			sysfatal("bad heap ordering");
 		k = (i << 1) + 1;
 		if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
-			vtFatal("bad heap ordering");
+			sysfatal("bad heap ordering");
 		k++;
 		if(k < c->nheap && c->heap[i]->used - now > c->heap[k]->used - now)
-			vtFatal("bad heap ordering");
+			sysfatal("bad heap ordering");
 	}
 
 	refed = 0;
 	for(i = 0; i < c->nblocks; i++){
 		b = &c->blocks[i];
 		if(b->data != &c->mem[i * size])
-			vtFatal("mis-blocked at %d", i);
+			sysfatal("mis-blocked at %d", i);
 		if(b->ref && b->heap == BadHeap){
 			refed++;
 		}
@@ -352,8 +346,8 @@
 	printed = 0;
 	if(c->nheap == 0){
 		while(c->nheap == 0){
-			vtWakeup(c->flush);
-			vtSleep(c->heapwait);
+			rwakeup(&c->flush);
+			rsleep(&c->heapwait);
 			if(c->nheap == 0){
 				printed = 1;
 				fprint(2, "%s: entire cache is busy, %d dirty "
@@ -414,27 +408,27 @@
 	/*
 	 * look for the block in the cache
 	 */
-	vtLock(c->lk);
+	qlock(&c->lk);
 	for(b = c->heads[h]; b != nil; b = b->next){
 		if(b->part == part && b->addr == addr)
 			break;
 	}
 	if(b == nil || b->vers != vers){
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		return nil;
 	}
-	if(!waitlock && !vtCanLock(b->lk)){
+	if(!waitlock && !canqlock(&b->lk)){
 		*lockfailure = 1;
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		return nil;
 	}
 	heapDel(b);
 	b->ref++;
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 
 	bwatchLock(b);
 	if(waitlock)
-		vtLock(b->lk);
+		qlock(&b->lk);
 	b->nlock = 1;
 
 	for(;;){
@@ -452,15 +446,15 @@
 			return b;
 		case BioReading:
 		case BioWriting:
-			vtSleep(b->ioready);
+			rsleep(&b->ioready);
 			break;
 		case BioVentiError:
 			blockPut(b);
-			vtSetError("venti i/o error block 0x%.8ux", addr);
+			werrstr("venti i/o error block 0x%.8ux", addr);
 			return nil;
 		case BioReadError:
 			blockPut(b);
-			vtSetError("error reading block 0x%.8ux", addr);
+			werrstr("error reading block 0x%.8ux", addr);
 			return nil;
 		}
 	}
@@ -490,14 +484,14 @@
 	/*
 	 * look for the block in the cache
 	 */
-	vtLock(c->lk);
+	qlock(&c->lk);
 	for(b = c->heads[h]; b != nil; b = b->next){
 		if(b->part != part || b->addr != addr)
 			continue;
 		if(epoch && b->l.epoch != epoch){
 fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
-			vtUnlock(c->lk);
-			vtSetError(ELabelMismatch);
+			qunlock(&c->lk);
+			werrstr(ELabelMismatch);
 			return nil;
 		}
 		heapDel(b);
@@ -520,7 +514,7 @@
 		b->prev = &c->heads[h];
 	}
 
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 
 	/*
 	 * BUG: what if the epoch changes right here?
@@ -534,7 +528,7 @@
 
 if(0)fprint(2, "%s: cacheLocal: %d: %d %x\n", argv0, getpid(), b->part, b->addr);
 	bwatchLock(b);
-	vtLock(b->lk);
+	qlock(&b->lk);
 	b->nlock = 1;
 
 	if(part == PartData && b->iostate == BioEmpty){
@@ -547,7 +541,7 @@
 	if(epoch && b->l.epoch != epoch){
 		blockPut(b);
 fprint(2, "%s: _cacheLocal want epoch %ud got %ud\n", argv0, epoch, b->l.epoch);
-		vtSetError(ELabelMismatch);
+		werrstr(ELabelMismatch);
 		return nil;
 	}
 
@@ -566,19 +560,19 @@
 			/* fall through */
 		case BioEmpty:
 			diskRead(c->disk, b);
-			vtSleep(b->ioready);
+			rsleep(&b->ioready);
 			break;
 		case BioClean:
 		case BioDirty:
 			return b;
 		case BioReading:
 		case BioWriting:
-			vtSleep(b->ioready);
+			rsleep(&b->ioready);
 			break;
 		case BioReadError:
 			blockSetIOState(b, BioEmpty);
 			blockPut(b);
-			vtSetError("error reading block 0x%.8ux", addr);
+			werrstr("error reading block 0x%.8ux", addr);
 			return nil;
 		}
 	}
@@ -607,7 +601,7 @@
 	if(b->l.type != type || b->l.tag != tag){
 		fprint(2, "%s: cacheLocalData: addr=%d type got %d exp %d: tag got %ux exp %ux\n",
 			argv0, addr, b->l.type, type, b->l.tag, tag);
-		vtSetError(ELabelMismatch);
+		werrstr(ELabelMismatch);
 		blockPut(b);
 		return nil;
 	}
@@ -641,7 +635,7 @@
 	/*
 	 * look for the block in the cache
 	 */
-	vtLock(c->lk);
+	qlock(&c->lk);
 	for(b = c->heads[h]; b != nil; b = b->next){
 		if(b->part != PartVenti || memcmp(b->score, score, VtScoreSize) != 0 || b->l.type != type)
 			continue;
@@ -667,10 +661,10 @@
 			b->next->prev = &b->next;
 		b->prev = &c->heads[h];
 	}
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 
 	bwatchLock(b);
-	vtLock(b->lk);
+	qlock(&b->lk);
 	b->nlock = 1;
 	b->pc = getcallerpc(&c);
 
@@ -678,27 +672,27 @@
 	default:
 		abort();
 	case BioEmpty:
-		n = vtRead(c->z, score, vtType[type], b->data, c->size);
-		if(n < 0 || !vtSha1Check(score, b->data, n)){
+		n = vtread(c->z, score, vtType[type], b->data, c->size);
+		if(n < 0 || vtsha1check(score, b->data, n) < 0){
 			blockSetIOState(b, BioVentiError);
 			blockPut(b);
-			vtSetError(
+			werrstr(
 			"venti error reading block %V or wrong score: %r",
 				score);
 			return nil;
 		}
-		vtZeroExtend(vtType[type], b->data, n, c->size);
+		vtzeroextend(vtType[type], b->data, n, c->size);
 		blockSetIOState(b, BioClean);
 		return b;
 	case BioClean:
 		return b;
 	case BioVentiError:
 		blockPut(b);
-		vtSetError("venti i/o error or wrong score, block %V", score);
+		werrstr("venti i/o error or wrong score, block %V", score);
 		return nil;
 	case BioReadError:
 		blockPut(b);
-		vtSetError("error reading block %V", b->score);
+		werrstr("error reading block %V", b->score);
 		return nil;
 	}
 	/* NOT REACHED */
@@ -722,12 +716,12 @@
 	n = c->size / LabelSize;
 	fl = c->fl;
 
-	vtLock(fl->lk);
+	qlock(&fl->lk);
 	addr = fl->last;
 	b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
 	if(b == nil){
-		fprint(2, "%s: cacheAllocBlock: xxx %R\n", argv0);
-		vtUnlock(fl->lk);
+		fprint(2, "%s: cacheAllocBlock: xxx %r\n", argv0);
+		qunlock(&fl->lk);
 		return nil;
 	}
 	nwrap = 0;
@@ -736,16 +730,16 @@
 			addr = 0;
 			if(++nwrap >= 2){
 				blockPut(b);
-				vtSetError("disk is full");
+				werrstr("disk is full");
 				/*
 				 * try to avoid a continuous spew of console
 				 * messages.
 				 */
 				if (fl->last != 0)
-					fprint(2, "%s: cacheAllocBlock: xxx1 %R\n",
+					fprint(2, "%s: cacheAllocBlock: xxx1 %r\n",
 						argv0);
 				fl->last = 0;
-				vtUnlock(fl->lk);
+				qunlock(&fl->lk);
 				return nil;
 			}
 		}
@@ -754,8 +748,8 @@
 			b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
 			if(b == nil){
 				fl->last = addr;
-				fprint(2, "%s: cacheAllocBlock: xxx2 %R\n", argv0);
-				vtUnlock(fl->lk);
+				fprint(2, "%s: cacheAllocBlock: xxx2 %r\n", argv0);
+				qunlock(&fl->lk);
 				return nil;
 			}
 		}
@@ -771,7 +765,7 @@
 	blockPut(b);
 	b = cacheLocal(c, PartData, addr, OOverWrite);
 	if(b == nil){
-		fprint(2, "%s: cacheAllocBlock: xxx3 %R\n", argv0);
+		fprint(2, "%s: cacheAllocBlock: xxx3 %r\n", argv0);
 		return nil;
 	}
 assert(b->iostate == BioLabel || b->iostate == BioClean);
@@ -782,17 +776,17 @@
 	lab.epoch = epoch;
 	lab.epochClose = ~(u32int)0;
 	if(!blockSetLabel(b, &lab, 1)){
-		fprint(2, "%s: cacheAllocBlock: xxx4 %R\n", argv0);
+		fprint(2, "%s: cacheAllocBlock: xxx4 %r\n", argv0);
 		blockPut(b);
 		return nil;
 	}
-	vtZeroExtend(vtType[type], b->data, 0, c->size);
+	vtzeroextend(vtType[type], b->data, 0, c->size);
 if(0)diskWrite(c->disk, b);
 
 if(0)fprint(2, "%s: fsAlloc %ud type=%d tag = %ux\n", argv0, addr, type, tag);
 	lastAlloc = addr;
 	fl->nused++;
-	vtUnlock(fl->lk);
+	qunlock(&fl->lk);
 	b->pc = getcallerpc(&c);
 	return b;
 }
@@ -815,11 +809,11 @@
 	fl = c->fl;
 	n = c->size / LabelSize;
 	*bsize = c->size;
-	vtLock(fl->lk);
+	qlock(&fl->lk);
 	if(fl->epochLow == epochLow){
 		*used = fl->nused;
 		*total = fl->end;
-		vtUnlock(fl->lk);
+		qunlock(&fl->lk);
 		return;
 	}
 	b = nil;
@@ -829,7 +823,7 @@
 			blockPut(b);
 			b = cacheLocal(c, PartLabel, addr/n, OReadOnly);
 			if(b == nil){
-				fprint(2, "%s: flCountUsed: loading %ux: %R\n",
+				fprint(2, "%s: flCountUsed: loading %ux: %r\n",
 					argv0, addr/n);
 				break;
 			}
@@ -850,7 +844,7 @@
 	}
 	*used = nused;
 	*total = fl->end;
-	vtUnlock(fl->lk);
+	qunlock(&fl->lk);
 	return;
 }
 
@@ -859,8 +853,7 @@
 {
 	FreeList *fl;
 
-	fl = vtMemAllocZ(sizeof(*fl));
-	fl->lk = vtLockAlloc();
+	fl = vtmallocz(sizeof(*fl));
 	fl->last = 0;
 	fl->end = end;
 	return fl;
@@ -869,8 +862,7 @@
 static void
 flFree(FreeList *fl)
 {
-	vtLockFree(fl->lk);
-	vtMemFree(fl);
+	vtfree(fl);
 }
 
 u32int
@@ -914,8 +906,8 @@
 
 	/*
 	 * b->nlock should probably stay at zero while
-	 * the block is unlocked, but diskThread and vtSleep
-	 * conspire to assume that they can just vtLock(b->lk); blockPut(b),
+	 * the block is unlocked, but diskThread and rsleep
+	 * conspire to assume that they can just qlock(&b->lk); blockPut(b),
 	 * so we have to keep b->nlock set to 1 even
 	 * when the block is unlocked.
 	 */
@@ -924,12 +916,12 @@
 //	b->pc = 0;
 
 	bwatchUnlock(b);
-	vtUnlock(b->lk);
+	qunlock(&b->lk);
 	c = b->c;
-	vtLock(c->lk);
+	qlock(&c->lk);
 
 	if(--b->ref > 0){
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		return;
 	}
 
@@ -950,7 +942,7 @@
 	case BioDirty:
 		break;
 	}
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 }
 
 /*
@@ -1098,12 +1090,12 @@
 		return 1;
 	assert(b->iostate == BioClean || b->iostate == BioLabel);
 
-	vtLock(c->lk);
+	qlock(&c->lk);
 	b->iostate = BioDirty;
 	c->ndirty++;
 	if(c->ndirty > (c->maxdirty>>1))
-		vtWakeup(c->flush);
-	vtUnlock(c->lk);
+		rwakeup(&c->flush);
+	qunlock(&c->lk);
 
 	return 1;
 }
@@ -1288,7 +1280,7 @@
 		 * queue to the cache unlink queue.
 		 */
 		if(b->iostate == BioDirty || b->iostate == BioWriting){
-			vtLock(c->lk);
+			qlock(&c->lk);
 			c->ndirty--;
 			b->iostate = iostate;	/* change here to keep in sync with ndirty */
 			b->vers = c->vers++;
@@ -1296,13 +1288,13 @@
 				/* add unlink blocks to unlink queue */
 				if(c->uhead == nil){
 					c->uhead = b->uhead;
-					vtWakeup(c->unlink);
+					rwakeup(&c->unlink);
 				}else
 					c->utail->next = b->uhead;
 				c->utail = b->utail;
 				b->uhead = nil;
 			}
-			vtUnlock(c->lk);
+			qunlock(&c->lk);
 		}
 		assert(!b->uhead);
 		dowakeup = 1;
@@ -1313,9 +1305,9 @@
 		 * Bump a version count, leave it dirty.
 		 */
 		if(b->iostate == BioWriting){
-			vtLock(c->lk);
+			qlock(&c->lk);
 			b->vers = c->vers++;
-			vtUnlock(c->lk);
+			qunlock(&c->lk);
 			dowakeup = 1;
 		}
 		break;
@@ -1327,9 +1319,9 @@
 		 * This is here because we need to lock c->lk to
 		 * manipulate the ref count.
 		 */
-		vtLock(c->lk);
+		qlock(&c->lk);
 		b->ref++;
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		break;
 	case BioReadError:
 	case BioVentiError:
@@ -1344,7 +1336,7 @@
 	 * Now that the state has changed, we can wake the waiters.
 	 */
 	if(dowakeup)
-		vtWakeupAll(b->ioready);
+		rwakeupall(&b->ioready);
 }
 
 /*
@@ -1571,11 +1563,11 @@
 	l.state |= BsClosed;
 	l.epochClose = p->epoch;
 	if(l.epochClose == l.epoch){
-		vtLock(c->fl->lk);
+		qlock(&c->fl->lk);
 		if(l.epoch == c->fl->epochLow)
 			c->fl->nused--;
 		blockSetLabel(b, &l, 0);
-		vtUnlock(c->fl->lk);
+		qunlock(&c->fl->lk);
 	}else
 		blockSetLabel(b, &l, 0);
 	blockPut(b);
@@ -1603,7 +1595,7 @@
 	}
 
 	c = b->c;
-	vtLock(c->lk);
+	qlock(&c->lk);
 	if(c->blfree == nil){
 		/*
 		 * No free BLists.  What are our options?
@@ -1611,7 +1603,7 @@
 	
 		/* Block has no priors? Just write it. */
 		if(b->prior == nil){
-			vtUnlock(c->lk);
+			qunlock(&c->lk);
 			diskWriteAndWait(c->disk, b);
 			return nil;
 		}
@@ -1629,8 +1621,8 @@
 		 * so it can't deadlock like we can.)
 		 */
 		while(c->blfree == nil){
-			vtWakeup(c->flush);
-			vtSleep(c->blrend);
+			rwakeup(&c->flush);
+			rsleep(&c->blrend);
 			if(c->blfree == nil)
 				fprint(2, "%s: flushing for blists\n", argv0);
 		}
@@ -1638,18 +1630,18 @@
 
 	p = c->blfree;
 	c->blfree = p->next;
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 	return p;
 }
 
 static void
 blistFree(Cache *c, BList *bl)
 {
-	vtLock(c->lk);
+	qlock(&c->lk);
 	bl->next = c->blfree;
 	c->blfree = bl;
-	vtWakeup(c->blrend);
-	vtUnlock(c->lk);
+	rwakeup(&c->blrend);
+	qunlock(&c->lk);
 }
 
 char*
@@ -1843,7 +1835,7 @@
 {
 	assert(b->heap == BadHeap);
 	upHeap(b->c->nheap++, b);
-	vtWakeup(b->c->heapwait);
+	rwakeup(&b->c->heapwait);
 }
 
 /*
@@ -1884,9 +1876,9 @@
 	while(c->uhead != nil){
 		p = c->uhead;
 		c->uhead = p->next;
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		doRemoveLink(c, p);
-		vtLock(c->lk);
+		qlock(&c->lk);
 		p->next = c->blfree;
 		c->blfree = p;
 	}
@@ -1900,19 +1892,19 @@
 {
 	Cache *c = a;
 
-	vtThreadSetName("unlink");
+	threadsetname("unlink");
 
-	vtLock(c->lk);
+	qlock(&c->lk);
 	for(;;){
-		while(c->uhead == nil && c->die == nil)
-			vtSleep(c->unlink);
-		if(c->die != nil)
+		while(c->uhead == nil && c->die.l == nil)
+			rsleep(&c->unlink);
+		if(c->die.l != nil)
 			break;
 		unlinkBody(c);
 	}
 	c->ref--;
-	vtWakeup(c->die);
-	vtUnlock(c->lk);
+	rwakeup(&c->die);
+	qunlock(&c->lk);
 }
 
 static int
@@ -1943,9 +1935,9 @@
 	BAddr *p;
 	Block *b;
 
-	vtLock(c->lk);
+	qlock(&c->lk);
 	if(c->ndirty == 0){
-		vtUnlock(c->lk);
+		qunlock(&c->lk);
 		return;
 	}
 
@@ -1969,7 +1961,7 @@
 			argv0, c->ndirty, ndirty);
 		c->ndirty = ndirty;
 	}
-	vtUnlock(c->lk);
+	qunlock(&c->lk);
 
 	c->bw = p - c->baddr;
 	qsort(c->baddr, c->bw, sizeof(BAddr), baddrCmp);
@@ -2043,11 +2035,11 @@
 	Cache *c = a;
 	int i;
 
-	vtThreadSetName("flush");
-	vtLock(c->lk);
-	while(c->die == nil){
-		vtSleep(c->flush);
-		vtUnlock(c->lk);
+	threadsetname("flush");
+	qlock(&c->lk);
+	while(c->die.l == nil){
+		rsleep(&c->flush);
+		qunlock(&c->lk);
 		for(i=0; i<FlushSize; i++)
 			if(!cacheFlushBlock(c)){
 				/*
@@ -2073,12 +2065,12 @@
 			 */
 			sleep(100);
 		}
-		vtLock(c->lk);
-		vtWakeupAll(c->flushwait);
+		qlock(&c->lk);
+		rwakeupall(&c->flushwait);
 	}
 	c->ref--;
-	vtWakeup(c->die);
-	vtUnlock(c->lk);
+	rwakeup(&c->die);
+	qunlock(&c->lk);
 }
 
 /*
@@ -2087,18 +2079,18 @@
 void
 cacheFlush(Cache *c, int wait)
 {
-	vtLock(c->lk);
+	qlock(&c->lk);
 	if(wait){
 		while(c->ndirty){
 		//	consPrint("cacheFlush: %d dirty blocks, uhead %p\n",
 		//		c->ndirty, c->uhead);
-			vtWakeup(c->flush);
-			vtSleep(c->flushwait);
+			rwakeup(&c->flush);
+			rsleep(&c->flushwait);
 		}
 	//	consPrint("cacheFlush: done (uhead %p)\n", c->ndirty, c->uhead);
 	}else if(c->ndirty)
-		vtWakeup(c->flush);
-	vtUnlock(c->lk);
+		rwakeup(&c->flush);
+	qunlock(&c->lk);
 }
 
 /*
diff --git a/src/cmd/fossil/check.c b/src/cmd/fossil/check.c
index 03ece44..88c3661 100644
--- a/src/cmd/fossil/check.c
+++ b/src/cmd/fossil/check.c
@@ -61,7 +61,7 @@
 	checkInit(chk);
 	b = superGet(chk->cache, &super);
 	if(b == nil){
-		chk->print("could not load super block: %R");
+		chk->print("could not load super block: %r");
 		return;
 	}
 	blockPut(b);
@@ -69,9 +69,9 @@
 	chk->hint = super.active;
 	checkEpochs(chk);
 
-	chk->smap = vtMemAllocZ(chk->nblocks/8+1);
+	chk->smap = vtmallocz(chk->nblocks/8+1);
 	checkDirs(chk);
-	vtMemFree(chk->smap);
+	vtfree(chk->smap);
 }
 
 static void checkEpoch(Fsck*, u32int);
@@ -87,10 +87,10 @@
 	uint nb;
 
 	nb = chk->nblocks;
-	chk->amap = vtMemAllocZ(nb/8+1);
-	chk->emap = vtMemAllocZ(nb/8+1);
-	chk->xmap = vtMemAllocZ(nb/8+1);
-	chk->errmap = vtMemAllocZ(nb/8+1);
+	chk->amap = vtmallocz(nb/8+1);
+	chk->emap = vtmallocz(nb/8+1);
+	chk->xmap = vtmallocz(nb/8+1);
+	chk->errmap = vtmallocz(nb/8+1);
 
 	for(e = chk->fs->ehi; e >= chk->fs->elo; e--){
 		memset(chk->emap, 0, chk->nblocks/8+1);
@@ -98,10 +98,10 @@
 		checkEpoch(chk, e);
 	}
 	checkLeak(chk);
-	vtMemFree(chk->amap);
-	vtMemFree(chk->emap);
-	vtMemFree(chk->xmap);
-	vtMemFree(chk->errmap);
+	vtfree(chk->amap);
+	vtfree(chk->emap);
+	vtfree(chk->xmap);
+	vtfree(chk->errmap);
 }
 
 static void
@@ -131,7 +131,7 @@
 	a = (a+chk->hint)%chk->nblocks;
 	b = cacheLocalData(chk->cache, a, BtDir, RootTag, OReadOnly, 0);
 	if(b == nil){
-		error(chk, "could not read root block 0x%.8#ux: %R", a);
+		error(chk, "could not read root block 0x%.8#ux: %r", a);
 		return;
 	}
 
@@ -146,7 +146,7 @@
 	 * just a convenience to help the search.
 	 */
 	if(!entryUnpack(&e, b->data, 0)){
-		error(chk, "could not unpack root block 0x%.8#ux: %R", a);
+		error(chk, "could not unpack root block 0x%.8#ux: %r", a);
 		blockPut(b);
 		return;
 	}
@@ -186,7 +186,7 @@
 
 	bb = cacheGlobal(chk->cache, score, type, tag, OReadOnly);
 	if(bb == nil){
-		error(chk, "could not load block %V type %d tag %ux: %R",
+		error(chk, "could not load block %V type %d tag %ux: %r",
 			score, type, tag);
 		chk->walkdepth--;
 		return 0;
@@ -284,7 +284,7 @@
 	case BtDir:
 		for(i = 0; i < chk->bsize/VtEntrySize; i++){
 			if(!entryUnpack(&e, bb->data, i)){
-				// error(chk, "walk: could not unpack entry: %ux[%d]: %R",
+				// error(chk, "walk: could not unpack entry: %ux[%d]: %r",
 				//	addr, i);
 				setBit(chk->errmap, bb->addr);
 				chk->clre(chk, bb, i);
@@ -360,7 +360,7 @@
 
 	for(a = 0; a < chk->nblocks; a++){
 		if(!readLabel(chk->cache, &l, a)){
-			error(chk, "could not read label: addr 0x%ux %d %d: %R",
+			error(chk, "could not read label: addr 0x%ux %d %d: %r",
 				a, l.type, l.state);
 			continue;
 		}
@@ -416,7 +416,7 @@
 
 	r = sourceOpen(s, offset, OReadOnly, 0);
 	if(r == nil){
-		warn(chk, "could not open source: %s -> %d: %R", name, offset);
+		warn(chk, "could not open source: %s -> %d: %r", name, offset);
 		goto Err;
 	}
 
@@ -469,7 +469,7 @@
 	int oo, o, n, i;
 	uchar *p;
 
-	mc = vtMemAlloc(mb->nindex*sizeof(MetaChunk));
+	mc = vtmalloc(mb->nindex*sizeof(MetaChunk));
 	p = mb->buf + MetaHeaderSize;
 	for(i = 0; i < mb->nindex; i++){
 		mc[i].offset = p[0]<<8 | p[1];
@@ -494,7 +494,7 @@
 	if(o+n > mb->size || mb->size - oo != mb->free)
 		goto Err;
 
-	vtMemFree(mc);
+	vtfree(mc);
 	return 1;
 
 Err:
@@ -509,7 +509,7 @@
 	fprint(2, "\tused=%d size=%d free=%d free2=%d\n",
 		oo, mb->size, mb->free, mb->size - oo);
 }
-	vtMemFree(mc);
+	vtfree(mc);
 	return 0;
 }
 
@@ -571,11 +571,11 @@
 		return;
 
 	if(!sourceLock2(source, meta, OReadOnly)){
-		warn(chk, "could not lock sources for %s: %R", name);
+		warn(chk, "could not lock sources for %s: %r", name);
 		return;
 	}
 	if(!sourceGetEntry(source, &e1) || !sourceGetEntry(meta, &e2)){
-		warn(chk, "could not load entries for %s: %R", name);
+		warn(chk, "could not load entries for %s: %r", name);
 		return;
 	}
 	a1 = globalToLocal(e1.score);
@@ -589,13 +589,13 @@
 	setBit(chk->smap, a1);
 	setBit(chk->smap, a2);
 
-	bm = vtMemAllocZ(sourceGetDirSize(source)/8 + 1);
+	bm = vtmallocz(sourceGetDirSize(source)/8 + 1);
 
 	nb = (sourceGetSize(meta) + meta->dsize - 1)/meta->dsize;
 	for(o = 0; o < nb; o++){
 		b = sourceBlock(meta, o, OReadOnly);
 		if(b == nil){
-			error(chk, "could not read block in meta file: %s[%ud]: %R",
+			error(chk, "could not read block in meta file: %s[%ud]: %r",
 				name, o);
 			continue;
 		}
@@ -606,13 +606,13 @@
 				b->addr, name);
 
 		if(!mbUnpack(&mb, b->data, meta->dsize)){
-			error(chk, "could not unpack meta block: %s[%ud]: %R",
+			error(chk, "could not unpack meta block: %s[%ud]: %r",
 				name, o);
 			blockPut(b);
 			continue;
 		}
 		if(!chkMetaBlock(&mb)){
-			error(chk, "bad meta block: %s[%ud]: %R", name, o);
+			error(chk, "bad meta block: %s[%ud]: %r", name, o);
 			blockPut(b);
 			continue;
 		}
@@ -621,7 +621,7 @@
 			meUnpack(&me, &mb, i);
 			if(!deUnpack(&de, &me)){
 				error(chk,
-				  "could not unpack dir entry: %s[%ud][%d]: %R",
+				  "could not unpack dir entry: %s[%ud][%d]: %r",
 					name, o, i);
 				continue;
 			}
@@ -629,8 +629,8 @@
 				error(chk,
 			   "dir entry out of order: %s[%ud][%d] = %s last = %s",
 					name, o, i, de.elem, s);
-			vtMemFree(s);
-			s = vtStrDup(de.elem);
+			vtfree(s);
+			s = vtstrdup(de.elem);
 			nn = smprint("%s/%s", name, de.elem);
 			if(nn == nil){
 				error(chk, "out of memory");
@@ -684,7 +684,7 @@
 			deCleanup(&de);
 
 		}
-		vtMemFree(s);
+		vtfree(s);
 		blockPut(b);
 	}
 
@@ -710,7 +710,7 @@
 
 	sourceUnlock(source);
 	sourceUnlock(meta);
-	vtMemFree(bm);
+	vtfree(bm);
 }
 
 static void
@@ -760,7 +760,7 @@
 	chk->print("error: %s\n", buf);
 
 //	if(nerr++ > 20)
-//		vtFatal("too many errors");
+//		sysfatal("too many errors");
 }
 
 static void
diff --git a/src/cmd/fossil/dat.h b/src/cmd/fossil/dat.h
index 9c9a570..d01dedb 100644
--- a/src/cmd/fossil/dat.h
+++ b/src/cmd/fossil/dat.h
@@ -37,7 +37,6 @@
 	Nowaitlock,
 	Waitlock,
 
-	NilBlock	= (~0UL),
 	MaxBlock	= (1UL<<31),
 };
 
@@ -79,7 +78,7 @@
 	int	mode;		/* immutable */
 	int	noatimeupd;	/* immutable */
 	int	blockSize;	/* immutable */
-	VtSession *z;		/* immutable */
+	VtConn *z;		/* immutable */
 	Snap	*snap;		/* immutable */
 	/* immutable; copy here & Fsys to ease error reporting */
 	char	*name;
@@ -94,7 +93,7 @@
 	 * Deletion and creation of snapshots occurs under a write lock of elk,
 	 * ensuring no file operations are occurring concurrently.
 	 */
-	VtLock	*elk;		/* epoch lock */
+	RWLock	elk;		/* epoch lock */
 	u32int	ehi;		/* epoch high */
 	u32int	elo;		/* epoch low */
 
@@ -136,7 +135,7 @@
 	Source	*parent;	/* immutable */
 	File	*file;		/* immutable; point back */
 
-	VtLock	*lk;
+	QLock	lk;
 	int	ref;
 	/*
 	 * epoch for the source
@@ -233,7 +232,7 @@
 	int	nlock;
 	uintptr	pc;		/* pc that fetched this block from the cache */
 
-	VtLock	*lk;
+	QLock	lk;
 
 	int 	part;
 	u32int	addr;
@@ -261,7 +260,7 @@
 
 	Block	*ionext;
 	int	iostate;
-	VtRendez *ioready;
+	Rendez	ioready;
 };
 
 /* tree walker, for gc and archiver */
diff --git a/src/cmd/fossil/disk.c b/src/cmd/fossil/disk.c
index 3ae43fb..8491a4b 100644
--- a/src/cmd/fossil/disk.c
+++ b/src/cmd/fossil/disk.c
@@ -15,16 +15,16 @@
 };
 
 struct Disk {
-	VtLock *lk;
+	QLock lk;
 	int ref;
 
 	int fd;
 	Header h;
 
-	VtRendez *flow;
-	VtRendez *starve;
-	VtRendez *flush;
-	VtRendez *die;
+	Rendez flow;
+	Rendez starve;
+	Rendez flush;
+	Rendez die;
 
 	int nqueue;
 
@@ -49,25 +49,23 @@
 	Disk *disk;
 
 	if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize){
-		vtSetError("short read: %r");
-		vtOSError();
+		werrstr("short read: %r");
 		return nil;
 	}
 
 	if(!headerUnpack(&h, buf)){
-		vtSetError("bad disk header");
+		werrstr("bad disk header");
 		return nil;
 	}
-	disk = vtMemAllocZ(sizeof(Disk));
-	disk->lk = vtLockAlloc();
-	disk->starve = vtRendezAlloc(disk->lk);
-	disk->flow = vtRendezAlloc(disk->lk);
-	disk->flush = vtRendezAlloc(disk->lk);
+	disk = vtmallocz(sizeof(Disk));
+	disk->starve.l = &disk->lk;
+	disk->flow.l = &disk->lk;
+	disk->flush.l = &disk->lk;
 	disk->fd = fd;
 	disk->h = h;
 
 	disk->ref = 2;
-	vtThread(diskThread, disk);
+	proccreate(diskThread, disk, STACK);
 
 	return disk;
 }
@@ -78,18 +76,14 @@
 	diskFlush(disk);
 
 	/* kill slave */
-	vtLock(disk->lk);
-	disk->die = vtRendezAlloc(disk->lk);
-	vtWakeup(disk->starve);
+	qlock(&disk->lk);
+	disk->die.l = &disk->lk;
+	rwakeup(&disk->starve);
 	while(disk->ref > 1)
-		vtSleep(disk->die);
-	vtUnlock(disk->lk);
-	vtRendezFree(disk->flow);
-	vtRendezFree(disk->starve);
-	vtRendezFree(disk->die);
-	vtLockFree(disk->lk);
+		rsleep(&disk->die);
+	qunlock(&disk->lk);
 	close(disk->fd);
-	vtMemFree(disk);
+	vtfree(disk);
 }
 
 static u32int
@@ -134,7 +128,7 @@
 	end = partEnd(disk, part);
 
 	if(addr >= end-start){
-		vtSetError(EBadAddr);
+		werrstr(EBadAddr);
 		return 0;
 	}
 
@@ -143,11 +137,11 @@
 	while(n > 0){
 		nn = pread(disk->fd, buf, n, offset);
 		if(nn < 0){
-			vtOSError();
+			werrstr("%r");
 			return 0;
 		}
 		if(nn == 0){
-			vtSetError("eof reading disk");
+			werrstr("eof reading disk");
 			return 0;
 		}
 		n -= nn;
@@ -168,18 +162,18 @@
 	end = partEnd(disk, part);
 
 	if(addr >= end - start){
-		vtSetError(EBadAddr);
+		werrstr(EBadAddr);
 		return 0;
 	}
 
 	offset = ((u64int)(addr + start))*disk->h.blockSize;
 	n = pwrite(disk->fd, buf, disk->h.blockSize, offset);
 	if(n < 0){
-		vtOSError();
+		werrstr("%r");
 		return 0;
 	}
 	if(n < disk->h.blockSize) {
-		vtSetError("short write");
+		werrstr("short write");
 		return 0;
 	}
 
@@ -191,9 +185,9 @@
 {
 	Block **bp, *bb;
 
-	vtLock(disk->lk);
+	qlock(&disk->lk);
 	while(disk->nqueue >= QueueSize)
-		vtSleep(disk->flow);
+		rsleep(&disk->flow);
 	if(disk->cur == nil || b->addr > disk->cur->addr)
 		bp = &disk->cur;
 	else
@@ -207,9 +201,9 @@
 	b->ionext = bb;
 	*bp = b;
 	if(disk->nqueue == 0)
-		vtWakeup(disk->starve);
+		rwakeup(&disk->starve);
 	disk->nqueue++;
-	vtUnlock(disk->lk);
+	qunlock(&disk->lk);
 }
 
 
@@ -238,7 +232,7 @@
 	/*
 	 * If b->nlock > 1, the block is aliased within
 	 * a single thread.  That thread is us.
-	 * DiskWrite does some funny stuff with VtLock
+	 * DiskWrite does some funny stuff with QLock
 	 * and blockPut that basically assumes b->nlock==1.
 	 * We humor diskWrite by temporarily setting
 	 * nlock to 1.  This needs to be revisited.
@@ -248,7 +242,7 @@
 		b->nlock = 1;
 	diskWrite(disk, b);
 	while(b->iostate != BioClean)
-		vtSleep(b->ioready);
+		rsleep(&b->ioready);
 	b->nlock = nlock;
 }
 
@@ -263,15 +257,15 @@
 {
 	Dir dir;
 
-	vtLock(disk->lk);
+	qlock(&disk->lk);
 	while(disk->nqueue > 0)
-		vtSleep(disk->flush);
-	vtUnlock(disk->lk);
+		rsleep(&disk->flush);
+	qunlock(&disk->lk);
 
 	/* there really should be a cleaner interface to flush an fd */
 	nulldir(&dir);
 	if(dirfwstat(disk->fd, &dir) < 0){
-		vtOSError();
+		werrstr("%r");
 		return 0;
 	}
 	return 1;
@@ -308,13 +302,13 @@
 	double t;
 	int nio;
 
-	vtThreadSetName("disk");
+	threadsetname("disk");
 
 //fprint(2, "diskThread %d\n", getpid());
 
-	buf = vtMemAlloc(disk->h.blockSize);
+	buf = vtmalloc(disk->h.blockSize);
 
-	vtLock(disk->lk);
+	qlock(&disk->lk);
 	if (Timing) {
 		nio = 0;
 		t = -nsec();
@@ -330,9 +324,9 @@
 					t = 0;
 				}
 			}
-			if(disk->die != nil)
+			if(disk->die.l != nil)
 				goto Done;
-			vtSleep(disk->starve);
+			rsleep(&disk->starve);
 			if (Timing)
 				t -= nsec();
 		}
@@ -344,7 +338,7 @@
 		}
 		b = disk->cur;
 		disk->cur = b->ionext;
-		vtUnlock(disk->lk);
+		qunlock(&disk->lk);
 
 		/*
 		 * no one should hold onto blocking in the
@@ -353,7 +347,7 @@
 		 */
 if(0)fprint(2, "fossil: diskThread: %d:%d %x\n", getpid(), b->part, b->addr);
 		bwatchLock(b);
-		vtLock(b->lk);
+		qlock(&b->lk);
 		b->pc = mypc(0);
 		assert(b->nlock == 1);
 		switch(b->iostate){
@@ -388,19 +382,19 @@
 		}
 
 		blockPut(b);		/* remove extra reference, unlock */
-		vtLock(disk->lk);
+		qlock(&disk->lk);
 		disk->nqueue--;
 		if(disk->nqueue == QueueSize-1)
-			vtWakeup(disk->flow);
+			rwakeup(&disk->flow);
 		if(disk->nqueue == 0)
-			vtWakeup(disk->flush);
+			rwakeup(&disk->flush);
 		if(Timing)
 			nio++;
 	}
 Done:
 //fprint(2, "diskThread done\n");
 	disk->ref--;
-	vtWakeup(disk->die);
-	vtUnlock(disk->lk);
-	vtMemFree(buf);
+	rwakeup(&disk->die);
+	qunlock(&disk->lk);
+	vtfree(buf);
 }
diff --git a/src/cmd/fossil/epoch.c b/src/cmd/fossil/epoch.c
index 6aa73bb..cce53f1 100644
--- a/src/cmd/fossil/epoch.c
+++ b/src/cmd/fossil/epoch.c
@@ -8,11 +8,11 @@
 usage(void)
 {
 	fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
-	exits("usage");
+	threadexitsall("usage");
 }
 
 void
-main(int argc, char **argv)
+threadmain(int argc, char **argv)
 {
 	int fd;
 	Header h;
@@ -47,5 +47,5 @@
 		if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
 			sysfatal("writing super block: %r");
 	}
-	exits(0);
+	threadexitsall(0);
 }
diff --git a/src/cmd/fossil/file.c b/src/cmd/fossil/file.c
index 5566df3..3c94cdb 100644
--- a/src/cmd/fossil/file.c
+++ b/src/cmd/fossil/file.c
@@ -26,7 +26,7 @@
 	File	*next;		/* sibling */
 
 	/* data for file */
-	VtLock	*lk;		/* lock for the following */
+	RWLock	lk;		/* lock for the following */
 	Source	*source;
 	Source	*msource;	/* for directories: meta data for children */
 	File	*down;		/* children */
@@ -51,8 +51,7 @@
 {
 	File *f;
 
-	f = vtMemAllocZ(sizeof(File));
-	f->lk = vtLockAlloc();
+	f = vtmallocz(sizeof(File));
 	f->ref = 1;
 	f->fs = fs;
 	f->boff = NilBlock;
@@ -64,12 +63,11 @@
 fileFree(File *f)
 {
 	sourceClose(f->source);
-	vtLockFree(f->lk);
 	sourceClose(f->msource);
 	deCleanup(&f->dir);
 
 	memset(f, ~0, sizeof(File));
-	vtMemFree(f);
+	vtfree(f);
 }
 
 /*
@@ -115,7 +113,7 @@
 		blockPut(b);
 		b = nil;
 	}
-	vtSetError(ENoFile);
+	werrstr(ENoFile);
 	/* fall through */
 Err:
 	sourceUnlock(meta);
@@ -216,7 +214,7 @@
 	if(r == nil)
 		return nil;
 	if(r->gen != gen){
-		vtSetError(ERemoved);
+		werrstr(ERemoved);
 		goto Err;
 	}
 	if(r->dir != dir && r->mode != -1){
@@ -229,7 +227,7 @@
 		free(rname);
 		free(fname);
 
-		vtSetError(EBadMeta);
+		werrstr(EBadMeta);
 		goto Err;
 	}
 	return r;
@@ -246,12 +244,12 @@
 	fileRAccess(f);
 
 	if(elem[0] == 0){
-		vtSetError(EBadPath);
+		werrstr(EBadPath);
 		return nil;
 	}
 
 	if(!fileIsDir(f)){
-		vtSetError(ENotDir);
+		werrstr(ENotDir);
 		return nil;
 	}
 
@@ -347,14 +345,14 @@
 		n = p - path;
 		if(n > 0){
 			if(n > VtMaxStringSize){
-				vtSetError("%s: element too long", EBadPath);
+				werrstr("%s: element too long", EBadPath);
 				goto Err;
 			}
 			memmove(elem, path, n);
 			elem[n] = 0;
 			ff = _fileWalk(f, elem, partial && *p=='\0');
 			if(ff == nil){
-				vtSetError("%.*s: %R", utfnlen(opath, p-opath),
+				werrstr("%.*s: %r", utfnlen(opath, p-opath),
 					opath);
 				goto Err;
 			}
@@ -422,20 +420,20 @@
 	for(ff = f->down; ff; ff=ff->next){
 		if(strcmp(elem, ff->dir.elem) == 0 && !ff->removed){
 			ff = nil;
-			vtSetError(EExists);
+			werrstr(EExists);
 			goto Err1;
 		}
 	}
 
 	ff = dirLookup(f, elem);
 	if(ff != nil){
-		vtSetError(EExists);
+		werrstr(EExists);
 		goto Err1;
 	}
 
 	pr = f->source;
 	if(pr->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		goto Err1;
 	}
 
@@ -455,7 +453,7 @@
 	}
 
 	dir = &ff->dir;
-	dir->elem = vtStrDup(elem);
+	dir->elem = vtstrdup(elem);
 	dir->entry = r->offset;
 	dir->gen = r->gen;
 	if(isdir){
@@ -465,9 +463,9 @@
 	dir->size = 0;
 	if(!fsNextQid(f->fs, &dir->qid))
 		goto Err;
-	dir->uid = vtStrDup(uid);
-	dir->gid = vtStrDup(f->dir.gid);
-	dir->mid = vtStrDup(uid);
+	dir->uid = vtstrdup(uid);
+	dir->gid = vtstrdup(f->dir.gid);
+	dir->mid = vtstrdup(uid);
 	dir->mtime = time(0L);
 	dir->mcount = 0;
 	dir->ctime = dir->mtime;
@@ -541,7 +539,7 @@
 		return -1;
 
 	if(offset < 0){
-		vtSetError(EBadOffset);
+		werrstr(EBadOffset);
 		goto Err1;
 	}
 
@@ -607,12 +605,12 @@
 
 	s = nil;
 	if(f->dir.mode & ModeDir){
-		vtSetError(ENotFile);
+		werrstr(ENotFile);
 		goto Err;
 	}
 
 	if(f->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		goto Err;
 	}
 
@@ -656,11 +654,11 @@
 		return 0;
 	r = 0;
 	if(f->dir.mode & ModeDir){
-		vtSetError(ENotFile);
+		werrstr(ENotFile);
 		goto Err;
 	}
 	if(f->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		goto Err;
 	}
 	if(!sourceLock(f->source, -1))
@@ -689,16 +687,16 @@
 
 	s = nil;
 	if(f->dir.mode & ModeDir){
-		vtSetError(ENotFile);
+		werrstr(ENotFile);
 		goto Err;
 	}
 
 	if(f->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		goto Err;
 	}
 	if(offset < 0){
-		vtSetError(EBadOffset);
+		werrstr(EBadOffset);
 		goto Err;
 	}
 
@@ -773,7 +771,7 @@
 fileTruncate(File *f, char *uid)
 {
 	if(fileIsDir(f)){
-		vtSetError(ENotFile);
+		werrstr(ENotFile);
 		return 0;
 	}
 
@@ -781,7 +779,7 @@
 		return 0;
 
 	if(f->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		fileUnlock(f);
 		return 0;
 	}
@@ -812,7 +810,7 @@
 
 	/* can not set permissions for the root */
 	if(fileIsRoot(f)){
-		vtSetError(ERoot);
+		werrstr(ERoot);
 		return 0;
 	}
 
@@ -820,7 +818,7 @@
 		return 0;
 
 	if(f->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		fileUnlock(f);
 		return 0;
 	}
@@ -831,7 +829,7 @@
 	if(strcmp(f->dir.elem, dir->elem) != 0){
 		for(ff = f->up->down; ff; ff=ff->next){
 			if(strcmp(dir->elem, ff->dir.elem) == 0 && !ff->removed){
-				vtSetError(EExists);
+				werrstr(EExists);
 				goto Err;
 			}
 		}
@@ -839,7 +837,7 @@
 		ff = dirLookup(f->up, dir->elem);
 		if(ff != nil){
 			fileDecRef(ff);
-			vtSetError(EExists);
+			werrstr(EExists);
 			goto Err;
 		}
 	}
@@ -868,17 +866,17 @@
 	oelem = nil;
 	if(strcmp(f->dir.elem, dir->elem) != 0){
 		oelem = f->dir.elem;
-		f->dir.elem = vtStrDup(dir->elem);
+		f->dir.elem = vtstrdup(dir->elem);
 	}
 
 	if(strcmp(f->dir.uid, dir->uid) != 0){
-		vtMemFree(f->dir.uid);
-		f->dir.uid = vtStrDup(dir->uid);
+		vtfree(f->dir.uid);
+		f->dir.uid = vtstrdup(dir->uid);
 	}
 
 	if(strcmp(f->dir.gid, dir->gid) != 0){
-		vtMemFree(f->dir.gid);
-		f->dir.gid = vtStrDup(dir->gid);
+		vtfree(f->dir.gid);
+		f->dir.gid = vtstrdup(dir->gid);
 	}
 
 	f->dir.mtime = dir->mtime;
@@ -892,7 +890,7 @@
 //fprint(2, "->%x\n", f->dir.mode);
 
 	fileMetaFlush2(f, oelem);
-	vtMemFree(oelem);
+	vtfree(oelem);
 
 	fileMetaUnlock(f);
 	fileUnlock(f);
@@ -1025,7 +1023,7 @@
 	nkids = 0;
 	for(p=f->down; p; p=p->next)
 		nkids++;
-	kids = vtMemAlloc(nkids*sizeof(File*));
+	kids = vtmalloc(nkids*sizeof(File*));
 	i = 0;
 	for(p=f->down; p; p=p->next){
 		kids[i++] = p;
@@ -1037,7 +1035,7 @@
 		rv |= fileMetaFlush(kids[i], 1);
 		fileDecRef(kids[i]);
 	}
-	vtMemFree(kids);
+	vtfree(kids);
 	return rv;
 }
 
@@ -1204,7 +1202,7 @@
 		if(!mbUnpack(&mb, b->data, r->dsize))
 			goto Err;
 		if(mb.nindex > 0){
-			vtSetError(ENotEmpty);
+			werrstr(ENotEmpty);
 			goto Err;
 		}
 		blockPut(b);
@@ -1222,7 +1220,7 @@
 
 	/* can not remove the root */
 	if(fileIsRoot(f)){
-		vtSetError(ERoot);
+		werrstr(ERoot);
 		return 0;
 	}
 
@@ -1230,7 +1228,7 @@
 		return 0;
 
 	if(f->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		goto Err1;
 	}
 	if(!sourceLock2(f->source, f->msource, -1))
@@ -1273,7 +1271,7 @@
 	if(f == nil)
 		return 0;
 	if(f->up->source->mode != OReadWrite){
-		vtSetError(EReadOnly);
+		werrstr(EReadOnly);
 		fileDecRef(f);
 		return 0;
 	}
@@ -1359,7 +1357,7 @@
 	File *p;
 
 	if(!fileIsDir(f)){
-		vtSetError(ENotDir);
+		werrstr(ENotDir);
 		fileDecRef(f);
 		return nil;
 	}
@@ -1371,7 +1369,7 @@
 		fileMetaFlush2(p, nil);
 	fileUnlock(f);
 
-	dee = vtMemAllocZ(sizeof(DirEntryEnum));
+	dee = vtmallocz(sizeof(DirEntryEnum));
 	dee->file = fileIncRef(f);
 
 	return dee;
@@ -1422,7 +1420,7 @@
 	/* clean up first */
 	for(i=dee->i; i<dee->n; i++)
 		deCleanup(dee->buf+i);
-	vtMemFree(dee->buf);
+	vtfree(dee->buf);
 	dee->buf = nil;
 	dee->i = 0;
 	dee->n = 0;
@@ -1439,7 +1437,7 @@
 		goto Err;
 
 	n = mb.nindex;
-	dee->buf = vtMemAlloc(n * sizeof(DirEntry));
+	dee->buf = vtmalloc(n * sizeof(DirEntry));
 
 	for(i=0; i<n; i++){
 		de = dee->buf + i;
@@ -1467,7 +1465,7 @@
 	u32int nb;
 
 	if(dee == nil){
-		vtSetError("cannot happen in deeRead");
+		werrstr("cannot happen in deeRead");
 		return -1;
 	}
 
@@ -1517,9 +1515,9 @@
 		return;
 	for(i=dee->i; i<dee->n; i++)
 		deCleanup(dee->buf+i);
-	vtMemFree(dee->buf);
+	vtfree(dee->buf);
 	fileDecRef(dee->file);
-	vtMemFree(dee);
+	vtfree(dee);
 }
 
 /*
@@ -1574,7 +1572,7 @@
 		/* mbAlloc might have changed block */
 		mbPack(&mb);
 		blockDirty(b);
-		vtSetError(EBadMeta);
+		werrstr(EBadMeta);
 		goto Err;
 	}
 
@@ -1617,7 +1615,7 @@
 		return 1;
 
 	if(f->source == nil || (f->dir.mode & ModeDir) && f->msource == nil){
-		vtSetError(ERemoved);
+		werrstr(ERemoved);
 		return 0;
 	}
 	return 1;
@@ -1626,8 +1624,8 @@
 static int
 fileRLock(File *f)
 {
-	assert(!vtCanLock(f->fs->elk));
-	vtRLock(f->lk);
+	assert(!canwlock(&f->fs->elk));
+	rlock(&f->lk);
 	if(!chkSource(f)){
 		fileRUnlock(f);
 		return 0;
@@ -1638,14 +1636,14 @@
 static void
 fileRUnlock(File *f)
 {
-	vtRUnlock(f->lk);
+	runlock(&f->lk);
 }
 
 static int
 fileLock(File *f)
 {
-	assert(!vtCanLock(f->fs->elk));
-	vtLock(f->lk);
+	assert(!canwlock(&f->fs->elk));
+	wlock(&f->lk);
 	if(!chkSource(f)){
 		fileUnlock(f);
 		return 0;
@@ -1656,7 +1654,7 @@
 static void
 fileUnlock(File *f)
 {
-	vtUnlock(f->lk);
+	wunlock(&f->lk);
 }
 
 /*
@@ -1670,14 +1668,14 @@
 if(f->up == nil)
 fprint(2, "f->elem = %s\n", f->dir.elem);
 	assert(f->up != nil);
-	assert(!vtCanLock(f->fs->elk));
-	vtLock(f->up->lk);
+	assert(!canwlock(&f->fs->elk));
+	wlock(&f->up->lk);
 }
 
 static void
 fileMetaUnlock(File *f)
 {
-	vtUnlock(f->up->lk);
+	wunlock(&f->up->lk);
 }
 
 /*
@@ -1709,8 +1707,8 @@
 	fileMetaLock(f);
 	f->dir.atime = f->dir.mtime = time(0L);
 	if(strcmp(f->dir.mid, mid) != 0){
-		vtMemFree(f->dir.mid);
-		f->dir.mid = vtStrDup(mid);
+		vtfree(f->dir.mid);
+		f->dir.mid = vtstrdup(mid);
 	}
 	f->dir.mcount++;
 	f->dirty = 1;
@@ -1842,11 +1840,11 @@
 	static char root[] = "/";
 
 	if (f == nil)
-		return vtStrDup("/**GOK**");
+		return vtstrdup("/**GOK**");
 
 	p = fileGetParent(f);
 	if (p == f)
-		name = vtStrDup(root);
+		name = vtstrdup(root);
 	else {
 		pname = fileName(p);
 		if (strcmp(pname, root) == 0)
diff --git a/src/cmd/fossil/flchk.c b/src/cmd/fossil/flchk.c
index b19fd5b..0506c68 100644
--- a/src/cmd/fossil/flchk.c
+++ b/src/cmd/fossil/flchk.c
@@ -10,7 +10,7 @@
 usage(void)
 {
 	fprint(2, "usage: %s [-c cachesize] [-h host] file\n", argv0);
-	exits("usage");
+	threadexitsall("usage");
 }
 
 #pragma	varargck	argpos	flprint	1
@@ -52,10 +52,10 @@
 }
 
 void
-main(int argc, char *argv[])
+threadmain(int argc, char *argv[])
 {
 	int csize = 1000;
-	VtSession *z;
+	VtConn *z;
 	char *host = nil;
 	
 	fsck.useventi = 1;
@@ -82,28 +82,25 @@
 	if(argc != 1)
 		usage();
 
-	vtAttach();
-
 	fmtinstall('L', labelFmt);
 	fmtinstall('V', scoreFmt);
-	fmtinstall('R', vtErrFmt);
 
 	/*
 	 * Connect to Venti.
 	 */
-	z = vtDial(host, 0);
+	z = vtdial(host);
 	if(z == nil){
 		if(fsck.useventi)
-			vtFatal("could not connect to server: %s", vtGetError());
-	}else if(!vtConnect(z, 0))
-		vtFatal("vtConnect: %s", vtGetError());
+			sysfatal("could not connect to server: %r");
+	}else if(vtconnect(z) < 0)
+		sysfatal("vtconnect: %r");
 
 	/*
 	 * Initialize file system.
 	 */
 	fsck.fs = fsOpen(argv[0], z, csize, OReadOnly);
 	if(fsck.fs == nil)
-		vtFatal("could not open file system: %R");
+		sysfatal("could not open file system: %r");
 
 	fsck.print = flprint;
 	fsck.clre = flclre;
@@ -113,6 +110,6 @@
 
 	fsCheck(&fsck);
 
-	exits(0);
+	threadexitsall(0);
 }
 
diff --git a/src/cmd/fossil/flfmt.c b/src/cmd/fossil/flfmt.c
index 687c41e..4bb354e 100644
--- a/src/cmd/fossil/flfmt.c
+++ b/src/cmd/fossil/flfmt.c
@@ -18,7 +18,7 @@
 static void topLevel(char *name);
 static int parseScore(uchar[VtScoreSize], char*);
 static u32int ventiRoot(char*, char*);
-static VtSession *z;
+static VtConn *z;
 
 #define TWID64	((u64int)~(u64int)0)
 
@@ -46,7 +46,7 @@
 }
 
 void
-main(int argc, char *argv[])
+threadmain(int argc, char *argv[])
 {
 	int fd, force;
 	Header h;
@@ -96,28 +96,25 @@
 		usage();
 
 	if(iso9660file && score)
-		vtFatal("cannot use -i with -v");
-
-	vtAttach();
+		sysfatal("cannot use -i with -v");
 
 	fmtinstall('V', scoreFmt);
-	fmtinstall('R', vtErrFmt);
 	fmtinstall('L', labelFmt);
 
 	fd = open(argv[0], ORDWR);
 	if(fd < 0)
-		vtFatal("could not open file: %s: %r", argv[0]);
+		sysfatal("could not open file: %s: %r", argv[0]);
 
-	buf = vtMemAllocZ(bsize);
+	buf = vtmallocz(bsize);
 	if(pread(fd, buf, bsize, HeaderOffset) != bsize)
-		vtFatal("could not read fs header block: %r");
+		sysfatal("could not read fs header block: %r");
 
 	if(headerUnpack(&h, buf) && !force
 	&& !confirm("fs header block already exists; are you sure?"))
 		goto Out;
 
 	if((d = dirfstat(fd)) == nil)
-		vtFatal("dirfstat: %r");
+		sysfatal("dirfstat: %r");
 
 	if(d->type == 'M' && !force
 	&& !confirm("fs file is mounted via devmnt (is not a kernel device); are you sure?"))
@@ -126,11 +123,11 @@
 	partition(fd, bsize, &h);
 	headerPack(&h, buf);
 	if(pwrite(fd, buf, bsize, HeaderOffset) < bsize)
-		vtFatal("could not write fs header: %r");
+		sysfatal("could not write fs header: %r");
 
 	disk = diskAlloc(fd);
 	if(disk == nil)
-		vtFatal("could not open disk: %r");
+		sysfatal("could not open disk: %r");
 
 	if(iso9660file)
 		iso9660init(fd, &h, iso9660file, iso9660off);
@@ -150,15 +147,14 @@
 		root = rootInit(&e);
 	}
 
-	superInit(label, root, vtZeroScore);
+	superInit(label, root, vtzeroscore);
 	diskFree(disk);
 
 	if(score == nil)
 		topLevel(argv[0]);
 
 Out:
-	vtDetach();
-	exits(0);
+	threadexitsall(0);
 }
 
 static u64int
@@ -169,7 +165,7 @@
 
 	dir = dirfstat(fd);
 	if(dir == nil)
-		vtFatal("could not stat file: %r");
+		sysfatal("could not stat file: %r");
 	size = dir->length;
 	free(dir);
 	return size;
@@ -180,7 +176,7 @@
 {
 	fprint(2, "usage: %s [-b blocksize] [-h host] [-i file offset] "
 		"[-l label] [-v score] [-y] file\n", argv0);
-	exits("usage");
+	threadexitsall("usage");
 }
 
 static void
@@ -203,7 +199,7 @@
 
 	/* sanity check */
 	if(nblock < (HeaderOffset*10)/bsize)
-		vtFatal("file too small");
+		sysfatal("file too small");
 
 	h->super = (HeaderOffset + 2*bsize)/bsize;
 	h->label = h->super + 1;
@@ -236,7 +232,7 @@
 	e->flags = VtEntryActive;
 	e->depth = 0;
 	e->size = 0;
-	memmove(e->score, vtZeroScore, VtScoreSize);
+	memmove(e->score, vtzeroscore, VtScoreSize);
 	e->tag = tagGen();
 	e->snap = 0;
 	e->archive = 0;
@@ -252,16 +248,16 @@
 	MetaEntry me;
 
 	memset(&de, 0, sizeof(de));
-	de.elem = vtStrDup("root");
+	de.elem = vtstrdup("root");
 	de.entry = 0;
 	de.gen = 0;
 	de.mentry = 1;
 	de.mgen = 0;
 	de.size = 0;
 	de.qid = qid++;
-	de.uid = vtStrDup("adm");
-	de.gid = vtStrDup("adm");
-	de.mid = vtStrDup("adm");
+	de.uid = vtstrdup("adm");
+	de.gid = vtstrdup("adm");
+	de.mid = vtstrdup("adm");
 	de.mtime = time(0);
 	de.mcount = 0;
 	de.ctime = time(0);
@@ -306,7 +302,7 @@
 	entryPack(e, buf, 2);
 
 	entryInit(e);
-	e->flags |= VtEntryDir;
+	e->flags |= _VtEntryDir;
 	entryPack(e, buf, 0);
 
 	entryInit(e);
@@ -315,7 +311,7 @@
 	blockWrite(PartData, addr);
 
 	entryInit(e);
-	e->flags |= VtEntryLocal|VtEntryDir;
+	e->flags |= VtEntryLocal|_VtEntryDir;
  	e->size = VtEntrySize*3;
 	e->tag = tag;
 	localToGlobal(addr, e->score);
@@ -341,9 +337,9 @@
 
 	blockRead(PartLabel, addr/lpb);
 	if(!labelUnpack(&l, buf, addr % lpb))
-		vtFatal("bad label: %r");
+		sysfatal("bad label: %r");
 	if(l.state != BsFree)
-		vtFatal("want to allocate block already in use");
+		sysfatal("want to allocate block already in use");
 	l.epoch = 1;
 	l.epochClose = ~(u32int)0;
 	l.type = type;
@@ -403,14 +399,14 @@
 blockRead(int part, u32int addr)
 {
 	if(!diskReadRaw(disk, part, addr, buf))
-		vtFatal("read failed: %r");
+		sysfatal("read failed: %r");
 }
 
 static void
 blockWrite(int part, u32int addr)
 {
 	if(!diskWriteRaw(disk, part, addr, buf))
-		vtFatal("write failed: %r");
+		sysfatal("write failed: %r");
 }
 
 static void
@@ -420,7 +416,7 @@
 
 	f = fileCreate(root, name, mode | ModeDir, "adm");
 	if(f == nil)
-		vtFatal("could not create file: %s: %r", name);
+		sysfatal("could not create file: %s: %r", name);
 	fileDecRef(f);
 }
 
@@ -433,18 +429,18 @@
 	/* ok, now we can open as a fs */
 	fs = fsOpen(name, z, 100, OReadWrite);
 	if(fs == nil)
-		vtFatal("could not open file system: %r");
-	vtRLock(fs->elk);
+		sysfatal("could not open file system: %r");
+	rlock(&fs->elk);
 	root = fsGetRoot(fs);
 	if(root == nil)
-		vtFatal("could not open root: %r");
+		sysfatal("could not open root: %r");
 	addFile(root, "active", 0555);
 	addFile(root, "archive", 0555);
 	addFile(root, "snapshot", 0555);
 	fileDecRef(root);
 	if(iso9660file)
 		iso9660copy(fs);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 	fsClose(fs);
 }
 
@@ -453,10 +449,10 @@
 {
 	int n;
 
-	n = vtRead(z, score, type, buf, bsize);
+	n = vtread(z, score, type, buf, bsize);
 	if(n < 0)
-		vtFatal("ventiRead %V (%d) failed: %R", score, type);
-	vtZeroExtend(type, buf, n, bsize);
+		sysfatal("ventiRead %V (%d) failed: %r", score, type);
+	vtzeroextend(type, buf, n, bsize);
 	return n;
 }
 
@@ -473,18 +469,18 @@
 	VtRoot root;
 
 	if(!parseScore(score, s))
-		vtFatal("bad score '%s'", s);
+		sysfatal("bad score '%s'", s);
 
-	if((z = vtDial(host, 0)) == nil
-	|| !vtConnect(z, nil))
-		vtFatal("connect to venti: %R");
+	if((z = vtdial(host)) == nil
+	|| vtconnect(z) < 0)
+		sysfatal("connect to venti: %r");
 
 	tag = tagGen();
 	addr = blockAlloc(BtDir, tag);
 
 	ventiRead(score, VtRootType);
-	if(!vtRootUnpack(&root, buf))
-		vtFatal("corrupted root: vtRootUnpack");
+	if(vtrootunpack(&root, buf) < 0)
+		sysfatal("corrupted root: vtrootunpack");
 	n = ventiRead(root.score, VtDirType);
 
 	/*
@@ -493,7 +489,7 @@
 	 */
 	if(n <= 2*VtEntrySize){
 		if(!entryUnpack(&e, buf, 0))
-			vtFatal("bad root: top entry");
+			sysfatal("bad root: top entry");
 		n = ventiRead(e.score, VtDirType);
 	}
 
@@ -505,11 +501,11 @@
 		|| !(e.flags&VtEntryActive)
 		|| e.psize < 256
 		|| e.dsize < 256)
-			vtFatal("bad root: entry %d", i);
+			sysfatal("bad root: entry %d", i);
 		fprint(2, "%V\n", e.score);
 	}
 	if(n > 3*VtEntrySize)
-		vtFatal("bad root: entry count");
+		sysfatal("bad root: entry count");
 
 	blockWrite(PartData, addr);
 
@@ -518,19 +514,19 @@
 	 */
 	ventiRead(e.score, VtDataType);
 	if(!mbUnpack(&mb, buf, bsize))
-		vtFatal("bad root: mbUnpack");
+		sysfatal("bad root: mbUnpack");
 	meUnpack(&me, &mb, 0);
 	if(!deUnpack(&de, &me))
-		vtFatal("bad root: dirUnpack");
+		sysfatal("bad root: dirUnpack");
 	if(!de.qidSpace)
-		vtFatal("bad root: no qidSpace");
+		sysfatal("bad root: no qidSpace");
 	qid = de.qidMax;
 
 	/*
 	 * Recreate the top layer of source.
 	 */
 	entryInit(&e);
-	e.flags |= VtEntryLocal|VtEntryDir;
+	e.flags |= VtEntryLocal|_VtEntryDir;
 	e.size = VtEntrySize*3;
 	e.tag = tag;
 	localToGlobal(addr, e.score);
diff --git a/src/cmd/fossil/flfmt9660.c b/src/cmd/fossil/flfmt9660.c
index 4464c9f..d409795 100644
--- a/src/cmd/fossil/flfmt9660.c
+++ b/src/cmd/fossil/flfmt9660.c
@@ -28,7 +28,7 @@
 #pragma varargck type "L" uchar*
 #pragma varargck type "B" uchar*
 #pragma varargck type "N" uchar*
-#pragma varargck type "T" uchar*
+#pragma varargck type "C" uchar*
 #pragma varargck type "D" uchar*
 
 typedef struct Voldesc Voldesc;
@@ -73,8 +73,8 @@
 	if(v->magic[0] == 0xFF)
 		return;
 
-	print("system %.32T\n", v->systemid);
-	print("volume %.32T\n", v->volumeid);
+	print("system %.32C\n", v->systemid);
+	print("volume %.32C\n", v->volumeid);
 	print("volume size %.4N\n", v->volsize);
 	print("charset %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux %.2ux\n",
 		v->charset[0], v->charset[1], v->charset[2], v->charset[3],
@@ -88,13 +88,13 @@
 	print("mpath loc %.4B\n", v->mpathloc);
 	print("opt mpath loc %.4B\n", v->ompathloc);
 	print("rootdir %D\n", v->rootdir);
-	print("volume set identifier %.128T\n", v->volsetid);
-	print("publisher %.128T\n", v->publisher);
-	print("preparer %.128T\n", v->prepid);
-	print("application %.128T\n", v->applid);
-	print("notice %.37T\n", v->notice);
-	print("abstract %.37T\n", v->abstract);
-	print("biblio %.37T\n", v->biblio);
+	print("volume set identifier %.128C\n", v->volsetid);
+	print("publisher %.128C\n", v->publisher);
+	print("preparer %.128C\n", v->prepid);
+	print("application %.128C\n", v->applid);
+	print("notice %.37C\n", v->notice);
+	print("abstract %.37C\n", v->abstract);
+	print("biblio %.37C\n", v->biblio);
 	print("creation date %.17s\n", v->cdate);
 	print("modification date %.17s\n", v->mdate);
 	print("expiration date %.17s\n", v->xdate);
@@ -129,7 +129,7 @@
 		snprint(buf, sizeof buf, ".%s dloc %.4N dlen %.4N",
 			c->name[0] ? "." : "", c->dloc, c->dlen);
 	} else {
-		snprint(buf, sizeof buf, "%.*T dloc %.4N dlen %.4N", c->namelen, c->name,
+		snprint(buf, sizeof buf, "%.*C dloc %.4N dlen %.4N", c->namelen, c->name,
 			c->dloc, c->dlen);
 	}
 	fmtstrcpy(fmt, buf);
@@ -239,7 +239,7 @@
 static void
 ascii(void)
 {
-	fmtinstall('T', asciiTfmt);
+	fmtinstall('C', asciiTfmt);
 }
 
 static int
@@ -299,35 +299,35 @@
 	off9660 = xoff9660;
 
 	if((b = Bopen(file9660, OREAD)) == nil)
-		vtFatal("Bopen %s: %r", file9660);
+		sysfatal("Bopen %s: %r", file9660);
 
 	getsect(root, 16);
 	ascii();
 
 	v = (Voldesc*)root;
 	if(memcmp(v->magic, "\x01CD001\x01\x00", 8) != 0)
-		vtFatal("%s not a cd image", file9660);
+		sysfatal("%s not a cd image", file9660);
 
 	startoff = iso9660start((Cdir*)v->rootdir)*Blocksize;
 	endoff = little(v->volsize, 4);	/* already in bytes */
 
 	fsoff = off9660 + h->data*h->blockSize;
 	if(fsoff > startoff)
-		vtFatal("fossil data starts after cd data");
+		sysfatal("fossil data starts after cd data");
 	if(off9660 + (vlong)h->end*h->blockSize < endoff)
-		vtFatal("fossil data ends before cd data");
+		sysfatal("fossil data ends before cd data");
 	if(fsoff%h->blockSize)
-		vtFatal("cd offset not a multiple of fossil block size");
+		sysfatal("cd offset not a multiple of fossil block size");
 
 	/* Read "same" block via CD image and via Fossil image */
 	getsect(sect, startoff/Blocksize);
 	if(seek(fd, startoff-off9660, 0) < 0)
-		vtFatal("cannot seek to first data sector on cd via fossil");
+		sysfatal("cannot seek to first data sector on cd via fossil");
 fprint(2, "look for %lud at %lud\n", startoff, startoff-off9660);
 	if(readn(fd, sect2, Blocksize) != Blocksize)
-		vtFatal("cannot read first data sector on cd via fossil");
+		sysfatal("cannot read first data sector on cd via fossil");
 	if(memcmp(sect, sect2, Blocksize) != 0)
-		vtFatal("iso9660 offset is a lie %08ux %08ux", *(long*)sect, *(long*)sect2);
+		sysfatal("iso9660 offset is a lie %08lux %08lux", *(long*)sect, *(long*)sect2);
 }
 
 void
@@ -339,10 +339,10 @@
 	uchar sect[Blocksize];
 
 	if(!diskReadRaw(disk, PartData, (startoff-fsoff)/h->blockSize, buf))
-		vtFatal("disk read failed: %r");
+		sysfatal("disk read failed: %r");
 	getsect(sect, startoff/Blocksize);
 	if(memcmp(buf, sect, Blocksize) != 0)
-		vtFatal("fsoff is wrong");
+		sysfatal("fsoff is wrong");
 
 	sb = (startoff-fsoff)/h->blockSize;
 	eb = (endoff-fsoff+h->blockSize-1)/h->blockSize;
@@ -378,10 +378,10 @@
 	root = fileOpen(fs, "/active");
 	iso9660copydir(fs, root, (Cdir*)v->rootdir);
 	fileDecRef(root);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 	if(!fsSnapshot(fs, nil, nil, 0))
-		vtFatal("snapshot failed: %R");
-	vtRLock(fs->elk);
+		sysfatal("snapshot failed: %r");
+	rlock(&fs->elk);
 }
 
 /*
@@ -400,7 +400,7 @@
 		c = (Cdir*)((uchar*)c+c->len);	/* skip dotdot */
 		/* oops: might happen if leftmost directory is empty or leftmost file is zero length! */
 		if(little(c->dloc, 4) == 0)
-			vtFatal("error parsing cd image or unfortunate cd image");	
+			sysfatal("error parsing cd image or unfortunate cd image");	
 	}
 	return little(c->dloc, 4);
 }
@@ -519,7 +519,7 @@
 		p++;
 	sysl = (uchar*)c + c->len - p;
 	if(sysl <= 0)
-		vtFatal("missing plan9 directory entry on %d/%d/%.*s", c->namelen, c->name[0], c->namelen, c->name);
+		sysfatal("missing plan9 directory entry on %d/%d/%.*s", c->namelen, c->name[0], c->namelen, c->name);
 	d.name = getname(&p);
 	d.uid = getname(&p);
 	d.gid = getname(&p);
@@ -537,7 +537,7 @@
 	if(d.mode&DMDIR)
 		mode |= ModeDir;
 	if((f = fileCreate(dir, d.name, mode, d.uid)) == nil)
-		vtFatal("could not create file '%s': %r", d.name);
+		sysfatal("could not create file '%s': %r", d.name);
 	if(d.mode&DMDIR)
 		iso9660copydir(fs, f, c);
 	else{
@@ -546,20 +546,20 @@
 		for(foff=0; foff<len; foff+=h->blockSize){
 			localToGlobal((off+foff-fsoff)/h->blockSize, score);
 			if(!fileMapBlock(f, foff/h->blockSize, score, Tag))
-				vtFatal("fileMapBlock: %R");
+				sysfatal("fileMapBlock: %r");
 		}
 		if(!fileSetSize(f, len))
-			vtFatal("fileSetSize: %R");
+			sysfatal("fileSetSize: %r");
 	}
 	if(!fileGetDir(f, &de))
-		vtFatal("fileGetDir: %R");
+		sysfatal("fileGetDir: %r");
 	de.uid = d.uid;
 	de.gid = d.gid;
 	de.mtime = d.mtime;
 	de.atime = d.atime;
 	de.mode = d.mode&0777;
 	if(!fileSetDir(f, &de, "sys"))
-		vtFatal("fileSetDir: %R");
+		sysfatal("fileSetDir: %r");
 	fileDecRef(f);
 	ind--;
 }
diff --git a/src/cmd/fossil/fns.h b/src/cmd/fossil/fns.h
index c22d3b7..daf9db7 100644
--- a/src/cmd/fossil/fns.h
+++ b/src/cmd/fossil/fns.h
@@ -18,7 +18,7 @@
 void	sourceUnlock(Source*);
 
 Block*	cacheAllocBlock(Cache*, int, u32int, u32int, u32int);
-Cache*	cacheAlloc(Disk*, VtSession*, ulong, int);
+Cache*	cacheAlloc(Disk*, VtConn*, ulong, int);
 void	cacheCountUsed(Cache*, u32int, u32int*, u32int*, u32int*);
 int	cacheDirty(Cache*);
 void	cacheFlush(Cache*, int);
@@ -81,11 +81,11 @@
 File*	fileRoot(Source*);
 int	fileSnapshot(File*, File*, u32int, int);
 int	fsNextQid(Fs*, u64int*);
-int	mkVac(VtSession*, uint, Entry*, Entry*, DirEntry*, uchar[VtScoreSize]);
+int	mkVac(VtConn*, uint, Entry*, Entry*, DirEntry*, uchar[VtScoreSize]);
 Block*	superGet(Cache*, Super*);
 
 void	archFree(Arch*);
-Arch*	archInit(Cache*, Disk*, Fs*, VtSession*);
+Arch*	archInit(Cache*, Disk*, Fs*, VtConn*);
 void	archKick(Arch*);
 
 void	bwatchDependency(Block*);
diff --git a/src/cmd/fossil/fossil.c b/src/cmd/fossil/fossil.c
index 8ef6808..bdfc8ad 100644
--- a/src/cmd/fossil/fossil.c
+++ b/src/cmd/fossil/fossil.c
@@ -12,7 +12,7 @@
 usage(void)
 {
 	fprint(2, "usage: %s [-Dt] [-c cmd] [-f partition] [-m %%]\n", argv0);
-	exits("usage");
+	threadexitsall("usage");
 }
 
 static void
@@ -44,7 +44,7 @@
 	for(i=0; i<nf; i++){
 		if(f[i][0] == '#')
 			continue;
-		cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*));
+		cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
 		/* expand argument '*' to mean current file */
 		if((p = strchr(f[i], '*')) && (p==f[i]||isspace(p[-1])) && (p[1]==0||isspace(p[1]))){
 			memmove(tbuf, f[i], p-f[i]);
@@ -52,7 +52,7 @@
 			strecpy(tbuf+strlen(tbuf), tbuf+sizeof tbuf, p+1);
 			f[i] = tbuf;
 		}
-		cmd[ncmd++] = vtStrDup(f[i]);
+		cmd[ncmd++] = vtstrdup(f[i]);
 	}
 	close(fd);
 	*pcmd = cmd;
@@ -60,7 +60,7 @@
 }
 
 void
-main(int argc, char* argv[])
+threadmain(int argc, char* argv[])
 {
 	char **cmd, *p;
 	int i, ncmd, tflag;
@@ -84,8 +84,6 @@
 	cmd = nil;
 	ncmd = tflag = 0;
 
-	vtAttach();
-
 	ARGBEGIN{
 	case '?':
 	default:
@@ -94,7 +92,7 @@
 	case 'c':
 		p = EARGF(usage());
 		currfsysname = p;
-		cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*));
+		cmd = vtrealloc(cmd, (ncmd+1)*sizeof(char*));
 		cmd[ncmd++] = p;
 		break;
 	case 'D':
@@ -132,12 +130,11 @@
 
 	for(i = 0; i < ncmd; i++)
 		if(cliExec(cmd[i]) == 0)
-			fprint(2, "%s: %R\n", cmd[i]);
-	vtMemFree(cmd);
+			fprint(2, "%s: %r\n", cmd[i]);
+	vtfree(cmd);
 
 	if(tflag && consTTY() == 0)
-		consPrint("%s\n", vtGetError());
+		consPrint("%r\n");
 
-	vtDetach();
-	exits(0);
+	threadexits(0);
 }
diff --git a/src/cmd/fossil/fs.c b/src/cmd/fossil/fs.c
index ba15e66..5f8a1cf 100644
--- a/src/cmd/fossil/fs.c
+++ b/src/cmd/fossil/fs.c
@@ -8,7 +8,7 @@
 static void snapClose(Snap*);
 
 Fs *
-fsOpen(char *file, VtSession *z, long ncache, int mode)
+fsOpen(char *file, VtConn *z, long ncache, int mode)
 {
 	int fd, m;
 	uchar oscore[VtScoreSize];
@@ -16,10 +16,11 @@
 	Disk *disk;
 	Fs *fs;
 	Super super;
+	char e[ERRMAX];
 
 	switch(mode){
 	default:
-		vtSetError(EBadMode);
+		werrstr(EBadMode);
 		return nil;
 	case OReadOnly:
 		m = OREAD;
@@ -30,23 +31,22 @@
 	}
 	fd = open(file, m);
 	if(fd < 0){
-		vtSetError("open %s: %r", file);
+		werrstr("open %s: %r", file);
 		return nil;
 	}
 
 	bwatchInit();
 	disk = diskAlloc(fd);
 	if(disk == nil){
-		vtSetError("diskAlloc: %R");
+		werrstr("diskAlloc: %r");
 		close(fd);
 		return nil;
 	}
 
-	fs = vtMemAllocZ(sizeof(Fs));
+	fs = vtmallocz(sizeof(Fs));
 	fs->mode = mode;
-	fs->name = vtStrDup(file);
+	fs->name = vtstrdup(file);
 	fs->blockSize = diskBlockSize(disk);
-	fs->elk = vtLockAlloc();
 	fs->cache = cacheAlloc(disk, z, ncache, mode);
 	if(mode == OReadWrite && z)
 		fs->arch = archInit(fs->cache, disk, fs, z);
@@ -57,7 +57,7 @@
 		goto Err;
 	if(!superUnpack(&super, b->data)){
 		blockPut(b);
-		vtSetError("bad super block");
+		werrstr("bad super block");
 		goto Err;
 	}
 	blockPut(b);
@@ -73,17 +73,18 @@
 		 * Perhaps it failed because the block is copy-on-write.
 		 * Do the copy and try again.
 		 */
-		if(mode == OReadOnly || strcmp(vtGetError(), EBadRoot) != 0)
+		rerrstr(e, sizeof e);
+		if(mode == OReadOnly || strcmp(e, EBadRoot) != 0)
 			goto Err;
 		b = cacheLocalData(fs->cache, super.active, BtDir, RootTag,
 			OReadWrite, 0);
 		if(b == nil){
-			vtSetError("cacheLocalData: %R");
+			werrstr("cacheLocalData: %r");
 			goto Err;
 		}
 		if(b->l.epoch == fs->ehi){
 			blockPut(b);
-			vtSetError("bad root source block");
+			werrstr("bad root source block");
 			goto Err;
 		}
 		b = blockCopy(b, RootTag, fs->ehi, fs->elo);
@@ -94,7 +95,7 @@
 		bs = cacheLocal(fs->cache, PartSuper, 0, OReadWrite);
 		if(bs == nil){
 			blockPut(b);
-			vtSetError("cacheLocal: %R");
+			werrstr("cacheLocal: %r");
 			goto Err;
 		}
 		superPack(&super, bs->data);
@@ -105,19 +106,19 @@
 		blockPut(bs);
 		fs->source = sourceRoot(fs, super.active, mode);
 		if(fs->source == nil){
-			vtSetError("sourceRoot: %R");
+			werrstr("sourceRoot: %r");
 			goto Err;
 		}
 	}
 
 //fprint(2, "%s: got fs source\n", argv0);
 
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	fs->file = fileRoot(fs->source);
 	fs->source->file = fs->file;		/* point back */
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 	if(fs->file == nil){
-		vtSetError("fileRoot: %R");
+		werrstr("fileRoot: %r");
 		goto Err;
 	}
 
@@ -138,32 +139,31 @@
 void
 fsClose(Fs *fs)
 {
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	periodicKill(fs->metaFlush);
 	snapClose(fs->snap);
 	if(fs->file){
 		fileMetaFlush(fs->file, 0);
 		if(!fileDecRef(fs->file))
-			vtFatal("fsClose: files still in use: %r\n");
+			sysfatal("fsClose: files still in use: %r");
 	}
 	fs->file = nil;
 	sourceClose(fs->source);
 	cacheFree(fs->cache);
 	if(fs->arch)
 		archFree(fs->arch);
-	vtMemFree(fs->name);
-	vtRUnlock(fs->elk);
-	vtLockFree(fs->elk);
+	vtfree(fs->name);
+	runlock(&fs->elk);
 	memset(fs, ~0, sizeof(Fs));
-	vtMemFree(fs);
+	vtfree(fs);
 }
 
 int
 fsRedial(Fs *fs, char *host)
 {
-	if(!vtRedial(fs->z, host))
+	if(vtredial(fs->z, host) < 0)
 		return 0;
-	if(!vtConnect(fs->z, 0))
+	if(vtconnect(fs->z) < 0)
 		return 0;
 	return 1;
 }
@@ -186,11 +186,11 @@
 	Block *b;
 
 	if((b = cacheLocal(c, PartSuper, 0, OReadWrite)) == nil){
-		fprint(2, "%s: superGet: cacheLocal failed: %R\n", argv0);
+		fprint(2, "%s: superGet: cacheLocal failed: %r\n", argv0);
 		return nil;
 	}
 	if(!superUnpack(super, b->data)){
-		fprint(2, "%s: superGet: superUnpack failed: %R\n", argv0);
+		fprint(2, "%s: superGet: superUnpack failed: %r\n", argv0);
 		blockPut(b);
 		return nil;
 	}
@@ -212,7 +212,7 @@
 		}
 		while(b->iostate != BioClean && b->iostate != BioDirty){
 			assert(b->iostate == BioWriting);
-			vtSleep(b->ioready);
+			rsleep(&b->ioready);
 		}
 		/*
 		 * it's okay that b might still be dirty.
@@ -361,13 +361,13 @@
 	snprint(buf, sizeof buf, "/archive/%d/%02d%02d",
 		now.year+1900, now.mon+1, now.mday);
 	need = 1;
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	f = fileOpen(fs, buf);
 	if(f){
 		need = 0;
 		fileDecRef(f);
 	}
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 	return need;
 }
 
@@ -377,15 +377,15 @@
 	Block *bs;
 	Super super;
 
-	vtLock(fs->elk);
+	wlock(&fs->elk);
 	if(low > fs->ehi){
-		vtSetError("bad low epoch (must be <= %ud)", fs->ehi);
-		vtUnlock(fs->elk);
+		werrstr("bad low epoch (must be <= %ud)", fs->ehi);
+		wunlock(&fs->elk);
 		return 0;
 	}
 
 	if((bs = superGet(fs->cache, &super)) == nil){
-		vtUnlock(fs->elk);
+		wunlock(&fs->elk);
 		return 0;
 	}
 
@@ -393,7 +393,7 @@
 	fs->elo = low;
 	superWrite(bs, &super, 1);
 	blockPut(bs);
-	vtUnlock(fs->elk);
+	wunlock(&fs->elk);
 
 	return 1;
 }
@@ -421,14 +421,14 @@
 		return 0;
 
 	memset(&e, 0, sizeof e);
-	e.flags = VtEntryActive | VtEntryLocal | VtEntryDir;
+	e.flags = VtEntryActive | VtEntryLocal | _VtEntryDir;
 	memmove(e.score, b->score, VtScoreSize);
 	e.tag = RootTag;
 	e.snap = b->l.epoch;
 
 	b = blockCopy(b, RootTag, fs->ehi+1, fs->elo);
 	if(b == nil){
-		fprint(2, "%s: bumpEpoch: blockCopy: %R\n", argv0);
+		fprint(2, "%s: bumpEpoch: blockCopy: %r\n", argv0);
 		return 0;
 	}
 
@@ -507,14 +507,14 @@
 	dst = nil;
 
 	if(fs->halted){
-		vtSetError("file system is halted");
+		werrstr("file system is halted");
 		return 0;
 	}
 
 	/*
 	 * Freeze file system activity.
 	 */
-	vtLock(fs->elk);
+	wlock(&fs->elk);
 
 	/*
 	 * Get the root of the directory we're going to save.
@@ -599,7 +599,7 @@
 			goto Err;
 	}
 
-	vtUnlock(fs->elk);
+	wunlock(&fs->elk);
 
 	/* BUG? can fs->arch fall out from under us here? */
 	if(doarchive && fs->arch)
@@ -608,12 +608,12 @@
 	return 1;
 
 Err:
-	fprint(2, "%s: fsSnapshot: %R\n", argv0);
+	fprint(2, "%s: fsSnapshot: %r\n", argv0);
 	if(src)
 		fileDecRef(src);
 	if(dst)
 		fileDecRef(dst);
-	vtUnlock(fs->elk);
+	wunlock(&fs->elk);
 	return 0;
 }
 
@@ -625,37 +625,37 @@
 	Entry e, ee;
 	File *f;
 
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	f = fileOpen(fs, name);
 	if(f == nil){
-		vtRUnlock(fs->elk);
+		runlock(&fs->elk);
 		return 0;
 	}
 
 	if(!fileGetSources(f, &e, &ee) || !fileGetDir(f, &de)){
 		fileDecRef(f);
-		vtRUnlock(fs->elk);
+		runlock(&fs->elk);
 		return 0;
 	}
 	fileDecRef(f);
 
 	r = mkVac(fs->z, fs->blockSize, &e, &ee, &de, score);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 	return r;
 }
 
 static int
-vtWriteBlock(VtSession *z, uchar *buf, uint n, uint type, uchar score[VtScoreSize])
+vtWriteBlock(VtConn *z, uchar *buf, uint n, uint type, uchar score[VtScoreSize])
 {
-	if(!vtWrite(z, score, type, buf, n))
+	if(vtwrite(z, score, type, buf, n) < 0)
 		return 0;
-	if(!vtSha1Check(score, buf, n))
+	if(vtsha1check(score, buf, n) < 0)
 		return 0;
 	return 1;
 }
 
 int
-mkVac(VtSession *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar score[VtScoreSize])
+mkVac(VtConn *z, uint blockSize, Entry *pe, Entry *pee, DirEntry *pde, uchar score[VtScoreSize])
 {
 	uchar buf[8192];
 	int i;
@@ -673,7 +673,7 @@
 
 	if(globalToLocal(e.score) != NilBlock
 	|| (ee.flags&VtEntryActive && globalToLocal(ee.score) != NilBlock)){
-		vtSetError("can only vac paths already stored on venti");
+		werrstr("can only vac paths already stored on venti");
 		return 0;
 	}
 
@@ -682,7 +682,7 @@
 	 */
 	n = deSize(&de);
 	if(n+MetaHeaderSize+MetaIndexSize > sizeof buf){
-		vtSetError("DirEntry too big");
+		werrstr("DirEntry too big");
 		return 0;
 	}
 	memset(buf, 0, sizeof buf);
@@ -721,11 +721,10 @@
 	/*
 	 * Save root.
 	 */
-	root.version = VtRootVersion;
 	strecpy(root.type, root.type+sizeof root.type, "vac");
 	strecpy(root.name, root.name+sizeof root.name, de.elem);
-	root.blockSize = blockSize;
-	vtRootPack(&root, buf);
+	root.blocksize = blockSize;
+	vtrootpack(&root, buf);
 	if(!vtWriteBlock(z, buf, VtRootSize, VtRootType, score))
 		return 0;
 
@@ -735,17 +734,17 @@
 int
 fsSync(Fs *fs)
 {
-	vtLock(fs->elk);
+	wlock(&fs->elk);
 	fileMetaFlush(fs->file, 1);
 	cacheFlush(fs->cache, 1);
-	vtUnlock(fs->elk);
+	wunlock(&fs->elk);
 	return 1;
 }
 
 int
 fsHalt(Fs *fs)
 {
-	vtLock(fs->elk);
+	wlock(&fs->elk);
 	fs->halted = 1;
 	fileMetaFlush(fs->file, 1);
 	cacheFlush(fs->cache, 1);
@@ -758,7 +757,7 @@
 	if(!fs->halted)
 		return 0;
 	fs->halted = 0;
-	vtUnlock(fs->elk);
+	wunlock(&fs->elk);
 	return 1;
 }
 
@@ -789,9 +788,9 @@
 	int rv;
 	Fs *fs = a;
 
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	rv = fileMetaFlush(fs->file, 1);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 	if(rv > 0)
 		cacheFlush(fs->cache, 0);
 }
@@ -828,7 +827,7 @@
 			if((ff = fileWalk(f, de.elem)) != nil){
 				t = smprint("%s/%s", path, de.elem);
 				n += fsEsearch1(ff, t, savetime, plo);
-				vtMemFree(t);
+				vtfree(t);
 				fileDecRef(ff);
 			}
 		}
@@ -876,11 +875,11 @@
 	 * given that we need to save all the unventied archives
 	 * and all the snapshots younger than age.
 	 */
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	lo = fs->ehi;
 	fsEsearch(fs, "/archive", 0, &lo);
 	fsEsearch(fs, "/snapshot", time(0)-age*60, &lo);
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 
 	fsEpochLow(fs, lo);
 	fsSnapshotRemove(fs);
@@ -895,7 +894,7 @@
 	DirEntry de;
 	DirEntryEnum *dee;
 	File *ff;
-	char *t;
+	char *t, e[ERRMAX];
 
 	dee = deeOpen(f);
 	if(dee == nil)
@@ -908,9 +907,10 @@
 			break;
 		n++;
 		if(de.mode & ModeSnapshot){
+			rerrstr(e, sizeof e);
 			if((ff = fileWalk(f, de.elem)) != nil)
 				fileDecRef(ff);
-			else if(strcmp(vtGetError(), ESnapOld) == 0){
+			else if(strcmp(e, ESnapOld) == 0){
 				if(fileClri(f, de.elem, "adm"))
 					n--;
 			}
@@ -921,7 +921,7 @@
 				if(fsRsearch1(ff, t) == 0)
 					if(fileRemove(ff, "adm"))
 						n--;
-				vtMemFree(t);
+				vtfree(t);
 				fileDecRef(ff);
 			}
 		}
@@ -961,16 +961,16 @@
 void
 fsSnapshotRemove(Fs *fs)
 {
-	vtRLock(fs->elk);
+	rlock(&fs->elk);
 	fsRsearch(fs, "/snapshot");
-	vtRUnlock(fs->elk);
+	runlock(&fs->elk);
 }
 
 struct Snap
 {
 	Fs	*fs;
 	Periodic*tick;
-	VtLock	*lk;
+	QLock	lk;
 	uint	snapMinutes;
 	uint	archMinute;
 	uint	snapLife;
@@ -992,7 +992,7 @@
 	s = v;
 
 	now = time(0)/60;
-	vtLock(s->lk);
+	qlock(&s->lk);
 
 	/*
 	 * Snapshots happen every snapMinutes minutes.
@@ -1002,7 +1002,7 @@
 	if(s->snapMinutes != ~0 && s->snapMinutes != 0
 	&& now%s->snapMinutes==0 && now != s->lastSnap){
 		if(!fsSnapshot(s->fs, nil, nil, 0))
-			fprint(2, "%s: fsSnapshot snap: %R\n", argv0);
+			fprint(2, "%s: fsSnapshot snap: %r\n", argv0);
 		s->lastSnap = now;
 	}
 
@@ -1038,7 +1038,7 @@
 		fsSnapshotCleanup(s->fs, s->snapLife);
 		s->lastCleanup = now;
 	}
-	vtUnlock(s->lk);
+	qunlock(&s->lk);
 }
 
 static Snap*
@@ -1046,10 +1046,9 @@
 {
 	Snap *s;
 
-	s = vtMemAllocZ(sizeof(Snap));
+	s = vtmallocz(sizeof(Snap));
 	s->fs = fs;
 	s->tick = periodicAlloc(snapEvent, s, 10*1000);
-	s->lk = vtLockAlloc();
 	s->snapMinutes = -1;
 	s->archMinute = -1;
 	s->snapLife = -1;
@@ -1067,11 +1066,11 @@
 		return;
 	}
 
-	vtLock(s->lk);
+	qlock(&s->lk);
 	*snap = s->snapMinutes;
 	*arch = s->archMinute;
 	*snaplen = s->snapLife;
-	vtUnlock(s->lk);
+	qunlock(&s->lk);
 }
 
 void
@@ -1080,11 +1079,11 @@
 	if(s == nil)
 		return;
 
-	vtLock(s->lk);
+	qlock(&s->lk);
 	s->snapMinutes = snap;
 	s->archMinute = arch;
 	s->snapLife = snaplen;
-	vtUnlock(s->lk);
+	qunlock(&s->lk);
 }
 
 static void
@@ -1094,6 +1093,6 @@
 		return;
 
 	periodicKill(s->tick);
-	vtMemFree(s);
+	vtfree(s);
 }
 
diff --git a/src/cmd/fossil/fs.h b/src/cmd/fossil/fs.h
index 67314d1..67792ce 100644
--- a/src/cmd/fossil/fs.h
+++ b/src/cmd/fossil/fs.h
@@ -6,6 +6,17 @@
 #pragma incomplete File
 #pragma incomplete DirEntryEnum
 
+enum
+{
+	STACK = 32*1024,
+};
+
+enum
+{
+	// XXX What to do here?
+	VtMaxLumpSize = 65536,
+};
+
 /* modes */
 
 enum {
@@ -21,7 +32,7 @@
 int	fsEpochLow(Fs*, u32int);
 File	*fsGetRoot(Fs*);
 int	fsHalt(Fs*);
-Fs	*fsOpen(char*, VtSession*, long, int);
+Fs	*fsOpen(char*, VtConn*, long, int);
 int	fsRedial(Fs*, char*);
 void	fsSnapshotCleanup(Fs*, u32int);
 int	fsSnapshot(Fs*, char*, char*, int);
diff --git a/src/cmd/fossil/mkfile b/src/cmd/fossil/mkfile
index cf2b0bd..7b76af7 100644
--- a/src/cmd/fossil/mkfile
+++ b/src/cmd/fossil/mkfile
@@ -1,7 +1,7 @@
 </$objtype/mkfile
 BIN=/$objtype/bin/fossil
 
-TARG=fossil flchk flfmt conf last
+TARG=fossil flchk flfmt conf last view
 
 LIBFILES=\
 	9p\
@@ -37,7 +37,7 @@
 LIB=libfs.a$O
 
 HFILES=\
-	/sys/include/oventi.h\
+	/sys/include/venti.h\
 	stdinc.h\
 	vac.h\
 	dat.h\
diff --git a/src/cmd/fossil/pack.c b/src/cmd/fossil/pack.c
index 9fd2070..1dc3347 100644
--- a/src/cmd/fossil/pack.c
+++ b/src/cmd/fossil/pack.c
@@ -35,12 +35,12 @@
 headerUnpack(Header *h, uchar *p)
 {
 	if(U32GET(p) != HeaderMagic){
-		vtSetError("vac header bad magic");
+		werrstr("vac header bad magic");
 		return 0;
 	}
 	h->version = U16GET(p+4);
 	if(h->version != HeaderVersion){
-		vtSetError("vac header bad version");
+		werrstr("vac header bad version");
 		return 0;
 	}
 	h->blockSize = U16GET(p+6);
@@ -74,7 +74,7 @@
 
 	if(l->type > BtMax){
 Bad:
-		vtSetError(EBadLabel);
+		werrstr(EBadLabel);
 		fprint(2, "%s: labelUnpack: bad label: 0x%.2ux 0x%.2ux 0x%.8ux "
 			"0x%.8ux 0x%.8ux\n", argv0, l->state, l->type, l->epoch,
 			l->epochClose, l->tag);
@@ -124,7 +124,7 @@
 	U32PUT(p, e->gen);
 	U16PUT(p+4, e->psize);
 	U16PUT(p+6, e->dsize);
-	flags = e->flags | ((e->depth << VtEntryDepthShift) & VtEntryDepthMask);
+	flags = e->flags | ((e->depth << _VtEntryDepthShift) & _VtEntryDepthMask);
 	U8PUT(p+8, flags);
 	memset(p+9, 0, 5);
 	U48PUT(p+14, e->size, t32);
@@ -150,8 +150,8 @@
 	e->psize = U16GET(p+4);
 	e->dsize = U16GET(p+6);
 	e->flags = U8GET(p+8);
-	e->depth = (e->flags & VtEntryDepthMask) >> VtEntryDepthShift;
-	e->flags &= ~VtEntryDepthMask;
+	e->depth = (e->flags & _VtEntryDepthMask) >> _VtEntryDepthShift;
+	e->flags &= ~_VtEntryDepthMask;
 	e->size = U48GET(p+14);
 
 	if(e->flags & VtEntryLocal){
@@ -173,7 +173,7 @@
 int
 entryType(Entry *e)
 {
-	return (((e->flags & VtEntryDir) != 0) << 3) | e->depth;
+	return (((e->flags & _VtEntryDir) != 0) << 3) | e->depth;
 }
 
 
@@ -219,7 +219,7 @@
 	return 1;
 Err:
 	memset(s, 0, sizeof(*s));
-	vtSetError(EBadSuper);
+	werrstr(EBadSuper);
 	return 0;
 }
 
diff --git a/src/cmd/fossil/periodic.c b/src/cmd/fossil/periodic.c
index 8a0c208..634f975 100644
--- a/src/cmd/fossil/periodic.c
+++ b/src/cmd/fossil/periodic.c
@@ -4,7 +4,7 @@
 #include "error.h"
 
 struct Periodic {
-	VtLock *lk;
+	QLock lk;
 	int die;		/* flag: quit if set */
 	void (*f)(void*);	/* call this each period */
 	void *a;		/* argument to f */
@@ -18,15 +18,14 @@
 {
 	Periodic *p;
 
-	p = vtMemAllocZ(sizeof(Periodic));
-	p->lk = vtLockAlloc();
+	p = vtmallocz(sizeof(Periodic));
 	p->f = f;
 	p->a = a;
 	p->msec = msec;
 	if(p->msec < 10)
 		p->msec = 10;
 
-	vtThread(periodicThread, p);
+	proccreate(periodicThread, p, STACK);
 	return p;
 }
 
@@ -35,16 +34,15 @@
 {
 	if(p == nil)
 		return;
-	vtLock(p->lk);
+	qlock(&p->lk);
 	p->die = 1;
-	vtUnlock(p->lk);
+	qunlock(&p->lk);
 }
 
 static void
 periodicFree(Periodic *p)
 {
-	vtLockFree(p->lk);
-	vtMemFree(p);
+	vtfree(p);
 }
 
 static void
@@ -53,7 +51,7 @@
 	Periodic *p = a;
 	vlong t, ct, ts;		/* times in ms. */
 
-	vtThreadSetName("periodic");
+	threadsetname("periodic");
 
 	ct = nsec() / 1000000;
 	t = ct + p->msec;		/* call p->f at or after this time */
@@ -65,9 +63,9 @@
 		if(ts > 0)
 			sleep(ts);	/* wait for cycle's start */
 
-		vtLock(p->lk);
+		qlock(&p->lk);
 		if(p->die){
-			vtUnlock(p->lk);
+			qunlock(&p->lk);
 			break;
 		}
 		ct = nsec() / 1000000;
@@ -77,7 +75,7 @@
 			while(t <= ct)	/* advance t to future cycle start */
 				t += p->msec;
 		}
-		vtUnlock(p->lk);
+		qunlock(&p->lk);
 	}
 	periodicFree(p);
 }
diff --git a/src/cmd/fossil/source.c b/src/cmd/fossil/source.c
index aa61419..d5bb297 100644
--- a/src/cmd/fossil/source.c
+++ b/src/cmd/fossil/source.c
@@ -83,12 +83,12 @@
 	epoch = b->l.epoch;
 	if(mode == OReadWrite){
 		if(e.snap != 0){
-			vtSetError(ESnapRO);
+			werrstr(ESnapRO);
 			return nil;
 		}
 	}else if(e.snap != 0){
 		if(e.snap < fs->elo){
-			vtSetError(ESnapOld);
+			werrstr(ESnapOld);
 			return nil;
 		}
 		if(e.snap >= fs->ehi)
@@ -96,21 +96,20 @@
 		epoch = e.snap;
 	}
 
-	r = vtMemAllocZ(sizeof(Source));
+	r = vtmallocz(sizeof(Source));
 	r->fs = fs;
 	r->mode = mode;
 	r->issnapshot = issnapshot;
 	r->dsize = e.dsize;
 	r->gen = e.gen;
-	r->dir = (e.flags & VtEntryDir) != 0;
-	r->lk = vtLockAlloc();
+	r->dir = (e.flags & _VtEntryDir) != 0;
 	r->ref = 1;
 	r->parent = p;
 	if(p){
-		vtLock(p->lk);
+		qlock(&p->lk);
 		assert(mode == OReadOnly || p->mode == OReadWrite);
 		p->ref++;
-		vtUnlock(p->lk);
+		qunlock(&p->lk);
 	}
 	r->epoch = epoch;
 //	consPrint("sourceAlloc: have %V be.%d fse.%d %s\n", b->score,
@@ -126,7 +125,7 @@
 	return r;
 Bad:
 	free(pname);
-	vtSetError(EBadEntry);
+	werrstr(EBadEntry);
 	return nil;
 }
 
@@ -144,7 +143,7 @@
 		consPrint("sourceRoot: fs->ehi = %ud, b->l = %L\n",
 			fs->ehi, &b->l);
 		blockPut(b);
-		vtSetError(EBadRoot);
+		werrstr(EBadRoot);
 		return nil;
 	}
 
@@ -163,7 +162,7 @@
 	if(r->mode == OReadWrite)
 		assert(r->epoch == r->b->l.epoch);
 	if(!r->dir){
-		vtSetError(ENotDir);
+		werrstr(ENotDir);
 		return nil;
 	}
 
@@ -189,7 +188,7 @@
 	assert(sourceIsLocked(r));
 
 	if(!r->dir){
-		vtSetError(ENotDir);
+		werrstr(ENotDir);
 		return nil;
 	}
 
@@ -219,7 +218,7 @@
 		blockPut(b);
 		if(offset == size){
 			fprint(2, "sourceCreate: cannot happen\n");
-			vtSetError("sourceCreate: cannot happen");
+			werrstr("sourceCreate: cannot happen");
 			return nil;
 		}
 		offset = size;
@@ -232,10 +231,10 @@
 	assert(psize && dsize);
 	e.flags = VtEntryActive;
 	if(dir)
-		e.flags |= VtEntryDir;
+		e.flags |= _VtEntryDir;
 	e.depth = 0;
 	e.size = 0;
-	memmove(e.score, vtZeroScore, VtScoreSize);
+	memmove(e.score, vtzeroscore, VtScoreSize);
 	e.tag = 0;
 	e.snap = 0;
 	e.archive = 0;
@@ -294,7 +293,7 @@
 	e.depth = 0;
 	e.size = 0;
 	e.tag = 0;
-	memmove(e.score, vtZeroScore, VtScoreSize);
+	memmove(e.score, vtzeroscore, VtScoreSize);
 	entryPack(&e, b->data, r->offset % r->epb);
 	blockDirty(b);
 	if(addr != NilBlock)
@@ -370,7 +369,7 @@
 		i = (size+ptrsz-1)/ptrsz;
 		for(; i<ppb; i++){
 			addr = globalToLocal(b->data+i*VtScoreSize);
-			memmove(b->data+i*VtScoreSize, vtZeroScore, VtScoreSize);
+			memmove(b->data+i*VtScoreSize, vtzeroscore, VtScoreSize);
 			blockDirty(b);
 			if(addr != NilBlock)
 				blockRemoveLink(b, addr, type-1, e->tag, 1);
@@ -420,7 +419,7 @@
 		return sourceTruncate(r);
 
 	if(size > VtMaxFileSize || size > ((uvlong)MaxBlock)*r->dsize){
-		vtSetError(ETooBig);
+		werrstr(ETooBig);
 		return 0;
 	}
 
@@ -637,7 +636,7 @@
 		type++;
 		e->tag = tag;
 		e->flags |= VtEntryLocal;
-		blockDependency(bb, b, 0, vtZeroScore, nil);
+		blockDependency(bb, b, 0, vtzeroscore, nil);
 		blockPut(b);
 		b = bb;
 		blockDirty(b);
@@ -718,7 +717,7 @@
 	blockDirty(p);
 
 	/* (ii) */
-	memmove(ob->data, vtZeroScore, VtScoreSize);
+	memmove(ob->data, vtzeroscore, VtScoreSize);
 	blockDependency(ob, p, 0, b->score, nil);
 	blockDirty(ob);
 
@@ -761,7 +760,7 @@
 		return nil;
 	if(r->issnapshot && (e.flags & VtEntryNoArchive)){
 		blockPut(b);
-		vtSetError(ENotArchived);
+		werrstr(ENotArchived);
 		return nil;
 	}
 
@@ -770,7 +769,7 @@
 			e.tag = tag;
 		else if(e.tag != tag){
 			fprint(2, "tag mismatch\n");
-			vtSetError("tag mismatch");
+			werrstr("tag mismatch");
 			goto Err;
 		}
 	}
@@ -779,7 +778,7 @@
 	memset(index, 0, sizeof(index));
 	for(i=0; bn > 0; i++){
 		if(i >= VtPointerDepth){
-			vtSetError(EBadAddr);
+			werrstr(EBadAddr);
 			goto Err;
 		}
 		index[i] = bn % np;
@@ -788,7 +787,7 @@
 
 	if(i > e.depth){
 		if(mode == OReadOnly){
-			vtSetError(EBadAddr);
+			werrstr(EBadAddr);
 			goto Err;
 		}
 		if(!sourceGrowDepth(r, b, &e, i))
@@ -827,19 +826,18 @@
 {
 	if(r == nil)
 		return;
-	vtLock(r->lk);
+	qlock(&r->lk);
 	r->ref--;
 	if(r->ref){
-		vtUnlock(r->lk);
+		qunlock(&r->lk);
 		return;
 	}
 	assert(r->ref == 0);
-	vtUnlock(r->lk);
+	qunlock(&r->lk);
 	if(r->parent)
 		sourceClose(r->parent);
-	vtLockFree(r->lk);
 	memset(r, ~0, sizeof(*r));
-	vtMemFree(r);
+	vtfree(r);
 }
 
 /*
@@ -858,6 +856,7 @@
 {
 	u32int addr;
 	Block *b;
+	char e[ERRMAX];
 
 	switch(r->mode){
 	default:
@@ -912,7 +911,8 @@
 		 * a snapshot.  (Or else the file system is read-only, but then
 		 * the archiver isn't going around deleting blocks.)
 		 */
-		if(strcmp(vtGetError(), ELabelMismatch) == 0){
+		rerrstr(e, sizeof e);
+		if(strcmp(e, ELabelMismatch) == 0){
 			if(!sourceLock(r->parent, OReadOnly))
 				return nil;
 			b = sourceBlock(r->parent, r->offset/r->epb, OReadOnly);
@@ -1027,7 +1027,7 @@
 	if(!entryUnpack(e, b->data, r->offset % r->epb))
 		return nil;
 	if(e->gen != r->gen){
-		vtSetError(ERemoved);
+		werrstr(ERemoved);
 		return nil;
 	}
 	blockDupLock(b);
diff --git a/src/cmd/fossil/stdinc.h b/src/cmd/fossil/stdinc.h
index ef61189..e18ad91 100644
--- a/src/cmd/fossil/stdinc.h
+++ b/src/cmd/fossil/stdinc.h
@@ -1,11 +1,12 @@
 #include <u.h>
 #include <libc.h>
+#include <libsec.h>
+#include <thread.h>
 
 typedef uvlong	u64int;
 typedef	uchar	u8int;
 typedef ushort	u16int;
 
-#include "oventi.h"
+#include "venti.h"
 #include "vac.h"
 #include "fs.h"
-
diff --git a/src/cmd/fossil/vac.c b/src/cmd/fossil/vac.c
index 526ff97..85f0c7f 100644
--- a/src/cmd/fossil/vac.c
+++ b/src/cmd/fossil/vac.c
@@ -45,7 +45,7 @@
 	*n -= 2;
 	if(nn > *n)
 		return 0;
-	*s = vtMemAlloc(nn+1);
+	*s = vtmalloc(nn+1);
 	memmove(*s, *p, nn);
 	(*s)[nn] = 0;
 	*p += nn;
@@ -99,7 +99,7 @@
 	*ri = b;	/* b is the index to insert this entry */
 	memset(me, 0, sizeof(*me));
 
-	vtSetError(ENoFile);
+	werrstr(ENoFile);
 	return 0;
 }
 
@@ -164,7 +164,7 @@
 
 	return 1;
 Err:
-	vtSetError(EBadMeta);
+	werrstr(EBadMeta);
 	return 0;
 }
 
@@ -375,7 +375,7 @@
 	int oo, o, n, i;
 	uchar *p;
 
-	mc = vtMemAlloc(mb->nindex*sizeof(MetaChunk));
+	mc = vtmalloc(mb->nindex*sizeof(MetaChunk));
 	p = mb->buf + MetaHeaderSize;
 	for(i = 0; i<mb->nindex; i++){
 		mc[i].offset = U16GET(p);
@@ -411,8 +411,8 @@
 oo += mc[i].size;
 }
 fprint(2, "\tused=%d size=%d free=%d free2=%d\n", oo, mb->size, mb->free, mb->size - oo);
-	vtSetError(EBadMeta);
-	vtMemFree(mc);
+	werrstr(EBadMeta);
+	vtfree(mc);
 	return nil;
 }
 
@@ -461,23 +461,23 @@
 	o = MetaHeaderSize + mb->maxindex*MetaIndexSize;
 	for(i=0; i<mb->nindex; i++){
 		if(mc[i].offset - o >= n){
-			vtMemFree(mc);
+			vtfree(mc);
 			return mb->buf + o;
 		}
 		o = mc[i].offset + mc[i].size;
 	}
 
 	if(mb->maxsize - o >= n){
-		vtMemFree(mc);
+		vtfree(mc);
 		return mb->buf + o;
 	}
 
 	/* compact and return off the end */
 	mbCompact(mb, mc);
-	vtMemFree(mc);
+	vtfree(mc);
 
 	if(mb->maxsize - mb->size < n){
-		vtSetError(EBadMeta);
+		werrstr(EBadMeta);
 		return nil;
 	}
 	return mb->buf + mb->size;
@@ -717,7 +717,7 @@
 	return 1;
 Err:
 if(0)print("deUnpack: XXXXXXXXXXXX EBadMeta\n");
-	vtSetError(EBadMeta);
+	werrstr(EBadMeta);
 	deCleanup(dir);
 	return 0;
 }
@@ -725,13 +725,13 @@
 void
 deCleanup(DirEntry *dir)
 {
-	vtMemFree(dir->elem);
+	vtfree(dir->elem);
 	dir->elem = nil;
-	vtMemFree(dir->uid);
+	vtfree(dir->uid);
 	dir->uid = nil;
-	vtMemFree(dir->gid);
+	vtfree(dir->gid);
 	dir->gid = nil;
-	vtMemFree(dir->mid);
+	vtfree(dir->mid);
 	dir->mid = nil;
 }
 
@@ -739,8 +739,8 @@
 deCopy(DirEntry *dst, DirEntry *src)
 {
 	*dst = *src;
-	dst->elem = vtStrDup(src->elem);
-	dst->uid = vtStrDup(src->uid);
-	dst->gid = vtStrDup(src->gid);
-	dst->mid = vtStrDup(src->mid);
+	dst->elem = vtstrdup(src->elem);
+	dst->uid = vtstrdup(src->uid);
+	dst->gid = vtstrdup(src->gid);
+	dst->mid = vtstrdup(src->mid);
 }
diff --git a/src/cmd/fossil/view.c b/src/cmd/fossil/view.c
index c2ac997..54a5586 100644
--- a/src/cmd/fossil/view.c
+++ b/src/cmd/fossil/view.c
@@ -52,9 +52,10 @@
 Tnode *initxroot(char *name, uchar[VtScoreSize]);
 
 int fd;
+int mainstacksize = STACK;
 Header h;
 Super super;
-VtSession *z;
+VtConn *z;
 VtRoot vac;
 int showinactive;
 
@@ -107,7 +108,6 @@
 		return bttab[type];
 	return "unknown";
 }
-#pragma varargck argpos stringnode 1
 
 Block*
 allocBlock(void)
@@ -197,21 +197,21 @@
 
 int vtType[BtMax] = {
 	VtDataType,		/* BtData | 0  */
-	VtPointerType0,		/* BtData | 1  */
-	VtPointerType1,		/* BtData | 2  */
-	VtPointerType2,		/* BtData | 3  */
-	VtPointerType3,		/* BtData | 4  */
-	VtPointerType4,		/* BtData | 5  */
-	VtPointerType5,		/* BtData | 6  */
-	VtPointerType6,		/* BtData | 7  */
+	VtDataType+1,		/* BtData | 1  */
+	VtDataType+2,		/* BtData | 2  */
+	VtDataType+3,		/* BtData | 3  */
+	VtDataType+4,		/* BtData | 4  */
+	VtDataType+5,		/* BtData | 5  */
+	VtDataType+6,		/* BtData | 6  */
+	VtDataType+7,		/* BtData | 7  */
 	VtDirType,		/* BtDir | 0  */
-	VtPointerType0,		/* BtDir | 1  */
-	VtPointerType1,		/* BtDir | 2  */
-	VtPointerType2,		/* BtDir | 3  */
-	VtPointerType3,		/* BtDir | 4  */
-	VtPointerType4,		/* BtDir | 5  */
-	VtPointerType5,		/* BtDir | 6  */
-	VtPointerType6,		/* BtDir | 7  */
+	VtDirType+1,		/* BtDir | 1  */
+	VtDirType+2,		/* BtDir | 2  */
+	VtDirType+3,		/* BtDir | 3  */
+	VtDirType+4,		/* BtDir | 4  */
+	VtDirType+5,		/* BtDir | 5  */
+	VtDirType+6,		/* BtDir | 6  */
+	VtDirType+7,		/* BtDir | 7  */
 };
 
 Block*
@@ -224,13 +224,13 @@
 	memmove(b->score, score, VtScoreSize);
 	b->addr = NilBlock;
 
-	n = vtRead(z, b->score, vtType[type], b->data, h.blockSize);
+	n = vtread(z, b->score, vtType[type], b->data, h.blockSize);
 	if(n < 0){
-		fprint(2, "vtRead returns %d: %R\n", n);
+		fprint(2, "vtread returns %d: %r\n", n);
 		blockPut(b);
 		return nil;
 	}
-	vtZeroExtend(vtType[type], b->data, n, h.blockSize);
+	vtzeroextend(vtType[type], b->data, n, h.blockSize);
 	b->l.type = type;
 	b->l.state = 0;
 	b->l.tag = 0;
@@ -255,7 +255,7 @@
 	if(bl == nil)
 		return nil;
 	if(!labelUnpack(&l, bl->data, addr%lpb)){
-		werrstr("%R");
+		werrstr("%r");
 		blockPut(bl);
 		return nil;
 	}
@@ -363,7 +363,7 @@
 	if(pread(fd, buf, HeaderSize, HeaderOffset) < HeaderSize)
 		return stringnode("error reading header: %r");
 	if(!headerUnpack(&h, buf))
-		return stringnode("error unpacking header: %R");
+		return stringnode("error unpacking header: %r");
 
 	t = stringnode("header "
 		"version=%#ux (%d) "
@@ -403,7 +403,7 @@
 		return stringnode("reading super: %r");
 	if(!superUnpack(&super, b->data)){
 		blockPut(b);
-		return stringnode("unpacking super: %R");
+		return stringnode("unpacking super: %r");
 	}
 	blockPut(b);
 	t = stringnode("super "
@@ -440,15 +440,15 @@
 	uchar buf[VtRootSize];
 	int n;
 
-	if((n = vtRead(z, score, VtRootType, buf, VtRootSize)) < 0)
-		return stringnode("reading root %V: %R", score);
+	if((n = vtread(z, score, VtRootType, buf, VtRootSize)) < 0)
+		return stringnode("reading root %V: %r", score);
 
-	if(!vtRootUnpack(&vac, buf))
-		return stringnode("unpack %d-byte root: %R", n);
+	if(vtrootunpack(&vac, buf) < 0)
+		return stringnode("unpack %d-byte root: %r", n);
 
-	h.blockSize = vac.blockSize;
-	t = stringnode("vac version=%#ux name=%s type=%s blockSize=%ud score=%V prev=%V",
-		vac.version, vac.name, vac.type, vac.blockSize, vac.score, vac.prev);
+	h.blockSize = vac.blocksize;
+	t = stringnode("vac version=%#ux name=%s type=%s blocksize=%lud score=%V prev=%V",
+		VtRootVersion, vac.name, vac.type, vac.blocksize, vac.score, vac.prev);
 	t->expand = xvacrootexpand;
 	return t;
 }
@@ -603,7 +603,7 @@
 	e = *ed;
 	e.depth--;
 	memmove(e.score, b->data+o*VtScoreSize, VtScoreSize);
-	if(memcmp(e.score, vtZeroScore, VtScoreSize) == 0)
+	if(memcmp(e.score, vtzeroscore, VtScoreSize) == 0)
 		return 0;
 	*tp = initxsource(e, 0);
 	return 1;
@@ -614,7 +614,7 @@
 {
 	uint t;
 
-	if(flags&VtEntryDir)
+	if(flags&_VtEntryDir)
 		t = BtDir;
 	else
 		t = BtData;
@@ -635,12 +635,12 @@
 		return stringnode("inactive Entry");
 
 	if(e.depth == 0){
-		if(e.flags & VtEntryDir)
+		if(e.flags & _VtEntryDir)
 			tt = initxentryblock(b, copyEntry(e));
 		else
 			tt = initxdatablock(b, e.dsize);
 	}else{
-		tt = initxblock(b, smprint("%s+%d pointer", (e.flags & VtEntryDir) ? "BtDir" : "BtData", e.depth),
+		tt = initxblock(b, smprint("%s+%d pointer", (e.flags & _VtEntryDir) ? "BtDir" : "BtData", e.depth),
 			ptrgen, copyEntry(e));
 	}
 
@@ -679,7 +679,7 @@
 	localToGlobal(addr, score);
 	b = dataBlock(score, BtDir, RootTag);
 	if(b == nil)
-		return stringnode("read data block %#ux: %R", addr);
+		return stringnode("read data block %#ux: %r", addr);
 	return initxblock(b, smprint("'%s' fs root", name), xlocalrootgen, nil);
 }
 
@@ -702,7 +702,7 @@
 
 	b = dataBlock(score, BtDir, RootTag);
 	if(b == nil)
-		return stringnode("read data block %V: %R", score);
+		return stringnode("read data block %V: %r", score);
 	return initxblock(b, smprint("'%s' fs root", name), xvacrootgen, nil);
 }
 Tnode*
@@ -712,7 +712,7 @@
 	Tnode *t;
 
 	if(!deUnpack(&dir, me))
-		return stringnode("deUnpack: %R");
+		return stringnode("deUnpack: %r");
 
 	t = stringnode("dirEntry elem=%s size=%llud data=%#lux/%#lux meta=%#lux/%#lux", dir.elem, dir.size, dir.entry, dir.gen, dir.mentry, dir.mgen);
 	t->nkid = 1;
@@ -845,16 +845,13 @@
 	Atree *a;
 	uchar score[VtScoreSize];
 
-	vtAttach();
-
 	fmtinstall('V', scoreFmt);
-	fmtinstall('R', vtErrFmt);
 
-	z = vtDial(nil, 1);
+	z = vtdial(nil);
 	if(z == nil)
-		fprint(2, "warning: cannot dial venti: %R\n");
-	if(!vtConnect(z, 0)){
-		fprint(2, "warning: cannot connect to venti: %R\n");
+		fprint(2, "warning: cannot dial venti: %r\n");
+	else if(vtconnect(z) < 0){
+		fprint(2, "warning: cannot connect to venti: %r\n");
 		z = nil;
 	}
 	a = mallocz(sizeof(Atree), 1);
@@ -999,8 +996,8 @@
 void
 usage(void)
 {
-	fprint(2, "usage: vtree /dev/sdC0/fossil\n");
-	exits("usage");
+	fprint(2, "usage: fossil/view /dev/sdC0/fossil\n");
+	threadexitsall("usage");
 }
 
 Tree t;
@@ -1030,7 +1027,7 @@
 Menu menu;
 
 void
-main(int argc, char **argv)
+threadmain(int argc, char **argv)
 {
 	int n;
 	char *dir;
@@ -1106,7 +1103,7 @@
 					break;
 				switch(n){
 				case IExit:
-					exits(nil);
+					threadexitsall(nil);
 				}
 				break;
 			case Right:
diff --git a/src/cmd/fossil/walk.c b/src/cmd/fossil/walk.c
index 802af64..632e3e5 100644
--- a/src/cmd/fossil/walk.c
+++ b/src/cmd/fossil/walk.c
@@ -11,7 +11,7 @@
 {
 	uint t;
 
-	if(e->flags&VtEntryDir)
+	if(e->flags&_VtEntryDir)
 		t = BtDir;
 	else
 		t = BtData;