2006-09-22 19:12:02 +04:00
|
|
|
/* $NetBSD: linux_termios.c,v 1.26 2006/09/22 15:12:02 christos Exp $ */
|
1998-10-01 07:36:27 +04:00
|
|
|
|
|
|
|
/*-
|
1998-10-04 04:02:23 +04:00
|
|
|
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
|
1998-10-01 07:36:27 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
1998-10-04 04:02:23 +04:00
|
|
|
* by Frank van der Linden and Eric Haszlakiewicz.
|
1998-10-01 07:36:27 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1996-03-08 07:55:59 +03:00
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2006-09-22 19:12:02 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: linux_termios.c,v 1.26 2006/09/22 15:12:02 christos Exp $");
|
2004-11-13 10:18:34 +03:00
|
|
|
|
|
|
|
#if defined(_KERNEL_OPT)
|
|
|
|
#include "opt_ptm.h"
|
|
|
|
#endif
|
2001-11-13 05:07:52 +03:00
|
|
|
|
1996-03-08 07:55:59 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/termios.h>
|
|
|
|
|
2003-01-19 00:21:28 +03:00
|
|
|
#include <sys/sa.h>
|
1996-03-08 07:55:59 +03:00
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
1998-10-04 00:17:36 +04:00
|
|
|
#include <compat/linux/common/linux_types.h>
|
|
|
|
#include <compat/linux/common/linux_ioctl.h>
|
|
|
|
#include <compat/linux/common/linux_signal.h>
|
|
|
|
#include <compat/linux/common/linux_util.h>
|
|
|
|
#include <compat/linux/common/linux_termios.h>
|
|
|
|
|
1996-03-08 07:55:59 +03:00
|
|
|
#include <compat/linux/linux_syscallargs.h>
|
|
|
|
|
2006-09-22 19:12:02 +04:00
|
|
|
#ifdef DEBUG_LINUX
|
|
|
|
#define DPRINTF(a) uprintf a
|
|
|
|
#else
|
|
|
|
#define DPRINTF(a)
|
|
|
|
#endif
|
|
|
|
|
1996-03-08 07:55:59 +03:00
|
|
|
int
|
2005-12-11 15:16:03 +03:00
|
|
|
linux_ioctl_termios(l, uap, retval)
|
|
|
|
struct lwp *l;
|
2000-03-30 15:24:16 +04:00
|
|
|
struct linux_sys_ioctl_args /* {
|
1996-03-08 07:55:59 +03:00
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(u_long) com;
|
|
|
|
syscallarg(caddr_t) data;
|
|
|
|
} */ *uap;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
2000-03-30 15:24:16 +04:00
|
|
|
struct file *fp;
|
|
|
|
struct filedesc *fdp;
|
1996-03-08 07:55:59 +03:00
|
|
|
u_long com;
|
|
|
|
struct linux_termio tmplt;
|
|
|
|
struct linux_termios tmplts;
|
|
|
|
struct termios tmpbts;
|
|
|
|
int idat;
|
|
|
|
struct sys_ioctl_args ia;
|
|
|
|
int error;
|
2000-12-10 17:12:16 +03:00
|
|
|
char tioclinux;
|
2005-12-11 15:16:03 +03:00
|
|
|
int (*bsdioctl)(struct file *, u_long, void *, struct lwp *);
|
1996-03-08 07:55:59 +03:00
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
fdp = l->l_proc->p_fd;
|
2001-06-15 00:32:41 +04:00
|
|
|
if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
|
1996-03-08 07:55:59 +03:00
|
|
|
return (EBADF);
|
|
|
|
|
2003-02-27 19:04:15 +03:00
|
|
|
if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
|
|
|
|
error = EBADF;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE_USE(fp);
|
1996-03-08 07:55:59 +03:00
|
|
|
|
2001-02-03 22:01:29 +03:00
|
|
|
bsdioctl = fp->f_ops->fo_ioctl;
|
1996-03-08 07:55:59 +03:00
|
|
|
com = SCARG(uap, com);
|
|
|
|
retval[0] = 0;
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2004-11-13 10:18:34 +03:00
|
|
|
switch (com & 0xffff) {
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TCGETS:
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCGETA, (caddr_t)&tmpbts, l);
|
1996-03-08 07:55:59 +03:00
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
bsd_termios_to_linux_termios(&tmpbts, &tmplts);
|
|
|
|
error = copyout(&tmplts, SCARG(uap, data), sizeof tmplts);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TCSETS:
|
|
|
|
case LINUX_TCSETSW:
|
|
|
|
case LINUX_TCSETSF:
|
|
|
|
/*
|
|
|
|
* First fill in all fields, so that we keep the current
|
|
|
|
* values for fields that Linux doesn't know about.
|
|
|
|
*/
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCGETA, (caddr_t)&tmpbts, l);
|
1996-03-08 07:55:59 +03:00
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
error = copyin(SCARG(uap, data), &tmplts, sizeof tmplts);
|
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
linux_termios_to_bsd_termios(&tmplts, &tmpbts);
|
|
|
|
switch (com) {
|
|
|
|
case LINUX_TCSETS:
|
|
|
|
com = TIOCSETA;
|
|
|
|
break;
|
|
|
|
case LINUX_TCSETSW:
|
|
|
|
com = TIOCSETAW;
|
|
|
|
break;
|
|
|
|
case LINUX_TCSETSF:
|
|
|
|
com = TIOCSETAF;
|
|
|
|
break;
|
|
|
|
}
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, com, (caddr_t)&tmpbts, l);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TCGETA:
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCGETA, (caddr_t)&tmpbts, l);
|
1996-03-08 07:55:59 +03:00
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
bsd_termios_to_linux_termio(&tmpbts, &tmplt);
|
|
|
|
error = copyout(&tmplt, SCARG(uap, data), sizeof tmplt);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TCSETA:
|
|
|
|
case LINUX_TCSETAW:
|
|
|
|
case LINUX_TCSETAF:
|
|
|
|
/*
|
|
|
|
* First fill in all fields, so that we keep the current
|
|
|
|
* values for fields that Linux doesn't know about.
|
|
|
|
*/
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCGETA, (caddr_t)&tmpbts, l);
|
1996-03-08 07:55:59 +03:00
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
error = copyin(SCARG(uap, data), &tmplt, sizeof tmplt);
|
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
linux_termio_to_bsd_termios(&tmplt, &tmpbts);
|
|
|
|
switch (com) {
|
|
|
|
case LINUX_TCSETA:
|
|
|
|
com = TIOCSETA;
|
|
|
|
break;
|
|
|
|
case LINUX_TCSETAW:
|
|
|
|
com = TIOCSETAW;
|
|
|
|
break;
|
|
|
|
case LINUX_TCSETAF:
|
|
|
|
com = TIOCSETAF;
|
|
|
|
break;
|
|
|
|
}
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, com, (caddr_t)&tmpbts, l);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
2001-02-03 22:01:29 +03:00
|
|
|
case LINUX_TCFLSH:
|
2001-02-05 07:33:41 +03:00
|
|
|
switch((u_long)SCARG(uap, data)) {
|
2001-02-03 22:01:29 +03:00
|
|
|
case 0:
|
|
|
|
idat = FREAD;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
idat = FWRITE;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
idat = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2003-02-27 19:04:15 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
2001-02-03 22:01:29 +03:00
|
|
|
}
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCFLUSH, (caddr_t)&idat, l);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TIOCGETD:
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCGETD, (caddr_t)&idat, l);
|
1996-03-08 07:55:59 +03:00
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
switch (idat) {
|
|
|
|
case TTYDISC:
|
|
|
|
idat = LINUX_N_TTY;
|
|
|
|
break;
|
|
|
|
case SLIPDISC:
|
|
|
|
idat = LINUX_N_SLIP;
|
|
|
|
break;
|
|
|
|
case PPPDISC:
|
|
|
|
idat = LINUX_N_PPP;
|
|
|
|
break;
|
1998-10-01 07:36:27 +04:00
|
|
|
case STRIPDISC:
|
|
|
|
idat = LINUX_N_STRIP;
|
|
|
|
break;
|
1996-03-08 07:55:59 +03:00
|
|
|
/*
|
|
|
|
* Linux does not have the tablet line discipline.
|
|
|
|
*/
|
|
|
|
case TABLDISC:
|
|
|
|
default:
|
|
|
|
idat = -1; /* XXX What should this be? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = copyout(&idat, SCARG(uap, data), sizeof idat);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TIOCSETD:
|
|
|
|
error = copyin(SCARG(uap, data), &idat, sizeof idat);
|
|
|
|
if (error)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
switch (idat) {
|
|
|
|
case LINUX_N_TTY:
|
|
|
|
idat = TTYDISC;
|
|
|
|
break;
|
|
|
|
case LINUX_N_SLIP:
|
|
|
|
idat = SLIPDISC;
|
|
|
|
break;
|
|
|
|
case LINUX_N_PPP:
|
|
|
|
idat = PPPDISC;
|
|
|
|
break;
|
1998-10-01 07:36:27 +04:00
|
|
|
case LINUX_N_STRIP:
|
|
|
|
idat = STRIPDISC;
|
|
|
|
break;
|
1996-03-08 07:55:59 +03:00
|
|
|
/*
|
|
|
|
* We can't handle the mouse line discipline Linux has.
|
|
|
|
*/
|
|
|
|
case LINUX_N_MOUSE:
|
1998-10-01 07:36:27 +04:00
|
|
|
case LINUX_N_AX25:
|
|
|
|
case LINUX_N_X25:
|
|
|
|
case LINUX_N_6PACK:
|
1996-03-08 07:55:59 +03:00
|
|
|
default:
|
2003-02-27 19:04:15 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
}
|
2005-12-11 15:16:03 +03:00
|
|
|
error = (*bsdioctl)(fp, TIOCSETD, (caddr_t)&idat, l);
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
2000-12-10 17:12:16 +03:00
|
|
|
case LINUX_TIOCLINUX:
|
|
|
|
error = copyin(SCARG(uap, data), &tioclinux, sizeof tioclinux);
|
|
|
|
if (error != 0)
|
2003-02-27 19:04:15 +03:00
|
|
|
goto out;
|
2000-12-10 17:12:16 +03:00
|
|
|
switch (tioclinux) {
|
|
|
|
case LINUX_TIOCLINUX_KERNMSG:
|
|
|
|
/*
|
|
|
|
* XXX needed to not fail for some things. Could
|
|
|
|
* try to use TIOCCONS, but the char argument
|
|
|
|
* specifies the VT #, not an fd.
|
|
|
|
*/
|
2003-02-27 19:04:15 +03:00
|
|
|
error = 0;
|
|
|
|
goto out;
|
2000-12-10 17:12:16 +03:00
|
|
|
case LINUX_TIOCLINUX_COPY:
|
|
|
|
case LINUX_TIOCLINUX_PASTE:
|
|
|
|
case LINUX_TIOCLINUX_UNBLANK:
|
|
|
|
case LINUX_TIOCLINUX_LOADLUT:
|
|
|
|
case LINUX_TIOCLINUX_READSHIFT:
|
|
|
|
case LINUX_TIOCLINUX_READMOUSE:
|
|
|
|
case LINUX_TIOCLINUX_VESABLANK:
|
|
|
|
case LINUX_TIOCLINUX_CURCONS: /* could use VT_GETACTIVE */
|
2003-02-27 19:04:15 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
2000-12-10 17:12:16 +03:00
|
|
|
}
|
|
|
|
break;
|
1996-03-08 07:55:59 +03:00
|
|
|
case LINUX_TIOCGWINSZ:
|
|
|
|
SCARG(&ia, com) = TIOCGWINSZ;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCSWINSZ:
|
|
|
|
SCARG(&ia, com) = TIOCSWINSZ;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCGPGRP:
|
|
|
|
SCARG(&ia, com) = TIOCGPGRP;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCSPGRP:
|
|
|
|
SCARG(&ia, com) = TIOCSPGRP;
|
|
|
|
break;
|
|
|
|
case LINUX_FIONREAD:
|
|
|
|
SCARG(&ia, com) = FIONREAD;
|
|
|
|
break;
|
|
|
|
case LINUX_FIONBIO:
|
|
|
|
SCARG(&ia, com) = FIONBIO;
|
|
|
|
break;
|
|
|
|
case LINUX_FIOASYNC:
|
|
|
|
SCARG(&ia, com) = FIOASYNC;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCEXCL:
|
|
|
|
SCARG(&ia, com) = TIOCEXCL;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCNXCL:
|
|
|
|
SCARG(&ia, com) = TIOCNXCL;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCCONS:
|
|
|
|
SCARG(&ia, com) = TIOCCONS;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCNOTTY:
|
|
|
|
SCARG(&ia, com) = TIOCNOTTY;
|
|
|
|
break;
|
2001-12-19 18:20:16 +03:00
|
|
|
case LINUX_TCSBRK:
|
|
|
|
SCARG(&ia, com) = SCARG(uap, data) ? TIOCDRAIN : TIOCSBRK;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCMGET:
|
|
|
|
SCARG(&ia, com) = TIOCMGET;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCMSET:
|
|
|
|
SCARG(&ia, com) = TIOCMSET;
|
|
|
|
break;
|
2005-10-24 16:58:34 +04:00
|
|
|
case LINUX_TIOCMBIC:
|
|
|
|
SCARG(&ia, com) = TIOCMBIC;
|
|
|
|
break;
|
|
|
|
case LINUX_TIOCMBIS:
|
|
|
|
SCARG(&ia, com) = TIOCMBIS;
|
|
|
|
break;
|
2004-11-13 10:18:34 +03:00
|
|
|
#ifdef LINUX_TIOCGPTN
|
|
|
|
case LINUX_TIOCGPTN:
|
|
|
|
#ifndef NO_DEV_PTM
|
|
|
|
{
|
2005-12-11 15:16:03 +03:00
|
|
|
caddr_t sg = stackgap_init(l->l_proc, 0);
|
|
|
|
struct ptmget ptm, *ptmp = stackgap_alloc(l->l_proc, &sg,
|
2004-11-13 10:18:34 +03:00
|
|
|
sizeof(*ptmp));
|
|
|
|
|
|
|
|
SCARG(&ia, fd) = SCARG(uap, fd);
|
|
|
|
SCARG(&ia, com) = TIOCPTSNAME;
|
|
|
|
SCARG(&ia, data) = ptmp;
|
|
|
|
|
|
|
|
if ((error = sys_ioctl(curlwp, &ia, retval)) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if ((error = copyin(ptmp, &ptm, sizeof(ptm))) != 0)
|
|
|
|
printf("copyin %d\n", error);
|
|
|
|
|
|
|
|
error = copyout(&ptm.sfd, SCARG(uap, data),
|
|
|
|
sizeof(ptm.sfd));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif /* NO_DEV_PTM */
|
|
|
|
#endif /* LINUX_TIOCGPTN */
|
2006-09-22 19:12:02 +04:00
|
|
|
#ifdef LINUX_TIOCSPTLCK
|
|
|
|
case LINUX_TIOCSPTLCK:
|
|
|
|
FILE_UNUSE(fp, l);
|
|
|
|
error = copyin(SCARG(uap, data), &idat, sizeof(idat));
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
DPRINTF(("TIOCSPTLCK %d\n", idat));
|
|
|
|
return 0;
|
|
|
|
#endif
|
1996-03-08 07:55:59 +03:00
|
|
|
default:
|
2003-02-27 19:04:15 +03:00
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
1996-03-08 07:55:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SCARG(&ia, fd) = SCARG(uap, fd);
|
|
|
|
SCARG(&ia, data) = SCARG(uap, data);
|
2003-01-19 00:21:28 +03:00
|
|
|
/* XXX NJWLWP */
|
2003-02-27 19:04:15 +03:00
|
|
|
error = sys_ioctl(curlwp, &ia, retval);
|
|
|
|
out:
|
2005-12-11 15:16:03 +03:00
|
|
|
FILE_UNUSE(fp, l);
|
2003-02-27 19:04:15 +03:00
|
|
|
return error;
|
1996-03-08 07:55:59 +03:00
|
|
|
}
|