Home | History | Annotate | Line # | Download | only in common
linux_ioctl.c revision 1.9
      1  1.9   thorpej /*	$NetBSD: linux_ioctl.c,v 1.9 1995/11/16 18:42:05 thorpej Exp $	*/
      2  1.1      fvdl 
      3  1.1      fvdl /*
      4  1.1      fvdl  * Copyright (c) 1995 Frank van der Linden
      5  1.1      fvdl  * All rights reserved.
      6  1.1      fvdl  *
      7  1.1      fvdl  * Redistribution and use in source and binary forms, with or without
      8  1.1      fvdl  * modification, are permitted provided that the following conditions
      9  1.1      fvdl  * are met:
     10  1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     11  1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     12  1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     14  1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     15  1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     16  1.1      fvdl  *    must display the following acknowledgement:
     17  1.1      fvdl  *      This product includes software developed for the NetBSD Project
     18  1.1      fvdl  *      by Frank van der Linden
     19  1.1      fvdl  * 4. The name of the author may not be used to endorse or promote products
     20  1.1      fvdl  *    derived from this software without specific prior written permission
     21  1.1      fvdl  *
     22  1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1      fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1      fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1      fvdl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1      fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1      fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1      fvdl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1      fvdl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1      fvdl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1      fvdl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1      fvdl  */
     33  1.1      fvdl 
     34  1.1      fvdl #include <sys/param.h>
     35  1.1      fvdl #include <sys/proc.h>
     36  1.1      fvdl #include <sys/systm.h>
     37  1.1      fvdl #include <sys/file.h>
     38  1.1      fvdl #include <sys/filedesc.h>
     39  1.1      fvdl #include <sys/ioctl.h>
     40  1.1      fvdl #include <sys/termios.h>
     41  1.1      fvdl #include <sys/tty.h>
     42  1.1      fvdl #include <sys/socket.h>
     43  1.1      fvdl #include <sys/ioctl.h>
     44  1.1      fvdl #include <sys/mount.h>
     45  1.2      fvdl #include <net/if.h>
     46  1.2      fvdl #include <sys/sockio.h>
     47  1.1      fvdl 
     48  1.1      fvdl #include <sys/syscallargs.h>
     49  1.4   mycroft 
     50  1.1      fvdl #include <compat/linux/linux_types.h>
     51  1.1      fvdl #include <compat/linux/linux_ioctl.h>
     52  1.2      fvdl #include <compat/linux/linux_sockio.h>
     53  1.1      fvdl #include <compat/linux/linux_util.h>
     54  1.4   mycroft #include <compat/linux/linux_signal.h>
     55  1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     56  1.1      fvdl 
     57  1.1      fvdl static speed_t linux_speeds[] = {
     58  1.1      fvdl 	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
     59  1.1      fvdl 	9600, 19200, 38400, 57600, 115200
     60  1.1      fvdl };
     61  1.1      fvdl 
     62  1.1      fvdl static int linux_spmasks[] = {
     63  1.1      fvdl 	LINUX_B0, LINUX_B50, LINUX_B75, LINUX_B110, LINUX_B134, LINUX_B150,
     64  1.1      fvdl 	LINUX_B200, LINUX_B300, LINUX_B600, LINUX_B1200, LINUX_B1800,
     65  1.1      fvdl 	LINUX_B2400, LINUX_B4800, LINUX_B9600, LINUX_B19200, LINUX_B38400,
     66  1.5   mycroft 	LINUX_B57600, LINUX_B115200, LINUX_B230400
     67  1.1      fvdl };
     68  1.1      fvdl 
     69  1.1      fvdl /*
     70  1.1      fvdl  * Deal with termio ioctl cruft. This doesn't look very good..
     71  1.1      fvdl  * XXX too much code duplication, obviously..
     72  1.1      fvdl  *
     73  1.1      fvdl  * The conversion routines between Linux and BSD structures assume
     74  1.1      fvdl  * that the fields are already filled with the current values,
     75  1.1      fvdl  * so that fields present in BSD but not in Linux keep their current
     76  1.1      fvdl  * values.
     77  1.1      fvdl  */
     78  1.1      fvdl 
     79  1.1      fvdl static int
     80  1.1      fvdl linux_termio_to_bsd_termios(lt, bts)
     81  1.1      fvdl 	register struct linux_termio *lt;
     82  1.1      fvdl 	register struct termios *bts;
     83  1.1      fvdl {
     84  1.1      fvdl 	int index;
     85  1.1      fvdl 
     86  1.1      fvdl 	bts->c_iflag = 0;
     87  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IGNBRK, IGNBRK);
     88  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_BRKINT, BRKINT);
     89  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IGNPAR, IGNPAR);
     90  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_INPCK, INPCK);
     91  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_ISTRIP, ISTRIP);
     92  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_INLCR, INLCR);
     93  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IGNCR, IGNCR);
     94  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_ICRNL, ICRNL);
     95  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IXON, IXON);
     96  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IXANY, IXANY);
     97  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IXOFF, IXOFF);
     98  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lt->c_iflag, LINUX_IMAXBEL, IMAXBEL);
     99  1.1      fvdl 
    100  1.1      fvdl 	bts->c_oflag = 0;
    101  1.1      fvdl 	bts->c_oflag |= cvtto_bsd_mask(lt->c_oflag, LINUX_OPOST, OPOST);
    102  1.1      fvdl 	bts->c_oflag |= cvtto_bsd_mask(lt->c_oflag, LINUX_ONLCR, ONLCR);
    103  1.1      fvdl 	bts->c_oflag |= cvtto_bsd_mask(lt->c_oflag, LINUX_XTABS, OXTABS);
    104  1.1      fvdl 
    105  1.1      fvdl 	/*
    106  1.1      fvdl 	 * This could have been:
    107  1.1      fvdl 	 * bts->c_cflag = (lt->c_flag & LINUX_CSIZE) << 4
    108  1.1      fvdl 	 * But who knows, those values might perhaps change one day.
    109  1.1      fvdl 	 */
    110  1.1      fvdl 	switch (lt->c_cflag & LINUX_CSIZE) {
    111  1.1      fvdl 	case LINUX_CS5:
    112  1.1      fvdl 		bts->c_cflag = CS5;
    113  1.1      fvdl 		break;
    114  1.1      fvdl 	case LINUX_CS6:
    115  1.1      fvdl 		bts->c_cflag = CS6;
    116  1.1      fvdl 		break;
    117  1.1      fvdl 	case LINUX_CS7:
    118  1.1      fvdl 		bts->c_cflag = CS7;
    119  1.1      fvdl 		break;
    120  1.1      fvdl 	case LINUX_CS8:
    121  1.1      fvdl 		bts->c_cflag = CS8;
    122  1.1      fvdl 		break;
    123  1.1      fvdl 	}
    124  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CSTOPB, CSTOPB);
    125  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CREAD, CREAD);
    126  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_PARENB, PARENB);
    127  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_PARODD, PARODD);
    128  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_HUPCL, HUPCL);
    129  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CLOCAL, CLOCAL);
    130  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lt->c_cflag, LINUX_CRTSCTS, CRTSCTS);
    131  1.1      fvdl 
    132  1.1      fvdl 	bts->c_lflag = 0;
    133  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ISIG, ISIG);
    134  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ICANON, ICANON);
    135  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHO, ECHO);
    136  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOE, ECHOE);
    137  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOK, ECHOK);
    138  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHONL, ECHONL);
    139  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_NOFLSH, NOFLSH);
    140  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_TOSTOP, TOSTOP);
    141  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOCTL, ECHOCTL);
    142  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOPRT, ECHOPRT);
    143  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_ECHOKE, ECHOKE);
    144  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_FLUSHO, FLUSHO);
    145  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_PENDIN, PENDIN);
    146  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lt->c_lflag, LINUX_IEXTEN, IEXTEN);
    147  1.1      fvdl 
    148  1.1      fvdl 	index = lt->c_cflag & LINUX_CBAUD;
    149  1.1      fvdl 	if (index & LINUX_CBAUDEX)
    150  1.1      fvdl 		index = (index & ~LINUX_CBAUDEX) + LINUX_NSPEEDS - 1;
    151  1.1      fvdl 	bts->c_ispeed = bts->c_ospeed = linux_speeds[index];
    152  1.1      fvdl 
    153  1.1      fvdl 	bts->c_cc[VINTR] = lt->c_cc[LINUX_VINTR];
    154  1.1      fvdl 	bts->c_cc[VQUIT] = lt->c_cc[LINUX_VQUIT];
    155  1.1      fvdl 	bts->c_cc[VERASE] = lt->c_cc[LINUX_VERASE];
    156  1.1      fvdl 	bts->c_cc[VKILL] = lt->c_cc[LINUX_VKILL];
    157  1.1      fvdl 	bts->c_cc[VEOF] = lt->c_cc[LINUX_VEOF];
    158  1.1      fvdl 	bts->c_cc[VTIME] = lt->c_cc[LINUX_VTIME];
    159  1.1      fvdl 	bts->c_cc[VMIN] = lt->c_cc[LINUX_VMIN];
    160  1.1      fvdl }
    161  1.1      fvdl 
    162  1.1      fvdl static int
    163  1.1      fvdl bsd_termios_to_linux_termio(bts, lt)
    164  1.1      fvdl 	register struct termios *bts;
    165  1.1      fvdl 	register struct linux_termio *lt;
    166  1.1      fvdl {
    167  1.1      fvdl 	int i, mask;
    168  1.1      fvdl 
    169  1.1      fvdl 	lt->c_iflag = 0;
    170  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNBRK, LINUX_IGNBRK);
    171  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, BRKINT, LINUX_BRKINT);
    172  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNPAR, LINUX_IGNPAR);
    173  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, INPCK, LINUX_INPCK);
    174  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, ISTRIP, LINUX_ISTRIP);
    175  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, INLCR, LINUX_INLCR);
    176  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNCR, LINUX_IGNCR);
    177  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, ICRNL, LINUX_ICRNL);
    178  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXON, LINUX_IXON);
    179  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXANY, LINUX_IXANY);
    180  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXOFF, LINUX_IXOFF);
    181  1.1      fvdl 	lt->c_iflag |= cvtto_linux_mask(bts->c_iflag, IMAXBEL, LINUX_IMAXBEL);
    182  1.1      fvdl 
    183  1.1      fvdl 	lt->c_oflag = 0;
    184  1.1      fvdl 	lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, OPOST, LINUX_OPOST);
    185  1.1      fvdl 	lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, ONLCR, LINUX_ONLCR);
    186  1.1      fvdl 	lt->c_oflag |= cvtto_linux_mask(bts->c_oflag, OXTABS, LINUX_XTABS);
    187  1.1      fvdl 
    188  1.1      fvdl 	switch (bts->c_cflag & CSIZE) {
    189  1.1      fvdl 	case CS5:
    190  1.1      fvdl 		lt->c_cflag = LINUX_CS5;
    191  1.1      fvdl 		break;
    192  1.1      fvdl 	case CS6:
    193  1.1      fvdl 		lt->c_cflag = LINUX_CS6;
    194  1.1      fvdl 		break;
    195  1.1      fvdl 	case CS7:
    196  1.1      fvdl 		lt->c_cflag = LINUX_CS7;
    197  1.1      fvdl 		break;
    198  1.1      fvdl 	case CS8:
    199  1.1      fvdl 		lt->c_cflag = LINUX_CS8;
    200  1.1      fvdl 		break;
    201  1.1      fvdl 	}
    202  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CSTOPB, LINUX_CSTOPB);
    203  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CREAD, LINUX_CREAD);
    204  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARENB, LINUX_PARENB);
    205  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARODD, LINUX_PARODD);
    206  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, HUPCL, LINUX_HUPCL);
    207  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CLOCAL, LINUX_CLOCAL);
    208  1.1      fvdl 	lt->c_cflag |= cvtto_linux_mask(bts->c_cflag, CRTSCTS, LINUX_CRTSCTS);
    209  1.1      fvdl 
    210  1.1      fvdl 	lt->c_lflag = 0;
    211  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ISIG, LINUX_ISIG);
    212  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ICANON, LINUX_ICANON);
    213  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHO, LINUX_ECHO);
    214  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOE, LINUX_ECHOE);
    215  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOK, LINUX_ECHOK);
    216  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHONL, LINUX_ECHONL);
    217  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, NOFLSH, LINUX_NOFLSH);
    218  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, TOSTOP, LINUX_TOSTOP);
    219  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOCTL, LINUX_ECHOCTL);
    220  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOPRT, LINUX_ECHOPRT);
    221  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOKE, LINUX_ECHOKE);
    222  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, FLUSHO, LINUX_FLUSHO);
    223  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, PENDIN, LINUX_PENDIN);
    224  1.1      fvdl 	lt->c_lflag |= cvtto_linux_mask(bts->c_lflag, IEXTEN, LINUX_IEXTEN);
    225  1.1      fvdl 
    226  1.1      fvdl 	mask = LINUX_B9600;	/* XXX default value should this be 0? */
    227  1.1      fvdl 	for (i = 0; i < sizeof (linux_speeds) / sizeof (speed_t); i++) {
    228  1.1      fvdl 		if (bts->c_ospeed == linux_speeds[i]) {
    229  1.1      fvdl 			mask = linux_spmasks[i];
    230  1.1      fvdl 			break;
    231  1.1      fvdl 		}
    232  1.1      fvdl 	}
    233  1.1      fvdl 	lt->c_cflag |= mask;
    234  1.1      fvdl 
    235  1.1      fvdl 	lt->c_cc[LINUX_VINTR] = bts->c_cc[VINTR];
    236  1.1      fvdl 	lt->c_cc[LINUX_VQUIT] = bts->c_cc[VQUIT];
    237  1.1      fvdl 	lt->c_cc[LINUX_VERASE] = bts->c_cc[VERASE];
    238  1.1      fvdl 	lt->c_cc[LINUX_VKILL] = bts->c_cc[VKILL];
    239  1.1      fvdl 	lt->c_cc[LINUX_VEOF] = bts->c_cc[VEOF];
    240  1.1      fvdl 	lt->c_cc[LINUX_VTIME] = bts->c_cc[VTIME];
    241  1.1      fvdl 	lt->c_cc[LINUX_VMIN] = bts->c_cc[VMIN];
    242  1.1      fvdl 	lt->c_cc[LINUX_VSWTC] = 0;
    243  1.1      fvdl 
    244  1.1      fvdl 	/* XXX should be fixed someday */
    245  1.1      fvdl 	lt->c_line = 0;
    246  1.1      fvdl }
    247  1.1      fvdl 
    248  1.1      fvdl static int
    249  1.1      fvdl linux_termios_to_bsd_termios(lts, bts)
    250  1.1      fvdl 	register struct linux_termios *lts;
    251  1.1      fvdl 	register struct termios *bts;
    252  1.1      fvdl {
    253  1.1      fvdl 	int index;
    254  1.1      fvdl 
    255  1.1      fvdl 	bts->c_iflag = 0;
    256  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNBRK, IGNBRK);
    257  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_BRKINT, BRKINT);
    258  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNPAR, IGNPAR);
    259  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_INPCK, INPCK);
    260  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_ISTRIP, ISTRIP);
    261  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_INLCR, INLCR);
    262  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IGNCR, IGNCR);
    263  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_ICRNL, ICRNL);
    264  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXON, IXON);
    265  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXANY, IXANY);
    266  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IXOFF, IXOFF);
    267  1.1      fvdl 	bts->c_iflag |= cvtto_bsd_mask(lts->c_iflag, LINUX_IMAXBEL, IMAXBEL);
    268  1.1      fvdl 
    269  1.1      fvdl 	bts->c_oflag = 0;
    270  1.1      fvdl 	bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_OPOST, OPOST);
    271  1.1      fvdl 	bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_ONLCR, ONLCR);
    272  1.1      fvdl 	bts->c_oflag |= cvtto_bsd_mask(lts->c_oflag, LINUX_XTABS, OXTABS);
    273  1.1      fvdl 
    274  1.1      fvdl 	bts->c_cflag = 0;
    275  1.1      fvdl 	switch (lts->c_cflag & LINUX_CSIZE) {
    276  1.1      fvdl 	case LINUX_CS5:
    277  1.1      fvdl 		bts->c_cflag = CS5;
    278  1.1      fvdl 		break;
    279  1.1      fvdl 	case LINUX_CS6:
    280  1.1      fvdl 		bts->c_cflag = CS6;
    281  1.1      fvdl 		break;
    282  1.1      fvdl 	case LINUX_CS7:
    283  1.1      fvdl 		bts->c_cflag = CS7;
    284  1.1      fvdl 		break;
    285  1.1      fvdl 	case LINUX_CS8:
    286  1.1      fvdl 		bts->c_cflag = CS8;
    287  1.1      fvdl 		break;
    288  1.1      fvdl 	}
    289  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CSTOPB, CSTOPB);
    290  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CREAD, CREAD);
    291  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_PARENB, PARENB);
    292  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_PARODD, PARODD);
    293  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_HUPCL, HUPCL);
    294  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CLOCAL, CLOCAL);
    295  1.1      fvdl 	bts->c_cflag |= cvtto_bsd_mask(lts->c_cflag, LINUX_CRTSCTS, CRTSCTS);
    296  1.1      fvdl 
    297  1.1      fvdl 	bts->c_lflag = 0;
    298  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ISIG, ISIG);
    299  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ICANON, ICANON);
    300  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHO, ECHO);
    301  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOE, ECHOE);
    302  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOK, ECHOK);
    303  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHONL, ECHONL);
    304  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_NOFLSH, NOFLSH);
    305  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_TOSTOP, TOSTOP);
    306  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOCTL, ECHOCTL);
    307  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOPRT, ECHOPRT);
    308  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_ECHOKE, ECHOKE);
    309  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_FLUSHO, FLUSHO);
    310  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_PENDIN, PENDIN);
    311  1.1      fvdl 	bts->c_lflag |= cvtto_bsd_mask(lts->c_lflag, LINUX_IEXTEN, IEXTEN);
    312  1.1      fvdl 
    313  1.1      fvdl 	index = lts->c_cflag & LINUX_CBAUD;
    314  1.1      fvdl 	if (index & LINUX_CBAUDEX)
    315  1.1      fvdl 		index = (index & ~LINUX_CBAUDEX) + LINUX_NSPEEDS - 1;
    316  1.1      fvdl 	bts->c_ispeed = bts->c_ospeed = linux_speeds[index];
    317  1.1      fvdl 
    318  1.1      fvdl 	bts->c_cc[VINTR] = lts->c_cc[LINUX_VINTR];
    319  1.1      fvdl 	bts->c_cc[VQUIT] = lts->c_cc[LINUX_VQUIT];
    320  1.1      fvdl 	bts->c_cc[VERASE] = lts->c_cc[LINUX_VERASE];
    321  1.1      fvdl 	bts->c_cc[VKILL] = lts->c_cc[LINUX_VKILL];
    322  1.1      fvdl 	bts->c_cc[VEOF] = lts->c_cc[LINUX_VEOF];
    323  1.1      fvdl 	bts->c_cc[VTIME] = lts->c_cc[LINUX_VTIME];
    324  1.1      fvdl 	bts->c_cc[VMIN] = lts->c_cc[LINUX_VMIN];
    325  1.1      fvdl 	bts->c_cc[VEOL] = lts->c_cc[LINUX_VEOL];
    326  1.1      fvdl 	bts->c_cc[VEOL2] = lts->c_cc[LINUX_VEOL2];
    327  1.1      fvdl 	bts->c_cc[VWERASE] = lts->c_cc[LINUX_VWERASE];
    328  1.1      fvdl 	bts->c_cc[VSUSP] = lts->c_cc[LINUX_VSUSP];
    329  1.1      fvdl 	bts->c_cc[VSTART] = lts->c_cc[LINUX_VSTART];
    330  1.1      fvdl 	bts->c_cc[VSTOP] = lts->c_cc[LINUX_VSTOP];
    331  1.1      fvdl 	bts->c_cc[VLNEXT] = lts->c_cc[LINUX_VLNEXT];
    332  1.1      fvdl 	bts->c_cc[VDISCARD] = lts->c_cc[LINUX_VDISCARD];
    333  1.1      fvdl 	bts->c_cc[VREPRINT] = lts->c_cc[LINUX_VREPRINT];
    334  1.1      fvdl }
    335  1.1      fvdl 
    336  1.1      fvdl static int
    337  1.1      fvdl bsd_termios_to_linux_termios(bts, lts)
    338  1.1      fvdl 	register struct termios *bts;
    339  1.1      fvdl 	register struct linux_termios *lts;
    340  1.1      fvdl {
    341  1.1      fvdl 	int i, mask;
    342  1.1      fvdl 
    343  1.1      fvdl 	lts->c_iflag = 0;
    344  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNBRK, LINUX_IGNBRK);
    345  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, BRKINT, LINUX_BRKINT);
    346  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNPAR, LINUX_IGNPAR);
    347  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, INPCK, LINUX_INPCK);
    348  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, ISTRIP, LINUX_ISTRIP);
    349  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, INLCR, LINUX_INLCR);
    350  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IGNCR, LINUX_IGNCR);
    351  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, ICRNL, LINUX_ICRNL);
    352  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXON, LINUX_IXON);
    353  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXANY, LINUX_IXANY);
    354  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IXOFF, LINUX_IXOFF);
    355  1.1      fvdl 	lts->c_iflag |= cvtto_linux_mask(bts->c_iflag, IMAXBEL, LINUX_IMAXBEL);
    356  1.1      fvdl 
    357  1.1      fvdl 	lts->c_oflag = 0;
    358  1.1      fvdl 	lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, OPOST, LINUX_OPOST);
    359  1.1      fvdl 	lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, ONLCR, LINUX_ONLCR);
    360  1.1      fvdl 	lts->c_oflag |= cvtto_linux_mask(bts->c_oflag, OXTABS, LINUX_XTABS);
    361  1.1      fvdl 
    362  1.1      fvdl 	switch (bts->c_cflag & CSIZE) {
    363  1.1      fvdl 	case CS5:
    364  1.1      fvdl 		lts->c_cflag = LINUX_CS5;
    365  1.1      fvdl 		break;
    366  1.1      fvdl 	case CS6:
    367  1.1      fvdl 		lts->c_cflag = LINUX_CS6;
    368  1.1      fvdl 		break;
    369  1.1      fvdl 	case CS7:
    370  1.1      fvdl 		lts->c_cflag = LINUX_CS7;
    371  1.1      fvdl 		break;
    372  1.1      fvdl 	case CS8:
    373  1.1      fvdl 		lts->c_cflag = LINUX_CS8;
    374  1.1      fvdl 		break;
    375  1.1      fvdl 	}
    376  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS5, LINUX_CS5);
    377  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS6, LINUX_CS6);
    378  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS7, LINUX_CS7);
    379  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CS8, LINUX_CS8);
    380  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CSTOPB, LINUX_CSTOPB);
    381  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CREAD, LINUX_CREAD);
    382  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARENB, LINUX_PARENB);
    383  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, PARODD, LINUX_PARODD);
    384  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, HUPCL, LINUX_HUPCL);
    385  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CLOCAL, LINUX_CLOCAL);
    386  1.1      fvdl 	lts->c_cflag |= cvtto_linux_mask(bts->c_cflag, CRTSCTS, LINUX_CRTSCTS);
    387  1.1      fvdl 
    388  1.1      fvdl 	lts->c_lflag = 0;
    389  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ISIG, LINUX_ISIG);
    390  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ICANON, LINUX_ICANON);
    391  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHO, LINUX_ECHO);
    392  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOE, LINUX_ECHOE);
    393  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOK, LINUX_ECHOK);
    394  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHONL, LINUX_ECHONL);
    395  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, NOFLSH, LINUX_NOFLSH);
    396  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, TOSTOP, LINUX_TOSTOP);
    397  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOCTL, LINUX_ECHOCTL);
    398  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOPRT, LINUX_ECHOPRT);
    399  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, ECHOKE, LINUX_ECHOKE);
    400  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, FLUSHO, LINUX_FLUSHO);
    401  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, PENDIN, LINUX_PENDIN);
    402  1.1      fvdl 	lts->c_lflag |= cvtto_linux_mask(bts->c_lflag, IEXTEN, LINUX_IEXTEN);
    403  1.1      fvdl 
    404  1.1      fvdl 	mask = LINUX_B9600;	/* XXX default value */
    405  1.1      fvdl 	for (i = 0; i < sizeof (linux_speeds) / sizeof (speed_t); i++) {
    406  1.1      fvdl 		if (bts->c_ospeed == linux_speeds[i]) {
    407  1.1      fvdl 			mask = linux_spmasks[i];
    408  1.1      fvdl 			break;
    409  1.1      fvdl 		}
    410  1.1      fvdl 	}
    411  1.1      fvdl 	lts->c_cflag |= mask;
    412  1.1      fvdl 
    413  1.1      fvdl 	lts->c_cc[LINUX_VINTR] = bts->c_cc[VINTR];
    414  1.1      fvdl 	lts->c_cc[LINUX_VQUIT] = bts->c_cc[VQUIT];
    415  1.1      fvdl 	lts->c_cc[LINUX_VERASE] = bts->c_cc[VERASE];
    416  1.1      fvdl 	lts->c_cc[LINUX_VKILL] = bts->c_cc[VKILL];
    417  1.1      fvdl 	lts->c_cc[LINUX_VEOF] = bts->c_cc[VEOF];
    418  1.1      fvdl 	lts->c_cc[LINUX_VTIME] = bts->c_cc[VTIME];
    419  1.1      fvdl 	lts->c_cc[LINUX_VMIN] = bts->c_cc[VMIN];
    420  1.1      fvdl 	lts->c_cc[LINUX_VEOL] = bts->c_cc[VEOL];
    421  1.1      fvdl 	lts->c_cc[LINUX_VEOL2] = bts->c_cc[VEOL2];
    422  1.1      fvdl 	lts->c_cc[LINUX_VWERASE] = bts->c_cc[VWERASE];
    423  1.1      fvdl 	lts->c_cc[LINUX_VSUSP] = bts->c_cc[VSUSP];
    424  1.1      fvdl 	lts->c_cc[LINUX_VSTART] = bts->c_cc[VSTART];
    425  1.1      fvdl 	lts->c_cc[LINUX_VSTOP] = bts->c_cc[VSTOP];
    426  1.1      fvdl 	lts->c_cc[LINUX_VLNEXT] = bts->c_cc[VLNEXT];
    427  1.1      fvdl 	lts->c_cc[LINUX_VDISCARD] = bts->c_cc[VDISCARD];
    428  1.1      fvdl 	lts->c_cc[LINUX_VREPRINT] = bts->c_cc[VREPRINT];
    429  1.1      fvdl 	lts->c_cc[LINUX_VSWTC] = 0;
    430  1.1      fvdl 
    431  1.1      fvdl 	/* XXX should be fixed someday */
    432  1.1      fvdl 	lts->c_line = 0;
    433  1.1      fvdl }
    434  1.1      fvdl 
    435  1.1      fvdl /*
    436  1.1      fvdl  * Most ioctl command are just converted to their NetBSD values,
    437  1.1      fvdl  * and passed on. The ones that take structure pointers and (flag)
    438  1.1      fvdl  * values need some massaging. This is done the usual way by
    439  1.1      fvdl  * allocating stackgap memory, letting the actual ioctl call do its
    440  1.1      fvdl  * work their and converting back the data afterwards.
    441  1.1      fvdl  */
    442  1.1      fvdl int
    443  1.8   mycroft linux_sys_ioctl(p, v, retval)
    444  1.1      fvdl 	register struct proc *p;
    445  1.7   thorpej 	void *v;
    446  1.7   thorpej 	register_t *retval;
    447  1.7   thorpej {
    448  1.8   mycroft 	register struct linux_sys_ioctl_args /* {
    449  1.1      fvdl 		syscallarg(int) fd;
    450  1.1      fvdl 		syscallarg(u_long) com;
    451  1.1      fvdl 		syscallarg(caddr_t) data;
    452  1.7   thorpej 	} */ *uap = v;
    453  1.1      fvdl 	int fd;
    454  1.1      fvdl 	unsigned long com;
    455  1.1      fvdl 	caddr_t data, sg;
    456  1.1      fvdl 	struct file *fp;
    457  1.1      fvdl 	struct filedesc *fdp;
    458  1.1      fvdl 	struct linux_termio tmplt, *alt;
    459  1.1      fvdl 	struct linux_termios tmplts, *alts;
    460  1.1      fvdl 	struct termios tmpbts, *abts;
    461  1.8   mycroft 	struct sys_ioctl_args ia;
    462  1.1      fvdl 	int error, idat, *idatp;
    463  1.1      fvdl 
    464  1.1      fvdl 	fd = SCARG(&ia, fd) = SCARG(uap, fd);
    465  1.1      fvdl 	com = SCARG(uap, com);
    466  1.1      fvdl 	data = SCARG(&ia, data) = SCARG(uap, data);
    467  1.1      fvdl 	retval[0] = 0;
    468  1.1      fvdl 
    469  1.1      fvdl 	fdp = p->p_fd;
    470  1.1      fvdl 	if ((u_int)fd >= fdp->fd_nfiles ||
    471  1.1      fvdl 	    (fp = fdp->fd_ofiles[fd]) == NULL)
    472  1.1      fvdl 		return (EBADF);
    473  1.1      fvdl 
    474  1.1      fvdl 	if ((fp->f_flag & (FREAD | FWRITE)) == 0)
    475  1.1      fvdl 		return (EBADF);
    476  1.1      fvdl 
    477  1.3  christos 	sg = stackgap_init(p->p_emul);
    478  1.1      fvdl 
    479  1.1      fvdl 	switch (com) {
    480  1.1      fvdl 	case LINUX_TCGETS:
    481  1.1      fvdl 		SCARG(&ia, com) = TIOCGETA;
    482  1.1      fvdl 		abts = stackgap_alloc(&sg, sizeof (*abts));
    483  1.1      fvdl 		SCARG(&ia, data) = (caddr_t) abts;
    484  1.8   mycroft 		if ((error = sys_ioctl(p, &ia, retval)) != 0)
    485  1.1      fvdl 			return error;
    486  1.1      fvdl 		if ((error = copyin(abts, &tmpbts, sizeof tmpbts)))
    487  1.1      fvdl 			return error;
    488  1.1      fvdl 		bsd_termios_to_linux_termios(&tmpbts, &tmplts);
    489  1.1      fvdl 		return copyout(&tmplts, data, sizeof tmplts);
    490  1.1      fvdl 	case LINUX_TCSETS:
    491  1.1      fvdl 	case LINUX_TCSETSW:
    492  1.1      fvdl 	case LINUX_TCSETSF:
    493  1.1      fvdl 		switch (com) {
    494  1.1      fvdl 		case LINUX_TCSETS:
    495  1.1      fvdl 			SCARG(&ia, com) = TIOCSETA;
    496  1.1      fvdl 			break;
    497  1.1      fvdl 		case LINUX_TCSETSW:
    498  1.1      fvdl 			SCARG(&ia, com) = TIOCSETAW;
    499  1.1      fvdl 			break;
    500  1.1      fvdl 		case LINUX_TCSETSF:
    501  1.1      fvdl 			SCARG(&ia, com) = TIOCSETAF;
    502  1.1      fvdl 			break;
    503  1.1      fvdl 		}
    504  1.1      fvdl 		if ((error = copyin(data, &tmplts, sizeof tmplts)))
    505  1.1      fvdl 			return error;
    506  1.1      fvdl 		abts = stackgap_alloc(&sg, sizeof tmpbts);
    507  1.1      fvdl 		/*
    508  1.1      fvdl 		 * First fill in all fields, so that we keep the current
    509  1.1      fvdl 		 * values for fields that Linux doesn't know about.
    510  1.1      fvdl 		 */
    511  1.1      fvdl 		if ((error = (*fp->f_ops->fo_ioctl)(fp, TIOCGETA,
    512  1.1      fvdl 		    (caddr_t) &tmpbts, p)))
    513  1.1      fvdl 			return error;
    514  1.1      fvdl 		linux_termios_to_bsd_termios(&tmplts, &tmpbts);
    515  1.1      fvdl 		if ((error = copyout(&tmpbts, abts, sizeof tmpbts)))
    516  1.1      fvdl 			return error;
    517  1.1      fvdl 		SCARG(&ia, data) = (caddr_t) abts;
    518  1.8   mycroft 		return sys_ioctl(p, &ia, retval);
    519  1.1      fvdl 	case LINUX_TCGETA:
    520  1.1      fvdl 		SCARG(&ia, com) = TIOCGETA;
    521  1.1      fvdl 		abts = stackgap_alloc(&sg, sizeof (*abts));
    522  1.1      fvdl 		SCARG(&ia, data) = (caddr_t) abts;
    523  1.8   mycroft 		if ((error = sys_ioctl(p, &ia, retval)) != 0)
    524  1.1      fvdl 			return error;
    525  1.1      fvdl 		if ((error = copyin(abts, &tmpbts, sizeof tmpbts)))
    526  1.1      fvdl 			return error;
    527  1.1      fvdl 		bsd_termios_to_linux_termio(&tmpbts, &tmplt);
    528  1.1      fvdl 		return copyout(&tmplt, data, sizeof tmplt);
    529  1.1      fvdl 	case LINUX_TCSETA:
    530  1.1      fvdl 	case LINUX_TCSETAW:
    531  1.1      fvdl 	case LINUX_TCSETAF:
    532  1.1      fvdl 		switch (com) {
    533  1.1      fvdl 		case LINUX_TCSETA:
    534  1.1      fvdl 			SCARG(&ia, com) = TIOCSETA;
    535  1.1      fvdl 			break;
    536  1.1      fvdl 		case LINUX_TCSETAW:
    537  1.1      fvdl 			SCARG(&ia, com) = TIOCSETAW;
    538  1.1      fvdl 			break;
    539  1.1      fvdl 		case LINUX_TCSETAF:
    540  1.1      fvdl 			SCARG(&ia, com) = TIOCSETAF;
    541  1.1      fvdl 			break;
    542  1.1      fvdl 		}
    543  1.9   thorpej 		if ((error = copyin(data, &tmplt, sizeof tmplt)))
    544  1.1      fvdl 			return error;
    545  1.1      fvdl 		abts = stackgap_alloc(&sg, sizeof tmpbts);
    546  1.1      fvdl 		/*
    547  1.1      fvdl 		 * First fill in all fields, so that we keep the current
    548  1.1      fvdl 		 * values for fields that Linux doesn't know about.
    549  1.1      fvdl 		 */
    550  1.1      fvdl 		if ((error = (*fp->f_ops->fo_ioctl)(fp, TIOCGETA,
    551  1.1      fvdl 		    (caddr_t) &tmpbts, p)))
    552  1.1      fvdl 			return error;
    553  1.1      fvdl 		linux_termio_to_bsd_termios(&tmplt, &tmpbts);
    554  1.1      fvdl 		if ((error = copyout(&tmpbts, abts, sizeof tmpbts)))
    555  1.1      fvdl 			return error;
    556  1.1      fvdl 		SCARG(&ia, data) = (caddr_t) abts;
    557  1.8   mycroft 		return sys_ioctl(p, &ia, retval);
    558  1.1      fvdl 	case LINUX_TIOCSETD:
    559  1.1      fvdl 		if ((error = copyin(data, (caddr_t) &idat, sizeof idat)))
    560  1.1      fvdl 			return error;
    561  1.1      fvdl 		switch (idat) {
    562  1.1      fvdl 		case LINUX_N_TTY:
    563  1.1      fvdl 			idat = TTYDISC;
    564  1.1      fvdl 			break;
    565  1.1      fvdl 		case LINUX_N_SLIP:
    566  1.1      fvdl 			idat = SLIPDISC;
    567  1.1      fvdl 			break;
    568  1.1      fvdl 		case LINUX_N_PPP:
    569  1.1      fvdl 			idat = PPPDISC;
    570  1.1      fvdl 			break;
    571  1.1      fvdl 		/*
    572  1.1      fvdl 		 * We can't handle the mouse line discipline Linux has.
    573  1.1      fvdl 		 */
    574  1.1      fvdl 		case LINUX_N_MOUSE:
    575  1.1      fvdl 		default:
    576  1.1      fvdl 			return EINVAL;
    577  1.1      fvdl 		}
    578  1.1      fvdl 
    579  1.1      fvdl 		idatp = (int *) stackgap_alloc(&sg, sizeof (int));
    580  1.1      fvdl 		if ((error = copyout(&idat, idatp, sizeof (int))))
    581  1.1      fvdl 			return error;
    582  1.1      fvdl 		SCARG(&ia, com) = TIOCSETD;
    583  1.1      fvdl 		SCARG(&ia, data) = (caddr_t) idatp;
    584  1.1      fvdl 		break;
    585  1.1      fvdl 	case LINUX_TIOCGETD:
    586  1.1      fvdl 		idatp = (int *) stackgap_alloc(&sg, sizeof (int));
    587  1.1      fvdl 		SCARG(&ia, com) = TIOCGETD;
    588  1.1      fvdl 		SCARG(&ia, data) = (caddr_t) idatp;
    589  1.8   mycroft 		if ((error = sys_ioctl(p, &ia, retval)))
    590  1.1      fvdl 			return error;
    591  1.1      fvdl 		if ((error = copyin(idatp, (caddr_t) &idat, sizeof (int))))
    592  1.1      fvdl 			return error;
    593  1.1      fvdl 		switch (idat) {
    594  1.1      fvdl 		case TTYDISC:
    595  1.1      fvdl 			idat = LINUX_N_TTY;
    596  1.1      fvdl 			break;
    597  1.1      fvdl 		case SLIPDISC:
    598  1.1      fvdl 			idat = LINUX_N_SLIP;
    599  1.1      fvdl 			break;
    600  1.1      fvdl 		case PPPDISC:
    601  1.1      fvdl 			idat = LINUX_N_PPP;
    602  1.1      fvdl 			break;
    603  1.1      fvdl 		/*
    604  1.1      fvdl 		 * Linux does not have the tablet line discipline.
    605  1.1      fvdl 		 */
    606  1.1      fvdl 		case TABLDISC:
    607  1.1      fvdl 		default:
    608  1.1      fvdl 			idat = -1;	/* XXX What should this be? */
    609  1.1      fvdl 			break;
    610  1.1      fvdl 		}
    611  1.1      fvdl 		return copyout(&idat, data, sizeof (int));
    612  1.1      fvdl 	case LINUX_TIOCGWINSZ:
    613  1.1      fvdl 		SCARG(&ia, com) = TIOCGWINSZ;
    614  1.1      fvdl 		break;
    615  1.1      fvdl 	case LINUX_TIOCSWINSZ:
    616  1.1      fvdl 		SCARG(&ia, com) = TIOCSWINSZ;
    617  1.1      fvdl 		break;
    618  1.1      fvdl 	case LINUX_TIOCGPGRP:
    619  1.1      fvdl 		SCARG(&ia, com) = TIOCGPGRP;
    620  1.1      fvdl 		break;
    621  1.1      fvdl 	case LINUX_TIOCSPGRP:
    622  1.1      fvdl 		SCARG(&ia, com) = TIOCSPGRP;
    623  1.1      fvdl 		break;
    624  1.1      fvdl 	case LINUX_FIONREAD:
    625  1.1      fvdl 		SCARG(&ia, com) = FIONREAD;
    626  1.1      fvdl 		break;
    627  1.1      fvdl 	case LINUX_FIONBIO:
    628  1.1      fvdl 		SCARG(&ia, com) = FIONBIO;
    629  1.1      fvdl 		break;
    630  1.1      fvdl 	case LINUX_FIOASYNC:
    631  1.1      fvdl 		SCARG(&ia, com) = FIOASYNC;
    632  1.1      fvdl 		break;
    633  1.1      fvdl 	case LINUX_TIOCEXCL:
    634  1.1      fvdl 		SCARG(&ia, com) = TIOCEXCL;
    635  1.1      fvdl 		break;
    636  1.1      fvdl 	case LINUX_TIOCNXCL:
    637  1.1      fvdl 		SCARG(&ia, com) = TIOCNXCL;
    638  1.1      fvdl 		break;
    639  1.1      fvdl 	case LINUX_TIOCCONS:
    640  1.1      fvdl 		SCARG(&ia, com) = TIOCCONS;
    641  1.1      fvdl 		break;
    642  1.1      fvdl 	case LINUX_TIOCNOTTY:
    643  1.1      fvdl 		SCARG(&ia, com) = TIOCNOTTY;
    644  1.2      fvdl 		break;
    645  1.2      fvdl 	case LINUX_SIOCADDMULTI:
    646  1.2      fvdl 		SCARG(&ia, com) = SIOCADDMULTI;
    647  1.2      fvdl 		break;
    648  1.2      fvdl 	case LINUX_SIOCDELMULTI:
    649  1.2      fvdl 		SCARG(&ia, com) = SIOCDELMULTI;
    650  1.1      fvdl 		break;
    651  1.1      fvdl 	default:
    652  1.6      fvdl 		return linux_machdepioctl(p, uap, retval);
    653  1.1      fvdl 	}
    654  1.1      fvdl 
    655  1.8   mycroft 	return sys_ioctl(p, &ia, retval);
    656  1.1      fvdl }
    657