Home | History | Annotate | Line # | Download | only in aoutm68k
aoutm68k_stat.c revision 1.23
      1  1.23        ad /*	$NetBSD: aoutm68k_stat.c,v 1.23 2008/03/23 13:58:47 ad Exp $	*/
      2   1.1       scw 
      3   1.1       scw /*-
      4   1.1       scw  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5   1.1       scw  * All rights reserved.
      6   1.1       scw  *
      7   1.1       scw  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1       scw  * by Steve C. Woodford.
      9   1.1       scw  *
     10   1.1       scw  * Redistribution and use in source and binary forms, with or without
     11   1.1       scw  * modification, are permitted provided that the following conditions
     12   1.1       scw  * are met:
     13   1.1       scw  * 1. Redistributions of source code must retain the above copyright
     14   1.1       scw  *    notice, this list of conditions and the following disclaimer.
     15   1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       scw  *    documentation and/or other materials provided with the distribution.
     18   1.1       scw  * 3. All advertising materials mentioning features or use of this software
     19   1.1       scw  *    must display the following acknowledgement:
     20   1.1       scw  *        This product includes software developed by the NetBSD
     21   1.1       scw  *        Foundation, Inc. and its contributors.
     22   1.1       scw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1       scw  *    contributors may be used to endorse or promote products derived
     24   1.1       scw  *    from this software without specific prior written permission.
     25   1.1       scw  *
     26   1.1       scw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1       scw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1       scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1       scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1       scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1       scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1       scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1       scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1       scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1       scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1       scw  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1       scw  */
     38   1.5     lukem 
     39   1.5     lukem #include <sys/cdefs.h>
     40  1.23        ad __KERNEL_RCSID(0, "$NetBSD: aoutm68k_stat.c,v 1.23 2008/03/23 13:58:47 ad Exp $");
     41   1.1       scw 
     42   1.4       mrg #if defined(_KERNEL_OPT)
     43   1.1       scw #include "opt_compat_netbsd.h"
     44   1.1       scw #include "opt_compat_43.h"
     45   1.2  jdolecek #endif
     46   1.1       scw 
     47   1.1       scw #include <sys/param.h>
     48   1.1       scw #include <sys/systm.h>
     49  1.18       dsl #include <sys/filedesc.h>
     50   1.1       scw #include <sys/mount.h>
     51  1.18       dsl #include <sys/namei.h>
     52   1.1       scw #include <sys/proc.h>
     53   1.1       scw #include <sys/stat.h>
     54  1.18       dsl #include <sys/vfs_syscalls.h>
     55   1.1       scw 
     56   1.1       scw #include <sys/syscall.h>
     57   1.1       scw #include <sys/syscallargs.h>
     58   1.1       scw 
     59  1.12        he #include <compat/sys/stat.h>
     60  1.12        he 
     61   1.1       scw #include <compat/aoutm68k/aoutm68k_util.h>
     62   1.1       scw #include <compat/aoutm68k/aoutm68k_stat.h>
     63   1.1       scw #include <compat/aoutm68k/aoutm68k_syscall.h>
     64   1.1       scw #include <compat/aoutm68k/aoutm68k_syscallargs.h>
     65   1.1       scw 
     66   1.1       scw #ifdef COMPAT_43
     67  1.18       dsl static void aoutm68k_stat43_convert(struct stat *, struct aoutm68k_stat43 *);
     68   1.1       scw #endif
     69   1.1       scw #ifdef COMPAT_12
     70  1.18       dsl static void aoutm68k_stat12_convert(struct stat *, struct aoutm68k_stat12 *);
     71   1.1       scw #endif
     72   1.1       scw static void aoutm68k_stat13_convert(struct stat *, struct aoutm68k_stat *);
     73   1.1       scw 
     74   1.1       scw 
     75   1.1       scw #ifdef COMPAT_43
     76   1.1       scw int
     77  1.22       dsl aoutm68k_compat_43_sys_stat(struct lwp *l, const struct aoutm68k_compat_43_sys_stat_args *uap, register_t *retval)
     78   1.1       scw {
     79   1.1       scw 	struct aoutm68k_stat43 ast;
     80  1.18       dsl 	struct stat sb;
     81   1.1       scw 	int error;
     82   1.1       scw 
     83  1.23        ad 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
     84  1.18       dsl 	if (error)
     85  1.18       dsl 		return error;
     86   1.1       scw 
     87  1.18       dsl 	aoutm68k_stat43_convert(&sb, &ast);
     88   1.1       scw 
     89  1.18       dsl 	return copyout(&ast, SCARG(uap, ub), sizeof(ast));
     90   1.1       scw }
     91   1.1       scw 
     92   1.1       scw int
     93  1.22       dsl aoutm68k_compat_43_sys_fstat(struct lwp *l, const struct aoutm68k_compat_43_sys_fstat_args *uap, register_t *retval)
     94   1.1       scw {
     95   1.1       scw 	struct aoutm68k_stat43 ast;
     96  1.18       dsl 	struct stat sb;
     97   1.1       scw 	int error;
     98   1.1       scw 
     99  1.23        ad 	error = do_sys_fstat(SCARG(uap, fd), &sb);
    100  1.18       dsl 	if (error != 0)
    101  1.18       dsl 		return error;
    102   1.1       scw 
    103  1.18       dsl 	aoutm68k_stat43_convert(&sb, &ast);
    104   1.1       scw 
    105  1.18       dsl 	return copyout(&ast, SCARG(uap, sb), sizeof(ast));
    106   1.1       scw }
    107   1.1       scw 
    108   1.1       scw int
    109  1.22       dsl aoutm68k_compat_43_sys_lstat(struct lwp *l, const struct aoutm68k_compat_43_sys_lstat_args *uap, register_t *retval)
    110   1.1       scw {
    111   1.1       scw 	struct aoutm68k_stat43 ast;
    112  1.18       dsl 	struct stat sb;
    113   1.1       scw 	int error;
    114   1.1       scw 
    115  1.23        ad 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    116  1.18       dsl 	if (error)
    117  1.18       dsl 		return error;
    118   1.1       scw 
    119  1.18       dsl 	aoutm68k_stat43_convert(&sb, &ast);
    120   1.1       scw 
    121  1.18       dsl 	return copyout(&ast, SCARG(uap, ub), sizeof(ast));
    122   1.1       scw }
    123   1.1       scw #endif /* COMPAT_43 */
    124   1.1       scw 
    125   1.1       scw #ifdef COMPAT_12
    126   1.1       scw int
    127  1.22       dsl aoutm68k_compat_12_sys_stat(struct lwp *l, const struct aoutm68k_compat_12_sys_stat_args *uap, register_t *retval)
    128   1.1       scw {
    129   1.1       scw 	struct aoutm68k_stat12 ast;
    130  1.18       dsl 	struct stat sb;
    131   1.1       scw 	int error;
    132   1.1       scw 
    133  1.23        ad 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    134  1.18       dsl 	if (error)
    135  1.18       dsl 		return error;
    136   1.1       scw 
    137  1.18       dsl 	aoutm68k_stat12_convert(&sb, &ast);
    138   1.1       scw 
    139  1.18       dsl 	return copyout(&ast, SCARG(uap, ub), sizeof(ast));
    140   1.1       scw }
    141   1.1       scw 
    142   1.1       scw int
    143  1.22       dsl aoutm68k_compat_12_sys_fstat(struct lwp *l, const struct aoutm68k_compat_12_sys_fstat_args *uap, register_t *retval)
    144   1.1       scw {
    145   1.1       scw 	struct aoutm68k_stat12 ast;
    146  1.18       dsl 	struct stat sb;
    147   1.1       scw 	int error;
    148   1.1       scw 
    149  1.23        ad 	error = do_sys_fstat(SCARG(uap, fd), &sb);
    150  1.18       dsl 	if (error != 0)
    151  1.18       dsl 		return error;
    152   1.1       scw 
    153  1.18       dsl 	aoutm68k_stat12_convert(&sb, &ast);
    154   1.1       scw 
    155  1.18       dsl 	return copyout(&ast, SCARG(uap, sb), sizeof(ast));
    156   1.1       scw }
    157   1.1       scw 
    158   1.1       scw int
    159  1.22       dsl aoutm68k_compat_12_sys_lstat(struct lwp *l, const struct aoutm68k_compat_12_sys_lstat_args *uap, register_t *retval)
    160   1.1       scw {
    161   1.1       scw 	struct aoutm68k_stat12 ast;
    162  1.18       dsl 	struct stat sb;
    163   1.1       scw 	int error;
    164   1.1       scw 
    165  1.23        ad 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    166  1.18       dsl 	if (error)
    167  1.18       dsl 		return error;
    168   1.1       scw 
    169  1.18       dsl 	aoutm68k_stat12_convert(&sb, &ast);
    170   1.1       scw 
    171  1.18       dsl 	return copyout(&ast, SCARG(uap, ub), sizeof(ast));
    172   1.1       scw }
    173   1.1       scw #endif /* COMPAT_12 */
    174   1.1       scw 
    175   1.1       scw int
    176  1.22       dsl aoutm68k_sys___stat13(struct lwp *l, const struct aoutm68k_sys___stat13_args *uap, register_t *retval)
    177   1.1       scw {
    178   1.1       scw 	struct aoutm68k_stat ast;
    179  1.18       dsl 	struct stat sb;
    180   1.1       scw 	int error;
    181   1.1       scw 
    182  1.23        ad 	error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
    183  1.18       dsl 	if (error)
    184  1.18       dsl 		return error;
    185   1.1       scw 
    186  1.18       dsl 	aoutm68k_stat13_convert(&sb, &ast);
    187   1.1       scw 
    188  1.18       dsl 	return copyout(&ast, SCARG(uap, ub), sizeof(ast));
    189   1.1       scw }
    190   1.1       scw 
    191   1.1       scw int
    192  1.22       dsl aoutm68k_sys___fstat13(struct lwp *l, const struct aoutm68k_sys___fstat13_args *uap, register_t *retval)
    193   1.1       scw {
    194   1.1       scw 	struct aoutm68k_stat ast;
    195  1.18       dsl 	struct stat sb;
    196   1.1       scw 	int error;
    197   1.1       scw 
    198  1.23        ad 	error = do_sys_fstat(SCARG(uap, fd), &sb);
    199  1.18       dsl 	if (error != 0)
    200  1.18       dsl 		return error;
    201   1.1       scw 
    202  1.18       dsl 	aoutm68k_stat13_convert(&sb, &ast);
    203   1.1       scw 
    204  1.18       dsl 	return copyout(&ast, SCARG(uap, sb), sizeof(ast));
    205   1.1       scw 
    206   1.1       scw }
    207   1.1       scw 
    208   1.1       scw int
    209  1.22       dsl aoutm68k_sys___lstat13(struct lwp *l, const struct aoutm68k_sys___lstat13_args *uap, register_t *retval)
    210   1.1       scw {
    211   1.1       scw 	struct aoutm68k_stat ast;
    212  1.18       dsl 	struct stat sb;
    213   1.1       scw 	int error;
    214   1.1       scw 
    215  1.23        ad 	error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
    216  1.18       dsl 	if (error)
    217  1.18       dsl 		return error;
    218   1.1       scw 
    219  1.18       dsl 	aoutm68k_stat13_convert(&sb, &ast);
    220   1.1       scw 
    221  1.18       dsl 	return copyout(&ast, SCARG(uap, ub), sizeof(ast));
    222   1.1       scw }
    223   1.1       scw 
    224   1.1       scw int
    225  1.22       dsl aoutm68k_sys_fhstat(struct lwp *l, const struct aoutm68k_sys_fhstat_args *uap, register_t *retval)
    226   1.1       scw {
    227   1.1       scw 	struct aoutm68k_stat ast;
    228  1.20       dsl 	struct stat sb;
    229   1.1       scw 	int error;
    230   1.1       scw 
    231  1.20       dsl 	error = do_fhstat(l, SCARG(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
    232  1.20       dsl 	if (error)
    233  1.20       dsl 		return error;
    234   1.1       scw 
    235  1.20       dsl 	aoutm68k_stat13_convert(&sb, &ast);
    236  1.20       dsl 	return copyout(&sb, SCARG(uap, sb), sizeof(sb));
    237   1.1       scw }
    238   1.1       scw 
    239   1.1       scw #ifdef COMPAT_43
    240   1.1       scw static void
    241  1.21       dsl aoutm68k_stat43_convert(struct stat *st, struct aoutm68k_stat43 *ast)
    242   1.1       scw {
    243   1.1       scw 
    244   1.1       scw 	memset(ast, 0, sizeof(*ast));
    245   1.1       scw 	ast->st_dev = st->st_dev;
    246   1.1       scw 	ast->st_ino = st->st_ino;
    247   1.1       scw 	ast->st_mode = st->st_mode;
    248   1.1       scw 	ast->st_nlink = st->st_nlink;
    249   1.1       scw 	ast->st_uid = st->st_uid;
    250   1.1       scw 	ast->st_gid = st->st_gid;
    251   1.1       scw 	ast->st_rdev = st->st_rdev;
    252  1.18       dsl 	if (st->st_size < (off_t)1 << 32)
    253  1.18       dsl 		ast->st_size = st->st_size;
    254  1.18       dsl 	else
    255  1.18       dsl 		ast->st_size = -2;
    256   1.1       scw 	ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
    257   1.1       scw 	ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
    258   1.1       scw 	ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
    259   1.1       scw 	ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
    260   1.1       scw 	ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
    261   1.1       scw 	ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
    262   1.1       scw 	ast->st_blksize = st->st_blksize;
    263   1.1       scw 	ast->st_blocks = st->st_blocks;
    264   1.1       scw 	ast->st_flags = st->st_flags;
    265   1.1       scw 	ast->st_gen = st->st_gen;
    266   1.1       scw }
    267   1.1       scw #endif /* COMPAT_43 */
    268   1.1       scw 
    269   1.1       scw #ifdef COMPAT_12
    270   1.1       scw static void
    271  1.21       dsl aoutm68k_stat12_convert(struct stat *st, struct aoutm68k_stat12 *ast)
    272   1.1       scw {
    273   1.1       scw 
    274   1.1       scw 	memset(ast, 0, sizeof(*ast));
    275   1.1       scw 	ast->st_dev = st->st_dev;
    276   1.1       scw 	ast->st_ino = st->st_ino;
    277   1.1       scw 	ast->st_mode = st->st_mode;
    278   1.1       scw 	ast->st_nlink = st->st_nlink;
    279   1.1       scw 	ast->st_uid = st->st_uid;
    280   1.1       scw 	ast->st_gid = st->st_gid;
    281   1.1       scw 	ast->st_rdev = st->st_rdev;
    282   1.1       scw 	ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
    283   1.1       scw 	ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
    284   1.1       scw 	ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
    285   1.1       scw 	ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
    286   1.1       scw 	ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
    287   1.1       scw 	ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
    288  1.18       dsl 	if (st->st_size < (off_t)1 << 32)
    289  1.18       dsl 		ast->st_size = st->st_size;
    290  1.18       dsl 	else
    291  1.18       dsl 		ast->st_size = -2;
    292   1.1       scw 	ast->st_blocks = st->st_blocks;
    293   1.1       scw 	ast->st_blksize = st->st_blksize;
    294   1.1       scw 	ast->st_flags = st->st_flags;
    295   1.1       scw 	ast->st_gen = st->st_gen;
    296   1.1       scw }
    297   1.1       scw #endif /* COMPAT_12 */
    298   1.1       scw 
    299   1.1       scw static void
    300  1.21       dsl aoutm68k_stat13_convert(struct stat *st, struct aoutm68k_stat *ast)
    301   1.1       scw {
    302   1.1       scw 
    303   1.1       scw 	memset(ast, 0, sizeof(*ast));
    304   1.1       scw 	ast->st_dev = st->st_dev;
    305   1.1       scw 	ast->st_ino = st->st_ino;
    306   1.1       scw 	ast->st_mode = st->st_mode;
    307   1.1       scw 	ast->st_nlink = st->st_nlink;
    308   1.1       scw 	ast->st_uid = st->st_uid;
    309   1.1       scw 	ast->st_gid = st->st_gid;
    310   1.1       scw 	ast->st_rdev = st->st_rdev;
    311   1.1       scw 	ast->st_atimespec.tv_sec = st->st_atimespec.tv_sec;
    312   1.1       scw 	ast->st_atimespec.tv_nsec = st->st_atimespec.tv_nsec;
    313   1.1       scw 	ast->st_mtimespec.tv_sec = st->st_mtimespec.tv_sec;
    314   1.1       scw 	ast->st_mtimespec.tv_nsec = st->st_mtimespec.tv_nsec;
    315   1.1       scw 	ast->st_ctimespec.tv_sec = st->st_ctimespec.tv_sec;
    316   1.1       scw 	ast->st_ctimespec.tv_nsec = st->st_ctimespec.tv_nsec;
    317  1.18       dsl 	if (st->st_size < (off_t)1 << 32)
    318  1.18       dsl 		ast->st_size = st->st_size;
    319  1.18       dsl 	else
    320  1.18       dsl 		ast->st_size = -2;
    321   1.1       scw 	ast->st_blocks = st->st_blocks;
    322   1.1       scw 	ast->st_blksize = st->st_blksize;
    323   1.1       scw 	ast->st_flags = st->st_flags;
    324   1.1       scw 	ast->st_gen = st->st_gen;
    325   1.8        he 	ast->st_qspare[0] = 0;
    326   1.8        he 	ast->st_qspare[1] = 0;
    327   1.1       scw }
    328