1 /* $NetBSD: osf1_file.c,v 1.30 2008/03/21 21:54:59 ad 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_file.c,v 1.30 2008/03/21 21:54:59 ad Exp $");
62
63 #if defined(_KERNEL_OPT)
64 #include "opt_syscall_debug.h"
65 #endif
66
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
70 #include <sys/proc.h>
71 #include <sys/file.h>
72 #include <sys/stat.h>
73 #include <sys/filedesc.h>
74 #include <sys/kernel.h>
75 #include <sys/malloc.h>
76 #include <sys/mman.h>
77 #include <sys/mount.h>
78 #include <sys/signal.h>
79 #include <sys/signalvar.h>
80 #include <sys/reboot.h>
81 #include <sys/syscallargs.h>
82 #include <sys/exec.h>
83 #include <sys/vnode.h>
84 #include <sys/socketvar.h>
85 #include <sys/resource.h>
86 #include <sys/resourcevar.h>
87 #include <sys/wait.h>
88 #include <sys/vfs_syscalls.h>
89
90 #include <compat/osf1/osf1.h>
91 #include <compat/osf1/osf1_syscallargs.h>
92 #include <compat/common/compat_util.h>
93 #include <compat/osf1/osf1_cvt.h>
94
95 int
96 osf1_sys_access(struct lwp *l, const struct osf1_sys_access_args *uap, register_t *retval)
97 {
98 struct sys_access_args a;
99 unsigned long leftovers;
100
101 SCARG(&a, path) = SCARG(uap, path);
102
103 /* translate flags */
104 SCARG(&a, flags) = emul_flags_translate(osf1_access_flags_xtab,
105 SCARG(uap, flags), &leftovers);
106 if (leftovers != 0)
107 return (EINVAL);
108
109 return sys_access(l, &a, retval);
110 }
111
112 int
113 osf1_sys_execve(struct lwp *l, const struct osf1_sys_execve_args *uap, register_t *retval)
114 {
115 struct sys_execve_args ap;
116
117 SCARG(&ap, path) = SCARG(uap, path);
118 SCARG(&ap, argp) = SCARG(uap, argp);
119 SCARG(&ap, envp) = SCARG(uap, envp);
120
121 return sys_execve(l, &ap, retval);
122 }
123
124 /*
125 * Get file status; this version does not follow links.
126 */
127 /* ARGSUSED */
128 int
129 osf1_sys_lstat(struct lwp *l, const struct osf1_sys_lstat_args *uap, register_t *retval)
130 {
131 struct stat sb;
132 struct osf1_stat osb;
133 int error;
134
135 error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
136 if (error)
137 return (error);
138 osf1_cvt_stat_from_native(&sb, &osb);
139 error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
140 return (error);
141 }
142
143 /*
144 * Get file status; this version does not follow links.
145 */
146 /* ARGSUSED */
147 int
148 osf1_sys_lstat2(struct lwp *l, const struct osf1_sys_lstat2_args *uap, register_t *retval)
149 {
150 struct stat sb;
151 struct osf1_stat2 osb;
152 int error;
153
154 error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
155 if (error)
156 return (error);
157 osf1_cvt_stat2_from_native(&sb, &osb);
158 error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
159 return (error);
160 }
161
162 int
163 osf1_sys_mknod(struct lwp *l, const struct osf1_sys_mknod_args *uap, register_t *retval)
164 {
165 struct sys_mknod_args a;
166
167 SCARG(&a, path) = SCARG(uap, path);
168 SCARG(&a, mode) = SCARG(uap, mode);
169 SCARG(&a, dev) = osf1_cvt_dev_to_native(SCARG(uap, dev));
170
171 return sys_mknod(l, &a, retval);
172 }
173
174 int
175 osf1_sys_open(struct lwp *l, const struct osf1_sys_open_args *uap, register_t *retval)
176 {
177 struct sys_open_args a;
178 const char *path;
179 unsigned long leftovers;
180 #ifdef SYSCALL_DEBUG
181 char pnbuf[1024];
182
183 if (scdebug &&
184 copyinstr(SCARG(uap, path), pnbuf, sizeof pnbuf, NULL) == 0)
185 printf("osf1_open: open: %s\n", pnbuf);
186 #endif
187
188 /* translate flags */
189 SCARG(&a, flags) = emul_flags_translate(osf1_open_flags_xtab,
190 SCARG(uap, flags), &leftovers);
191 if (leftovers != 0)
192 return (EINVAL);
193
194 /* copy mode, no translation necessary */
195 SCARG(&a, mode) = SCARG(uap, mode);
196
197 /* pick appropriate path */
198 path = SCARG(uap, path);
199 SCARG(&a, path) = path;
200
201 return sys_open(l, &a, retval);
202 }
203
204 int
205 osf1_sys_pathconf(struct lwp *l, const struct osf1_sys_pathconf_args *uap, register_t *retval)
206 {
207 struct sys_pathconf_args a;
208 int error;
209
210 SCARG(&a, path) = SCARG(uap, path);
211
212 error = osf1_cvt_pathconf_name_to_native(SCARG(uap, name),
213 &SCARG(&a, name));
214
215 if (error == 0)
216 error = sys_pathconf(l, &a, retval);
217
218 return (error);
219 }
220
221 /*
222 * Get file status; this version follows links.
223 */
224 /* ARGSUSED */
225 int
226 osf1_sys_stat(struct lwp *l, const struct osf1_sys_stat_args *uap, register_t *retval)
227 {
228 struct stat sb;
229 struct osf1_stat osb;
230 int error;
231
232 error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
233 if (error)
234 return (error);
235 osf1_cvt_stat_from_native(&sb, &osb);
236 error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
237 return (error);
238 }
239
240 /*
241 * Get file status; this version follows links.
242 */
243 /* ARGSUSED */
244 int
245 osf1_sys_stat2(struct lwp *l, const struct osf1_sys_stat2_args *uap, register_t *retval)
246 {
247 struct stat sb;
248 struct osf1_stat2 osb;
249 int error;
250
251 error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
252 if (error)
253 return (error);
254 osf1_cvt_stat2_from_native(&sb, &osb);
255 error = copyout((void *)&osb, (void *)SCARG(uap, ub), sizeof (osb));
256 return (error);
257 }
258
259 int
260 osf1_sys_truncate(struct lwp *l, const struct osf1_sys_truncate_args *uap, register_t *retval)
261 {
262 struct sys_truncate_args a;
263
264 SCARG(&a, path) = SCARG(uap, path);
265 SCARG(&a, pad) = 0;
266 SCARG(&a, length) = SCARG(uap, length);
267
268 return sys_truncate(l, &a, retval);
269 }
270
271 int
272 osf1_sys_utimes(struct lwp *l, const struct osf1_sys_utimes_args *uap, register_t *retval)
273 {
274 struct osf1_timeval otv;
275 struct timeval tv[2], *tvp;
276 int error;
277
278 if (SCARG(uap, tptr) == NULL)
279 tvp = NULL;
280 else {
281 /* get the OSF/1 timeval argument */
282 error = copyin(SCARG(uap, tptr), &otv, sizeof otv);
283 if (error != 0)
284 return error;
285
286 /* fill in and copy out the NetBSD timeval */
287 tv[0].tv_sec = otv.tv_sec;
288 tv[0].tv_usec = otv.tv_usec;
289 /* Set access and modified to the same time */
290 tv[1].tv_sec = otv.tv_sec;
291 tv[1].tv_usec = otv.tv_usec;
292 tvp = tv;
293 }
294
295 return do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW,
296 tvp, UIO_SYSSPACE);
297 }
Cache object: 7f9e42c7ccc7bc454df233bbd7dd6b75
|