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