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