uts: make emu10k non-verbose
[unleashed.git] / kernel / syscall / ioctl.c
blob988031d9493a3253ed562218b06e270210b078ee
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley 4.3 BSD
31 * under license from the Regents of the University of California.
34 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/param.h>
37 #include <sys/isa_defs.h>
38 #include <sys/types.h>
39 #include <sys/sysmacros.h>
40 #include <sys/cred.h>
41 #include <sys/systm.h>
42 #include <sys/errno.h>
43 #include <sys/ttold.h>
44 #include <sys/vnode.h>
45 #include <sys/file.h>
46 #include <sys/mode.h>
47 #include <sys/proc.h>
48 #include <sys/uio.h>
49 #include <sys/kmem.h>
50 #include <sys/filio.h>
51 #include <sys/sunddi.h>
52 #include <sys/debug.h>
53 #include <sys/int_limits.h>
54 #include <sys/model.h>
57 * I/O control.
60 int
61 ioctl(int fdes, int cmd, intptr_t arg)
63 file_t *fp;
64 int error = 0;
65 vnode_t *vp;
66 struct vattr vattr;
67 int32_t flag;
68 int rv = 0;
70 if ((fp = getf(fdes)) == NULL)
71 return (set_errno(EBADF));
72 vp = fp->f_vnode;
74 if (vp->v_type == VREG || vp->v_type == VDIR) {
76 * Handle these two ioctls for regular files and
77 * directories. All others will usually be failed
78 * with ENOTTY by the VFS-dependent code. System V
79 * always failed all ioctls on regular files, but SunOS
80 * supported these.
82 switch (cmd) {
83 case FIONREAD: {
85 * offset is int32_t because that is what FIONREAD
86 * is defined in terms of. We cap at INT_MAX as in
87 * other cases for this ioctl.
89 int32_t offset;
91 vattr.va_mask = AT_SIZE;
92 error = fop_getattr(vp, &vattr, 0, fp->f_cred, NULL);
93 if (error) {
94 releasef(fdes);
95 return (set_errno(error));
97 offset = MIN(vattr.va_size - fp->f_offset, INT_MAX);
98 if (copyout(&offset, (caddr_t)arg, sizeof (offset))) {
99 releasef(fdes);
100 return (set_errno(EFAULT));
102 releasef(fdes);
103 return (0);
106 case FIONBIO:
107 if (copyin((caddr_t)arg, &flag, sizeof (flag))) {
108 releasef(fdes);
109 return (set_errno(EFAULT));
111 mutex_enter(&fp->f_tlock);
112 if (flag)
113 fp->f_flag |= FNDELAY;
114 else
115 fp->f_flag &= ~FNDELAY;
116 mutex_exit(&fp->f_tlock);
117 releasef(fdes);
118 return (0);
120 default:
121 break;
126 * ioctl() now passes in the model information in some high bits.
128 * FIXME: This is a terrible hack to preserve the original behavior
129 * before we combined f_flag and f_flag2 into a single field. The
130 * proper fix would be to pass the file_t pointer to the fop_ioctl
131 * function instead of the vnode. The data model could be passed in
132 * by itself. (get_udatamodel uses curproc so we can't push it into
133 * the individual ioctl functions or we'd break kernel-issued
134 * ioctls.)
136 flag = (fp->f_flag & 0xffff) | get_udatamodel();
137 error = fop_ioctl(fp->f_vnode, cmd, arg, flag, CRED(), &rv, NULL);
138 if (error != 0) {
139 releasef(fdes);
140 return (set_errno(error));
142 switch (cmd) {
143 case FIONBIO:
144 if (copyin((caddr_t)arg, &flag, sizeof (flag))) {
145 releasef(fdes);
146 return (set_errno(EFAULT));
148 mutex_enter(&fp->f_tlock);
149 if (flag)
150 fp->f_flag |= FNDELAY;
151 else
152 fp->f_flag &= ~FNDELAY;
153 mutex_exit(&fp->f_tlock);
154 break;
156 default:
157 break;
159 releasef(fdes);
160 return (rv);
164 * Old stty and gtty. (Still.)
167 stty(int fdes, intptr_t arg)
169 return (ioctl(fdes, TIOCSETP, arg));
173 gtty(int fdes, intptr_t arg)
175 return (ioctl(fdes, TIOCGETP, arg));