changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: move Entry and Root back to appl/lib/venti.b. it seems there is where it belongs. still a bit questionable, but plan 9 has it like this, no need to do it differently in inferno.

changeset 127: 7f377ffc9ad3
parent 126: 07b5d02499fd
child 128: 42396bd501da
author: Mechiel Lukkien <mechiel@ueber.net>
date: Mon, 20 Aug 2007 13:51:43 +0200
files: appl/cmd/vacput.b appl/cmd/venti/copy.b appl/cmd/venti/get.b appl/cmd/venti/parse.b appl/cmd/venti/put.b appl/cmd/ventry.b appl/lib/vac.b appl/lib/venti.b module/vac.m module/venti.m
description: move Entry and Root back to appl/lib/venti.b. it seems there is where it belongs. still a bit questionable, but plan 9 has it like this, no need to do it differently in inferno.
     1.1--- a/appl/cmd/vacput.b	Mon Aug 20 13:08:21 2007 +0200
     1.2+++ b/appl/cmd/vacput.b	Mon Aug 20 13:51:43 2007 +0200
     1.3@@ -21,8 +21,8 @@
     1.4 
     1.5 print, sprint, fprint, fildes: import sys;
     1.6 Score, Session: import venti;
     1.7-Rootversion, Roottype, Dirtype, Datatype, Rootsize: import venti;
     1.8-Rootversionvar, Root, Entry, Direntry, Entrysize, File, Sink, MSink, Vacdir: import vac;
     1.9+Entry, Entrysize, Root, Roottype, Dirtype, Datatype: import venti;
    1.10+Direntry, File, Sink, MSink, Vacdir: import vac;
    1.11 Rcfg, Rfile: import rabin;
    1.12 
    1.13 Vacput: module {
    1.14@@ -31,7 +31,7 @@
    1.15 
    1.16 addr := "net!$venti!venti";
    1.17 Dflag, vflag, qflag, rflag: int;
    1.18-blocksize := vac->Dsize;
    1.19+blocksize := Venti->Dsize;
    1.20 session: ref Session;
    1.21 name := "vac";
    1.22 basescore: ref Score;
    1.23@@ -108,11 +108,11 @@
    1.24 		if(err != nil)
    1.25 			error("opening base score: "+err);
    1.26 
    1.27-		d := session.read(*basescore, Roottype, Rootsize);
    1.28+		d := session.read(*basescore, Roottype, Venti->Rootsize);
    1.29 		if(d == nil)
    1.30 			error("reading base root block: "+err);
    1.31 		r := Root.unpack(d);
    1.32-		if(rflag && r.version != Rootversionvar || !rflag && r.version != Rootversion)
    1.33+		if(rflag && r.version != Venti->Rootversionvar || !rflag && r.version != Venti->Rootversion)
    1.34 			error("old archive not of same type as new archive");
    1.35 	}
    1.36 
    1.37@@ -159,7 +159,7 @@
    1.38 
    1.39 	root := Root.new(name, "vac", tscore, blocksize, nil);
    1.40 	if(rflag) {
    1.41-		root.version = Vac->Rootversionvar;
    1.42+		root.version = Venti->Rootversionvar;
    1.43 		root.blocksize = 0;
    1.44 	}
    1.45 	if(basescore != nil)
     2.1--- a/appl/cmd/venti/copy.b	Mon Aug 20 13:08:21 2007 +0200
     2.2+++ b/appl/cmd/venti/copy.b	Mon Aug 20 13:51:43 2007 +0200
     2.3@@ -9,15 +9,13 @@
     2.4 include "arg.m";
     2.5 include "string.m";
     2.6 include "venti.m";
     2.7-include "vac.m";
     2.8 
     2.9 str: String;
    2.10 venti: Venti;
    2.11-vac: Vac;
    2.12 
    2.13 print, sprint, fprint, fildes: import sys;
    2.14-Pointertype0, Pointertype6, Score, Session, Roottype, Dirtype, Datatype, Scoresize: import venti;
    2.15-Pointervarmask, Root, Rootsize, Entry, Entrysize, Entryactive, Entrydir: import vac;
    2.16+Pointertype0, Pointertype6, Score, Session, Roottype, Dirtype, Datatype, Scoresize, Pointervarmask, Root, Rootsize, Entry, Entrysize, Entryactive, Entrydir: import venti;
    2.17+
    2.18 
    2.19 Venticopy: module {
    2.20 	init:	fn(nil: ref Draw->Context, args: list of string);
    2.21@@ -34,10 +32,8 @@
    2.22 	arg := load Arg Arg->PATH;
    2.23 	str = load String String->PATH;
    2.24 	venti = load Venti Venti->PATH;
    2.25-	vac = load Vac Vac->PATH;
    2.26 
    2.27 	venti->init();
    2.28-	vac->init();
    2.29 
    2.30 	arg->init(args);
    2.31 	arg->setusage(sprint("%s [-df] srcaddr dstaddr [vac:]score", arg->progname()));
    2.32@@ -112,7 +108,7 @@
    2.33 			if(!(e.flags&Entryactive))
    2.34 				continue;
    2.35 			tvar := 0;
    2.36-			if(e.flags & Vac->Entryvarblocks)
    2.37+			if(e.flags & Venti->Entryvarblocks)
    2.38 				tvar = Pointervarmask;
    2.39 			nt := Datatype;
    2.40 			if(e.flags&Entrydir)
     3.1--- a/appl/cmd/venti/get.b	Mon Aug 20 13:08:21 2007 +0200
     3.2+++ b/appl/cmd/venti/get.b	Mon Aug 20 13:51:43 2007 +0200
     3.3@@ -16,9 +16,8 @@
     3.4 vac: Vac;
     3.5 
     3.6 print, sprint, fprint, fildes: import sys;
     3.7-Score, Session: import venti;
     3.8-Dirtype, Datatype: import venti;
     3.9-Entry, Entrysize, Vacfile: import vac;
    3.10+Score, Session, Entry, Entrysize, Dirtype, Datatype: import venti;
    3.11+Vacfile: import vac;
    3.12 
    3.13 Ventiget: module {
    3.14 	init:	fn(nil: ref Draw->Context, args: list of string);
     4.1--- a/appl/cmd/venti/parse.b	Mon Aug 20 13:08:21 2007 +0200
     4.2+++ b/appl/cmd/venti/parse.b	Mon Aug 20 13:51:43 2007 +0200
     4.3@@ -13,8 +13,8 @@
     4.4 vac: Vac;
     4.5 
     4.6 fprint, sprint, print, fildes: import sys;
     4.7-Score, Scoresize, Dirtype, Datatype, Pointertype0: import venti;
     4.8-Pointervarmask, Root, Entry, Direntry, Metablock, Metaentry, Entrysize, Metablocksize, Metaentrysize, Entrydir: import vac;
     4.9+Score, Scoresize, Pointervarmask, Root, Entry, Entrysize, Entrydir, Dirtype, Datatype, Pointertype0: import venti;
    4.10+Direntry, Metablock, Metaentry, Metablocksize, Metaentrysize: import vac;
    4.11 
    4.12 Ventiparse: module {
    4.13 	init:	fn(nil: ref Draw->Context, args: list of string);
    4.14@@ -182,7 +182,7 @@
    4.15 	if(e.depth > 0) {
    4.16 		which := "pointers";
    4.17 		dtype := Pointertype0+e.depth-1;
    4.18-		if(e.flags & Vac->Entryvarblocks) {
    4.19+		if(e.flags & Venti->Entryvarblocks) {
    4.20 			which = "rpointers";
    4.21 			dtype |= Pointervarmask;
    4.22 		}
    4.23@@ -242,7 +242,7 @@
    4.24 		if(mb == nil)
    4.25 			error(sprint("unpacking metablock: %r"));
    4.26 		printmetablock(mb, d[i:], 1);
    4.27-		i += Vac->Dsize;
    4.28+		i += Venti->Dsize;
    4.29 	}
    4.30 }
    4.31 
     5.1--- a/appl/cmd/venti/put.b	Mon Aug 20 13:08:21 2007 +0200
     5.2+++ b/appl/cmd/venti/put.b	Mon Aug 20 13:51:43 2007 +0200
     5.3@@ -16,9 +16,8 @@
     5.4 rabin: Rabin;
     5.5 
     5.6 print, sprint, fprint, fildes: import sys;
     5.7-Score, Session: import venti;
     5.8-Dirtype, Datatype: import venti;
     5.9-Entry, File: import vac;
    5.10+Score, Session, Entry, Dirtype, Datatype: import venti;
    5.11+File: import vac;
    5.12 Rcfg, Rfile: import rabin;
    5.13 
    5.14 Ventiput: module {
    5.15@@ -28,7 +27,7 @@
    5.16 addr := "net!$venti!venti";
    5.17 dflag := 0;
    5.18 rflag := 0;
    5.19-blocksize := vac->Dsize;
    5.20+blocksize := Venti->Dsize;
    5.21 session: ref Session;
    5.22 
    5.23 init(nil: ref Draw->Context, args: list of string)
     6.1--- a/appl/cmd/ventry.b	Mon Aug 20 13:08:21 2007 +0200
     6.2+++ b/appl/cmd/ventry.b	Mon Aug 20 13:51:43 2007 +0200
     6.3@@ -14,8 +14,8 @@
     6.4 vac: Vac;
     6.5 
     6.6 print, sprint, fprint, fildes: import sys;
     6.7-Score, Session, Datatype, Dirtype: import venti;
     6.8-Entry, Entrysize, Vacfile, Source: import vac;
     6.9+Score, Session, Entry, Entrysize, Datatype, Dirtype: import venti;
    6.10+Vacfile, Source: import vac;
    6.11 
    6.12 Ventry: module {
    6.13 	init:	fn(nil: ref Draw->Context, args: list of string);
     7.1--- a/appl/lib/vac.b	Mon Aug 20 13:08:21 2007 +0200
     7.2+++ b/appl/lib/vac.b	Mon Aug 20 13:51:43 2007 +0200
     7.3@@ -10,7 +10,8 @@
     7.4 venti: Venti;
     7.5 
     7.6 werrstr, sprint, fprint, fildes: import sys;
     7.7-Roottype, Dirtype, Pointertype0, Datatype: import venti;
     7.8+Root, Rootsize, Entry, Entrysize, Roottype, Dirtype, Pointertype0, Datatype: import venti;
     7.9+Pointervarmask, Entryactive, Entrydir, Entrydepthshift, Entrydepthmask, Entrylocal, Entryvarblocks: import venti;
    7.10 Score, Session, Scoresize: import venti;
    7.11 
    7.12 debug := 0;
    7.13@@ -81,132 +82,6 @@
    7.14 	return (string a[o:e], e);
    7.15 }
    7.16 
    7.17-gtstring(a: array of byte, o: int, n: int): string
    7.18-{
    7.19-	e := o + n;
    7.20-	if(e > len a)
    7.21-		return nil;
    7.22-	for(i := o; i < e; i++)
    7.23-		if(a[i] == byte 0)
    7.24-			break;
    7.25-	return string a[o:i];
    7.26-}
    7.27-
    7.28-
    7.29-Root.new(name, rtype: string, score: Score, blocksize: int, prev: ref Score): ref Root
    7.30-{
    7.31-	return ref Root(Rootversion, name, rtype, score, blocksize, prev);
    7.32-}
    7.33-
    7.34-Root.pack(r: self ref Root): array of byte
    7.35-{
    7.36-	d := array[Rootsize] of byte;
    7.37-	i := 0;
    7.38-	i = p16(d, i, r.version);
    7.39-	i = ptstring(d, i, r.name, Rootnamelen);
    7.40-	if(i < 0)
    7.41-		return nil;
    7.42-	i = ptstring(d, i, r.rtype, Rootnamelen);
    7.43-	if(i < 0)
    7.44-		return nil;
    7.45-	i = pscore(d, i, r.score);
    7.46-	i = p16(d, i, r.blocksize);
    7.47-	if(r.prev == nil) {
    7.48-		for(j := 0; j < Scoresize; j++)
    7.49-			d[i+j] = byte 0;
    7.50-		i += Scoresize;
    7.51-	} else 
    7.52-		i = pscore(d, i, *r.prev);
    7.53-	if(i != len d) {
    7.54-		sys->werrstr("root pack, bad length: "+string i);
    7.55-		return nil;
    7.56-	}
    7.57-	return d;
    7.58-}
    7.59-
    7.60-Root.unpack(d: array of byte): ref Root
    7.61-{
    7.62-	if(len d != Rootsize){
    7.63-		sys->werrstr("root entry is wrong length");
    7.64-		return nil;
    7.65-	}
    7.66-	r := ref blankroot;
    7.67-	r.version = g16(d, 0);
    7.68-	if(r.version != Rootversion && r.version != Rootversionvar){
    7.69-		sys->werrstr("unknown root version");
    7.70-		return nil;
    7.71-	}
    7.72-	o := BIT16SZ;
    7.73-	r.name = gtstring(d, o, Rootnamelen);
    7.74-	o += Rootnamelen;
    7.75-	r.rtype = gtstring(d, o, Rootnamelen);
    7.76-	o += Rootnamelen;
    7.77-	r.score = gscore(d, o);
    7.78-	o += Scoresize;
    7.79-	r.blocksize = g16(d, o);
    7.80-	o += BIT16SZ;
    7.81-	r.prev = ref gscore(d, o);
    7.82-	return r;
    7.83-}
    7.84-
    7.85-Entry.new(psize, dsize, flags: int, size: big, score: Venti->Score): ref Entry
    7.86-{
    7.87-	return ref Entry(0, psize, dsize, (flags&Entrydepthmask)>>Entrydepthshift, flags, size, score);
    7.88-}
    7.89-
    7.90-Entry.pack(e: self ref Entry): array of byte
    7.91-{
    7.92-	d := array[Entrysize] of byte;
    7.93-	i := 0;
    7.94-	i = p32(d, i, e.gen);
    7.95-	i = p16(d, i, e.psize);
    7.96-	i = p16(d, i, e.dsize);
    7.97-	e.flags |= e.depth<<Entrydepthshift;
    7.98-	d[i++] = byte e.flags;
    7.99-	for(j := 0; j < 5; j++)
   7.100-		d[i++] = byte 0;
   7.101-	i = p48(d, i, e.size);
   7.102-	i = pscore(d, i, e.score);
   7.103-	if(i != len d) {
   7.104-		werrstr(sprint("bad length, have %d, want %d", i, len d));
   7.105-		return nil;
   7.106-	}
   7.107-	return d;
   7.108-}
   7.109-
   7.110-Entry.unpack(d: array of byte): ref Entry
   7.111-{
   7.112-	if(len d != Entrysize){
   7.113-		sys->werrstr("entry is wrong length");
   7.114-		return nil;
   7.115-	}
   7.116-	e := ref blankentry;
   7.117-	i := 0;
   7.118-	e.gen = g32(d, i);
   7.119-	i += BIT32SZ;
   7.120-	e.psize = g16(d, i);
   7.121-	i += BIT16SZ;
   7.122-	e.dsize = g16(d, i);
   7.123-	i += BIT16SZ;
   7.124-	e.flags = int d[i];
   7.125-	e.depth = (e.flags & Entrydepthmask) >> Entrydepthshift;
   7.126-	e.flags &= ~Entrydepthmask;
   7.127-	i += BIT8SZ;
   7.128-	i += 5;			# padding
   7.129-	e.size = g48(d, i);
   7.130-	i += BIT48SZ;
   7.131-	e.score = gscore(d, i);
   7.132-	i += Scoresize;
   7.133-	if((e.flags & Entryactive) == 0)
   7.134-		return e;
   7.135-	varblocks := e.flags&Entryvarblocks;
   7.136-	if(!checksize(e.psize) || (varblocks && e.dsize != 0 || !varblocks && !checksize(e.dsize))){
   7.137-		sys->werrstr(sys->sprint("bad blocksize (%d or %d)", e.psize, e.dsize));
   7.138-		return nil;
   7.139-	}
   7.140-	return e;
   7.141-}
   7.142-
   7.143 Direntry.new(): ref Direntry
   7.144 {
   7.145 	return ref Direntry(9, "", 0, 0, 0, 0, big 0, "", "", "", 0, 0, 0, 0, 0, 0);
   7.146@@ -537,7 +412,7 @@
   7.147 	s := e.score;
   7.148 	dsize := e.dsize;
   7.149 	if(dsize == 0)
   7.150-		dsize = Dsize;	# xxx not clean
   7.151+		dsize = Venti->Dsize;	# xxx not clean
   7.152 	if(e.depth == 0) {
   7.153 		p := Page.new(dsize, varblocks);
   7.154 		return ref File(array[1] of {p}, Datatype, dsize, big 0, session, varblocks);
   7.155@@ -1123,22 +998,6 @@
   7.156 	return (tag, ref s, nil);
   7.157 }
   7.158 
   7.159-checksize(n: int): int
   7.160-{
   7.161-	if(n < 256 || n > Venti->Maxlumpsize) {
   7.162-		sys->werrstr("bad block size");
   7.163-		return 0;
   7.164-	}
   7.165-	return 1;
   7.166-}
   7.167-
   7.168-gscore(f: array of byte, i: int): Score
   7.169-{
   7.170-	s := Score(array[Scoresize] of byte);
   7.171-	s.a[0:] = f[i:i+Scoresize];
   7.172-	return s;
   7.173-}
   7.174-
   7.175 g16(f: array of byte, i: int): int
   7.176 {
   7.177 	return (int f[i] << 8) | int f[i+1];
   7.178@@ -1191,39 +1050,12 @@
   7.179 	return i+BIT64SZ;
   7.180 }
   7.181 
   7.182-ptstring(d: array of byte, i: int, s: string, l: int): int
   7.183-{
   7.184-	a := array of byte s;
   7.185-	if(len a > l) {
   7.186-		sys->werrstr("string too long: "+s);
   7.187-		return -1;
   7.188-	}
   7.189-	for(j := 0; j < len a; j++)
   7.190-		d[i+j] = a[j];
   7.191-	while(j < l)
   7.192-		d[i+j++] = byte 0;
   7.193-	return i+l;
   7.194-}
   7.195-
   7.196-pscore(d: array of byte, i: int, s: Score): int
   7.197-{
   7.198-	for(j := 0; j < Scoresize; j++)
   7.199-		d[i+j] = s.a[j];
   7.200-	return i+Scoresize;
   7.201-}
   7.202-
   7.203 echeck(f: array of byte, i: int, l: int)
   7.204 {
   7.205 	if(i+l > len f)
   7.206 		raise sprint("too small: buffer length is %d, requested %d bytes starting at offset %d", len f, l, i);
   7.207 }
   7.208 
   7.209-egscore(f: array of byte, i: int): (Score, int)
   7.210-{
   7.211-	echeck(f, i, Scoresize);
   7.212-	return (gscore(f, i), i+Scoresize);
   7.213-}
   7.214-
   7.215 egstring(a: array of byte, o: int): (string, int)
   7.216 {
   7.217 	(s, no) := gstring(a, o);
     8.1--- a/appl/lib/venti.b	Mon Aug 20 13:08:21 2007 +0200
     8.2+++ b/appl/lib/venti.b	Mon Aug 20 13:51:43 2007 +0200
     8.3@@ -8,6 +8,7 @@
     8.4 BIT16SZ:	con 2;
     8.5 BIT32SZ:	con 4;
     8.6 BIT48SZ:	con 6;
     8.7+BIT64SZ:	con 8;
     8.8 SCORE:	con 20;
     8.9 STR:		con BIT16SZ;
    8.10 H: con BIT16SZ+BIT8SZ+BIT8SZ;		# minimum header length: size[2] op[1] tid[1]
    8.11@@ -473,6 +474,123 @@
    8.12 	return s;
    8.13 }
    8.14 
    8.15+
    8.16+Root.new(name, rtype: string, score: Score, blocksize: int, prev: ref Score): ref Root
    8.17+{
    8.18+	return ref Root(Rootversion, name, rtype, score, blocksize, prev);
    8.19+}
    8.20+
    8.21+Root.pack(r: self ref Root): array of byte
    8.22+{
    8.23+	d := array[Rootsize] of byte;
    8.24+	i := 0;
    8.25+	i = p16(d, i, r.version);
    8.26+	i = ptstring(d, i, r.name, Rootnamelen);
    8.27+	if(i < 0)
    8.28+		return nil;
    8.29+	i = ptstring(d, i, r.rtype, Rootnamelen);
    8.30+	if(i < 0)
    8.31+		return nil;
    8.32+	i = pscore(d, i, r.score);
    8.33+	i = p16(d, i, r.blocksize);
    8.34+	if(r.prev == nil) {
    8.35+		for(j := 0; j < Scoresize; j++)
    8.36+			d[i+j] = byte 0;
    8.37+		i += Scoresize;
    8.38+	} else 
    8.39+		i = pscore(d, i, *r.prev);
    8.40+	if(i != len d) {
    8.41+		sys->werrstr("root pack, bad length: "+string i);
    8.42+		return nil;
    8.43+	}
    8.44+	return d;
    8.45+}
    8.46+
    8.47+Root.unpack(d: array of byte): ref Root
    8.48+{
    8.49+	if(len d != Rootsize){
    8.50+		sys->werrstr("root entry is wrong length");
    8.51+		return nil;
    8.52+	}
    8.53+	r := ref blankroot;
    8.54+	r.version = g16(d, 0);
    8.55+	if(r.version != Rootversion && r.version != Rootversionvar){
    8.56+		sys->werrstr("unknown root version");
    8.57+		return nil;
    8.58+	}
    8.59+	o := BIT16SZ;
    8.60+	r.name = gtstring(d, o, Rootnamelen);
    8.61+	o += Rootnamelen;
    8.62+	r.rtype = gtstring(d, o, Rootnamelen);
    8.63+	o += Rootnamelen;
    8.64+	r.score = gscore(d, o);
    8.65+	o += Scoresize;
    8.66+	r.blocksize = g16(d, o);
    8.67+	o += BIT16SZ;
    8.68+	r.prev = ref gscore(d, o);
    8.69+	return r;
    8.70+}
    8.71+
    8.72+
    8.73+Entry.new(psize, dsize, flags: int, size: big, score: Venti->Score): ref Entry
    8.74+{
    8.75+	return ref Entry(0, psize, dsize, (flags&Entrydepthmask)>>Entrydepthshift, flags, size, score);
    8.76+}
    8.77+
    8.78+Entry.pack(e: self ref Entry): array of byte
    8.79+{
    8.80+	d := array[Entrysize] of byte;
    8.81+	i := 0;
    8.82+	i = p32(d, i, e.gen);
    8.83+	i = p16(d, i, e.psize);
    8.84+	i = p16(d, i, e.dsize);
    8.85+	e.flags |= e.depth<<Entrydepthshift;
    8.86+	d[i++] = byte e.flags;
    8.87+	for(j := 0; j < 5; j++)
    8.88+		d[i++] = byte 0;
    8.89+	i = p48(d, i, e.size);
    8.90+	i = pscore(d, i, e.score);
    8.91+	if(i != len d) {
    8.92+		sys->werrstr(sys->sprint("bad length, have %d, want %d", i, len d));
    8.93+		return nil;
    8.94+	}
    8.95+	return d;
    8.96+}
    8.97+
    8.98+Entry.unpack(d: array of byte): ref Entry
    8.99+{
   8.100+	if(len d != Entrysize){
   8.101+		sys->werrstr("entry is wrong length");
   8.102+		return nil;
   8.103+	}
   8.104+	e := ref blankentry;
   8.105+	i := 0;
   8.106+	e.gen = g32(d, i);
   8.107+	i += BIT32SZ;
   8.108+	e.psize = g16(d, i);
   8.109+	i += BIT16SZ;
   8.110+	e.dsize = g16(d, i);
   8.111+	i += BIT16SZ;
   8.112+	e.flags = int d[i];
   8.113+	e.depth = (e.flags & Entrydepthmask) >> Entrydepthshift;
   8.114+	e.flags &= ~Entrydepthmask;
   8.115+	i += BIT8SZ;
   8.116+	i += 5;			# padding
   8.117+	e.size = g48(d, i);
   8.118+	i += BIT48SZ;
   8.119+	e.score = gscore(d, i);
   8.120+	i += Scoresize;
   8.121+	if((e.flags & Entryactive) == 0)
   8.122+		return e;
   8.123+	varblocks := e.flags&Entryvarblocks;
   8.124+	if(!checksize(e.psize) || (varblocks && e.dsize != 0 || !varblocks && !checksize(e.dsize))){
   8.125+		sys->werrstr(sys->sprint("bad blocksize (%d or %d)", e.psize, e.dsize));
   8.126+		return nil;
   8.127+	}
   8.128+	return e;
   8.129+}
   8.130+
   8.131+
   8.132 readn(fd: ref Sys->FD, buf: array of byte, nb: int): int
   8.133 {
   8.134 	for(nr := 0; nr < nb;){
   8.135@@ -555,3 +673,90 @@
   8.136 		}
   8.137 	return n;
   8.138 }
   8.139+
   8.140+checksize(n: int): int
   8.141+{
   8.142+	if(n < 256 || n > Venti->Maxlumpsize) {
   8.143+		sys->werrstr("bad block size");
   8.144+		return 0;
   8.145+	}
   8.146+	return 1;
   8.147+}
   8.148+
   8.149+gtstring(a: array of byte, o: int, n: int): string
   8.150+{
   8.151+	e := o + n;
   8.152+	if(e > len a)
   8.153+		return nil;
   8.154+	for(i := o; i < e; i++)
   8.155+		if(a[i] == byte 0)
   8.156+			break;
   8.157+	return string a[o:i];
   8.158+}
   8.159+
   8.160+gscore(f: array of byte, i: int): Score
   8.161+{
   8.162+	s := Score(array[Scoresize] of byte);
   8.163+	s.a[0:] = f[i:i+Scoresize];
   8.164+	return s;
   8.165+}
   8.166+
   8.167+g16(f: array of byte, i: int): int
   8.168+{
   8.169+	return (int f[i] << 8) | int f[i+1];
   8.170+}
   8.171+
   8.172+g32(f: array of byte, i: int): int
   8.173+{
   8.174+	return (((((int f[i+0] << 8) | int f[i+1]) << 8) | int f[i+2]) << 8) | int f[i+3];
   8.175+}
   8.176+
   8.177+g48(f: array of byte, i: int): big
   8.178+{
   8.179+	b1 := (((((int f[i+0] << 8) | int f[i+1]) << 8) | int f[i+2]) << 8) | int f[i+3];
   8.180+	b0 := (int f[i+4] << 8) | int f[i+5];
   8.181+	return (big b1 << 16) | big b0;
   8.182+}
   8.183+
   8.184+p16(d: array of byte, i: int, v: int): int
   8.185+{
   8.186+	d[i+0] = byte (v>>8);
   8.187+	d[i+1] = byte v;
   8.188+	return i+BIT16SZ;
   8.189+}
   8.190+
   8.191+p32(d: array of byte, i: int, v: int): int
   8.192+{
   8.193+	p16(d, i+0, v>>16);
   8.194+	p16(d, i+2, v);
   8.195+	return i+BIT32SZ;
   8.196+}
   8.197+
   8.198+p48(d: array of byte, i: int, v: big): int
   8.199+{
   8.200+	p16(d, i+0, int (v>>32));
   8.201+	p32(d, i+2, int v);
   8.202+	return i+BIT48SZ;
   8.203+}
   8.204+
   8.205+ptstring(d: array of byte, i: int, s: string, l: int): int
   8.206+{
   8.207+	a := array of byte s;
   8.208+	if(len a > l) {
   8.209+		sys->werrstr("string too long: "+s);
   8.210+		return -1;
   8.211+	}
   8.212+	for(j := 0; j < len a; j++)
   8.213+		d[i+j] = a[j];
   8.214+	while(j < l)
   8.215+		d[i+j++] = byte 0;
   8.216+	return i+l;
   8.217+}
   8.218+
   8.219+pscore(d: array of byte, i: int, s: Score): int
   8.220+{
   8.221+	for(j := 0; j < Scoresize; j++)
   8.222+		d[i+j] = s.a[j];
   8.223+	return i+Scoresize;
   8.224+}
   8.225+
     9.1--- a/module/vac.m	Mon Aug 20 13:08:21 2007 +0200
     9.2+++ b/module/vac.m	Mon Aug 20 13:51:43 2007 +0200
     9.3@@ -24,23 +24,9 @@
     9.4 	Modedev,
     9.5 	Modenamedpipe: con 1<<(9+iota);
     9.6 
     9.7-	Entrysize:	con 40;
     9.8-	Rootsize:	con 300;
     9.9 	Metablocksize:	con 12;
    9.10 	Metaentrysize:	con 4;
    9.11 
    9.12-	Rootversionvar:	con 3;	# xxx move to venti.m
    9.13-	Pointervarmask:	con (1<<4);	# xxx move to venti.m
    9.14-
    9.15-	Dsize:	con 8*1024;
    9.16-
    9.17-	Entryactive:	con (1<<0);	# entry is in use
    9.18-	Entrydir:	con (1<<1);	# a directory
    9.19-	Entrydepthshift:	con 2;	# shift for pointer depth
    9.20-	Entrydepthmask:	con (16r7<<2);	# mask for pointer depth
    9.21-	Entrylocal:	con (1<<5);	# used for local storage: should not be set for venti blocks
    9.22-	Entryvarblocks:	con (1<<7);	# variable block size, e.g. for rabin fingerprinting
    9.23-
    9.24 	Direntrymagic:	con 16r1c4d9072;
    9.25 	Metablockmagic:	con 16r5656fc79;
    9.26 
    9.27@@ -51,33 +37,6 @@
    9.28 	Rabinblockmin:	con 1024;
    9.29 	Rabinblockmax:	con 32*1024;
    9.30 
    9.31-	Root: adt {
    9.32-		version:	int;
    9.33-		name:	string;
    9.34-		rtype:	string;
    9.35-		score:	Venti->Score;		# to a Dir block
    9.36-		blocksize:	int;				# maximum block size
    9.37-		prev:		ref Venti->Score;		# last root block
    9.38-
    9.39-		new:	fn(name, rtype: string, score: Venti->Score, blocksize: int, prev: ref Venti->Score): ref Root;
    9.40-		unpack:	fn(d: array of byte): ref Root;
    9.41-		pack:	fn(r: self ref Root): array of byte;
    9.42-	};
    9.43-
    9.44-	Entry: adt {
    9.45-		gen:		int;		# generation number (XXX should be unsigned)
    9.46-		psize:	int;		# pointer block size
    9.47-		dsize:	int;		# data block size
    9.48-		depth:	int;		# unpacked from flags
    9.49-		flags:	int;
    9.50-		size:		big;		# (XXX should be unsigned)
    9.51-		score:	Venti->Score;
    9.52-
    9.53-		new:	fn(psize, dsize, flags: int, size: big, score: Venti->Score): ref Entry;
    9.54-		pack:	fn(e: self ref Entry): array of byte;
    9.55-		unpack:	fn(d: array of byte): ref Entry;
    9.56-	};
    9.57-
    9.58 	Direntry: adt {
    9.59 		version:	int;
    9.60 		elem:	string;
    9.61@@ -133,8 +92,8 @@
    9.62 
    9.63 		new:	fn(s: ref Venti->Session, dtype, dsize, varblocks: int): ref File;
    9.64 		write:	fn(f: self ref File, d: array of byte): int;
    9.65-		finish:	fn(f: self ref File): ref Entry;
    9.66-		mkstate:	fn(session: ref Venti->Session, e: ref Entry, varblocks: int): ref File;
    9.67+		finish:	fn(f: self ref File): ref Venti->Entry;
    9.68+		mkstate:	fn(session: ref Venti->Session, e: ref Venti->Entry, varblocks: int): ref File;
    9.69 	};
    9.70 
    9.71 	# for writing venti directories (entries)
    9.72@@ -144,8 +103,8 @@
    9.73 		nd, ne:	int;
    9.74 
    9.75 		new:	fn(s: ref Venti->Session, dsize: int): ref Sink;
    9.76-		add:	fn(m: self ref Sink, e: ref Entry): int;
    9.77-		finish:	fn(m: self ref Sink): ref Entry;
    9.78+		add:	fn(m: self ref Sink, e: ref Venti->Entry): int;
    9.79+		finish:	fn(m: self ref Sink): ref Venti->Entry;
    9.80 	};
    9.81 
    9.82 	Mentry: adt {
    9.83@@ -164,15 +123,15 @@
    9.84 
    9.85 		new:	fn(s: ref Venti->Session, dsize: int): ref MSink;
    9.86 		add:	fn(m: self ref MSink, de: ref Direntry): int;
    9.87-		finish:	fn(m: self ref MSink): ref Entry;
    9.88+		finish:	fn(m: self ref MSink): ref Venti->Entry;
    9.89 	};
    9.90 
    9.91 	# for reading pages from a hash tree referenced by an entry
    9.92 	Source: adt {
    9.93 		session:	ref Venti->Session;
    9.94-		e:	ref Entry;
    9.95+		e:	ref Venti->Entry;
    9.96 
    9.97-		new:	fn(s: ref Venti->Session, e: ref Entry): ref Source;
    9.98+		new:	fn(s: ref Venti->Session, e: ref Venti->Entry): ref Source;
    9.99 		get:	fn(s: self ref Source, i: big, d: array of byte): int;
   9.100 		oget:	fn(s: self ref Source, offset: big): array of byte;
   9.101 	};
   9.102@@ -183,7 +142,7 @@
   9.103 		o:	big;
   9.104 
   9.105 		mk:	fn(s: ref Source): ref Vacfile;
   9.106-		new:	fn(session: ref Venti->Session, e: ref Entry): ref Vacfile;
   9.107+		new:	fn(session: ref Venti->Session, e: ref Venti->Entry): ref Vacfile;
   9.108 		read:	fn(v: self ref Vacfile, d: array of byte, n: int): int;
   9.109 		seek:	fn(v: self ref Vacfile, offset: big): big;
   9.110 		pread:	fn(v: self ref Vacfile, d: array of byte, n: int, offset: big): int;
   9.111@@ -197,9 +156,9 @@
   9.112 		i:	int;
   9.113 
   9.114 		mk:	fn(vf: ref Vacfile, ms: ref Source): ref Vacdir;
   9.115-		new:	fn(session: ref Venti->Session, e, me: ref Entry): ref Vacdir;
   9.116+		new:	fn(session: ref Venti->Session, e, me: ref Venti->Entry): ref Vacdir;
   9.117 		walk:	fn(v: self ref Vacdir, elem: string): ref Direntry;
   9.118-		open:	fn(v: self ref Vacdir, de: ref Direntry): (ref Entry, ref Entry);
   9.119+		open:	fn(v: self ref Vacdir, de: ref Direntry): (ref Venti->Entry, ref Venti->Entry);
   9.120 		readdir:	fn(v: self ref Vacdir): (int, ref Direntry);
   9.121 		rewind:		fn(v: self ref Vacdir);
   9.122 	};
    10.1--- a/module/venti.m	Mon Aug 20 13:08:21 2007 +0200
    10.2+++ b/module/venti.m	Mon Aug 20 13:51:43 2007 +0200
    10.3@@ -69,12 +69,18 @@
    10.4 	Entrydepthshift: con 2;				# shift for pointer depth
    10.5 	Entrydepthmask: con (16r7<<2);		# mask for pointer depth
    10.6 	Entrylocal: con (1<<5);				# used for local storage: should not be set for venti blocks
    10.7+	Entryvarblocks:	con (1<<7);		# variable block size, e.g. for rabin fingerprinting
    10.8 
    10.9 	Maxlumpsize:	con 56 * 1024;
   10.10 	Pointerdepth:	con 7;
   10.11 	Entrysize:		con 40;
   10.12 	Rootsize:		con 300;
   10.13 	Rootversion:	con 2;
   10.14+	Rootversionvar: con 3;
   10.15+
   10.16+	Pointervarmask: con (1<<4);
   10.17+
   10.18+	Dsize:	con 8*1024;
   10.19 
   10.20 	Maxfilesize:	con (big 1 << 48) - big 1;
   10.21 
   10.22@@ -124,7 +130,11 @@
   10.23 		rtype:	string;
   10.24 		score:	Venti->Score;		# to a Dir block
   10.25 		blocksize:	int;				# maximum block size
   10.26-		prev:		Venti->Score;		# last root block
   10.27+		prev:		ref Venti->Score;		# last root block
   10.28+
   10.29+		new:	fn(name, rtype: string, score: Venti->Score, blocksize: int, prev: ref Venti->Score): ref Root;
   10.30+		unpack:	fn(d: array of byte): ref Root;
   10.31+		pack:	fn(r: self ref Root): array of byte;
   10.32 	};
   10.33 
   10.34 	Entry: adt {
   10.35@@ -135,7 +145,12 @@
   10.36 		flags:	int;
   10.37 		size:		big;		# (XXX should be unsigned)
   10.38 		score:	Venti->Score;
   10.39+
   10.40+		new:	fn(psize, dsize, flags: int, size: big, score: Venti->Score): ref Entry;
   10.41+		pack:	fn(e: self ref Entry): array of byte;
   10.42+		unpack:	fn(d: array of byte): ref Entry;
   10.43 	};
   10.44+
   10.45 	Score: adt {
   10.46 		a: array of byte;
   10.47 		eq:		fn(a: self Score, b: Score): int;
   10.48@@ -143,6 +158,7 @@
   10.49 		parse:	fn(s: string): (int, Score);
   10.50 		zero:		fn(): Score;
   10.51 	};
   10.52+
   10.53 	Session: adt {
   10.54 		fd:		ref Sys->FD;
   10.55 		version:	string;
   10.56@@ -153,5 +169,6 @@
   10.57 		sync:	fn(s: self ref Session): int;
   10.58 		rpc:		fn(s: self ref Session, m: ref Vmsg): (ref Vmsg, string);
   10.59 	};
   10.60+
   10.61 	init:	fn();
   10.62 };