Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_30.c revision 1.27.4.2
      1  1.27.4.2  christos /*	$NetBSD: netbsd32_compat_30.c,v 1.27.4.2 2009/01/04 01:56:02 christos Exp $	*/
      2  1.27.4.2  christos 
      3  1.27.4.2  christos /*
      4  1.27.4.2  christos  * Copyright (c) 1998, 2001 Matthew R. Green
      5  1.27.4.2  christos  * All rights reserved.
      6  1.27.4.2  christos  *
      7  1.27.4.2  christos  * Redistribution and use in source and binary forms, with or without
      8  1.27.4.2  christos  * modification, are permitted provided that the following conditions
      9  1.27.4.2  christos  * are met:
     10  1.27.4.2  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.27.4.2  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.27.4.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.27.4.2  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.27.4.2  christos  *    documentation and/or other materials provided with the distribution.
     15  1.27.4.2  christos  *
     16  1.27.4.2  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.27.4.2  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.27.4.2  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.27.4.2  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.27.4.2  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  1.27.4.2  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  1.27.4.2  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  1.27.4.2  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  1.27.4.2  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.27.4.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.27.4.2  christos  * SUCH DAMAGE.
     27  1.27.4.2  christos  */
     28  1.27.4.2  christos 
     29  1.27.4.2  christos #include <sys/cdefs.h>
     30  1.27.4.2  christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.27.4.2 2009/01/04 01:56:02 christos Exp $");
     31  1.27.4.2  christos 
     32  1.27.4.2  christos #include <sys/param.h>
     33  1.27.4.2  christos #include <sys/systm.h>
     34  1.27.4.2  christos #include <sys/malloc.h>
     35  1.27.4.2  christos #include <sys/mount.h>
     36  1.27.4.2  christos #include <sys/socket.h>
     37  1.27.4.2  christos #include <sys/socketvar.h>
     38  1.27.4.2  christos #include <sys/stat.h>
     39  1.27.4.2  christos #include <sys/time.h>
     40  1.27.4.2  christos #include <sys/ktrace.h>
     41  1.27.4.2  christos #include <sys/resourcevar.h>
     42  1.27.4.2  christos #include <sys/vnode.h>
     43  1.27.4.2  christos #include <sys/file.h>
     44  1.27.4.2  christos #include <sys/filedesc.h>
     45  1.27.4.2  christos #include <sys/namei.h>
     46  1.27.4.2  christos #include <sys/statvfs.h>
     47  1.27.4.2  christos #include <sys/syscallargs.h>
     48  1.27.4.2  christos #include <sys/proc.h>
     49  1.27.4.2  christos #include <sys/dirent.h>
     50  1.27.4.2  christos #include <sys/kauth.h>
     51  1.27.4.2  christos #include <sys/vfs_syscalls.h>
     52  1.27.4.2  christos 
     53  1.27.4.2  christos #include <compat/netbsd32/netbsd32.h>
     54  1.27.4.2  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     55  1.27.4.2  christos #include <compat/netbsd32/netbsd32_conv.h>
     56  1.27.4.2  christos #include <compat/sys/mount.h>
     57  1.27.4.2  christos 
     58  1.27.4.2  christos 
     59  1.27.4.2  christos int
     60  1.27.4.2  christos compat_30_netbsd32_getdents(struct lwp *l, const struct compat_30_netbsd32_getdents_args *uap, register_t *retval)
     61  1.27.4.2  christos {
     62  1.27.4.2  christos 	/* {
     63  1.27.4.2  christos 		syscallarg(int) fd;
     64  1.27.4.2  christos 		syscallarg(netbsd32_charp) buf;
     65  1.27.4.2  christos 		syscallarg(netbsd32_size_t) count;
     66  1.27.4.2  christos 	} */
     67  1.27.4.2  christos 	file_t *fp;
     68  1.27.4.2  christos 	int error, done;
     69  1.27.4.2  christos 	char  *buf;
     70  1.27.4.2  christos 	netbsd32_size_t count;
     71  1.27.4.2  christos 
     72  1.27.4.2  christos 	/* Limit the size on any kernel buffers used by VOP_READDIR */
     73  1.27.4.2  christos 	count = min(MAXBSIZE, SCARG(uap, count));
     74  1.27.4.2  christos 
     75  1.27.4.2  christos 	/* fd_getvnode() will use the descriptor for us */
     76  1.27.4.2  christos 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
     77  1.27.4.2  christos 		return (error);
     78  1.27.4.2  christos 	if ((fp->f_flag & FREAD) == 0) {
     79  1.27.4.2  christos 		error = EBADF;
     80  1.27.4.2  christos 		goto out;
     81  1.27.4.2  christos 	}
     82  1.27.4.2  christos 	buf = malloc(count, M_TEMP, M_WAITOK);
     83  1.27.4.2  christos 	error = vn_readdir(fp, buf, UIO_SYSSPACE, count, &done, l, 0, 0);
     84  1.27.4.2  christos 	if (error == 0) {
     85  1.27.4.2  christos 		*retval = netbsd32_to_dirent12(buf, done);
     86  1.27.4.2  christos 		error = copyout(buf, SCARG_P32(uap, buf), *retval);
     87  1.27.4.2  christos 	}
     88  1.27.4.2  christos 	free(buf, M_TEMP);
     89  1.27.4.2  christos  out:
     90  1.27.4.2  christos  	fd_putfile(SCARG(uap, fd));
     91  1.27.4.2  christos 	return (error);
     92  1.27.4.2  christos }
     93  1.27.4.2  christos 
     94  1.27.4.2  christos int
     95  1.27.4.2  christos compat_30_netbsd32___stat13(struct lwp *l, const struct compat_30_netbsd32___stat13_args *uap, register_t *retval)
     96  1.27.4.2  christos {
     97  1.27.4.2  christos 	/* {
     98  1.27.4.2  christos 		syscallarg(const netbsd32_charp) path;
     99  1.27.4.2  christos 		syscallarg(netbsd32_stat13p_t) ub;
    100  1.27.4.2  christos 	} */
    101  1.27.4.2  christos 	struct netbsd32_stat13 sb32;
    102  1.27.4.2  christos 	struct stat sb;
    103  1.27.4.2  christos 	int error;
    104  1.27.4.2  christos 	const char *path;
    105  1.27.4.2  christos 
    106  1.27.4.2  christos 	path = SCARG_P32(uap, path);
    107  1.27.4.2  christos 
    108  1.27.4.2  christos 	error = do_sys_stat(path, FOLLOW, &sb);
    109  1.27.4.2  christos 	if (error)
    110  1.27.4.2  christos 		return (error);
    111  1.27.4.2  christos 	netbsd32_from___stat13(&sb, &sb32);
    112  1.27.4.2  christos 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    113  1.27.4.2  christos 	return (error);
    114  1.27.4.2  christos }
    115  1.27.4.2  christos 
    116  1.27.4.2  christos int
    117  1.27.4.2  christos compat_30_netbsd32___fstat13(struct lwp *l, const struct compat_30_netbsd32___fstat13_args *uap, register_t *retval)
    118  1.27.4.2  christos {
    119  1.27.4.2  christos 	/* {
    120  1.27.4.2  christos 		syscallarg(int) fd;
    121  1.27.4.2  christos 		syscallarg(netbsd32_stat13p_t) sb;
    122  1.27.4.2  christos 	} */
    123  1.27.4.2  christos 	int fd = SCARG(uap, fd);
    124  1.27.4.2  christos 	file_t *fp;
    125  1.27.4.2  christos 	struct netbsd32_stat13 sb32;
    126  1.27.4.2  christos 	struct stat ub;
    127  1.27.4.2  christos 	int error = 0;
    128  1.27.4.2  christos 
    129  1.27.4.2  christos 	if ((fp = fd_getfile(fd)) == NULL)
    130  1.27.4.2  christos 		return (EBADF);
    131  1.27.4.2  christos 	error = (*fp->f_ops->fo_stat)(fp, &ub);
    132  1.27.4.2  christos 	fd_putfile(fd);
    133  1.27.4.2  christos 
    134  1.27.4.2  christos 	if (error == 0) {
    135  1.27.4.2  christos 		netbsd32_from___stat13(&ub, &sb32);
    136  1.27.4.2  christos 		error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    137  1.27.4.2  christos 	}
    138  1.27.4.2  christos 	return (error);
    139  1.27.4.2  christos }
    140  1.27.4.2  christos 
    141  1.27.4.2  christos int
    142  1.27.4.2  christos compat_30_netbsd32___lstat13(struct lwp *l, const struct compat_30_netbsd32___lstat13_args *uap, register_t *retval)
    143  1.27.4.2  christos {
    144  1.27.4.2  christos 	/* {
    145  1.27.4.2  christos 		syscallarg(const netbsd32_charp) path;
    146  1.27.4.2  christos 		syscallarg(netbsd32_stat13p_t) ub;
    147  1.27.4.2  christos 	} */
    148  1.27.4.2  christos 	struct netbsd32_stat13 sb32;
    149  1.27.4.2  christos 	struct stat sb;
    150  1.27.4.2  christos 	int error;
    151  1.27.4.2  christos 	const char *path;
    152  1.27.4.2  christos 
    153  1.27.4.2  christos 	path = SCARG_P32(uap, path);
    154  1.27.4.2  christos 
    155  1.27.4.2  christos 	error = do_sys_stat(path, NOFOLLOW, &sb);
    156  1.27.4.2  christos 	if (error)
    157  1.27.4.2  christos 		return (error);
    158  1.27.4.2  christos 	netbsd32_from___stat13(&sb, &sb32);
    159  1.27.4.2  christos 	error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
    160  1.27.4.2  christos 	return (error);
    161  1.27.4.2  christos }
    162  1.27.4.2  christos 
    163  1.27.4.2  christos int
    164  1.27.4.2  christos compat_30_netbsd32_fhstat(struct lwp *l, const struct compat_30_netbsd32_fhstat_args *uap, register_t *retval)
    165  1.27.4.2  christos {
    166  1.27.4.2  christos 	/* {
    167  1.27.4.2  christos 		syscallarg(const netbsd32_fhandlep_t) fhp;
    168  1.27.4.2  christos 		syscallarg(netbsd32_stat13p_t) sb;
    169  1.27.4.2  christos 	} */
    170  1.27.4.2  christos 	struct stat sb;
    171  1.27.4.2  christos 	struct netbsd32_stat13 sb32;
    172  1.27.4.2  christos 	int error;
    173  1.27.4.2  christos 	struct compat_30_fhandle fh;
    174  1.27.4.2  christos 	struct mount *mp;
    175  1.27.4.2  christos 	struct vnode *vp;
    176  1.27.4.2  christos 
    177  1.27.4.2  christos 	/*
    178  1.27.4.2  christos 	 * Must be super user
    179  1.27.4.2  christos 	 */
    180  1.27.4.2  christos 	if ((error = kauth_authorize_system(l->l_cred,
    181  1.27.4.2  christos 	    KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)))
    182  1.27.4.2  christos 		return (error);
    183  1.27.4.2  christos 
    184  1.27.4.2  christos 	if ((error = copyin(SCARG_P32(uap, fhp), &fh, sizeof(fh))) != 0)
    185  1.27.4.2  christos 		return (error);
    186  1.27.4.2  christos 
    187  1.27.4.2  christos 	if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
    188  1.27.4.2  christos 		return (ESTALE);
    189  1.27.4.2  christos 	if (mp->mnt_op->vfs_fhtovp == NULL)
    190  1.27.4.2  christos 		return EOPNOTSUPP;
    191  1.27.4.2  christos 	if ((error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, &vp)))
    192  1.27.4.2  christos 		return (error);
    193  1.27.4.2  christos 	error = vn_stat(vp, &sb);
    194  1.27.4.2  christos 	vput(vp);
    195  1.27.4.2  christos 	if (error)
    196  1.27.4.2  christos 		return (error);
    197  1.27.4.2  christos 	netbsd32_from___stat13(&sb, &sb32);
    198  1.27.4.2  christos 	error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
    199  1.27.4.2  christos 	return (error);
    200  1.27.4.2  christos }
    201  1.27.4.2  christos 
    202  1.27.4.2  christos int
    203  1.27.4.2  christos compat_30_netbsd32_fhstatvfs1(struct lwp *l, const struct compat_30_netbsd32_fhstatvfs1_args *uap, register_t *retval)
    204  1.27.4.2  christos {
    205  1.27.4.2  christos 	/* {
    206  1.27.4.2  christos 		syscallarg(const netbsd32_fhandlep_t) fhp;
    207  1.27.4.2  christos 		syscallarg(netbsd32_statvfsp_t) buf;
    208  1.27.4.2  christos 		syscallarg(int) flags;
    209  1.27.4.2  christos 	} */
    210  1.27.4.2  christos 	struct statvfs *sbuf;
    211  1.27.4.2  christos 	struct netbsd32_statvfs *s32;
    212  1.27.4.2  christos 	int error;
    213  1.27.4.2  christos 
    214  1.27.4.2  christos 	sbuf = STATVFSBUF_GET();
    215  1.27.4.2  christos 	error = do_fhstatvfs(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, sbuf,
    216  1.27.4.2  christos 	    SCARG(uap, flags));
    217  1.27.4.2  christos 
    218  1.27.4.2  christos 	if (error != 0) {
    219  1.27.4.2  christos 		s32 = malloc(sizeof *s32, M_TEMP, M_WAITOK);
    220  1.27.4.2  christos 		netbsd32_from_statvfs(sbuf, s32);
    221  1.27.4.2  christos 		error = copyout(s32, SCARG_P32(uap, buf), sizeof *s32);
    222  1.27.4.2  christos 		free(s32, M_TEMP);
    223  1.27.4.2  christos 	}
    224  1.27.4.2  christos 	STATVFSBUF_PUT(sbuf);
    225  1.27.4.2  christos 
    226  1.27.4.2  christos 	return (error);
    227  1.27.4.2  christos }
    228  1.27.4.2  christos 
    229  1.27.4.2  christos int
    230  1.27.4.2  christos compat_30_netbsd32_socket(struct lwp *l, const struct compat_30_netbsd32_socket_args *uap, register_t *retval)
    231  1.27.4.2  christos {
    232  1.27.4.2  christos 	/* {
    233  1.27.4.2  christos 		syscallarg(int) domain;
    234  1.27.4.2  christos 		syscallarg(int) type;
    235  1.27.4.2  christos 		syscallarg(int) protocol;
    236  1.27.4.2  christos 	} */
    237  1.27.4.2  christos 	struct compat_30_sys_socket_args ua;
    238  1.27.4.2  christos 
    239  1.27.4.2  christos 	NETBSD32TO64_UAP(domain);
    240  1.27.4.2  christos 	NETBSD32TO64_UAP(type);
    241  1.27.4.2  christos 	NETBSD32TO64_UAP(protocol);
    242  1.27.4.2  christos 	return (compat_30_sys_socket(l, &ua, retval));
    243  1.27.4.2  christos }
    244  1.27.4.2  christos 
    245  1.27.4.2  christos int
    246  1.27.4.2  christos compat_30_netbsd32_getfh(struct lwp *l, const struct compat_30_netbsd32_getfh_args *uap, register_t *retval)
    247  1.27.4.2  christos {
    248  1.27.4.2  christos 	/* {
    249  1.27.4.2  christos 		syscallarg(const netbsd32_charp) fname;
    250  1.27.4.2  christos 		syscallarg(netbsd32_compat_30_fhandlep_t) fhp;
    251  1.27.4.2  christos 	} */
    252  1.27.4.2  christos 	struct compat_30_sys_getfh_args ua;
    253  1.27.4.2  christos 
    254  1.27.4.2  christos 	NETBSD32TOP_UAP(fname, const char);
    255  1.27.4.2  christos 	NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
    256  1.27.4.2  christos 	/* Lucky for us a fhandle_t doesn't change sizes */
    257  1.27.4.2  christos 	return (compat_30_sys_getfh(l, &ua, retval));
    258  1.27.4.2  christos }
    259  1.27.4.2  christos 
    260  1.27.4.2  christos 
    261  1.27.4.2  christos int
    262  1.27.4.2  christos compat_30_netbsd32___fhstat30(struct lwp *l, const struct compat_30_netbsd32___fhstat30_args *uap, register_t *retval)
    263  1.27.4.2  christos {
    264  1.27.4.2  christos 	/* {
    265  1.27.4.2  christos 		syscallarg(const netbsd32_fhandlep_t) fhp;
    266  1.27.4.2  christos 		syscallarg(netbsd32_statp_t) sb;
    267  1.27.4.2  christos 	} */
    268  1.27.4.2  christos 	struct stat sb;
    269  1.27.4.2  christos 	struct netbsd32_stat50 sb32;
    270  1.27.4.2  christos 	int error;
    271  1.27.4.2  christos 
    272  1.27.4.2  christos 	error = do_fhstat(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
    273  1.27.4.2  christos 	if (error)
    274  1.27.4.2  christos 		return error;
    275  1.27.4.2  christos 
    276  1.27.4.2  christos 	netbsd32_from___stat50(&sb, &sb32);
    277  1.27.4.2  christos 	error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
    278  1.27.4.2  christos 	return error;
    279  1.27.4.2  christos }
    280  1.27.4.2  christos 
    281  1.27.4.2  christos /*
    282  1.27.4.2  christos  * Open a file given a file handle.
    283  1.27.4.2  christos  *
    284  1.27.4.2  christos  * Check permissions, allocate an open file structure,
    285  1.27.4.2  christos  * and call the device open routine if any.
    286  1.27.4.2  christos  */
    287  1.27.4.2  christos int
    288  1.27.4.2  christos compat_30_netbsd32_fhopen(struct lwp *l, const struct compat_30_netbsd32_fhopen_args *uap, register_t *retval)
    289  1.27.4.2  christos {
    290  1.27.4.2  christos 	/* {
    291  1.27.4.2  christos 		syscallarg(const fhandle_t *) fhp;
    292  1.27.4.2  christos 		syscallarg(int) flags;
    293  1.27.4.2  christos 	} */
    294  1.27.4.2  christos 	struct compat_30_sys_fhopen_args ua;
    295  1.27.4.2  christos 
    296  1.27.4.2  christos 	NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
    297  1.27.4.2  christos 	NETBSD32TO64_UAP(flags);
    298  1.27.4.2  christos 	return (compat_30_sys_fhopen(l, &ua, retval));
    299  1.27.4.2  christos }
    300