svr4_ioctl.c revision 43412
143412Snewton/* 243412Snewton * Copyright (c) 1998 Mark Newton 343412Snewton * Copyright (c) 1994 Christos Zoulas 443412Snewton * All rights reserved. 543412Snewton * 643412Snewton * Redistribution and use in source and binary forms, with or without 743412Snewton * modification, are permitted provided that the following conditions 843412Snewton * are met: 943412Snewton * 1. Redistributions of source code must retain the above copyright 1043412Snewton * notice, this list of conditions and the following disclaimer. 1143412Snewton * 2. Redistributions in binary form must reproduce the above copyright 1243412Snewton * notice, this list of conditions and the following disclaimer in the 1343412Snewton * documentation and/or other materials provided with the distribution. 1443412Snewton * 3. The name of the author may not be used to endorse or promote products 1543412Snewton * derived from this software without specific prior written permission 1643412Snewton * 1743412Snewton * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1843412Snewton * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1943412Snewton * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2043412Snewton * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2143412Snewton * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2243412Snewton * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2343412Snewton * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2443412Snewton * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2543412Snewton * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2643412Snewton * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2743412Snewton */ 2843412Snewton 2943412Snewton#include <sys/param.h> 3043412Snewton#include <sys/proc.h> 3143412Snewton#include <sys/systm.h> 3243412Snewton#include <sys/file.h> 3343412Snewton#include <sys/filedesc.h> 3443412Snewton#include <sys/unistd.h> 3543412Snewton#include <sys/fcntl.h> 3643412Snewton#include <sys/termios.h> 3743412Snewton#include <sys/tty.h> 3843412Snewton#include <sys/socket.h> 3943412Snewton#include <sys/socketvar.h> 4043412Snewton#include <sys/mount.h> 4143412Snewton#include <net/if.h> 4243412Snewton#include <sys/malloc.h> 4343412Snewton 4443412Snewton#include <sys/sysproto.h> 4543412Snewton 4643412Snewton#include <svr4/svr4.h> 4743412Snewton#include <svr4/svr4_types.h> 4843412Snewton#include <svr4/svr4_util.h> 4943412Snewton#include <svr4/svr4_signal.h> 5043412Snewton#include <svr4/svr4_proto.h> 5143412Snewton#include <svr4/svr4_stropts.h> 5243412Snewton#include <svr4/svr4_ioctl.h> 5343412Snewton#include <svr4/svr4_termios.h> 5443412Snewton#include <svr4/svr4_ttold.h> 5543412Snewton#include <svr4/svr4_filio.h> 5643412Snewton#include <svr4/svr4_sockio.h> 5743412Snewton 5843412Snewton#ifdef DEBUG_SVR4 5943412Snewtonstatic void svr4_decode_cmd __P((u_long, char *, char *, int *, int *)); 6043412Snewton/* 6143412Snewton * Decode an ioctl command symbolically 6243412Snewton */ 6343412Snewtonstatic void 6443412Snewtonsvr4_decode_cmd(cmd, dir, c, num, argsiz) 6543412Snewton u_long cmd; 6643412Snewton char *dir, *c; 6743412Snewton int *num, *argsiz; 6843412Snewton{ 6943412Snewton if (cmd & SVR4_IOC_VOID) 7043412Snewton *dir++ = 'V'; 7143412Snewton if (cmd & SVR4_IOC_IN) 7243412Snewton *dir++ = 'R'; 7343412Snewton if (cmd & SVR4_IOC_OUT) 7443412Snewton *dir++ = 'W'; 7543412Snewton *dir = '\0'; 7643412Snewton if (cmd & SVR4_IOC_INOUT) 7743412Snewton *argsiz = (cmd >> 16) & 0xff; 7843412Snewton else 7943412Snewton *argsiz = -1; 8043412Snewton 8143412Snewton *c = (cmd >> 8) & 0xff; 8243412Snewton *num = cmd & 0xff; 8343412Snewton} 8443412Snewton#endif 8543412Snewton 8643412Snewtonint 8743412Snewtonsvr4_sys_ioctl(p, uap) 8843412Snewton register struct proc *p; 8943412Snewton struct svr4_sys_ioctl_args *uap; 9043412Snewton{ 9143412Snewton int *retval; 9243412Snewton struct file *fp; 9343412Snewton struct filedesc *fdp; 9443412Snewton u_long cmd; 9543412Snewton int (*fun) __P((struct file *, struct proc *, register_t *, 9643412Snewton int, u_long, caddr_t)); 9743412Snewton#ifdef DEBUG_SVR4 9843412Snewton char dir[4]; 9943412Snewton char c; 10043412Snewton int num; 10143412Snewton int argsiz; 10243412Snewton 10343412Snewton svr4_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz); 10443412Snewton 10543412Snewton DPRINTF(("svr4_ioctl[%x](%d, _IO%s(%c, %d, %d), %p);\n", SCARG(uap, com), SCARG(uap, fd), 10643412Snewton dir, c, num, argsiz, SCARG(uap, data))); 10743412Snewton#endif 10843412Snewton retval = p->p_retval; 10943412Snewton fdp = p->p_fd; 11043412Snewton cmd = SCARG(uap, com); 11143412Snewton 11243412Snewton if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || 11343412Snewton (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) 11443412Snewton return EBADF; 11543412Snewton 11643412Snewton if ((fp->f_flag & (FREAD | FWRITE)) == 0) 11743412Snewton return EBADF; 11843412Snewton 11943412Snewton#if defined(DEBUG_SVR4) 12043412Snewton if (fp->f_type == DTYPE_SOCKET) { 12143412Snewton struct socket *so = fp->f_data; 12243412Snewton DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state)); 12343412Snewton } 12443412Snewton#endif 12543412Snewton 12643412Snewton switch (cmd & 0xff00) { 12743412Snewton case SVR4_tIOC: 12843412Snewton DPRINTF(("ttold\n")); 12943412Snewton fun = svr4_ttold_ioctl; 13043412Snewton break; 13143412Snewton 13243412Snewton case SVR4_TIOC: 13343412Snewton DPRINTF(("term\n")); 13443412Snewton fun = svr4_term_ioctl; 13543412Snewton break; 13643412Snewton 13743412Snewton case SVR4_STR: 13843412Snewton DPRINTF(("stream\n")); 13943412Snewton fun = svr4_stream_ioctl; 14043412Snewton break; 14143412Snewton 14243412Snewton case SVR4_FIOC: 14343412Snewton DPRINTF(("file\n")); 14443412Snewton fun = svr4_fil_ioctl; 14543412Snewton break; 14643412Snewton 14743412Snewton case SVR4_SIOC: 14843412Snewton DPRINTF(("socket\n")); 14943412Snewton fun = svr4_sock_ioctl; 15043412Snewton break; 15143412Snewton 15243412Snewton case SVR4_XIOC: 15343412Snewton /* We do not support those */ 15443412Snewton return EINVAL; 15543412Snewton 15643412Snewton default: 15743412Snewton DPRINTF(("Unimplemented ioctl %lx\n", cmd)); 15843412Snewton return 0; /* XXX: really ENOSYS */ 15943412Snewton } 16043412Snewton#if defined(DEBUG_SVR4) 16143412Snewton if (fp->f_type == DTYPE_SOCKET) { 16243412Snewton struct socket *so = fp->f_data; 16343412Snewton DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state)); 16443412Snewton } 16543412Snewton#endif 16643412Snewton return (*fun)(fp, p, retval, SCARG(uap, fd), cmd, SCARG(uap, data)); 16743412Snewton} 168