Home | History | Annotate | Line # | Download | only in sunos
sunos_ioctl.c revision 1.60.6.1
      1 /*	$NetBSD: sunos_ioctl.c,v 1.60.6.1 2008/05/10 23:48:59 wrstuden Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993 Markus Wild.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. The name of the author may not be used to endorse or promote products
     13  *    derived from this software without specific prior written permission
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  *
     26  * loosely from: Header: sunos_ioctl.c,v 1.7 93/05/28 04:40:43 torek Exp
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: sunos_ioctl.c,v 1.60.6.1 2008/05/10 23:48:59 wrstuden Exp $");
     31 
     32 #if defined(_KERNEL_OPT)
     33 #include "opt_execfmt.h"
     34 #endif
     35 
     36 #include <sys/param.h>
     37 #include <sys/proc.h>
     38 #include <sys/systm.h>
     39 #include <sys/file.h>
     40 #include <sys/filedesc.h>
     41 #include <sys/ioctl.h>
     42 #include <sys/termios.h>
     43 #include <sys/tty.h>
     44 #include <sys/socket.h>
     45 #include <sys/audioio.h>
     46 #include <sys/vnode.h>
     47 #include <sys/mount.h>
     48 #include <sys/disklabel.h>
     49 #include <sys/sa.h>
     50 #include <sys/syscallargs.h>
     51 
     52 #include <miscfs/specfs/specdev.h>
     53 
     54 #include <net/if.h>
     55 
     56 #include <compat/sys/sockio.h>
     57 
     58 #include <dev/sun/disklabel.h>
     59 
     60 #include <compat/sunos/sunos.h>
     61 #include <compat/sunos/sunos_syscallargs.h>
     62 #include <compat/common/compat_util.h>
     63 
     64 /*
     65  * SunOS ioctl calls.
     66  * This file is something of a hodge-podge.
     67  * Support gets added as things turn up....
     68  */
     69 
     70 static const struct speedtab sptab[] = {
     71 	{ 0, 0 },
     72 	{ 50, 1 },
     73 	{ 75, 2 },
     74 	{ 110, 3 },
     75 	{ 134, 4 },
     76 	{ 135, 4 },
     77 	{ 150, 5 },
     78 	{ 200, 6 },
     79 	{ 300, 7 },
     80 	{ 600, 8 },
     81 	{ 1200, 9 },
     82 	{ 1800, 10 },
     83 	{ 2400, 11 },
     84 	{ 4800, 12 },
     85 	{ 9600, 13 },
     86 	{ 19200, 14 },
     87 	{ 38400, 15 },
     88 	{ -1, -1 }
     89 };
     90 
     91 static const u_long s2btab[] = {
     92 	0,
     93 	50,
     94 	75,
     95 	110,
     96 	134,
     97 	150,
     98 	200,
     99 	300,
    100 	600,
    101 	1200,
    102 	1800,
    103 	2400,
    104 	4800,
    105 	9600,
    106 	19200,
    107 	38400,
    108 };
    109 
    110 static void stios2btios(struct sunos_termios *, struct termios *);
    111 static void btios2stios(struct termios *, struct sunos_termios *);
    112 static void stios2stio(struct sunos_termios *, struct sunos_termio *);
    113 static void stio2stios(struct sunos_termio *, struct sunos_termios *);
    114 
    115 /*
    116  * These two conversion functions have mostly been done
    117  * with some perl cut&paste, then hand-edited to comment
    118  * out what doesn't exist under NetBSD.
    119  * A note from Markus's code:
    120  *	(l & BITMASK1) / BITMASK1 * BITMASK2  is translated
    121  *	optimally by gcc m68k, much better than any ?: stuff.
    122  *	Code may vary with different architectures of course.
    123  *
    124  * I don't know what optimizer you used, but seeing divu's and
    125  * bfextu's in the m68k assembly output did not encourage me...
    126  * as well, gcc on the sparc definitely generates much better
    127  * code with `?:'.
    128  */
    129 
    130 static void
    131 stios2btios(struct sunos_termios *st, struct termios *bt)
    132 {
    133 	u_long l, r;
    134 
    135 	l = st->c_iflag;
    136 	r = 	((l & 0x00000001) ? IGNBRK	: 0);
    137 	r |=	((l & 0x00000002) ? BRKINT	: 0);
    138 	r |=	((l & 0x00000004) ? IGNPAR	: 0);
    139 	r |=	((l & 0x00000008) ? PARMRK	: 0);
    140 	r |=	((l & 0x00000010) ? INPCK	: 0);
    141 	r |=	((l & 0x00000020) ? ISTRIP	: 0);
    142 	r |= 	((l & 0x00000040) ? INLCR	: 0);
    143 	r |=	((l & 0x00000080) ? IGNCR	: 0);
    144 	r |=	((l & 0x00000100) ? ICRNL	: 0);
    145 	/*	((l & 0x00000200) ? IUCLC	: 0) */
    146 	r |=	((l & 0x00000400) ? IXON	: 0);
    147 	r |=	((l & 0x00000800) ? IXANY	: 0);
    148 	r |=	((l & 0x00001000) ? IXOFF	: 0);
    149 	r |=	((l & 0x00002000) ? IMAXBEL	: 0);
    150 	bt->c_iflag = r;
    151 
    152 	l = st->c_oflag;
    153 	r = 	((l & 0x00000001) ? OPOST	: 0);
    154 	/*	((l & 0x00000002) ? OLCUC	: 0) */
    155 	r |=	((l & 0x00000004) ? ONLCR	: 0);
    156 	/*	((l & 0x00000008) ? OCRNL	: 0) */
    157 	/*	((l & 0x00000010) ? ONOCR	: 0) */
    158 	/*	((l & 0x00000020) ? ONLRET	: 0) */
    159 	/*	((l & 0x00000040) ? OFILL	: 0) */
    160 	/*	((l & 0x00000080) ? OFDEL	: 0) */
    161 	/*	((l & 0x00000100) ? NLDLY	: 0) */
    162 	/*	((l & 0x00000100) ? NL1		: 0) */
    163 	/*	((l & 0x00000600) ? CRDLY	: 0) */
    164 	/*	((l & 0x00000200) ? CR1		: 0) */
    165 	/*	((l & 0x00000400) ? CR2		: 0) */
    166 	/*	((l & 0x00000600) ? CR3		: 0) */
    167 	/*	((l & 0x00001800) ? TABDLY	: 0) */
    168 	/*	((l & 0x00000800) ? TAB1	: 0) */
    169 	/*	((l & 0x00001000) ? TAB2	: 0) */
    170 	r |=	((l & 0x00001800) ? OXTABS	: 0);
    171 	/*	((l & 0x00002000) ? BSDLY	: 0) */
    172 	/*	((l & 0x00002000) ? BS1		: 0) */
    173 	/*	((l & 0x00004000) ? VTDLY	: 0) */
    174 	/*	((l & 0x00004000) ? VT1		: 0) */
    175 	/*	((l & 0x00008000) ? FFDLY	: 0) */
    176 	/*	((l & 0x00008000) ? FF1		: 0) */
    177 	/*	((l & 0x00010000) ? PAGEOUT	: 0) */
    178 	/*	((l & 0x00020000) ? WRAP	: 0) */
    179 	bt->c_oflag = r;
    180 
    181 	l = st->c_cflag;
    182 	switch (l & 0x00000030) {
    183 	case 0:
    184 		r = CS5;
    185 		break;
    186 	case 0x00000010:
    187 		r = CS6;
    188 		break;
    189 	case 0x00000020:
    190 		r = CS7;
    191 		break;
    192 	case 0x00000030:
    193 		r = CS8;
    194 		break;
    195 	}
    196 	r |=	((l & 0x00000040) ? CSTOPB	: 0);
    197 	r |=	((l & 0x00000080) ? CREAD	: 0);
    198 	r |= 	((l & 0x00000100) ? PARENB	: 0);
    199 	r |=	((l & 0x00000200) ? PARODD	: 0);
    200 	r |=	((l & 0x00000400) ? HUPCL	: 0);
    201 	r |=	((l & 0x00000800) ? CLOCAL	: 0);
    202 	/*	((l & 0x00001000) ? LOBLK	: 0) */
    203 	r |=	((l & 0x80000000) ? (CRTS_IFLOW|CCTS_OFLOW) : 0);
    204 	bt->c_cflag = r;
    205 
    206 	bt->c_ispeed = bt->c_ospeed = s2btab[l & 0x0000000f];
    207 
    208 	l = st->c_lflag;
    209 	r = 	((l & 0x00000001) ? ISIG	: 0);
    210 	r |=	((l & 0x00000002) ? ICANON	: 0);
    211 	/*	((l & 0x00000004) ? XCASE	: 0) */
    212 	r |=	((l & 0x00000008) ? ECHO	: 0);
    213 	r |=	((l & 0x00000010) ? ECHOE	: 0);
    214 	r |=	((l & 0x00000020) ? ECHOK	: 0);
    215 	r |=	((l & 0x00000040) ? ECHONL	: 0);
    216 	r |= 	((l & 0x00000080) ? NOFLSH	: 0);
    217 	r |=	((l & 0x00000100) ? TOSTOP	: 0);
    218 	r |=	((l & 0x00000200) ? ECHOCTL	: 0);
    219 	r |=	((l & 0x00000400) ? ECHOPRT	: 0);
    220 	r |=	((l & 0x00000800) ? ECHOKE	: 0);
    221 	/*	((l & 0x00001000) ? DEFECHO	: 0) */
    222 	r |=	((l & 0x00002000) ? FLUSHO	: 0);
    223 	r |=	((l & 0x00004000) ? PENDIN	: 0);
    224 	bt->c_lflag = r;
    225 
    226 	bt->c_cc[VINTR]    = st->c_cc[0]  ? st->c_cc[0]  : _POSIX_VDISABLE;
    227 	bt->c_cc[VQUIT]    = st->c_cc[1]  ? st->c_cc[1]  : _POSIX_VDISABLE;
    228 	bt->c_cc[VERASE]   = st->c_cc[2]  ? st->c_cc[2]  : _POSIX_VDISABLE;
    229 	bt->c_cc[VKILL]    = st->c_cc[3]  ? st->c_cc[3]  : _POSIX_VDISABLE;
    230 	bt->c_cc[VEOF]     = st->c_cc[4]  ? st->c_cc[4]  : _POSIX_VDISABLE;
    231 	bt->c_cc[VEOL]     = st->c_cc[5]  ? st->c_cc[5]  : _POSIX_VDISABLE;
    232 	bt->c_cc[VEOL2]    = st->c_cc[6]  ? st->c_cc[6]  : _POSIX_VDISABLE;
    233     /*	bt->c_cc[VSWTCH]   = st->c_cc[7]  ? st->c_cc[7]  : _POSIX_VDISABLE; */
    234 	bt->c_cc[VSTART]   = st->c_cc[8]  ? st->c_cc[8]  : _POSIX_VDISABLE;
    235 	bt->c_cc[VSTOP]    = st->c_cc[9]  ? st->c_cc[9]  : _POSIX_VDISABLE;
    236 	bt->c_cc[VSUSP]    = st->c_cc[10] ? st->c_cc[10] : _POSIX_VDISABLE;
    237 	bt->c_cc[VDSUSP]   = st->c_cc[11] ? st->c_cc[11] : _POSIX_VDISABLE;
    238 	bt->c_cc[VREPRINT] = st->c_cc[12] ? st->c_cc[12] : _POSIX_VDISABLE;
    239 	bt->c_cc[VDISCARD] = st->c_cc[13] ? st->c_cc[13] : _POSIX_VDISABLE;
    240 	bt->c_cc[VWERASE]  = st->c_cc[14] ? st->c_cc[14] : _POSIX_VDISABLE;
    241 	bt->c_cc[VLNEXT]   = st->c_cc[15] ? st->c_cc[15] : _POSIX_VDISABLE;
    242 	bt->c_cc[VSTATUS]  = st->c_cc[16] ? st->c_cc[16] : _POSIX_VDISABLE;
    243 
    244 	/* if `raw mode', create native VMIN/VTIME from SunOS VEOF/VEOL */
    245 	bt->c_cc[VMIN]	   = (bt->c_lflag & ICANON) ? 1 : bt->c_cc[VEOF];
    246 	bt->c_cc[VTIME]	   = (bt->c_lflag & ICANON) ? 1 : bt->c_cc[VEOL];
    247 }
    248 
    249 
    250 static void
    251 btios2stios(struct termios *bt, struct sunos_termios *st)
    252 {
    253 	u_long l, r;
    254 	int s;
    255 
    256 	l = bt->c_iflag;
    257 	r = 	((l &  IGNBRK) ? 0x00000001	: 0);
    258 	r |=	((l &  BRKINT) ? 0x00000002	: 0);
    259 	r |=	((l &  IGNPAR) ? 0x00000004	: 0);
    260 	r |=	((l &  PARMRK) ? 0x00000008	: 0);
    261 	r |=	((l &   INPCK) ? 0x00000010	: 0);
    262 	r |=	((l &  ISTRIP) ? 0x00000020	: 0);
    263 	r |=	((l &   INLCR) ? 0x00000040	: 0);
    264 	r |=	((l &   IGNCR) ? 0x00000080	: 0);
    265 	r |=	((l &   ICRNL) ? 0x00000100	: 0);
    266 	/*	((l &   IUCLC) ? 0x00000200	: 0) */
    267 	r |=	((l &    IXON) ? 0x00000400	: 0);
    268 	r |=	((l &   IXANY) ? 0x00000800	: 0);
    269 	r |=	((l &   IXOFF) ? 0x00001000	: 0);
    270 	r |=	((l & IMAXBEL) ? 0x00002000	: 0);
    271 	st->c_iflag = r;
    272 
    273 	l = bt->c_oflag;
    274 	r =	((l &   OPOST) ? 0x00000001	: 0);
    275 	/*	((l &   OLCUC) ? 0x00000002	: 0) */
    276 	r |=	((l &   ONLCR) ? 0x00000004	: 0);
    277 	/*	((l &   OCRNL) ? 0x00000008	: 0) */
    278 	/*	((l &   ONOCR) ? 0x00000010	: 0) */
    279 	/*	((l &  ONLRET) ? 0x00000020	: 0) */
    280 	/*	((l &   OFILL) ? 0x00000040	: 0) */
    281 	/*	((l &   OFDEL) ? 0x00000080	: 0) */
    282 	/*	((l &   NLDLY) ? 0x00000100	: 0) */
    283 	/*	((l &     NL1) ? 0x00000100	: 0) */
    284 	/*	((l &   CRDLY) ? 0x00000600	: 0) */
    285 	/*	((l &     CR1) ? 0x00000200	: 0) */
    286 	/*	((l &     CR2) ? 0x00000400	: 0) */
    287 	/*	((l &     CR3) ? 0x00000600	: 0) */
    288 	/*	((l &  TABDLY) ? 0x00001800	: 0) */
    289 	/*	((l &    TAB1) ? 0x00000800	: 0) */
    290 	/*	((l &    TAB2) ? 0x00001000	: 0) */
    291 	r |=	((l &  OXTABS) ? 0x00001800	: 0);
    292 	/*	((l &   BSDLY) ? 0x00002000	: 0) */
    293 	/*	((l &     BS1) ? 0x00002000	: 0) */
    294 	/*	((l &   VTDLY) ? 0x00004000	: 0) */
    295 	/*	((l &     VT1) ? 0x00004000	: 0) */
    296 	/*	((l &   FFDLY) ? 0x00008000	: 0) */
    297 	/*	((l &     FF1) ? 0x00008000	: 0) */
    298 	/*	((l & PAGEOUT) ? 0x00010000	: 0) */
    299 	/*	((l &    WRAP) ? 0x00020000	: 0) */
    300 	st->c_oflag = r;
    301 
    302 	l = bt->c_cflag;
    303 	switch (l & CSIZE) {
    304 	case CS5:
    305 		r = 0;
    306 		break;
    307 	case CS6:
    308 		r = 0x00000010;
    309 		break;
    310 	case CS7:
    311 		r = 0x00000020;
    312 		break;
    313 	case CS8:
    314 		r = 0x00000030;
    315 		break;
    316 	}
    317 	r |=	((l &  CSTOPB) ? 0x00000040	: 0);
    318 	r |=	((l &   CREAD) ? 0x00000080	: 0);
    319 	r |=	((l &  PARENB) ? 0x00000100	: 0);
    320 	r |=	((l &  PARODD) ? 0x00000200	: 0);
    321 	r |=	((l &   HUPCL) ? 0x00000400	: 0);
    322 	r |=	((l &  CLOCAL) ? 0x00000800	: 0);
    323 	/*	((l &   LOBLK) ? 0x00001000	: 0) */
    324 	r |=	((l & (CRTS_IFLOW|CCTS_OFLOW)) ? 0x80000000 : 0);
    325 	st->c_cflag = r;
    326 
    327 	l = bt->c_lflag;
    328 	r =	((l &    ISIG) ? 0x00000001	: 0);
    329 	r |=	((l &  ICANON) ? 0x00000002	: 0);
    330 	/*	((l &   XCASE) ? 0x00000004	: 0) */
    331 	r |=	((l &    ECHO) ? 0x00000008	: 0);
    332 	r |=	((l &   ECHOE) ? 0x00000010	: 0);
    333 	r |=	((l &   ECHOK) ? 0x00000020	: 0);
    334 	r |=	((l &  ECHONL) ? 0x00000040	: 0);
    335 	r |=	((l &  NOFLSH) ? 0x00000080	: 0);
    336 	r |=	((l &  TOSTOP) ? 0x00000100	: 0);
    337 	r |=	((l & ECHOCTL) ? 0x00000200	: 0);
    338 	r |=	((l & ECHOPRT) ? 0x00000400	: 0);
    339 	r |=	((l &  ECHOKE) ? 0x00000800	: 0);
    340 	/*	((l & DEFECHO) ? 0x00001000	: 0) */
    341 	r |=	((l &  FLUSHO) ? 0x00002000	: 0);
    342 	r |=	((l &  PENDIN) ? 0x00004000	: 0);
    343 	st->c_lflag = r;
    344 
    345 	s = ttspeedtab(bt->c_ospeed, sptab);
    346 	if (s >= 0)
    347 		st->c_cflag |= s;
    348 
    349 	st->c_cc[0] = bt->c_cc[VINTR]   != _POSIX_VDISABLE? bt->c_cc[VINTR]:0;
    350 	st->c_cc[1] = bt->c_cc[VQUIT]   != _POSIX_VDISABLE? bt->c_cc[VQUIT]:0;
    351 	st->c_cc[2] = bt->c_cc[VERASE]  != _POSIX_VDISABLE? bt->c_cc[VERASE]:0;
    352 	st->c_cc[3] = bt->c_cc[VKILL]   != _POSIX_VDISABLE? bt->c_cc[VKILL]:0;
    353 	st->c_cc[4] = bt->c_cc[VEOF]    != _POSIX_VDISABLE? bt->c_cc[VEOF]:0;
    354 	st->c_cc[5] = bt->c_cc[VEOL]    != _POSIX_VDISABLE? bt->c_cc[VEOL]:0;
    355 	st->c_cc[6] = bt->c_cc[VEOL2]   != _POSIX_VDISABLE? bt->c_cc[VEOL2]:0;
    356 	st->c_cc[7] = 0;
    357 		/*    bt->c_cc[VSWTCH]  != _POSIX_VDISABLE? bt->c_cc[VSWTCH]: */
    358 	st->c_cc[8] = bt->c_cc[VSTART]  != _POSIX_VDISABLE? bt->c_cc[VSTART]:0;
    359 	st->c_cc[9] = bt->c_cc[VSTOP]   != _POSIX_VDISABLE? bt->c_cc[VSTOP]:0;
    360 	st->c_cc[10]= bt->c_cc[VSUSP]   != _POSIX_VDISABLE? bt->c_cc[VSUSP]:0;
    361 	st->c_cc[11]= bt->c_cc[VDSUSP]  != _POSIX_VDISABLE? bt->c_cc[VDSUSP]:0;
    362 	st->c_cc[12]= bt->c_cc[VREPRINT]!= _POSIX_VDISABLE? bt->c_cc[VREPRINT]:0;
    363 	st->c_cc[13]= bt->c_cc[VDISCARD]!= _POSIX_VDISABLE? bt->c_cc[VDISCARD]:0;
    364 	st->c_cc[14]= bt->c_cc[VWERASE] != _POSIX_VDISABLE? bt->c_cc[VWERASE]:0;
    365 	st->c_cc[15]= bt->c_cc[VLNEXT]  != _POSIX_VDISABLE? bt->c_cc[VLNEXT]:0;
    366 	st->c_cc[16]= bt->c_cc[VSTATUS] != _POSIX_VDISABLE? bt->c_cc[VSTATUS]:0;
    367 
    368 	if (!(bt->c_lflag & ICANON)) {
    369 		/* SunOS stores VMIN/VTIME in VEOF/VEOL (if ICANON is off) */
    370 		st->c_cc[4] = bt->c_cc[VMIN];
    371 		st->c_cc[5] = bt->c_cc[VTIME];
    372 	}
    373 
    374 	st->c_line = 0;
    375 }
    376 
    377 static void
    378 stios2stio(struct sunos_termios *ts, struct sunos_termio *t)
    379 {
    380 	t->c_iflag = ts->c_iflag;
    381 	t->c_oflag = ts->c_oflag;
    382 	t->c_cflag = ts->c_cflag;
    383 	t->c_lflag = ts->c_lflag;
    384 	t->c_line  = ts->c_line;
    385 	memcpy(t->c_cc, ts->c_cc, 8);
    386 }
    387 
    388 static void
    389 stio2stios(struct sunos_termio *t, struct sunos_termios *ts)
    390 {
    391 	ts->c_iflag = t->c_iflag;
    392 	ts->c_oflag = t->c_oflag;
    393 	ts->c_cflag = t->c_cflag;
    394 	ts->c_lflag = t->c_lflag;
    395 	ts->c_line  = t->c_line;
    396 	memcpy(ts->c_cc, t->c_cc, 8); /* don't touch the upper fields! */
    397 }
    398 
    399 int
    400 sunos_sys_ioctl(struct lwp *l, const struct sunos_sys_ioctl_args *uap, register_t *retval)
    401 {
    402 	/* {
    403 		int	fd;
    404 		u_long	com;
    405 		void *	data;
    406 	} */
    407 	file_t *fp;
    408 	int (*ctl)(struct file *, u_long, void *);
    409 	struct sys_ioctl_args pass_ua;
    410 	int error;
    411 
    412 	if ((fp = fd_getfile(SCARG(uap, fd))) == NULL)
    413 		return EBADF;
    414 
    415 	if ((fp->f_flag & (FREAD|FWRITE)) == 0) {
    416 		error = EBADF;
    417 		goto out;
    418 	}
    419 
    420 	error = EPASSTHROUGH;
    421 	SCARG(&pass_ua, com) = SCARG(uap, com);
    422 	ctl = fp->f_ops->fo_ioctl;
    423 
    424 	switch (SCARG(uap, com)) {
    425 	case _IOR('t', 0, int):
    426 		SCARG(&pass_ua, com) = TIOCGETD;
    427 		break;
    428 	case _IOW('t', 1, int):
    429 	    {
    430 		int disc;
    431 
    432 		if ((error = copyin(SCARG(uap, data), (void *)&disc,
    433 		    sizeof disc)) != 0)
    434 			break;
    435 
    436 		/* map SunOS NTTYDISC into our termios discipline */
    437 		if (disc == 2)
    438 			disc = 0;
    439 		/* all other disciplines are not supported by NetBSD */
    440 		if (disc) {
    441 			error = ENXIO;
    442 			break;
    443 		}
    444 
    445 		error = (*ctl)(fp, TIOCSETD, &disc);
    446 	    }
    447 	case _IOW('t', 101, int):	/* sun SUNOS_TIOCSSOFTCAR */
    448 	    {
    449 		int x;	/* unused */
    450 
    451 		error = copyin((void *)&x, SCARG(uap, data), sizeof x);
    452 		break;
    453 	    }
    454 	case _IOR('t', 100, int):	/* sun SUNOS_TIOCSSOFTCAR */
    455 	    {
    456 		int x = 0;
    457 
    458 		error = copyout((void *)&x, SCARG(uap, data), sizeof x);
    459 		break;
    460 	    }
    461 	case _IO('t', 36): 		/* sun TIOCCONS, no parameters */
    462 	    {
    463 		int on = 1;
    464 		error = (*ctl)(fp, TIOCCONS, &on);
    465 		break;
    466 	    }
    467 	case _IOW('t', 37, struct sunos_ttysize):
    468 	    {
    469 		struct winsize ws;
    470 		struct sunos_ttysize ss;
    471 
    472 		if ((error = (*ctl)(fp, TIOCGWINSZ, &ws)) != 0)
    473 			break;
    474 
    475 		if ((error = copyin (SCARG(uap, data), &ss, sizeof (ss))) != 0)
    476 			break;
    477 
    478 		ws.ws_row = ss.ts_row;
    479 		ws.ws_col = ss.ts_col;
    480 
    481 		error = (*ctl)(fp, TIOCSWINSZ, &ws);
    482 		break;
    483 	    }
    484 	case _IOW('t', 38, struct sunos_ttysize):
    485 	    {
    486 		struct winsize ws;
    487 		struct sunos_ttysize ss;
    488 
    489 		if ((error = (*ctl)(fp, TIOCGWINSZ, &ws)) != 0)
    490 			break;
    491 
    492 		ss.ts_row = ws.ws_row;
    493 		ss.ts_col = ws.ws_col;
    494 
    495 		error = copyout((void *)&ss, SCARG(uap, data), sizeof (ss));
    496 		break;
    497 	    }
    498 	case _IOR('t', 119, int):	/* TIOCGPGRP */
    499 	    {
    500 		int pgrp;
    501 
    502 		error = (*ctl)(fp, TIOCGPGRP, &pgrp);
    503 		if (error == 0 && pgrp == 0)
    504 			error = EIO;
    505 		if (error)
    506 			break;
    507 		error = copyout((void *)&pgrp, SCARG(uap, data), sizeof(pgrp));
    508 		break;
    509 	    }
    510 	case _IOW('t', 130, int):	/* TIOCSETPGRP: posix variant */
    511 		SCARG(&pass_ua, com) = TIOCSPGRP;
    512 		break;
    513 	case _IOR('t', 131, int):	/* TIOCGETPGRP: posix variant */
    514 	    {
    515 		/*
    516 		 * sigh, must do error translation on pty devices.  if the pgrp
    517 		 * returned is 0 (and no error), we convert this to EIO, if it
    518 		 * is on a pty.
    519 		 */
    520 		int pgrp;
    521 		struct vnode *vp;
    522 
    523 		error = (*ctl)(fp, TIOCGPGRP, &pgrp);
    524 		if (error) {
    525 			vp = (struct vnode *)fp->f_data;
    526 			if ((error == EIO || (error == 0 && pgrp == 0)) &&
    527 			    vp != NULL &&
    528 			    vp->v_type == VCHR &&
    529 			    major(vp->v_rdev) == 21)
    530 				error = ENOTTY;
    531 			break;
    532 		}
    533 		error = copyout((void *)&pgrp, SCARG(uap, data), sizeof(pgrp));
    534 		break;
    535 	    }
    536 	case _IO('t', 132):
    537 		SCARG(&pass_ua, com) = TIOCSCTTY;
    538 		break;
    539 	case SUNOS_TCGETA:
    540 	case SUNOS_TCGETS:
    541 	    {
    542 		struct termios bts;
    543 		struct sunos_termios sts;
    544 		struct sunos_termio st;
    545 
    546 		if ((error = (*ctl)(fp, TIOCGETA, &bts)) != 0)
    547 			break;
    548 
    549 		btios2stios (&bts, &sts);
    550 		if (SCARG(uap, com) == SUNOS_TCGETA) {
    551 			stios2stio (&sts, &st);
    552 			error = copyout((void *)&st, SCARG(uap, data),
    553 			    sizeof (st));
    554 		} else
    555 			error = copyout((void *)&sts, SCARG(uap, data),
    556 			    sizeof (sts));
    557 		break;
    558 	    }
    559 	case SUNOS_TCSETA:
    560 	case SUNOS_TCSETAW:
    561 	case SUNOS_TCSETAF:
    562 	    {
    563 		struct termios bts;
    564 		struct sunos_termios sts;
    565 		struct sunos_termio st;
    566 
    567 		if ((error = copyin(SCARG(uap, data), &st, sizeof (st))) != 0)
    568 			break;
    569 
    570 		/* get full BSD termios so we don't lose information */
    571 		if ((error = (*ctl)(fp, TIOCGETA, &bts)) != 0)
    572 			break;
    573 
    574 		/*
    575 		 * convert to sun termios, copy in information from
    576 		 * termio, and convert back, then set new values.
    577 		 */
    578 		btios2stios(&bts, &sts);
    579 		stio2stios(&st, &sts);
    580 		stios2btios(&sts, &bts);
    581 
    582 		error = (*ctl)(fp, SCARG(uap, com) - SUNOS_TCSETA + TIOCSETA,
    583 		    &bts);
    584 		break;
    585 	    }
    586 	case SUNOS_TCSETS:
    587 	case SUNOS_TCSETSW:
    588 	case SUNOS_TCSETSF:
    589 	    {
    590 		struct termios bts;
    591 		struct sunos_termios sts;
    592 
    593 		if ((error = copyin (SCARG(uap, data), (void *)&sts,
    594 		    sizeof (sts))) != 0)
    595 			break;
    596 		stios2btios (&sts, &bts);
    597 		error = (*ctl)(fp, SCARG(uap, com) - SUNOS_TCSETS + TIOCSETA,
    598 		    &bts);
    599 		break;
    600 	    }
    601 /*
    602  * Pseudo-tty ioctl translations.
    603  */
    604 	case _IOW('t', 32, int): {	/* TIOCTCNTL */
    605 		int on;
    606 
    607 		error = copyin (SCARG(uap, data), (void *)&on, sizeof (on));
    608 		if (error)
    609 			break;
    610 		error = (*ctl)(fp, TIOCUCNTL, &on);
    611 		break;
    612 	}
    613 	case _IOW('t', 33, int): {	/* TIOCSIGNAL */
    614 		int sig;
    615 
    616 		error = copyin (SCARG(uap, data), (void *)&sig, sizeof (sig));
    617 		if (error)
    618 			break;
    619 		error = (*ctl)(fp, TIOCSIG, &sig);
    620 		break;
    621 	}
    622 
    623 /*
    624  * Socket ioctl translations.
    625  */
    626 #define IFREQ_IN(a) { \
    627 	struct oifreq ifreq; \
    628 	error = copyin (SCARG(uap, data), (void *)&ifreq, sizeof (ifreq)); \
    629 	if (error) \
    630 		break; \
    631 	error = (*ctl)(fp, a, &ifreq); \
    632 	break; \
    633 }
    634 #define IFREQ_INOUT(a) { \
    635 	struct oifreq ifreq; \
    636 	error = copyin (SCARG(uap, data), (void *)&ifreq, sizeof (ifreq)); \
    637 	if (error) \
    638 		break; \
    639 	if ((error = (*ctl)(fp, a, &ifreq)) != 0) \
    640 		break; \
    641 	error = copyout ((void *)&ifreq, SCARG(uap, data), sizeof (ifreq)); \
    642 	break; \
    643 }
    644 
    645 	case _IOW('i', 12, struct oifreq):	/* SIOCSIFADDR */
    646 	case _IOW('i', 14, struct oifreq):	/* SIOCSIFDSTADDR */
    647 	case _IOW('i', 16, struct oifreq):	/* SIOCSIFFLAGS */
    648 	case _IOWR('i', 17, struct oifreq):	/* SIOCGIFFLAGS */
    649 	case _IOW('i', 30, struct arpreq):	/* SIOCSARP */
    650 	case _IOWR('i', 31, struct arpreq):	/* SIOCGARP */
    651 	case _IOW('i', 32, struct arpreq):	/* SIOCDARP */
    652 		break;
    653 
    654 	case _IOWR('i', 13, struct oifreq):
    655 		IFREQ_INOUT(OOSIOCGIFADDR);
    656 
    657 	case _IOWR('i', 15, struct oifreq):
    658 		IFREQ_INOUT(OOSIOCGIFDSTADDR);
    659 
    660 	case _IOW('i', 21, struct oifreq):
    661 		IFREQ_IN(SIOCSIFMTU);
    662 
    663 	case _IOWR('i', 22, struct oifreq):
    664 		IFREQ_INOUT(SIOCGIFMTU);
    665 
    666 	case _IOWR('i', 23, struct oifreq):
    667 		IFREQ_INOUT(SIOCGIFBRDADDR);
    668 
    669 	case _IOW('i', 24, struct oifreq):
    670 		IFREQ_IN(SIOCSIFBRDADDR);
    671 
    672 	case _IOWR('i', 25, struct oifreq):
    673 		IFREQ_INOUT(OOSIOCGIFNETMASK);
    674 
    675 	case _IOW('i', 26, struct oifreq):
    676 		IFREQ_IN(SIOCSIFNETMASK);
    677 
    678 	case _IOWR('i', 27, struct oifreq):
    679 		IFREQ_INOUT(SIOCGIFMETRIC);
    680 
    681 	case _IOWR('i', 28, struct oifreq):
    682 		IFREQ_IN(SIOCSIFMETRIC);
    683 
    684 	case _IOW('i', 18, struct oifreq):	/* SIOCSIFMEM */
    685 	case _IOWR('i', 19, struct oifreq):	/* SIOCGIFMEM */
    686 	case _IOW('i', 40, struct oifreq):	/* SIOCUPPER */
    687 	case _IOW('i', 41, struct oifreq):	/* SIOCLOWER */
    688 	case _IOW('i', 44, struct oifreq):	/* SIOCSETSYNC */
    689 	case _IOWR('i', 45, struct oifreq):	/* SIOCGETSYNC */
    690 	case _IOWR('i', 46, struct oifreq):	/* SIOCSDSTATS */
    691 	case _IOWR('i', 47, struct oifreq):	/* SIOCSESTATS */
    692 	case _IOW('i', 48, int):		/* SIOCSPROMISC */
    693 	case _IOW('i', 49, struct oifreq):	/* SIOCADDMULTI */
    694 	case _IOW('i', 50, struct oifreq):	/* SIOCDELMULTI */
    695 		error = EOPNOTSUPP;
    696 		break;
    697 
    698 	case _IOWR('i', 20, struct oifconf):	/* SIOCGIFCONF */
    699 	    {
    700 		struct oifconf ifc;
    701 
    702 		/*
    703 		 * XXX: two more problems
    704 		 * 1. our sockaddr's are variable length, not always sizeof(sockaddr)
    705 		 * 2. this returns a name per protocol, ie. it returns two "lo0"'s
    706 		 */
    707 		error = copyin (SCARG(uap, data), &ifc, sizeof (ifc));
    708 		if (error)
    709 			break;
    710 		error = (*ctl)(fp, OOSIOCGIFCONF, &ifc);
    711 		if (error)
    712 			break;
    713 		error = copyout ((void *)&ifc, SCARG(uap, data),
    714 		    sizeof (ifc));
    715 		break;
    716 	    }
    717 
    718 /*
    719  * Audio ioctl translations.
    720  */
    721 	case _IOR('A', 1, struct sunos_audio_info):	/* AUDIO_GETINFO */
    722 	sunos_au_getinfo:
    723 	    {
    724 		struct audio_info aui;
    725 		struct sunos_audio_info sunos_aui;
    726 
    727 		error = (*ctl)(fp, AUDIO_GETINFO, &aui);
    728 		if (error)
    729 			break;
    730 
    731 		sunos_aui.play = *(struct sunos_audio_prinfo *)&aui.play;
    732 		sunos_aui.record = *(struct sunos_audio_prinfo *)&aui.record;
    733 
    734 		/* `avail_ports' is `seek' in BSD */
    735 		sunos_aui.play.avail_ports = AUDIO_SPEAKER | AUDIO_HEADPHONE;
    736 		sunos_aui.record.avail_ports = AUDIO_SPEAKER | AUDIO_HEADPHONE;
    737 
    738 		sunos_aui.play.waiting = 0;
    739 		sunos_aui.record.waiting = 0;
    740 		sunos_aui.play.eof = 0;
    741 		sunos_aui.record.eof = 0;
    742 		sunos_aui.monitor_gain = 0; /* aui.__spare; XXX */
    743 		/*XXXsunos_aui.output_muted = 0;*/
    744 		/*XXX*/sunos_aui.reserved[0] = 0;
    745 		/*XXX*/sunos_aui.reserved[1] = 0;
    746 		/*XXX*/sunos_aui.reserved[2] = 0;
    747 		/*XXX*/sunos_aui.reserved[3] = 0;
    748 
    749 		error = copyout ((void *)&sunos_aui, SCARG(uap, data),
    750 				sizeof (sunos_aui));
    751 		break;
    752 	    }
    753 
    754 	case _IOWR('A', 2, struct sunos_audio_info):	/* AUDIO_SETINFO */
    755 	    {
    756 		struct audio_info aui;
    757 		struct sunos_audio_info sunos_aui;
    758 
    759 		error = copyin (SCARG(uap, data), (void *)&sunos_aui,
    760 		    sizeof (sunos_aui));
    761 		if (error)
    762 			break;
    763 
    764 		aui.play = *(struct audio_prinfo *)&sunos_aui.play;
    765 		aui.record = *(struct audio_prinfo *)&sunos_aui.record;
    766 		/* aui.__spare = sunos_aui.monitor_gain; */
    767 		aui.blocksize = ~0;
    768 		aui.hiwat = ~0;
    769 		aui.lowat = ~0;
    770 		/* XXX somebody check this please. - is: aui.backlog = ~0; */
    771 		aui.mode = ~0;
    772 		/*
    773 		 * The bsd driver does not distinguish between paused and
    774 		 * active. (In the sun driver, not active means samples are
    775 		 * not output at all, but paused means the last streams buffer
    776 		 * is drained and then output stops.)  If either are 0, then
    777 		 * when stop output. Otherwise, if either are non-zero,
    778 		 * we resume.
    779 		 */
    780 		if (sunos_aui.play.pause == 0 || sunos_aui.play.active == 0)
    781 			aui.play.pause = 0;
    782 		else if (sunos_aui.play.pause != (u_char)~0 ||
    783 			 sunos_aui.play.active != (u_char)~0)
    784 			aui.play.pause = 1;
    785 		if (sunos_aui.record.pause == 0 || sunos_aui.record.active == 0)
    786 			aui.record.pause = 0;
    787 		else if (sunos_aui.record.pause != (u_char)~0 ||
    788 			 sunos_aui.record.active != (u_char)~0)
    789 			aui.record.pause = 1;
    790 
    791 		error = (*ctl)(fp, AUDIO_SETINFO, &aui);
    792 		if (error)
    793 			break;
    794 		/* Return new state */
    795 		goto sunos_au_getinfo;
    796 	    }
    797 	case _IO('A', 3):	/* AUDIO_DRAIN */
    798 		error = (*ctl)(fp, AUDIO_DRAIN, NULL);
    799 		break;
    800 	case _IOR('A', 4, int):	/* AUDIO_GETDEV */
    801 	    {
    802 		int devtype = SUNOS_AUDIO_DEV_AMD;
    803 		error = copyout ((void *)&devtype, SCARG(uap, data),
    804 				sizeof (devtype));
    805 		break;
    806 	    }
    807 
    808 /*
    809  * Selected streams ioctls.
    810  */
    811 #define SUNOS_S_FLUSHR		1
    812 #define SUNOS_S_FLUSHW		2
    813 #define SUNOS_S_FLUSHRW		3
    814 
    815 #define SUNOS_S_INPUT		1
    816 #define SUNOS_S_HIPRI		2
    817 #define SUNOS_S_OUTPUT		4
    818 #define SUNOS_S_MSG		8
    819 
    820 	case _IO('S', 5):	/* I_FLUSH */
    821 	    {
    822 		int tmp = 0;
    823 		switch ((int)(u_long)SCARG(uap, data)) {
    824 		case SUNOS_S_FLUSHR:	tmp = FREAD;
    825 		case SUNOS_S_FLUSHW:	tmp = FWRITE;
    826 		case SUNOS_S_FLUSHRW:	tmp = FREAD|FWRITE;
    827 		}
    828                 error = (*ctl)(fp, TIOCFLUSH, &tmp);
    829 		break;
    830 	    }
    831 	case _IO('S', 9):	/* I_SETSIG */
    832 	    {
    833 		int on = 1;
    834 		if (((int)(u_long)SCARG(uap, data) &
    835 			(SUNOS_S_HIPRI|SUNOS_S_INPUT)) == SUNOS_S_HIPRI) {
    836 			error = EOPNOTSUPP;
    837 			break;
    838 		}
    839                 error = (*ctl)(fp, FIOASYNC, &on);
    840 		break;
    841 	    }
    842 	/*
    843 	 * SunOS disk ioctls, taken from arch/sparc/sparc/disksubr.c
    844 	 * (which was from the old sparc/scsi/sun_disklabel.c), and
    845 	 * modified to suite.
    846 	 */
    847 	case DKIOCGGEOM:
    848             {
    849 		struct disklabel dl;
    850 
    851 		error = (*ctl)(fp, DIOCGDINFO, &dl);
    852 		if (error)
    853 			break;
    854 
    855 #define datageom	((struct sun_dkgeom *)SCARG(uap, data))
    856 		memset(SCARG(uap, data), 0, sizeof(*datageom));
    857 
    858 		datageom->sdkc_ncylinders = dl.d_ncylinders;
    859 		datageom->sdkc_acylinders = dl.d_acylinders;
    860 		datageom->sdkc_ntracks = dl.d_ntracks;
    861 		datageom->sdkc_nsectors = dl.d_nsectors;
    862 		datageom->sdkc_interleave = dl.d_interleave;
    863 		datageom->sdkc_sparespercyl = dl.d_sparespercyl;
    864 		datageom->sdkc_rpm = dl.d_rpm;
    865 		datageom->sdkc_pcylinders = dl.d_ncylinders + dl.d_acylinders;
    866 #undef datageom
    867 		break;
    868 	    }
    869 
    870 	case DKIOCINFO:
    871 		/* Homey don't do DKIOCINFO */
    872 		memset(SCARG(uap, data), 0, sizeof(struct sun_dkctlr));
    873 		break;
    874 
    875 	case DKIOCGPART:
    876             {
    877 		struct partinfo pi;
    878 
    879 		error = (*ctl)(fp, DIOCGPART, &pi);
    880 		if (error)
    881 			break;
    882 
    883 		if (pi.disklab->d_secpercyl == 0) {
    884 			error = ERANGE;	/* XXX */
    885 			break;
    886 		}
    887 		if (pi.part->p_offset % pi.disklab->d_secpercyl != 0) {
    888 			error = ERANGE;	/* XXX */
    889 			break;
    890 		}
    891 
    892 #define datapart	((struct sun_dkpart *)SCARG(uap, data))
    893 		datapart->sdkp_cyloffset = pi.part->p_offset / pi.disklab->d_secpercyl;
    894 		datapart->sdkp_nsectors = pi.part->p_size;
    895 #undef datapart
    896 		break;
    897 	    }
    898 
    899 	}
    900 
    901 out:
    902 	fd_putfile(SCARG(uap, fd));
    903 	if (error == EPASSTHROUGH) {
    904 		SCARG(&pass_ua, fd) = SCARG(uap, fd);
    905 		SCARG(&pass_ua, data) = SCARG(uap, data);
    906 		error = sys_ioctl(l, &pass_ua, retval);
    907 	}
    908 	return (error);
    909 }
    910 
    911 /* SunOS fcntl(2) cmds not implemented */
    912 #define SUN_F_RGETLK	10
    913 #define SUN_F_RSETLK	11
    914 #define SUN_F_CNVT	12
    915 #define SUN_F_RSETLKW	13
    916 
    917 /* SunOS flock translation */
    918 struct sunos_flock {
    919 	short	l_type;
    920 	short	l_whence;
    921 	long	l_start;
    922 	long	l_len;
    923 	short	l_pid;
    924 	short	l_xxx;
    925 };
    926 
    927 static void bsd_to_sunos_flock(struct flock *, struct sunos_flock *);
    928 static void sunos_to_bsd_flock(struct sunos_flock *, struct flock *);
    929 
    930 #define SUNOS_F_RDLCK	1
    931 #define	SUNOS_F_WRLCK	2
    932 #define SUNOS_F_UNLCK	3
    933 
    934 static void
    935 bsd_to_sunos_flock(struct flock *iflp, struct sunos_flock *oflp)
    936 {
    937 	switch (iflp->l_type) {
    938 	case F_RDLCK:
    939 		oflp->l_type = SUNOS_F_RDLCK;
    940 		break;
    941 	case F_WRLCK:
    942 		oflp->l_type = SUNOS_F_WRLCK;
    943 		break;
    944 	case F_UNLCK:
    945 		oflp->l_type = SUNOS_F_UNLCK;
    946 		break;
    947 	default:
    948 		oflp->l_type = -1;
    949 		break;
    950 	}
    951 
    952 	oflp->l_whence = (short) iflp->l_whence;
    953 	oflp->l_start = (long) iflp->l_start;
    954 	oflp->l_len = (long) iflp->l_len;
    955 	oflp->l_pid = (short) iflp->l_pid;
    956 	oflp->l_xxx = 0;
    957 }
    958 
    959 
    960 static void
    961 sunos_to_bsd_flock(struct sunos_flock *iflp, struct flock *oflp)
    962 {
    963 	switch (iflp->l_type) {
    964 	case SUNOS_F_RDLCK:
    965 		oflp->l_type = F_RDLCK;
    966 		break;
    967 	case SUNOS_F_WRLCK:
    968 		oflp->l_type = F_WRLCK;
    969 		break;
    970 	case SUNOS_F_UNLCK:
    971 		oflp->l_type = F_UNLCK;
    972 		break;
    973 	default:
    974 		oflp->l_type = -1;
    975 		break;
    976 	}
    977 
    978 	oflp->l_whence = iflp->l_whence;
    979 	oflp->l_start = (off_t) iflp->l_start;
    980 	oflp->l_len = (off_t) iflp->l_len;
    981 	oflp->l_pid = (pid_t) iflp->l_pid;
    982 
    983 }
    984 static struct {
    985 	long	sun_flg;
    986 	long	bsd_flg;
    987 } sunfcntl_flgtab[] = {
    988 	/* F_[GS]ETFLags that differ: */
    989 #define SUN_FSETBLK	0x0010
    990 #define SUN_SHLOCK	0x0080
    991 #define SUN_EXLOCK	0x0100
    992 #define SUN_FNBIO	0x1000
    993 #define SUN_FSYNC	0x2000
    994 #define SUN_NONBLOCK	0x4000
    995 #define SUN_FNOCTTY	0x8000
    996 	{ SUN_NONBLOCK, O_NONBLOCK },
    997 	{ SUN_FNBIO, O_NONBLOCK },
    998 	{ SUN_SHLOCK, O_SHLOCK },
    999 	{ SUN_EXLOCK, O_EXLOCK },
   1000 	{ SUN_FSYNC, O_FSYNC },
   1001 	{ SUN_FSETBLK, 0 },
   1002 	{ SUN_FNOCTTY, 0 }
   1003 };
   1004 
   1005 int
   1006 sunos_sys_fcntl(struct lwp *l, const struct sunos_sys_fcntl_args *uap, register_t *retval)
   1007 {
   1008 	long flg;
   1009 	int n, ret;
   1010 	struct sys_fcntl_args bsd_ua;
   1011 
   1012 	SCARG(&bsd_ua, fd) = SCARG(uap, fd);
   1013 	SCARG(&bsd_ua, cmd) = SCARG(uap, cmd);
   1014 	SCARG(&bsd_ua, arg) = SCARG(uap, arg);
   1015 
   1016 
   1017 	switch (SCARG(uap, cmd)) {
   1018 	case F_SETFL:
   1019 		flg = (long)SCARG(uap, arg);
   1020 		n = sizeof(sunfcntl_flgtab) / sizeof(sunfcntl_flgtab[0]);
   1021 		while (--n >= 0) {
   1022 			if (flg & sunfcntl_flgtab[n].sun_flg) {
   1023 				flg &= ~sunfcntl_flgtab[n].sun_flg;
   1024 				flg |= sunfcntl_flgtab[n].bsd_flg;
   1025 			}
   1026 		}
   1027 		SCARG(&bsd_ua, arg) = (void *)flg;
   1028 		break;
   1029 
   1030 	case F_GETLK:
   1031 	case F_SETLK:
   1032 	case F_SETLKW:
   1033 		{
   1034 			int error;
   1035 			struct sunos_flock	 ifl;
   1036 			struct flock		 fl;
   1037 
   1038 			error = copyin(SCARG(uap, arg), &ifl, sizeof ifl);
   1039 			if (error)
   1040 				return error;
   1041 			sunos_to_bsd_flock(&ifl, &fl);
   1042 
   1043 			error = do_fcntl_lock(SCARG(uap, fd), SCARG(uap, cmd), &fl);
   1044 			if (error)
   1045 				return error;
   1046 
   1047 			if (error || SCARG(uap, cmd) != F_GETLK)
   1048 				return error;
   1049 
   1050 			bsd_to_sunos_flock(&fl, &ifl);
   1051 
   1052 			return copyout(&ifl, SCARG(uap, arg), sizeof ifl);
   1053 		}
   1054 		break;
   1055 	case SUN_F_RGETLK:
   1056 	case SUN_F_RSETLK:
   1057 	case SUN_F_CNVT:
   1058 	case SUN_F_RSETLKW:
   1059 		return (EOPNOTSUPP);
   1060 
   1061 	default:
   1062 		break;
   1063 	}
   1064 
   1065 	ret = sys_fcntl(l, &bsd_ua, retval);
   1066 
   1067 	switch (SCARG(&bsd_ua, cmd)) {
   1068 	case F_GETFL:
   1069 		n = sizeof(sunfcntl_flgtab) / sizeof(sunfcntl_flgtab[0]);
   1070 		while (--n >= 0) {
   1071 			if (ret & sunfcntl_flgtab[n].bsd_flg) {
   1072 				ret &= ~sunfcntl_flgtab[n].bsd_flg;
   1073 				ret |= sunfcntl_flgtab[n].sun_flg;
   1074 			}
   1075 		}
   1076 		break;
   1077 	default:
   1078 		break;
   1079 	}
   1080 
   1081 	return (ret);
   1082 }
   1083