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