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