Annotation of Net2/arch/i386/boot/sys.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Ported to boot 386BSD by Julian Elischer ([email protected]) Sept 1992
        !             3:  *
        !             4:  * Mach Operating System
        !             5:  * Copyright (c) 1992, 1991 Carnegie Mellon University
        !             6:  * All Rights Reserved.
        !             7:  * 
        !             8:  * Permission to use, copy, modify and distribute this software and its
        !             9:  * documentation is hereby granted, provided that both the copyright
        !            10:  * notice and this permission notice appear in all copies of the
        !            11:  * software, derivative works or modified versions, and any portions
        !            12:  * thereof, and that both notices appear in supporting documentation.
        !            13:  * 
        !            14:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
        !            15:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
        !            16:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
        !            17:  * 
        !            18:  * Carnegie Mellon requests users of this software to return to
        !            19:  * 
        !            20:  *  Software Distribution Coordinator  or  [email protected]
        !            21:  *  School of Computer Science
        !            22:  *  Carnegie Mellon University
        !            23:  *  Pittsburgh PA 15213-3890
        !            24:  * 
        !            25:  * any improvements or extensions that they make and grant Carnegie Mellon
        !            26:  * the rights to redistribute these changes.
        !            27:  */
        !            28: 
        !            29: /*
        !            30:  * HISTORY
        !            31:  * $Log: sys.c,v $
        !            32:  * Revision 1.1  1993/03/21 18:08:45  cgd
        !            33:  * after 0.2.2 "stable" patches applied
        !            34:  *
        !            35:  * Revision 2.2  92/04/04  11:36:34  rpd
        !            36:  *     Fabricated from 3.0 bootstrap and scratch.
        !            37:  *     [92/03/30            mg32]
        !            38:  * 
        !            39:  */
        !            40: 
        !            41: #include "boot.h"
        !            42: #include <sys/dir.h>
        !            43: #include <sys/reboot.h>
        !            44: 
        !            45: /* #define BUFSIZE 4096 */
        !            46: #define BUFSIZE MAXBSIZE
        !            47: 
        !            48: char buf[BUFSIZE], fsbuf[SBSIZE], iobuf[MAXBSIZE];
        !            49: 
        !            50: int xread(addr, size)
        !            51:        char            * addr;
        !            52:        int             size;
        !            53: {
        !            54:        int count = BUFSIZE;
        !            55:        while (size > 0) {
        !            56:                if (BUFSIZE > size)
        !            57:                        count = size;
        !            58:                read(buf, count);
        !            59:                pcpy(buf, addr, count);
        !            60:                size -= count;
        !            61:                addr += count;
        !            62:        }
        !            63: }
        !            64: 
        !            65: read(buffer, count)
        !            66:        int count;
        !            67:        char *buffer;
        !            68: {
        !            69:        int logno, off, size;
        !            70:        int cnt2, bnum2;
        !            71: 
        !            72:        while (count) {
        !            73:                off = blkoff(fs, poff);
        !            74:                logno = lblkno(fs, poff);
        !            75:                cnt2 = size = blksize(fs, &inode, logno);
        !            76:                bnum2 = fsbtodb(fs, block_map(logno)) + boff;
        !            77:                cnt = cnt2;
        !            78:                bnum = bnum2;
        !            79:                if (    (!off)  && (size <= count))
        !            80:                {
        !            81:                        iodest = buffer;
        !            82:                        devread();
        !            83:                }
        !            84:                else
        !            85:                {
        !            86:                        iodest = iobuf;
        !            87:                        size -= off;
        !            88:                        if (size > count)
        !            89:                                size = count;
        !            90:                        devread();
        !            91:                        bcopy(iodest+off,buffer,size);
        !            92:                }
        !            93:                buffer += size;
        !            94:                count -= size;
        !            95:                poff += size;
        !            96:        }
        !            97: }
        !            98: 
        !            99: find(path)
        !           100:      char *path;
        !           101: {
        !           102:        char *rest, ch;
        !           103:        int block, off, loc, ino = ROOTINO;
        !           104:        struct direct *dp;
        !           105: loop:  iodest = iobuf;
        !           106:        cnt = fs->fs_bsize;
        !           107:        bnum = fsbtodb(fs,itod(fs,ino)) + boff;
        !           108:        devread();
        !           109:        bcopy(&((struct dinode *)iodest)[ino % fs->fs_inopb],
        !           110:              &inode.i_din,
        !           111:              sizeof (struct dinode));
        !           112:        if (!*path)
        !           113:                return 1;
        !           114:        while (*path == '/')
        !           115:                path++;
        !           116:        if (!inode.i_size || ((inode.i_mode&IFMT) != IFDIR))
        !           117:                return 0;
        !           118:        for (rest = path; (ch = *rest) && ch != '/'; rest++) ;
        !           119:        *rest = 0;
        !           120:        loc = 0;
        !           121:        do {
        !           122:                if (loc >= inode.i_size)
        !           123:                        return 0;
        !           124:                if (!(off = blkoff(fs, loc))) {
        !           125:                        block = lblkno(fs, loc);
        !           126:                        cnt = blksize(fs, &inode, block);
        !           127:                        bnum = fsbtodb(fs, block_map(block)) + boff;
        !           128:                        iodest = iobuf;
        !           129:                        devread();
        !           130:                }
        !           131:                dp = (struct direct *)(iodest + off);
        !           132:                loc += dp->d_reclen;
        !           133:        } while (!dp->d_ino || strcmp(path, dp->d_name));
        !           134:        ino = dp->d_ino;
        !           135:        *(path = rest) = ch;
        !           136:        goto loop;
        !           137: }
        !           138: 
        !           139: char mapbuf[MAXBSIZE];
        !           140: int mapblock = 0;
        !           141: 
        !           142: block_map(file_block)
        !           143:      int file_block;
        !           144: {
        !           145:        if (file_block < NDADDR)
        !           146:                return(inode.i_db[file_block]);
        !           147:        if ((bnum=fsbtodb(fs, inode.i_ib[0])+boff) != mapblock) {
        !           148:                iodest = mapbuf;
        !           149:                cnt = fs->fs_bsize;
        !           150:                devread();
        !           151:                mapblock = bnum;
        !           152:        }
        !           153:        return (((int *)mapbuf)[(file_block - NDADDR) % NINDIR(fs)]);
        !           154: }
        !           155: 
        !           156: openrd()
        !           157: {
        !           158:        char **devp, *cp = name;
        !           159:        /*******************************************************\
        !           160:        * If bracket given look for preceding device name       *
        !           161:        \*******************************************************/
        !           162:        while (*cp && *cp!='(')
        !           163:                cp++;
        !           164:        if (!*cp)
        !           165:        {
        !           166:                cp = name;
        !           167:        }
        !           168:        else
        !           169:        {
        !           170:                if (cp++ != name)
        !           171:                {
        !           172:                        for (devp = devs; *devp; devp++)
        !           173:                                if (name[0] == (*devp)[0] &&
        !           174:                                    name[1] == (*devp)[1])
        !           175:                                        break;
        !           176:                        if (!*devp)
        !           177:                        {
        !           178:                                printf("Unknown device\n");
        !           179:                                return 1;
        !           180:                        }
        !           181:                        maj = devp-devs;
        !           182:                }
        !           183:                /*******************************************************\
        !           184:                * Look inside brackets for unit number, and partition   *
        !           185:                \*******************************************************/
        !           186:                if (*cp >= '0' && *cp <= '9')
        !           187:                        if ((unit = *cp++ - '0') > 1)
        !           188:                        {
        !           189:                                printf("Bad unit\n");
        !           190:                                return 1;
        !           191:                        }
        !           192:                if (!*cp || (*cp == ',' && !*++cp))
        !           193:                        return 1;
        !           194:                if (*cp >= 'a' && *cp <= 'p')
        !           195:                        part = *cp++ - 'a';
        !           196:                while (*cp && *cp++!=')') ;
        !           197:                if (!*cp)
        !           198:                        return 1;
        !           199:        }
        !           200:        switch(maj)
        !           201:        {
        !           202:        case 1:
        !           203:                dosdev = unit | 0x80;
        !           204:                unit = 0;
        !           205:                break;
        !           206:        case 0:
        !           207:        case 4:
        !           208:                dosdev = unit | 0x80;
        !           209:                break;
        !           210:        case 2:
        !           211:                dosdev = unit;
        !           212:                break;
        !           213:        case 3:
        !           214:                printf("Wangtek unsupported\n");
        !           215:                return 1;
        !           216:                break;
        !           217:        }
        !           218:        inode.i_dev = dosdev;
        !           219:        /***********************************************\
        !           220:        * Now we know the disk unit and part,           *
        !           221:        * Load disk info, (open the device)             *
        !           222:        \***********************************************/
        !           223:        if (devopen())
        !           224:                return 1;
        !           225: 
        !           226:        /***********************************************\
        !           227:        * Load Filesystem info (mount the device)       *
        !           228:        \***********************************************/
        !           229:        iodest = (char *)(fs = (struct fs *)fsbuf);
        !           230:        cnt = SBSIZE;
        !           231:        bnum = SBLOCK + boff;
        !           232:        devread();
        !           233:        /***********************************************\
        !           234:        * Find the actual FILE on the mounted device    *
        !           235:        \***********************************************/
        !           236:        if (!find(cp))
        !           237:        {
        !           238:                return 1;
        !           239:        }
        !           240:        poff = 0;
        !           241:        name = cp;
        !           242:        return 0;
        !           243: }

unix.superglobalmegacorp.com

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