Home | History | Annotate | Line # | Download | only in common
tty_43.c revision 1.32
      1  1.32  christos /*	$NetBSD: tty_43.c,v 1.32 2019/01/28 15:46:49 christos Exp $	*/
      2  1.25        ad 
      3  1.25        ad /*-
      4  1.25        ad  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.25        ad  * All rights reserved.
      6  1.25        ad  *
      7  1.25        ad  * Redistribution and use in source and binary forms, with or without
      8  1.25        ad  * modification, are permitted provided that the following conditions
      9  1.25        ad  * are met:
     10  1.25        ad  * 1. Redistributions of source code must retain the above copyright
     11  1.25        ad  *    notice, this list of conditions and the following disclaimer.
     12  1.25        ad  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.25        ad  *    notice, this list of conditions and the following disclaimer in the
     14  1.25        ad  *    documentation and/or other materials provided with the distribution.
     15  1.25        ad  *
     16  1.25        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.25        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.25        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.25        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.25        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.25        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.25        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.25        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.25        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.25        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.25        ad  * POSSIBILITY OF SUCH DAMAGE.
     27  1.25        ad  */
     28   1.1  christos 
     29   1.1  christos /*-
     30   1.1  christos  * Copyright (c) 1982, 1986, 1991, 1993
     31   1.1  christos  *	The Regents of the University of California.  All rights reserved.
     32   1.1  christos  *
     33   1.1  christos  * Redistribution and use in source and binary forms, with or without
     34   1.1  christos  * modification, are permitted provided that the following conditions
     35   1.1  christos  * are met:
     36   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     37   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     38   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     39   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     40   1.1  christos  *    documentation and/or other materials provided with the distribution.
     41  1.17       agc  * 3. Neither the name of the University nor the names of its contributors
     42   1.1  christos  *    may be used to endorse or promote products derived from this software
     43   1.1  christos  *    without specific prior written permission.
     44   1.1  christos  *
     45   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     46   1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     47   1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     48   1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     49   1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     50   1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     51   1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     52   1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     53   1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     54   1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     55   1.1  christos  * SUCH DAMAGE.
     56   1.1  christos  *
     57   1.8      fvdl  *	@(#)tty_compat.c	8.2 (Berkeley) 1/9/95
     58   1.1  christos  */
     59   1.1  christos 
     60   1.1  christos /*
     61   1.1  christos  * mapping routines for old line discipline (yuck)
     62   1.1  christos  */
     63  1.13     lukem 
     64  1.13     lukem #include <sys/cdefs.h>
     65  1.32  christos __KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.32 2019/01/28 15:46:49 christos Exp $");
     66  1.31  pgoyette 
     67  1.31  pgoyette #if defined(_KERNEL_OPT)
     68  1.31  pgoyette #include "opt_compat_netbsd.h"
     69  1.31  pgoyette #endif
     70  1.13     lukem 
     71   1.1  christos #include <sys/param.h>
     72   1.1  christos #include <sys/systm.h>
     73   1.1  christos #include <sys/ioctl.h>
     74   1.1  christos #include <sys/proc.h>
     75  1.11     itohy #include <sys/conf.h>
     76   1.1  christos #include <sys/tty.h>
     77   1.1  christos #include <sys/termios.h>
     78   1.1  christos #include <sys/file.h>
     79   1.1  christos #include <sys/kernel.h>
     80   1.1  christos #include <sys/syslog.h>
     81  1.32  christos #include <sys/compat_stub.h>
     82  1.32  christos #include <sys/module_hook.h>
     83   1.2  christos #include <sys/ioctl_compat.h>
     84   1.1  christos 
     85  1.31  pgoyette #include <compat/common/compat_mod.h>
     86  1.32  christos #include <compat/sys/ttycom.h>
     87  1.31  pgoyette 
     88   1.1  christos int ttydebug = 0;
     89   1.1  christos 
     90  1.18      matt static const struct speedtab compatspeeds[] = {
     91   1.1  christos #define MAX_SPEED	17
     92   1.1  christos 	{ 115200, 17 },
     93   1.1  christos 	{ 57600, 16 },
     94   1.1  christos 	{ 38400, 15 },
     95   1.1  christos 	{ 19200, 14 },
     96   1.1  christos 	{ 9600,	13 },
     97   1.1  christos 	{ 4800,	12 },
     98   1.1  christos 	{ 2400,	11 },
     99   1.1  christos 	{ 1800,	10 },
    100   1.1  christos 	{ 1200,	9 },
    101   1.1  christos 	{ 600,	8 },
    102   1.1  christos 	{ 300,	7 },
    103   1.1  christos 	{ 200,	6 },
    104   1.1  christos 	{ 150,	5 },
    105   1.1  christos 	{ 134,	4 },
    106   1.1  christos 	{ 110,	3 },
    107   1.1  christos 	{ 75,	2 },
    108   1.1  christos 	{ 50,	1 },
    109   1.1  christos 	{ 0,	0 },
    110   1.1  christos 	{ -1,	-1 },
    111   1.1  christos };
    112  1.18      matt static const int compatspcodes[] = {
    113   1.1  christos 	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
    114   1.1  christos 	1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200
    115   1.1  christos };
    116   1.1  christos 
    117  1.25        ad static int ttcompatgetflags(struct tty *);
    118  1.25        ad static void ttcompatsetflags(struct tty *, struct termios *);
    119  1.25        ad static void ttcompatsetlflags(struct tty *, struct termios *);
    120   1.3  christos 
    121   1.1  christos /*ARGSUSED*/
    122   1.3  christos int
    123  1.32  christos compat_43_ttioctl(struct tty *tp, u_long com, void *data, int flag,
    124  1.32  christos     struct lwp *l)
    125   1.1  christos {
    126   1.1  christos 
    127   1.1  christos 	switch (com) {
    128   1.1  christos 	case TIOCGETP: {
    129  1.10  augustss 		struct sgttyb *sg = (struct sgttyb *)data;
    130  1.10  augustss 		int speed;
    131   1.1  christos 
    132  1.25        ad 		mutex_spin_enter(&tty_lock);
    133   1.1  christos 		speed = ttspeedtab(tp->t_ospeed, compatspeeds);
    134   1.1  christos 		sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed;
    135   1.1  christos 		if (tp->t_ispeed == 0)
    136   1.1  christos 			sg->sg_ispeed = sg->sg_ospeed;
    137   1.1  christos 		else {
    138   1.1  christos 			speed = ttspeedtab(tp->t_ispeed, compatspeeds);
    139   1.1  christos 			sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed;
    140   1.1  christos 		}
    141  1.30  dholland 		sg->sg_erase = tty_getctrlchar(tp, VERASE);
    142  1.30  dholland 		sg->sg_kill = tty_getctrlchar(tp, VKILL);
    143   1.1  christos 		sg->sg_flags = ttcompatgetflags(tp);
    144  1.25        ad 		mutex_spin_exit(&tty_lock);
    145   1.1  christos 		break;
    146   1.1  christos 	}
    147   1.1  christos 
    148   1.1  christos 	case TIOCSETP:
    149   1.1  christos 	case TIOCSETN: {
    150  1.10  augustss 		struct sgttyb *sg = (struct sgttyb *)data;
    151   1.1  christos 		struct termios term;
    152   1.1  christos 		int speed;
    153   1.1  christos 
    154  1.25        ad 		mutex_spin_enter(&tty_lock);
    155   1.1  christos 		term = tp->t_termios;
    156   1.1  christos 		if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
    157   1.1  christos 			term.c_ispeed = speed;
    158   1.1  christos 		else
    159   1.1  christos 			term.c_ispeed = compatspcodes[speed];
    160   1.1  christos 		if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
    161   1.1  christos 			term.c_ospeed = speed;
    162   1.1  christos 		else
    163   1.1  christos 			term.c_ospeed = compatspcodes[speed];
    164   1.1  christos 		term.c_cc[VERASE] = sg->sg_erase;
    165   1.1  christos 		term.c_cc[VKILL] = sg->sg_kill;
    166   1.1  christos 		tp->t_flags = (ttcompatgetflags(tp)&0xffff0000) | (sg->sg_flags&0xffff);
    167   1.1  christos 		ttcompatsetflags(tp, &term);
    168  1.25        ad 		mutex_spin_exit(&tty_lock);
    169   1.1  christos 		return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA,
    170  1.22  christos 			(void *)&term, flag, l));
    171   1.1  christos 	}
    172   1.1  christos 
    173   1.1  christos 	case TIOCGETC: {
    174   1.1  christos 		struct tchars *tc = (struct tchars *)data;
    175   1.1  christos 
    176  1.30  dholland 		tc->t_intrc = tty_getctrlchar(tp, VINTR);
    177  1.30  dholland 		tc->t_quitc = tty_getctrlchar(tp, VQUIT);
    178  1.30  dholland 		tc->t_startc = tty_getctrlchar(tp, VSTART);
    179  1.30  dholland 		tc->t_stopc = tty_getctrlchar(tp, VSTOP);
    180  1.30  dholland 		tc->t_eofc = tty_getctrlchar(tp, VEOF);
    181  1.30  dholland 		tc->t_brkc = tty_getctrlchar(tp, VEOL);
    182   1.1  christos 		break;
    183   1.1  christos 	}
    184   1.1  christos 	case TIOCSETC: {
    185   1.1  christos 		struct tchars *tc = (struct tchars *)data;
    186   1.1  christos 
    187  1.30  dholland 		tty_setctrlchar(tp, VINTR, tc->t_intrc);
    188  1.30  dholland 		tty_setctrlchar(tp, VQUIT, tc->t_quitc);
    189  1.30  dholland 		tty_setctrlchar(tp, VSTART, tc->t_startc);
    190  1.30  dholland 		tty_setctrlchar(tp, VSTOP, tc->t_stopc);
    191  1.30  dholland 		tty_setctrlchar(tp, VEOF, tc->t_eofc);
    192  1.30  dholland 		tty_setctrlchar(tp, VEOL, tc->t_brkc);
    193   1.5      mark 		if (tc->t_brkc == (char)-1)
    194  1.30  dholland 			tty_setctrlchar(tp, VEOL2, _POSIX_VDISABLE);
    195   1.1  christos 		break;
    196   1.1  christos 	}
    197   1.1  christos 	case TIOCSLTC: {
    198   1.1  christos 		struct ltchars *ltc = (struct ltchars *)data;
    199   1.1  christos 
    200  1.30  dholland 		tty_setctrlchar(tp, VSUSP, ltc->t_suspc);
    201  1.30  dholland 		tty_setctrlchar(tp, VDSUSP, ltc->t_dsuspc);
    202  1.30  dholland 		tty_setctrlchar(tp, VREPRINT, ltc->t_rprntc);
    203  1.30  dholland 		tty_setctrlchar(tp, VDISCARD, ltc->t_flushc);
    204  1.30  dholland 		tty_setctrlchar(tp, VWERASE, ltc->t_werasc);
    205  1.30  dholland 		tty_setctrlchar(tp, VLNEXT, ltc->t_lnextc);
    206   1.1  christos 		break;
    207   1.1  christos 	}
    208   1.1  christos 	case TIOCGLTC: {
    209   1.1  christos 		struct ltchars *ltc = (struct ltchars *)data;
    210   1.1  christos 
    211  1.30  dholland 		ltc->t_suspc = tty_getctrlchar(tp, VSUSP);
    212  1.30  dholland 		ltc->t_dsuspc = tty_getctrlchar(tp, VDSUSP);
    213  1.30  dholland 		ltc->t_rprntc = tty_getctrlchar(tp, VREPRINT);
    214  1.30  dholland 		ltc->t_flushc = tty_getctrlchar(tp, VDISCARD);
    215  1.30  dholland 		ltc->t_werasc = tty_getctrlchar(tp, VWERASE);
    216  1.30  dholland 		ltc->t_lnextc = tty_getctrlchar(tp, VLNEXT);
    217   1.1  christos 		break;
    218   1.1  christos 	}
    219   1.1  christos 	case TIOCLBIS:
    220   1.1  christos 	case TIOCLBIC:
    221   1.1  christos 	case TIOCLSET: {
    222   1.1  christos 		struct termios term;
    223   1.1  christos 		int flags;
    224   1.1  christos 
    225  1.25        ad 		mutex_spin_enter(&tty_lock);
    226   1.1  christos 		term = tp->t_termios;
    227   1.1  christos 		flags = ttcompatgetflags(tp);
    228   1.1  christos 		switch (com) {
    229   1.1  christos 		case TIOCLSET:
    230   1.1  christos 			tp->t_flags = (flags&0xffff) | (*(int *)data<<16);
    231   1.1  christos 			break;
    232   1.1  christos 		case TIOCLBIS:
    233   1.1  christos 			tp->t_flags = flags | (*(int *)data<<16);
    234   1.1  christos 			break;
    235   1.1  christos 		case TIOCLBIC:
    236   1.1  christos 			tp->t_flags = flags & ~(*(int *)data<<16);
    237   1.1  christos 			break;
    238   1.1  christos 		}
    239   1.1  christos 		ttcompatsetlflags(tp, &term);
    240  1.25        ad 		mutex_spin_exit(&tty_lock);
    241  1.22  christos 		return (ttioctl(tp, TIOCSETA, (void *)&term, flag, l));
    242   1.1  christos 	}
    243   1.1  christos 	case TIOCLGET:
    244  1.25        ad 		mutex_spin_enter(&tty_lock);
    245   1.1  christos 		*(int *)data = ttcompatgetflags(tp)>>16;
    246  1.25        ad 		mutex_spin_exit(&tty_lock);
    247   1.1  christos 		if (ttydebug)
    248   1.7  christos 			printf("CLGET: returning %x\n", *(int *)data);
    249   1.1  christos 		break;
    250   1.1  christos 
    251   1.1  christos 	case OTIOCGETD:
    252  1.25        ad 		mutex_spin_enter(&tty_lock);
    253  1.19   thorpej 		*(int *)data = (tp->t_linesw == NULL) ?
    254  1.19   thorpej 		    2 /* XXX old NTTYDISC */ : tp->t_linesw->l_no;
    255  1.25        ad 		mutex_spin_exit(&tty_lock);
    256   1.1  christos 		break;
    257   1.1  christos 
    258   1.1  christos 	case OTIOCSETD: {
    259   1.1  christos 		int ldisczero = 0;
    260   1.1  christos 
    261   1.1  christos 		return (ttioctl(tp, TIOCSETD,
    262  1.22  christos 			*(int *)data == 2 ? (void *)&ldisczero : data, flag,
    263  1.20  christos 			l));
    264   1.1  christos 	    }
    265   1.1  christos 
    266   1.1  christos 	case OTIOCCONS:
    267   1.1  christos 		*(int *)data = 1;
    268  1.20  christos 		return (ttioctl(tp, TIOCCONS, data, flag, l));
    269   1.1  christos 
    270   1.1  christos 	case TIOCHPCL:
    271  1.25        ad 		mutex_spin_enter(&tty_lock);
    272   1.1  christos 		SET(tp->t_cflag, HUPCL);
    273  1.25        ad 		mutex_spin_exit(&tty_lock);
    274   1.1  christos 		break;
    275   1.1  christos 
    276   1.1  christos 	case TIOCGSID:
    277  1.26        ad 		mutex_enter(proc_lock);
    278  1.25        ad 		if (tp->t_session == NULL) {
    279  1.26        ad 			mutex_exit(proc_lock);
    280   1.1  christos 			return ENOTTY;
    281  1.25        ad 		}
    282  1.25        ad 		if (tp->t_session->s_leader == NULL) {
    283  1.26        ad 			mutex_exit(proc_lock);
    284   1.1  christos 			return ENOTTY;
    285  1.25        ad 		}
    286   1.1  christos 		*(int *) data =  tp->t_session->s_leader->p_pid;
    287  1.26        ad 		mutex_exit(proc_lock);
    288   1.1  christos 		break;
    289   1.1  christos 
    290   1.1  christos 	default:
    291  1.14    atatat 		return (EPASSTHROUGH);
    292   1.1  christos 	}
    293   1.1  christos 	return (0);
    294   1.1  christos }
    295   1.1  christos 
    296  1.25        ad static int
    297  1.24       dsl ttcompatgetflags(struct tty *tp)
    298   1.1  christos {
    299  1.10  augustss 	tcflag_t iflag = tp->t_iflag;
    300  1.10  augustss 	tcflag_t lflag = tp->t_lflag;
    301  1.10  augustss 	tcflag_t oflag = tp->t_oflag;
    302  1.10  augustss 	tcflag_t cflag = tp->t_cflag;
    303  1.10  augustss 	int flags = 0;
    304   1.1  christos 
    305  1.25        ad 	KASSERT(mutex_owned(&tty_lock));
    306  1.25        ad 
    307   1.1  christos 	if (ISSET(iflag, IXOFF))
    308   1.1  christos 		SET(flags, TANDEM);
    309   1.1  christos 	if (ISSET(iflag, ICRNL) || ISSET(oflag, ONLCR))
    310   1.1  christos 		SET(flags, CRMOD);
    311   1.1  christos 	if (ISSET(cflag, PARENB)) {
    312   1.1  christos 		if (ISSET(iflag, INPCK)) {
    313   1.1  christos 			if (ISSET(cflag, PARODD))
    314   1.1  christos 				SET(flags, ODDP);
    315   1.1  christos 			else
    316   1.1  christos 				SET(flags, EVENP);
    317   1.1  christos 		} else
    318   1.1  christos 			SET(flags, ANYP);
    319   1.1  christos 	}
    320   1.1  christos 
    321   1.1  christos 	if (!ISSET(lflag, ICANON)) {
    322   1.1  christos 		/* fudge */
    323   1.1  christos 		if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) ||
    324   1.1  christos 		    ISSET(cflag, PARENB))
    325   1.1  christos 			SET(flags, CBREAK);
    326   1.1  christos 		else
    327   1.1  christos 			SET(flags, RAW);
    328   1.1  christos 	}
    329   1.1  christos 
    330   1.1  christos 	if (ISSET(flags, RAW))
    331   1.1  christos 		SET(flags, ISSET(tp->t_flags, LITOUT|PASS8));
    332   1.1  christos 	else if (ISSET(cflag, CSIZE) == CS8) {
    333   1.1  christos 		if (!ISSET(oflag, OPOST))
    334   1.1  christos 			SET(flags, LITOUT);
    335   1.1  christos 		if (!ISSET(iflag, ISTRIP))
    336   1.1  christos 			SET(flags, PASS8);
    337   1.1  christos 	}
    338   1.1  christos 
    339   1.1  christos 	if (ISSET(cflag, MDMBUF))
    340   1.1  christos 		SET(flags, MDMBUF);
    341   1.1  christos 	if (!ISSET(cflag, HUPCL))
    342   1.1  christos 		SET(flags, NOHANG);
    343   1.1  christos 	if (ISSET(oflag, OXTABS))
    344   1.1  christos 		SET(flags, XTABS);
    345   1.1  christos 	if (ISSET(lflag, ECHOE))
    346   1.1  christos 		SET(flags, CRTERA|CRTBS);
    347   1.1  christos 	if (ISSET(lflag, ECHOKE))
    348   1.1  christos 		SET(flags, CRTKIL|CRTBS);
    349   1.1  christos 	if (ISSET(lflag, ECHOPRT))
    350   1.1  christos 		SET(flags, PRTERA);
    351   1.1  christos 	if (ISSET(lflag, ECHOCTL))
    352   1.1  christos 		SET(flags, CTLECH);
    353   1.1  christos 	if (!ISSET(iflag, IXANY))
    354   1.1  christos 		SET(flags, DECCTQ);
    355   1.1  christos 	SET(flags, ISSET(lflag, ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH));
    356   1.1  christos 	if (ttydebug)
    357   1.7  christos 		printf("getflags: %x\n", flags);
    358   1.1  christos 	return (flags);
    359   1.1  christos }
    360   1.1  christos 
    361  1.25        ad static void
    362  1.24       dsl ttcompatsetflags(struct tty *tp, struct termios *t)
    363   1.1  christos {
    364  1.10  augustss 	int flags = tp->t_flags;
    365  1.25        ad 
    366  1.25        ad 	KASSERT(mutex_owned(&tty_lock));
    367  1.25        ad 
    368  1.10  augustss 	tcflag_t iflag = t->c_iflag;
    369  1.10  augustss 	tcflag_t oflag = t->c_oflag;
    370  1.10  augustss 	tcflag_t lflag = t->c_lflag;
    371  1.10  augustss 	tcflag_t cflag = t->c_cflag;
    372   1.1  christos 
    373   1.1  christos 	if (ISSET(flags, TANDEM))
    374   1.1  christos 		SET(iflag, IXOFF);
    375   1.1  christos 	else
    376   1.1  christos 		CLR(iflag, IXOFF);
    377   1.1  christos 	if (ISSET(flags, ECHO))
    378   1.1  christos 		SET(lflag, ECHO);
    379   1.1  christos 	else
    380   1.1  christos 		CLR(lflag, ECHO);
    381   1.1  christos 	if (ISSET(flags, CRMOD)) {
    382   1.1  christos 		SET(iflag, ICRNL);
    383   1.1  christos 		SET(oflag, ONLCR);
    384   1.1  christos 	} else {
    385   1.1  christos 		CLR(iflag, ICRNL);
    386   1.1  christos 		CLR(oflag, ONLCR);
    387   1.1  christos 	}
    388   1.1  christos 	if (ISSET(flags, XTABS))
    389   1.1  christos 		SET(oflag, OXTABS);
    390   1.1  christos 	else
    391   1.1  christos 		CLR(oflag, OXTABS);
    392   1.1  christos 
    393   1.1  christos 
    394   1.1  christos 	if (ISSET(flags, RAW)) {
    395   1.1  christos 		iflag &= IXOFF;
    396   1.1  christos 		CLR(lflag, ISIG|ICANON|IEXTEN);
    397   1.1  christos 		CLR(cflag, PARENB);
    398   1.1  christos 	} else {
    399   1.1  christos 		SET(iflag, BRKINT|IXON|IMAXBEL);
    400   1.1  christos 		SET(lflag, ISIG|IEXTEN);
    401   1.1  christos 		if (ISSET(flags, CBREAK))
    402   1.1  christos 			CLR(lflag, ICANON);
    403   1.1  christos 		else
    404   1.1  christos 			SET(lflag, ICANON);
    405   1.1  christos 		switch (ISSET(flags, ANYP)) {
    406   1.1  christos 		case 0:
    407   1.1  christos 			CLR(cflag, PARENB);
    408   1.1  christos 			break;
    409   1.1  christos 		case ANYP:
    410   1.1  christos 			SET(cflag, PARENB);
    411   1.1  christos 			CLR(iflag, INPCK);
    412   1.1  christos 			break;
    413   1.1  christos 		case EVENP:
    414   1.1  christos 			SET(cflag, PARENB);
    415   1.1  christos 			SET(iflag, INPCK);
    416   1.1  christos 			CLR(cflag, PARODD);
    417   1.1  christos 			break;
    418   1.1  christos 		case ODDP:
    419   1.1  christos 			SET(cflag, PARENB);
    420   1.1  christos 			SET(iflag, INPCK);
    421   1.1  christos 			SET(cflag, PARODD);
    422   1.1  christos 			break;
    423   1.1  christos 		}
    424   1.1  christos 	}
    425   1.1  christos 
    426   1.1  christos 	if (ISSET(flags, RAW|LITOUT|PASS8)) {
    427   1.1  christos 		CLR(cflag, CSIZE);
    428   1.1  christos 		SET(cflag, CS8);
    429   1.1  christos 		if (!ISSET(flags, RAW|PASS8))
    430   1.1  christos 			SET(iflag, ISTRIP);
    431   1.1  christos 		else
    432   1.1  christos 			CLR(iflag, ISTRIP);
    433   1.1  christos 		if (!ISSET(flags, RAW|LITOUT))
    434   1.1  christos 			SET(oflag, OPOST);
    435   1.1  christos 		else
    436   1.1  christos 			CLR(oflag, OPOST);
    437   1.1  christos 	} else {
    438   1.1  christos 		CLR(cflag, CSIZE);
    439   1.1  christos 		SET(cflag, CS7);
    440   1.1  christos 		SET(iflag, ISTRIP);
    441   1.1  christos 		SET(oflag, OPOST);
    442   1.1  christos 	}
    443   1.1  christos 
    444   1.1  christos 	t->c_iflag = iflag;
    445   1.1  christos 	t->c_oflag = oflag;
    446   1.1  christos 	t->c_lflag = lflag;
    447   1.1  christos 	t->c_cflag = cflag;
    448   1.1  christos }
    449   1.1  christos 
    450  1.25        ad static void
    451  1.24       dsl ttcompatsetlflags(struct tty *tp, struct termios *t)
    452   1.1  christos {
    453  1.10  augustss 	int flags = tp->t_flags;
    454  1.10  augustss 	tcflag_t iflag = t->c_iflag;
    455  1.10  augustss 	tcflag_t oflag = t->c_oflag;
    456  1.10  augustss 	tcflag_t lflag = t->c_lflag;
    457  1.10  augustss 	tcflag_t cflag = t->c_cflag;
    458   1.1  christos 
    459  1.25        ad 	KASSERT(mutex_owned(&tty_lock));
    460  1.25        ad 
    461   1.1  christos 	/* Nothing we can do with CRTBS. */
    462   1.1  christos 	if (ISSET(flags, PRTERA))
    463   1.1  christos 		SET(lflag, ECHOPRT);
    464   1.1  christos 	else
    465   1.1  christos 		CLR(lflag, ECHOPRT);
    466   1.1  christos 	if (ISSET(flags, CRTERA))
    467   1.1  christos 		SET(lflag, ECHOE);
    468   1.1  christos 	else
    469   1.1  christos 		CLR(lflag, ECHOE);
    470   1.1  christos 	/* Nothing we can do with TILDE. */
    471   1.1  christos 	if (ISSET(flags, MDMBUF))
    472   1.1  christos 		SET(cflag, MDMBUF);
    473   1.1  christos 	else
    474   1.1  christos 		CLR(cflag, MDMBUF);
    475   1.1  christos 	if (ISSET(flags, NOHANG))
    476   1.1  christos 		CLR(cflag, HUPCL);
    477   1.1  christos 	else
    478   1.1  christos 		SET(cflag, HUPCL);
    479   1.1  christos 	if (ISSET(flags, CRTKIL))
    480   1.1  christos 		SET(lflag, ECHOKE);
    481   1.1  christos 	else
    482   1.1  christos 		CLR(lflag, ECHOKE);
    483   1.1  christos 	if (ISSET(flags, CTLECH))
    484   1.1  christos 		SET(lflag, ECHOCTL);
    485   1.1  christos 	else
    486   1.1  christos 		CLR(lflag, ECHOCTL);
    487   1.1  christos 	if (!ISSET(flags, DECCTQ))
    488   1.1  christos 		SET(iflag, IXANY);
    489   1.1  christos 	else
    490   1.1  christos 		CLR(iflag, IXANY);
    491   1.1  christos 	CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH);
    492   1.1  christos 	SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
    493   1.1  christos 
    494   1.1  christos 	if (ISSET(flags, RAW|LITOUT|PASS8)) {
    495   1.1  christos 		CLR(cflag, CSIZE);
    496   1.1  christos 		SET(cflag, CS8);
    497   1.1  christos 		if (!ISSET(flags, RAW|PASS8))
    498   1.1  christos 			SET(iflag, ISTRIP);
    499   1.1  christos 		else
    500   1.1  christos 			CLR(iflag, ISTRIP);
    501   1.1  christos 		if (!ISSET(flags, RAW|LITOUT))
    502   1.1  christos 			SET(oflag, OPOST);
    503   1.1  christos 		else
    504   1.1  christos 			CLR(oflag, OPOST);
    505   1.1  christos 	} else {
    506   1.1  christos 		CLR(cflag, CSIZE);
    507   1.1  christos 		SET(cflag, CS7);
    508   1.1  christos 		SET(iflag, ISTRIP);
    509   1.1  christos 		SET(oflag, OPOST);
    510   1.1  christos 	}
    511   1.1  christos 
    512   1.1  christos 	t->c_iflag = iflag;
    513   1.1  christos 	t->c_oflag = oflag;
    514   1.1  christos 	t->c_lflag = lflag;
    515   1.1  christos 	t->c_cflag = cflag;
    516   1.1  christos }
    517  1.31  pgoyette 
    518  1.31  pgoyette int
    519  1.32  christos kern_tty_43_init(void)
    520  1.31  pgoyette {
    521  1.32  christos 	MODULE_SET_HOOK(compat_43_ttioctl_hook, "tty_43", compat_43_ttioctl);
    522  1.31  pgoyette 	return 0;
    523  1.31  pgoyette }
    524  1.31  pgoyette 
    525  1.31  pgoyette int
    526  1.32  christos kern_tty_43_fini(void)
    527  1.31  pgoyette {
    528  1.32  christos 	MODULE_UNSET_HOOK(compat_43_ttioctl_hook);
    529  1.31  pgoyette 	return 0;
    530  1.31  pgoyette }
    531