Line data Source code
1 : /* $OpenBSD: subr_xxx.c,v 1.16 2018/04/03 08:58:05 mpi 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/conf.h>
42 :
43 :
44 : /*
45 : * Unsupported device function (e.g. writing to read-only device).
46 : */
47 : int
48 0 : enodev(void)
49 : {
50 :
51 0 : return (ENODEV);
52 : }
53 :
54 : /*
55 : * Unconfigured device function; driver not configured.
56 : */
57 : int
58 0 : enxio(void)
59 : {
60 :
61 0 : return (ENXIO);
62 : }
63 :
64 : /*
65 : * Unsupported ioctl function.
66 : */
67 : int
68 0 : enoioctl(void)
69 : {
70 :
71 0 : return (ENOTTY);
72 : }
73 :
74 : /*
75 : * Unsupported system function.
76 : * This is used for an otherwise-reasonable operation
77 : * that is not supported by the current system binary.
78 : */
79 : int
80 0 : enosys(void)
81 : {
82 :
83 0 : return (ENOSYS);
84 : }
85 :
86 : /*
87 : * Return error for operation not supported
88 : * on a specific object or file type.
89 : */
90 : int
91 0 : eopnotsupp(void *v)
92 : {
93 :
94 0 : return (EOPNOTSUPP);
95 : }
96 :
97 : /*
98 : * Generic null operation, always returns success.
99 : */
100 : int
101 0 : nullop(void *v)
102 : {
103 :
104 0 : return (0);
105 : }
106 :
107 : struct bdevsw *
108 0 : bdevsw_lookup(dev_t dev)
109 : {
110 0 : return (&bdevsw[major(dev)]);
111 : }
112 :
113 : struct cdevsw *
114 0 : cdevsw_lookup(dev_t dev)
115 : {
116 0 : return (&cdevsw[major(dev)]);
117 : }
118 :
119 : /*
120 : * Convert a character device number to a block device number.
121 : */
122 : dev_t
123 0 : chrtoblk(dev_t dev)
124 : {
125 : int blkmaj;
126 :
127 0 : if (major(dev) >= nchrdev || major(dev) >= nchrtoblktbl)
128 0 : return (NODEV);
129 0 : blkmaj = chrtoblktbl[major(dev)];
130 0 : if (blkmaj == NODEV)
131 0 : return (NODEV);
132 0 : return (makedev(blkmaj, minor(dev)));
133 0 : }
134 :
135 : /*
136 : * Convert a block device number to a character device number.
137 : */
138 : dev_t
139 0 : blktochr(dev_t dev)
140 : {
141 0 : int blkmaj = major(dev);
142 : int i;
143 :
144 0 : if (blkmaj >= nblkdev)
145 0 : return (NODEV);
146 0 : for (i = 0; i < nchrtoblktbl; i++)
147 0 : if (blkmaj == chrtoblktbl[i])
148 0 : return (makedev(i, minor(dev)));
149 0 : return (NODEV);
150 0 : }
151 :
152 : /*
153 : * Check that we're in a context where it's okay to sleep.
154 : */
155 : void
156 0 : assertwaitok(void)
157 : {
158 0 : if (panicstr || db_active)
159 : return;
160 :
161 0 : splassert(IPL_NONE);
162 : #ifdef DIAGNOSTIC
163 0 : if (curcpu()->ci_mutex_level != 0)
164 0 : panic("assertwaitok: non-zero mutex count: %d",
165 0 : curcpu()->ci_mutex_level);
166 : #endif
167 0 : }
|