ultrix_ioctl.c revision 1.17 1 /* $NetBSD: ultrix_ioctl.c,v 1.17 2001/06/14 20:32:46 thorpej Exp $ */
2 /* from : NetBSD: sunos_ioctl.c,v 1.21 1995/10/07 06:27:31 mycroft Exp */
3
4 /*
5 * Copyright (c) 1993 Markus Wild.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * loosely from: Header: sunos_ioctl.c,v 1.7 93/05/28 04:40:43 torek Exp
28 */
29
30 #if defined(_KERNEL_OPT)
31 #include "opt_compat_ultrix.h"
32 #include "opt_compat_sunos.h"
33 #endif
34
35 #include <sys/param.h>
36 #include <sys/proc.h>
37 #include <sys/systm.h>
38 #include <sys/file.h>
39 #include <sys/filedesc.h>
40 #include <sys/ioctl.h>
41 #include <sys/termios.h>
42 #include <sys/tty.h>
43 #include <sys/socket.h>
44 #include <sys/audioio.h>
45 #include <net/if.h>
46
47 #include <sys/mount.h>
48
49 #include <compat/ultrix/ultrix_syscallargs.h>
50 #include <sys/syscallargs.h>
51
52 #include <compat/sunos/sunos.h>
53
54 #include <compat/ultrix/ultrix_tty.h>
55
56 #define emul_termio ultrix_termio
57 #define emul_termios ultrix_termios
58
59 /*
60 * SunOS ioctl calls.
61 * This file is something of a hodge-podge.
62 * Support gets added as things turn up....
63 */
64
65 static struct speedtab sptab[] = {
66 { 0, 0 },
67 { 50, 1 },
68 { 75, 2 },
69 { 110, 3 },
70 { 134, 4 },
71 { 135, 4 },
72 { 150, 5 },
73 { 200, 6 },
74 { 300, 7 },
75 { 600, 8 },
76 { 1200, 9 },
77 { 1800, 10 },
78 { 2400, 11 },
79 { 4800, 12 },
80 { 9600, 13 },
81 { 19200, 14 },
82 { 38400, 15 },
83 { -1, -1 }
84 };
85
86 static u_long s2btab[] = {
87 0,
88 50,
89 75,
90 110,
91 134,
92 150,
93 200,
94 300,
95 600,
96 1200,
97 1800,
98 2400,
99 4800,
100 9600,
101 19200,
102 38400,
103 };
104
105
106 /*
107 * Translate a single tty control char from the emulation value
108 * to native termios, and vice-versa. Special-case
109 * the value of POSIX_VDISABLE, mapping it to and from 0.
110 */
111 #define NATIVE_TO_EMUL_CC(bsd_cc) \
112 (((bsd_cc) != _POSIX_VDISABLE) ? (bsd_cc) : 0)
113
114 #define EMUL_TO_NATIVE_CC(emul_cc) \
115 (emul_cc) ? (emul_cc) : _POSIX_VDISABLE;
116
117
118 static void stios2btios __P((struct emul_termios *, struct termios *));
119 static void btios2stios __P((struct termios *, struct emul_termios *));
120 static void stios2stio __P((struct emul_termios *, struct emul_termio *));
121 static void stio2stios __P((struct emul_termio *, struct emul_termios *));
122
123 /*
124 * these two conversion functions have mostly been done
125 * with some perl cut&paste, then handedited to comment
126 * out what doesn't exist under NetBSD.
127 * A note from Markus's code:
128 * (l & BITMASK1) / BITMASK1 * BITMASK2 is translated
129 * optimally by gcc m68k, much better than any ?: stuff.
130 * Code may vary with different architectures of course.
131 *
132 * I don't know what optimizer you used, but seeing divu's and
133 * bfextu's in the m68k assembly output did not encourage me...
134 * as well, gcc on the sparc definately generates much better
135 * code with ?:.
136 */
137
138
139 static void
140 stios2btios(st, bt)
141 struct emul_termios *st;
142 struct termios *bt;
143 {
144 u_long l, r;
145
146 l = st->c_iflag;
147 r = ((l & 0x00000001) ? IGNBRK : 0);
148 r |= ((l & 0x00000002) ? BRKINT : 0);
149 r |= ((l & 0x00000004) ? IGNPAR : 0);
150 r |= ((l & 0x00000008) ? PARMRK : 0);
151 r |= ((l & 0x00000010) ? INPCK : 0);
152 r |= ((l & 0x00000020) ? ISTRIP : 0);
153 r |= ((l & 0x00000040) ? INLCR : 0);
154 r |= ((l & 0x00000080) ? IGNCR : 0);
155 r |= ((l & 0x00000100) ? ICRNL : 0);
156 /* ((l & 0x00000200) ? IUCLC : 0) */
157 r |= ((l & 0x00000400) ? IXON : 0);
158 r |= ((l & 0x00000800) ? IXANY : 0);
159 r |= ((l & 0x00001000) ? IXOFF : 0);
160 r |= ((l & 0x00002000) ? IMAXBEL : 0);
161 bt->c_iflag = r;
162
163 l = st->c_oflag;
164 r = ((l & 0x00000001) ? OPOST : 0);
165 /* ((l & 0x00000002) ? OLCUC : 0) */
166 r |= ((l & 0x00000004) ? ONLCR : 0);
167 /* ((l & 0x00000008) ? OCRNL : 0) */
168 /* ((l & 0x00000010) ? ONOCR : 0) */
169 /* ((l & 0x00000020) ? ONLRET : 0) */
170 /* ((l & 0x00000040) ? OFILL : 0) */
171 /* ((l & 0x00000080) ? OFDEL : 0) */
172 /* ((l & 0x00000100) ? NLDLY : 0) */
173 /* ((l & 0x00000100) ? NL1 : 0) */
174 /* ((l & 0x00000600) ? CRDLY : 0) */
175 /* ((l & 0x00000200) ? CR1 : 0) */
176 /* ((l & 0x00000400) ? CR2 : 0) */
177 /* ((l & 0x00000600) ? CR3 : 0) */
178 /* ((l & 0x00001800) ? TABDLY : 0) */
179 /* ((l & 0x00000800) ? TAB1 : 0) */
180 /* ((l & 0x00001000) ? TAB2 : 0) */
181 r |= ((l & 0x00001800) ? OXTABS : 0);
182 /* ((l & 0x00002000) ? BSDLY : 0) */
183 /* ((l & 0x00002000) ? BS1 : 0) */
184 /* ((l & 0x00004000) ? VTDLY : 0) */
185 /* ((l & 0x00004000) ? VT1 : 0) */
186 /* ((l & 0x00008000) ? FFDLY : 0) */
187 /* ((l & 0x00008000) ? FF1 : 0) */
188 /* ((l & 0x00010000) ? PAGEOUT : 0) */
189 /* ((l & 0x00020000) ? WRAP : 0) */
190 bt->c_oflag = r;
191
192 l = st->c_cflag;
193 switch (l & 0x00000030) {
194 case 0:
195 r = CS5;
196 break;
197 case 0x00000010:
198 r = CS6;
199 break;
200 case 0x00000020:
201 r = CS7;
202 break;
203 case 0x00000030:
204 r = CS8;
205 break;
206 }
207 r |= ((l & 0x00000040) ? CSTOPB : 0);
208 r |= ((l & 0x00000080) ? CREAD : 0);
209 r |= ((l & 0x00000100) ? PARENB : 0);
210 r |= ((l & 0x00000200) ? PARODD : 0);
211 r |= ((l & 0x00000400) ? HUPCL : 0);
212 r |= ((l & 0x00000800) ? CLOCAL : 0);
213 /* ((l & 0x00001000) ? LOBLK : 0) */
214 r |= ((l & 0x80000000) ? (CRTS_IFLOW|CCTS_OFLOW) : 0);
215 bt->c_cflag = r;
216
217 bt->c_ispeed = bt->c_ospeed = s2btab[l & 0x0000000f];
218
219 l = st->c_lflag;
220 r = ((l & 0x00000001) ? ISIG : 0);
221 r |= ((l & 0x00000002) ? ICANON : 0);
222 /* ((l & 0x00000004) ? XCASE : 0) */
223 r |= ((l & 0x00000008) ? ECHO : 0);
224 r |= ((l & 0x00000010) ? ECHOE : 0);
225 r |= ((l & 0x00000020) ? ECHOK : 0);
226 r |= ((l & 0x00000040) ? ECHONL : 0);
227 r |= ((l & 0x00000080) ? NOFLSH : 0);
228 r |= ((l & 0x00000100) ? TOSTOP : 0);
229 r |= ((l & 0x00000200) ? ECHOCTL : 0);
230 r |= ((l & 0x00000400) ? ECHOPRT : 0);
231 r |= ((l & 0x00000800) ? ECHOKE : 0);
232 /* ((l & 0x00001000) ? DEFECHO : 0) */
233 r |= ((l & 0x00002000) ? FLUSHO : 0);
234 r |= ((l & 0x00004000) ? PENDIN : 0);
235 bt->c_lflag = r;
236
237 bt->c_cc[VINTR] = EMUL_TO_NATIVE_CC(st->c_cc[0]);
238 bt->c_cc[VQUIT] = EMUL_TO_NATIVE_CC(st->c_cc[1]);
239 bt->c_cc[VERASE] = EMUL_TO_NATIVE_CC(st->c_cc[2]);
240 bt->c_cc[VKILL] = EMUL_TO_NATIVE_CC(st->c_cc[3]);
241 bt->c_cc[VEOF] = EMUL_TO_NATIVE_CC(st->c_cc[4]);
242 bt->c_cc[VEOL] = EMUL_TO_NATIVE_CC(st->c_cc[5]);
243 bt->c_cc[VEOL2] = EMUL_TO_NATIVE_CC(st->c_cc[6]);
244 /* not present on NetBSD */
245 /* bt->c_cc[VSWTCH] = EMUL_TO_NATIVE_CC(st->c_cc[7]); */
246 bt->c_cc[VSTART] = EMUL_TO_NATIVE_CC(st->c_cc[10]);
247 bt->c_cc[VSTOP] = EMUL_TO_NATIVE_CC(st->c_cc[11]);
248 bt->c_cc[VSUSP] = EMUL_TO_NATIVE_CC(st->c_cc[12]);
249 bt->c_cc[VDSUSP] = EMUL_TO_NATIVE_CC(st->c_cc[13]);
250 bt->c_cc[VREPRINT] = EMUL_TO_NATIVE_CC(st->c_cc[14]);
251 bt->c_cc[VDISCARD] = EMUL_TO_NATIVE_CC(st->c_cc[15]);
252 bt->c_cc[VWERASE] = EMUL_TO_NATIVE_CC(st->c_cc[16]);
253 bt->c_cc[VLNEXT] = EMUL_TO_NATIVE_CC(st->c_cc[17]);
254 bt->c_cc[VSTATUS] = EMUL_TO_NATIVE_CC(st->c_cc[18]);
255
256 #ifdef COMPAT_ULTRIX
257 /* Ultrix termio/termios has real vmin/vtime */
258 bt->c_cc[VMIN] = EMUL_TO_NATIVE_CC(st->c_cc[8]);
259 bt->c_cc[VTIME] = EMUL_TO_NATIVE_CC(st->c_cc[9]);
260 #else
261 /* if `raw mode', create native VMIN/VTIME from SunOS VEOF/VEOL */
262 bt->c_cc[VMIN] = (bt->c_lflag & ICANON) ? 1 : bt->c_cc[VEOF];
263 bt->c_cc[VTIME] = (bt->c_lflag & ICANON) ? 1 : bt->c_cc[VEOL];
264 #endif
265
266 }
267
268 /*
269 * Convert bsd termios to "sunos" emulated termios
270 */
271 static void
272 btios2stios(bt, st)
273 struct termios *bt;
274 struct emul_termios *st;
275 {
276 u_long l, r;
277
278 l = bt->c_iflag;
279 r = ((l & IGNBRK) ? 0x00000001 : 0);
280 r |= ((l & BRKINT) ? 0x00000002 : 0);
281 r |= ((l & IGNPAR) ? 0x00000004 : 0);
282 r |= ((l & PARMRK) ? 0x00000008 : 0);
283 r |= ((l & INPCK) ? 0x00000010 : 0);
284 r |= ((l & ISTRIP) ? 0x00000020 : 0);
285 r |= ((l & INLCR) ? 0x00000040 : 0);
286 r |= ((l & IGNCR) ? 0x00000080 : 0);
287 r |= ((l & ICRNL) ? 0x00000100 : 0);
288 /* ((l & IUCLC) ? 0x00000200 : 0) */
289 r |= ((l & IXON) ? 0x00000400 : 0);
290 r |= ((l & IXANY) ? 0x00000800 : 0);
291 r |= ((l & IXOFF) ? 0x00001000 : 0);
292 r |= ((l & IMAXBEL) ? 0x00002000 : 0);
293 st->c_iflag = r;
294
295 l = bt->c_oflag;
296 r = ((l & OPOST) ? 0x00000001 : 0);
297 /* ((l & OLCUC) ? 0x00000002 : 0) */
298 r |= ((l & ONLCR) ? 0x00000004 : 0);
299 /* ((l & OCRNL) ? 0x00000008 : 0) */
300 /* ((l & ONOCR) ? 0x00000010 : 0) */
301 /* ((l & ONLRET) ? 0x00000020 : 0) */
302 /* ((l & OFILL) ? 0x00000040 : 0) */
303 /* ((l & OFDEL) ? 0x00000080 : 0) */
304 /* ((l & NLDLY) ? 0x00000100 : 0) */
305 /* ((l & NL1) ? 0x00000100 : 0) */
306 /* ((l & CRDLY) ? 0x00000600 : 0) */
307 /* ((l & CR1) ? 0x00000200 : 0) */
308 /* ((l & CR2) ? 0x00000400 : 0) */
309 /* ((l & CR3) ? 0x00000600 : 0) */
310 /* ((l & TABDLY) ? 0x00001800 : 0) */
311 /* ((l & TAB1) ? 0x00000800 : 0) */
312 /* ((l & TAB2) ? 0x00001000 : 0) */
313 r |= ((l & OXTABS) ? 0x00001800 : 0);
314 /* ((l & BSDLY) ? 0x00002000 : 0) */
315 /* ((l & BS1) ? 0x00002000 : 0) */
316 /* ((l & VTDLY) ? 0x00004000 : 0) */
317 /* ((l & VT1) ? 0x00004000 : 0) */
318 /* ((l & FFDLY) ? 0x00008000 : 0) */
319 /* ((l & FF1) ? 0x00008000 : 0) */
320 /* ((l & PAGEOUT) ? 0x00010000 : 0) */
321 /* ((l & WRAP) ? 0x00020000 : 0) */
322 st->c_oflag = r;
323
324 l = bt->c_cflag;
325 switch (l & CSIZE) {
326 case CS5:
327 r = 0;
328 break;
329 case CS6:
330 r = 0x00000010;
331 break;
332 case CS7:
333 r = 0x00000020;
334 break;
335 case CS8:
336 r = 0x00000030;
337 break;
338 }
339 r |= ((l & CSTOPB) ? 0x00000040 : 0);
340 r |= ((l & CREAD) ? 0x00000080 : 0);
341 r |= ((l & PARENB) ? 0x00000100 : 0);
342 r |= ((l & PARODD) ? 0x00000200 : 0);
343 r |= ((l & HUPCL) ? 0x00000400 : 0);
344 r |= ((l & CLOCAL) ? 0x00000800 : 0);
345 /* ((l & LOBLK) ? 0x00001000 : 0) */
346 r |= ((l & (CRTS_IFLOW|CCTS_OFLOW)) ? 0x80000000 : 0);
347 st->c_cflag = r;
348
349 l = bt->c_lflag;
350 r = ((l & ISIG) ? 0x00000001 : 0);
351 r |= ((l & ICANON) ? 0x00000002 : 0);
352 /* ((l & XCASE) ? 0x00000004 : 0) */
353 r |= ((l & ECHO) ? 0x00000008 : 0);
354 r |= ((l & ECHOE) ? 0x00000010 : 0);
355 r |= ((l & ECHOK) ? 0x00000020 : 0);
356 r |= ((l & ECHONL) ? 0x00000040 : 0);
357 r |= ((l & NOFLSH) ? 0x00000080 : 0);
358 r |= ((l & TOSTOP) ? 0x00000100 : 0);
359 r |= ((l & ECHOCTL) ? 0x00000200 : 0);
360 r |= ((l & ECHOPRT) ? 0x00000400 : 0);
361 r |= ((l & ECHOKE) ? 0x00000800 : 0);
362 /* ((l & DEFECHO) ? 0x00001000 : 0) */
363 r |= ((l & FLUSHO) ? 0x00002000 : 0);
364 r |= ((l & PENDIN) ? 0x00004000 : 0);
365 st->c_lflag = r;
366
367 l = ttspeedtab(bt->c_ospeed, sptab);
368 if (l >= 0)
369 st->c_cflag |= l;
370
371 st->c_cc[0] = NATIVE_TO_EMUL_CC(bt->c_cc[VINTR]);
372 st->c_cc[1] = NATIVE_TO_EMUL_CC(bt->c_cc[VQUIT]);
373 st->c_cc[2] = NATIVE_TO_EMUL_CC(bt->c_cc[VERASE]);
374 st->c_cc[3] = NATIVE_TO_EMUL_CC(bt->c_cc[VKILL]);
375 st->c_cc[4] = NATIVE_TO_EMUL_CC(bt->c_cc[VEOF]);
376 st->c_cc[5] = NATIVE_TO_EMUL_CC(bt->c_cc[VEOL]);
377 st->c_cc[6] = NATIVE_TO_EMUL_CC(bt->c_cc[VEOL2]);
378
379 /* XXX ultrix has a VSWTCH. NetBSD does not. */
380 #ifdef notdef
381 st->c_cc[7] = NATIVE_TO_EMUL_CC(bt->c_cc[VSWTCH]);
382 #else
383 st->c_cc[7] = 0;
384 #endif
385 st->c_cc[10] = NATIVE_TO_EMUL_CC(bt->c_cc[VSTART]);
386 st->c_cc[11] = NATIVE_TO_EMUL_CC(bt->c_cc[VSTOP]);
387 st->c_cc[12]= NATIVE_TO_EMUL_CC(bt->c_cc[VSUSP]);
388 st->c_cc[13]= NATIVE_TO_EMUL_CC(bt->c_cc[VDSUSP]);
389 st->c_cc[14]= NATIVE_TO_EMUL_CC(bt->c_cc[VREPRINT]);
390 st->c_cc[15]= NATIVE_TO_EMUL_CC(bt->c_cc[VDISCARD]);
391 st->c_cc[16]= NATIVE_TO_EMUL_CC(bt->c_cc[VWERASE]);
392 st->c_cc[17]= NATIVE_TO_EMUL_CC(bt->c_cc[VLNEXT]);
393 st->c_cc[18]= NATIVE_TO_EMUL_CC(bt->c_cc[VSTATUS]);
394
395 #ifdef COMPAT_ULTRIX
396 st->c_cc[8]= NATIVE_TO_EMUL_CC(bt->c_cc[VMIN]);
397 st->c_cc[9]= NATIVE_TO_EMUL_CC(bt->c_cc[VTIME]);
398 #else
399 if (!(bt->c_lflag & ICANON)) {
400 /* SunOS stores VMIN/VTIME in VEOF/VEOL (if ICANON is off) */
401 st->c_cc[4] = bt->c_cc[VMIN];
402 st->c_cc[5] = bt->c_cc[VTIME];
403 }
404 #endif
405
406 #ifdef COMPAT_SUNOS
407 st->c_line = 0; /* 4.3bsd "old" line discipline */
408 #else
409 st->c_line = 2; /* 4.3bsd "new" line discipline, Ultrix default. */
410 #endif
411 }
412
413 #define TERMIO_NCC 10 /* ultrix termio NCC is 10 */
414
415 /*
416 * Convert emulated struct termios to termio(?)
417 */
418 static void
419 stios2stio(ts, t)
420 struct emul_termios *ts;
421 struct emul_termio *t;
422 {
423 t->c_iflag = ts->c_iflag;
424 t->c_oflag = ts->c_oflag;
425 t->c_cflag = ts->c_cflag;
426 t->c_lflag = ts->c_lflag;
427 t->c_line = ts->c_line;
428 memcpy(t->c_cc, ts->c_cc, TERMIO_NCC);
429 }
430
431 /*
432 * Convert the other way
433 */
434 static void
435 stio2stios(t, ts)
436 struct emul_termio *t;
437 struct emul_termios *ts;
438 {
439 ts->c_iflag = t->c_iflag;
440 ts->c_oflag = t->c_oflag;
441 ts->c_cflag = t->c_cflag;
442 ts->c_lflag = t->c_lflag;
443 ts->c_line = t->c_line;
444 memcpy(ts->c_cc, t->c_cc, TERMIO_NCC); /* don't touch the upper fields! */
445 }
446
447 int
448 ultrix_sys_ioctl(p, v, retval)
449 struct proc *p;
450 void *v;
451 register_t *retval;
452 {
453 struct ultrix_sys_ioctl_args *uap = v;
454 struct filedesc *fdp = p->p_fd;
455 struct file *fp;
456 int (*ctl) __P((struct file *, u_long, caddr_t, struct proc *));
457 int error;
458
459 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
460 return EBADF;
461
462 if ((fp->f_flag & (FREAD|FWRITE)) == 0)
463 return EBADF;
464
465 ctl = fp->f_ops->fo_ioctl;
466
467 switch (SCARG(uap, com)) {
468 case _IOR('t', 0, int):
469 SCARG(uap, com) = TIOCGETD;
470 break;
471 case _IOW('t', 1, int):
472 {
473 int disc;
474
475 if ((error = copyin(SCARG(uap, data), (caddr_t)&disc,
476 sizeof disc)) != 0)
477 return error;
478
479 /* map SunOS NTTYDISC into our termios discipline */
480 if (disc == 2)
481 disc = 0;
482 /* all other disciplines are not supported by NetBSD */
483 if (disc)
484 return ENXIO;
485
486 return (*ctl)(fp, TIOCSETD, (caddr_t)&disc, p);
487 }
488 case _IOW('t', 101, int): /* sun SUNOS_TIOCSSOFTCAR */
489 {
490 int x; /* unused */
491
492 return copyin((caddr_t)&x, SCARG(uap, data), sizeof x);
493 }
494 case _IOR('t', 100, int): /* sun SUNOS_TIOCSSOFTCAR */
495 {
496 int x = 0;
497
498 return copyout((caddr_t)&x, SCARG(uap, data), sizeof x);
499 }
500 case _IO('t', 36): /* sun TIOCCONS, no parameters */
501 {
502 int on = 1;
503 return (*ctl)(fp, TIOCCONS, (caddr_t)&on, p);
504 }
505 case _IOW('t', 37, struct sunos_ttysize):
506 {
507 struct winsize ws;
508 struct sunos_ttysize ss;
509
510 if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
511 return (error);
512
513 if ((error = copyin (SCARG(uap, data), &ss, sizeof (ss))) != 0)
514 return error;
515
516 ws.ws_row = ss.ts_row;
517 ws.ws_col = ss.ts_col;
518
519 return ((*ctl)(fp, TIOCSWINSZ, (caddr_t)&ws, p));
520 }
521 case _IOW('t', 38, struct sunos_ttysize):
522 {
523 struct winsize ws;
524 struct sunos_ttysize ss;
525
526 if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
527 return (error);
528
529 ss.ts_row = ws.ws_row;
530 ss.ts_col = ws.ws_col;
531
532 return copyout ((caddr_t)&ss, SCARG(uap, data), sizeof (ss));
533 }
534 case _IOW('t', 118, int):
535 SCARG(uap, com) = TIOCSPGRP;
536 break;
537 case _IOR('t', 119, int):
538 SCARG(uap, com) = TIOCGPGRP;
539 break;
540
541 /* Emulate termio or termios tcget() */
542 case ULTRIX_TCGETA:
543 case ULTRIX_TCGETS:
544 {
545 struct termios bts;
546 struct ultrix_termios sts;
547 struct ultrix_termio st;
548
549 if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bts, p)) != 0)
550 return error;
551
552 btios2stios (&bts, &sts);
553 if (SCARG(uap, com) == ULTRIX_TCGETA) {
554 stios2stio (&sts, &st);
555 return copyout((caddr_t)&st, SCARG(uap, data),
556 sizeof (st));
557 } else
558 return copyout((caddr_t)&sts, SCARG(uap, data),
559 sizeof (sts));
560 /*NOTREACHED*/
561 }
562 /* Emulate termio tcset() */
563 case ULTRIX_TCSETA:
564 case ULTRIX_TCSETAW:
565 case ULTRIX_TCSETAF:
566 {
567 struct termios bts;
568 struct ultrix_termios sts;
569 struct ultrix_termio st;
570 int result;
571
572 if ((error = copyin(SCARG(uap, data), (caddr_t)&st,
573 sizeof (st))) != 0)
574 return error;
575
576 /* get full BSD termios so we don't lose information */
577 if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bts, p)) != 0)
578 return error;
579
580 /*
581 * convert to sun termios, copy in information from
582 * termio, and convert back, then set new values.
583 */
584 btios2stios(&bts, &sts);
585 stio2stios(&st, &sts);
586 stios2btios(&sts, &bts);
587
588 /*
589 * map ioctl code: ultrix tcsets are numbered in reverse order
590 */
591 #ifdef notyet
592 return (*ctl)(fp, ULTRIX_TCSETA - SCARG(uap, com) + TIOCSETA,
593 (caddr_t)&bts, p);
594 #else
595 result= (*ctl)(fp, ULTRIX_TCSETA - SCARG(uap, com) + TIOCSETA,
596 (caddr_t)&bts, p);
597 printf("ultrix TCSETA %lx returns %d\n",
598 ULTRIX_TCSETA - SCARG(uap, com), result);
599 return result;
600 #endif
601
602 }
603 /* Emulate termios tcset() */
604 case ULTRIX_TCSETS:
605 case ULTRIX_TCSETSW:
606 case ULTRIX_TCSETSF:
607 {
608 struct termios bts;
609 struct ultrix_termios sts;
610
611 if ((error = copyin (SCARG(uap, data), (caddr_t)&sts,
612 sizeof (sts))) != 0)
613 return error;
614 stios2btios (&sts, &bts);
615 return (*ctl)(fp, ULTRIX_TCSETS - SCARG(uap, com) + TIOCSETA,
616 (caddr_t)&bts, p);
617 }
618 /*
619 * Pseudo-tty ioctl translations.
620 */
621 case _IOW('t', 32, int): { /* TIOCTCNTL */
622 int error, on;
623
624 error = copyin (SCARG(uap, data), (caddr_t)&on, sizeof (on));
625 if (error != 0)
626 return error;
627 return (*ctl)(fp, TIOCUCNTL, (caddr_t)&on, p);
628 }
629 case _IOW('t', 33, int): { /* TIOCSIGNAL */
630 int error, sig;
631
632 error = copyin (SCARG(uap, data), (caddr_t)&sig, sizeof (sig));
633 if (error != 0)
634 return error;
635 return (*ctl)(fp, TIOCSIG, (caddr_t)&sig, p);
636 }
637
638 /*
639 * Socket ioctl translations.
640 */
641 #define IN_TYPE(a, type_t) { \
642 type_t localbuf; \
643 if ((error = copyin (SCARG(uap, data), \
644 (caddr_t)&localbuf, sizeof (type_t))) != 0) \
645 return error; \
646 return (*ctl)(fp, a, (caddr_t)&localbuf, p); \
647 }
648
649 #define INOUT_TYPE(a, type_t) { \
650 type_t localbuf; \
651 if ((error = copyin (SCARG(uap, data), (caddr_t)&localbuf, \
652 sizeof (type_t))) != 0) \
653 return error; \
654 if ((error = (*ctl)(fp, a, (caddr_t)&localbuf, p)) != 0) \
655 return error; \
656 return copyout ((caddr_t)&localbuf, SCARG(uap, data), sizeof (type_t)); \
657 }
658
659
660 #define IFREQ_IN(a) { \
661 struct ifreq ifreq; \
662 if ((error = copyin (SCARG(uap, data), (caddr_t)&ifreq, sizeof (ifreq))) != 0) \
663 return error; \
664 return (*ctl)(fp, a, (caddr_t)&ifreq, p); \
665 }
666
667 #define IFREQ_INOUT(a) { \
668 struct ifreq ifreq; \
669 if ((error = copyin (SCARG(uap, data), (caddr_t)&ifreq, sizeof (ifreq))) != 0) \
670 return error; \
671 if ((error = (*ctl)(fp, a, (caddr_t)&ifreq, p)) != 0) \
672 return error; \
673 return copyout ((caddr_t)&ifreq, SCARG(uap, data), sizeof (ifreq)); \
674 }
675
676 case _IOW('i', 12, struct ifreq):
677 /* SIOCSIFADDR */
678 break;
679
680 case _IOWR('i', 13, struct ifreq):
681 IFREQ_INOUT(OSIOCGIFADDR);
682
683 case _IOW('i', 14, struct ifreq):
684 /* SIOCSIFDSTADDR */
685 break;
686
687 case _IOWR('i', 15, struct ifreq):
688 IFREQ_INOUT(OSIOCGIFDSTADDR);
689
690 case _IOW('i', 16, struct ifreq):
691 /* SIOCSIFFLAGS */
692 break;
693
694 case _IOWR('i', 17, struct ifreq):
695 /* SIOCGIFFLAGS */
696 break;
697
698 case _IOWR('i', 18, struct ifreq):
699 IFREQ_INOUT(SIOCGIFBRDADDR);
700
701 case _IOWR('i', 19, struct ifreq):
702 IFREQ_INOUT(SIOCSIFBRDADDR);
703
704 case _IOWR('i', 21, struct ifreq):
705 IFREQ_INOUT(OSIOCGIFNETMASK);
706
707 case _IOW('i', 22, struct ifreq):
708 IFREQ_IN(SIOCSIFNETMASK);
709
710 /* 18: _IOWR('i', 18, struct ifreq): Ultrix SIOCGIFBRDADDR */
711 /* 19: _IOW('i', 19, struct ifreq): Ultrix SIOCSIFBRDADDR */
712 /* 20: _IOWR('i', 20, struct ifreq): Ultrix SIOCSIFCONF */
713 /* 21: _IOWR('i', 21, struct ifreq): Ultrix SIOCGIFNETMASK */
714 /* 22: _IOW('i', 22, struct ifreq): Ultrix SIOCSIFNETMASK */
715 /* 23: _IOWR('i', 23, struct ifreq): Ultrix SIOCSPHYADDR */
716 /* 24: _IOWR('i', 24, struct ifreq): Ultrix SIOCSADDMULTI */
717 /* 25: _IOWR('i', 25, struct ifreq): Ultrix SIOCSDELMULTI */
718
719 /* 30: _IOWR('i', 30, struct arpreq): Ultrix SIOCSARP */
720 /* 31: _IOWR('i', 31, struct arpreq): Ultrix SIOCGARP */
721 /* 32: _IOWR('i', 32, struct arpreq): Ultrix SIOCDARP */
722
723 case _IOWR('i', 41, struct ifreq):
724 IFREQ_INOUT(SIOCGIFMETRIC);
725
726 case _IOWR('i', 42, struct ifreq):
727 IFREQ_IN(SIOCSIFMETRIC);
728
729 case _IOW('i', 30, struct arpreq):
730 /* SIOCSARP */
731 break;
732
733 case _IOWR('i', 31, struct arpreq):
734 /* SIOCGARP */
735 break;
736
737 case _IOW('i', 32, struct arpreq):
738 /* SIOCDARP */
739 break;
740
741 case _IOW('i', 26, struct ifreq): /* SIOCSIFRDCTRS? */
742 case _IOWR('i', 27, struct ifreq): /* SIOCGIFZCTRS? */
743 case _IOWR('i', 28, struct ifreq): /* read physaddr ? */
744
745 case _IOW('i', 40, struct ifreq): /* SIOCARPREQ */
746 case _IOW('i', 44, struct ifreq): /* SIOCSETSYNC */
747 case _IOWR('i', 45, struct ifreq): /* SIOCGETSYNC */
748 case _IOWR('i', 46, struct ifreq): /* SIOCSDSTATS */
749 case _IOWR('i', 47, struct ifreq): /* SIOCSESTATS */
750 case _IOW('i', 48, int): /* SIOCSPROMISC */
751 return EOPNOTSUPP;
752
753 /* emulate for vat, vic tools */
754 case _IOW('i', 49, struct ifreq): /* SIOCADDMULTI */
755 case _IOW('i', 50, struct ifreq): /* SIOCDELMULTI */
756 return EOPNOTSUPP;
757
758 case _IOWR('i', 20, struct ifconf): /* SIOCGIFCONF */
759 {
760 struct ifconf ifconf;
761
762 /*
763 * XXX: two more problems
764 * 1. our sockaddr's are variable length, not always sizeof(sockaddr)
765 * 2. this returns a name per protocol, ie. it returns two "lo0"'s
766 */
767 error = copyin (SCARG(uap, data), (caddr_t)&ifconf,
768 sizeof (ifconf));
769 if (error)
770 return error;
771 error = (*ctl)(fp, OSIOCGIFCONF, (caddr_t)&ifconf, p);
772 if (error)
773 return error;
774 return copyout ((caddr_t)&ifconf, SCARG(uap, data),
775 sizeof (ifconf));
776 }
777
778 }
779 return (sys_ioctl(p, uap, retval));
780 }
781