svr4_ioctl.c revision 193014
1139743Simp/*- 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 29116174Sobrien#include <sys/cdefs.h> 30116174Sobrien__FBSDID("$FreeBSD: head/sys/compat/svr4/svr4_ioctl.c 193014 2009-05-29 05:58:46Z delphij $"); 31116174Sobrien 3243412Snewton#include <sys/param.h> 3397658Stanimura#include <sys/proc.h> 3443412Snewton#include <sys/file.h> 3543412Snewton#include <sys/filedesc.h> 3697658Stanimura#include <sys/fcntl.h> 3743412Snewton#include <sys/socket.h> 3854300Snewton#include <sys/socketvar.h> 3954300Snewton#include <sys/systm.h> 4043412Snewton 4165302Sobrien#include <compat/svr4/svr4.h> 4265302Sobrien#include <compat/svr4/svr4_types.h> 4365302Sobrien#include <compat/svr4/svr4_util.h> 4465302Sobrien#include <compat/svr4/svr4_signal.h> 4565302Sobrien#include <compat/svr4/svr4_proto.h> 4665302Sobrien#include <compat/svr4/svr4_stropts.h> 4765302Sobrien#include <compat/svr4/svr4_ioctl.h> 4865302Sobrien#include <compat/svr4/svr4_termios.h> 4965302Sobrien#include <compat/svr4/svr4_filio.h> 5065302Sobrien#include <compat/svr4/svr4_sockio.h> 5143412Snewton 5243412Snewton#ifdef DEBUG_SVR4 5392761Salfredstatic void svr4_decode_cmd(u_long, char *, char *, int *, int *); 5443412Snewton/* 5543412Snewton * Decode an ioctl command symbolically 5643412Snewton */ 5743412Snewtonstatic void 5843412Snewtonsvr4_decode_cmd(cmd, dir, c, num, argsiz) 5943412Snewton u_long cmd; 6043412Snewton char *dir, *c; 6143412Snewton int *num, *argsiz; 6243412Snewton{ 6343412Snewton if (cmd & SVR4_IOC_VOID) 6443412Snewton *dir++ = 'V'; 6543412Snewton if (cmd & SVR4_IOC_IN) 6643412Snewton *dir++ = 'R'; 6743412Snewton if (cmd & SVR4_IOC_OUT) 6843412Snewton *dir++ = 'W'; 6943412Snewton *dir = '\0'; 7043412Snewton if (cmd & SVR4_IOC_INOUT) 7143412Snewton *argsiz = (cmd >> 16) & 0xff; 7243412Snewton else 7343412Snewton *argsiz = -1; 7443412Snewton 7543412Snewton *c = (cmd >> 8) & 0xff; 7643412Snewton *num = cmd & 0xff; 7743412Snewton} 7843412Snewton#endif 7943412Snewton 8043412Snewtonint 8183366Sjuliansvr4_sys_ioctl(td, uap) 82193014Sdelphij struct thread *td; 8343412Snewton struct svr4_sys_ioctl_args *uap; 8443412Snewton{ 8543412Snewton int *retval; 8643412Snewton struct file *fp; 8743412Snewton u_long cmd; 8892761Salfred int (*fun)(struct file *, struct thread *, register_t *, 8992761Salfred int, u_long, caddr_t); 9089306Salfred int error; 9143412Snewton#ifdef DEBUG_SVR4 9243412Snewton char dir[4]; 9343412Snewton char c; 9443412Snewton int num; 9543412Snewton int argsiz; 9643412Snewton 97107849Salfred svr4_decode_cmd(uap->com, dir, &c, &num, &argsiz); 9843412Snewton 99107849Salfred DPRINTF(("svr4_ioctl[%lx](%d, _IO%s(%c, %d, %d), %p);\n", uap->com, uap->fd, 100107849Salfred dir, c, num, argsiz, uap->data)); 10143412Snewton#endif 10283366Sjulian retval = td->td_retval; 103107849Salfred cmd = uap->com; 10443412Snewton 10589319Salfred if ((error = fget(td, uap->fd, &fp)) != 0) 10689319Salfred return (error); 10743412Snewton 10889306Salfred if ((fp->f_flag & (FREAD | FWRITE)) == 0) { 10989306Salfred fdrop(fp, td); 11043412Snewton return EBADF; 11189306Salfred } 11243412Snewton 11343412Snewton#if defined(DEBUG_SVR4) 11443412Snewton if (fp->f_type == DTYPE_SOCKET) { 115109153Sdillon struct socket *so = fp->f_data; 11697658Stanimura DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state)); 11743412Snewton } 11843412Snewton#endif 11943412Snewton 12043412Snewton switch (cmd & 0xff00) { 12143412Snewton case SVR4_TIOC: 12243412Snewton DPRINTF(("term\n")); 12343412Snewton fun = svr4_term_ioctl; 12443412Snewton break; 12543412Snewton 12643412Snewton case SVR4_STR: 12743412Snewton DPRINTF(("stream\n")); 12843412Snewton fun = svr4_stream_ioctl; 12943412Snewton break; 13043412Snewton 13143412Snewton case SVR4_FIOC: 13243412Snewton DPRINTF(("file\n")); 13343412Snewton fun = svr4_fil_ioctl; 13443412Snewton break; 13543412Snewton 13643412Snewton case SVR4_SIOC: 13743412Snewton DPRINTF(("socket\n")); 13843412Snewton fun = svr4_sock_ioctl; 13943412Snewton break; 14043412Snewton 14143412Snewton case SVR4_XIOC: 14243412Snewton /* We do not support those */ 14389306Salfred fdrop(fp, td); 14443412Snewton return EINVAL; 14543412Snewton 14643412Snewton default: 14789306Salfred fdrop(fp, td); 14843412Snewton DPRINTF(("Unimplemented ioctl %lx\n", cmd)); 14943412Snewton return 0; /* XXX: really ENOSYS */ 15043412Snewton } 15143412Snewton#if defined(DEBUG_SVR4) 15243412Snewton if (fp->f_type == DTYPE_SOCKET) { 15389306Salfred struct socket *so; 15489306Salfred 155109153Sdillon so = fp->f_data; 15697658Stanimura DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state)); 15743412Snewton } 15843412Snewton#endif 159107849Salfred error = (*fun)(fp, td, retval, uap->fd, cmd, uap->data); 16089306Salfred fdrop(fp, td); 16189306Salfred return (error); 16243412Snewton} 163