svr4_ioctl.c revision 43412
1/* 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1994 Christos Zoulas 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/param.h> 30#include <sys/proc.h> 31#include <sys/systm.h> 32#include <sys/file.h> 33#include <sys/filedesc.h> 34#include <sys/unistd.h> 35#include <sys/fcntl.h> 36#include <sys/termios.h> 37#include <sys/tty.h> 38#include <sys/socket.h> 39#include <sys/socketvar.h> 40#include <sys/mount.h> 41#include <net/if.h> 42#include <sys/malloc.h> 43 44#include <sys/sysproto.h> 45 46#include <svr4/svr4.h> 47#include <svr4/svr4_types.h> 48#include <svr4/svr4_util.h> 49#include <svr4/svr4_signal.h> 50#include <svr4/svr4_proto.h> 51#include <svr4/svr4_stropts.h> 52#include <svr4/svr4_ioctl.h> 53#include <svr4/svr4_termios.h> 54#include <svr4/svr4_ttold.h> 55#include <svr4/svr4_filio.h> 56#include <svr4/svr4_sockio.h> 57 58#ifdef DEBUG_SVR4 59static void svr4_decode_cmd __P((u_long, char *, char *, int *, int *)); 60/* 61 * Decode an ioctl command symbolically 62 */ 63static void 64svr4_decode_cmd(cmd, dir, c, num, argsiz) 65 u_long cmd; 66 char *dir, *c; 67 int *num, *argsiz; 68{ 69 if (cmd & SVR4_IOC_VOID) 70 *dir++ = 'V'; 71 if (cmd & SVR4_IOC_IN) 72 *dir++ = 'R'; 73 if (cmd & SVR4_IOC_OUT) 74 *dir++ = 'W'; 75 *dir = '\0'; 76 if (cmd & SVR4_IOC_INOUT) 77 *argsiz = (cmd >> 16) & 0xff; 78 else 79 *argsiz = -1; 80 81 *c = (cmd >> 8) & 0xff; 82 *num = cmd & 0xff; 83} 84#endif 85 86int 87svr4_sys_ioctl(p, uap) 88 register struct proc *p; 89 struct svr4_sys_ioctl_args *uap; 90{ 91 int *retval; 92 struct file *fp; 93 struct filedesc *fdp; 94 u_long cmd; 95 int (*fun) __P((struct file *, struct proc *, register_t *, 96 int, u_long, caddr_t)); 97#ifdef DEBUG_SVR4 98 char dir[4]; 99 char c; 100 int num; 101 int argsiz; 102 103 svr4_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz); 104 105 DPRINTF(("svr4_ioctl[%x](%d, _IO%s(%c, %d, %d), %p);\n", SCARG(uap, com), SCARG(uap, fd), 106 dir, c, num, argsiz, SCARG(uap, data))); 107#endif 108 retval = p->p_retval; 109 fdp = p->p_fd; 110 cmd = SCARG(uap, com); 111 112 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles || 113 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL) 114 return EBADF; 115 116 if ((fp->f_flag & (FREAD | FWRITE)) == 0) 117 return EBADF; 118 119#if defined(DEBUG_SVR4) 120 if (fp->f_type == DTYPE_SOCKET) { 121 struct socket *so = fp->f_data; 122 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state)); 123 } 124#endif 125 126 switch (cmd & 0xff00) { 127 case SVR4_tIOC: 128 DPRINTF(("ttold\n")); 129 fun = svr4_ttold_ioctl; 130 break; 131 132 case SVR4_TIOC: 133 DPRINTF(("term\n")); 134 fun = svr4_term_ioctl; 135 break; 136 137 case SVR4_STR: 138 DPRINTF(("stream\n")); 139 fun = svr4_stream_ioctl; 140 break; 141 142 case SVR4_FIOC: 143 DPRINTF(("file\n")); 144 fun = svr4_fil_ioctl; 145 break; 146 147 case SVR4_SIOC: 148 DPRINTF(("socket\n")); 149 fun = svr4_sock_ioctl; 150 break; 151 152 case SVR4_XIOC: 153 /* We do not support those */ 154 return EINVAL; 155 156 default: 157 DPRINTF(("Unimplemented ioctl %lx\n", cmd)); 158 return 0; /* XXX: really ENOSYS */ 159 } 160#if defined(DEBUG_SVR4) 161 if (fp->f_type == DTYPE_SOCKET) { 162 struct socket *so = fp->f_data; 163 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state)); 164 } 165#endif 166 return (*fun)(fp, p, retval, SCARG(uap, fd), cmd, SCARG(uap, data)); 167} 168