Annotation of Gnu-Mach/device/dev_name.c, revision 1.1.1.4

1.1.1.2   root        1: /*
1.1       root        2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
                      4:  * All Rights Reserved.
1.1.1.2   root        5:  *
1.1       root        6:  * Permission to use, copy, modify and distribute this software and its
                      7:  * documentation is hereby granted, provided that both the copyright
                      8:  * notice and this permission notice appear in all copies of the
                      9:  * software, derivative works or modified versions, and any portions
                     10:  * thereof, and that both notices appear in supporting documentation.
1.1.1.2   root       11:  *
1.1       root       12:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     13:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     14:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.1.1.2   root       15:  *
1.1       root       16:  * Carnegie Mellon requests users of this software to return to
1.1.1.2   root       17:  *
1.1       root       18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
1.1.1.2   root       22:  *
1.1       root       23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
                     26: /*
                     27:  *     Author: David B. Golub, Carnegie Mellon University
                     28:  *     Date:   8/89
                     29:  */
                     30: 
1.1.1.3   root       31: #include <kern/printf.h>
                     32: #include <string.h>
1.1       root       33: #include <device/device_types.h>
                     34: #include <device/dev_hdr.h>
                     35: #include <device/conf.h>
                     36: 
                     37: 
                     38: 
                     39: /*
                     40:  * Routines placed in empty entries in the device tables
                     41:  */
1.1.1.4 ! root       42: int nulldev(void)
1.1       root       43: {
                     44:        return (D_SUCCESS);
                     45: }
                     46: 
1.1.1.4 ! root       47: int nulldev_open(dev_t dev, int flags, io_req_t ior)
        !            48: {
        !            49:        return (D_SUCCESS);
        !            50: }
        !            51: 
        !            52: void nulldev_close(dev_t dev, int flags)
        !            53: {
        !            54: }
        !            55: 
        !            56: int nulldev_read(dev_t dev, io_req_t ior)
        !            57: {
        !            58:        return (D_SUCCESS);
        !            59: }
        !            60: 
        !            61: int nulldev_write(dev_t dev, io_req_t ior)
        !            62: {
        !            63:        return (D_SUCCESS);
        !            64: }
        !            65: 
        !            66: io_return_t nulldev_getstat(dev_t dev, int flavor, int *data, natural_t *count)
        !            67: {
        !            68:        return (D_SUCCESS);
        !            69: }
        !            70: 
        !            71: io_return_t nulldev_setstat(dev_t dev, int flavor, int *data, natural_t count)
        !            72: {
        !            73:        return (D_SUCCESS);
        !            74: }
        !            75: 
        !            76: int nulldev_portdeath(dev_t dev, mach_port_t port)
        !            77: {
        !            78:        return (D_SUCCESS);
        !            79: }
        !            80: 
        !            81: int nodev(void)
1.1       root       82: {
                     83:        return (D_INVALID_OPERATION);
                     84: }
                     85: 
1.1.1.4 ! root       86: int
        !            87: nomap(dev_t dev, vm_offset_t off, int prot)
1.1       root       88: {
                     89:        return (D_INVALID_OPERATION);
                     90: }
                     91: 
                     92: /*
                     93:  * Name comparison routine.
                     94:  * Compares first 'len' characters of 'src'
                     95:  * with 'target', which is zero-terminated.
                     96:  * Returns TRUE if strings are equal:
                     97:  *   src and target are equal in first 'len' characters
                     98:  *   next character of target is 0 (end of string).
                     99:  */
1.1.1.4 ! root      100: boolean_t __attribute__ ((pure))
1.1       root      101: name_equal(src, len, target)
1.1.1.4 ! root      102:        const char      *src;
        !           103:        int             len;
        !           104:        const char      *target;
1.1       root      105: {
                    106:        while (--len >= 0)
                    107:            if (*src++ != *target++)
                    108:                return FALSE;
                    109:        return *target == 0;
                    110: }
                    111: 
                    112: /*
                    113:  * device name lookup
                    114:  */
1.1.1.4 ! root      115: boolean_t dev_name_lookup(
        !           116:        char            *name,
        !           117:        dev_ops_t       *ops,   /* out */
        !           118:        int             *unit)  /* out */
1.1       root      119: {
                    120:        /*
                    121:         * Assume that block device names are of the form
                    122:         *
                    123:         * <device_name><unit_number>[[<slice num>]<partition>]
                    124:         *
                    125:         * where
                    126:         * <device_name>        is the name in the device table
                    127:         * <unit_number>        is an integer
                    128:         * <slice num>  *       is 's' followed by a number (disks only!)
                    129:         * <partition>          is a letter in [a-h] (disks only?)
                    130:         */
                    131: 
1.1.1.3   root      132:        char            *cp = name;
1.1       root      133:        int             len;
1.1.1.3   root      134:        int             j = 0;
                    135:        int             c;
1.1       root      136:        dev_ops_t       dev;
1.1.1.3   root      137:        boolean_t       found;
1.1       root      138: 
1.1.1.3   root      139:        int slice_num = 0;
1.1       root      140: 
                    141:        /*
                    142:         * Find device type name (characters before digit)
                    143:         */
                    144:        while ((c = *cp) != '\0' &&
                    145:                !(c >= '0' && c <= '9'))
                    146:            cp++;
                    147: 
                    148:        len = cp - name;
                    149:        if (c != '\0') {
                    150:            /*
                    151:             * Find unit number
                    152:             */
                    153:            while ((c = *cp) != '\0' &&
                    154:                    c >= '0' && c <= '9') {
                    155:                j = j * 10 + (c - '0');
                    156:                cp++;
                    157:            }
                    158:        }
                    159: 
                    160:        found = FALSE;
                    161:        dev_search(dev) {
                    162:            if (name_equal(name, len, dev->d_name)) {
                    163:                found = TRUE;
                    164:                break;
                    165:            }
                    166:        }
                    167:        if (!found) {
                    168:            /* name not found - try indirection list */
1.1.1.3   root      169:            dev_indirect_t      di;
1.1       root      170: 
                    171:            dev_indirect_search(di) {
                    172:                if (name_equal(name, len, di->d_name)) {
                    173:                    /*
                    174:                     * Return device and unit from indirect vector.
                    175:                     */
                    176:                    *ops = di->d_ops;
                    177:                    *unit = di->d_unit;
                    178:                    return (TRUE);
                    179:                }
                    180:            }
                    181:            /* Not found in either list. */
                    182:            return (FALSE);
                    183:        }
                    184: 
                    185:        *ops = dev;
                    186:        *unit = j;
                    187: 
                    188:        /*
                    189:         * Find sub-device number
                    190:         */
                    191: 
                    192:        j = dev->d_subdev;
                    193:        if (j > 0) {
                    194:            /* if no slice string, slice num = 0 */
                    195: 
                    196:            /* <subdev_count>*unit + <slice_number>*16 -- I know it's bad */
                    197:            *unit *= j;
                    198: 
                    199:            /* find slice ? */
1.1.1.3   root      200:            if (c == 's') {
1.1       root      201:                cp++;
                    202:                while ((c = *cp) != '\0' &&
                    203:                        c >= '0' && c <= '9') {
                    204:                    slice_num = slice_num * 10 + (c - '0');
                    205:                    cp++;
                    206:                }
                    207:            }
                    208: 
1.1.1.3   root      209:            *unit += (slice_num << 4);
1.1.1.4 ! root      210:                /* if slice==0, it is either compatibility or whole device */
1.1       root      211: 
                    212:            if (c >= 'a' && c < 'a' + j) { /* note: w/o this -> whole slice */
                    213:                /*
                    214:                 * Minor number is <subdev_count>*unit + letter.
                    215:                 * NOW it is slice result + letter
                    216:                 */
                    217:                *unit += (c - 'a' +1);
                    218:            }
                    219:        }
                    220:        return (TRUE);
                    221: }
                    222: 
                    223: /*
                    224:  * Change an entry in the indirection list.
                    225:  */
                    226: void
                    227: dev_set_indirection(name, ops, unit)
1.1.1.4 ! root      228:        const char      *name;
1.1       root      229:        dev_ops_t       ops;
                    230:        int             unit;
                    231: {
1.1.1.3   root      232:        dev_indirect_t di;
1.1       root      233: 
                    234:        dev_indirect_search(di) {
                    235:            if (!strcmp(di->d_name, name)) {
                    236:                di->d_ops = ops;
                    237:                di->d_unit = unit;
                    238:                break;
                    239:            }
                    240:        }
                    241: }
                    242: 
                    243: boolean_t dev_change_indirect(iname, dname, unit)
1.1.1.4 ! root      244:        const char      *iname;
        !           245:        const char      *dname;
        !           246:        int             unit;
1.1       root      247: {
                    248:     struct dev_ops *dp;
                    249:     struct dev_indirect *di;
1.1.1.3   root      250:     boolean_t found = FALSE;
1.1       root      251: 
                    252:     dev_search(dp) {
1.1.1.3   root      253:        if (!strcmp(dp->d_name, dname)) {
1.1       root      254:            found = TRUE;
                    255:            break;
                    256:        }
                    257:     }
                    258:     if (!found) return FALSE;
                    259:     dev_indirect_search(di) {
1.1.1.3   root      260:        if (!strcmp(di->d_name, iname)) {
1.1       root      261:            di->d_ops = dp;
                    262:            di->d_unit = unit;
                    263:            return TRUE;
                    264:        }
                    265:     }
                    266:     return FALSE;
                    267: }

unix.superglobalmegacorp.com

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