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