Browse Source

Plan 9 from Bell Labs 2011-06-15

David du Colombier 13 years ago
parent
commit
057dcd5f87

+ 108 - 0
rc/bin/loadfossil

@@ -0,0 +1,108 @@
+#!/bin/rc
+# loadfossil - populate a fossil partition or file
+#
+# due to name clashes in /srv, will only work on a machine
+# without a fossil named `fossil' already running.
+
+rfork en
+
+fn killfossil {
+	sleep 1
+	unmount /n/f &
+	sleep 1
+	rm -f /srv/^(fossil fossil.open fscons fscons.open)
+	kill fossil | rc
+	sleep 1
+}
+
+fn sendexpect {		# send expect timeout
+	echo $1
+	if(! dial/expect -qt $3 $2)
+		echo -n 'no '^$"1^'...' > /dev/cons
+}
+
+fn usage {
+	echo usage: $argv0 partition root proto fossil.conf >[1=2]
+	exit usage
+}
+
+fn sigexit {
+	rm -f /tmp/fossil-no-list.conf
+	exit
+}
+fn sigint sighup sigterm {
+	rm -f /tmp/fossil-no-list.conf
+	killfossil
+	exit note
+}
+
+# process arguments
+if (! ~ $#* 4)
+	usage
+argv0=$0
+fosspart=$1
+srcroot=$2
+proto=$3
+fossconf=$4
+
+if (test -e /srv/fossil -o -e /srv/fossil.open) {
+	echo $0: /srv/fossil* exists, not safe to start a new one >[1=2]
+	exit fossil-already-running
+}
+
+# initialise fossil
+fossil/flfmt -y $fosspart
+
+# install listen-less config for fossil creation
+{
+	grep -v '^listen ' $fossconf | sed '/^fsys main config/c\
+fsys main config '^$fosspart
+	echo create /active/adm adm sys d775
+	echo create /active/adm/users adm sys 664
+} >/tmp/fossil-no-list.conf
+fossil/conf -w $fosspart /tmp/fossil-no-list.conf
+
+# start fossil
+fossil/fossil -f $fosspart
+mount -cC /srv/fossil.open /n/f
+
+# set up /adm/users
+cp /adm/users /n/f/adm
+{
+	echo
+	dial/drain &
+	sleep 2
+	sendexpect 'users -r /active/adm/users' ': ' 5
+} </srv/fscons.open >>/srv/fscons.open
+
+# remount with new users
+unmount /n/f
+mount -cC /srv/fossil.open /n/f
+
+# populate fossil
+@ {
+	# logs are boring, make them all appear empty
+	chmod +arw /tmp/empty-log >/tmp/empty-log
+	cd $srcroot/sys/log && {
+		for (f in [0-9a-z]* */*)
+			if (! ~ $f httpd mkfile smtpdb timesync.d vac year)
+				bind /tmp/empty-log $f
+	}
+	cd /tmp
+	disk/mkfs -u $srcroot/adm/users -U -d /n/f -s $srcroot $proto
+}
+
+# stop fossil gracefully
+{
+	echo
+	dial/drain &
+	sleep 2
+	sendexpect 'fsys all sync' ': ' 120
+	sendexpect 'fsys all halt' ': ' 5
+} </srv/fscons.open >>/srv/fscons.open
+killfossil
+
+# install permanent fossil configuration
+sed '/^fsys main config/c\
+fsys main config '^$fosspart $fossconf >/tmp/fossil-no-list.conf
+fossil/conf -w $fosspart /tmp/fossil-no-list.conf

+ 5 - 79
rc/bin/mkusbboot

@@ -14,33 +14,13 @@ quantum=1000000
 # (sources, /n/sources/plan9, ~370MB).
 size=1900
 
-fn killfossil {
-	sleep 1
-	unmount /n/f &
-	sleep 1
-	rm -f /srv/^(fossil fossil.open fscons fscons.open)
-	kill fossil | rc
-	sleep 1
-}
-
-fn sendexpect {		# send expect timeout
-	echo $1
-	if(! dial/expect -qt $3 $2)
-		echo -n 'no '^$"1^'...' > /dev/cons
-}
-
 fn usage {
 	echo usage: $argv0 '[-p proto] [-r root] [-s 10⁶-bytes]' >[1=2]
 	exit usage
 }
 
-fn sigexit {
-	rm -f /tmp/^(9load fossil-no-list.conf)
-	exit
-}
 fn sigint sighup sigterm {
-	rm -f /tmp/^(9load fossil-no-list.conf)
-	killfossil
+	rm -f /tmp/9load
 	exit note
 }
 
@@ -98,63 +78,9 @@ disk/format -b /$objtype/pbslba -d -r 2 9fat /tmp/9load $k \
 	grep -v '^(add .* at clust |Init|type |Adding file|used )'
 cp /dev/zero nvram >[2]/dev/null
 cp /dev/zero fscfg >[2]/dev/null
+rm -f /tmp/9load
 
-# initialise fossil
-echo -n fossil init... >[1=2]
-fossil/flfmt -y fossil
-
-# install listen-less config for fossil creation
-{
-	grep -v '^listen ' $syscfg/usb/fossil.conf
-	echo create /active/adm adm sys d775
-	echo create /active/adm/users adm sys 664
-} >/tmp/fossil-no-list.conf
-fossil/conf -w fossil /tmp/fossil-no-list.conf
-if (test -e /srv/fossil -o -e /srv/fossil.open) {
-	echo $0: /srv/fossil* exists, not safe to start a new one >[1=2]
-	exit exists
-}
-
-# start fossil
-fossil/fossil -f /dev/sdXX/fossil
-mount -cC /srv/fossil.open /n/f
-
-# set up /adm/users
-cp /adm/users /n/f/adm
-{
-	echo
-	dial/drain &
-	sleep 2
-	sendexpect 'users -r /active/adm/users' ': ' 5
-} </srv/fscons.open >>/srv/fscons.open
-
-# remount with new users
-unmount /n/f
-mount -cC /srv/fossil.open /n/f
-
-# populate fossil
+# fill the fossil
 9fs $srcfs
-@ {
-	# logs are boring, make them all appear empty
-	chmod +arw /tmp/empty-log >/tmp/empty-log
-	cd $srcroot/sys/log && {
-		for (f in [0-9a-z]* */*)
-			if (! ~ $f httpd mkfile smtpdb timesync.d vac year)
-				bind /tmp/empty-log $f
-	}
-	cd /tmp
-	disk/mkfs -u $srcroot/adm/users -U -d /n/f -s $srcroot $proto
-}
-
-# stop fossil gracefully
-{
-	echo
-	dial/drain &
-	sleep 2
-	sendexpect 'fsys all sync' ': ' 120
-	sendexpect 'fsys all halt' ': ' 5
-} </srv/fscons.open >>/srv/fscons.open
-killfossil
-
-# install permanent fossil configuration
-fossil/conf -w fossil $syscfg/usb/fossil.conf
+echo -n load fossil... >[1=2]
+exec loadfossil /dev/sdXX/fossil $srcroot $proto $syscfg/usb/fossil.conf

+ 49 - 4
sys/lib/sysconfig/proto/stand-usb

@@ -114,6 +114,50 @@ amd64	- sys sys
 		*	- sys sys
 		ape	- sys sys
 			+	- sys sys
+arm	- sys sys
+	*	- sys sys
+	bin	- sys sys
+		*	- sys sys
+		ape	- sys sys
+			+	- sys sys
+		auth	- sys sys
+			+	- sys sys
+		aux	- sys sys
+			+	- sys sys
+		aviation	- sys sys
+			+	- sys sys
+		bitsy	- sys sys
+			+	- sys sys
+		dial	- sys sys
+			+	- sys sys
+		disk	- sys sys
+			+	- sys sys
+		fossil	- sys sys
+			+	- sys sys
+		fs	- sys sys
+			+	- sys sys
+		games	- sys sys
+			+	- sys sys
+		ip	- sys sys
+			+	- sys sys
+		ndb	- sys sys
+			+	- sys sys
+		replica	- sys sys
+			+	- sys sys
+		upas	- sys sys
+			+	- sys sys
+		usb	- sys sys
+			+	- sys sys
+		venti	- sys sys
+			+	- sys sys
+	include	- sys sys
+		*	- sys sys
+		ape	- sys sys
+			+	- sys sys
+	lib	- sys sys
+		*	- sys sys
+		ape	- sys sys
+			+	- sys sys
 
 # everything else is owned by sys
 acme	- sys sys
@@ -121,10 +165,11 @@ acme	- sys sys
 cron	- sys sys
 	upas	- upas sys
 		+	- upas sys
-fd	- sys sys
-	+	- sys sys
-env	- sys sys
-	+	- sys sys
+# these are in #/
+#fd	- sys sys
+#	+	- sys sys
+#env	- sys sys
+#	+	- sys sys
 lib	- sys sys
 	*	- sys sys
 	cmap	- sys sys

+ 69 - 0
sys/man/8/loadfossil

@@ -0,0 +1,69 @@
+.TH LOADFOSSIL 8
+.SH NAME
+loadfossil - populate a fossil filesystem
+.SH SYNOPSIS
+.B loadfossil
+.I fossil
+.I root
+.I proto
+.I fossil.conf
+.SH DESCRIPTION
+.I Loadfossil
+formats the partition (or file)
+.IR fossil
+as a
+.IR fossil (4)
+file system,
+populates it with files from
+.I root
+using the
+.IR mkfs (8)
+prototype file
+.I proto
+and installs a configuration derived from
+.IR fossil.conf .
+.PP
+The
+.LR "fsys main config"
+line of
+.I fossil.conf
+will be replaced by a reference to
+.IR fossil ,
+so
+.I fossil
+ought to be a full path name.
+.SH EXAMPLES
+Create a standalone
+.I fossil
+root filesystem for a laptop from the local Plan 9 installation.
+.IP
+.EX
+sc=/sys/lib/sysconfig
+loadfossil /dev/sdC0/fossil /n/boot $sc/proto/stand-usb \e
+	$sc/usb/fossil.conf
+.EE
+.SH FILES
+.TF /srv/fscons.open
+.PD 0
+.TP
+.B /srv/fossil
+.TP
+.B /srv/fossil.open
+.TP
+.B /srv/fscons
+.TP
+.B /srv/fscons.open
+files created while executing
+.SH SOURCE
+.B /rc/bin/loadfossil
+.SH SEE ALSO
+.IR fossilcons (8),
+.IR mkusbboot (8),
+.IR prep (8)
+.SH BUGS
+Due to name clashes in
+.BR /srv ,
+should be run only on machines with no running
+.I fossil
+instance named
+.LR fossil .

+ 7 - 6
sys/man/8/mkusbboot

@@ -21,15 +21,13 @@ called
 from the filesystem at
 .I root
 (by default
-.B /n/boot
-but could be
-.BR /n/sources/plan9 ),
-and using the
+.BR /n/boot ),
+.\" but could be
+.\" .BR /n/sources/plan9 ),
+using the
 .IR mkfs (8)
 prototype file
 .I proto
-(by default
-.BR /sys/lib/sysconfig/proto/stand-usb )
 and files in
 .BR /sys/lib/sysconfig/usb .
 .PP
@@ -77,6 +75,8 @@ and
 for the generated system
 .TP
 .B /sys/lib/sysconfig/proto/stand-usb
+default
+.I proto
 .TP
 .B /env/objtype
 architecture of the boot programs in the disk image
@@ -98,6 +98,7 @@ files created while executing
 .IR usb (4),
 .IR boot (8),
 .IR diskparts (8),
+.IR loadfossil (8),
 .IR partfs (8),
 .IR plan9.ini (8),
 .IR prep (8)

+ 5 - 18
sys/man/8/prep

@@ -708,20 +708,6 @@ disk/prep -bw -a^(9fat nvram fossil cache swap) /dev/sdC0/plan9
 disk/format -b /386/pbslba -d -r 2 /dev/sdC0/9fat \e
 	/386/9load /386/9pcf /tmp/plan9.ini
 .EE
-.PP
-Create a bootable USB disk or flash-memory device to be booted
-via the BIOS and containing only a FAT Plan 9 partition.
-.IP
-.EX
-disk/partfs /dev/sdU0.0/data
-cd /dev/sdXX
-disk/mbr -m /386/mbr data
-disk/fdisk -baw data
-disk/prep -bw -a^(9fat nvram fossil) plan9
-cp /386/9loadusb /tmp/9load  # force format to use the name `9load'
-disk/format -b /386/pbslba -d -r 2 9fat /tmp/9load \e
-	/386/9pccpuf /tmp/plan9.ini
-.EE
 .SH FILES
 .TF /386/mbr.bootmgr
 .TP
@@ -730,21 +716,22 @@ disk/format -b /386/pbslba -d -r 2 9fat /tmp/9load \e
 .B /386/mbr.bootmgr
 self-configuring `smart boot manager'
 .SH SOURCE
-.TF /sys/src/cmd/disk/prep
+.TF /n/sources/extra/bootmgr.tgz
 .TP
 .B /sys/src/cmd/disk/prep
 .TP
 .B /sys/src/boot/pc
 .TP
 .B /n/sources/extra/bootmgr.tgz
-source for
-.BR /386/mbr.bootmgr ;
-compilable on (l)unix
+.I nasm
+assembler source for
+.B /386/mbr.bootmgr
 .SH SEE ALSO
 .IR floppy (3),
 .IR sd (3),
 .IR usb (4),
 .IR 9load (8),
+.IR mkusbboot (8),
 .IR partfs (8)
 .SH BUGS
 .I Format

+ 13 - 1
sys/src/9/pc/vgamach64xx.c

@@ -190,11 +190,23 @@ mach64xxenable(VGAscr* scr)
 static void
 mach64xxlinear(VGAscr* scr, int size, int)
 {
+	ulong mmiophys;
+
 	vgalinearpci(scr);
 	if(scr->paddr == 0)
 		return;
+	/*
+	 * vgalinearpci sets framebuffer into write combining mode.
+	 * Because mmio register page is inside framebuffer space,
+	 * set it back to uncached.
+	 */
+	mmiophys = scr->paddr + size - BY2PG;
+	if(!waserror()){
+		mtrr(mmiophys, BY2PG, "uc");
+		poperror();
+	}
 	scr->mmio = (ulong*)((uchar*)scr->vaddr+size-1024);
-	addvgaseg("mach64mmio", scr->paddr+size-BY2PG, BY2PG);
+	addvgaseg("mach64mmio", mmiophys, BY2PG);
 	addvgaseg("mach64screen", scr->paddr, scr->apsize);
 }
 

+ 7 - 0
sys/src/boot/pc/load.c

@@ -7,6 +7,10 @@
 #include "sd.h"
 #include "fs.h"
 
+enum {
+	Datamagic = 0xcafebabe,
+};
+
 /*
  * "cache" must be in this list so that 9load will pass the definition of
  * the cache partition into the kernel so that the disk named by the `cfs'
@@ -314,6 +318,7 @@ main(void)
 	int flag, i, mode, tried;
 	char def[2*NAMELEN], line[80], *p, *file;
 	Type *tp;
+	static ulong vfy = Datamagic;
 
 	i8042a20();
 	memset(m, 0, sizeof(Mach));
@@ -338,6 +343,8 @@ main(void)
 	if((ulong)&end > (KZERO|(640*1024)))
 		panic("i'm too big");
 
+	if (vfy != Datamagic)
+		panic("data segment incorrectly aligned or loaded");
 	if (!pxe)
 		/* TODO turning off debug and debugload makes loading fail */
 		debug = 1;

+ 11 - 3
sys/src/boot/pc/pci.c

@@ -420,8 +420,10 @@ pcirouting(void)
 		if (p[0] == '$' && p[1] == 'P' && p[2] == 'I' && p[3] == 'R')
 			break;
 
-	if (p >= (uchar *)KADDR(0xfffff))
+	if (p >= (uchar *)KADDR(0xfffff)) {
+		print("no pci routing table in bios");
 		return;
+	}
 
 	r = (router_t *)p;
 
@@ -546,9 +548,15 @@ pcicfginit(void)
 		outb(PciCSE, n);
 	}
 
-	if(pcicfgmode < 0)
-		goto out;
+	if(pcicfgmode < 0) {
+		static int whined;
 
+		if (!whined) {
+			print("pcicfginit failed!\n");
+			whined = 1;
+		}
+		goto out;
+	}
 
 	if(p = getconf("*pcimaxbno"))
 		pcimaxbno = strtoul(p, 0, 0);

+ 1 - 0
sys/src/cmd/aux/consolefs.c

@@ -1263,6 +1263,7 @@ usage(void)
 void
 threadmain(int argc, char **argv)
 {
+	rfork(RFNOTEG);
 	fmtinstall('F', fcallfmt);
 
 	ARGBEGIN{

+ 1 - 0
sys/src/cmd/init.c

@@ -27,6 +27,7 @@ main(int argc, char *argv[])
 	char ctl[128];
 
 	closefds();
+	alarm(0);
 
 	service = "cpu";
 	manual = 0;

+ 36 - 15
sys/src/libc/9sys/dial.c

@@ -53,6 +53,9 @@ struct Dest {
 	Conn	*connend;
 	int	nkid;
 
+	long	oalarm;
+	int	naddrs;
+
 	QLock	winlck;
 	int	winner;			/* index into conn[] */
 
@@ -140,10 +143,15 @@ connsalloc(Dest *dp, int addrs)
 static void
 freedest(Dest *dp)
 {
-	if (dp != nil) {
-		free(dp->conn);
-		free(dp);
-	}
+	long oalarm;
+
+	if (dp == nil)
+		return;
+	oalarm = dp->oalarm;
+	free(dp->conn);
+	free(dp);
+	if (oalarm >= 0)
+		alarm(oalarm);
 }
 
 static void
@@ -233,7 +241,7 @@ connectwait(Dest *dp, char *besterr)
 	/* kill all of our still-live kids & reap them */
 	for (conn = dp->conn; conn < dp->connend; conn++)
 		if (!conn->dead)
-			postnote(PNPROC, conn->pid, "die");
+			postnote(PNPROC, conn->pid, "alarm");
 	while (reap(dp) >= 0)
 		;
 
@@ -276,9 +284,12 @@ pickuperr(char *besterr, char *err)
 }
 
 static void
-catcher(void*, char *)
+catcher(void *, char *s)
 {
-	noted(NDFLT);
+	if (strstr(s, "alarm") != nil)
+		noted(NCONT);
+	else
+		noted(NDFLT);
 }
 
 /*
@@ -289,7 +300,7 @@ catcher(void*, char *)
 static int
 dialmulti(DS *ds, Dest *dp)
 {
-	int rv, kid, kidme, oalarm;
+	int rv, kid, kidme;
 	char *clone, *dest;
 	char err[ERRMAX], besterr[ERRMAX];
 
@@ -302,11 +313,8 @@ dialmulti(DS *ds, Dest *dp)
 		if (kid < 0)
 			--dp->nkid;
 		else if (kid == 0) {
-			/* die on alarm, avoid atnotify callbacks */
+			/* only in kid, to avoid atnotify callbacks in parent */
 			notify(catcher);
-			/* don't override outstanding alarm */
-			oalarm = alarm(0);
-			alarm(oalarm > 0? oalarm: Maxconnms);
 
 			*besterr = '\0';
 			rv = call(clone, dest, ds, dp, &dp->conn[kidme]);
@@ -336,6 +344,7 @@ csdial(DS *ds)
 	if(dp == nil)
 		return -1;
 	dp->winner = -1;
+	dp->oalarm = alarm(0);
 	if (connsalloc(dp, 1) < 0) {		/* room for a single conn. */
 		freedest(dp);
 		return -1;
@@ -390,6 +399,7 @@ csdial(DS *ds)
 
 	*besterr = 0;
 	rv = -1;				/* pessimistic default */
+	dp->naddrs = addrs;
 	if (addrs == 0)
 		werrstr("no address to dial");
 	else if (addrs == 1) {
@@ -413,7 +423,7 @@ csdial(DS *ds)
 static int
 call(char *clone, char *dest, DS *ds, Dest *dp, Conn *conn)
 {
-	int fd, cfd, n, oalarm;
+	int fd, cfd, n, calleralarm, oalarm;
 	char cname[Maxpath], name[Maxpath], data[Maxpath], *p;
 
 	/* because cs is in a different name space, replace the mount point */
@@ -448,6 +458,13 @@ call(char *clone, char *dest, DS *ds, Dest *dp, Conn *conn)
 		snprint(conn->dir, NETPATHLEN, "%s/%s", cname, name);
 	snprint(data, sizeof(data), "%s/%s/data", cname, name);
 
+	/* should be no alarm pending now; re-instate caller's alarm, if any */
+	calleralarm = dp->oalarm > 0;
+	if (calleralarm)
+		alarm(dp->oalarm);
+	else if (dp->naddrs > 1)	/* in a sub-process? */
+		alarm(Maxconnms);
+
 	/* connect */
 	if(ds->local)
 		snprint(name, sizeof(name), "connect %s %s", dest, ds->local);
@@ -458,24 +475,28 @@ call(char *clone, char *dest, DS *ds, Dest *dp, Conn *conn)
 		return -1;
 	}
 
+	oalarm = alarm(0);	/* don't let alarm interrupt critical section */
+	if (calleralarm)
+		dp->oalarm = oalarm;	/* time has passed, so update user's */
+
 	/* open data connection */
 	conn->dfd = fd = open(data, ORDWR);
 	if(fd < 0){
 		closeopenfd(&conn->cfd);
+		alarm(dp->oalarm);
 		return -1;
 	}
 	if(ds->cfdp == nil)
 		closeopenfd(&conn->cfd);
 
 	n = conn - dp->conn;
-	oalarm = alarm(0);	/* don't let alarm interrupt critical section */
 	if (dp->winner < 0) {
 		qlock(&dp->winlck);
 		if (dp->winner < 0 && conn < dp->connend)
 			dp->winner = n;
 		qunlock(&dp->winlck);
 	}
-	alarm(oalarm);
+	alarm(calleralarm? dp->oalarm: 0);
 	return fd;
 }