1 /* $NetBSD: svr4_ioctl.c,v 1.27 2005/12/11 12:20:26 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: svr4_ioctl.c,v 1.27 2005/12/11 12:20:26 christos Exp $");
41
42 #include <sys/param.h>
43 #include <sys/proc.h>
44 #include <sys/systm.h>
45 #include <sys/file.h>
46 #include <sys/filedesc.h>
47 #include <sys/ioctl.h>
48 #include <sys/termios.h>
49 #include <sys/tty.h>
50 #include <sys/socket.h>
51 #include <sys/ioctl.h>
52 #include <sys/mount.h>
53 #include <net/if.h>
54 #include <sys/malloc.h>
55
56 #include <sys/sa.h>
57 #include <sys/syscallargs.h>
58
59 #include <compat/sys/socket.h>
60
61 #include <compat/svr4/svr4_types.h>
62 #include <compat/svr4/svr4_util.h>
63 #include <compat/svr4/svr4_signal.h>
64 #include <compat/svr4/svr4_lwp.h>
65 #include <compat/svr4/svr4_ucontext.h>
66 #include <compat/svr4/svr4_syscallargs.h>
67 #include <compat/svr4/svr4_stropts.h>
68 #include <compat/svr4/svr4_ioctl.h>
69 #include <compat/svr4/svr4_termios.h>
70 #include <compat/svr4/svr4_ttold.h>
71 #include <compat/svr4/svr4_filio.h>
72 #include <compat/svr4/svr4_sockio.h>
73
74 #ifdef DEBUG_SVR4
75 static void svr4_decode_cmd __P((u_long, char *, char *, int *, int *));
76 /*
77 * Decode an ioctl command symbolically
78 */
79 static void
80 svr4_decode_cmd(cmd, dir, c, num, argsiz)
81 u_long cmd;
82 char *dir, *c;
83 int *num, *argsiz;
84 {
85 if (cmd & SVR4_IOC_VOID)
86 *dir++ = 'V';
87 if (cmd & SVR4_IOC_IN)
88 *dir++ = 'R';
89 if (cmd & SVR4_IOC_OUT)
90 *dir++ = 'W';
91 *dir = '\0';
92 if (cmd & SVR4_IOC_INOUT)
93 *argsiz = (cmd >> 16) & 0xff;
94 else
95 *argsiz = -1;
96
97 *c = (cmd >> 8) & 0xff;
98 *num = cmd & 0xff;
99 }
100 #endif
101
102 int
103 svr4_sys_ioctl(l, v, retval)
104 struct lwp *l;
105 void *v;
106 register_t *retval;
107 {
108 struct svr4_sys_ioctl_args *uap = v;
109 struct proc *p = l->l_proc;
110 struct file *fp;
111 struct filedesc *fdp;
112 u_long cmd;
113 int error;
114 int (*fun) __P((struct file *, struct lwp *, register_t *,
115 int, u_long, caddr_t));
116 #ifdef DEBUG_SVR4
117 char dir[4];
118 char c;
119 int num;
120 int argsiz;
121
122 svr4_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz);
123
124 uprintf("svr4_ioctl(%d, _IO%s(%c, %d, %d), %p);\n", SCARG(uap, fd),
125 dir, c, num, argsiz, SCARG(uap, data));
126 #endif
127 fdp = p->p_fd;
128 cmd = SCARG(uap, com);
129
130 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
131 return EBADF;
132
133 FILE_USE(fp);
134
135 if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
136 error = EBADF;
137 goto out;
138 }
139
140 switch (cmd & 0xff00) {
141 case SVR4_tIOC:
142 fun = svr4_ttold_ioctl;
143 break;
144
145 case SVR4_TIOC:
146 fun = svr4_term_ioctl;
147 break;
148
149 case SVR4_STR:
150 fun = svr4_stream_ioctl;
151 break;
152
153 case SVR4_FIOC:
154 fun = svr4_fil_ioctl;
155 break;
156
157 case SVR4_SIOC:
158 fun = svr4_sock_ioctl;
159 break;
160
161 case SVR4_XIOC:
162 /* We do not support those */
163 error = EINVAL;
164 goto out;
165
166 default:
167 DPRINTF(("Unimplemented ioctl %lx\n", cmd));
168 error = 0; /* XXX: really ENOSYS */
169 goto out;
170 }
171
172 error = (*fun)(fp, l, retval, SCARG(uap, fd), cmd, SCARG(uap, data));
173 out:
174 FILE_UNUSE(fp, l);
175 return (error);
176 }
Cache object: 17a8cbf8068bf714a810f915f235c46b
|