|
|
|
1992/0317/sys/src/9/boot/boot.c:1,22 –
1992/0318/sys/src/9/boot/boot.c:1,11
(short | long | prev | next)
|
|
1992/0317
| |
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include "../port/bootp.h"
#include "../port/arp.h"
|
|
1992/0318
| |
#include "../boot/boot.h"
|
|
1992/0317
| |
#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];
|
|
1992/0317/sys/src/9/boot/boot.c:28,47 –
1992/0318/sys/src/9/boot/boot.c:17,33
|
|
1992/0317
| |
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)
|
|
1992/0318
| |
main(int argc, char *argv[])
|
|
1992/0317
| |
{
int fd;
Method *mp;
char cmd[64];
char flags[5];
|
|
1992/0318
| |
char flags[6];
|
|
1992/0317
| |
int islocal;
sleep(1000);
|
|
1992/0317/sys/src/9/boot/boot.c:71,84 –
1992/0318/sys/src/9/boot/boot.c:57,70
|
|
1992/0317
| |
/*
* pick a method and initialize it
*/
mp = rootserver(*argv);
islocal = strcmp(mp->name, "local") == 0;
|
|
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
*/
(*pword)(mp);
|
|
1992/0318
| |
(*pword)(islocal, mp);
|
|
1992/0317
| |
/*
* connect to the root file system
|
|
1992/0317/sys/src/9/boot/boot.c:89,95 –
1992/0318/sys/src/9/boot/boot.c:75,82
|
|
1992/0317
| |
if(!islocal){
nop(fd);
session(fd);
fd = cache(fd);
|
|
1992/0318
| |
if(cfs)
fd = (*cfs)(fd);
|
|
1992/0317
| |
srvcreate(sys, fd);
}
srvcreate("boot", fd);
|
|
1992/0317/sys/src/9/boot/boot.c:104,120 –
1992/0318/sys/src/9/boot/boot.c:91,109
|
|
1992/0317
| |
close(fd);
/*
* start local fs if its not the root file server
|
|
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){
local = (*mp->connect)(mp);
if(local < 0)
|
|
1992/0318
| |
(*mp->config)(mp);
fd = (*mp->connect)();
if(fd < 0)
|
|
1992/0317
| |
break;
if(mount(local, "/n/kfs", MAFTER|MCREATE, "", "") < 0)
|
|
1992/0318
| |
if(mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") < 0)
|
|
1992/0317
| |
fatal("mount");
close(local);
|
|
1992/0318
| |
close(fd);
|
|
1992/0317
| |
break;
}
}
|
|
1992/0317/sys/src/9/boot/boot.c:124,136 –
1992/0318/sys/src/9/boot/boot.c:113,125
|
|
1992/0317
| |
sleep(1000);
sprint(cmd, "/%s/init", cputype);
sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m", "");
|
|
1992/0318
| |
sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m" : "");
|
|
1992/0317
| |
execl(cmd, "init", flags, 0);
fatal(cmd);
}
/*
* ask user from whence comes the root file system
|
|
1992/0318
| |
* ask user from whence cometh the root file system
|
|
1992/0317
| |
*/
Method*
rootserver(char *arg)
|
|
1992/0317/sys/src/9/boot/boot.c:142,159 –
1992/0318/sys/src/9/boot/boot.c:131,148
|
|
1992/0317
| |
int n;
mp = method;
n = 0;
sprint(prompt, "root is from (", mp->name);
|
|
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, ")");
for(;;){
|
|
1992/0318
| |
if(arg)
strcpy(reply, arg);
else
|
|
1992/0317
| |
strcpy(reply, method->name);
if(arg == 0)
|
|
1992/0318
| |
for(;;){
if(arg == 0 || mflag)
|
|
1992/0317
| |
outin(prompt, reply, sizeof(reply));
else
strcpy(reply, arg);
arg = 0;
for(mp = method; mp->name; mp++)
if(*reply == *mp->name){
|
|
1992/0317/sys/src/9/boot/boot.c:168,261 –
1992/0318/sys/src/9/boot/boot.c:157,162
|
|
1992/0317
| |
}
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;
|
|
1992/0317/sys/src/9/boot/boot.c:267,327 –
1992/0318/sys/src/9/boot/boot.c:168,171
|
|
1992/0317
| |
}
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);
}
|