proc->thread stage 2: MAJOR revamping of system calls, ucred, jail API,
[dragonfly.git] / sys / emulation / svr4 / svr4_ioctl.c
CommitLineData
984263bc
MD
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 * $FreeBSD: src/sys/svr4/svr4_ioctl.c,v 1.6 1999/12/08 12:00:48 newton Exp $
41c20dac 29 * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ioctl.c,v 1.3 2003/06/23 17:55:49 dillon Exp $
984263bc
MD
30 */
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 <svr4/svr4.h>
42#include <svr4/svr4_types.h>
43#include <svr4/svr4_util.h>
44#include <svr4/svr4_signal.h>
45#include <svr4/svr4_proto.h>
46#include <svr4/svr4_stropts.h>
47#include <svr4/svr4_ioctl.h>
48#include <svr4/svr4_termios.h>
49#include <svr4/svr4_ttold.h>
50#include <svr4/svr4_filio.h>
51#include <svr4/svr4_sockio.h>
52
53#ifdef DEBUG_SVR4
54static void svr4_decode_cmd __P((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
41c20dac 82svr4_sys_ioctl(struct svr4_sys_ioctl_args *uap)
984263bc 83{
41c20dac 84 struct proc *p = curproc;
984263bc
MD
85 int *retval;
86 struct file *fp;
87 struct filedesc *fdp;
88 u_long cmd;
89 int (*fun) __P((struct file *, struct proc *, register_t *,
90 int, u_long, caddr_t));
91#ifdef DEBUG_SVR4
92 char dir[4];
93 char c;
94 int num;
95 int argsiz;
96
97 svr4_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz);
98
99 DPRINTF(("svr4_ioctl[%x](%d, _IO%s(%c, %d, %d), %p);\n", SCARG(uap, com), SCARG(uap, fd),
100 dir, c, num, argsiz, SCARG(uap, data)));
101#endif
102 retval = p->p_retval;
103 fdp = p->p_fd;
104 cmd = SCARG(uap, com);
105
106 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
107 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
108 return EBADF;
109
110 if ((fp->f_flag & (FREAD | FWRITE)) == 0)
111 return EBADF;
112
113#if defined(DEBUG_SVR4)
114 if (fp->f_type == DTYPE_SOCKET) {
115 struct socket *so = fp->f_data;
116 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state));
117 }
118#endif
119
120 switch (cmd & 0xff00) {
121 case SVR4_tIOC:
122 DPRINTF(("ttold\n"));
123 fun = svr4_ttold_ioctl;
124 break;
125
126 case SVR4_TIOC:
127 DPRINTF(("term\n"));
128 fun = svr4_term_ioctl;
129 break;
130
131 case SVR4_STR:
132 DPRINTF(("stream\n"));
133 fun = svr4_stream_ioctl;
134 break;
135
136 case SVR4_FIOC:
137 DPRINTF(("file\n"));
138 fun = svr4_fil_ioctl;
139 break;
140
141 case SVR4_SIOC:
142 DPRINTF(("socket\n"));
143 fun = svr4_sock_ioctl;
144 break;
145
146 case SVR4_XIOC:
147 /* We do not support those */
148 return EINVAL;
149
150 default:
151 DPRINTF(("Unimplemented ioctl %lx\n", cmd));
152 return 0; /* XXX: really ENOSYS */
153 }
154#if defined(DEBUG_SVR4)
155 if (fp->f_type == DTYPE_SOCKET) {
156 struct socket *so = fp->f_data;
157 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state));
158 }
159#endif
160 return (*fun)(fp, p, retval, SCARG(uap, fd), cmd, SCARG(uap, data));
161}