Annotation of lucent/sys/src/9/boot/dosboot.c, revision 1.1

1.1     ! root        1: #include <u.h>
        !             2: #include <libc.h>
        !             3: #include <auth.h>
        !             4: #include "../boot/boot.h"
        !             5: 
        !             6: #define DEFSYS "bootes"
        !             7: typedef struct Net     Net;
        !             8: typedef struct Flavor  Flavor;
        !             9: 
        !            10: int    printcol;
        !            11: 
        !            12: char   cputype[NAMELEN];
        !            13: char   terminal[NAMELEN];
        !            14: char   sys[2*NAMELEN];
        !            15: char   username[NAMELEN];
        !            16: char   bootfile[3*NAMELEN];
        !            17: char   conffile[NAMELEN];
        !            18: 
        !            19: int mflag;
        !            20: int fflag;
        !            21: int kflag;
        !            22: 
        !            23: static void    swapproc(void);
        !            24: static Method  *rootserver(char*);
        !            25: 
        !            26: static int
        !            27: rconv(void *o, Fconv *fp)
        !            28: {
        !            29:        char s[ERRLEN];
        !            30: 
        !            31:        USED(o);
        !            32: 
        !            33:        s[0] = 0;
        !            34:        errstr(s);
        !            35:        strconv(s, fp);
        !            36:        return 0;
        !            37: }
        !            38: 
        !            39: void
        !            40: dosboot(int argc, char *argv[])
        !            41: {
        !            42:        int fd;
        !            43:        Method *mp;
        !            44:        char cmd[64];
        !            45:        char flags[6];
        !            46:        int islocal;
        !            47:        char rootdir[3*NAMELEN];
        !            48: 
        !            49:        sleep(1000);
        !            50: 
        !            51:        fmtinstall('r', rconv);
        !            52: 
        !            53:        open("#c/cons", OREAD);
        !            54:        open("#c/cons", OWRITE);
        !            55:        open("#c/cons", OWRITE);
        !            56: /*     print("argc=%d\n", argc);
        !            57:        for(fd = 0; fd < argc; fd++)
        !            58:                print("%s ", argv[fd]);
        !            59:        print("\n");/**/
        !            60: 
        !            61:        ARGBEGIN{
        !            62:        }ARGEND
        !            63: 
        !            64:        readfile("#e/cputype", cputype, sizeof(cputype));
        !            65:        readfile("#e/terminal", terminal, sizeof(terminal));
        !            66:        getconffile(conffile, terminal);
        !            67: 
        !            68:        /*
        !            69:         *  pick a method and initialize it
        !            70:         */
        !            71:        mp = rootserver(argc ? *argv : 0);
        !            72:        (*mp->config)(mp);
        !            73:        islocal = strcmp(mp->name, "local") == 0;
        !            74: 
        !            75:        /* set host's owner (and uid of current process) */
        !            76:        if(writefile("#c/hostowner", "none", strlen("none")) < 0)
        !            77:                fatal("can't set user name");
        !            78: 
        !            79:        /*
        !            80:         *  connect to the root file system
        !            81:         */
        !            82:        fd = (*mp->connect)();
        !            83:        if(fd < 0)
        !            84:                fatal("can't connect to file server");
        !            85:        srvcreate("boot", fd);
        !            86: 
        !            87:        /*
        !            88:         *  create the name space
        !            89:         */
        !            90:        if(mount(fd, "/", MAFTER|MCREATE, "") < 0)
        !            91:                fatal("mount");
        !            92: 
        !            93:        /*
        !            94:         *  hack to let us have the logical root in a
        !            95:         *  subdirectory - useful when we're the 'second'
        !            96:         *  OS along with some other like DOS.
        !            97:         */
        !            98:        readfile("#e/rootdir", rootdir, sizeof(rootdir));
        !            99:        if(rootdir[0]) {
        !           100:                if(bind(rootdir, "/", MREPL|MCREATE) >= 0)
        !           101:                        bind("#/", "/", MBEFORE);
        !           102:        }
        !           103:        close(fd);
        !           104: 
        !           105:        settime(islocal);
        !           106:        swapproc();
        !           107:        remove("#e/password");  /* just in case */
        !           108: 
        !           109:        sprint(cmd, "/%s/init", cputype);
        !           110:        sprint(flags, "-%s%s", cpuflag ? "c" : "t", mflag ? "m" : "");
        !           111:        execl(cmd, "init", flags, 0);
        !           112:        fatal(cmd);
        !           113: }
        !           114: 
        !           115: /*
        !           116:  *  ask user from whence cometh the root file system
        !           117:  */
        !           118: Method*
        !           119: rootserver(char *arg)
        !           120: {
        !           121:        char prompt[256];
        !           122:        char reply[64];
        !           123:        Method *mp;
        !           124:        char *cp, *goodarg;
        !           125:        int n, j;
        !           126: 
        !           127:        goodarg = 0;
        !           128:        mp = method;
        !           129:        n = sprint(prompt, "root is from (%s", mp->name);
        !           130:        if(arg && strncmp(arg, mp->name, strlen(mp->name)) == 0)
        !           131:                goodarg = arg;
        !           132:        for(mp++; mp->name; mp++){
        !           133:                n += sprint(prompt+n, ", %s", mp->name);
        !           134:                if(arg && strncmp(arg, mp->name, strlen(mp->name)) == 0)
        !           135:                        goodarg = arg;
        !           136:        }
        !           137:        sprint(prompt+n, ")");
        !           138: 
        !           139:        if(goodarg)
        !           140:                strcpy(reply, goodarg);
        !           141:        else {
        !           142:                strcpy(reply, method->name);
        !           143:        }
        !           144:        for(;;){
        !           145:                if(goodarg == 0)
        !           146:                        outin(cpuflag, prompt, reply, sizeof(reply));
        !           147:                cp = strchr(reply, '!');
        !           148:                if(cp)
        !           149:                        j = cp - reply;
        !           150:                else
        !           151:                        j = strlen(reply);
        !           152:                for(mp = method; mp->name; mp++)
        !           153:                        if(strncmp(reply, mp->name, j) == 0){
        !           154:                                if(cp)
        !           155:                                        strcpy(sys, cp+1);
        !           156:                                return mp;
        !           157:                        }
        !           158:                if(mp->name == 0)
        !           159:                        continue;
        !           160:        }
        !           161:        return 0;               /* not reached */
        !           162: }
        !           163: 
        !           164: static void
        !           165: swapproc(void)
        !           166: {
        !           167:        int fd;
        !           168: 
        !           169:        fd = open("#c/swap", OWRITE);
        !           170:        if(fd < 0){
        !           171:                warning("opening #c/swap");
        !           172:                return;
        !           173:        }
        !           174:        if(write(fd, "start", 5) <= 0)
        !           175:                warning("starting swap kproc");
        !           176: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.