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