aoutm68k_stat.c revision 1.21 1 /* $NetBSD: aoutm68k_stat.c,v 1.21 2007/12/08 18:35:53 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.21 2007/12/08 18:35:53 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(struct lwp *l, void *v, register_t *retval)
78 {
79 struct aoutm68k_compat_43_sys_stat_args *uap = v;
80 struct aoutm68k_stat43 ast;
81 struct stat sb;
82 int error;
83
84 error = do_sys_stat(l, SCARG(uap, path), FOLLOW, &sb);
85 if (error)
86 return error;
87
88 aoutm68k_stat43_convert(&sb, &ast);
89
90 return copyout(&ast, SCARG(uap, ub), sizeof(ast));
91 }
92
93 int
94 aoutm68k_compat_43_sys_fstat(struct lwp *l, void *v, register_t *retval)
95 {
96 struct aoutm68k_compat_43_sys_fstat_args *uap = v;
97 struct aoutm68k_stat43 ast;
98 struct stat sb;
99 int error;
100
101 error = do_sys_fstat(l, SCARG(uap, fd), &sb);
102 if (error != 0)
103 return error;
104
105 aoutm68k_stat43_convert(&sb, &ast);
106
107 return copyout(&ast, SCARG(uap, sb), sizeof(ast));
108 }
109
110 int
111 aoutm68k_compat_43_sys_lstat(struct lwp *l, void *v, register_t *retval)
112 {
113 struct aoutm68k_compat_43_sys_lstat_args *uap = v;
114 struct aoutm68k_stat43 ast;
115 struct stat sb;
116 int error;
117
118 error = do_sys_stat(l, SCARG(uap, path), NOFOLLOW, &sb);
119 if (error)
120 return error;
121
122 aoutm68k_stat43_convert(&sb, &ast);
123
124 return copyout(&ast, SCARG(uap, ub), sizeof(ast));
125 }
126 #endif /* COMPAT_43 */
127
128 #ifdef COMPAT_12
129 int
130 aoutm68k_compat_12_sys_stat(struct lwp *l, void *v, register_t *retval)
131 {
132 struct aoutm68k_compat_12_sys_stat_args *uap = v;
133 struct aoutm68k_stat12 ast;
134 struct stat sb;
135 int error;
136
137 error = do_sys_stat(l, SCARG(uap, path), FOLLOW, &sb);
138 if (error)
139 return error;
140
141 aoutm68k_stat12_convert(&sb, &ast);
142
143 return copyout(&ast, SCARG(uap, ub), sizeof(ast));
144 }
145
146 int
147 aoutm68k_compat_12_sys_fstat(struct lwp *l, void *v, register_t *retval)
148 {
149 struct aoutm68k_compat_12_sys_fstat_args *uap = v;
150 struct aoutm68k_stat12 ast;
151 struct stat sb;
152 int error;
153
154 error = do_sys_fstat(l, SCARG(uap, fd), &sb);
155 if (error != 0)
156 return error;
157
158 aoutm68k_stat12_convert(&sb, &ast);
159
160 return copyout(&ast, SCARG(uap, sb), sizeof(ast));
161 }
162
163 int
164 aoutm68k_compat_12_sys_lstat(struct lwp *l, void *v, register_t *retval)
165 {
166 struct aoutm68k_compat_12_sys_lstat_args *uap = v;
167 struct aoutm68k_stat12 ast;
168 struct stat sb;
169 int error;
170
171 error = do_sys_stat(l, SCARG(uap, path), NOFOLLOW, &sb);
172 if (error)
173 return error;
174
175 aoutm68k_stat12_convert(&sb, &ast);
176
177 return copyout(&ast, SCARG(uap, ub), sizeof(ast));
178 }
179 #endif /* COMPAT_12 */
180
181 int
182 aoutm68k_sys___stat13(struct lwp *l, void *v, register_t *retval)
183 {
184 struct aoutm68k_sys___stat13_args *uap = v;
185 struct aoutm68k_stat ast;
186 struct stat sb;
187 int error;
188
189 error = do_sys_stat(l, SCARG(uap, path), FOLLOW, &sb);
190 if (error)
191 return error;
192
193 aoutm68k_stat13_convert(&sb, &ast);
194
195 return copyout(&ast, SCARG(uap, ub), sizeof(ast));
196 }
197
198 int
199 aoutm68k_sys___fstat13(struct lwp *l, void *v, register_t *retval)
200 {
201 struct aoutm68k_sys___fstat13_args *uap = v;
202 struct aoutm68k_stat ast;
203 struct stat sb;
204 int error;
205
206 error = do_sys_fstat(l, SCARG(uap, fd), &sb);
207 if (error != 0)
208 return error;
209
210 aoutm68k_stat13_convert(&sb, &ast);
211
212 return copyout(&ast, SCARG(uap, sb), sizeof(ast));
213
214 }
215
216 int
217 aoutm68k_sys___lstat13(struct lwp *l, void *v, register_t *retval)
218 {
219 struct aoutm68k_sys___lstat13_args *uap = v;
220 struct aoutm68k_stat ast;
221 struct stat sb;
222 int error;
223
224 error = do_sys_stat(l, SCARG(uap, path), NOFOLLOW, &sb);
225 if (error)
226 return error;
227
228 aoutm68k_stat13_convert(&sb, &ast);
229
230 return copyout(&ast, SCARG(uap, ub), sizeof(ast));
231 }
232
233 int
234 aoutm68k_sys_fhstat(struct lwp *l, void *v, register_t *retval)
235 {
236 struct aoutm68k_sys_fhstat_args *uap = v;
237 struct aoutm68k_stat ast;
238 struct stat sb;
239 int error;
240
241 error = do_fhstat(l, SCARG(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
242 if (error)
243 return error;
244
245 aoutm68k_stat13_convert(&sb, &ast);
246 return copyout(&sb, SCARG(uap, sb), sizeof(sb));
247 }
248
249 #ifdef COMPAT_43
250 static void
251 aoutm68k_stat43_convert(struct stat *st, struct aoutm68k_stat43 *ast)
252 {
253
254 memset(ast, 0, sizeof(*ast));
255 ast->st_dev = st->st_dev;
256 ast->st_ino = st->st_ino;
257 ast->st_mode = st->st_mode;
258 ast->st_nlink = st->st_nlink;
259 ast->st_uid = st->st_uid;
260 ast->st_gid = st->st_gid;
261 ast->st_rdev = st->st_rdev;
262 if (st->st_size < (off_t)1 << 32)
263 ast->st_size = st->st_size;
264 else
265 ast->st_size = -2;
266 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
267 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
268 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
269 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
270 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
271 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
272 ast->st_blksize = st->st_blksize;
273 ast->st_blocks = st->st_blocks;
274 ast->st_flags = st->st_flags;
275 ast->st_gen = st->st_gen;
276 }
277 #endif /* COMPAT_43 */
278
279 #ifdef COMPAT_12
280 static void
281 aoutm68k_stat12_convert(struct stat *st, struct aoutm68k_stat12 *ast)
282 {
283
284 memset(ast, 0, sizeof(*ast));
285 ast->st_dev = st->st_dev;
286 ast->st_ino = st->st_ino;
287 ast->st_mode = st->st_mode;
288 ast->st_nlink = st->st_nlink;
289 ast->st_uid = st->st_uid;
290 ast->st_gid = st->st_gid;
291 ast->st_rdev = st->st_rdev;
292 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
293 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
294 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
295 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
296 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
297 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
298 if (st->st_size < (off_t)1 << 32)
299 ast->st_size = st->st_size;
300 else
301 ast->st_size = -2;
302 ast->st_blocks = st->st_blocks;
303 ast->st_blksize = st->st_blksize;
304 ast->st_flags = st->st_flags;
305 ast->st_gen = st->st_gen;
306 }
307 #endif /* COMPAT_12 */
308
309 static void
310 aoutm68k_stat13_convert(struct stat *st, struct aoutm68k_stat *ast)
311 {
312
313 memset(ast, 0, sizeof(*ast));
314 ast->st_dev = st->st_dev;
315 ast->st_ino = st->st_ino;
316 ast->st_mode = st->st_mode;
317 ast->st_nlink = st->st_nlink;
318 ast->st_uid = st->st_uid;
319 ast->st_gid = st->st_gid;
320 ast->st_rdev = st->st_rdev;
321 ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
322 ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
323 ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
324 ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
325 ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
326 ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
327 if (st->st_size < (off_t)1 << 32)
328 ast->st_size = st->st_size;
329 else
330 ast->st_size = -2;
331 ast->st_blocks = st->st_blocks;
332 ast->st_blksize = st->st_blksize;
333 ast->st_flags = st->st_flags;
334 ast->st_gen = st->st_gen;
335 ast->st_qspare[0] = 0;
336 ast->st_qspare[1] = 0;
337 }
338