Browse Source

Plan 9 from Bell Labs 2006-11-01

David du Colombier 14 years ago
parent
commit
5c6a02ab68

+ 8 - 8
dist/replica/_plan9.db

@@ -482,8 +482,8 @@
 386/bin/usb/usbd - 775 sys sys 1130594805 129878
 386/bin/usb/usbmouse - 775 sys sys 1130594806 138159
 386/bin/usb/usbprinter - 775 sys sys 1089408719 222
-386/bin/vac - 775 sys sys 1132506885 169484
-386/bin/vacfs - 775 sys sys 1134389881 175020
+386/bin/vac - 775 sys sys 1162351724 170720
+386/bin/vacfs - 775 sys sys 1162351725 175522
 386/bin/venti - 20000000775 sys sys 947360466 0
 386/bin/venti/buildindex - 775 sys sys 1130594807 154175
 386/bin/venti/checkarenas - 775 sys sys 1130594808 158418
@@ -14135,21 +14135,21 @@ sys/src/cmd/vac/cache.c - 664 sys sys 1071245791 15806
 sys/src/cmd/vac/dat.h - 664 sys sys 1091904424 3994
 sys/src/cmd/vac/error.c - 664 sys sys 1036006057 633
 sys/src/cmd/vac/error.h - 664 sys sys 1036024048 327
-sys/src/cmd/vac/file.c - 664 sys sys 1048645298 18984
+sys/src/cmd/vac/file.c - 664 sys sys 1162350655 19061
 sys/src/cmd/vac/fns.h - 664 sys sys 1036006061 1746
-sys/src/cmd/vac/fs.c - 664 sys sys 1076129457 2934
+sys/src/cmd/vac/fs.c - 664 sys sys 1162327826 2902
 sys/src/cmd/vac/mkfile - 664 sys sys 1036024045 434
 sys/src/cmd/vac/pack.c - 664 sys sys 1036006059 10126
 sys/src/cmd/vac/rtest.c - 664 sys sys 1019678787 1116
-sys/src/cmd/vac/source.c - 664 sys sys 1039797584 6723
+sys/src/cmd/vac/source.c - 664 sys sys 1162327879 6767
 sys/src/cmd/vac/srcload.c - 664 sys sys 1036024047 4925
 sys/src/cmd/vac/stdinc.h - 664 sys sys 1036006059 121
 sys/src/cmd/vac/util.c - 664 sys sys 1019678787 930
-sys/src/cmd/vac/vac.c - 664 sys sys 1158618260 23102
+sys/src/cmd/vac/vac.c - 664 sys sys 1162350579 23803
 sys/src/cmd/vac/vac.h - 664 sys sys 1091904424 3598
-sys/src/cmd/vac/vacfs.c - 664 sys sys 1134305451 13635
+sys/src/cmd/vac/vacfs.c - 664 sys sys 1162327841 13629
 sys/src/cmd/vac/vactest.c - 664 sys sys 1036024047 2742
-sys/src/cmd/vac/vtdump.c - 664 sys sys 1158618245 7166
+sys/src/cmd/vac/vtdump.c - 664 sys sys 1162327892 7323
 sys/src/cmd/vac/vtread.c - 664 sys sys 1019678788 2052
 sys/src/cmd/vac/wtest.c - 664 sys sys 1019678788 766
 sys/src/cmd/vc - 20000000775 sys sys 947099614 0

+ 8 - 8
dist/replica/plan9.db

@@ -482,8 +482,8 @@
 386/bin/usb/usbd - 775 sys sys 1130594805 129878
 386/bin/usb/usbmouse - 775 sys sys 1130594806 138159
 386/bin/usb/usbprinter - 775 sys sys 1089408719 222
-386/bin/vac - 775 sys sys 1132506885 169484
-386/bin/vacfs - 775 sys sys 1134389881 175020
+386/bin/vac - 775 sys sys 1162351724 170720
+386/bin/vacfs - 775 sys sys 1162351725 175522
 386/bin/venti - 20000000775 sys sys 947360466 0
 386/bin/venti/buildindex - 775 sys sys 1130594807 154175
 386/bin/venti/checkarenas - 775 sys sys 1130594808 158418
@@ -14135,21 +14135,21 @@ sys/src/cmd/vac/cache.c - 664 sys sys 1071245791 15806
 sys/src/cmd/vac/dat.h - 664 sys sys 1091904424 3994
 sys/src/cmd/vac/error.c - 664 sys sys 1036006057 633
 sys/src/cmd/vac/error.h - 664 sys sys 1036024048 327
-sys/src/cmd/vac/file.c - 664 sys sys 1048645298 18984
+sys/src/cmd/vac/file.c - 664 sys sys 1162350655 19061
 sys/src/cmd/vac/fns.h - 664 sys sys 1036006061 1746
-sys/src/cmd/vac/fs.c - 664 sys sys 1076129457 2934
+sys/src/cmd/vac/fs.c - 664 sys sys 1162327826 2902
 sys/src/cmd/vac/mkfile - 664 sys sys 1036024045 434
 sys/src/cmd/vac/pack.c - 664 sys sys 1036006059 10126
 sys/src/cmd/vac/rtest.c - 664 sys sys 1019678787 1116
-sys/src/cmd/vac/source.c - 664 sys sys 1039797584 6723
+sys/src/cmd/vac/source.c - 664 sys sys 1162327879 6767
 sys/src/cmd/vac/srcload.c - 664 sys sys 1036024047 4925
 sys/src/cmd/vac/stdinc.h - 664 sys sys 1036006059 121
 sys/src/cmd/vac/util.c - 664 sys sys 1019678787 930
-sys/src/cmd/vac/vac.c - 664 sys sys 1158618260 23102
+sys/src/cmd/vac/vac.c - 664 sys sys 1162350579 23803
 sys/src/cmd/vac/vac.h - 664 sys sys 1091904424 3598
-sys/src/cmd/vac/vacfs.c - 664 sys sys 1134305451 13635
+sys/src/cmd/vac/vacfs.c - 664 sys sys 1162327841 13629
 sys/src/cmd/vac/vactest.c - 664 sys sys 1036024047 2742
-sys/src/cmd/vac/vtdump.c - 664 sys sys 1158618245 7166
+sys/src/cmd/vac/vtdump.c - 664 sys sys 1162327892 7323
 sys/src/cmd/vac/vtread.c - 664 sys sys 1019678788 2052
 sys/src/cmd/vac/wtest.c - 664 sys sys 1019678788 766
 sys/src/cmd/vc - 20000000775 sys sys 947099614 0

+ 8 - 0
dist/replica/plan9.log

@@ -31677,3 +31677,11 @@
 1162242006 34 c 386/lib/libip.a - 664 sys sys 1162241052 35552
 1162242006 35 c 386/lib/libsec.a - 664 sys sys 1162241054 646724
 1162243806 0 c sys/games/lib/fortunes - 664 sys sys 1162243786 261387
+1162328406 0 c sys/src/cmd/vac/fs.c - 664 sys sys 1162327826 2902
+1162328406 1 c sys/src/cmd/vac/source.c - 664 sys sys 1162327879 6767
+1162328406 2 c sys/src/cmd/vac/vacfs.c - 664 sys sys 1162327841 13629
+1162328406 3 c sys/src/cmd/vac/vtdump.c - 664 sys sys 1162327892 7323
+1162351806 0 c 386/bin/vac - 775 sys sys 1162351724 170720
+1162351806 1 c 386/bin/vacfs - 775 sys sys 1162351725 175522
+1162351806 2 c sys/src/cmd/vac/file.c - 664 sys sys 1162350655 19061
+1162351806 3 c sys/src/cmd/vac/vac.c - 664 sys sys 1162350579 23803

+ 7 - 0
sys/src/cmd/vac/file.c

@@ -1212,3 +1212,10 @@ Err:
 	return NilBlock;
 }
 
+VacFS *
+vacfs(VacFile *vf)
+{
+	if (vf == nil)
+		return nil;
+	return vf->fs;
+}

+ 3 - 6
sys/src/cmd/vac/fs.c

@@ -94,7 +94,7 @@ vfsOpen(VtSession *z, char *file, int readOnly, long ncache)
 	}
 
 	fs = vfsAlloc(z, rt.blockSize, ncache);
-	memmove(fs->score, score, VtScoreSize);
+	vfsGetScore(fs, score);
 	fs->readOnly = readOnly;
 	root = vfRoot(fs, rt.score);
 	if(root == nil)
@@ -112,10 +112,7 @@ Err:
 VacFS *
 vacFsCreate(VtSession *z, int bsize, long ncache)
 {
-	VacFS *fs;
-
-	fs = vfsAlloc(z, bsize, ncache);
-	return fs;
+	return vfsAlloc(z, bsize, ncache);
 }
 
 int
@@ -139,7 +136,7 @@ vfsGetBlockSize(VacFS *fs)
 int
 vfsGetScore(VacFS *fs, uchar score[VtScoreSize])
 {
-	memmove(fs, score, VtScoreSize);
+	memmove(fs->score, score, VtScoreSize);
 	return 1;
 }
 

+ 4 - 4
sys/src/cmd/vac/source.c

@@ -36,14 +36,14 @@ sourceAlloc(Cache *c, Lump *u, ulong block, int entry, int readOnly)
 		return nil;
 	
 	if(!(d.flags & VtEntryActive)) {
-fprint(2, "bad flags %#ux %V\n", d.flags, d.score);
+fprint(2, "%s: bad flags %#ux %V\n", argv0, d.flags, d.score);
 		vtSetError(ENoDir);
 		return nil;
 	}
 	
 	/* HACK for backwards compatiblity - should go away at some point */
 	if(d.depth == 0) {
-if(d.size > d.dsize) fprint(2, "depth == 0! size = %ulld\n", d.size);
+if(d.size > d.dsize) fprint(2, "%s: depth == 0! size = %ulld\n", argv0, d.size);
 		d.depth = sizeToDepth(d.size, d.psize, d.dsize);
 	}
 
@@ -77,7 +77,7 @@ sourceOpen(Source *r, ulong entry, int readOnly)
 	ulong bn;
 	Lump *u;
 
-if(0)fprint(2, "sourceOpen: %V:%d: %lud\n", r->lump->score, r->entry, entry);
+if(0)fprint(2, "%s: sourceOpen: %V:%d: %lud\n", argv0, r->lump->score, r->entry, entry);
 	if(r->readOnly && !readOnly) {
 		vtSetError(EReadOnly);
 		return nil;
@@ -365,7 +365,7 @@ sourceGetLump(Source *r, ulong block, int readOnly, int lock)
 		vtSetError(ENilBlock);
 		return nil;
 	}
-if(0)fprint(2, "sourceGetLump: %V:%d %lud\n", r->lump->score, r->entry, block);
+if(0)fprint(2, "%s: sourceGetLump: %V:%d %lud\n", argv0, r->lump->score, r->entry, block);
 	u = sourceWalk(r, block, readOnly, &off);
 	if(u == nil)
 		return nil;

+ 75 - 52
sys/src/cmd/vac/vac.c

@@ -71,6 +71,7 @@ void metaSinkFree(MetaSink *k);
 void plan9ToVacDir(VacDir*, Dir*, ulong entry, uvlong qid);
 
 enum {
+	Debug = 1,
 	Version = 8,
 	BlockSize = 8*1024,
 	MaxExclude = 1000,
@@ -101,7 +102,6 @@ void
 main(int argc, char *argv[])
 {
 	VtSession *z;
-	char *p;
 	char *host = nil;
 	int statsFlag = 0;
 
@@ -111,40 +111,26 @@ main(int argc, char *argv[])
 	default:
 		usage();
 	case 'b':
-		p = ARGF();
-		if(p == 0)
-			usage();
-		bsize = unittoull(p);
+		bsize = unittoull(EARGF(usage()));
 		if(bsize == ~0)
 			usage();
 		break;
 	case 'd':
-		dfile = ARGF();
-		if(dfile == nil)
-			usage();
+		dfile = EARGF(usage());
 		break;
 	case 'e':
 		if(nexclude >= MaxExclude)
 			sysfatal("too many exclusions");
-		exclude[nexclude] = ARGF();
-		if(exclude[nexclude] == nil)
-			usage();
-		nexclude++;
+		exclude[nexclude++] = EARGF(usage());
 		break;
 	case 'f':
-		oname = ARGF();
-		if(oname == 0)
-			usage();
+		oname = EARGF(usage());
 		break;
 	case 'h':
-		host = ARGF();
-		if(host == nil)
-			usage();
+		host = EARGF(usage());
 		break;
 	case 'i':
-		isi = ARGF();
-		if(isi == nil)
-			usage();
+		isi = EARGF(usage());
 		break;
 	case 'n':
 		nowrite++;
@@ -185,10 +171,13 @@ main(int argc, char *argv[])
 
 	vac(z, argv);
 	if(!vtSync(z))
-		fprint(2, "warning: could not ask server to flush pending writes: %R\n");
+		fprint(2,
+	"%s: warning: could not ask server to flush pending writes: %R\n",
+			argv0);
 
 	if(statsFlag)
-		fprint(2, "files %ld:%ld data %ld:%ld:%ld meta %ld\n", stats.file, stats.sfile,
+		fprint(2, "%s: files %ld:%ld data %ld:%ld:%ld meta %ld\n",
+			argv0, stats.file, stats.sfile,
 			stats.data, stats.skip, stats.sdata, stats.meta);
 //packetStats();
 	vtClose(z);
@@ -197,15 +186,15 @@ main(int argc, char *argv[])
 	exits(0);
 }
 
-void
-static usage(void)
+static void
+usage(void)
 {
 	fprint(2, "usage: %s [-amqsv] [-h host] [-d vacfile] [-b blocksize] [-i name] [-e exclude] [-f vacfile] file ... \n", argv0);
 	exits("usage");
 }
 
-static
-int strpCmp(void *p0, void *p1)
+static int
+strpCmp(void *p0, void *p1)
 {
 	return strcmp(*(char**)p0, *(char**)p1);
 }
@@ -241,7 +230,8 @@ assert(n > 0);
 		uchar score2[VtScoreSize];
 
 		vtSha1(score2, buf, n);
-fprint(2, "vtSha1Check: n = %d %V %V\n", n, score, score2);
+		fprint(2, "%s: vtSha1Check: n = %d %V %V\n",
+			argv0, n, score, score2);
 		vtSetError("vtSha1Check failed");
 		return 0;
 	}
@@ -274,7 +264,8 @@ vac(VtSession *z, char *argv[])
 	if(dfile != nil) {
 		fs = vfsOpen(z, dfile, 1, 10000);
 		if(fs == nil)
-			fprint(2, "could not open diff: %s: %s\n", dfile, vtGetError());
+			fprint(2, "%s: could not open diff: %s: %s\n",
+				argv0, dfile, vtGetError());
 	}
 
 
@@ -401,6 +392,7 @@ vacFile(DirSink *dsink, char *lname, char *sname, VacFile *vf)
 {
 	int fd;
 	Dir *dir;
+	Dir fake;
 	VacDir vd;
 	ulong entry;
 
@@ -415,6 +407,29 @@ vacFile(DirSink *dsink, char *lname, char *sname, VacFile *vf)
 	fd = open(sname, OREAD);
 	if(fd < 0) {
 		warn("could not open file: %s: %s", lname, vtOSError());
+
+		/*
+		 * fake up dsink & vf contents so we don't explode later.
+		 * I'm not certain that this is needed, but it seems like
+		 * a wise precaution.
+		 */
+		entry = dsink->nentry;
+		/* pretend it's a plain file */
+		dir = &fake;
+		nulldir(dir);
+		dir->type = 'M';
+		dir->dev = 10;
+		dir->qid = (Qid){ 10, 2, QTFILE};
+		dir->mode = 0664;
+		dir->atime = dir->mtime = time(nil);
+		dir->length = 0;
+		dir->name = sname;
+		dir->uid = dir->gid = dir->muid = "missing";
+
+		vacData(dsink, fd, lname, vf, dir);
+		plan9ToVacDir(&vd, dir, entry, fileid++);
+		metaSinkWriteDir(dsink->msink, &vd);
+		vdCleanup(&vd);
 		return;
 	}
 
@@ -488,7 +503,8 @@ vacDataSkip(Sink *sink, VacFile *vf, int fd, ulong blocks, uchar *buf, char *lna
 		warn("error checking append only file: %s", lname);
 		goto Err;
 	}
-	if(!vfGetBlockScore(vf, blocks-1, score) || !vtSha1Check(score, buf, n)) {
+	if(!vfGetBlockScore(vf, blocks-1, score) ||
+	    !vtSha1Check(score, buf, n)) {
 		warn("last block of append file did not match: %s", lname);
 		goto Err;
 	}
@@ -523,9 +539,10 @@ vacData(DirSink *dsink, int fd, char *lname, VacFile *vf, Dir *dir)
 	vfblocks = 0;
 	if(vf != nil && qdiff) {
 		vfGetDir(vf, &vd);
-		if(vd.mtime == dir->mtime)
-		if(vd.size == dir->length)
-		if(!vd.plan9 || /* vd.p9path == dir->qid.path && */ vd.p9version == dir->qid.vers)
+		if(vd.mtime == dir->mtime && vd.size == dir->length &&
+		    (!vd.plan9 ||
+		     /* vd.p9path == dir->qid.path && */
+		     vd.p9version == dir->qid.vers))
 		if(dirSinkWriteFile(dsink, vf)) {
 			stats.sfile++;
 			vdCleanup(&vd);
@@ -533,10 +550,8 @@ vacData(DirSink *dsink, int fd, char *lname, VacFile *vf, Dir *dir)
 		}
 
 		/* look for an append only file */
-		if((dir->mode&DMAPPEND) != 0)
-		if(vd.size < dir->length)
-		if(vd.plan9)
-		if(vd.p9path == dir->qid.path)
+		if((dir->mode&DMAPPEND) && vd.size < dir->length &&
+		    vd.plan9 && vd.p9path == dir->qid.path)
 			vfblocks = vd.size/bsize;
 
 		vdCleanup(&vd);
@@ -555,10 +570,12 @@ if(0) fprint(2, "vacData: %s: %ld\n", lname, block);
 	for(;;) {
 		n = readBlock(fd, buf, bsize);
 		if(0 && n < 0)
-			warn("file truncated due to read error: %s: %s", lname, vtOSError());
+			warn("file truncated due to read error: %s: %s",
+				lname, vtOSError());
 		if(n <= 0)
 			break;
-		if(vf != nil && vfGetBlockScore(vf, block, score) && vtSha1Check(score, buf, n)) {
+		if(vf != nil && vfGetBlockScore(vf, block, score) &&
+		    vtSha1Check(score, buf, n)) {
 			stats.sdata++;
 			sinkWriteScore(sink, score, n);
 		} else
@@ -566,8 +583,7 @@ if(0) fprint(2, "vacData: %s: %ld\n", lname, block);
 		block++;
 	}
 	same = stats.sdata+stats.skip - same;
-
-	if(same && (dir->mode&DMAPPEND) != 0)
+	if(same && (dir->mode&DMAPPEND))
 		if(0)fprint(2, "%s: total %lud same %lud:%lud diff %lud\n",
 			lname, block, same, vfblocks, block-same);
 
@@ -577,28 +593,35 @@ if(0) fprint(2, "vacData: %s: %ld\n", lname, block);
 	free(buf);
 }
 
-
 static void
 vacDir(DirSink *dsink, int fd, char *lname, char *sname, VacFile *vf)
 {
 	Dir *dirs;
 	char *ln, *sn;
+	char *name;
 	int i, nd;
 	DirSink *ds;
 	VacFile *vvf;
-	char *name;
+
+	/*
+	 * if we could see the score underlying dir, we could quickly
+	 * short-circuit further directory descent if vf (see vacfs(vf)->score)
+	 * and dir had identical scores.
+	 */
 
 	ds = dirSinkAlloc(dsink->sink->z, bsize, bsize);
 	while((nd = dirread(fd, &dirs)) > 0){
 		for(i = 0; i < nd; i++){
 			name = dirs[i].name;
 			/* check for bad file names */
-			if(name[0] == 0 || strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
+			if(name[0] == 0 || name[0] == '/' ||
+			    strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
 				continue;
-			ln = vtMemAlloc(strlen(lname) + strlen(name) + 2);
-			sn = vtMemAlloc(strlen(sname) + strlen(name) + 2);
-			sprint(ln, "%s/%s", lname, name);
-			sprint(sn, "%s/%s", sname, name);
+			ln = smprint("%s/%s", lname, name);
+			sn = smprint("%s/%s", sname, name);
+			if (ln == nil || sn == nil)
+				sysfatal("out of memory");
+
 			if(vf != nil)
 				vvf = vfWalk(vf, name);
 			else
@@ -606,8 +629,8 @@ vacDir(DirSink *dsink, int fd, char *lname, char *sname, VacFile *vf)
 			vacFile(ds, ln, sn, vvf);
 			if(vvf != nil)
 				vfDecRef(vvf);
-			vtMemFree(ln);
-			vtMemFree(sn);
+			free(ln);
+			free(sn);
 		}
 		free(dirs);
 	}
@@ -642,7 +665,7 @@ vacMergeFile(DirSink *dsink, VacFile *vf, VacDir *dir, uvlong offset, uvlong *ma
 		vtEntryUnpack(&md, buf, 0);
 	}
 
-	/* max might incorrect in some old dumps */
+	/* max might be incorrect in some old dumps */
 	if(dir->qid >= *max) {
 		warn("qid out of range: %s", dir->elem);
 		*max = dir->qid;
@@ -695,7 +718,7 @@ vacMerge(DirSink *dsink, char *lname, char *sname)
 		goto Done;
 
 	if(verbose)
-		fprint(2, "merging: %s\n", lname);
+		fprint(2, "%s: merging: %s\n", argv0, lname);
 
 	if(maxbsize < vfsGetBlockSize(fs))
 		maxbsize = vfsGetBlockSize(fs);

+ 3 - 3
sys/src/cmd/vac/vacfs.c

@@ -797,6 +797,7 @@ io(void)
 int
 permf(VacFile *vf, char *user, int p)
 {
+	int ok = 1;
 	VacDir dir;
 	ulong perm;
 
@@ -811,11 +812,10 @@ permf(VacFile *vf, char *user, int p)
 		goto Good;
 	if(strcmp(user, dir.uid)==0 && ((p*Powner) & perm))
 		goto Good;
-	vdCleanup(&dir);
-	return 0;
+	ok = 0;
 Good:
 	vdCleanup(&dir);
-	return 1;
+	return ok;
 }
 
 int

+ 10 - 4
sys/src/cmd/vac/vtdump.c

@@ -53,13 +53,15 @@ main(int argc, char *argv[])
 		break;
 	case 'f':
 		find++;
-		p = ARGF();
-		if(p == nil || !parseScore(fscore, p, strlen(p)))
+		p = EARGF(usage());
+		if(!parseScore(fscore, p, strlen(p)))
 			usage();
 		break;
 	case 'a':
 		all = 1;
 		break;
+	default:
+		usage();
 	}ARGEND
 
 	vtAttach();
@@ -93,6 +95,8 @@ main(int argc, char *argv[])
 		Bprint(bout, "bsize: %d\n", bsize);
 		Bprint(bout, "prev: %V\n", root.prev);
 	}
+	if (bsize == 0)
+		sysfatal("zero bsize");
 
 	switch(ver) {
 	default:
@@ -284,6 +288,8 @@ dumpDir(Source *s, int indent)
 	uchar buf[VtMaxLumpSize];
 	Source ss;
 
+	if (s->dsize == 0)
+		sysfatal("dumpDir: zero s->dsize");
 	pb = s->dsize/VtEntrySize;
 	ne = pb*(s->size/s->dsize) + (s->size%s->dsize)/VtEntrySize;
 	nb = (s->size + s->dsize - 1)/s->dsize;
@@ -320,7 +326,7 @@ dumpDir(Source *s, int indent)
 void
 usage(void)
 {
-	fprint(2, "%s: [file]\n", argv0);
+	fprint(2, "usage: %s [-ac] [-f findscore] [-h host] [file]\n", argv0);
 	exits("usage");
 }
 
@@ -359,7 +365,7 @@ readRoot(VtRoot *root, uchar *score, char *file)
 	uchar buf[VtRootSize];
 	int i, n, nn;
 
-	if(file == 0)
+	if(file == nil)
 		fd = 0;
 	else {
 		fd = open(file, OREAD);