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/cdefs.h>
| 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/cdefs.h>
|
30__FBSDID("$FreeBSD: head/sys/compat/svr4/svr4_ioctl.c 116174 2003-06-10 21:44:29Z obrien $");
| 30__FBSDID("$FreeBSD: head/sys/compat/svr4/svr4_ioctl.c 130892 2004-06-21 22:57:16Z phk $");
|
31 32#include <sys/param.h> 33#include <sys/proc.h> 34#include <sys/file.h> 35#include <sys/filedesc.h> 36#include <sys/fcntl.h> 37#include <sys/socket.h> 38#include <sys/socketvar.h> 39#include <sys/systm.h> 40 41#include <compat/svr4/svr4.h> 42#include <compat/svr4/svr4_types.h> 43#include <compat/svr4/svr4_util.h> 44#include <compat/svr4/svr4_signal.h> 45#include <compat/svr4/svr4_proto.h> 46#include <compat/svr4/svr4_stropts.h> 47#include <compat/svr4/svr4_ioctl.h> 48#include <compat/svr4/svr4_termios.h> 49#include <compat/svr4/svr4_ttold.h> 50#include <compat/svr4/svr4_filio.h> 51#include <compat/svr4/svr4_sockio.h> 52 53#ifdef DEBUG_SVR4 54static void svr4_decode_cmd(u_long, char *, char *, int *, int *); 55/* 56 * Decode an ioctl command symbolically 57 */ 58static void 59svr4_decode_cmd(cmd, dir, c, num, argsiz) 60 u_long cmd; 61 char *dir, *c; 62 int *num, *argsiz; 63{ 64 if (cmd & SVR4_IOC_VOID) 65 *dir++ = 'V'; 66 if (cmd & SVR4_IOC_IN) 67 *dir++ = 'R'; 68 if (cmd & SVR4_IOC_OUT) 69 *dir++ = 'W'; 70 *dir = '\0'; 71 if (cmd & SVR4_IOC_INOUT) 72 *argsiz = (cmd >> 16) & 0xff; 73 else 74 *argsiz = -1; 75 76 *c = (cmd >> 8) & 0xff; 77 *num = cmd & 0xff; 78} 79#endif 80 81int 82svr4_sys_ioctl(td, uap) 83 register struct thread *td; 84 struct svr4_sys_ioctl_args *uap; 85{ 86 int *retval; 87 struct file *fp; 88 u_long cmd; 89 int (*fun)(struct file *, struct thread *, register_t *, 90 int, u_long, caddr_t); 91 int error; 92#ifdef DEBUG_SVR4 93 char dir[4]; 94 char c; 95 int num; 96 int argsiz; 97 98 svr4_decode_cmd(uap->com, dir, &c, &num, &argsiz); 99 100 DPRINTF(("svr4_ioctl[%lx](%d, _IO%s(%c, %d, %d), %p);\n", uap->com, uap->fd, 101 dir, c, num, argsiz, uap->data)); 102#endif 103 retval = td->td_retval; 104 cmd = uap->com; 105 106 if ((error = fget(td, uap->fd, &fp)) != 0) 107 return (error); 108 109 if ((fp->f_flag & (FREAD | FWRITE)) == 0) { 110 fdrop(fp, td); 111 return EBADF; 112 } 113 114#if defined(DEBUG_SVR4) 115 if (fp->f_type == DTYPE_SOCKET) { 116 struct socket *so = fp->f_data; 117 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state)); 118 } 119#endif 120 121 switch (cmd & 0xff00) {
| 31 32#include <sys/param.h> 33#include <sys/proc.h> 34#include <sys/file.h> 35#include <sys/filedesc.h> 36#include <sys/fcntl.h> 37#include <sys/socket.h> 38#include <sys/socketvar.h> 39#include <sys/systm.h> 40 41#include <compat/svr4/svr4.h> 42#include <compat/svr4/svr4_types.h> 43#include <compat/svr4/svr4_util.h> 44#include <compat/svr4/svr4_signal.h> 45#include <compat/svr4/svr4_proto.h> 46#include <compat/svr4/svr4_stropts.h> 47#include <compat/svr4/svr4_ioctl.h> 48#include <compat/svr4/svr4_termios.h> 49#include <compat/svr4/svr4_ttold.h> 50#include <compat/svr4/svr4_filio.h> 51#include <compat/svr4/svr4_sockio.h> 52 53#ifdef DEBUG_SVR4 54static void svr4_decode_cmd(u_long, char *, char *, int *, int *); 55/* 56 * Decode an ioctl command symbolically 57 */ 58static void 59svr4_decode_cmd(cmd, dir, c, num, argsiz) 60 u_long cmd; 61 char *dir, *c; 62 int *num, *argsiz; 63{ 64 if (cmd & SVR4_IOC_VOID) 65 *dir++ = 'V'; 66 if (cmd & SVR4_IOC_IN) 67 *dir++ = 'R'; 68 if (cmd & SVR4_IOC_OUT) 69 *dir++ = 'W'; 70 *dir = '\0'; 71 if (cmd & SVR4_IOC_INOUT) 72 *argsiz = (cmd >> 16) & 0xff; 73 else 74 *argsiz = -1; 75 76 *c = (cmd >> 8) & 0xff; 77 *num = cmd & 0xff; 78} 79#endif 80 81int 82svr4_sys_ioctl(td, uap) 83 register struct thread *td; 84 struct svr4_sys_ioctl_args *uap; 85{ 86 int *retval; 87 struct file *fp; 88 u_long cmd; 89 int (*fun)(struct file *, struct thread *, register_t *, 90 int, u_long, caddr_t); 91 int error; 92#ifdef DEBUG_SVR4 93 char dir[4]; 94 char c; 95 int num; 96 int argsiz; 97 98 svr4_decode_cmd(uap->com, dir, &c, &num, &argsiz); 99 100 DPRINTF(("svr4_ioctl[%lx](%d, _IO%s(%c, %d, %d), %p);\n", uap->com, uap->fd, 101 dir, c, num, argsiz, uap->data)); 102#endif 103 retval = td->td_retval; 104 cmd = uap->com; 105 106 if ((error = fget(td, uap->fd, &fp)) != 0) 107 return (error); 108 109 if ((fp->f_flag & (FREAD | FWRITE)) == 0) { 110 fdrop(fp, td); 111 return EBADF; 112 } 113 114#if defined(DEBUG_SVR4) 115 if (fp->f_type == DTYPE_SOCKET) { 116 struct socket *so = fp->f_data; 117 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state)); 118 } 119#endif 120 121 switch (cmd & 0xff00) {
|
| 122#ifndef BURN_BRIDGES
|
122 case SVR4_tIOC: 123 DPRINTF(("ttold\n")); 124 fun = svr4_ttold_ioctl; 125 break;
| 123 case SVR4_tIOC: 124 DPRINTF(("ttold\n")); 125 fun = svr4_ttold_ioctl; 126 break;
|
| 127#endif
|
126 127 case SVR4_TIOC: 128 DPRINTF(("term\n")); 129 fun = svr4_term_ioctl; 130 break; 131 132 case SVR4_STR: 133 DPRINTF(("stream\n")); 134 fun = svr4_stream_ioctl; 135 break; 136 137 case SVR4_FIOC: 138 DPRINTF(("file\n")); 139 fun = svr4_fil_ioctl; 140 break; 141 142 case SVR4_SIOC: 143 DPRINTF(("socket\n")); 144 fun = svr4_sock_ioctl; 145 break; 146 147 case SVR4_XIOC: 148 /* We do not support those */ 149 fdrop(fp, td); 150 return EINVAL; 151 152 default: 153 fdrop(fp, td); 154 DPRINTF(("Unimplemented ioctl %lx\n", cmd)); 155 return 0; /* XXX: really ENOSYS */ 156 } 157#if defined(DEBUG_SVR4) 158 if (fp->f_type == DTYPE_SOCKET) { 159 struct socket *so; 160 161 so = fp->f_data; 162 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state)); 163 } 164#endif 165 error = (*fun)(fp, td, retval, uap->fd, cmd, uap->data); 166 fdrop(fp, td); 167 return (error); 168}
| 128 129 case SVR4_TIOC: 130 DPRINTF(("term\n")); 131 fun = svr4_term_ioctl; 132 break; 133 134 case SVR4_STR: 135 DPRINTF(("stream\n")); 136 fun = svr4_stream_ioctl; 137 break; 138 139 case SVR4_FIOC: 140 DPRINTF(("file\n")); 141 fun = svr4_fil_ioctl; 142 break; 143 144 case SVR4_SIOC: 145 DPRINTF(("socket\n")); 146 fun = svr4_sock_ioctl; 147 break; 148 149 case SVR4_XIOC: 150 /* We do not support those */ 151 fdrop(fp, td); 152 return EINVAL; 153 154 default: 155 fdrop(fp, td); 156 DPRINTF(("Unimplemented ioctl %lx\n", cmd)); 157 return 0; /* XXX: really ENOSYS */ 158 } 159#if defined(DEBUG_SVR4) 160 if (fp->f_type == DTYPE_SOCKET) { 161 struct socket *so; 162 163 so = fp->f_data; 164 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state)); 165 } 166#endif 167 error = (*fun)(fp, td, retval, uap->fd, cmd, uap->data); 168 fdrop(fp, td); 169 return (error); 170}
|