aoutm68k_stat.c revision 1.4 1 /* $NetBSD: aoutm68k_stat.c,v 1.4 2001/05/30 11:37:22 mrg Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #if defined(_KERNEL_OPT)
40 #include "opt_compat_netbsd.h"
41 #include "opt_compat_43.h"
42 #endif
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/mount.h>
47 #include <sys/proc.h>
48 #include <sys/stat.h>
49
50 #include <sys/syscall.h>
51 #include <sys/syscallargs.h>
52
53 #include <compat/aoutm68k/aoutm68k_util.h>
54 #include <compat/aoutm68k/aoutm68k_stat.h>
55 #include <compat/aoutm68k/aoutm68k_syscall.h>
56 #include <compat/aoutm68k/aoutm68k_syscallargs.h>
57
58 #ifdef COMPAT_43
59 static void aoutm68k_stat43_convert(struct stat43 *, struct aoutm68k_stat43 *);
60 #endif
61 #ifdef COMPAT_12
62 static void aoutm68k_stat12_convert(struct stat12 *, struct aoutm68k_stat12 *);
63 #endif
64 static void aoutm68k_stat13_convert(struct stat *, struct aoutm68k_stat *);
65
66
67 #ifdef COMPAT_43
68 int
69 aoutm68k_compat_43_sys_stat(p, v, retval)
70 struct proc *p;
71 void *v;
72 register_t *retval;
73 {
74 struct aoutm68k_compat_43_sys_stat_args *uap = v;
75 caddr_t sg = stackgap_init(p->p_emul);
76 struct compat_43_sys_stat_args cup;
77 struct aoutm68k_stat43 ast;
78 struct stat43 st;
79 int error;
80
81 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
82 #ifdef COMPAT_AOUT_ALTPATH
83 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
84 #endif
85 SCARG(&cup, path) = SCARG(uap, path);
86
87 if ((error = compat_43_sys_stat(p, &cup, retval)) != 0 ||
88 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
89 return (error);
90
91 aoutm68k_stat43_convert(&st, &ast);
92
93 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
94 }
95
96 int
97 aoutm68k_compat_43_sys_fstat(p, v, retval)
98 struct proc *p;
99 void *v;
100 register_t *retval;
101 {
102 struct aoutm68k_compat_43_sys_fstat_args *uap = v;
103 caddr_t sg = stackgap_init(p->p_emul);
104 struct compat_43_sys_fstat_args cup;
105 struct aoutm68k_stat43 ast;
106 struct stat43 st;
107 int error;
108
109 SCARG(&cup, fd) = SCARG(uap, fd);
110 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
111
112 if ((error = compat_43_sys_fstat(p, &cup, retval)) != 0 ||
113 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
114 return (error);
115
116 aoutm68k_stat43_convert(&st, &ast);
117
118 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
119 }
120
121 int
122 aoutm68k_compat_43_sys_lstat(p, v, retval)
123 struct proc *p;
124 void *v;
125 register_t *retval;
126 {
127 struct aoutm68k_compat_43_sys_lstat_args *uap = v;
128 caddr_t sg = stackgap_init(p->p_emul);
129 struct compat_43_sys_lstat_args cup;
130 struct aoutm68k_stat43 ast;
131 struct stat43 st;
132 int error;
133
134 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
135 #ifdef COMPAT_AOUT_ALTPATH
136 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
137 #endif
138 SCARG(&cup, path) = SCARG(uap, path);
139
140 if ((error = compat_43_sys_lstat(p, &cup, retval)) != 0 ||
141 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
142 return (error);
143
144 aoutm68k_stat43_convert(&st, &ast);
145
146 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
147 }
148 #endif /* COMPAT_43 */
149
150 #ifdef COMPAT_12
151 int
152 aoutm68k_compat_12_sys_stat(p, v, retval)
153 struct proc *p;
154 void *v;
155 register_t *retval;
156 {
157 struct aoutm68k_compat_12_sys_stat_args *uap = v;
158 caddr_t sg = stackgap_init(p->p_emul);
159 struct compat_12_sys_stat_args cup;
160 struct aoutm68k_stat12 ast;
161 struct stat12 st;
162 int error;
163
164 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
165 #ifdef COMPAT_AOUT_ALTPATH
166 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
167 #endif
168 SCARG(&cup, path) = SCARG(uap, path);
169
170 if ((error = compat_12_sys_stat(p, &cup, retval)) != 0 ||
171 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
172 return (error);
173
174 aoutm68k_stat12_convert(&st, &ast);
175
176 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
177 }
178
179 int
180 aoutm68k_compat_12_sys_fstat(p, v, retval)
181 struct proc *p;
182 void *v;
183 register_t *retval;
184 {
185 struct aoutm68k_compat_12_sys_fstat_args *uap = v;
186 caddr_t sg = stackgap_init(p->p_emul);
187 struct compat_12_sys_fstat_args cup;
188 struct aoutm68k_stat12 ast;
189 struct stat12 st;
190 int error;
191
192 SCARG(&cup, fd) = SCARG(uap, fd);
193 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
194
195 if ((error = compat_12_sys_fstat(p, &cup, retval)) != 0 ||
196 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
197 return (error);
198
199 aoutm68k_stat12_convert(&st, &ast);
200
201 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
202 }
203
204 int
205 aoutm68k_compat_12_sys_lstat(p, v, retval)
206 struct proc *p;
207 void *v;
208 register_t *retval;
209 {
210 struct aoutm68k_compat_12_sys_lstat_args *uap = v;
211 caddr_t sg = stackgap_init(p->p_emul);
212 struct compat_12_sys_lstat_args cup;
213 struct aoutm68k_stat12 ast;
214 struct stat12 st;
215 int error;
216
217 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
218 #ifdef COMPAT_AOUT_ALTPATH
219 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
220 #endif
221 SCARG(&cup, path) = SCARG(uap, path);
222
223 if ((error = compat_12_sys_lstat(p, &cup, retval)) != 0 ||
224 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
225 return (error);
226
227 aoutm68k_stat12_convert(&st, &ast);
228
229 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
230 }
231 #endif /* COMPAT_12 */
232
233 int
234 aoutm68k_sys___stat13(p, v, retval)
235 struct proc *p;
236 void *v;
237 register_t *retval;
238 {
239 struct aoutm68k_sys___stat13_args *uap = v;
240 caddr_t sg = stackgap_init(p->p_emul);
241 struct sys___stat13_args cup;
242 struct aoutm68k_stat ast;
243 struct stat st;
244 int error;
245
246 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
247 #ifdef COMPAT_AOUT_ALTPATH
248 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
249 #endif
250 SCARG(&cup, path) = SCARG(uap, path);
251
252 if ((error = sys___stat13(p, &cup, retval)) != 0 ||
253 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
254 return (error);
255
256 aoutm68k_stat13_convert(&st, &ast);
257
258 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
259 }
260
261 int
262 aoutm68k_sys___fstat13(p, v, retval)
263 struct proc *p;
264 void *v;
265 register_t *retval;
266 {
267 struct aoutm68k_sys___fstat13_args *uap = v;
268 caddr_t sg = stackgap_init(p->p_emul);
269 struct sys___fstat13_args cup;
270 struct aoutm68k_stat ast;
271 struct stat st;
272 int error;
273
274 SCARG(&cup, fd) = SCARG(uap, fd);
275 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
276
277 if ((error = sys___fstat13(p, &cup, retval)) != 0 ||
278 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
279 return (error);
280
281 aoutm68k_stat13_convert(&st, &ast);
282
283 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
284
285 }
286
287 int
288 aoutm68k_sys___lstat13(p, v, retval)
289 struct proc *p;
290 void *v;
291 register_t *retval;
292 {
293 struct aoutm68k_sys___lstat13_args *uap = v;
294 caddr_t sg = stackgap_init(p->p_emul);
295 struct sys___lstat13_args cup;
296 struct aoutm68k_stat ast;
297 struct stat st;
298 int error;
299
300 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
301 #ifdef COMPAT_AOUT_ALTPATH
302 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
303 #endif
304 SCARG(&cup, path) = SCARG(uap, path);
305
306 if ((error = sys___lstat13(p, &cup, retval)) != 0 ||
307 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
308 return (error);
309
310 aoutm68k_stat13_convert(&st, &ast);
311
312 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
313 }
314
315 int
316 aoutm68k_sys_fhstat(p, v, retval)
317 struct proc *p;
318 void *v;
319 register_t *retval;
320 {
321 struct aoutm68k_sys_fhstat_args *uap = v;
322 caddr_t sg = stackgap_init(p->p_emul);
323 struct sys_fhstat_args cup;
324 struct aoutm68k_stat ast;
325 struct stat st;
326 int error;
327
328 SCARG(&cup, fhp) = SCARG(uap, fhp);
329 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
330
331 if ((error = sys_fhstat(p, &cup, retval)) != 0 ||
332 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
333 return (error);
334
335 aoutm68k_stat13_convert(&st, &ast);
336
337 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
338 }
339
340 #ifdef COMPAT_43
341 static void
342 aoutm68k_stat43_convert(st, ast)
343 struct stat43 *st;
344 struct aoutm68k_stat43 *ast;
345 {
346
347 memset(ast, 0, sizeof(*ast));
348 ast->st_dev = st->st_dev;
349 ast->st_ino = st->st_ino;
350 ast->st_mode = st->st_mode;
351 ast->st_nlink = st->st_nlink;
352 ast->st_uid = st->st_uid;
353 ast->st_gid = st->st_gid;
354 ast->st_rdev = st->st_rdev;
355 ast->st_size = st->st_size;
356 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
357 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
358 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
359 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
360 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
361 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
362 ast->st_blksize = st->st_blksize;
363 ast->st_blocks = st->st_blocks;
364 ast->st_flags = st->st_flags;
365 ast->st_gen = st->st_gen;
366 }
367 #endif /* COMPAT_43 */
368
369 #ifdef COMPAT_12
370 static void
371 aoutm68k_stat12_convert(st, ast)
372 struct stat12 *st;
373 struct aoutm68k_stat12 *ast;
374 {
375
376 memset(ast, 0, sizeof(*ast));
377 ast->st_dev = st->st_dev;
378 ast->st_ino = st->st_ino;
379 ast->st_mode = st->st_mode;
380 ast->st_nlink = st->st_nlink;
381 ast->st_uid = st->st_uid;
382 ast->st_gid = st->st_gid;
383 ast->st_rdev = st->st_rdev;
384 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
385 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
386 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
387 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
388 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
389 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
390 ast->st_size = st->st_size;
391 ast->st_blocks = st->st_blocks;
392 ast->st_blksize = st->st_blksize;
393 ast->st_flags = st->st_flags;
394 ast->st_gen = st->st_gen;
395 ast->st_lspare = st->st_lspare;
396 ast->st_qspare[0] = st->st_qspare[0];
397 ast->st_qspare[1] = st->st_qspare[1];
398 }
399 #endif /* COMPAT_12 */
400
401 static void
402 aoutm68k_stat13_convert(st, ast)
403 struct stat *st;
404 struct aoutm68k_stat *ast;
405 {
406
407 memset(ast, 0, sizeof(*ast));
408 ast->st_dev = st->st_dev;
409 ast->st_ino = st->st_ino;
410 ast->st_mode = st->st_mode;
411 ast->st_nlink = st->st_nlink;
412 ast->st_uid = st->st_uid;
413 ast->st_gid = st->st_gid;
414 ast->st_rdev = st->st_rdev;
415 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
416 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
417 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
418 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
419 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
420 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
421 ast->st_size = st->st_size;
422 ast->st_blocks = st->st_blocks;
423 ast->st_blksize = st->st_blksize;
424 ast->st_flags = st->st_flags;
425 ast->st_gen = st->st_gen;
426 ast->st_qspare[0] = st->st_qspare[0];
427 ast->st_qspare[1] = st->st_qspare[1];
428 }
429