Browse Source

Plan 9 from Bell Labs 2008-06-19

David du Colombier 13 years ago
parent
commit
b9359969e4
7 changed files with 329 additions and 6 deletions
  1. 5 2
      dist/replica/_plan9.db
  2. 5 2
      dist/replica/plan9.db
  3. 7 0
      dist/replica/plan9.log
  4. 1 1
      sys/lib/dist/mkfile
  5. 120 0
      sys/man/1/pump
  6. 1 1
      sys/src/cmd/auth/rsa2x509.c
  7. 190 0
      sys/src/cmd/pump.c

+ 5 - 2
dist/replica/_plan9.db

@@ -383,6 +383,7 @@
 386/bin/prof - 775 sys sys 1209614551 112005
 386/bin/proof - 775 sys sys 1210392905 180118
 386/bin/ps - 775 sys sys 1209614557 68753
+386/bin/pump - 775 sys sys 1213813262 60580
 386/bin/pwd - 775 sys sys 1148500685 36932
 386/bin/ramfs - 775 sys sys 1209184388 89491
 386/bin/rc - 775 sys sys 1183001109 145286
@@ -6230,7 +6231,7 @@ sys/lib/dist/cmd/touchfs.c - 664 sys sys 1018469727 1120
 sys/lib/dist/cmd/unbflz.c - 664 sys sys 1018469727 1688
 sys/lib/dist/logcompress.awk - 664 sys sys 1210371936 301
 sys/lib/dist/logtime.awk - 664 sys sys 1019526213 38
-sys/lib/dist/mkfile - 664 sys sys 1210371401 5469
+sys/lib/dist/mkfile - 664 sys sys 1213807255 5494
 sys/lib/dist/pc - 20000000775 sys sys 1147022870 0
 sys/lib/dist/pc/cd0.proto - 664 sys sys 1114358485 7
 sys/lib/dist/pc/empty - 20000000775 sys sys 1020895854 0
@@ -7473,6 +7474,7 @@ sys/man/1/prof - 664 sys sys 1196638933 3594
 sys/man/1/proof - 664 sys sys 1196638933 2300
 sys/man/1/ps - 664 sys sys 1196638933 1722
 sys/man/1/ps2pdf - 664 sys sys 1196638936 1359
+sys/man/1/pump - 664 sys sys 1213765898 1777
 sys/man/1/pwd - 664 sys sys 1196638933 744
 sys/man/1/rc - 664 sys sys 1196638936 20021
 sys/man/1/replica - 664 sys sys 1196638936 7210
@@ -9698,7 +9700,7 @@ sys/src/cmd/auth/rsa2any.h - 664 sys sys 1206420009 277
 sys/src/cmd/auth/rsa2csr.c - 664 sys sys 1048614963 621
 sys/src/cmd/auth/rsa2pub.c - 664 sys sys 1048614964 651
 sys/src/cmd/auth/rsa2ssh.c - 664 sys sys 1048614964 483
-sys/src/cmd/auth/rsa2x509.c - 664 sys sys 1048614964 794
+sys/src/cmd/auth/rsa2x509.c - 664 sys sys 1213807380 795
 sys/src/cmd/auth/rsafill.c - 664 sys sys 1048614963 747
 sys/src/cmd/auth/rsagen.c - 664 sys sys 1048614963 992
 sys/src/cmd/auth/secstore - 20000000775 sys sys 1106575527 0
@@ -13221,6 +13223,7 @@ sys/src/cmd/proof/mkfile - 664 sys sys 944961622 180
 sys/src/cmd/proof/proof.h - 664 sys sys 955223407 919
 sys/src/cmd/proof/screen.c - 664 sys sys 1204590226 6673
 sys/src/cmd/ps.c - 664 sys sys 1144686672 2783
+sys/src/cmd/pump.c - 664 sys sys 1213765467 2941
 sys/src/cmd/pwd.c - 664 sys sys 1067722792 287
 sys/src/cmd/qa - 20000000775 sys sys 1039727573 0
 sys/src/cmd/qa/a.h - 664 sys sys 1089299169 3252

+ 5 - 2
dist/replica/plan9.db

@@ -383,6 +383,7 @@
 386/bin/prof - 775 sys sys 1209614551 112005
 386/bin/proof - 775 sys sys 1210392905 180118
 386/bin/ps - 775 sys sys 1209614557 68753
+386/bin/pump - 775 sys sys 1213813262 60580
 386/bin/pwd - 775 sys sys 1148500685 36932
 386/bin/ramfs - 775 sys sys 1209184388 89491
 386/bin/rc - 775 sys sys 1183001109 145286
@@ -6230,7 +6231,7 @@ sys/lib/dist/cmd/touchfs.c - 664 sys sys 1018469727 1120
 sys/lib/dist/cmd/unbflz.c - 664 sys sys 1018469727 1688
 sys/lib/dist/logcompress.awk - 664 sys sys 1210371936 301
 sys/lib/dist/logtime.awk - 664 sys sys 1019526213 38
-sys/lib/dist/mkfile - 664 sys sys 1210371401 5469
+sys/lib/dist/mkfile - 664 sys sys 1213807255 5494
 sys/lib/dist/pc - 20000000775 sys sys 1147022870 0
 sys/lib/dist/pc/cd0.proto - 664 sys sys 1114358485 7
 sys/lib/dist/pc/empty - 20000000775 sys sys 1020895854 0
@@ -7473,6 +7474,7 @@ sys/man/1/prof - 664 sys sys 1196638933 3594
 sys/man/1/proof - 664 sys sys 1196638933 2300
 sys/man/1/ps - 664 sys sys 1196638933 1722
 sys/man/1/ps2pdf - 664 sys sys 1196638936 1359
+sys/man/1/pump - 664 sys sys 1213765898 1777
 sys/man/1/pwd - 664 sys sys 1196638933 744
 sys/man/1/rc - 664 sys sys 1196638936 20021
 sys/man/1/replica - 664 sys sys 1196638936 7210
@@ -9698,7 +9700,7 @@ sys/src/cmd/auth/rsa2any.h - 664 sys sys 1206420009 277
 sys/src/cmd/auth/rsa2csr.c - 664 sys sys 1048614963 621
 sys/src/cmd/auth/rsa2pub.c - 664 sys sys 1048614964 651
 sys/src/cmd/auth/rsa2ssh.c - 664 sys sys 1048614964 483
-sys/src/cmd/auth/rsa2x509.c - 664 sys sys 1048614964 794
+sys/src/cmd/auth/rsa2x509.c - 664 sys sys 1213807380 795
 sys/src/cmd/auth/rsafill.c - 664 sys sys 1048614963 747
 sys/src/cmd/auth/rsagen.c - 664 sys sys 1048614963 992
 sys/src/cmd/auth/secstore - 20000000775 sys sys 1106575527 0
@@ -13221,6 +13223,7 @@ sys/src/cmd/proof/mkfile - 664 sys sys 944961622 180
 sys/src/cmd/proof/proof.h - 664 sys sys 955223407 919
 sys/src/cmd/proof/screen.c - 664 sys sys 1204590226 6673
 sys/src/cmd/ps.c - 664 sys sys 1144686672 2783
+sys/src/cmd/pump.c - 664 sys sys 1213765467 2941
 sys/src/cmd/pwd.c - 664 sys sys 1067722792 287
 sys/src/cmd/qa - 20000000775 sys sys 1039727573 0
 sys/src/cmd/qa/a.h - 664 sys sys 1089299169 3252

+ 7 - 0
dist/replica/plan9.log

@@ -19889,3 +19889,10 @@
 1213644604 0 c sys/man/4/cdfs - 664 sys sys 1213644483 5267
 1213734604 0 c rc/bin/diskparts - 775 sys sys 1213733501 1052
 1213734604 1 c sys/man/8/prep - 664 sys sys 1213733470 14329
+1213765205 0 a sys/man/1/pump - 664 sys sys 1213765472 1702
+1213765205 1 a sys/src/cmd/pump.c - 664 sys sys 1213765467 2941
+1213767003 0 a 386/bin/pump - 775 sys sys 1213765478 60580
+1213767003 1 c sys/man/1/pump - 664 sys sys 1213765898 1777
+1213808404 0 c sys/lib/dist/mkfile - 664 sys sys 1213807255 5494
+1213808404 1 c sys/src/cmd/auth/rsa2x509.c - 664 sys sys 1213807380 795
+1213813804 0 c 386/bin/pump - 775 sys sys 1213813262 60580

+ 1 - 1
sys/lib/dist/mkfile

@@ -159,7 +159,7 @@ worldwritable-mail:V:
 	9fs boot
 	test -e /n/boot/sys
 	/usr/rsc/bin/$cputype/lsr -t -d /n/boot/sys /n/boot/lib |
-		grep -v /lib/audio/ |		# give us a break
+		grep -v '/lib/audio/|/sys/src/cmd/vac/test/' |		# give us a break
 		awk '$2 ~ /[2367][^2367].$/' |
 		datemail 'non-group-writable files on fs' 9trouble
 	status=''

+ 120 - 0
sys/man/1/pump

@@ -0,0 +1,120 @@
+.TH PUMP 1
+.SH NAME
+pump \- copy asynchronously via a large circular buffer
+.SH SYNOPSIS
+.B pump
+[
+.B -b
+.I iando
+] [
+.B -d
+.I sleepms
+] [
+.B -f
+.I ofile
+] [
+.B -i
+.I ireadsize
+] [
+.B -k
+.I KB-buf
+] [
+.B -o
+.I owritesize
+] [
+.B -s
+.I start-KB
+] [
+.I file
+\&... ]
+.SH DESCRIPTION
+.I Pump
+copies
+.IR files
+(or standard input if none)
+to standard output
+by using two processes,
+one reading and one writing,
+sharing a large circular buffer,
+thus permitting the reading process to
+get ahead of the writing process if the
+output device is slow (e.g., an optical disc).
+This in turn can keep the output device busy.
+The pipeline
+.L "dd | dd"
+can approximate this, but pipe buffering is limited to 64K
+bytes, which is fairly modest.
+.PP
+Options are:
+.TF \fL-m
+.TP
+.B -b
+sets the size of
+.I read
+and
+.I write
+operations to
+.I iando
+kilobytes.
+The default size is 8 kilobytes.
+.TP
+.B -d
+causes the output process to sleep for
+.I sleepms
+milliseconds initially, giving the reading
+process time to accumulate data in the buffer.
+.TP
+.B -f
+writes
+.I ofile
+rather than standard output
+.TP
+.B -i
+sets the size of
+.I read
+operations to
+.I ireadsize
+kilobytes.
+.TP
+.B -k
+allocates a circular buffer of
+.I KB-buf
+kilobytes rather than the default
+5000 kilobytes.
+.TP
+.B -o
+sets the size of
+.I write
+operations to
+.I owritesize
+kilobytes.
+.TP
+.B -s
+prevents output until
+.I start-KB
+kilobytes have been read.
+.SH EXAMPLES
+Append a
+.IR venti (8)
+arena to a DVD or BD quickly.
+.PD 0
+.IP
+.EX
+cdfs
+venti/rdarena arena0 arena.3 |
+	pump -b 65536 -k 51200 >/mnt/cd/wd/arena.3
+.EE
+.PD
+.\" .SH FILES
+.SH SOURCE
+.B /sys/src/cmd/pump.c
+.SH SEE ALSO
+.IR cdfs (1),
+.IR cp (1),
+.IR dd (1),
+.IR ecp (1)
+.\" .SH DIAGNOSTICS
+.SH BUGS
+.I Pump
+processes spin while waiting for the circular buffer
+to fill or drain.

+ 1 - 1
sys/src/cmd/auth/rsa2x509.c

@@ -9,7 +9,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: aux/rsa2x509 [-e expireseconds] 'C=US ...CN=xxx' [key]");
+	fprint(2, "usage: auth/rsa2x509 [-e expireseconds] 'C=US ...CN=xxx' [key]");
 	exits("usage");
 }
 

+ 190 - 0
sys/src/cmd/pump.c

@@ -0,0 +1,190 @@
+/* pump - copy through circular buffer */
+#include <u.h>
+#include <libc.h>
+
+uchar*	buf;
+ulong	nin;
+ulong	nout;
+ulong	kilo;
+ulong	max;
+long	ssize;
+long	tsize;
+int	dsize;
+int	done;
+int	ibsize;
+int	obsize;
+int	verb;
+
+void	doinput(int);
+void	dooutput(int);
+
+static void
+usage(void)
+{
+	fprint(2, "usage: pump [-f ofile] [-k KB-buffer] [-i ireadsize]\n"
+		"\t[-o owritesize] [-b iando] [-s start-KB] [-d sleeptime] "
+		"[files]\n");
+	exits("usage");
+}
+
+void
+main(int argc, char *argv[])
+{
+	int i, f, fo;
+	char *file;
+
+	kilo = 5000;
+	obsize = ibsize = 8*1024;
+	dsize = 0;
+	fo = 1;
+
+	ARGBEGIN {
+	default:
+		usage();
+	case 'b':
+		obsize = ibsize = atoi(EARGF(usage()));
+		break;
+	case 'd':
+		dsize = atoi(EARGF(usage()));
+		break;
+	case 'f':
+		file = EARGF(usage());
+		fo = create(file, 1, 0666);
+		if(fo < 0)
+			sysfatal("can't create %s: %r", file);
+		break;
+	case 'i':
+		ibsize = atoi(EARGF(usage()));
+		break;
+	case 'k':
+		kilo = atoi(EARGF(usage()));
+		break;
+	case 'o':
+		obsize = atoi(EARGF(usage()));
+		break;
+	case 's':
+		ssize = atoi(EARGF(usage()));
+		if(ssize <= 0)
+			ssize = 800;
+		ssize <<= 10;
+		break;
+	case 't':
+		tsize = atol(EARGF(usage()));
+		tsize *= 10584000;		/* minutes */
+		break;
+	} ARGEND
+	kilo <<= 10;
+
+	buf = malloc(kilo);
+	if(buf == nil)
+		sysfatal("no memory: %r");
+	nin = 0;
+	nout = 0;
+	done = 0;
+	max = 0;
+
+	switch(rfork(RFPROC|RFNOWAIT|RFNAMEG|RFMEM)) {
+	default:
+		dooutput(fo);
+		break;
+	case 0:
+		for(i=0; i<argc; i++) {
+			f = open(argv[i], OREAD);
+			if(f < 0) {
+				fprint(2, "%s: can't open %s: %r\n",
+					argv0, argv[i]);
+				break;
+			}
+			doinput(f);
+			close(f);
+		}
+		if(argc == 0)
+			doinput(0);
+		break;
+	case -1:
+		fprint(2, "%s: fork failed: %r\n", argv0);
+		break;
+	}
+	done = 1;
+	exits(0);
+}
+
+void
+dooutput(int f)
+{
+	long n, l, c;
+
+	for (;;) {
+		n = nin - nout;
+		if(n == 0) {
+			if(done)
+				break;
+			sleep(dsize);
+			continue;
+		}
+		if(verb && n > max) {
+			fprint(2, "n = %ld\n", n);
+			max = n;
+		}
+		l = nout % kilo;
+		if(kilo-l < n)
+			n = kilo-l;
+		if(n > obsize)
+			n = obsize;
+		c = write(f, buf+l, n);
+		if(c != n) {
+			fprint(2, "%s: write error: %r\n", argv0);
+			break;
+		}
+		nout += c;
+		if(tsize && nout > tsize) {
+			fprint(2, "%s: time limit exceeded\n", argv0);
+			break;
+		}
+	}
+}
+
+void
+doinput(int f)
+{
+	long n, l, c, xnin;
+
+	if(ssize > 0) {
+		for (xnin = 0; xnin < ssize && !done; xnin += c) {
+			n = kilo - (xnin - nout);
+			if(n == 0)
+				break;
+			l = xnin % kilo;
+			if(kilo-l < n)
+				n = kilo-l;
+			if(n > ibsize)
+				n = ibsize;
+			c = read(f, buf+l, n);
+			if(c <= 0) {
+				if(c < 0)
+					fprint(2, "%s: read error: %r\n", argv0);
+				break;
+			}
+		}
+		nin = xnin;
+	}
+	while(!done) {
+		n = kilo - (nin - nout);
+		if(n == 0) {
+			sleep(0);
+			continue;
+		}
+		l = nin % kilo;
+		if(kilo-l < n)
+			n = kilo-l;
+		if(n > ibsize)
+			n = ibsize;
+		c = read(f, buf+l, n);
+		if(c <= 0) {
+			if(c < 0)
+				fprint(2, "%s: read error: %r\n", argv0);
+			break;
+		}
+		nin += c;
+	}
+}