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]
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>
41 #include <sys/systm.h>
42 #include <sys/errno.h>
43 #include <sys/ttold.h>
44 #include <sys/vnode.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>
61 ioctl(int fdes
, int cmd
, intptr_t arg
)
70 if ((fp
= getf(fdes
)) == NULL
)
71 return (set_errno(EBADF
));
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
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.
91 vattr
.va_mask
= AT_SIZE
;
92 error
= fop_getattr(vp
, &vattr
, 0, fp
->f_cred
, NULL
);
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
))) {
100 return (set_errno(EFAULT
));
107 if (copyin((caddr_t
)arg
, &flag
, sizeof (flag
))) {
109 return (set_errno(EFAULT
));
111 mutex_enter(&fp
->f_tlock
);
113 fp
->f_flag
|= FNDELAY
;
115 fp
->f_flag
&= ~FNDELAY
;
116 mutex_exit(&fp
->f_tlock
);
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
136 flag
= (fp
->f_flag
& 0xffff) | get_udatamodel();
137 error
= fop_ioctl(fp
->f_vnode
, cmd
, arg
, flag
, CRED(), &rv
, NULL
);
140 return (set_errno(error
));
144 if (copyin((caddr_t
)arg
, &flag
, sizeof (flag
))) {
146 return (set_errno(EFAULT
));
148 mutex_enter(&fp
->f_tlock
);
150 fp
->f_flag
|= FNDELAY
;
152 fp
->f_flag
&= ~FNDELAY
;
153 mutex_exit(&fp
->f_tlock
);
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
));