1*ce099b40Smartin /* $NetBSD: aoutm68k_stat.c,v 1.24 2008/04/28 20:23:41 martin Exp $ */
247a35be2Sscw
347a35be2Sscw /*-
447a35be2Sscw * Copyright (c) 2000 The NetBSD Foundation, Inc.
547a35be2Sscw * All rights reserved.
647a35be2Sscw *
747a35be2Sscw * This code is derived from software contributed to The NetBSD Foundation
847a35be2Sscw * by Steve C. Woodford.
947a35be2Sscw *
1047a35be2Sscw * Redistribution and use in source and binary forms, with or without
1147a35be2Sscw * modification, are permitted provided that the following conditions
1247a35be2Sscw * are met:
1347a35be2Sscw * 1. Redistributions of source code must retain the above copyright
1447a35be2Sscw * notice, this list of conditions and the following disclaimer.
1547a35be2Sscw * 2. Redistributions in binary form must reproduce the above copyright
1647a35be2Sscw * notice, this list of conditions and the following disclaimer in the
1747a35be2Sscw * documentation and/or other materials provided with the distribution.
1847a35be2Sscw *
1947a35be2Sscw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2047a35be2Sscw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2147a35be2Sscw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2247a35be2Sscw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2347a35be2Sscw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2447a35be2Sscw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2547a35be2Sscw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2647a35be2Sscw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2747a35be2Sscw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2847a35be2Sscw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2947a35be2Sscw * POSSIBILITY OF SUCH DAMAGE.
3047a35be2Sscw */
3147a35be2Sscw
32dab6ef8bSlukem #include <sys/cdefs.h>
33*ce099b40Smartin __KERNEL_RCSID(0, "$NetBSD: aoutm68k_stat.c,v 1.24 2008/04/28 20:23:41 martin Exp $");
34dab6ef8bSlukem
356a89288aSmrg #if defined(_KERNEL_OPT)
3647a35be2Sscw #include "opt_compat_netbsd.h"
3747a35be2Sscw #include "opt_compat_43.h"
3879e6f661Sjdolecek #endif
3947a35be2Sscw
4047a35be2Sscw #include <sys/param.h>
4147a35be2Sscw #include <sys/systm.h>
42893faeaeSdsl #include <sys/filedesc.h>
4347a35be2Sscw #include <sys/mount.h>
44893faeaeSdsl #include <sys/namei.h>
4547a35be2Sscw #include <sys/proc.h>
4647a35be2Sscw #include <sys/stat.h>
47893faeaeSdsl #include <sys/vfs_syscalls.h>
4847a35be2Sscw
4947a35be2Sscw #include <sys/syscall.h>
5047a35be2Sscw #include <sys/syscallargs.h>
5147a35be2Sscw
5287e3d67bShe #include <compat/sys/stat.h>
5387e3d67bShe
5447a35be2Sscw #include <compat/aoutm68k/aoutm68k_util.h>
5547a35be2Sscw #include <compat/aoutm68k/aoutm68k_stat.h>
5647a35be2Sscw #include <compat/aoutm68k/aoutm68k_syscall.h>
5747a35be2Sscw #include <compat/aoutm68k/aoutm68k_syscallargs.h>
5847a35be2Sscw
5947a35be2Sscw #ifdef COMPAT_43
60893faeaeSdsl static void aoutm68k_stat43_convert(struct stat *, struct aoutm68k_stat43 *);
6147a35be2Sscw #endif
6247a35be2Sscw #ifdef COMPAT_12
63893faeaeSdsl static void aoutm68k_stat12_convert(struct stat *, struct aoutm68k_stat12 *);
6447a35be2Sscw #endif
6547a35be2Sscw static void aoutm68k_stat13_convert(struct stat *, struct aoutm68k_stat *);
6647a35be2Sscw
6747a35be2Sscw
6847a35be2Sscw #ifdef COMPAT_43
6947a35be2Sscw int
aoutm68k_compat_43_sys_stat(struct lwp * l,const struct aoutm68k_compat_43_sys_stat_args * uap,register_t * retval)707e2790cfSdsl aoutm68k_compat_43_sys_stat(struct lwp *l, const struct aoutm68k_compat_43_sys_stat_args *uap, register_t *retval)
7147a35be2Sscw {
7247a35be2Sscw struct aoutm68k_stat43 ast;
73893faeaeSdsl struct stat sb;
7447a35be2Sscw int error;
7547a35be2Sscw
76c9a93c8cSad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
77893faeaeSdsl if (error)
78893faeaeSdsl return error;
7947a35be2Sscw
80893faeaeSdsl aoutm68k_stat43_convert(&sb, &ast);
8147a35be2Sscw
82893faeaeSdsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
8347a35be2Sscw }
8447a35be2Sscw
8547a35be2Sscw int
aoutm68k_compat_43_sys_fstat(struct lwp * l,const struct aoutm68k_compat_43_sys_fstat_args * uap,register_t * retval)867e2790cfSdsl aoutm68k_compat_43_sys_fstat(struct lwp *l, const struct aoutm68k_compat_43_sys_fstat_args *uap, register_t *retval)
8747a35be2Sscw {
8847a35be2Sscw struct aoutm68k_stat43 ast;
89893faeaeSdsl struct stat sb;
9047a35be2Sscw int error;
9147a35be2Sscw
92c9a93c8cSad error = do_sys_fstat(SCARG(uap, fd), &sb);
93893faeaeSdsl if (error != 0)
94893faeaeSdsl return error;
9547a35be2Sscw
96893faeaeSdsl aoutm68k_stat43_convert(&sb, &ast);
9747a35be2Sscw
98893faeaeSdsl return copyout(&ast, SCARG(uap, sb), sizeof(ast));
9947a35be2Sscw }
10047a35be2Sscw
10147a35be2Sscw int
aoutm68k_compat_43_sys_lstat(struct lwp * l,const struct aoutm68k_compat_43_sys_lstat_args * uap,register_t * retval)1027e2790cfSdsl aoutm68k_compat_43_sys_lstat(struct lwp *l, const struct aoutm68k_compat_43_sys_lstat_args *uap, register_t *retval)
10347a35be2Sscw {
10447a35be2Sscw struct aoutm68k_stat43 ast;
105893faeaeSdsl struct stat sb;
10647a35be2Sscw int error;
10747a35be2Sscw
108c9a93c8cSad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
109893faeaeSdsl if (error)
110893faeaeSdsl return error;
11147a35be2Sscw
112893faeaeSdsl aoutm68k_stat43_convert(&sb, &ast);
11347a35be2Sscw
114893faeaeSdsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
11547a35be2Sscw }
11647a35be2Sscw #endif /* COMPAT_43 */
11747a35be2Sscw
11847a35be2Sscw #ifdef COMPAT_12
11947a35be2Sscw int
aoutm68k_compat_12_sys_stat(struct lwp * l,const struct aoutm68k_compat_12_sys_stat_args * uap,register_t * retval)1207e2790cfSdsl aoutm68k_compat_12_sys_stat(struct lwp *l, const struct aoutm68k_compat_12_sys_stat_args *uap, register_t *retval)
12147a35be2Sscw {
12247a35be2Sscw struct aoutm68k_stat12 ast;
123893faeaeSdsl struct stat sb;
12447a35be2Sscw int error;
12547a35be2Sscw
126c9a93c8cSad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
127893faeaeSdsl if (error)
128893faeaeSdsl return error;
12947a35be2Sscw
130893faeaeSdsl aoutm68k_stat12_convert(&sb, &ast);
13147a35be2Sscw
132893faeaeSdsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
13347a35be2Sscw }
13447a35be2Sscw
13547a35be2Sscw int
aoutm68k_compat_12_sys_fstat(struct lwp * l,const struct aoutm68k_compat_12_sys_fstat_args * uap,register_t * retval)1367e2790cfSdsl aoutm68k_compat_12_sys_fstat(struct lwp *l, const struct aoutm68k_compat_12_sys_fstat_args *uap, register_t *retval)
13747a35be2Sscw {
13847a35be2Sscw struct aoutm68k_stat12 ast;
139893faeaeSdsl struct stat sb;
14047a35be2Sscw int error;
14147a35be2Sscw
142c9a93c8cSad error = do_sys_fstat(SCARG(uap, fd), &sb);
143893faeaeSdsl if (error != 0)
144893faeaeSdsl return error;
14547a35be2Sscw
146893faeaeSdsl aoutm68k_stat12_convert(&sb, &ast);
14747a35be2Sscw
148893faeaeSdsl return copyout(&ast, SCARG(uap, sb), sizeof(ast));
14947a35be2Sscw }
15047a35be2Sscw
15147a35be2Sscw int
aoutm68k_compat_12_sys_lstat(struct lwp * l,const struct aoutm68k_compat_12_sys_lstat_args * uap,register_t * retval)1527e2790cfSdsl aoutm68k_compat_12_sys_lstat(struct lwp *l, const struct aoutm68k_compat_12_sys_lstat_args *uap, register_t *retval)
15347a35be2Sscw {
15447a35be2Sscw struct aoutm68k_stat12 ast;
155893faeaeSdsl struct stat sb;
15647a35be2Sscw int error;
15747a35be2Sscw
158c9a93c8cSad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
159893faeaeSdsl if (error)
160893faeaeSdsl return error;
16147a35be2Sscw
162893faeaeSdsl aoutm68k_stat12_convert(&sb, &ast);
16347a35be2Sscw
164893faeaeSdsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
16547a35be2Sscw }
16647a35be2Sscw #endif /* COMPAT_12 */
16747a35be2Sscw
16847a35be2Sscw int
aoutm68k_sys___stat13(struct lwp * l,const struct aoutm68k_sys___stat13_args * uap,register_t * retval)1697e2790cfSdsl aoutm68k_sys___stat13(struct lwp *l, const struct aoutm68k_sys___stat13_args *uap, register_t *retval)
17047a35be2Sscw {
17147a35be2Sscw struct aoutm68k_stat ast;
172893faeaeSdsl struct stat sb;
17347a35be2Sscw int error;
17447a35be2Sscw
175c9a93c8cSad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
176893faeaeSdsl if (error)
177893faeaeSdsl return error;
17847a35be2Sscw
179893faeaeSdsl aoutm68k_stat13_convert(&sb, &ast);
18047a35be2Sscw
181893faeaeSdsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
18247a35be2Sscw }
18347a35be2Sscw
18447a35be2Sscw int
aoutm68k_sys___fstat13(struct lwp * l,const struct aoutm68k_sys___fstat13_args * uap,register_t * retval)1857e2790cfSdsl aoutm68k_sys___fstat13(struct lwp *l, const struct aoutm68k_sys___fstat13_args *uap, register_t *retval)
18647a35be2Sscw {
18747a35be2Sscw struct aoutm68k_stat ast;
188893faeaeSdsl struct stat sb;
18947a35be2Sscw int error;
19047a35be2Sscw
191c9a93c8cSad error = do_sys_fstat(SCARG(uap, fd), &sb);
192893faeaeSdsl if (error != 0)
193893faeaeSdsl return error;
19447a35be2Sscw
195893faeaeSdsl aoutm68k_stat13_convert(&sb, &ast);
19647a35be2Sscw
197893faeaeSdsl return copyout(&ast, SCARG(uap, sb), sizeof(ast));
19847a35be2Sscw
19947a35be2Sscw }
20047a35be2Sscw
20147a35be2Sscw int
aoutm68k_sys___lstat13(struct lwp * l,const struct aoutm68k_sys___lstat13_args * uap,register_t * retval)2027e2790cfSdsl aoutm68k_sys___lstat13(struct lwp *l, const struct aoutm68k_sys___lstat13_args *uap, register_t *retval)
20347a35be2Sscw {
20447a35be2Sscw struct aoutm68k_stat ast;
205893faeaeSdsl struct stat sb;
20647a35be2Sscw int error;
20747a35be2Sscw
208c9a93c8cSad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
209893faeaeSdsl if (error)
210893faeaeSdsl return error;
21147a35be2Sscw
212893faeaeSdsl aoutm68k_stat13_convert(&sb, &ast);
21347a35be2Sscw
214893faeaeSdsl return copyout(&ast, SCARG(uap, ub), sizeof(ast));
21547a35be2Sscw }
21647a35be2Sscw
21747a35be2Sscw int
aoutm68k_sys_fhstat(struct lwp * l,const struct aoutm68k_sys_fhstat_args * uap,register_t * retval)2187e2790cfSdsl aoutm68k_sys_fhstat(struct lwp *l, const struct aoutm68k_sys_fhstat_args *uap, register_t *retval)
21947a35be2Sscw {
22047a35be2Sscw struct aoutm68k_stat ast;
221906b9af2Sdsl struct stat sb;
22247a35be2Sscw int error;
22347a35be2Sscw
224906b9af2Sdsl error = do_fhstat(l, SCARG(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
225906b9af2Sdsl if (error)
226906b9af2Sdsl return error;
22747a35be2Sscw
228906b9af2Sdsl aoutm68k_stat13_convert(&sb, &ast);
229906b9af2Sdsl return copyout(&sb, SCARG(uap, sb), sizeof(sb));
23047a35be2Sscw }
23147a35be2Sscw
23247a35be2Sscw #ifdef COMPAT_43
23347a35be2Sscw static void
aoutm68k_stat43_convert(struct stat * st,struct aoutm68k_stat43 * ast)23428bae79bSdsl aoutm68k_stat43_convert(struct stat *st, struct aoutm68k_stat43 *ast)
23547a35be2Sscw {
23647a35be2Sscw
23747a35be2Sscw memset(ast, 0, sizeof(*ast));
23847a35be2Sscw ast->st_dev = st->st_dev;
23947a35be2Sscw ast->st_ino = st->st_ino;
24047a35be2Sscw ast->st_mode = st->st_mode;
24147a35be2Sscw ast->st_nlink = st->st_nlink;
24247a35be2Sscw ast->st_uid = st->st_uid;
24347a35be2Sscw ast->st_gid = st->st_gid;
24447a35be2Sscw ast->st_rdev = st->st_rdev;
245893faeaeSdsl if (st->st_size < (off_t)1 << 32)
24647a35be2Sscw ast->st_size = st->st_size;
247893faeaeSdsl else
248893faeaeSdsl ast->st_size = -2;
24947a35be2Sscw ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
25047a35be2Sscw ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
25147a35be2Sscw ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
25247a35be2Sscw ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
25347a35be2Sscw ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
25447a35be2Sscw ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
25547a35be2Sscw ast->st_blksize = st->st_blksize;
25647a35be2Sscw ast->st_blocks = st->st_blocks;
25747a35be2Sscw ast->st_flags = st->st_flags;
25847a35be2Sscw ast->st_gen = st->st_gen;
25947a35be2Sscw }
26047a35be2Sscw #endif /* COMPAT_43 */
26147a35be2Sscw
26247a35be2Sscw #ifdef COMPAT_12
26347a35be2Sscw static void
aoutm68k_stat12_convert(struct stat * st,struct aoutm68k_stat12 * ast)26428bae79bSdsl aoutm68k_stat12_convert(struct stat *st, struct aoutm68k_stat12 *ast)
26547a35be2Sscw {
26647a35be2Sscw
26747a35be2Sscw memset(ast, 0, sizeof(*ast));
26847a35be2Sscw ast->st_dev = st->st_dev;
26947a35be2Sscw ast->st_ino = st->st_ino;
27047a35be2Sscw ast->st_mode = st->st_mode;
27147a35be2Sscw ast->st_nlink = st->st_nlink;
27247a35be2Sscw ast->st_uid = st->st_uid;
27347a35be2Sscw ast->st_gid = st->st_gid;
27447a35be2Sscw ast->st_rdev = st->st_rdev;
27547a35be2Sscw ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
27647a35be2Sscw ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
27747a35be2Sscw ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
27847a35be2Sscw ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
27947a35be2Sscw ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
28047a35be2Sscw ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
281893faeaeSdsl if (st->st_size < (off_t)1 << 32)
28247a35be2Sscw ast->st_size = st->st_size;
283893faeaeSdsl else
284893faeaeSdsl ast->st_size = -2;
28547a35be2Sscw ast->st_blocks = st->st_blocks;
28647a35be2Sscw ast->st_blksize = st->st_blksize;
28747a35be2Sscw ast->st_flags = st->st_flags;
28847a35be2Sscw ast->st_gen = st->st_gen;
28947a35be2Sscw }
29047a35be2Sscw #endif /* COMPAT_12 */
29147a35be2Sscw
29247a35be2Sscw static void
aoutm68k_stat13_convert(struct stat * st,struct aoutm68k_stat * ast)29328bae79bSdsl aoutm68k_stat13_convert(struct stat *st, struct aoutm68k_stat *ast)
29447a35be2Sscw {
29547a35be2Sscw
29647a35be2Sscw memset(ast, 0, sizeof(*ast));
29747a35be2Sscw ast->st_dev = st->st_dev;
29847a35be2Sscw ast->st_ino = st->st_ino;
29947a35be2Sscw ast->st_mode = st->st_mode;
30047a35be2Sscw ast->st_nlink = st->st_nlink;
30147a35be2Sscw ast->st_uid = st->st_uid;
30247a35be2Sscw ast->st_gid = st->st_gid;
30347a35be2Sscw ast->st_rdev = st->st_rdev;
30447a35be2Sscw ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
30547a35be2Sscw ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
30647a35be2Sscw ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
30747a35be2Sscw ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
30847a35be2Sscw ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
30947a35be2Sscw ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
310893faeaeSdsl if (st->st_size < (off_t)1 << 32)
31147a35be2Sscw ast->st_size = st->st_size;
312893faeaeSdsl else
313893faeaeSdsl ast->st_size = -2;
31447a35be2Sscw ast->st_blocks = st->st_blocks;
31547a35be2Sscw ast->st_blksize = st->st_blksize;
31647a35be2Sscw ast->st_flags = st->st_flags;
31747a35be2Sscw ast->st_gen = st->st_gen;
3180a34406cShe ast->st_qspare[0] = 0;
3190a34406cShe ast->st_qspare[1] = 0;
32047a35be2Sscw }
321