2 * Copyright (c) 1997-2012 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1993 NeXT Computer, Inc.
31 * UNIX Device switch tables.
35 * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com)
36 * enabled file descriptor pseudo-device.
37 * 18 June 1993 ? at NeXT
38 * Cleaned up a lot of stuff in this file.
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/ioctl.h>
47 /* Prototypes that should be elsewhere: */
48 extern dev_t
chrtoblk(dev_t dev
);
49 extern int chrtoblk_set(int cdev
, int bdev
);
51 struct bdevsw bdevsw
[] =
54 * For block devices, every other block of 8 slots is
55 * reserved for Apple. The other slots are available for
56 * the user. This way we can both add new entries without
57 * running into each other. Be sure to fill in Apple's
58 * 8 reserved slots when you jump over us -- we'll do the
62 /* 0 - 7 are reserved for Apple */
73 /* 8 - 15 are reserved to the user */
83 /* 16 - 23 are reserved for Apple */
94 const int nblkdev
= sizeof(bdevsw
) / sizeof(bdevsw
[0]);
96 extern struct tty
*km_tty
[];
97 extern d_open_t cnopen
;
98 extern d_close_t cnclose
;
99 extern d_read_t cnread
;
100 extern d_write_t cnwrite
;
101 extern d_ioctl_t cnioctl
;
102 extern d_select_t cnselect
;
103 extern d_open_t kmopen
;
104 extern d_close_t kmclose
;
105 extern d_read_t kmread
;
106 extern d_write_t kmwrite
;
107 extern d_ioctl_t kmioctl
;
108 extern d_open_t sgopen
;
109 extern d_close_t sgclose
;
110 extern d_ioctl_t sgioctl
;
113 extern d_open_t volopen
;
114 extern d_close_t volclose
;
115 extern d_ioctl_t volioctl
;
117 #define volopen eno_opcl
118 #define volclose eno_opcl
119 #define volioctl eno_ioctl
122 extern d_open_t cttyopen
;
123 extern d_read_t cttyread
;
124 extern d_write_t cttywrite
;
125 extern d_ioctl_t cttyioctl
;
126 extern d_select_t cttyselect
;
128 extern d_read_t mmread
;
129 extern d_write_t mmwrite
;
130 extern d_ioctl_t mmioctl
;
131 #define mmselect (select_fcn_t *)seltrue
132 #define mmmmap eno_mmap
136 extern d_open_t ptsopen
;
137 extern d_close_t ptsclose
;
138 extern d_read_t ptsread
;
139 extern d_write_t ptswrite
;
140 extern d_stop_t ptsstop
;
141 extern d_select_t ptsselect
;
142 extern d_open_t ptcopen
;
143 extern d_close_t ptcclose
;
144 extern d_read_t ptcread
;
145 extern d_write_t ptcwrite
;
146 extern d_select_t ptcselect
;
147 extern d_ioctl_t ptyioctl
;
149 #define ptsopen eno_opcl
150 #define ptsclose eno_opcl
151 #define ptsread eno_rdwrt
152 #define ptswrite eno_rdwrt
153 #define ptsstop nulldev
155 #define ptcopen eno_opcl
156 #define ptcclose eno_opcl
157 #define ptcread eno_rdwrt
158 #define ptcwrite eno_rdwrt
159 #define ptcselect eno_select
160 #define ptyioctl eno_ioctl
163 extern d_open_t logopen
;
164 extern d_close_t logclose
;
165 extern d_read_t logread
;
166 extern d_ioctl_t logioctl
;
167 extern d_select_t logselect
;
168 extern d_open_t fdesc_open
;
169 extern d_read_t fdesc_read
;
170 extern d_write_t fdesc_write
;
171 extern d_ioctl_t fdesc_ioctl
;
172 extern d_select_t fdesc_select
;
174 extern d_open_t oslog_streamopen
;
175 extern d_close_t oslog_streamclose
;
176 extern d_read_t oslog_streamread
;
177 extern d_ioctl_t oslog_streamioctl
;
178 extern d_select_t oslog_streamselect
;
180 extern d_open_t oslogopen
;
181 extern d_close_t oslogclose
;
182 extern d_select_t oslogselect
;
183 extern d_ioctl_t oslogioctl
;
185 #define nullopen (d_open_t *)&nulldev
186 #define nullclose (d_close_t *)&nulldev
187 #define nullread (d_read_t *)&nulldev
188 #define nullwrite (d_write_t *)&nulldev
189 #define nullioctl (d_ioctl_t *)&nulldev
190 #define nullselect (d_select_t *)&nulldev
191 #define nullstop (d_stop_t *)&nulldev
192 #define nullreset (d_reset_t *)&nulldev
194 struct cdevsw cdevsw
[] =
197 * For character devices, every other block of 16 slots is
198 * reserved for Apple. The other slots are available for
199 * the user. This way we can both add new entries without
200 * running into each other. Be sure to fill in Apple's
201 * 16 reserved slots when you jump over us -- we'll do the
205 /* 0 - 15 are reserved for Apple */
208 cnopen
, cnclose
, cnread
, cnwrite
, /* 0*/
209 cnioctl
, nullstop
, nullreset
, 0, cnselect
,
210 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
214 cttyopen
, nullclose
, cttyread
, cttywrite
, /* 2*/
215 cttyioctl
, nullstop
, nullreset
, 0, cttyselect
,
216 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
219 nullopen
, nullclose
, mmread
, mmwrite
, /* 3*/
220 mmioctl
, nullstop
, nullreset
, 0, mmselect
,
221 mmmmap
, eno_strat
, eno_getc
, eno_putc
, D_DISK
224 ptsopen
, ptsclose
, ptsread
, ptswrite
, /* 4*/
225 ptyioctl
, ptsstop
, nullreset
, 0, ptsselect
,
226 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
229 ptcopen
, ptcclose
, ptcread
, ptcwrite
, /* 5*/
230 ptyioctl
, nullstop
, nullreset
, 0, ptcselect
,
231 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
234 logopen
, logclose
, logread
, eno_rdwrt
, /* 6*/
235 logioctl
, eno_stop
, nullreset
, 0, logselect
,
236 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
239 oslogopen
, oslogclose
, eno_rdwrt
, eno_rdwrt
, /* 7*/
240 oslogioctl
, eno_stop
, nullreset
, 0, oslogselect
,
241 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
244 oslog_streamopen
, oslog_streamclose
, oslog_streamread
, eno_rdwrt
, /* 8*/
245 oslog_streamioctl
, eno_stop
, nullreset
, 0, oslog_streamselect
,
246 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
252 kmopen
, kmclose
, kmread
, kmwrite
, /*12*/
253 kmioctl
, nullstop
, nullreset
, km_tty
, ttselect
,
254 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
260 /* 16 - 31 are reserved to the user */
278 /* 32 - 47 are reserved to NeXT */
280 fdesc_open
, eno_opcl
, fdesc_read
, fdesc_write
, /*32*/
281 fdesc_ioctl
, eno_stop
, eno_reset
, 0, fdesc_select
,
282 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
288 sgopen
, sgclose
, eno_rdwrt
, eno_rdwrt
, /*33*/
289 sgioctl
, eno_stop
, eno_reset
, 0, eno_select
,
290 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TAPE
302 volopen
, volclose
, eno_rdwrt
, eno_rdwrt
, /*42*/
303 volioctl
, eno_stop
, eno_reset
, 0, (select_fcn_t
*)seltrue
,
304 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
307 const int nchrdev
= sizeof(cdevsw
) / sizeof(cdevsw
[0]);
309 uint64_t cdevsw_flags
[sizeof(cdevsw
) / sizeof(cdevsw
[0])];
311 #include <sys/vnode.h> /* for VCHR and VBLK */
313 * return true if a disk
316 isdisk(dev_t dev
, int type
)
318 dev_t maj
= major(dev
);
328 if (bdevsw
[maj
].d_type
== D_DISK
) {
336 static int chrtoblktab
[] = {
337 /* CHR*/ /* BLK*/ /* CHR*/ /* BLK*/
338 /* 0 */ NODEV
, /* 1 */ NODEV
,
339 /* 2 */ NODEV
, /* 3 */ NODEV
,
340 /* 4 */ NODEV
, /* 5 */ NODEV
,
341 /* 6 */ NODEV
, /* 7 */ NODEV
,
342 /* 8 */ NODEV
, /* 9 */ NODEV
,
343 /* 10 */ NODEV
, /* 11 */ NODEV
,
344 /* 12 */ NODEV
, /* 13 */ NODEV
,
345 /* 14 */ NODEV
, /* 15 */ NODEV
,
346 /* 16 */ NODEV
, /* 17 */ NODEV
,
347 /* 18 */ NODEV
, /* 19 */ NODEV
,
348 /* 20 */ NODEV
, /* 21 */ NODEV
,
349 /* 22 */ NODEV
, /* 23 */ NODEV
,
350 /* 24 */ NODEV
, /* 25 */ NODEV
,
351 /* 26 */ NODEV
, /* 27 */ NODEV
,
352 /* 28 */ NODEV
, /* 29 */ NODEV
,
353 /* 30 */ NODEV
, /* 31 */ NODEV
,
354 /* 32 */ NODEV
, /* 33 */ NODEV
,
355 /* 34 */ NODEV
, /* 35 */ NODEV
,
356 /* 36 */ NODEV
, /* 37 */ NODEV
,
357 /* 38 */ NODEV
, /* 39 */ NODEV
,
358 /* 40 */ NODEV
, /* 41 */ NODEV
,
359 /* 42 */ NODEV
, /* 43 */ NODEV
,
364 * convert chr dev to blk dev
371 if (major(dev
) >= nchrdev
)
373 blkmaj
= chrtoblktab
[major(dev
)];
376 return(makedev(blkmaj
, minor(dev
)));
380 chrtoblk_set(int cdev
, int bdev
)
384 if (bdev
!= NODEV
&& bdev
>= nblkdev
)
386 chrtoblktab
[cdev
] = bdev
;