1 /* $NetBSD: svr4_32_ioctl.c,v 1.9 2005/02/26 23:10:21 perry 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_32_ioctl.c,v 1.9 2005/02/26 23:10:21 perry 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/svr4_32/svr4_32_types.h>
60 #include <compat/svr4_32/svr4_32_util.h>
61 #include <compat/svr4_32/svr4_32_signal.h>
62 #include <compat/svr4_32/svr4_32_lwp.h>
63 #include <compat/svr4_32/svr4_32_ucontext.h>
64 #include <compat/svr4_32/svr4_32_syscallargs.h>
65 #include <compat/svr4_32/svr4_32_stropts.h>
66 #include <compat/svr4_32/svr4_32_ioctl.h>
67 #include <compat/svr4_32/svr4_32_termios.h>
68 #include <compat/svr4/svr4_ttold.h>
69 #include <compat/svr4/svr4_filio.h>
70 #include <compat/svr4_32/svr4_32_sockio.h>
71
72 #ifdef DEBUG_SVR4
73 static void svr4_32_decode_cmd __P((netbsd32_u_long, char *, char *, int *, int *));
74 /*
75 * Decode an ioctl command symbolically
76 */
77 static void
78 svr4_32_decode_cmd(cmd, dir, c, num, argsiz)
79 netbsd32_u_long cmd;
80 char *dir, *c;
81 int *num, *argsiz;
82 {
83 if (cmd & SVR4_IOC_VOID)
84 *dir++ = 'V';
85 if (cmd & SVR4_IOC_IN)
86 *dir++ = 'R';
87 if (cmd & SVR4_IOC_OUT)
88 *dir++ = 'W';
89 *dir = '\0';
90 if (cmd & SVR4_IOC_INOUT)
91 *argsiz = (cmd >> 16) & 0xff;
92 else
93 *argsiz = -1;
94
95 *c = (cmd >> 8) & 0xff;
96 *num = cmd & 0xff;
97 }
98 #endif
99
100 int
101 svr4_32_sys_ioctl(l, v, retval)
102 struct lwp *l;
103 void *v;
104 register_t *retval;
105 {
106 struct svr4_32_sys_ioctl_args *uap = v;
107 struct proc *p = l->l_proc;
108 struct file *fp;
109 struct filedesc *fdp;
110 u_long cmd;
111 int (*fun) __P((struct file *, struct lwp *, register_t *,
112 int, u_long, caddr_t));
113 #ifdef DEBUG_SVR4
114 char dir[4];
115 char c;
116 int num;
117 int argsiz;
118
119 svr4_32_decode_cmd(SCARG(uap, com), dir, &c, &num, &argsiz);
120
121 uprintf("svr4_32_ioctl(%d, _IO%s(%c, %d, %d), %#x);\n", SCARG(uap, fd),
122 dir, c, num, argsiz, SCARG(uap, data));
123 #endif
124 fdp = p->p_fd;
125 cmd = SCARG(uap, com);
126
127 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
128 return EBADF;
129
130 if ((fp->f_flag & (FREAD | FWRITE)) == 0)
131 return EBADF;
132
133 switch (cmd & 0xff00) {
134 case SVR4_tIOC:
135 fun = svr4_ttold_ioctl;
136 break;
137
138 case SVR4_TIOC:
139 fun = svr4_32_term_ioctl;
140 break;
141
142 case SVR4_STR:
143 fun = svr4_32_stream_ioctl;
144 break;
145
146 case SVR4_FIOC:
147 fun = svr4_fil_ioctl;
148 break;
149
150 case SVR4_SIOC:
151 fun = svr4_32_sock_ioctl;
152 break;
153
154 case SVR4_XIOC:
155 /* We do not support those */
156 return EINVAL;
157
158 default:
159 DPRINTF(("Unimplemented ioctl %lx\n", cmd));
160 return 0; /* XXX: really ENOSYS */
161 }
162 return (*fun)(fp, l, retval, SCARG(uap, fd), cmd,
163 (caddr_t)(u_long)SCARG(uap, data));
164 }
Cache object: 064e40434c71cbca47f9fa0e4451859a
|