1 /* $NetBSD: irix_ioctl.c,v 1.19 2008/03/21 21:54:58 ad Exp $ */
4 * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_ioctl.c,v 1.19 2008/03/21 21:54:58 ad Exp $");
35 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/mount.h>
40 #include <sys/filio.h>
41 #include <sys/filedesc.h>
42 #include <sys/ioctl.h>
43 #include <sys/vnode.h>
44 #include <sys/types.h>
45 #include <sys/syscallargs.h>
48 #include <miscfs/specfs/specdev.h>
50 #include <compat/common/compat_util.h>
52 #include <compat/svr4/svr4_types.h>
53 #include <compat/svr4/svr4_lwp.h>
54 #include <compat/svr4/svr4_ucontext.h>
55 #include <compat/svr4/svr4_signal.h>
56 #include <compat/svr4/svr4_syscall.h>
57 #include <compat/svr4/svr4_syscallargs.h>
59 #include <compat/irix/irix_ioctl.h>
60 #include <compat/irix/irix_usema.h>
61 #include <compat/irix/irix_signal.h>
62 #include <compat/irix/irix_types.h>
63 #include <compat/irix/irix_exec.h>
64 #include <compat/irix/irix_syscallargs.h>
67 irix_sys_ioctl(struct lwp
*l
, const struct irix_sys_ioctl_args
*uap
, register_t
*retval
)
71 syscallarg(u_long) com;
72 syscallarg(void *) data;
74 extern const struct cdevsw irix_usema_cdevsw
;
80 struct irix_ioctl_usrdata iiu
;
84 * This duplicates 6 lines from svr4_sys_ioctl()
85 * It would be nice to merge it.
88 cmd
= SCARG(uap
, com
);
89 data
= SCARG(uap
, data
);
91 if ((fp
= fd_getfile(fd
)) == NULL
)
94 if ((fp
->f_flag
& (FREAD
| FWRITE
)) == 0) {
100 * A special hook for /dev/usemaclone ioctls. Some of the ioctl
101 * commands need to set the return value, which is normally
102 * impossible in the file methods and lower. We do the job by
103 * copying the retval address and the data argument to a
104 * struct irix_ioctl_usrdata. The data argument
105 * is set to the address of the structure, and the underlying
106 * code will be able to retreive both data and the retval address
107 * from the struct irix_ioctl_usrdata.
109 * We also bypass the checks in sys_ioctl() because theses ioctl
110 * are defined _IO but really are _IOR. XXX need security review.
112 if ((cmd
& IRIX_UIOC_MASK
) == IRIX_UIOC
) {
113 if (fp
->f_type
!= DTYPE_VNODE
) {
118 if (vp
->v_type
!= VCHR
||
119 cdevsw_lookup(vp
->v_rdev
) != &irix_usema_cdevsw
||
120 minor(vp
->v_rdev
) != IRIX_USEMACLNDEV_MINOR
) {
126 iiu
.iiu_retval
= retval
;
128 error
= (*fp
->f_ops
->fo_ioctl
)(fp
, cmd
, &iiu
);
135 case IRIX_SIOCNREAD
: /* number of bytes to read */
136 error
= (*(fp
->f_ops
->fo_ioctl
))(fp
, FIONREAD
,
141 case IRIX_MTIOCGETBLKSIZE
: /* get tape block size in 512B units */
142 if (fp
->f_type
!= DTYPE_VNODE
) {
149 switch (vp
->v_type
) {
160 error
= VOP_GETATTR(vp
, &vattr
, l
->l_cred
);
162 val
= vattr
.va_blocksize
/ 512;
163 error
= copyout(&val
, data
, sizeof(int));
174 default: /* Fallback to the standard SVR4 ioctl's */
176 return svr4_sys_ioctl(l
, (const void *)uap
, retval
);