]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved | |
30 | * Copyright (c) 1993 NeXT Computer, Inc. | |
31 | * | |
32 | * UNIX Device switch tables. | |
33 | * | |
34 | * HISTORY | |
35 | * | |
36 | * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com) | |
37 | * enabled file descriptor pseudo-device. | |
38 | * 18 June 1993 ? at NeXT | |
39 | * Cleaned up a lot of stuff in this file. | |
40 | */ | |
41 | ||
42 | #include <sys/param.h> | |
43 | #include <sys/systm.h> | |
1c79356b A |
44 | #include <sys/ioctl.h> |
45 | #include <sys/tty.h> | |
46 | #include <sys/conf.h> | |
47 | ||
48 | ||
49 | extern int nulldev(); | |
50 | ||
51 | struct bdevsw bdevsw[] = | |
52 | { | |
53 | /* | |
54 | * For block devices, every other block of 8 slots is | |
55 | * reserved to NeXT. The other slots are available for | |
56 | * the user. This way we can both add new entries without | |
57 | * running into each other. Be sure to fill in NeXT's | |
58 | * 8 reserved slots when you jump over us -- we'll do the | |
59 | * same for you. | |
60 | */ | |
61 | ||
62 | /* 0 - 7 are reserved to NeXT */ | |
63 | ||
64 | NO_BDEVICE, /* 0*/ | |
65 | NO_BDEVICE, /* 1*/ | |
66 | NO_BDEVICE, /* 2*/ | |
67 | NO_BDEVICE, /* 3*/ | |
68 | NO_BDEVICE, /* 4*/ | |
69 | NO_BDEVICE, /* 5*/ | |
70 | NO_BDEVICE, /* 6*/ | |
71 | NO_BDEVICE, /* 7*/ | |
72 | ||
73 | /* 8 - 15 are reserved to the user */ | |
74 | NO_BDEVICE, /* 8*/ | |
75 | NO_BDEVICE, /* 9*/ | |
76 | NO_BDEVICE, /*10*/ | |
77 | NO_BDEVICE, /*11*/ | |
78 | NO_BDEVICE, /*12*/ | |
79 | NO_BDEVICE, /*13*/ | |
80 | NO_BDEVICE, /*14*/ | |
81 | NO_BDEVICE, /*15*/ | |
82 | ||
83 | /* 16 - 23 are reserved to NeXT */ | |
84 | NO_BDEVICE, /*16*/ | |
85 | NO_BDEVICE, /*17*/ | |
86 | NO_BDEVICE, /*18*/ | |
87 | NO_BDEVICE, /*18*/ | |
88 | NO_BDEVICE, /*20*/ | |
89 | NO_BDEVICE, /*21*/ | |
90 | NO_BDEVICE, /*22*/ | |
91 | NO_BDEVICE, /*23*/ | |
92 | }; | |
93 | ||
94 | int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]); | |
95 | ||
96 | extern struct tty *km_tty[]; | |
97 | extern int consopen(), consclose(), consread(), conswrite(), consioctl(), | |
98 | consselect(), cons_getc(), cons_putc(); | |
99 | extern int kmopen(),kmclose(),kmread(),kmwrite(),kmioctl(), | |
100 | kmgetc(), kmputc(dev_t dev, char c); | |
101 | ||
102 | extern int cttyopen(), cttyread(), cttywrite(), cttyioctl(), cttyselect(); | |
103 | ||
91447636 | 104 | extern int mmread(),mmwrite(),mmioctl(); |
1c79356b A |
105 | #define mmselect seltrue |
106 | ||
107 | #if 1 | |
55e303ae A |
108 | #ifdef NPTY |
109 | #undef NPTY | |
110 | #endif /* NPTY */ | |
1c79356b A |
111 | #define NPTY 32 |
112 | #else /* 1 */ | |
113 | #include <pty.h> | |
114 | #endif /* 1 */ | |
115 | #if NPTY > 0 | |
116 | extern struct tty *pt_tty[]; | |
117 | extern int ptsopen(),ptsclose(),ptsread(),ptswrite(),ptsstop(),ptsputc(); | |
118 | extern int ptcopen(),ptcclose(),ptcread(),ptcwrite(),ptcselect(), | |
119 | ptyioctl(); | |
120 | #else | |
121 | #define ptsopen eno_opcl | |
122 | #define ptsclose eno_opcl | |
123 | #define ptsread eno_rdwrt | |
124 | #define ptswrite eno_rdwrt | |
125 | #define ptsstop nulldev | |
126 | #define ptsputc nulldev | |
127 | ||
128 | #define ptcopen eno_opcl | |
129 | #define ptcclose eno_opcl | |
130 | #define ptcread eno_rdwrt | |
131 | #define ptcwrite eno_rdwrt | |
132 | #define ptcselect eno_select | |
133 | #define ptyioctl eno_ioctl | |
134 | #endif | |
135 | ||
136 | extern int logopen(),logclose(),logread(),logioctl(),logselect(); | |
137 | extern int seltrue(); | |
138 | ||
139 | struct cdevsw cdevsw[] = | |
140 | { | |
141 | /* | |
142 | * For character devices, every other block of 16 slots is | |
143 | * reserved to NeXT. The other slots are available for | |
144 | * the user. This way we can both add new entries without | |
145 | * running into each other. Be sure to fill in NeXT's | |
146 | * 16 reserved slots when you jump over us -- we'll do the | |
147 | * same for you. | |
148 | */ | |
149 | ||
150 | /* 0 - 15 are reserved to NeXT */ | |
151 | ||
152 | { | |
153 | consopen, consclose, consread, conswrite, /* 0*/ | |
154 | consioctl, nulldev, nulldev, 0, consselect, | |
55e303ae | 155 | eno_mmap, eno_strat, (getc_fcn_t *)cons_getc, (putc_fcn_t *)cons_putc, D_TTY |
1c79356b A |
156 | }, |
157 | NO_CDEVICE, /* 1*/ | |
158 | { | |
159 | cttyopen, nulldev, cttyread, cttywrite, /* 2*/ | |
160 | cttyioctl, nulldev, nulldev, 0, cttyselect, | |
161 | eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY | |
162 | }, | |
163 | { | |
164 | nulldev, nulldev, mmread, mmwrite, /* 3*/ | |
91447636 A |
165 | mmioctl, nulldev, nulldev, 0, (select_fcn_t *)mmselect, |
166 | eno_mmap, eno_strat, eno_getc, eno_putc, D_DISK | |
1c79356b A |
167 | }, |
168 | { | |
169 | ptsopen, ptsclose, ptsread, ptswrite, /* 4*/ | |
170 | ptyioctl, ptsstop, nulldev, pt_tty, ttselect, | |
171 | eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY | |
172 | }, | |
173 | { | |
174 | ptcopen, ptcclose, ptcread, ptcwrite, /* 5*/ | |
175 | ptyioctl, nulldev, nulldev, 0, ptcselect, | |
176 | eno_mmap, eno_strat, eno_getc, eno_putc, D_TTY | |
177 | }, | |
178 | { | |
179 | logopen, logclose, logread, eno_rdwrt, /* 6*/ | |
180 | logioctl, eno_stop, nulldev, 0, logselect, | |
181 | eno_mmap, eno_strat, eno_getc, eno_putc, 0 | |
182 | }, | |
183 | NO_CDEVICE, /* 7*/ | |
184 | NO_CDEVICE, /* 8*/ | |
185 | NO_CDEVICE, /* 9*/ | |
186 | NO_CDEVICE, /*10*/ | |
187 | NO_CDEVICE, /*11*/ | |
188 | { | |
189 | kmopen, kmclose, kmread, kmwrite, /*12*/ | |
190 | kmioctl, nulldev, nulldev, km_tty, ttselect, | |
191 | eno_mmap, eno_strat, kmgetc, kmputc, 0 | |
192 | }, | |
193 | NO_CDEVICE, /*13*/ | |
194 | NO_CDEVICE, /*14*/ | |
195 | NO_CDEVICE, /*15*/ | |
196 | ||
197 | /* 16 - 31 are reserved to the user */ | |
198 | NO_CDEVICE, /*16*/ | |
199 | NO_CDEVICE, /*17*/ | |
200 | NO_CDEVICE, /*18*/ | |
201 | NO_CDEVICE, /*19*/ | |
202 | NO_CDEVICE, /*20*/ | |
203 | NO_CDEVICE, /*21*/ | |
204 | NO_CDEVICE, /*22*/ | |
205 | NO_CDEVICE, /*23*/ | |
206 | NO_CDEVICE, /*24*/ | |
207 | NO_CDEVICE, /*25*/ | |
208 | NO_CDEVICE, /*26*/ | |
209 | NO_CDEVICE, /*27*/ | |
210 | NO_CDEVICE, /*28*/ | |
211 | NO_CDEVICE, /*29*/ | |
212 | NO_CDEVICE, /*30*/ | |
213 | NO_CDEVICE, /*31*/ | |
214 | ||
215 | /* 32 - 47 are reserved to NeXT */ | |
216 | NO_CDEVICE, /*32*/ | |
217 | NO_CDEVICE, /*33*/ | |
218 | NO_CDEVICE, /*34*/ | |
219 | NO_CDEVICE, /*35*/ | |
220 | NO_CDEVICE, /*36*/ | |
221 | /* 37 used to be for nvram */ | |
222 | NO_CDEVICE, /*37*/ | |
223 | NO_CDEVICE, /*38*/ | |
224 | NO_CDEVICE, /*39*/ | |
225 | NO_CDEVICE, /*40*/ | |
226 | /* 41 used to be for fd */ | |
227 | NO_CDEVICE, /*41*/ | |
228 | NO_CDEVICE, /*42*/ | |
229 | }; | |
230 | int nchrdev = sizeof (cdevsw) / sizeof (cdevsw[0]); | |
231 | ||
232 | ||
233 | #include <sys/vnode.h> /* for VCHR and VBLK */ | |
234 | /* | |
235 | * return true if a disk | |
236 | */ | |
237 | int | |
238 | isdisk(dev, type) | |
239 | dev_t dev; | |
240 | int type; | |
241 | { | |
9bccf70c A |
242 | dev_t maj = major(dev); |
243 | ||
244 | switch (type) { | |
245 | case VCHR: | |
246 | maj = chrtoblk(maj); | |
247 | if (maj == NODEV) { | |
248 | break; | |
249 | } | |
250 | /* FALL THROUGH */ | |
251 | case VBLK: | |
252 | if (bdevsw[maj].d_type == D_DISK) { | |
253 | return (1); | |
254 | } | |
1c79356b A |
255 | break; |
256 | } | |
257 | return(0); | |
258 | } | |
259 | ||
260 | static int chrtoblktab[] = { | |
261 | /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/ | |
262 | /* 0 */ NODEV, /* 1 */ NODEV, | |
263 | /* 2 */ NODEV, /* 3 */ NODEV, | |
264 | /* 4 */ NODEV, /* 5 */ NODEV, | |
265 | /* 6 */ NODEV, /* 7 */ NODEV, | |
266 | /* 8 */ NODEV, /* 9 */ NODEV, | |
267 | /* 10 */ NODEV, /* 11 */ NODEV, | |
268 | /* 12 */ NODEV, /* 13 */ NODEV, | |
269 | /* 14 */ 6, /* 15 */ NODEV, | |
270 | /* 16 */ NODEV, /* 17 */ NODEV, | |
271 | /* 18 */ NODEV, /* 19 */ NODEV, | |
272 | /* 20 */ NODEV, /* 21 */ NODEV, | |
273 | /* 22 */ NODEV, /* 23 */ NODEV, | |
274 | /* 24 */ NODEV, /* 25 */ NODEV, | |
275 | /* 26 */ NODEV, /* 27 */ NODEV, | |
276 | /* 28 */ NODEV, /* 29 */ NODEV, | |
277 | /* 30 */ NODEV, /* 31 */ NODEV, | |
278 | /* 32 */ NODEV, /* 33 */ NODEV, | |
279 | /* 34 */ NODEV, /* 35 */ NODEV, | |
280 | /* 36 */ NODEV, /* 37 */ NODEV, | |
281 | /* 38 */ NODEV, /* 39 */ NODEV, | |
282 | /* 40 */ NODEV, /* 41 */ 1, | |
283 | /* 42 */ NODEV, /* 43 */ NODEV, | |
284 | /* 44 */ NODEV, | |
285 | }; | |
286 | ||
287 | /* | |
288 | * convert chr dev to blk dev | |
289 | */ | |
290 | dev_t | |
291 | chrtoblk(dev) | |
292 | dev_t dev; | |
293 | { | |
294 | int blkmaj; | |
295 | ||
296 | if (major(dev) >= nchrdev) | |
297 | return(NODEV); | |
298 | blkmaj = chrtoblktab[major(dev)]; | |
299 | if (blkmaj == NODEV) | |
300 | return(NODEV); | |
301 | return(makedev(blkmaj, minor(dev))); | |
302 | } | |
303 | ||
9bccf70c A |
304 | int |
305 | chrtoblk_set(int cdev, int bdev) | |
306 | { | |
307 | if (cdev >= nchrdev) | |
308 | return (NODEV); | |
309 | if (bdev != NODEV && bdev >= nblkdev) | |
310 | return (NODEV); | |
311 | chrtoblktab[cdev] = bdev; | |
312 | return 0; | |
313 | } | |
314 | ||
1c79356b A |
315 | /* |
316 | * Returns true if dev is /dev/mem or /dev/kmem. | |
317 | */ | |
318 | int iskmemdev(dev) | |
319 | dev_t dev; | |
320 | { | |
321 | ||
322 | return (major(dev) == 3 && minor(dev) < 2); | |
323 | } |