2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/capability.h>
36 #include <sys/filedesc.h>
37 #include <sys/fcntl.h>
38 #include <sys/socket.h>
39 #include <sys/socketvar.h>
40 #include <sys/systm.h>
42 #include <compat/svr4/svr4.h>
43 #include <compat/svr4/svr4_types.h>
44 #include <compat/svr4/svr4_util.h>
45 #include <compat/svr4/svr4_signal.h>
46 #include <compat/svr4/svr4_proto.h>
47 #include <compat/svr4/svr4_stropts.h>
48 #include <compat/svr4/svr4_ioctl.h>
49 #include <compat/svr4/svr4_termios.h>
50 #include <compat/svr4/svr4_filio.h>
51 #include <compat/svr4/svr4_sockio.h>
54 static void svr4_decode_cmd(u_long, char *, char *, int *, int *);
56 * Decode an ioctl command symbolically
59 svr4_decode_cmd(cmd, dir, c, num, argsiz)
64 if (cmd & SVR4_IOC_VOID)
66 if (cmd & SVR4_IOC_IN)
68 if (cmd & SVR4_IOC_OUT)
71 if (cmd & SVR4_IOC_INOUT)
72 *argsiz = (cmd >> 16) & 0xff;
76 *c = (cmd >> 8) & 0xff;
82 svr4_sys_ioctl(td, uap)
84 struct svr4_sys_ioctl_args *uap;
90 int (*fun)(struct file *, struct thread *, register_t *,
91 int, u_long, caddr_t);
99 svr4_decode_cmd(uap->com, dir, &c, &num, &argsiz);
101 DPRINTF(("svr4_ioctl[%lx](%d, _IO%s(%c, %d, %d), %p);\n", uap->com, uap->fd,
102 dir, c, num, argsiz, uap->data));
104 retval = td->td_retval;
107 error = fget(td, uap->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
111 if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
116 #if defined(DEBUG_SVR4)
117 if (fp->f_type == DTYPE_SOCKET) {
118 struct socket *so = fp->f_data;
119 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state));
123 switch (cmd & 0xff00) {
126 fun = svr4_term_ioctl;
130 DPRINTF(("stream\n"));
131 fun = svr4_stream_ioctl;
136 fun = svr4_fil_ioctl;
140 DPRINTF(("socket\n"));
141 fun = svr4_sock_ioctl;
145 /* We do not support those */
151 DPRINTF(("Unimplemented ioctl %lx\n", cmd));
152 return 0; /* XXX: really ENOSYS */
154 #if defined(DEBUG_SVR4)
155 if (fp->f_type == DTYPE_SOCKET) {
159 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state));
162 error = (*fun)(fp, td, retval, uap->fd, cmd, uap->data);