[BACK]Return to devopen.c CVS log [TXT][DIR] Up to [local] / sys / arch / hp300 / stand / cdboot

Annotation of sys/arch/hp300/stand/cdboot/devopen.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: devopen.c,v 1.3 2006/08/17 06:31:10 miod Exp $        */
        !             2: /*     $NetBSD: devopen.c,v 1.7 1996/10/14 07:31:47 thorpej Exp $      */
        !             3:
        !             4: /*-
        !             5:  *  Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
        !             6:  *  Copyright (c) 1993 John Brezak
        !             7:  *  All rights reserved.
        !             8:  *
        !             9:  *  Redistribution and use in source and binary forms, with or without
        !            10:  *  modification, are permitted provided that the following conditions
        !            11:  *  are met:
        !            12:  *  1. Redistributions of source code must retain the above copyright
        !            13:  *     notice, this list of conditions and the following disclaimer.
        !            14:  *  2. Redistributions in binary form must reproduce the above copyright
        !            15:  *     notice, this list of conditions and the following disclaimer in the
        !            16:  *     documentation and/or other materials provided with the distribution.
        !            17:  *  3. The name of the author may not be used to endorse or promote products
        !            18:  *     derived from this software without specific prior written permission.
        !            19:  *
        !            20:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
        !            21:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
        !            22:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        !            23:  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
        !            24:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
        !            25:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        !            26:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
        !            28:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
        !            29:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            30:  * POSSIBILITY OF SUCH DAMAGE.
        !            31:  */
        !            32:
        !            33: #include <sys/param.h>
        !            34: #include <sys/reboot.h>
        !            35:
        !            36: #include <lib/libsa/stand.h>
        !            37:
        !            38: #include "samachdep.h"
        !            39:
        !            40: int    atoi(char *);
        !            41: int    devlookup(const char*, int);
        !            42: int    devparse(const char *, int *, int *, int *, int *, int *, char **);
        !            43: void   usage(void);
        !            44:
        !            45: u_int opendev;
        !            46:
        !            47: #define ispart(c)      ((c) >= 'a' && (c) <= 'h')
        !            48:
        !            49: int
        !            50: atoi(char *cp)
        !            51: {
        !            52:        int val = 0;
        !            53:        while(isdigit(*cp))
        !            54:                val = val * 10 + (*cp++ - '0');
        !            55:        return(val);
        !            56: }
        !            57:
        !            58: void
        !            59: usage()
        !            60: {
        !            61:        printf("Usage: device(adaptor, controller, drive, partition)file\n"
        !            62:               "       <device><unit><partitionletter>:file\n");
        !            63: }
        !            64:
        !            65: int
        !            66: devlookup(const char *d, int len)
        !            67: {
        !            68:        struct devsw *dp = devsw;
        !            69:        int i;
        !            70:
        !            71:        for (i = 0; i < ndevs; i++, dp++) {
        !            72:                if (dp->dv_name && strncmp(dp->dv_name, d, len) == 0) {
        !            73:                        /*
        !            74:                         * Set the filesystem and startup up according to
        !            75:                         * the device being opened.
        !            76:                         */
        !            77:                        switch (i) {
        !            78:                        case 4: /* sd - only supports cd9660 */
        !            79:                                bcopy(file_system_cd9660, file_system,
        !            80:                                    sizeof(struct fs_ops));
        !            81:                                break;
        !            82:
        !            83:                        case 0: /* ct - not supported */
        !            84:                        case 2: /* hd - not supported */
        !            85:                        case 6: /* le - not supported */
        !            86:                        default:
        !            87:                                /* Agh!  What happened?! */
        !            88:                                goto bad;
        !            89:                        }
        !            90:                        return(i);
        !            91:                }
        !            92:        }
        !            93:
        !            94: bad:
        !            95:        printf("No such device - Configured devices are:\n");
        !            96:        for (dp = devsw, i = 0; i < ndevs; i++, dp++)
        !            97:                if (dp->dv_name)
        !            98:                        printf(" %s", dp->dv_name);
        !            99:        printf("\n");
        !           100:        errno = ENODEV;
        !           101:        return(-1);
        !           102: }
        !           103:
        !           104: /*
        !           105:  * Parse a device spec in one of two forms.
        !           106:  *
        !           107:  * dev(adapt, ctlr, unit, part)file
        !           108:  * [A-Za-z]*[0-9]*[A-Za-z]:file
        !           109:  *    dev   unit  part
        !           110:  */
        !           111: int
        !           112: devparse(const char *fname, int *dev, int *adapt, int *ctlr, int *unit,
        !           113:     int *part, char **file)
        !           114: {
        !           115:        int i;
        !           116:        char *s, *args[4];
        !           117:
        !           118:        /* get device name and make lower case */
        !           119:        for (s = (char *)fname; *s && *s != '/' && *s != ':' && *s != '('; s++)
        !           120:                if (isupper(*s)) *s = tolower(*s);
        !           121:
        !           122:        /* first form */
        !           123:        if (*s == '(') {
        !           124:                /* lookup device and get index */
        !           125:                if ((*dev = devlookup(fname, s - fname)) < 0)
        !           126:                        goto baddev;
        !           127:
        !           128:                /* tokenize device ident */
        !           129:                args[0] = ++s;
        !           130:                for (args[0] = s, i = 1; *s && *s != ')'; s++) {
        !           131:                        if (*s == ',')
        !           132:                                args[i++] = ++s;
        !           133:                }
        !           134:                switch(i) {
        !           135:                case 4:
        !           136:                        *adapt = atoi(args[0]);
        !           137:                        *ctlr  = atoi(args[1]);
        !           138:                        *unit  = atoi(args[2]);
        !           139:                        *part  = atoi(args[3]);
        !           140:                        break;
        !           141:                case 3:
        !           142:                        *ctlr  = atoi(args[0]);
        !           143:                        *unit  = atoi(args[1]);
        !           144:                        *part  = atoi(args[2]);
        !           145:                        break;
        !           146:                case 2:
        !           147:                        *unit  = atoi(args[0]);
        !           148:                        *part  = atoi(args[1]);
        !           149:                        break;
        !           150:                case 1:
        !           151:                        *part  = atoi(args[0]);
        !           152:                        break;
        !           153:                case 0:
        !           154:                        break;
        !           155:                }
        !           156:                *file = ++s;
        !           157:        }
        !           158:
        !           159:        /* second form */
        !           160:        else if (*s == ':') {
        !           161:                int temp;
        !           162:
        !           163:                /* isolate device */
        !           164:                for (s = (char *)fname; *s != ':' && !isdigit(*s); s++);
        !           165:
        !           166:                /* lookup device and get index */
        !           167:                if ((*dev = devlookup(fname, s - fname)) < 0)
        !           168:                        goto baddev;
        !           169:
        !           170:                /* isolate unit */
        !           171:                if ((temp = atoi(s)) > 255)
        !           172:                        goto bad;
        !           173:                *adapt = temp / 8;
        !           174:                *ctlr = temp % 8;
        !           175:                for (; isdigit(*s); s++);
        !           176:
        !           177:                /* translate partition */
        !           178:                if (!ispart(*s))
        !           179:                        goto bad;
        !           180:
        !           181:                *part = *s++ - 'a';
        !           182:                if (*s != ':')
        !           183:                        goto bad;
        !           184:                *file = ++s;
        !           185:        }
        !           186:
        !           187:        /* no device present */
        !           188:        else
        !           189:                *file = (char *)fname;
        !           190:
        !           191:        /* return the remaining unparsed part as the file to boot */
        !           192:        return(0);
        !           193:
        !           194: bad:
        !           195:        usage();
        !           196:
        !           197: baddev:
        !           198:        return(-1);
        !           199: }
        !           200:
        !           201:
        !           202: int
        !           203: devopen(struct open_file *f, const char *fname, char **file)
        !           204: {
        !           205:        int error;
        !           206:        int dev, adapt, ctlr, unit, part;
        !           207:        struct devsw *dp = &devsw[0];
        !           208:
        !           209:        dev   = B_TYPE(bootdev);
        !           210:        adapt = B_ADAPTOR(bootdev);
        !           211:        ctlr  = B_CONTROLLER(bootdev);
        !           212:        unit  = B_UNIT(bootdev);
        !           213:        part  = B_PARTITION(bootdev);
        !           214:
        !           215:        if ((error = devparse(fname, &dev, &adapt, &ctlr, &unit, &part, file)))
        !           216:            return(error);
        !           217:
        !           218:        /*
        !           219:         * Set up filesystem type based on what device we're opening.
        !           220:         */
        !           221:        switch (dev) {
        !           222:        case 4:         /* sd - only supports cd9660 */
        !           223:                bcopy(file_system_cd9660, file_system, sizeof(struct fs_ops));
        !           224:                break;
        !           225:
        !           226:        case 0:         /* ct - not supported */
        !           227:        case 2:         /* hd - not supported */
        !           228:        case 6:         /* le - not supported */
        !           229:        default:
        !           230:                /* XXX what else should we do here? */
        !           231:                printf("WARNING: BOGUS BOOT DEV TYPE 0x%x!\n", dev);
        !           232:                return (EIO);
        !           233:        }
        !           234:
        !           235:        dp = &devsw[dev];
        !           236:
        !           237:        if (!dp->dv_open)
        !           238:                return(ENODEV);
        !           239:
        !           240:        f->f_dev = dp;
        !           241:
        !           242:        if ((error = (*dp->dv_open)(f, adapt, ctlr, part)) == 0) {
        !           243:                if ((error =
        !           244:                    (*punitsw[dev].p_punit)(adapt, ctlr, &unit)) != 0) {
        !           245:                        goto bad;
        !           246:                }
        !           247:                opendev = MAKEBOOTDEV(dev, adapt, ctlr, unit, part);
        !           248:                return(0);
        !           249:        }
        !           250:
        !           251: bad:
        !           252:        printf("%s(%d,%d,%d,%d): %s\n", devsw[dev].dv_name,
        !           253:            adapt, ctlr, unit, part, strerror(error));
        !           254:
        !           255:        return(error);
        !           256: }

CVSweb