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