No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / osf1 / osf1_descrip.c
blob97915398a4f3e6c55f80ef828acf50bd239b44bb
1 /* $NetBSD: osf1_descrip.c,v 1.27 2009/01/26 13:00:05 njoly Exp $ */
3 /*
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
8 * are met:
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>
66 #include <sys/proc.h>
67 #include <sys/file.h>
68 #include <sys/stat.h>
69 #include <sys/filedesc.h>
70 #include <sys/kernel.h>
71 #include <sys/malloc.h>
72 #include <sys/mman.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>
78 #include <sys/exec.h>
79 #include <sys/vnode.h>
80 #include <sys/socketvar.h>
81 #include <sys/resource.h>
82 #include <sys/resourcevar.h>
83 #include <sys/wait.h>
85 #include <compat/osf1/osf1.h>
86 #include <compat/osf1/osf1_syscallargs.h>
87 #include <compat/osf1/osf1_cvt.h>
89 int
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;
94 struct flock nflock;
95 unsigned long xfl, leftovers;
96 int error;
98 SCARG(&a, fd) = SCARG(uap, fd);
100 leftovers = 0;
101 switch (SCARG(uap, cmd)) {
102 case OSF1_F_DUPFD:
103 SCARG(&a, cmd) = F_DUPFD;
104 SCARG(&a, arg) = SCARG(uap, arg);
105 break;
107 case OSF1_F_GETFD:
108 SCARG(&a, cmd) = F_GETFD;
109 SCARG(&a, arg) = 0; /* ignored */
110 break;
112 case OSF1_F_SETFD:
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);
117 break;
119 case OSF1_F_GETFL:
120 SCARG(&a, cmd) = F_GETFL;
121 SCARG(&a, arg) = 0; /* ignored */
122 break;
124 case OSF1_F_SETFL:
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;
131 break;
133 case OSF1_F_GETOWN: /* XXX not yet supported */
134 case OSF1_F_SETOWN: /* XXX not yet supported */
135 /* XXX translate. */
136 return (EINVAL);
138 case OSF1_F_GETLK:
139 case OSF1_F_SETLK:
140 case OSF1_F_SETLKW:
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);
149 if (error != 0)
150 return error;
151 error = osf1_cvt_flock_to_native(&oflock, &nflock);
152 if (error != 0)
153 return error;
154 error = do_fcntl_lock(SCARG(uap, fd), SCARG(&a, cmd), &nflock);
155 if (SCARG(&a, cmd) != F_GETLK || error != 0)
156 return error;
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 */
166 default:
167 /* XXX syslog? */
168 return (EINVAL);
170 if (leftovers != 0)
171 return (EINVAL);
173 error = sys_fcntl(l, &a, retval);
175 if (error)
176 return error;
178 switch (SCARG(uap, cmd)) {
179 case OSF1_F_GETFD:
180 retval[0] = emul_flags_translate(
181 osf1_fcntl_getsetfd_flags_rxtab, retval[0], NULL);
182 break;
184 case OSF1_F_GETFL:
185 xfl = emul_flags_translate(osf1_open_flags_rxtab,
186 retval[0], &leftovers);
187 xfl |= emul_flags_translate(osf1_fcntl_getsetfl_flags_rxtab,
188 leftovers, NULL);
189 retval[0] = xfl;
190 break;
193 return error;
197 osf1_sys_fpathconf(struct lwp *l, const struct osf1_sys_fpathconf_args *uap, register_t *retval)
199 struct sys_fpathconf_args a;
200 int error;
202 SCARG(&a, fd) = SCARG(uap, fd);
204 error = osf1_cvt_pathconf_name_to_native(SCARG(uap, name),
205 &SCARG(&a, name));
207 if (error == 0)
208 error = sys_fpathconf(l, &a, retval);
210 return (error);
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)
219 struct stat ub;
220 struct osf1_stat oub;
221 int error;
223 error = do_sys_fstat(SCARG(uap, fd), &ub);
224 osf1_cvt_stat_from_native(&ub, &oub);
225 if (error == 0)
226 error = copyout(&oub, SCARG(uap, sb), sizeof(oub));
228 return (error);
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)
237 struct stat ub;
238 struct osf1_stat2 oub;
239 int error;
241 error = do_sys_fstat(SCARG(uap, fd), &ub);
242 osf1_cvt_stat2_from_native(&ub, &oub);
243 if (error == 0)
244 error = copyout(&oub, SCARG(uap, sb), sizeof(oub));
246 return (error);
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);
255 SCARG(&a, PAD) = 0;
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);
267 SCARG(&a, PAD) = 0;
268 SCARG(&a, offset) = SCARG(uap, offset);
269 SCARG(&a, whence) = SCARG(uap, whence);
271 return sys_lseek(l, &a, retval);