1 /* $NetBSD: aoutm68k_stat.c,v 1.23 2008/03/23 13:58:47 ad Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: aoutm68k_stat.c,v 1.23 2008/03/23 13:58:47 ad Exp $");
35 #if defined(_KERNEL_OPT)
36 #include "opt_compat_netbsd.h"
37 #include "opt_compat_43.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/filedesc.h>
43 #include <sys/mount.h>
44 #include <sys/namei.h>
47 #include <sys/vfs_syscalls.h>
49 #include <sys/syscall.h>
50 #include <sys/syscallargs.h>
52 #include <compat/sys/stat.h>
54 #include <compat/aoutm68k/aoutm68k_util.h>
55 #include <compat/aoutm68k/aoutm68k_stat.h>
56 #include <compat/aoutm68k/aoutm68k_syscall.h>
57 #include <compat/aoutm68k/aoutm68k_syscallargs.h>
60 static void aoutm68k_stat43_convert(struct stat
*, struct aoutm68k_stat43
*);
63 static void aoutm68k_stat12_convert(struct stat
*, struct aoutm68k_stat12
*);
65 static void aoutm68k_stat13_convert(struct stat
*, struct aoutm68k_stat
*);
70 aoutm68k_compat_43_sys_stat(struct lwp
*l
, const struct aoutm68k_compat_43_sys_stat_args
*uap
, register_t
*retval
)
72 struct aoutm68k_stat43 ast
;
76 error
= do_sys_stat(SCARG(uap
, path
), FOLLOW
, &sb
);
80 aoutm68k_stat43_convert(&sb
, &ast
);
82 return copyout(&ast
, SCARG(uap
, ub
), sizeof(ast
));
86 aoutm68k_compat_43_sys_fstat(struct lwp
*l
, const struct aoutm68k_compat_43_sys_fstat_args
*uap
, register_t
*retval
)
88 struct aoutm68k_stat43 ast
;
92 error
= do_sys_fstat(SCARG(uap
, fd
), &sb
);
96 aoutm68k_stat43_convert(&sb
, &ast
);
98 return copyout(&ast
, SCARG(uap
, sb
), sizeof(ast
));
102 aoutm68k_compat_43_sys_lstat(struct lwp
*l
, const struct aoutm68k_compat_43_sys_lstat_args
*uap
, register_t
*retval
)
104 struct aoutm68k_stat43 ast
;
108 error
= do_sys_stat(SCARG(uap
, path
), NOFOLLOW
, &sb
);
112 aoutm68k_stat43_convert(&sb
, &ast
);
114 return copyout(&ast
, SCARG(uap
, ub
), sizeof(ast
));
116 #endif /* COMPAT_43 */
120 aoutm68k_compat_12_sys_stat(struct lwp
*l
, const struct aoutm68k_compat_12_sys_stat_args
*uap
, register_t
*retval
)
122 struct aoutm68k_stat12 ast
;
126 error
= do_sys_stat(SCARG(uap
, path
), FOLLOW
, &sb
);
130 aoutm68k_stat12_convert(&sb
, &ast
);
132 return copyout(&ast
, SCARG(uap
, ub
), sizeof(ast
));
136 aoutm68k_compat_12_sys_fstat(struct lwp
*l
, const struct aoutm68k_compat_12_sys_fstat_args
*uap
, register_t
*retval
)
138 struct aoutm68k_stat12 ast
;
142 error
= do_sys_fstat(SCARG(uap
, fd
), &sb
);
146 aoutm68k_stat12_convert(&sb
, &ast
);
148 return copyout(&ast
, SCARG(uap
, sb
), sizeof(ast
));
152 aoutm68k_compat_12_sys_lstat(struct lwp
*l
, const struct aoutm68k_compat_12_sys_lstat_args
*uap
, register_t
*retval
)
154 struct aoutm68k_stat12 ast
;
158 error
= do_sys_stat(SCARG(uap
, path
), NOFOLLOW
, &sb
);
162 aoutm68k_stat12_convert(&sb
, &ast
);
164 return copyout(&ast
, SCARG(uap
, ub
), sizeof(ast
));
166 #endif /* COMPAT_12 */
169 aoutm68k_sys___stat13(struct lwp
*l
, const struct aoutm68k_sys___stat13_args
*uap
, register_t
*retval
)
171 struct aoutm68k_stat ast
;
175 error
= do_sys_stat(SCARG(uap
, path
), FOLLOW
, &sb
);
179 aoutm68k_stat13_convert(&sb
, &ast
);
181 return copyout(&ast
, SCARG(uap
, ub
), sizeof(ast
));
185 aoutm68k_sys___fstat13(struct lwp
*l
, const struct aoutm68k_sys___fstat13_args
*uap
, register_t
*retval
)
187 struct aoutm68k_stat ast
;
191 error
= do_sys_fstat(SCARG(uap
, fd
), &sb
);
195 aoutm68k_stat13_convert(&sb
, &ast
);
197 return copyout(&ast
, SCARG(uap
, sb
), sizeof(ast
));
202 aoutm68k_sys___lstat13(struct lwp
*l
, const struct aoutm68k_sys___lstat13_args
*uap
, register_t
*retval
)
204 struct aoutm68k_stat ast
;
208 error
= do_sys_stat(SCARG(uap
, path
), NOFOLLOW
, &sb
);
212 aoutm68k_stat13_convert(&sb
, &ast
);
214 return copyout(&ast
, SCARG(uap
, ub
), sizeof(ast
));
218 aoutm68k_sys_fhstat(struct lwp
*l
, const struct aoutm68k_sys_fhstat_args
*uap
, register_t
*retval
)
220 struct aoutm68k_stat ast
;
224 error
= do_fhstat(l
, SCARG(uap
, fhp
), FHANDLE_SIZE_COMPAT
, &sb
);
228 aoutm68k_stat13_convert(&sb
, &ast
);
229 return copyout(&sb
, SCARG(uap
, sb
), sizeof(sb
));
234 aoutm68k_stat43_convert(struct stat
*st
, struct aoutm68k_stat43
*ast
)
237 memset(ast
, 0, sizeof(*ast
));
238 ast
->st_dev
= st
->st_dev
;
239 ast
->st_ino
= st
->st_ino
;
240 ast
->st_mode
= st
->st_mode
;
241 ast
->st_nlink
= st
->st_nlink
;
242 ast
->st_uid
= st
->st_uid
;
243 ast
->st_gid
= st
->st_gid
;
244 ast
->st_rdev
= st
->st_rdev
;
245 if (st
->st_size
< (off_t
)1 << 32)
246 ast
->st_size
= st
->st_size
;
249 ast
->st_atimespec
.tv_sec
= st
->st_atimespec
.tv_sec
;
250 ast
->st_atimespec
.tv_nsec
= st
->st_atimespec
.tv_nsec
;
251 ast
->st_mtimespec
.tv_sec
= st
->st_mtimespec
.tv_sec
;
252 ast
->st_mtimespec
.tv_nsec
= st
->st_mtimespec
.tv_nsec
;
253 ast
->st_ctimespec
.tv_sec
= st
->st_ctimespec
.tv_sec
;
254 ast
->st_ctimespec
.tv_nsec
= st
->st_ctimespec
.tv_nsec
;
255 ast
->st_blksize
= st
->st_blksize
;
256 ast
->st_blocks
= st
->st_blocks
;
257 ast
->st_flags
= st
->st_flags
;
258 ast
->st_gen
= st
->st_gen
;
260 #endif /* COMPAT_43 */
264 aoutm68k_stat12_convert(struct stat
*st
, struct aoutm68k_stat12
*ast
)
267 memset(ast
, 0, sizeof(*ast
));
268 ast
->st_dev
= st
->st_dev
;
269 ast
->st_ino
= st
->st_ino
;
270 ast
->st_mode
= st
->st_mode
;
271 ast
->st_nlink
= st
->st_nlink
;
272 ast
->st_uid
= st
->st_uid
;
273 ast
->st_gid
= st
->st_gid
;
274 ast
->st_rdev
= st
->st_rdev
;
275 ast
->st_atimespec
.tv_sec
= st
->st_atimespec
.tv_sec
;
276 ast
->st_atimespec
.tv_nsec
= st
->st_atimespec
.tv_nsec
;
277 ast
->st_mtimespec
.tv_sec
= st
->st_mtimespec
.tv_sec
;
278 ast
->st_mtimespec
.tv_nsec
= st
->st_mtimespec
.tv_nsec
;
279 ast
->st_ctimespec
.tv_sec
= st
->st_ctimespec
.tv_sec
;
280 ast
->st_ctimespec
.tv_nsec
= st
->st_ctimespec
.tv_nsec
;
281 if (st
->st_size
< (off_t
)1 << 32)
282 ast
->st_size
= st
->st_size
;
285 ast
->st_blocks
= st
->st_blocks
;
286 ast
->st_blksize
= st
->st_blksize
;
287 ast
->st_flags
= st
->st_flags
;
288 ast
->st_gen
= st
->st_gen
;
290 #endif /* COMPAT_12 */
293 aoutm68k_stat13_convert(struct stat
*st
, struct aoutm68k_stat
*ast
)
296 memset(ast
, 0, sizeof(*ast
));
297 ast
->st_dev
= st
->st_dev
;
298 ast
->st_ino
= st
->st_ino
;
299 ast
->st_mode
= st
->st_mode
;
300 ast
->st_nlink
= st
->st_nlink
;
301 ast
->st_uid
= st
->st_uid
;
302 ast
->st_gid
= st
->st_gid
;
303 ast
->st_rdev
= st
->st_rdev
;
304 ast
->st_atimespec
.tv_sec
= st
->st_atimespec
.tv_sec
;
305 ast
->st_atimespec
.tv_nsec
= st
->st_atimespec
.tv_nsec
;
306 ast
->st_mtimespec
.tv_sec
= st
->st_mtimespec
.tv_sec
;
307 ast
->st_mtimespec
.tv_nsec
= st
->st_mtimespec
.tv_nsec
;
308 ast
->st_ctimespec
.tv_sec
= st
->st_ctimespec
.tv_sec
;
309 ast
->st_ctimespec
.tv_nsec
= st
->st_ctimespec
.tv_nsec
;
310 if (st
->st_size
< (off_t
)1 << 32)
311 ast
->st_size
= st
->st_size
;
314 ast
->st_blocks
= st
->st_blocks
;
315 ast
->st_blksize
= st
->st_blksize
;
316 ast
->st_flags
= st
->st_flags
;
317 ast
->st_gen
= st
->st_gen
;
318 ast
->st_qspare
[0] = 0;
319 ast
->st_qspare
[1] = 0;