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