[BACK]Return to subr_xxx.c CVS log [TXT][DIR] Up to [local] / sys / kern

Annotation of sys/kern/subr_xxx.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: subr_xxx.c,v 1.9 2005/12/09 09:09:52 jsg Exp $        */
                      2: /*     $NetBSD: subr_xxx.c,v 1.10 1996/02/04 02:16:51 christos Exp $   */
                      3:
                      4: /*
                      5:  * Copyright (c) 1982, 1986, 1991, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. Neither the name of the University nor the names of its contributors
                     17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  *
                     32:  *     @(#)subr_xxx.c  8.1 (Berkeley) 6/10/93
                     33:  */
                     34:
                     35: /*
                     36:  * Miscellaneous trivial functions, including many
                     37:  * that are often inline-expanded or done in assembler.
                     38:  */
                     39: #include <sys/param.h>
                     40: #include <sys/systm.h>
                     41: #include <sys/device.h>
                     42: #include <sys/conf.h>
                     43:
                     44: #include <machine/cpu.h>
                     45:
                     46: /*
                     47:  * Unsupported device function (e.g. writing to read-only device).
                     48:  */
                     49: int
                     50: enodev(void)
                     51: {
                     52:
                     53:        return (ENODEV);
                     54: }
                     55:
                     56: /*
                     57:  * Unconfigured device function; driver not configured.
                     58:  */
                     59: int
                     60: enxio(void)
                     61: {
                     62:
                     63:        return (ENXIO);
                     64: }
                     65:
                     66: /*
                     67:  * Unsupported ioctl function.
                     68:  */
                     69: int
                     70: enoioctl(void)
                     71: {
                     72:
                     73:        return (ENOTTY);
                     74: }
                     75:
                     76: /*
                     77:  * Unsupported system function.
                     78:  * This is used for an otherwise-reasonable operation
                     79:  * that is not supported by the current system binary.
                     80:  */
                     81: int
                     82: enosys(void)
                     83: {
                     84:
                     85:        return (ENOSYS);
                     86: }
                     87:
                     88: /*
                     89:  * Return error for operation not supported
                     90:  * on a specific object or file type.
                     91:  */
                     92: /*ARGSUSED*/
                     93: int
                     94: eopnotsupp(void *v)
                     95: {
                     96:
                     97:        return (EOPNOTSUPP);
                     98: }
                     99:
                    100: /*
                    101:  * Generic null operation, always returns success.
                    102:  */
                    103: /*ARGSUSED*/
                    104: int
                    105: nullop(void *v)
                    106: {
                    107:
                    108:        return (0);
                    109: }
                    110:
                    111: struct bdevsw *
                    112: bdevsw_lookup(dev_t dev)
                    113: {
                    114:        return (&bdevsw[major(dev)]);
                    115: }
                    116:
                    117: struct cdevsw *
                    118: cdevsw_lookup(dev_t dev)
                    119: {
                    120:        return (&cdevsw[major(dev)]);
                    121: }
                    122:
                    123: /*
                    124:  * Convert a character device number to a block device number.
                    125:  */
                    126: dev_t
                    127: chrtoblk(dev_t dev)
                    128: {
                    129:        int blkmaj;
                    130:
                    131:        if (major(dev) >= nchrdev || major(dev) >= nchrtoblktbl)
                    132:                return (NODEV);
                    133:        blkmaj = chrtoblktbl[major(dev)];
                    134:        if (blkmaj == NODEV)
                    135:                return (NODEV);
                    136:        return (makedev(blkmaj, minor(dev)));
                    137: }
                    138:
                    139: /*
                    140:  * Convert a block device number to a character device number.
                    141:  */
                    142: dev_t
                    143: blktochr(dev_t dev)
                    144: {
                    145:        int blkmaj = major(dev);
                    146:        int i;
                    147:
                    148:        if (blkmaj >= nblkdev)
                    149:                return (NODEV);
                    150:        for (i = 0; i < nchrtoblktbl; i++)
                    151:                if (blkmaj == chrtoblktbl[i])
                    152:                        return (makedev(i, minor(dev)));
                    153:        return (NODEV);
                    154: }

CVSweb