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