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