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