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