Remove so_gencnt and so_gen_t. The generation counter is not used any more.
[dragonfly.git] / sys / emulation / svr4 / svr4_ioctl.c
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 $
29  * $DragonFly: src/sys/emulation/svr4/Attic/svr4_ioctl.c,v 1.14 2006/05/20 02:42:05 dillon Exp $
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 <emulation/43bsd/43bsd_socket.h>
42
43 #include "svr4.h"
44 #include "svr4_types.h"
45 #include "svr4_util.h"
46 #include "svr4_signal.h"
47 #include "svr4_proto.h"
48 #include "svr4_stropts.h"
49 #include "svr4_ioctl.h"
50 #include "svr4_termios.h"
51 #include "svr4_ttold.h"
52 #include "svr4_filio.h"
53 #include "svr4_sockio.h"
54
55 #ifdef DEBUG_SVR4
56 static void svr4_decode_cmd (u_long, char *, char *, int *, int *);
57 /*
58  * Decode an ioctl command symbolically
59  */
60 static void
61 svr4_decode_cmd(cmd, dir, c, num, argsiz)
62         u_long            cmd;
63         char             *dir, *c;
64         int              *num, *argsiz;
65 {
66         if (cmd & SVR4_IOC_VOID)
67                 *dir++ = 'V';
68         if (cmd & SVR4_IOC_IN)
69                 *dir++ = 'R';
70         if (cmd & SVR4_IOC_OUT)
71                 *dir++ = 'W';
72         *dir = '\0';
73         if (cmd & SVR4_IOC_INOUT)
74                 *argsiz = (cmd >> 16) & 0xff;
75         else
76                 *argsiz = -1;
77
78         *c = (cmd >> 8) & 0xff;
79         *num = cmd & 0xff;
80 }
81 #endif
82
83 int
84 svr4_sys_ioctl(struct svr4_sys_ioctl_args *uap)
85 {
86         struct thread   *td = curthread;
87         struct proc     *p = td->td_proc;
88         int             *retval;
89         struct file     *fp;
90         u_long           cmd;
91         int (*fun) (struct file *, struct thread *, register_t *,
92                         int, u_long, caddr_t);
93         int              error;
94 #ifdef DEBUG_SVR4
95         char             dir[4];
96         char             c;
97         int              num;
98         int              argsiz;
99
100         KKASSERT(p);
101
102         svr4_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz);
103
104         DPRINTF(("svr4_ioctl[%lx](%d, _IO%s(%c, %d, %d), %p);\n",
105             SCARG(uap, com), SCARG(uap, fd),
106             dir, c, num, argsiz, SCARG(uap, data)));
107 #endif
108         retval = &uap->sysmsg_result;
109         cmd = SCARG(uap, com);
110
111         fp = holdfp(p->p_fd, SCARG(uap, fd), FREAD|FWRITE);
112         if (fp == NULL)
113                 return EBADF;
114
115 #if defined(DEBUG_SVR4)
116         if (fp->f_type == DTYPE_SOCKET) {
117                 struct socket *so = (struct socket *)fp->f_data;
118                 DPRINTF(("<<< IN: so_state = 0x%x\n", so->so_state));
119         }
120 #endif
121
122         switch (cmd & 0xff00) {
123         case SVR4_tIOC:
124                 DPRINTF(("ttold\n"));
125                 fun = svr4_ttold_ioctl;
126                 break;
127
128         case SVR4_TIOC:
129                 DPRINTF(("term\n"));
130                 fun = svr4_term_ioctl;
131                 break;
132
133         case SVR4_STR:
134                 DPRINTF(("stream\n"));
135                 fun = svr4_stream_ioctl;
136                 break;
137
138         case SVR4_FIOC:
139                 DPRINTF(("file\n"));
140                 fun = svr4_fil_ioctl;
141                 break;
142
143         case SVR4_SIOC:
144                 DPRINTF(("socket\n"));
145                 fun = svr4_sock_ioctl;
146                 break;
147
148         case SVR4_XIOC:
149                 /* We do not support those */
150                 error = EINVAL;
151                 goto done;
152
153         default:
154                 DPRINTF(("Unimplemented ioctl %lx\n", cmd));
155                 error = 0;      /* XXX: really ENOSYS */
156                 goto done;
157         }
158 #if defined(DEBUG_SVR4)
159         if (fp->f_type == DTYPE_SOCKET) {
160                 struct socket *so = (struct socket *)fp->f_data;
161                 DPRINTF((">>> OUT: so_state = 0x%x\n", so->so_state));
162         }
163 #endif
164         error = (*fun)(fp, td, retval, SCARG(uap, fd), cmd, SCARG(uap, data));
165 done:
166         fdrop(fp);
167         return (error);
168 }