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