2 * Copyright (c) 2000-2020 Apple Inc. All rights reserved.
5 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
6 * Copyright (c) 1993 NeXT Computer, Inc.
8 * UNIX Device switch tables.
12 * 30 July 1997 Umesh Vaishampayan (umeshv@apple.com)
13 * enabled file descriptor pseudo-device.
14 * 18 June 1993 ? at NeXT
15 * Cleaned up a lot of stuff in this file.
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/ioctl.h>
24 /* Prototypes that should be elsewhere: */
25 extern dev_t
chrtoblk(dev_t dev
);
26 extern int chrtoblk_set(int cdev
, int bdev
);
28 struct bdevsw bdevsw
[] =
31 * For block devices, every other block of 8 slots is
32 * reserved to NeXT. The other slots are available for
33 * the user. This way we can both add new entries without
34 * running into each other. Be sure to fill in NeXT's
35 * 8 reserved slots when you jump over us -- we'll do the
39 /* 0 - 7 are reserved to NeXT */
50 /* 8 - 15 are reserved to the user */
60 /* 16 - 23 are reserved to NeXT */
71 const int nblkdev
= sizeof(bdevsw
) / sizeof(bdevsw
[0]);
73 extern struct tty
*km_tty
[];
74 extern d_open_t cnopen
;
75 extern d_close_t cnclose
;
76 extern d_read_t cnread
;
77 extern d_write_t cnwrite
;
78 extern d_ioctl_t cnioctl
;
79 extern d_select_t cnselect
;
80 extern d_open_t kmopen
;
81 extern d_close_t kmclose
;
82 extern d_read_t kmread
;
83 extern d_write_t kmwrite
;
84 extern d_ioctl_t kmioctl
;
85 extern d_open_t sgopen
;
86 extern d_close_t sgclose
;
87 extern d_ioctl_t sgioctl
;
90 extern d_open_t volopen
;
91 extern d_close_t volclose
;
92 extern d_ioctl_t volioctl
;
94 #define volopen eno_opcl
95 #define volclose eno_opcl
96 #define volioctl eno_ioctl
99 extern d_open_t cttyopen
;
100 extern d_read_t cttyread
;
101 extern d_write_t cttywrite
;
102 extern d_ioctl_t cttyioctl
;
103 extern d_select_t cttyselect
;
105 extern d_read_t mmread
;
106 extern d_write_t mmwrite
;
107 extern d_ioctl_t mmioctl
;
108 #define mmselect (select_fcn_t *)seltrue
109 #define mmmmap eno_mmap
113 extern d_open_t ptsopen
;
114 extern d_close_t ptsclose
;
115 extern d_read_t ptsread
;
116 extern d_write_t ptswrite
;
117 extern d_stop_t ptsstop
;
118 extern d_select_t ptsselect
;
119 extern d_open_t ptcopen
;
120 extern d_close_t ptcclose
;
121 extern d_read_t ptcread
;
122 extern d_write_t ptcwrite
;
123 extern d_select_t ptcselect
;
124 extern d_ioctl_t ptyioctl
;
126 #define ptsopen eno_opcl
127 #define ptsclose eno_opcl
128 #define ptsread eno_rdwrt
129 #define ptswrite eno_rdwrt
130 #define ptsstop nulldev
132 #define ptcopen eno_opcl
133 #define ptcclose eno_opcl
134 #define ptcread eno_rdwrt
135 #define ptcwrite eno_rdwrt
136 #define ptcselect eno_select
137 #define ptyioctl eno_ioctl
140 extern d_open_t logopen
;
141 extern d_close_t logclose
;
142 extern d_read_t logread
;
143 extern d_ioctl_t logioctl
;
144 extern d_select_t logselect
;
146 extern d_open_t oslog_streamopen
;
147 extern d_close_t oslog_streamclose
;
148 extern d_read_t oslog_streamread
;
149 extern d_ioctl_t oslog_streamioctl
;
150 extern d_select_t oslog_streamselect
;
152 extern d_open_t oslogopen
;
153 extern d_close_t oslogclose
;
154 extern d_select_t oslogselect
;
155 extern d_ioctl_t oslogioctl
;
157 #define nullopen (d_open_t *)&nulldev
158 #define nullclose (d_close_t *)&nulldev
159 #define nullread (d_read_t *)&nulldev
160 #define nullwrite (d_write_t *)&nulldev
161 #define nullioctl (d_ioctl_t *)&nulldev
162 #define nullselect (d_select_t *)&nulldev
163 #define nullstop (d_stop_t *)&nulldev
164 #define nullreset (d_reset_t *)&nulldev
166 struct cdevsw cdevsw
[] = {
168 * To add character devices to this table dynamically, use cdevsw_add.
172 cnopen
, cnclose
, cnread
, cnwrite
,
173 cnioctl
, nullstop
, nullreset
, 0, cnselect
,
174 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
178 cttyopen
, nullclose
, cttyread
, cttywrite
,
179 cttyioctl
, nullstop
, nullreset
, 0, cttyselect
,
180 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
183 nullopen
, nullclose
, mmread
, mmwrite
,
184 mmioctl
, nullstop
, nullreset
, 0, mmselect
,
185 mmmmap
, eno_strat
, eno_getc
, eno_putc
, D_DISK
188 ptsopen
, ptsclose
, ptsread
, ptswrite
,
189 ptyioctl
, ptsstop
, nullreset
, 0, ptsselect
,
190 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
193 ptcopen
, ptcclose
, ptcread
, ptcwrite
,
194 ptyioctl
, nullstop
, nullreset
, 0, ptcselect
,
195 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, D_TTY
198 logopen
, logclose
, logread
, eno_rdwrt
,
199 logioctl
, eno_stop
, nullreset
, 0, logselect
,
200 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
203 oslogopen
, oslogclose
, eno_rdwrt
, eno_rdwrt
,
204 oslogioctl
, eno_stop
, nullreset
, 0, oslogselect
,
205 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
208 oslog_streamopen
, oslog_streamclose
, oslog_streamread
, eno_rdwrt
,
209 oslog_streamioctl
, eno_stop
, nullreset
, 0, oslog_streamselect
,
210 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
212 [9 ... 11] = NO_CDEVICE
,
214 kmopen
, kmclose
, kmread
, kmwrite
,
215 kmioctl
, nullstop
, nullreset
, km_tty
, ttselect
,
216 eno_mmap
, eno_strat
, eno_getc
, eno_putc
, 0
218 [13 ... 42] = NO_CDEVICE
,
220 const int nchrdev
= sizeof(cdevsw
) / sizeof(cdevsw
[0]);
222 uint64_t cdevsw_flags
[sizeof(cdevsw
) / sizeof(cdevsw
[0])];
224 #include <sys/vnode.h> /* for VCHR and VBLK */
226 * return true if a disk
229 isdisk(dev_t dev
, int type
)
231 dev_t maj
= major(dev
);
241 if (bdevsw
[maj
].d_type
== D_DISK
) {
249 static int chrtoblktab
[] = {[0 ... nchrdev
] = NODEV
};
252 * convert chr dev to blk dev
259 if (major(dev
) >= nchrdev
) {
262 blkmaj
= chrtoblktab
[major(dev
)];
263 if (blkmaj
== NODEV
) {
266 return makedev(blkmaj
, minor(dev
));
270 chrtoblk_set(int cdev
, int bdev
)
272 if (cdev
>= nchrdev
) {
275 if (bdev
!= NODEV
&& bdev
>= nblkdev
) {
278 chrtoblktab
[cdev
] = bdev
;