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