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