Home | History | Annotate | Line # | Download | only in sunos
sunos_ioctl.c revision 1.1
      1  1.1  deraadt /*
      2  1.1  deraadt  * Copyright (c) 1992, 1993
      3  1.1  deraadt  *	The Regents of the University of California.  All rights reserved.
      4  1.1  deraadt  *
      5  1.1  deraadt  * This software was developed by the Computer Systems Engineering group
      6  1.1  deraadt  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      7  1.1  deraadt  * contributed to Berkeley.
      8  1.1  deraadt  *
      9  1.1  deraadt  * All advertising materials mentioning features or use of this software
     10  1.1  deraadt  * must display the following acknowledgement:
     11  1.1  deraadt  *	This product includes software developed by the University of
     12  1.1  deraadt  *	California, Lawrence Berkeley Laboratory.
     13  1.1  deraadt  *
     14  1.1  deraadt  * Redistribution and use in source and binary forms, with or without
     15  1.1  deraadt  * modification, are permitted provided that the following conditions
     16  1.1  deraadt  * are met:
     17  1.1  deraadt  * 1. Redistributions of source code must retain the above copyright
     18  1.1  deraadt  *    notice, this list of conditions and the following disclaimer.
     19  1.1  deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     20  1.1  deraadt  *    notice, this list of conditions and the following disclaimer in the
     21  1.1  deraadt  *    documentation and/or other materials provided with the distribution.
     22  1.1  deraadt  * 3. All advertising materials mentioning features or use of this software
     23  1.1  deraadt  *    must display the following acknowledgement:
     24  1.1  deraadt  *	This product includes software developed by the University of
     25  1.1  deraadt  *	California, Berkeley and its contributors.
     26  1.1  deraadt  * 4. Neither the name of the University nor the names of its contributors
     27  1.1  deraadt  *    may be used to endorse or promote products derived from this software
     28  1.1  deraadt  *    without specific prior written permission.
     29  1.1  deraadt  *
     30  1.1  deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     31  1.1  deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     32  1.1  deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     33  1.1  deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     34  1.1  deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     35  1.1  deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     36  1.1  deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     37  1.1  deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     38  1.1  deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     39  1.1  deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     40  1.1  deraadt  * SUCH DAMAGE.
     41  1.1  deraadt  *
     42  1.1  deraadt  *	@(#)sun_ioctl.c	8.1 (Berkeley) 6/11/93
     43  1.1  deraadt  *
     44  1.1  deraadt  * from: Header: sun_ioctl.c,v 1.7 93/05/28 04:40:43 torek Exp
     45  1.1  deraadt  * $Id: sunos_ioctl.c,v 1.1 1993/10/02 10:24:39 deraadt Exp $
     46  1.1  deraadt  */
     47  1.1  deraadt 
     48  1.1  deraadt #include <sys/param.h>
     49  1.1  deraadt #include <sys/proc.h>
     50  1.1  deraadt #include <sys/file.h>
     51  1.1  deraadt #include <sys/filedesc.h>
     52  1.1  deraadt #include <sys/ioctl.h>
     53  1.1  deraadt #include <sys/termios.h>
     54  1.1  deraadt #include <sys/tty.h>
     55  1.1  deraadt 
     56  1.1  deraadt /*
     57  1.1  deraadt  * SunOS ioctl calls.
     58  1.1  deraadt  * This file is something of a hodge-podge.
     59  1.1  deraadt  * Support gets added as things turn up....
     60  1.1  deraadt  */
     61  1.1  deraadt 
     62  1.1  deraadt struct sun_ttysize {
     63  1.1  deraadt 	int	ts_row;
     64  1.1  deraadt 	int	ts_col;
     65  1.1  deraadt };
     66  1.1  deraadt 
     67  1.1  deraadt struct sun_termio {
     68  1.1  deraadt 	u_short	c_iflag;
     69  1.1  deraadt 	u_short	c_oflag;
     70  1.1  deraadt 	u_short	c_cflag;
     71  1.1  deraadt 	u_short	c_lflag;
     72  1.1  deraadt 	char	c_line;
     73  1.1  deraadt 	unsigned char c_cc[8];
     74  1.1  deraadt };
     75  1.1  deraadt 
     76  1.1  deraadt struct sun_ioctl_args {
     77  1.1  deraadt 	int	fd;
     78  1.1  deraadt 	int	cmd;
     79  1.1  deraadt 	caddr_t	data;
     80  1.1  deraadt };
     81  1.1  deraadt sun_ioctl(p, uap, retval)
     82  1.1  deraadt 	register struct proc *p;
     83  1.1  deraadt 	register struct sun_ioctl_args *uap;
     84  1.1  deraadt 	int *retval;
     85  1.1  deraadt {
     86  1.1  deraadt 	register struct filedesc *fdp = p->p_fd;
     87  1.1  deraadt 	register struct file *fp;
     88  1.1  deraadt 	register int (*ctl)();
     89  1.1  deraadt 	int error;
     90  1.1  deraadt 
     91  1.1  deraadt 	if ((unsigned)uap->fd >= fdp->fd_nfiles ||
     92  1.1  deraadt 	    (fp = fdp->fd_ofiles[uap->fd]) == NULL)
     93  1.1  deraadt 		return (EBADF);
     94  1.1  deraadt 	if ((fp->f_flag & (FREAD|FWRITE)) == 0)
     95  1.1  deraadt 		return (EBADF);
     96  1.1  deraadt 	ctl = fp->f_ops->fo_ioctl;
     97  1.1  deraadt 
     98  1.1  deraadt 	switch (uap->cmd) {
     99  1.1  deraadt 
    100  1.1  deraadt 	case _IOR('t', 0, int):
    101  1.1  deraadt 		uap->cmd = TIOCGETD;
    102  1.1  deraadt 		break;
    103  1.1  deraadt 
    104  1.1  deraadt 	case _IOW('t', 1, int):
    105  1.1  deraadt 		uap->cmd = TIOCSETD;
    106  1.1  deraadt 		break;
    107  1.1  deraadt 
    108  1.1  deraadt 	case _IO('t', 36): {		/* sun TIOCCONS, no parameters */
    109  1.1  deraadt 		int on = 1;
    110  1.1  deraadt 		return ((*ctl)(fp, TIOCCONS, (caddr_t)&on, p));
    111  1.1  deraadt 	    }
    112  1.1  deraadt 
    113  1.1  deraadt 	case _IOW('t', 37, struct sun_ttysize): {
    114  1.1  deraadt 		struct winsize ws;
    115  1.1  deraadt 		if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
    116  1.1  deraadt 			return (error);
    117  1.1  deraadt 		ws.ws_row = ((struct sun_ttysize *)uap->data)->ts_row;
    118  1.1  deraadt 		ws.ws_col = ((struct sun_ttysize *)uap->data)->ts_col;
    119  1.1  deraadt 		return ((*ctl)(fp, TIOCSWINSZ, (caddr_t)&ws, p));
    120  1.1  deraadt 	    }
    121  1.1  deraadt 
    122  1.1  deraadt 	case _IOW('t', 38, struct sun_ttysize): {
    123  1.1  deraadt 		struct winsize ws;
    124  1.1  deraadt 		if ((error = (*ctl)(fp, TIOCGWINSZ, (caddr_t)&ws, p)) != 0)
    125  1.1  deraadt 			return (error);
    126  1.1  deraadt 		((struct sun_ttysize *)uap->data)->ts_row = ws.ws_row;
    127  1.1  deraadt 		((struct sun_ttysize *)uap->data)->ts_col = ws.ws_col;
    128  1.1  deraadt 		return (0);
    129  1.1  deraadt 	    }
    130  1.1  deraadt 
    131  1.1  deraadt 	case _IOR('t', 130, int):
    132  1.1  deraadt 		uap->cmd = TIOCSPGRP;
    133  1.1  deraadt 		break;
    134  1.1  deraadt 
    135  1.1  deraadt 	case _IOR('t', 131, int):
    136  1.1  deraadt 		uap->cmd = TIOCGPGRP;
    137  1.1  deraadt 		break;
    138  1.1  deraadt 
    139  1.1  deraadt 	case _IO('t', 132):
    140  1.1  deraadt 		uap->cmd = TIOCSCTTY;
    141  1.1  deraadt 		break;
    142  1.1  deraadt 
    143  1.1  deraadt 	case _IOR('T', 1, struct sun_termio): {
    144  1.1  deraadt 		struct termios bt;
    145  1.1  deraadt 		struct sun_termio st;
    146  1.1  deraadt 		int speed;
    147  1.1  deraadt 		static struct speedtab sptab[] = {
    148  1.1  deraadt 			{ 0, 0 }, { 50, 1 }, { 75, 2 }, { 110, 3 },
    149  1.1  deraadt 			{ 134, 4 }, { 135, 4 }, { 150, 5 }, { 200, 6 },
    150  1.1  deraadt 			{ 300, 7 }, { 600, 8 }, { 1200, 9 }, { 1800, 10 },
    151  1.1  deraadt 			{ 2400, 11 }, { 4800, 12 }, { 9600, 13 },
    152  1.1  deraadt 			{ 19200, 14 }, { 38400, 15 }, { -1, -1 }
    153  1.1  deraadt 		};
    154  1.1  deraadt 
    155  1.1  deraadt 		if ((error = (*ctl)(fp, TIOCGETA, (caddr_t)&bt, p)) != 0)
    156  1.1  deraadt 			return (error);
    157  1.1  deraadt 		/* most bits match */
    158  1.1  deraadt 		st.c_iflag = bt.c_iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|
    159  1.1  deraadt 		    ISTRIP|INLCR|IGNCR|ICRNL|IXANY|IMAXBEL);
    160  1.1  deraadt 		if (bt.c_iflag & IXON)
    161  1.1  deraadt 			st.c_iflag |= 0x0400;
    162  1.1  deraadt 		if (bt.c_iflag & IXOFF)
    163  1.1  deraadt 			st.c_iflag |= 0x1000;
    164  1.1  deraadt 		st.c_oflag = bt.c_oflag & OPOST;
    165  1.1  deraadt 		if (bt.c_oflag & ONLCR)
    166  1.1  deraadt 			st.c_oflag |= 0x0004;
    167  1.1  deraadt 		if (bt.c_oflag & OXTABS)
    168  1.1  deraadt 			st.c_oflag |= 0x1800;
    169  1.1  deraadt 		speed = ttspeedtab(bt.c_ospeed, sptab);
    170  1.1  deraadt 		st.c_cflag = speed >= 0 ? speed : 0;
    171  1.1  deraadt 		st.c_cflag |= (bt.c_cflag & CSIZE) >> 4;
    172  1.1  deraadt 		if (bt.c_cflag & CSTOPB)
    173  1.1  deraadt 			st.c_cflag |= 0x40;
    174  1.1  deraadt 		if (bt.c_cflag & PARENB)
    175  1.1  deraadt 			st.c_cflag |= 0x100;
    176  1.1  deraadt 		if (bt.c_cflag & PARODD)
    177  1.1  deraadt 			st.c_cflag |= 0x200;
    178  1.1  deraadt 		if (bt.c_cflag & HUPCL)
    179  1.1  deraadt 			st.c_cflag |= 0x400;
    180  1.1  deraadt 		if (bt.c_cflag & CLOCAL)
    181  1.1  deraadt 			st.c_cflag |= 0x800;
    182  1.1  deraadt 		st.c_lflag = 0;
    183  1.1  deraadt 		if (bt.c_lflag & (ECHOKE|ECHOE|ECHOK))
    184  1.1  deraadt 			st.c_lflag |= 0x0800;
    185  1.1  deraadt 		if (bt.c_lflag & ECHO)
    186  1.1  deraadt 			st.c_lflag |= 0x0008;
    187  1.1  deraadt 		if (bt.c_lflag & ECHONL)
    188  1.1  deraadt 			st.c_lflag |= 0x0040;
    189  1.1  deraadt 		if (bt.c_lflag & ECHOPRT)
    190  1.1  deraadt 			st.c_lflag |= 0x0400;
    191  1.1  deraadt 		if (bt.c_lflag & ECHOCTL)
    192  1.1  deraadt 			st.c_lflag |= 0x0200;
    193  1.1  deraadt 		if (bt.c_lflag & ISIG)
    194  1.1  deraadt 			st.c_lflag |= 0x0001;
    195  1.1  deraadt 		if (bt.c_lflag & ICANON)
    196  1.1  deraadt 			st.c_lflag |= 0x0002;
    197  1.1  deraadt 		if (bt.c_lflag & IEXTEN)
    198  1.1  deraadt 			st.c_lflag |= 0x8000;
    199  1.1  deraadt 		if (bt.c_lflag & NOFLSH)
    200  1.1  deraadt 			st.c_lflag |= 0x0080;
    201  1.1  deraadt #define mapcc(x) ((x) == _POSIX_VDISABLE ? 0 : (x))
    202  1.1  deraadt 		st.c_cc[0] = mapcc(bt.c_cc[VINTR]);
    203  1.1  deraadt 		st.c_cc[1] = mapcc(bt.c_cc[VQUIT]);
    204  1.1  deraadt 		st.c_cc[2] = mapcc(bt.c_cc[VERASE]);
    205  1.1  deraadt 		st.c_cc[3] = mapcc(bt.c_cc[VKILL]);
    206  1.1  deraadt 		st.c_cc[4] = mapcc(bt.c_cc[VEOF]);
    207  1.1  deraadt 		st.c_cc[5] = mapcc(bt.c_cc[VEOL]);
    208  1.1  deraadt 		st.c_cc[6] = mapcc(bt.c_cc[VEOL2]);
    209  1.1  deraadt 		st.c_cc[7] = 0;
    210  1.1  deraadt 		return (copyout((caddr_t)&st, uap->data, sizeof(st)));
    211  1.1  deraadt 	    }
    212  1.1  deraadt 	}
    213  1.1  deraadt 	return (ioctl(p, uap, retval));
    214  1.1  deraadt }
    215