1 /* $NetBSD: osf1_descrip.c,v 1.29 2010/04/23 15:19:20 rmind Exp $ */
2
3 /*
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
5 *
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
20 *
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.
31 */
32
33 /*
34 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
35 * All rights reserved.
36 *
37 * Author: Chris G. Demetriou
38 *
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.
44 *
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.
48 *
49 * Carnegie Mellon requests users of this software to return to
50 *
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
55 *
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
58 */
59
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: osf1_descrip.c,v 1.29 2010/04/23 15:19:20 rmind Exp $");
62
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/mman.h>
72 #include <sys/mount.h>
73 #include <sys/signal.h>
74 #include <sys/signalvar.h>
75 #include <sys/reboot.h>
76 #include <sys/syscallargs.h>
77 #include <sys/exec.h>
78 #include <sys/vnode.h>
79 #include <sys/socketvar.h>
80 #include <sys/resource.h>
81 #include <sys/resourcevar.h>
82 #include <sys/wait.h>
83
84 #include <compat/osf1/osf1.h>
85 #include <compat/osf1/osf1_syscallargs.h>
86 #include <compat/osf1/osf1_cvt.h>
87
88 int
osf1_sys_fcntl(struct lwp * l,const struct osf1_sys_fcntl_args * uap,register_t * retval)89 osf1_sys_fcntl(struct lwp *l, const struct osf1_sys_fcntl_args *uap, register_t *retval)
90 {
91 struct sys_fcntl_args a;
92 struct osf1_flock oflock;
93 struct flock nflock;
94 unsigned long xfl, leftovers;
95 int error;
96
97 SCARG(&a, fd) = SCARG(uap, fd);
98
99 leftovers = 0;
100 switch (SCARG(uap, cmd)) {
101 case OSF1_F_DUPFD:
102 SCARG(&a, cmd) = F_DUPFD;
103 SCARG(&a, arg) = SCARG(uap, arg);
104 break;
105
106 case OSF1_F_GETFD:
107 SCARG(&a, cmd) = F_GETFD;
108 SCARG(&a, arg) = 0; /* ignored */
109 break;
110
111 case OSF1_F_SETFD:
112 SCARG(&a, cmd) = F_SETFD;
113 SCARG(&a, arg) = (void *)emul_flags_translate(
114 osf1_fcntl_getsetfd_flags_xtab,
115 (unsigned long)SCARG(uap, arg), &leftovers);
116 break;
117
118 case OSF1_F_GETFL:
119 SCARG(&a, cmd) = F_GETFL;
120 SCARG(&a, arg) = 0; /* ignored */
121 break;
122
123 case OSF1_F_SETFL:
124 SCARG(&a, cmd) = F_SETFL;
125 xfl = emul_flags_translate(osf1_open_flags_xtab,
126 (unsigned long)SCARG(uap, arg), &leftovers);
127 xfl |= emul_flags_translate(osf1_fcntl_getsetfl_flags_xtab,
128 leftovers, &leftovers);
129 SCARG(&a, arg) = (void *)xfl;
130 break;
131
132 case OSF1_F_GETOWN: /* XXX not yet supported */
133 case OSF1_F_SETOWN: /* XXX not yet supported */
134 /* XXX translate. */
135 return (EINVAL);
136
137 case OSF1_F_GETLK:
138 case OSF1_F_SETLK:
139 case OSF1_F_SETLKW:
140 if (SCARG(uap, cmd) == OSF1_F_GETLK)
141 SCARG(&a, cmd) = F_GETLK;
142 else if (SCARG(uap, cmd) == OSF1_F_SETLK)
143 SCARG(&a, cmd) = F_SETLK;
144 else if (SCARG(uap, cmd) == OSF1_F_SETLKW)
145 SCARG(&a, cmd) = F_SETLKW;
146
147 error = copyin(SCARG(uap, arg), &oflock, sizeof oflock);
148 if (error != 0)
149 return error;
150 error = osf1_cvt_flock_to_native(&oflock, &nflock);
151 if (error != 0)
152 return error;
153 error = do_fcntl_lock(SCARG(uap, fd), SCARG(&a, cmd), &nflock);
154 if (SCARG(&a, cmd) != F_GETLK || error != 0)
155 return error;
156 osf1_cvt_flock_from_native(&nflock, &oflock);
157 return copyout(&oflock, SCARG(uap, arg), sizeof oflock);
158
159 case OSF1_F_RGETLK: /* [lock mgr op] XXX not supported */
160 case OSF1_F_RSETLK: /* [lock mgr op] XXX not supported */
161 case OSF1_F_CNVT: /* [lock mgr op] XXX not supported */
162 case OSF1_F_RSETLKW: /* [lock mgr op] XXX not supported */
163 case OSF1_F_PURGEFS: /* [lock mgr op] XXX not supported */
164 case OSF1_F_PURGENFS: /* [DECsafe op] XXX not supported */
165 default:
166 /* XXX syslog? */
167 return (EINVAL);
168 }
169 if (leftovers != 0)
170 return (EINVAL);
171
172 error = sys_fcntl(l, &a, retval);
173
174 if (error)
175 return error;
176
177 switch (SCARG(uap, cmd)) {
178 case OSF1_F_GETFD:
179 retval[0] = emul_flags_translate(
180 osf1_fcntl_getsetfd_flags_rxtab, retval[0], NULL);
181 break;
182
183 case OSF1_F_GETFL:
184 xfl = emul_flags_translate(osf1_open_flags_rxtab,
185 retval[0], &leftovers);
186 xfl |= emul_flags_translate(osf1_fcntl_getsetfl_flags_rxtab,
187 leftovers, NULL);
188 retval[0] = xfl;
189 break;
190 }
191
192 return error;
193 }
194
195 int
osf1_sys_fpathconf(struct lwp * l,const struct osf1_sys_fpathconf_args * uap,register_t * retval)196 osf1_sys_fpathconf(struct lwp *l, const struct osf1_sys_fpathconf_args *uap, register_t *retval)
197 {
198 struct sys_fpathconf_args a;
199 int error;
200
201 SCARG(&a, fd) = SCARG(uap, fd);
202
203 error = osf1_cvt_pathconf_name_to_native(SCARG(uap, name),
204 &SCARG(&a, name));
205
206 if (error == 0)
207 error = sys_fpathconf(l, &a, retval);
208
209 return (error);
210 }
211
212 /*
213 * Return status information about a file descriptor.
214 */
215 int
osf1_sys_fstat(struct lwp * l,const struct osf1_sys_fstat_args * uap,register_t * retval)216 osf1_sys_fstat(struct lwp *l, const struct osf1_sys_fstat_args *uap, register_t *retval)
217 {
218 struct stat ub;
219 struct osf1_stat oub;
220 int error;
221
222 error = do_sys_fstat(SCARG(uap, fd), &ub);
223 osf1_cvt_stat_from_native(&ub, &oub);
224 if (error == 0)
225 error = copyout(&oub, SCARG(uap, sb), sizeof(oub));
226
227 return (error);
228 }
229
230 /*
231 * Return status information about a file descriptor.
232 */
233 int
osf1_sys_fstat2(struct lwp * l,const struct osf1_sys_fstat2_args * uap,register_t * retval)234 osf1_sys_fstat2(struct lwp *l, const struct osf1_sys_fstat2_args *uap, register_t *retval)
235 {
236 struct stat ub;
237 struct osf1_stat2 oub;
238 int error;
239
240 error = do_sys_fstat(SCARG(uap, fd), &ub);
241 osf1_cvt_stat2_from_native(&ub, &oub);
242 if (error == 0)
243 error = copyout(&oub, SCARG(uap, sb), sizeof(oub));
244
245 return (error);
246 }
247
248 int
osf1_sys_ftruncate(struct lwp * l,const struct osf1_sys_ftruncate_args * uap,register_t * retval)249 osf1_sys_ftruncate(struct lwp *l, const struct osf1_sys_ftruncate_args *uap, register_t *retval)
250 {
251 struct sys_ftruncate_args a;
252
253 SCARG(&a, fd) = SCARG(uap, fd);
254 SCARG(&a, PAD) = 0;
255 SCARG(&a, length) = SCARG(uap, length);
256
257 return sys_ftruncate(l, &a, retval);
258 }
259
260 int
osf1_sys_lseek(struct lwp * l,const struct osf1_sys_lseek_args * uap,register_t * retval)261 osf1_sys_lseek(struct lwp *l, const struct osf1_sys_lseek_args *uap, register_t *retval)
262 {
263 struct sys_lseek_args a;
264
265 SCARG(&a, fd) = SCARG(uap, fd);
266 SCARG(&a, PAD) = 0;
267 SCARG(&a, offset) = SCARG(uap, offset);
268 SCARG(&a, whence) = SCARG(uap, whence);
269
270 return sys_lseek(l, &a, retval);
271 }
272