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