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