Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/boot/boot.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname boot/boot.c 1992/0317
## diff -e /dev/null /n/bootesdump/1992/0317/sys/src/9/boot/boot.c
0a
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include "../port/bootp.h"
#include "../port/arp.h"

#define DEFSYS "bootes"
typedef struct Net	Net;
typedef struct Flavor	Flavor;

enum
{
	Nterm	= 4,
	CtrlD	= 4,
	Cr	= 13,
	View	= 0x80,
};

Fcall	hdr;
int	printcol;

char	cputype[NAMELEN];
char	terminal[NAMELEN];
char	sys[2*NAMELEN];
char	username[NAMELEN];

int mflag;
int fflag;
int kflag;

void	nop(int);
void	session(int);
int	cache(int);
void	swapproc(void);
void	settime(int);
Method	*rootserver(char*);

void
main(int argc, char *argv)
{
	int fd;
	Method *mp;
	char cmd[64];
	char flags[5];
	int islocal;

	sleep(1000);

	open("#c/cons", OREAD);
	open("#c/cons", OWRITE);
	open("#c/cons", OWRITE);

	ARGBEGIN{
	case 'u':
		strcpy(username, ARGF());
		break;
	case 'k':
		kflag = 1;
		break;
	case 'm':
		mflag = 1;
		break;
	case 'f':
		fflag = 1;
		break;
	}ARGEND

	readenv("cputype", cputype, sizeof(cputype));
	readenv("terminal", terminal, sizeof(cputype));

	/*
	 *  pick a method and initialize it
	 */
	mp = rootserver(*argv);
	islocal = strcmp(mp->name, "local") == 0;
	(*mp->config)(mp);

	/*
	 *  get/set key or password
	 */
	(*pword)(mp);

	/*
	 *  connect to the root file system
	 */
	fd = (*mp->connect)();
	if(fd < 0)
		fatal("can't connect to file server");
	if(!islocal){
		nop(fd);
		session(fd);
		fd = cache(fd);
		srvcreate(sys, fd);
	}
	srvcreate("boot", fd);

	/*
	 *  create the name space, mount the root fs
	 */
	if(bind("/", "/", MREPL) < 0)
		fatal("bind");
	if(mount(fd, "/", MAFTER|MCREATE, "", "") < 0)
		fatal("mount");
	close(fd);

	/*
	 *  start local fs if its not the root file server
	 */
	if(!islocal){
		for(mp = method; mp->name; mp++)
			if(strcmp(mp->name, "local")==0){
				local = (*mp->connect)(mp);
				if(local < 0)
					break;
				if(mount(local, "/n/kfs", MAFTER|MCREATE, "", "") < 0)
					fatal("mount");
				close(local);
				break;
			}
	}

	settime(islocal);
	swapproc();

	sleep(1000);
	sprint(cmd, "/%s/init", cputype);
	sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m", "");
	execl(cmd, "init", flags, 0);
	fatal(cmd);
}

/*
 *  ask user from whence comes the root file system
 */
Method*
rootserver(char *arg)
{
	char prompt[256];
	char reply[64];
	Method *mp;
	char *cp;
	int n;

	mp = method;
	n = 0;
	sprint(prompt, "root is from (", mp->name);
	for(mp++; mp->name; mp++)
		n += sprint(prompt+n, ", %s", mp->name);
	sprint(prompt+n, ")");

	for(;;){
		strcpy(reply, method->name);
		if(arg == 0)
			outin(prompt, reply, sizeof(reply));
		else
			strcpy(reply, arg);
		arg = 0;
		for(mp = method; mp->name; mp++)
			if(*reply == *mp->name){
				cp = strchr(reply, '!');
				if(cp)
					strcpy(sys, cp+1);
				return mp;
			}
		if(mp->name == 0)
			continue;
	}
}

void
nop(int fd)
{
	long n;

	print("nop...");
	hdr.type = Tnop;
	hdr.tag = NOTAG;
	n = convS2M(&hdr, buf);
	if(write(fd, buf, n) != n)
		fatal("write nop");
	n = read(fd, buf, sizeof buf);
	if(n==2 && buf[0]=='O' && buf[1]=='K')
		n = read(fd, buf, sizeof buf);
	if(n <= 0)
		fatal("read nop");
	if(convM2S(buf, &hdr, n) == 0) {
		print("n = %d; buf = %#.2x %#.2x %#.2x %#.2x\n",
			n, buf[0], buf[1], buf[2], buf[3]);
		fatal("format nop");
	}
	if(hdr.type != Rnop)
		fatal("not Rnop");
}

void
session(int fd)
{
	long n;

	print("session...");
	hdr.type = Tsession;
	hdr.tag = NOTAG;
	n = convS2M(&hdr, buf);
	if(write(fd, buf, n) != n)
		fatal("write session");
	n = read(fd, buf, sizeof buf);
	if(n <= 0)
		fatal("read session");
	if(convM2S(buf, &hdr, n) == 0)
		fatal("format session");
	if(hdr.type == Rerror){
		print("error %s;", hdr.ename);
		fatal(hdr.ename);
	}
	if(hdr.type != Rsession)
		fatal("not Rsession");
}

int
cache(int fd)
{
	ulong i;
	int p[2];
	char d[DIRLEN];
	char partition[2*NAMELEN];

	if(stat("/cfs", d) < 0)
		return fd;
	sprint(partition, "%scache", bootdisk);
	if(stat(partition, d) < 0)
		return fd;
	print("cfs...");
	if(pipe(p)<0)
		fatal("pipe");
	switch(fork()){
	case -1:
		fatal("fork");
	case 0:
		close(p[1]);
		dup(fd, 0);
		close(fd);
		dup(p[0], 1);
		close(p[0]);
		if(format)
			execl("/cfs", "bootcfs", "-fs", "-p", partition, 0);
		else
			execl("/cfs", "bootcfs", "-s", "-p", partition, 0);
		break;
	default:
		close(p[0]);
		close(fd);
		fd = p[1];
		break;
	}
	return fd;
}

void
swapproc(void)
{
	int fd;

	fd = open("#c/swap", OWRITE);
	if(fd < 0){
		warning("opening #c/swap");
		return;
	}
	if(write(fd, "start", 5) <= 0)
		warning("starting swap kproc");
}

void
settime(int islocal)
{
	int n, f;
	int timeset;
	Dir dir;
	char dirbuf[DIRLEN];
	char *srvname;

	print("time...");
	timeset = 0;
	if(islocal){
		/*
		 *  set the time from the real time clock
		 */
		f = open("#r/rtc", ORDWR);
		if(f >= 0){
			if((n = read(f, dirbuf, sizeof(dirbuf)-1)) > 0){
				dirbuf[n] = 0;
				timeset = 1;
			}
			close(f);
		}
	}
	if(timeset == 0){
		/*
		 *  set the time from the access time of the root
		 */
		f = open("#s/boot", ORDWR);
		if(f < 0)
			return;
		if(mount(f, "/n/boot", MREPL, "", "") < 0){
			close(f);
			return;
		}
		close(f);
		if(stat("/n/boot", dirbuf) < 0)
			fatal("stat");
		convM2D(dirbuf, &dir);
		sprint(dirbuf, "%ld", dir.atime);
		unmount(0, "/n/boot");
		/*
		 *  set real time clock if there is one
		 */
		f = open("#r/rtc", ORDWR);
		if(f > 0){
			write(f, dirbuf, strlen(dirbuf));
			close(f);
		}
		close(f);
	}

	f = open("#c/time", OWRITE);
	write(f, dirbuf, strlen(dirbuf));
	close(f);
}
.
## diffname boot/boot.c 1992/0318
## diff -e /n/bootesdump/1992/0317/sys/src/9/boot/boot.c /n/bootesdump/1992/0318/sys/src/9/boot/boot.c
270,326d
171,258d
155,156d
153c
	for(;;){
		if(arg == 0 || mflag)
.
151c
	if(arg)
		strcpy(reply, arg);
	else
.
145,146c
	n = sprint(prompt, "root is from (%s", mp->name);
.
133c
 *  ask user from whence cometh the root file system
.
127c
	sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m" : "");
.
117c
				close(fd);
.
115c
				if(mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") < 0)
.
112,113c
				(*mp->config)(mp);
				fd = (*mp->connect)();
				if(fd < 0)
.
107c
	 *  if a local file server exists and it's not the
	 *  root file server, start it and mount it onto /n/kfs
.
92c
		if(cfs)
			fd = (*cfs)(fd);
.
81c
	(*pword)(islocal, mp);
.
76a
	islocal = strcmp(mp->name, "local") == 0;
.
74,75c
	mp = rootserver(argc ? *argv : 0);
.
44c
	char flags[6];
.
39c
main(int argc, char *argv[])
.
35d
31,32d
11,19d
3,5c
#include "../boot/boot.h"
.
## diffname boot/boot.c 1992/0319
## diff -e /n/bootesdump/1992/0318/sys/src/9/boot/boot.c /n/bootesdump/1992/0319/sys/src/9/boot/boot.c
114d
## diffname boot/boot.c 1992/0320
## diff -e /n/bootesdump/1992/0319/sys/src/9/boot/boot.c /n/bootesdump/1992/0320/sys/src/9/boot/boot.c
91a
	newkernel();
.
## diffname boot/boot.c 1992/0321
## diff -e /n/bootesdump/1992/0320/sys/src/9/boot/boot.c /n/bootesdump/1992/0321/sys/src/9/boot/boot.c
80d
## diffname boot/boot.c 1992/0322
## diff -e /n/bootesdump/1992/0321/sys/src/9/boot/boot.c /n/bootesdump/1992/0322/sys/src/9/boot/boot.c
145d
142,143c
	for(notfirst = 0;; notfirst = 1){
		if(mflag || notfirst)
.
130a
	int notfirst;
.
115c
	sprint(flags, "-%s%s%s", cpuflag ? "c" : "t", mflag ? "m" : "", aflag ? "a" : "");
.
39a
	case 'a':
		aflag = 1;
		break;
.
18a
int aflag;
.
## diffname boot/boot.c 1992/0323
## diff -e /n/bootesdump/1992/0322/sys/src/9/boot/boot.c /n/bootesdump/1992/0323/sys/src/9/boot/boot.c
148c
		if(pflag || notfirst)
.
92c
	if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0)
.
52a
	case 'p':
		pflag = 1;
		break;
.
50a
		pflag = 1;
.
19a
int pflag;
.
14a
char 	*sauth = "";
.
## diffname boot/boot.c 1992/0325
## diff -e /n/bootesdump/1992/0323/sys/src/9/boot/boot.c /n/bootesdump/1992/0325/sys/src/9/boot/boot.c
98,99c
	sauth = "";
	if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0){
		sauth = "any";
		if(mount(fd, "/", MAFTER|MCREATE, "", sauth) < 0)
			fatal("mount");
	}
.
15c
char	*sauth;
.
## diffname boot/boot.c 1992/0327
## diff -e /n/bootesdump/1992/0325/sys/src/9/boot/boot.c /n/bootesdump/1992/0327/sys/src/9/boot/boot.c
119c
					print("failed to mount kfs\n");
.
## diffname boot/boot.c 1992/0520
## diff -e /n/bootesdump/1992/0327/sys/src/9/boot/boot.c /n/bootesdump/1992/0520/sys/src/9/boot/boot.c
169a
	return 0;		/* not reached */
.
## diffname boot/boot.c 1992/0522
## diff -e /n/bootesdump/1992/0520/sys/src/9/boot/boot.c /n/bootesdump/1992/0522/sys/src/9/boot/boot.c
28c
boot(int argc, char *argv[])
.
15a
char	bootfile[3*NAMELEN];
.
## diffname boot/boot.c 1992/0530
## diff -e /n/bootesdump/1992/0522/sys/src/9/boot/boot.c /n/bootesdump/1992/0530/sys/src/9/boot/boot.c
174c
static void
.
66a
	getconffile(conffile, terminal);
.
24,26c
static void	swapproc(void);
static Method	*rootserver(char*);
.
16a
char	conffile[NAMELEN];
.
## diffname boot/boot.c 1992/0609
## diff -e /n/bootesdump/1992/0530/sys/src/9/boot/boot.c /n/bootesdump/1992/0609/sys/src/9/boot/boot.c
107c
	if(cpuflag == 0)
		newkernel();
.
## diffname boot/boot.c 1992/0610
## diff -e /n/bootesdump/1992/0609/sys/src/9/boot/boot.c /n/bootesdump/1992/0610/sys/src/9/boot/boot.c
65,66c
	readfile("#e/cputype", cputype, sizeof(cputype));
	readfile("#e/terminal", terminal, sizeof(cputype));
.
42a
/*	for(fd = 0; fd < argc; fd++)
		print("%s ", argv[fd]);
	print("\n");/**/

.
## diffname boot/boot.c 1992/0611
## diff -e /n/bootesdump/1992/0610/sys/src/9/boot/boot.c /n/bootesdump/1992/0611/sys/src/9/boot/boot.c
118,129c
	for(mp = method; mp->name; mp++){
		if(strcmp(mp->name, "local") != 0)
			continue;
		if(access("#s/kfs", ORDWR) >= 0)
			break;
		(*mp->config)(mp);
		fd = (*mp->connect)();
		if(fd < 0)
			break;
		if(mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") < 0)
			print("failed to mount kfs\n");
		close(fd);
		break;
.
115,116c
	 *  if a local file server exists and it's not
	 *  running, start it and mount it onto /n/kfs
.
## diffname boot/boot.c 1992/0725
## diff -e /n/bootesdump/1992/0611/sys/src/9/boot/boot.c /n/bootesdump/1992/0725/sys/src/9/boot/boot.c
42d
## diffname boot/boot.c 1992/0813
## diff -e /n/bootesdump/1992/0725/sys/src/9/boot/boot.c /n/bootesdump/1992/0813/sys/src/9/boot/boot.c
42c
/**/	print("argc=%d\n", argc);
	for(fd = 0; fd < argc; fd++)
.
## diffname boot/boot.c 1992/0814
## diff -e /n/bootesdump/1992/0813/sys/src/9/boot/boot.c /n/bootesdump/1992/0814/sys/src/9/boot/boot.c
42c
/*	print("argc=%d\n", argc);
.
## diffname boot/boot.c 1992/0902
## diff -e /n/bootesdump/1992/0814/sys/src/9/boot/boot.c /n/bootesdump/1992/0902/sys/src/9/boot/boot.c
123,130c
		}
.
118,121c
	if(!islocal){
		for(mp = method; mp->name; mp++){
			if(strcmp(mp->name, "local") != 0)
				continue;
			(*mp->config)(mp);
			fd = (*mp->connect)();
			if(fd < 0)
				break;
			mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") ;
			close(fd);
.
## diffname boot/boot.c 1992/0909
## diff -e /n/bootesdump/1992/0902/sys/src/9/boot/boot.c /n/bootesdump/1992/0909/sys/src/9/boot/boot.c
118c
	if(!islocal && !ishybrid){
.
91c
	if(!islocal && !ishybrid){
.
78a
	ishybrid = strcmp(mp->name, "hybrid") == 0;
.
35c
	int islocal, ishybrid;
.
## diffname boot/boot.c 1992/0918
## diff -e /n/bootesdump/1992/0909/sys/src/9/boot/boot.c /n/bootesdump/1992/0918/sys/src/9/boot/boot.c
169,170c
			if(strncmp(reply, mp->name, j) == 0){
.
167a
		cp = strchr(reply, '!');
		if(cp)
			j = cp - reply;
		else
			j = strlen(reply);
.
152c
	int n, j;
.
## diffname boot/boot.c 1992/1006
## diff -e /n/bootesdump/1992/0918/sys/src/9/boot/boot.c /n/bootesdump/1992/1006/sys/src/9/boot/boot.c
119c
	if(access("#s/kfs", 0) < 0){
.
## diffname boot/boot.c 1992/1021
## diff -e /n/bootesdump/1992/1006/sys/src/9/boot/boot.c /n/bootesdump/1992/1021/sys/src/9/boot/boot.c
46a
	if(argc <= 1)
		pflag = 1;

.
## diffname boot/boot.c 1993/0330
## diff -e /n/bootesdump/1992/1021/sys/src/9/boot/boot.c /n/bootesdump/1993/0330/sys/src/9/boot/boot.c
137a
	remove("#e/password");
.
136a
	close(afd);
.
130c
			mount(fd, "/n/kfs", MAFTER|MCREATE, "") ;
.
108,113c
	if(mount(fd, "/", MAFTER|MCREATE, "") < 0)
		fatal("mount");
.
99a
		doauthenticate(fd, mp);
.
97d
23a
int afd = -1;
.
15d
2a
#include <auth.h>
.
## diffname boot/boot.c 1993/0402
## diff -e /n/bootesdump/1993/0330/sys/src/9/boot/boot.c /n/bootesdump/1993/0402/sys/src/9/boot/boot.c
97d
## diffname boot/boot.c 1993/0501
## diff -e /n/bootesdump/1993/0402/sys/src/9/boot/boot.c /n/fornaxdump/1993/0501/sys/src/brazil/boot/boot.c
197a
	close(fd);
}

void
reattach(int rec, Method *amp, char *buf)
{
	char *mp;
	int fd, n, sv[2];
	char tmp[64], *p;

	mp = strchr(buf, ' ');
	if(mp == 0)
		goto fail;
	*mp++ = '\0';

	p = strrchr(buf, '/');
	if(p == 0)
		goto fail;
	*p = '\0';

	sprint(tmp, "%s/remote", buf);
	fd = open(tmp, OREAD);
	if(fd < 0)
		goto fail;
	n = read(fd, tmp, sizeof(tmp));
	if(n < 0)
		goto fail;
	close(fd);
	tmp[n-1] = '\0';

	print("boot: Service %s down, wait...\n", tmp);

	p = strrchr(buf, '/');
	if(p == 0)
		goto fail;
	*p = '\0';

	while(plumb(buf, tmp, sv, 0) < 0)
		sleep(30);

	nop(sv[1]);
	doauthenticate(sv[1], amp);

	print("boot: Service %s Ok\n", tmp);

	n = sprint(tmp, "%d %s", sv[1], mp);
	if(write(rec, tmp, n) < 0) {
		errstr(tmp);
		print("write recover: %s\n", tmp);
	}
	exits(0);
fail:
	print("recover fail: %s\n", buf);
	exits(0);
}

void
recover(Method *mp)
{
	int fd, n;
	char buf[256];

	fd = open("#/./recover", ORDWR);
	if(fd < 0)
		exits(0);

	for(;;) {
		n = read(fd, buf, sizeof(buf));
		if(n < 0)
			exits(0);
		buf[n] = '\0';

		if(fork() == 0)
			reattach(fd, mp, buf);
	}
.
185a
int
nop(int fd)
{
	int n;
	Fcall hdr;
	char buf[128];

	print("boot: nop...");
	hdr.type = Tnop;
	hdr.tag = NOTAG;
	n = convS2M(&hdr, buf);
	if(write(fd, buf, n) != n){
		fatal("write nop");
		return 0;
	}
reread:
	n = read(fd, buf, sizeof buf);
	if(n <= 0){
		fatal("read nop");
		return 0;
	}
	if(n == 2)
		goto reread;
	if(convM2S(buf, &hdr, n) == 0) {
		fatal("format nop");
		return 0;
	}
	if(hdr.type != Rnop){
		fatal("not Rnop");
		return 0;
	}
	if(hdr.tag != NOTAG){
		fatal("tag not NOTAG");
		return 0;
	}
	return 1;
}

.
135d
95a
	nop(fd);
.
89a
	switch(rfork(RFPROC|RFNAMEG|RFFDG)) {
	case -1:
		print("failed to start recover: %r\n");
		break;
	case 0:
		recover(mp);
		break;
	}

.
26a
static void	recover(Method*);
.
18,25c
int	printcol;
int	mflag;
int	fflag;
int	kflag;
int	aflag;
int	pflag;
int	afd = -1;
.
10,11d
6d
3a
#include <fcall.h>
.
## diffname boot/boot.c 1993/0525
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/boot/boot.c /n/fornaxdump/1993/0525/sys/src/brazil/boot/boot.c
44a

	ethertest();
.
41c
	print("argc=%d\n", argc);
.
27a
ethertest(void)
{
	int cf, df, n, t;
	char buf[64];
	struct Etherpkt
	{
		uchar	d[6];
		uchar	s[6];
		uchar	type[2];
	} p;

	cf = open("#l/ether/clone", ORDWR);
	if(cf < 0){
		print("can't open #l/ether/clone: %r\n");
		exits(0);
	}
	n = read(cf, buf, 12);
	if(n < 0){
		print("can't read #l/ether/clone: %r\n");
		exits(0);
	}
	buf[n] = 0;
	sprint(buf, "#l/ether/%d/data", atoi(buf));
	df = open(buf, ORDWR);
	if(df < 0){
		print("can't open %s: %r\n", buf);
		exits(0);
	}
	if(write(cf, "connect -1", sizeof("connect -1")-1) < 0){
		print("can't connect -1: %r\n");
		exits(0);
	}
	close(cf);
	for(;;){
		n = read(df, &p, sizeof(p));
		if(n <= 0){
			print("read returns %d: %r\n", n);
			continue;
		}
		t = (p.type[0]<<8) | p.type[1];
		print("%d %2.2ux%2.2ux%2.2ux%2.2ux%2.2ux%2.2ux -> %2.2ux%2.2ux%2.2ux%2.2ux%2.2ux%2.2ux %ux\n", n, p.s[0], p.s[1], p.s[2], p.s[3], p.s[4], p.s[5], p.d[0], p.d[1], p.d[2], p.d[3], p.d[4], p.d[5], t);
	}
}

void
.
## diffname boot/boot.c 1993/0528
## diff -e /n/fornaxdump/1993/0525/sys/src/brazil/boot/boot.c /n/fornaxdump/1993/0528/sys/src/brazil/boot/boot.c
90a
	pipetest();
	pipetest2();
.
89c
	print("\n");
#endif DEBUG
.
85a
#ifdef DEBUG
.
69a
	close(df);
.
61c
	for(i=0;i<20;i++){
.
30c
	int cf, df, n, t, i;
.
27a
pipetest(void)
{
	int i, n, p[2];
	ulong buf[1];

	if(bind("#c", "/dev", MREPL) < 0)
		print("can't bind #c\n");

	if(pipe(p) < 0){
		print("pipe fails\n");
		exits(0);
	}
	switch(fork()){
	case -1:
		print("fork fails\n");
		exits(0);
	case 0:
		close(p[0]);
		for(;;){
			n = read(p[1], buf, 1);
			if(n <= 0){
				print("1 exiting %d\n", time(0));
				exits(0);
			}
			write(p[1], buf, 1);
		}
	default:
		close(p[1]);
		print("start %d\n", time(0));
		for(i = 0; i < 100000; i++){
			if(write(p[0], buf, 1) != 1){
				print("sndr broke\n");
				exits(0);
			}
			n = read(p[0], buf, 1);
			if(n <= 0){
				print("0 exiting %d\n", time(0));
				exits(0);
			}
		}
		close(p[0]);
		sleep(1000);
	}
}

void
pipetest2(void)
{
	int i, n, p[2];
	uchar buf[4096];

	if(bind("#c", "/dev", MREPL) < 0)
		print("can't bind #c\n");

	if(pipe(p) < 0){
		print("pipe fails\n");
		exits(0);
	}
	switch(fork()){
	case -1:
		print("fork fails\n");
		exits(0);
	case 0:
		close(p[0]);
		for(;;){
			n = read(p[1], buf, sizeof(buf));
			if(n <= 0){
				print("1 exiting %d\n", time(0));
				exits(0);
			}
		}
	default:
		close(p[1]);
		print("start %d\n", time(0));
		for(i = 0; i < 40000; i++){
			if(write(p[0], buf, sizeof(buf)) != sizeof(buf)){
				print("sndr broke\n");
				exits(0);
			}
		}
		close(p[0]);
		sleep(1000);
	}

}

void
.
## diffname boot/boot.c 1993/0601
## diff -e /n/fornaxdump/1993/0528/sys/src/brazil/boot/boot.c /n/fornaxdump/1993/0601/sys/src/brazil/boot/boot.c
180a
	intest();
.
27a
intest(void)
{
	int n;
	char buf[128];

	print(">");
	n = read(0, buf, sizeof(buf)-1);
print("read %d bytes\n", n);
	write(1, buf, n);
}

void
.
## diffname boot/boot.c 1993/0724
## diff -e /n/fornaxdump/1993/0601/sys/src/brazil/boot/boot.c /n/fornaxdump/1993/0724/sys/src/brazil/boot/boot.c
192,196d
28,172d
## diffname boot/boot.c 1994/0219
## diff -e /n/fornaxdump/1993/0724/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/0219/sys/src/brazil/boot/boot.c
171,174c
	strcpy(reply, method->name);
	if(arg){
		j = strlen(arg);
		for(mp = method; mp->name; mp++)
			if(strncmp(arg, mp->name, j) == 0)
				break;
		if(mp->name)
			strcpy(reply, arg);
	}

.
## diffname boot/boot.c 1994/0311
## diff -e /n/fornaxdump/1994/0219/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/0311/sys/src/brazil/boot/boot.c
197a

.
195,196c
			cp = strchr(reply, '!');
			if(cp)
				strcpy(sys, cp+1);
			return mp;
		}
.
184,193c
		mp = findmethod(reply);
		if(mp){
			for(cp = reply; *cp; cp++){
				while(*cp && *cp != ' ')
					cp++;
				while(*cp == ' ')
					*cp++ = 0;
				if(*cp)
					bargv[bargc++] = cp;
.
180a
	/* parse replies */
.
179a
	if(reply[0] == 0)
		strcpy(reply, method->name);
.
171,178c
	/* create default reply */
	readfile("#e/bootargs", reply, sizeof(reply));
	if(reply[0] == 0 && arg != 0)
		strcpy(reply, arg);
	if(reply[0]){
		mp = findmethod(reply);
		if(mp == 0)
			reply[0] = 0;
.
164a
	/* make list of methods */
.
162c
	int n;
.
159d
151a
Method*
findmethod(char *a)
{
	Method *mp;
	int i, j;
	char *cp;

	i = strlen(a);
	cp = strchr(a, '!');
	if(cp)
		i = cp - a;
	for(mp = method; mp->name; mp++){
		j = strlen(mp->name);
		if(j > i)
			j = i;
		if(strncmp(a, mp->name, j) == 0)
			break;
	}
	if(mp->name)
		return mp;
	return 0;
}

.
40a
	bind("#c", "/dev", MAFTER);
.
25a
char	*bargv[6];
int	bargc;
.
15a
char 	reply[64];
.
## diffname boot/boot.c 1994/0317
## diff -e /n/fornaxdump/1994/0311/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/0317/sys/src/brazil/boot/boot.c
216c
			for(cp = reply; bargc < Nbarg-1 && *cp; cp++){
.
27,28d
23a

char	*bargv[Nbarg];
int	bargc;

.
16c
char 	reply[256];
.
## diffname boot/boot.c 1994/0713
## diff -e /n/fornaxdump/1994/0317/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/0713/sys/src/brazil/boot/boot.c
224c
					bargv[bargc++] = cp++;
.
218c
			for(cp = reply; bargc < Nbarg-1 && *cp;){
.
## diffname boot/boot.c 1994/0728
## diff -e /n/fornaxdump/1994/0713/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/0728/sys/src/brazil/boot/boot.c
50c
		print("%lux %s ", argv[fd], argv[fd]);
.
46a

.
## diffname boot/boot.c 1994/0829
## diff -e /n/fornaxdump/1994/0728/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/0829/sys/src/brazil/boot/boot.c
330c
	print("\nboot: Service %s Ok\n", tmp);
.
317c
	print("boot: Service %s!%s down, wait...\n", buf, tmp);
.
## diffname boot/boot.c 1994/1111
## diff -e /n/fornaxdump/1994/0829/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/1111/sys/src/brazil/boot/boot.c
128c
	if(cpuflag == 0 && nflag == 0)
.
67a
	case 'n':
		nflag = 1;
		break;
.
21a
int	nflag;
.
## diffname boot/boot.c 1994/1212
## diff -e /n/fornaxdump/1994/1111/sys/src/brazil/boot/boot.c /n/fornaxdump/1994/1212/sys/src/brazil/boot/boot.c
317a

.
314a

.
308a

.
## diffname boot/boot.c 1995/02021
## diff -e /n/fornaxdump/1994/1212/sys/src/brazil/boot/boot.c /n/fornaxdump/1995/02021/sys/src/brazil/boot/boot.c
218,220c
	for(;;){
		outin(prompt, reply, sizeof(reply));
.
132,133d
76,78d
73d
69,71d
56,58d
22,23d
## diffname boot/boot.c 1995/0301
## diff -e /n/fornaxdump/1995/02021/sys/src/brazil/boot/boot.c /n/fornaxdump/1995/0301/sys/src/brazil/boot/boot.c
182d
41a
	fmtinstall('r', rconv);

.
30a
static int
rconv(void *o, Fconv *fp)
{
	char s[ERRLEN];

	USED(o);

	s[0] = 0;
	errstr(s);
	strconv(s, fp);
	return 0;
}

.
## diffname boot/boot.c 1995/1122
## diff -e /n/fornaxdump/1995/0301/sys/src/brazil/boot/boot.c /n/fornaxdump/1995/1122/sys/src/brazil/boot/boot.c
349c
static void
.
190c
static Method*
.
60a
	bind("#e", "/env", MREPL|MCREATE);
.
## diffname boot/boot.c 1996/0111
## diff -e /n/fornaxdump/1995/1122/sys/src/brazil/boot/boot.c /n/fornaxdump/1996/0111/sys/src/brazil/boot/boot.c
156d
22d
## diffname boot/boot.c 1996/0214
## diff -e /n/fornaxdump/1996/0111/sys/src/brazil/boot/boot.c /n/fornaxdump/1996/0214/sys/src/brazil/boot/boot.c
35c
	USED(arg);
.
31c
rconv(va_list *arg, Fconv *fp)
.
## diffname boot/boot.c 1997/0327
## diff -e /n/fornaxdump/1996/0214/sys/src/brazil/boot/boot.c /n/emeliedump/1997/0327/sys/src/brazil/boot/boot.c
221,228c
			bargc = parsefields(reply, bargv, Nbarg-1, " ");
.
158c
	sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m" : "");
.
88,89d
70,72d
21d
14,15d
11d
7,9d
## diffname boot/boot.c 1997/0812
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/boot/boot.c /n/emeliedump/1997/0812/sys/src/brazil/boot/boot.c
121c
		fatal("mount /");
.
119c
		fatal("bind /");
.
## diffname boot/boot.c 1999/0316
## diff -e /n/emeliedump/1997/0812/sys/src/brazil/boot/boot.c /n/emeliedump/1999/0316/sys/src/brazil/boot/boot.c
122a

	setenv("rootdir", rootdir);
.
121a
	if(bind(rootdir, "/", MAFTER|MCREATE) < 0)
		fatal("bind /");
.
120c
	if(mount(fd, "/root", MREPL|MCREATE, "") < 0)
.
## diffname boot/boot.c 2000/0308
## diff -e /n/emeliedump/1999/0316/sys/src/brazil/boot/boot.c /n/emeliedump/2000/0308/sys/src/9/boot/boot.c
213c
			bargc = getfields(reply, bargv, Nbarg-1, 1, " ");
.
## diffname boot/boot.c 2000/0310
## diff -e /n/emeliedump/2000/0308/sys/src/9/boot/boot.c /n/emeliedump/2000/0310/sys/src/9/boot/boot.c
125,126c
	setenv("rootdir", rp);
.
122,123c
	rp = getenv("rootdir");
	if(rp == nil)
		rp = rootdir;
	if(strncmp(rp, "/root", 5) != 0){
		snprint(rootbuf, sizeof rootbuf, "/root/%s", rp);
		rp = rootbuf;
	}
	if(bind(rp, "/", MAFTER|MCREATE) < 0)
		fatal("second bind /");
.
120c
	rp = getenv("rootspec");
	if(rp == nil)
		rp = "";
	if(mount(fd, "/root", MREPL|MCREATE, rp) < 0)
.
43a
	char *rp;
.
41a
	char rootbuf[64];
.
## diffname boot/boot.c 2000/0311
## diff -e /n/emeliedump/2000/0310/sys/src/9/boot/boot.c /n/emeliedump/2000/0311/sys/src/9/boot/boot.c
134,135d
132a
		if(bind(rp, "/", MAFTER|MCREATE) < 0){
			fprint(2, "boot: couldn't bind $rootdir=%s to root: %r\n", rp);
			fatal("second bind /");
		}
.
130c
	if(bind(rp, "/", MAFTER|MCREATE) < 0){
		if(strncmp(rp, "/root", 5) == 0){
			fprint(2, "boot: couldn't bind $rootdir=%s to root: %r\n", rp);
			fatal("second bind /");
		}
.
## diffname boot/boot.c 2000/0318
## diff -e /n/emeliedump/2000/0311/sys/src/9/boot/boot.c /n/emeliedump/2000/0318/sys/src/9/boot/boot.c
139c
			if(strcmp(rootbuf, "/root//plan9") == 0){
				fprint(2, "**** warning: remove rootdir=/plan9 entry from plan9.ini\n");
				rp = "/root";
				if(bind(rp, "/", MAFTER|MCREATE) < 0)
					fatal("second bind /");
			}else
				fatal("second bind /");
.
## diffname boot/boot.c 2000/1019
## diff -e /n/emeliedump/2000/0318/sys/src/9/boot/boot.c /n/emeliedump/2000/1019/sys/src/9/boot/boot.c
158a
			bargc = 1;
.
## diffname boot/boot.c 2000/1107
## diff -e /n/emeliedump/2000/1019/sys/src/9/boot/boot.c /n/emeliedump/2000/1107/sys/src/9/boot/boot.c
237c
			bargc = parsecmd(reply, bargv, Nbarg);
.
201a
int
parsecmd(char *s, char **av, int n)
{
	int ac;

	n--;
	for(ac = 0; ac < n; ac++){
		while(*s == ' ' || *s == '\t')
			s++;
		if(*s == 0 || *s == '\n' || *s == '\r')
			break;
		if(*s == '\''){
			s++;
			av[ac] = s;
			while(*s && *s != '\'')
				s++;
		} else {
			av[ac] = s;
			while(*s && *s != ' ' && *s != '\t')
				s++;
		}
		if(*s != 0)
			*s++ = 0;
	}
	av[ac] = 0;
	return ac;
}

.
## diffname boot/boot.c 2001/0217
## diff -e /n/emeliedump/2000/1107/sys/src/9/boot/boot.c /n/emeliedump/2001/0217/sys/src/9/boot/boot.c
173,175c
	cmd = getenv("init");
	if(cmd == nil){
		sprint(cmdbuf, "/%s/init -%s%s", cputype,
			cpuflag ? "c" : "t", mflag ? "m" : "");
		cmd = cmdbuf;
	}
	iargc = tokenize(cmd, iargv, nelem(iargv)-1);
	cmd = iargv[0];

	/* make iargv[0] basename(iargv[0]) */
	if(iargv[0] = strrchr(iargv[0], '/'))
		iargv[0]++;
	else
		iargv[0] = cmd;

	iargv[iargc] = nil;

	exec(cmd, iargv);
.
44c
	int islocal, ishybrid, iargc;
.
41c
	char *cmd, cmdbuf[64], *iargv[16];
.
## diffname boot/boot.c 2001/0301
## diff -e /n/emeliedump/2001/0217/sys/src/9/boot/boot.c /n/emeliedump/2001/0301/sys/src/9/boot/boot.c
43d
## diffname boot/boot.c 2001/0527
## diff -e /n/emeliedump/2001/0301/sys/src/9/boot/boot.c /n/emeliedump/2001/0527/sys/src/9/boot/boot.c
393,417c
	return p[1];	
.
355,391c
	print("srvold9p...");
	switch(fork()) {
	case -1:
		fatal("rfork srvold9p");
	case 0:
		dup(fd, 1);
		close(fd);
		dup(p[0], 0);
		close(p[0]);
		close(p[1]);
		execl("/srvold9p", "srvold9p", "-s", 0);
		fatal("exec srvold9p");
	default:
		close(fd);
		close(p[0]);
.
350,353c
	if(pipe(p) < 0)
		fatal("pipe");
.
346,348c
	int p[2];
.
343,344c
int
old9p(int fd)
.
290,327d
279c
			bargc = getfields(reply, bargv, Nbarg-1, 1, " ");
.
216,243d
172,189c
	sprint(cmd, "/%s/ninit", cputype);
	sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m" : "");
	execl(cmd, "init", flags, 0);
.
158d
154c
	if(0 && access("#s/kfs", 0) < 0){	/* BUG: DISABLED UNTIL KFS SUPPORTS 9P2000 */
.
108c
	if(getenv("srvold9p"))
		fd = old9p(fd);
	print("version...");
	buf[0] = '\0';
	n = fversion(fd, 0, buf, sizeof buf);
	if(n < 0)
		fatal("can't init 9P");
	print("(%.*s)", n, buf);
.
93,101d
44a
	int n;
	char buf[32];
.
43c
	char flags[6];
	int islocal, ishybrid;
.
41c
	char cmd[64];
.
30,31c
	s[0] = '\0';
	errstr(s, sizeof s);
.
26c
	char s[ERRMAX];
.
20d
7,9c
char	cputype[64];
char	sys[2*64];
.
## diffname boot/boot.c 2001/0607
## diff -e /n/emeliedump/2001/0527/sys/src/9/boot/boot.c /n/emeliedump/2001/0607/sys/src/9/boot/boot.c
107c
	print("(%.*s)...", n, buf);
.
## diffname boot/boot.c 2001/0807
## diff -e /n/emeliedump/2001/0607/sys/src/9/boot/boot.c /n/emeliedump/2001/0807/sys/src/9/boot/boot.c
124a
print("mount is done\n");
.
122a
print("boot about to mount\n");
.
## diffname boot/boot.c 2001/0819
## diff -e /n/emeliedump/2001/0807/sys/src/9/boot/boot.c /n/emeliedump/2001/0819/sys/src/9/boot/boot.c
169c
	settime(islocal, afd);
.
163c
			mount(fd, -1, "/n/kfs", MAFTER|MCREATE, "") ;
.
126d
123,124c
	
	afd = fauth(fd, rp);
	if(afd >= 0){
		ai = auth_proxy(afd, "p9any", 0, auth_getkey);
		if(ai == nil)
			print("authentication failed (%r), trying mount anyways\n");
	}
	if(mount(fd, afd, "/root", MREPL|MCREATE, rp) < 0)
.
111d
92c
	authentication(cpuflag);
.
90c
 	 *  authentication agent
.
65,67d
55a
	bind("#s", "/srv", MREPL|MCREATE);
.
48a

.
45a
	AuthInfo *ai;
.
37c
	int fd, afd;
.
## diffname boot/boot.c 2001/0820
## diff -e /n/emeliedump/2001/0819/sys/src/9/boot/boot.c /n/emeliedump/2001/0820/sys/src/9/boot/boot.c
154,171d
107,111d
101a
	if(!islocal && !ishybrid){
		if(cfs)
			fd = (*cfs)(fd);
	}
.
## diffname boot/boot.c 2001/0911
## diff -e /n/emeliedump/2001/0820/sys/src/9/boot/boot.c /n/emeliedump/2001/0911/sys/src/9/boot/boot.c
157,159c
	cmd = getenv("init");
	if(cmd == nil){
		sprint(cmdbuf, "/%s/ninit -%s%s", cputype,
			cpuflag ? "c" : "t", mflag ? "m" : "");
		cmd = cmdbuf;
	}
	iargc = tokenize(cmd, iargv, nelem(iargv)-1);
	cmd = iargv[0];

	/* make iargv[0] basename(iargv[0]) */
	if(iargv[0] = strrchr(iargv[0], '/'))
		iargv[0]++;
	else
		iargv[0] = cmd;

	iargv[iargc] = nil;

	exec(cmd, iargv);
.
44c
	int iargc, n;
.
41d
39c
	char *cmd, cmdbuf[64], *iargv[16];
.
## diffname boot/boot.c 2001/1103
## diff -e /n/emeliedump/2001/0911/sys/src/9/boot/boot.c /n/emeliedump/2001/1103/sys/src/9/boot/boot.c
158c
		sprint(cmdbuf, "/%s/init -%s%s", cputype,
.
## diffname boot/boot.c 2001/1105
## diff -e /n/emeliedump/2001/1103/sys/src/9/boot/boot.c /n/emeliedump/2001/1105/sys/src/9/boot/boot.c
123c
		ai = auth_proxy(afd, auth_getkey, "proto=p9any role=client");
.
## diffname boot/boot.c 2001/1117
## diff -e /n/emeliedump/2001/1105/sys/src/9/boot/boot.c /n/emeliedump/2001/1117/sys/src/9/boot/boot.c
235c
			bargc = tokenize(reply, bargv, Nbarg-1);
.
## diffname boot/boot.c 2002/0110
## diff -e /n/emeliedump/2001/1117/sys/src/9/boot/boot.c /n/emeliedump/2002/0110/sys/src/9/boot/boot.c
56c
	/*
	 * init will reinitialize its namespace.
	 * #ec gets us plan9.ini settings.
	 */
	bind("#ec", "/env", MREPL|MCREATE);
	bind("#e", "/env", MAFTER);
.
47,49d
## diffname boot/boot.c 2002/0217
## diff -e /n/emeliedump/2002/0110/sys/src/9/boot/boot.c /n/emeliedump/2002/0217/sys/src/9/boot/boot.c
30,31c
	return fmtstrcpy(fp, s);
.
26,27d
22c
rconv(Fmt* fp)
.
## diffname boot/boot.c 2002/0221
## diff -e /n/emeliedump/2002/0217/sys/src/9/boot/boot.c /n/emeliedump/2002/0221/sys/src/9/boot/boot.c
44c
	fmtinstall('r', errfmt);
.
21,30d
## diffname boot/boot.c 2002/0401
## diff -e /n/emeliedump/2002/0221/sys/src/9/boot/boot.c /n/emeliedump/2002/0401/sys/src/9/boot/boot.c
223a
	    HaveMethod:
.
199a
	/* look for required reply */
	readfile("#e/nobootprompt", reply, sizeof(reply));
	if(reply[0]){
		mp = findmethod(reply);
		if(mp)
			goto HaveMethod;
		print("boot method %s not found\n", reply);
		reply[0] = 0;
	}

.
## diffname boot/boot.c 2002/0411
## diff -e /n/emeliedump/2002/0401/sys/src/9/boot/boot.c /n/emeliedump/2002/0411/sys/src/9/boot/boot.c
235c
			bargc = tokenize(reply, bargv, Nbarg-2);
			bargv[bargc] = nil;
.
231a
		if(strlen(reply) == 0)
			continue;
.
## diffname boot/boot.c 2002/1002
## diff -e /n/emeliedump/2002/0411/sys/src/9/boot/boot.c /n/emeliedump/2002/1002/sys/src/9/boot/boot.c
142c
	settime(islocal, afd, rsp);
.
117a
	rsp = rp;
.
29c
	char *rp, *rsp;
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.