1 /* $NetBSD: osf1_descrip.c,v 1.27 2009/01/26 13:00:05 njoly Exp $ */
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: osf1_descrip.c,v 1.27 2009/01/26 13:00:05 njoly Exp $");
63 #include <sys/param.h>
64 #include <sys/systm.h>
65 #include <sys/namei.h>
69 #include <sys/filedesc.h>
70 #include <sys/kernel.h>
71 #include <sys/malloc.h>
73 #include <sys/mount.h>
74 #include <sys/signal.h>
75 #include <sys/signalvar.h>
76 #include <sys/reboot.h>
77 #include <sys/syscallargs.h>
79 #include <sys/vnode.h>
80 #include <sys/socketvar.h>
81 #include <sys/resource.h>
82 #include <sys/resourcevar.h>
85 #include <compat/osf1/osf1.h>
86 #include <compat/osf1/osf1_syscallargs.h>
87 #include <compat/osf1/osf1_cvt.h>
90 osf1_sys_fcntl(struct lwp
*l
, const struct osf1_sys_fcntl_args
*uap
, register_t
*retval
)
92 struct sys_fcntl_args a
;
93 struct osf1_flock oflock
;
95 unsigned long xfl
, leftovers
;
98 SCARG(&a
, fd
) = SCARG(uap
, fd
);
101 switch (SCARG(uap
, cmd
)) {
103 SCARG(&a
, cmd
) = F_DUPFD
;
104 SCARG(&a
, arg
) = SCARG(uap
, arg
);
108 SCARG(&a
, cmd
) = F_GETFD
;
109 SCARG(&a
, arg
) = 0; /* ignored */
113 SCARG(&a
, cmd
) = F_SETFD
;
114 SCARG(&a
, arg
) = (void *)emul_flags_translate(
115 osf1_fcntl_getsetfd_flags_xtab
,
116 (unsigned long)SCARG(uap
, arg
), &leftovers
);
120 SCARG(&a
, cmd
) = F_GETFL
;
121 SCARG(&a
, arg
) = 0; /* ignored */
125 SCARG(&a
, cmd
) = F_SETFL
;
126 xfl
= emul_flags_translate(osf1_open_flags_xtab
,
127 (unsigned long)SCARG(uap
, arg
), &leftovers
);
128 xfl
|= emul_flags_translate(osf1_fcntl_getsetfl_flags_xtab
,
129 leftovers
, &leftovers
);
130 SCARG(&a
, arg
) = (void *)xfl
;
133 case OSF1_F_GETOWN
: /* XXX not yet supported */
134 case OSF1_F_SETOWN
: /* XXX not yet supported */
141 if (SCARG(uap
, cmd
) == OSF1_F_GETLK
)
142 SCARG(&a
, cmd
) = F_GETLK
;
143 else if (SCARG(uap
, cmd
) == OSF1_F_SETLK
)
144 SCARG(&a
, cmd
) = F_SETLK
;
145 else if (SCARG(uap
, cmd
) == OSF1_F_SETLKW
)
146 SCARG(&a
, cmd
) = F_SETLKW
;
148 error
= copyin(SCARG(uap
, arg
), &oflock
, sizeof oflock
);
151 error
= osf1_cvt_flock_to_native(&oflock
, &nflock
);
154 error
= do_fcntl_lock(SCARG(uap
, fd
), SCARG(&a
, cmd
), &nflock
);
155 if (SCARG(&a
, cmd
) != F_GETLK
|| error
!= 0)
157 osf1_cvt_flock_from_native(&nflock
, &oflock
);
158 return copyout(&oflock
, SCARG(uap
, arg
), sizeof oflock
);
160 case OSF1_F_RGETLK
: /* [lock mgr op] XXX not supported */
161 case OSF1_F_RSETLK
: /* [lock mgr op] XXX not supported */
162 case OSF1_F_CNVT
: /* [lock mgr op] XXX not supported */
163 case OSF1_F_RSETLKW
: /* [lock mgr op] XXX not supported */
164 case OSF1_F_PURGEFS
: /* [lock mgr op] XXX not supported */
165 case OSF1_F_PURGENFS
: /* [DECsafe op] XXX not supported */
173 error
= sys_fcntl(l
, &a
, retval
);
178 switch (SCARG(uap
, cmd
)) {
180 retval
[0] = emul_flags_translate(
181 osf1_fcntl_getsetfd_flags_rxtab
, retval
[0], NULL
);
185 xfl
= emul_flags_translate(osf1_open_flags_rxtab
,
186 retval
[0], &leftovers
);
187 xfl
|= emul_flags_translate(osf1_fcntl_getsetfl_flags_rxtab
,
197 osf1_sys_fpathconf(struct lwp
*l
, const struct osf1_sys_fpathconf_args
*uap
, register_t
*retval
)
199 struct sys_fpathconf_args a
;
202 SCARG(&a
, fd
) = SCARG(uap
, fd
);
204 error
= osf1_cvt_pathconf_name_to_native(SCARG(uap
, name
),
208 error
= sys_fpathconf(l
, &a
, retval
);
214 * Return status information about a file descriptor.
217 osf1_sys_fstat(struct lwp
*l
, const struct osf1_sys_fstat_args
*uap
, register_t
*retval
)
220 struct osf1_stat oub
;
223 error
= do_sys_fstat(SCARG(uap
, fd
), &ub
);
224 osf1_cvt_stat_from_native(&ub
, &oub
);
226 error
= copyout(&oub
, SCARG(uap
, sb
), sizeof(oub
));
232 * Return status information about a file descriptor.
235 osf1_sys_fstat2(struct lwp
*l
, const struct osf1_sys_fstat2_args
*uap
, register_t
*retval
)
238 struct osf1_stat2 oub
;
241 error
= do_sys_fstat(SCARG(uap
, fd
), &ub
);
242 osf1_cvt_stat2_from_native(&ub
, &oub
);
244 error
= copyout(&oub
, SCARG(uap
, sb
), sizeof(oub
));
250 osf1_sys_ftruncate(struct lwp
*l
, const struct osf1_sys_ftruncate_args
*uap
, register_t
*retval
)
252 struct sys_ftruncate_args a
;
254 SCARG(&a
, fd
) = SCARG(uap
, fd
);
256 SCARG(&a
, length
) = SCARG(uap
, length
);
258 return sys_ftruncate(l
, &a
, retval
);
262 osf1_sys_lseek(struct lwp
*l
, const struct osf1_sys_lseek_args
*uap
, register_t
*retval
)
264 struct sys_lseek_args a
;
266 SCARG(&a
, fd
) = SCARG(uap
, fd
);
268 SCARG(&a
, offset
) = SCARG(uap
, offset
);
269 SCARG(&a
, whence
) = SCARG(uap
, whence
);
271 return sys_lseek(l
, &a
, retval
);