changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > ventivac / changeset: make venti/parse guess the type of the block based on contents when the type isn't specified on the command-line.

changeset 94: b9bb5133d444
parent 93: e90e73b6c2e7
child 95: 12540c444626
author: Mechiel Lukkien <mechiel@ueber.net>
date: Mon, 06 Aug 2007 14:42:23 +0200
files: appl/cmd/venti/parse.b appl/lib/vac.b man/1/venti module/vac.m
description: make venti/parse guess the type of the block based on contents when the type isn't specified on the command-line.
     1.1--- a/appl/cmd/venti/parse.b	Mon Aug 06 12:12:12 2007 +0200
     1.2+++ b/appl/cmd/venti/parse.b	Mon Aug 06 14:42:23 2007 +0200
     1.3@@ -33,17 +33,27 @@
     1.4 	vac->init();
     1.5 
     1.6 	arg->init(args);
     1.7-	arg->setusage(arg->progname() + " type");
     1.8+	arg->setusage(arg->progname() + " [type]");
     1.9 	while((c := arg->opt()) != 0)
    1.10 		case c {
    1.11 		* =>	fprint(fildes(2), "bad option: -%c\n", c);
    1.12 			arg->usage();
    1.13 		}
    1.14 	args = arg->argv();
    1.15-	if(len args != 1)
    1.16+	if(len args >= 2)
    1.17 		arg->usage();
    1.18+
    1.19 	d := read();
    1.20-	case str->tolower(hd args) {
    1.21+
    1.22+	dtype := "";
    1.23+	if(len args == 1)
    1.24+		dtype = hd args;
    1.25+	if(dtype == nil)
    1.26+		dtype = guesstype(d);
    1.27+	if(dtype == nil)
    1.28+		error("could not guess type");
    1.29+
    1.30+	case str->tolower(dtype) {
    1.31 	"vac" or "root" =>
    1.32 		root(d);
    1.33 	"entry" =>
    1.34@@ -66,6 +76,47 @@
    1.35 	}
    1.36 }
    1.37 
    1.38+g32(f: array of byte, i: int): int
    1.39+{
    1.40+	return (((((int f[i+0] << 8) | int f[i+1]) << 8) | int f[i+2]) << 8) | int f[i+3];
    1.41+}
    1.42+
    1.43+zeros(d: array of byte): int
    1.44+{
    1.45+	n := 0;
    1.46+	for(i := 0; i < len d; i++)
    1.47+		if(d[i] == byte 0)
    1.48+			n++;
    1.49+	return n;
    1.50+}
    1.51+
    1.52+guesstype(d: array of byte): string
    1.53+{
    1.54+	if(len d < 4)
    1.55+		return nil;
    1.56+	v := g32(d, 0);
    1.57+	if(v == Vac->Direntrymagic)
    1.58+		return "direntry";
    1.59+	if(v == Vac->Metablockmagic)
    1.60+		return "metablocks";
    1.61+	if(len d == 300)
    1.62+		return "root";
    1.63+
    1.64+	nz := zeros(d);
    1.65+	if(len d % Entrysize == 0 && nz > (8*len d/Entrysize))
    1.66+		return "entries";
    1.67+	if(len d % Scoresize == 0 && len d % (Scoresize+8) == 0) {
    1.68+		if(nz > 2*len d/Scoresize)
    1.69+			return "rpointers";
    1.70+		return "pointers";
    1.71+	}
    1.72+	if(len d % Scoresize == 0)
    1.73+		return "pointers";
    1.74+	if(len d % (Scoresize+8) == 0)
    1.75+		return "rpointers";
    1.76+	return nil;
    1.77+}
    1.78+
    1.79 read(): array of byte
    1.80 {
    1.81 	d := array[0] of byte;
     2.1--- a/appl/lib/vac.b	Mon Aug 06 12:12:12 2007 +0200
     2.2+++ b/appl/lib/vac.b	Mon Aug 06 14:42:23 2007 +0200
     2.3@@ -23,8 +23,6 @@
     2.4 Rootnamelen:	con 128;
     2.5 Rootversion:	con 2;
     2.6 Rootversionrabin:	con 3;
     2.7-Direntrymagic:	con 16r1c4d9072;
     2.8-Metablockmagic:	con 16r5656fc79;
     2.9 Maxstringsize: con 1000;
    2.10 
    2.11 blankroot: Root;
     3.1--- a/man/1/venti	Mon Aug 06 12:12:12 2007 +0200
     3.2+++ b/man/1/venti	Mon Aug 06 14:42:23 2007 +0200
     3.3@@ -71,7 +71,9 @@
     3.4 .I tag:score
     3.5 .br
     3.6 .B venti/parse
     3.7+[
     3.8 .I type
     3.9+]
    3.10 .SH DESCRIPTION
    3.11 .I Venti/read
    3.12 reads the block
    3.13@@ -123,7 +125,7 @@
    3.14 .I entry
    3.15 and
    3.16 .I entries
    3.17-the command to descend further in the tree is printed.
    3.18+the command to descend further down the tree is printed.  If the type is missing it is guessed based on its contents.
    3.19 .PP
    3.20 The options:
    3.21 .TP
     4.1--- a/module/vac.m	Mon Aug 06 12:12:12 2007 +0200
     4.2+++ b/module/vac.m	Mon Aug 06 14:42:23 2007 +0200
     4.3@@ -42,6 +42,9 @@
     4.4 	Entrylocal:	con (1<<5);	# used for local storage: should not be set for venti blocks
     4.5 	Entryvarblocks:	con (1<<7);	# variable block size, e.g. for rabin fingerprinting
     4.6 
     4.7+	Direntrymagic:	con 16r1c4d9072;
     4.8+	Metablockmagic:	con 16r5656fc79;
     4.9+
    4.10 	Root: adt {
    4.11 		version:	int;
    4.12 		name:	string;