aoutm68k_stat.c revision 1.2 1 /* $NetBSD: aoutm68k_stat.c,v 1.2 2000/12/06 21:25:39 jdolecek 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) && !defined(_LKM)
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 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
83 SCARG(&cup, path) = SCARG(uap, path);
84
85 if ((error = compat_43_sys_stat(p, &cup, retval)) != 0 ||
86 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
87 return (error);
88
89 aoutm68k_stat43_convert(&st, &ast);
90
91 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
92 }
93
94 int
95 aoutm68k_compat_43_sys_fstat(p, v, retval)
96 struct proc *p;
97 void *v;
98 register_t *retval;
99 {
100 struct aoutm68k_compat_43_sys_fstat_args *uap = v;
101 caddr_t sg = stackgap_init(p->p_emul);
102 struct compat_43_sys_fstat_args cup;
103 struct aoutm68k_stat43 ast;
104 struct stat43 st;
105 int error;
106
107 SCARG(&cup, fd) = SCARG(uap, fd);
108 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
109
110 if ((error = compat_43_sys_fstat(p, &cup, retval)) != 0 ||
111 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
112 return (error);
113
114 aoutm68k_stat43_convert(&st, &ast);
115
116 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
117 }
118
119 int
120 aoutm68k_compat_43_sys_lstat(p, v, retval)
121 struct proc *p;
122 void *v;
123 register_t *retval;
124 {
125 struct aoutm68k_compat_43_sys_lstat_args *uap = v;
126 caddr_t sg = stackgap_init(p->p_emul);
127 struct compat_43_sys_lstat_args cup;
128 struct aoutm68k_stat43 ast;
129 struct stat43 st;
130 int error;
131
132 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
133 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
134 SCARG(&cup, path) = SCARG(uap, path);
135
136 if ((error = compat_43_sys_lstat(p, &cup, retval)) != 0 ||
137 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
138 return (error);
139
140 aoutm68k_stat43_convert(&st, &ast);
141
142 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
143 }
144 #endif /* COMPAT_43 */
145
146 #ifdef COMPAT_12
147 int
148 aoutm68k_compat_12_sys_stat(p, v, retval)
149 struct proc *p;
150 void *v;
151 register_t *retval;
152 {
153 struct aoutm68k_compat_12_sys_stat_args *uap = v;
154 caddr_t sg = stackgap_init(p->p_emul);
155 struct compat_12_sys_stat_args cup;
156 struct aoutm68k_stat12 ast;
157 struct stat12 st;
158 int error;
159
160 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
161 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
162 SCARG(&cup, path) = SCARG(uap, path);
163
164 if ((error = compat_12_sys_stat(p, &cup, retval)) != 0 ||
165 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
166 return (error);
167
168 aoutm68k_stat12_convert(&st, &ast);
169
170 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
171 }
172
173 int
174 aoutm68k_compat_12_sys_fstat(p, v, retval)
175 struct proc *p;
176 void *v;
177 register_t *retval;
178 {
179 struct aoutm68k_compat_12_sys_fstat_args *uap = v;
180 caddr_t sg = stackgap_init(p->p_emul);
181 struct compat_12_sys_fstat_args cup;
182 struct aoutm68k_stat12 ast;
183 struct stat12 st;
184 int error;
185
186 SCARG(&cup, fd) = SCARG(uap, fd);
187 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
188
189 if ((error = compat_12_sys_fstat(p, &cup, retval)) != 0 ||
190 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
191 return (error);
192
193 aoutm68k_stat12_convert(&st, &ast);
194
195 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
196 }
197
198 int
199 aoutm68k_compat_12_sys_lstat(p, v, retval)
200 struct proc *p;
201 void *v;
202 register_t *retval;
203 {
204 struct aoutm68k_compat_12_sys_lstat_args *uap = v;
205 caddr_t sg = stackgap_init(p->p_emul);
206 struct compat_12_sys_lstat_args cup;
207 struct aoutm68k_stat12 ast;
208 struct stat12 st;
209 int error;
210
211 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
212 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
213 SCARG(&cup, path) = SCARG(uap, path);
214
215 if ((error = compat_12_sys_lstat(p, &cup, retval)) != 0 ||
216 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
217 return (error);
218
219 aoutm68k_stat12_convert(&st, &ast);
220
221 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
222 }
223 #endif /* COMPAT_12 */
224
225 int
226 aoutm68k_sys___stat13(p, v, retval)
227 struct proc *p;
228 void *v;
229 register_t *retval;
230 {
231 struct aoutm68k_sys___stat13_args *uap = v;
232 caddr_t sg = stackgap_init(p->p_emul);
233 struct sys___stat13_args cup;
234 struct aoutm68k_stat ast;
235 struct stat st;
236 int error;
237
238 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
239 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
240 SCARG(&cup, path) = SCARG(uap, path);
241
242 if ((error = sys___stat13(p, &cup, retval)) != 0 ||
243 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
244 return (error);
245
246 aoutm68k_stat13_convert(&st, &ast);
247
248 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
249 }
250
251 int
252 aoutm68k_sys___fstat13(p, v, retval)
253 struct proc *p;
254 void *v;
255 register_t *retval;
256 {
257 struct aoutm68k_sys___fstat13_args *uap = v;
258 caddr_t sg = stackgap_init(p->p_emul);
259 struct sys___fstat13_args cup;
260 struct aoutm68k_stat ast;
261 struct stat st;
262 int error;
263
264 SCARG(&cup, fd) = SCARG(uap, fd);
265 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
266
267 if ((error = sys___fstat13(p, &cup, retval)) != 0 ||
268 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
269 return (error);
270
271 aoutm68k_stat13_convert(&st, &ast);
272
273 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
274
275 }
276
277 int
278 aoutm68k_sys___lstat13(p, v, retval)
279 struct proc *p;
280 void *v;
281 register_t *retval;
282 {
283 struct aoutm68k_sys___lstat13_args *uap = v;
284 caddr_t sg = stackgap_init(p->p_emul);
285 struct sys___lstat13_args cup;
286 struct aoutm68k_stat ast;
287 struct stat st;
288 int error;
289
290 SCARG(&cup, ub) = stackgap_alloc(&sg, sizeof(st));
291 CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
292 SCARG(&cup, path) = SCARG(uap, path);
293
294 if ((error = sys___lstat13(p, &cup, retval)) != 0 ||
295 (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
296 return (error);
297
298 aoutm68k_stat13_convert(&st, &ast);
299
300 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, ub), sizeof(ast)));
301 }
302
303 int
304 aoutm68k_sys_fhstat(p, v, retval)
305 struct proc *p;
306 void *v;
307 register_t *retval;
308 {
309 struct aoutm68k_sys_fhstat_args *uap = v;
310 caddr_t sg = stackgap_init(p->p_emul);
311 struct sys_fhstat_args cup;
312 struct aoutm68k_stat ast;
313 struct stat st;
314 int error;
315
316 SCARG(&cup, fhp) = SCARG(uap, fhp);
317 SCARG(&cup, sb) = stackgap_alloc(&sg, sizeof(st));
318
319 if ((error = sys_fhstat(p, &cup, retval)) != 0 ||
320 (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
321 return (error);
322
323 aoutm68k_stat13_convert(&st, &ast);
324
325 return (copyout((caddr_t)&ast, (caddr_t)SCARG(uap, sb), sizeof(ast)));
326 }
327
328 #ifdef COMPAT_43
329 static void
330 aoutm68k_stat43_convert(st, ast)
331 struct stat43 *st;
332 struct aoutm68k_stat43 *ast;
333 {
334
335 memset(ast, 0, sizeof(*ast));
336 ast->st_dev = st->st_dev;
337 ast->st_ino = st->st_ino;
338 ast->st_mode = st->st_mode;
339 ast->st_nlink = st->st_nlink;
340 ast->st_uid = st->st_uid;
341 ast->st_gid = st->st_gid;
342 ast->st_rdev = st->st_rdev;
343 ast->st_size = st->st_size;
344 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
345 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
346 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
347 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
348 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
349 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
350 ast->st_blksize = st->st_blksize;
351 ast->st_blocks = st->st_blocks;
352 ast->st_flags = st->st_flags;
353 ast->st_gen = st->st_gen;
354 }
355 #endif /* COMPAT_43 */
356
357 #ifdef COMPAT_12
358 static void
359 aoutm68k_stat12_convert(st, ast)
360 struct stat12 *st;
361 struct aoutm68k_stat12 *ast;
362 {
363
364 memset(ast, 0, sizeof(*ast));
365 ast->st_dev = st->st_dev;
366 ast->st_ino = st->st_ino;
367 ast->st_mode = st->st_mode;
368 ast->st_nlink = st->st_nlink;
369 ast->st_uid = st->st_uid;
370 ast->st_gid = st->st_gid;
371 ast->st_rdev = st->st_rdev;
372 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
373 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
374 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
375 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
376 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
377 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
378 ast->st_size = st->st_size;
379 ast->st_blocks = st->st_blocks;
380 ast->st_blksize = st->st_blksize;
381 ast->st_flags = st->st_flags;
382 ast->st_gen = st->st_gen;
383 ast->st_lspare = st->st_lspare;
384 ast->st_qspare[0] = st->st_qspare[0];
385 ast->st_qspare[1] = st->st_qspare[1];
386 }
387 #endif /* COMPAT_12 */
388
389 static void
390 aoutm68k_stat13_convert(st, ast)
391 struct stat *st;
392 struct aoutm68k_stat *ast;
393 {
394
395 memset(ast, 0, sizeof(*ast));
396 ast->st_dev = st->st_dev;
397 ast->st_ino = st->st_ino;
398 ast->st_mode = st->st_mode;
399 ast->st_nlink = st->st_nlink;
400 ast->st_uid = st->st_uid;
401 ast->st_gid = st->st_gid;
402 ast->st_rdev = st->st_rdev;
403 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
404 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
405 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
406 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
407 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
408 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
409 ast->st_size = st->st_size;
410 ast->st_blocks = st->st_blocks;
411 ast->st_blksize = st->st_blksize;
412 ast->st_flags = st->st_flags;
413 ast->st_gen = st->st_gen;
414 ast->st_qspare[0] = st->st_qspare[0];
415 ast->st_qspare[1] = st->st_qspare[1];
416 }
417