plan 9 kernel history: overview | file list | diff list

1992/0322/boot/boot.c (diff list | history)

boot/boot.c on 1992/0317
1992/0317    
#include <u.h> 
#include <libc.h> 
1992/0318    
#include "../boot/boot.h" 
1992/0317    
 
#define DEFSYS "bootes" 
typedef struct Net	Net; 
typedef struct Flavor	Flavor; 
 
int	printcol; 
 
char	cputype[NAMELEN]; 
char	terminal[NAMELEN]; 
char	sys[2*NAMELEN]; 
char	username[NAMELEN]; 
 
int mflag; 
int fflag; 
int kflag; 
1992/0322    
int aflag; 
1992/0317    
 
int	cache(int); 
void	swapproc(void); 
Method	*rootserver(char*); 
 
void 
1992/0318    
main(int argc, char *argv[]) 
1992/0317    
{ 
	int fd; 
	Method *mp; 
	char cmd[64]; 
1992/0318    
	char flags[6]; 
1992/0317    
	int islocal; 
 
	sleep(1000); 
 
	open("#c/cons", OREAD); 
	open("#c/cons", OWRITE); 
	open("#c/cons", OWRITE); 
 
	ARGBEGIN{ 
1992/0322    
	case 'a': 
		aflag = 1; 
		break; 
1992/0317    
	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 
	 */ 
1992/0318    
	mp = rootserver(argc ? *argv : 0); 
1992/0317    
	(*mp->config)(mp); 
1992/0318    
	islocal = strcmp(mp->name, "local") == 0; 
1992/0317    
 
	/* 
	 *  get/set key or password 
	 */ 
1992/0318    
	(*pword)(islocal, mp); 
1992/0317    
 
	/* 
	 *  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); 
1992/0318    
		if(cfs) 
			fd = (*cfs)(fd); 
1992/0317    
	} 
	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); 
1992/0320    
	newkernel(); 
1992/0317    
 
	/* 
1992/0318    
	 *  if a local file server exists and it's not the 
	 *  root file server, start it and mount it onto /n/kfs 
1992/0317    
	 */ 
	if(!islocal){ 
		for(mp = method; mp->name; mp++) 
			if(strcmp(mp->name, "local")==0){ 
1992/0318    
				(*mp->config)(mp); 
				fd = (*mp->connect)(); 
				if(fd < 0) 
1992/0317    
					break; 
1992/0318    
				if(mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") < 0) 
1992/0317    
					fatal("mount"); 
1992/0318    
				close(fd); 
1992/0317    
				break; 
			} 
	} 
 
	settime(islocal); 
	swapproc(); 
 
	sprint(cmd, "/%s/init", cputype); 
1992/0322    
	sprint(flags, "-%s%s%s", cpuflag ? "c" : "t", mflag ? "m" : "", aflag ? "a" : ""); 
1992/0317    
	execl(cmd, "init", flags, 0); 
	fatal(cmd); 
} 
 
/* 
1992/0318    
 *  ask user from whence cometh the root file system 
1992/0317    
 */ 
Method* 
rootserver(char *arg) 
{ 
	char prompt[256]; 
	char reply[64]; 
	Method *mp; 
	char *cp; 
	int n; 
1992/0322    
	int notfirst; 
1992/0317    
 
	mp = method; 
1992/0318    
	n = sprint(prompt, "root is from (%s", mp->name); 
1992/0317    
	for(mp++; mp->name; mp++) 
		n += sprint(prompt+n, ", %s", mp->name); 
	sprint(prompt+n, ")"); 
 
1992/0318    
	if(arg) 
		strcpy(reply, arg); 
	else 
1992/0317    
		strcpy(reply, method->name); 
1992/0322    
	for(notfirst = 0;; notfirst = 1){ 
		if(mflag || notfirst) 
1992/0317    
			outin(prompt, reply, sizeof(reply)); 
		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 
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"); 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)