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

Annotation of sys/arch/zaurus/stand/zboot/devopen.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: devopen.c,v 1.6 2007/06/27 20:29:38 mk Exp $  */
                      2:
                      3: /*
                      4:  * Copyright (c) 1996-1999 Michael Shalayeff
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     17:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     18:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     19:  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
                     20:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     21:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     22:  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
                     24:  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
                     25:  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
                     26:  * THE POSSIBILITY OF SUCH DAMAGE.
                     27:  */
                     28:
                     29: #include <sys/param.h>
                     30: #include <sys/disklabel.h>
                     31: #include <dev/cons.h>
                     32: #include "libsa.h"
                     33: #include <stand/boot/cmd.h>
                     34:
                     35: /* XXX use slot for 'rd' for 'hd' pseudo-device */
                     36: const char bdevs[][4] = {
                     37:        "wd", "", "fd", "", "sd", "st", "cd", "mcd",
                     38:        "", "", "", "", "", "", "", "scd", "", "hd", ""
                     39:
                     40: };
                     41: const int nbdevs = NENTS(bdevs);
                     42:
                     43: const char cdevs[][4] = {
                     44:        "cn", "", "", "", "", "", "", "",
                     45:        "", "", "", "", "com"
                     46: };
                     47: const int ncdevs = NENTS(cdevs);
                     48:
                     49: /* pass dev_t to the open routines */
                     50: int
                     51: devopen(struct open_file *f, const char *fname, char **file)
                     52: {
                     53:        struct devsw *dp = devsw;
                     54:        register int i, rc = 1;
                     55:
                     56:        *file = (char *)fname;
                     57:
                     58: #ifdef DEBUG
                     59:        if (debug)
                     60:                printf("devopen:");
                     61: #endif
                     62:
                     63:        for (i = 0; i < ndevs && rc != 0; dp++, i++) {
                     64: #ifdef DEBUG
                     65:                if (debug)
                     66:                        printf(" %s: ", dp->dv_name);
                     67: #endif
                     68:                if ((rc = (*dp->dv_open)(f, file)) == 0) {
                     69:                        f->f_dev = dp;
                     70:                        return 0;
                     71:                }
                     72: #ifdef DEBUG
                     73:                else if (debug)
                     74:                        printf("%d", rc);
                     75: #endif
                     76:
                     77:        }
                     78: #ifdef DEBUG
                     79:        if (debug)
                     80:                putchar('\n');
                     81: #endif
                     82:
                     83:        if ((f->f_flags & F_NODEV) == 0)
                     84:                f->f_dev = dp;
                     85:
                     86:        return rc;
                     87: }
                     88:
                     89: void
                     90: devboot(dev_t bootdev, char *p)
                     91: {
                     92:        dev_t unit = 0;         /* XXX */
                     93:
                     94:        *p++ = 'h';
                     95:        *p++ = 'd';
                     96:        *p++ = '0' + unit;
                     97:        *p++ = 'a';
                     98:        *p = '\0';
                     99: }
                    100:
                    101: int pch_pos = 0;
                    102:
                    103: void
                    104: putchar(int c)
                    105: {
                    106:        switch (c) {
                    107:        case '\177':    /* DEL erases */
                    108:                cnputc('\b');
                    109:                cnputc(' ');
                    110:        case '\b':
                    111:                cnputc('\b');
                    112:                if (pch_pos)
                    113:                        pch_pos--;
                    114:                break;
                    115:        case '\t':
                    116:                do
                    117:                        cnputc(' ');
                    118:                while (++pch_pos % 8);
                    119:                break;
                    120:        case '\n':
                    121:        case '\r':
                    122:                cnputc(c);
                    123:                pch_pos=0;
                    124:                break;
                    125:        default:
                    126:                cnputc(c);
                    127:                pch_pos++;
                    128:                break;
                    129:        }
                    130: }
                    131:
                    132: int
                    133: getchar(void)
                    134: {
                    135:        register int c = cngetc();
                    136:
                    137:        if (c == '\r')
                    138:                c = '\n';
                    139:
                    140:        if ((c < ' ' && c != '\n') || c == '\177')
                    141:                return c;
                    142:
                    143:        putchar(c);
                    144:
                    145:        return c;
                    146: }
                    147:
                    148: char ttyname_buf[8];
                    149:
                    150: char *
                    151: ttyname(int fd)
                    152: {
                    153:        snprintf(ttyname_buf, sizeof ttyname_buf, "%s%d",
                    154:            cdevs[major(cn_tab->cn_dev)], minor(cn_tab->cn_dev));
                    155:
                    156:        return ttyname_buf;
                    157: }
                    158:
                    159: dev_t
                    160: ttydev(char *name)
                    161: {
                    162:        int i, unit = -1;
                    163:        char *no = name + strlen(name) - 1;
                    164:
                    165:        while (no >= name && *no >= '0' && *no <= '9')
                    166:                unit = (unit < 0 ? 0 : (unit * 10)) + *no-- - '0';
                    167:        if (no < name || unit < 0)
                    168:                return NODEV;
                    169:        for (i = 0; i < ncdevs; i++)
                    170:                if (strncmp(name, cdevs[i], no - name + 1) == 0)
                    171:                        return (makedev(i, unit));
                    172:        return NODEV;
                    173: }

CVSweb