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