Home | History | Annotate | Line # | Download | only in aoutm68k
aoutm68k_stat.c revision 1.17
      1 /*	$NetBSD: aoutm68k_stat.c,v 1.17 2007/03/04 06:01:12 christos 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.17 2007/03/04 06:01:12 christos 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/mount.h>
     50 #include <sys/proc.h>
     51 #include <sys/stat.h>
     52 
     53 #include <sys/syscall.h>
     54 #include <sys/syscallargs.h>
     55 
     56 #include <compat/sys/stat.h>
     57 
     58 #include <compat/aoutm68k/aoutm68k_util.h>
     59 #include <compat/aoutm68k/aoutm68k_stat.h>
     60 #include <compat/aoutm68k/aoutm68k_syscall.h>
     61 #include <compat/aoutm68k/aoutm68k_syscallargs.h>
     62 
     63 #ifdef COMPAT_43
     64 static void aoutm68k_stat43_convert(struct stat43 *, struct aoutm68k_stat43 *);
     65 #endif
     66 #ifdef COMPAT_12
     67 static void aoutm68k_stat12_convert(struct stat12 *, struct aoutm68k_stat12 *);
     68 #endif
     69 static void aoutm68k_stat13_convert(struct stat *, struct aoutm68k_stat *);
     70 
     71 
     72 #ifdef COMPAT_43
     73 int
     74 aoutm68k_compat_43_sys_stat(l, v, retval)
     75 	struct lwp *l;
     76 	void *v;
     77 	register_t *retval;
     78 {
     79 	struct aoutm68k_compat_43_sys_stat_args *uap = v;
     80 	struct proc *p = l->l_proc;
     81 	void *sg = stackgap_init(p, 0);
     82 	struct compat_43_sys_stat_args cup;
     83 	struct aoutm68k_stat43 ast;
     84 	struct stat43 st;
     85 	int error;
     86 
     87 	SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st));
     88 #ifdef COMPAT_AOUT_ALTPATH
     89 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
     90 #endif
     91 	SCARG(&cup, path) = SCARG(uap, path);
     92 
     93 	if ((error = compat_43_sys_stat(l, &cup, retval)) != 0 ||
     94 	    (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
     95 		return (error);
     96 
     97 	aoutm68k_stat43_convert(&st, &ast);
     98 
     99 	return (copyout((void *)&ast, (void *)SCARG(uap, ub), sizeof(ast)));
    100 }
    101 
    102 int
    103 aoutm68k_compat_43_sys_fstat(l, v, retval)
    104 	struct lwp *l;
    105 	void *v;
    106 	register_t *retval;
    107 {
    108 	struct aoutm68k_compat_43_sys_fstat_args *uap = v;
    109 	struct proc *p = l->l_proc;
    110 	void *sg = stackgap_init(p, 0);
    111 	struct compat_43_sys_fstat_args cup;
    112 	struct aoutm68k_stat43 ast;
    113 	struct stat43 st;
    114 	int error;
    115 
    116 	SCARG(&cup, fd) = SCARG(uap, fd);
    117 	SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st));
    118 
    119 	if ((error = compat_43_sys_fstat(l, &cup, retval)) != 0 ||
    120 	    (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
    121 		return (error);
    122 
    123 	aoutm68k_stat43_convert(&st, &ast);
    124 
    125 	return (copyout((void *)&ast, (void *)SCARG(uap, sb), sizeof(ast)));
    126 }
    127 
    128 int
    129 aoutm68k_compat_43_sys_lstat(l, v, retval)
    130 	struct lwp *l;
    131 	void *v;
    132 	register_t *retval;
    133 {
    134 	struct aoutm68k_compat_43_sys_lstat_args *uap = v;
    135 	struct proc *p = l->l_proc;
    136 	void *sg = stackgap_init(p, 0);
    137 	struct compat_43_sys_lstat_args cup;
    138 	struct aoutm68k_stat43 ast;
    139 	struct stat43 st;
    140 	int error;
    141 
    142 	SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st));
    143 #ifdef COMPAT_AOUT_ALTPATH
    144 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    145 #endif
    146 	SCARG(&cup, path) = SCARG(uap, path);
    147 
    148 	if ((error = compat_43_sys_lstat(l, &cup, retval)) != 0 ||
    149 	    (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
    150 		return (error);
    151 
    152 	aoutm68k_stat43_convert(&st, &ast);
    153 
    154 	return (copyout((void *)&ast, (void *)SCARG(uap, ub), sizeof(ast)));
    155 }
    156 #endif /* COMPAT_43 */
    157 
    158 #ifdef COMPAT_12
    159 int
    160 aoutm68k_compat_12_sys_stat(l, v, retval)
    161 	struct lwp *l;
    162 	void *v;
    163 	register_t *retval;
    164 {
    165 	struct aoutm68k_compat_12_sys_stat_args *uap = v;
    166 	struct proc *p = l->l_proc;
    167 	void *sg = stackgap_init(p, 0);
    168 	struct compat_12_sys_stat_args cup;
    169 	struct aoutm68k_stat12 ast;
    170 	struct stat12 st;
    171 	int error;
    172 
    173 	SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st));
    174 #ifdef COMPAT_AOUT_ALTPATH
    175 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    176 #endif
    177 	SCARG(&cup, path) = SCARG(uap, path);
    178 
    179 	if ((error = compat_12_sys_stat(l, &cup, retval)) != 0 ||
    180 	    (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
    181 		return (error);
    182 
    183 	aoutm68k_stat12_convert(&st, &ast);
    184 
    185 	return (copyout((void *)&ast, (void *)SCARG(uap, ub), sizeof(ast)));
    186 }
    187 
    188 int
    189 aoutm68k_compat_12_sys_fstat(l, v, retval)
    190 	struct lwp *l;
    191 	void *v;
    192 	register_t *retval;
    193 {
    194 	struct aoutm68k_compat_12_sys_fstat_args *uap = v;
    195 	struct proc *p = l->l_proc;
    196 	void *sg = stackgap_init(p, 0);
    197 	struct compat_12_sys_fstat_args cup;
    198 	struct aoutm68k_stat12 ast;
    199 	struct stat12 st;
    200 	int error;
    201 
    202 	SCARG(&cup, fd) = SCARG(uap, fd);
    203 	SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st));
    204 
    205 	if ((error = compat_12_sys_fstat(l, &cup, retval)) != 0 ||
    206 	    (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
    207 		return (error);
    208 
    209 	aoutm68k_stat12_convert(&st, &ast);
    210 
    211 	return (copyout((void *)&ast, (void *)SCARG(uap, sb), sizeof(ast)));
    212 }
    213 
    214 int
    215 aoutm68k_compat_12_sys_lstat(l, v, retval)
    216 	struct lwp *l;
    217 	void *v;
    218 	register_t *retval;
    219 {
    220 	struct aoutm68k_compat_12_sys_lstat_args *uap = v;
    221 	struct proc *p = l->l_proc;
    222 	void *sg = stackgap_init(p, 0);
    223 	struct compat_12_sys_lstat_args cup;
    224 	struct aoutm68k_stat12 ast;
    225 	struct stat12 st;
    226 	int error;
    227 
    228 	SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st));
    229 #ifdef COMPAT_AOUT_ALTPATH
    230 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    231 #endif
    232 	SCARG(&cup, path) = SCARG(uap, path);
    233 
    234 	if ((error = compat_12_sys_lstat(l, &cup, retval)) != 0 ||
    235 	    (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
    236 		return (error);
    237 
    238 	aoutm68k_stat12_convert(&st, &ast);
    239 
    240 	return (copyout((void *)&ast, (void *)SCARG(uap, ub), sizeof(ast)));
    241 }
    242 #endif /* COMPAT_12 */
    243 
    244 int
    245 aoutm68k_sys___stat13(l, v, retval)
    246 	struct lwp *l;
    247 	void *v;
    248 	register_t *retval;
    249 {
    250 	struct aoutm68k_sys___stat13_args *uap = v;
    251 	struct proc *p = l->l_proc;
    252 	void *sg = stackgap_init(p, 0);
    253 	struct sys___stat30_args cup;
    254 	struct aoutm68k_stat ast;
    255 	struct stat st;
    256 	int error;
    257 
    258 	SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st));
    259 #ifdef COMPAT_AOUT_ALTPATH
    260 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    261 #endif
    262 	SCARG(&cup, path) = SCARG(uap, path);
    263 
    264 	if ((error = sys___stat30(l, &cup, retval)) != 0 ||
    265 	    (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
    266 		return (error);
    267 
    268 	aoutm68k_stat13_convert(&st, &ast);
    269 
    270 	return (copyout((void *)&ast, (void *)SCARG(uap, ub), sizeof(ast)));
    271 }
    272 
    273 int
    274 aoutm68k_sys___fstat13(l, v, retval)
    275 	struct lwp *l;
    276 	void *v;
    277 	register_t *retval;
    278 {
    279 	struct aoutm68k_sys___fstat13_args *uap = v;
    280 	struct proc *p = l->l_proc;
    281 	void *sg = stackgap_init(p, 0);
    282 	struct sys___fstat30_args cup;
    283 	struct aoutm68k_stat ast;
    284 	struct stat st;
    285 	int error;
    286 
    287 	SCARG(&cup, fd) = SCARG(uap, fd);
    288 	SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st));
    289 
    290 	if ((error = sys___fstat30(l, &cup, retval)) != 0 ||
    291 	    (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
    292 		return (error);
    293 
    294 	aoutm68k_stat13_convert(&st, &ast);
    295 
    296 	return (copyout((void *)&ast, (void *)SCARG(uap, sb), sizeof(ast)));
    297 
    298 }
    299 
    300 int
    301 aoutm68k_sys___lstat13(l, v, retval)
    302 	struct lwp *l;
    303 	void *v;
    304 	register_t *retval;
    305 {
    306 	struct aoutm68k_sys___lstat13_args *uap = v;
    307 	struct proc *p = l->l_proc;
    308 	void *sg = stackgap_init(p, 0);
    309 	struct sys___lstat30_args cup;
    310 	struct aoutm68k_stat ast;
    311 	struct stat st;
    312 	int error;
    313 
    314 	SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(st));
    315 #ifdef COMPAT_AOUT_ALTPATH
    316 	CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
    317 #endif
    318 	SCARG(&cup, path) = SCARG(uap, path);
    319 
    320 	if ((error = sys___lstat30(l, &cup, retval)) != 0 ||
    321 	    (error = copyin(SCARG(&cup, ub), &st, sizeof(st))) != 0)
    322 		return (error);
    323 
    324 	aoutm68k_stat13_convert(&st, &ast);
    325 
    326 	return (copyout((void *)&ast, (void *)SCARG(uap, ub), sizeof(ast)));
    327 }
    328 
    329 int
    330 aoutm68k_sys_fhstat(l, v, retval)
    331 	struct lwp *l;
    332 	void *v;
    333 	register_t *retval;
    334 {
    335 	struct aoutm68k_sys_fhstat_args *uap = v;
    336 	struct proc *p = l->l_proc;
    337 	void *sg = stackgap_init(p, 0);
    338 	struct compat_30_sys___fhstat30_args cup;
    339 	struct aoutm68k_stat ast;
    340 	struct stat st;
    341 	int error;
    342 
    343 	SCARG(&cup, fhp) = SCARG(uap, fhp);
    344 	SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(st));
    345 
    346 	if ((error = compat_30_sys___fhstat30(l, &cup, retval)) != 0 ||
    347 	    (error = copyin(SCARG(&cup, sb), &st, sizeof(st))) != 0)
    348 		return (error);
    349 
    350 	aoutm68k_stat13_convert(&st, &ast);
    351 
    352 	return (copyout((void *)&ast, (void *)SCARG(uap, sb), sizeof(ast)));
    353 }
    354 
    355 #ifdef COMPAT_43
    356 static void
    357 aoutm68k_stat43_convert(st, ast)
    358 	struct stat43 *st;
    359 	struct aoutm68k_stat43 *ast;
    360 {
    361 
    362 	memset(ast, 0, sizeof(*ast));
    363 	ast->st_dev = st->st_dev;
    364 	ast->st_ino = st->st_ino;
    365 	ast->st_mode = st->st_mode;
    366 	ast->st_nlink = st->st_nlink;
    367 	ast->st_uid = st->st_uid;
    368 	ast->st_gid = st->st_gid;
    369 	ast->st_rdev = st->st_rdev;
    370 	ast->st_size = st->st_size;
    371 	ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
    372 	ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
    373 	ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
    374 	ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
    375 	ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
    376 	ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
    377 	ast->st_blksize = st->st_blksize;
    378 	ast->st_blocks = st->st_blocks;
    379 	ast->st_flags = st->st_flags;
    380 	ast->st_gen = st->st_gen;
    381 }
    382 #endif /* COMPAT_43 */
    383 
    384 #ifdef COMPAT_12
    385 static void
    386 aoutm68k_stat12_convert(st, ast)
    387 	struct stat12 *st;
    388 	struct aoutm68k_stat12 *ast;
    389 {
    390 
    391 	memset(ast, 0, sizeof(*ast));
    392 	ast->st_dev = st->st_dev;
    393 	ast->st_ino = st->st_ino;
    394 	ast->st_mode = st->st_mode;
    395 	ast->st_nlink = st->st_nlink;
    396 	ast->st_uid = st->st_uid;
    397 	ast->st_gid = st->st_gid;
    398 	ast->st_rdev = st->st_rdev;
    399 	ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
    400 	ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
    401 	ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
    402 	ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
    403 	ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
    404 	ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
    405 	ast->st_size = st->st_size;
    406 	ast->st_blocks = st->st_blocks;
    407 	ast->st_blksize = st->st_blksize;
    408 	ast->st_flags = st->st_flags;
    409 	ast->st_gen = st->st_gen;
    410 	ast->st_lspare = st->st_lspare;
    411 	ast->st_qspare[0] = st->st_qspare[0];
    412 	ast->st_qspare[1] = st->st_qspare[1];
    413 }
    414 #endif /* COMPAT_12 */
    415 
    416 static void
    417 aoutm68k_stat13_convert(st, ast)
    418 	struct stat *st;
    419 	struct aoutm68k_stat *ast;
    420 {
    421 
    422 	memset(ast, 0, sizeof(*ast));
    423 	ast->st_dev = st->st_dev;
    424 	ast->st_ino = st->st_ino;
    425 	ast->st_mode = st->st_mode;
    426 	ast->st_nlink = st->st_nlink;
    427 	ast->st_uid = st->st_uid;
    428 	ast->st_gid = st->st_gid;
    429 	ast->st_rdev = st->st_rdev;
    430 	ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
    431 	ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
    432 	ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
    433 	ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
    434 	ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
    435 	ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
    436 	ast->st_size = st->st_size;
    437 	ast->st_blocks = st->st_blocks;
    438 	ast->st_blksize = st->st_blksize;
    439 	ast->st_flags = st->st_flags;
    440 	ast->st_gen = st->st_gen;
    441 	ast->st_qspare[0] = 0;
    442 	ast->st_qspare[1] = 0;
    443 }
    444