Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_30.c revision 1.4.8.2
      1  1.4.8.2      yamt /*	$NetBSD: netbsd32_compat_30.c,v 1.4.8.2 2006/05/24 10:57:31 yamt Exp $	*/
      2      1.1  christos 
      3      1.1  christos /*
      4      1.1  christos  * Copyright (c) 1998, 2001 Matthew R. Green
      5      1.1  christos  * All rights reserved.
      6      1.1  christos  *
      7      1.1  christos  * Redistribution and use in source and binary forms, with or without
      8      1.1  christos  * modification, are permitted provided that the following conditions
      9      1.1  christos  * are met:
     10      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11      1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12      1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  christos  *    documentation and/or other materials provided with the distribution.
     15      1.1  christos  * 3. The name of the author may not be used to endorse or promote products
     16      1.1  christos  *    derived from this software without specific prior written permission.
     17      1.1  christos  *
     18      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19      1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20      1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21      1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22      1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23      1.1  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24      1.1  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25      1.1  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26      1.1  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27      1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28      1.1  christos  * SUCH DAMAGE.
     29      1.1  christos  */
     30      1.1  christos 
     31      1.1  christos #include <sys/cdefs.h>
     32  1.4.8.2      yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.4.8.2 2006/05/24 10:57:31 yamt Exp $");
     33      1.1  christos 
     34      1.1  christos #include <sys/param.h>
     35      1.1  christos #include <sys/systm.h>
     36      1.1  christos #include <sys/malloc.h>
     37      1.1  christos #include <sys/mount.h>
     38      1.1  christos #include <sys/socket.h>
     39      1.1  christos #include <sys/socketvar.h>
     40      1.1  christos #include <sys/stat.h>
     41      1.1  christos #include <sys/time.h>
     42      1.1  christos #include <sys/ktrace.h>
     43      1.1  christos #include <sys/resourcevar.h>
     44      1.1  christos #include <sys/vnode.h>
     45      1.1  christos #include <sys/file.h>
     46      1.1  christos #include <sys/filedesc.h>
     47      1.1  christos #include <sys/namei.h>
     48      1.1  christos #include <sys/sa.h>
     49      1.1  christos #include <sys/statvfs.h>
     50      1.1  christos #include <sys/syscallargs.h>
     51      1.1  christos #include <sys/proc.h>
     52      1.2  christos #include <sys/dirent.h>
     53  1.4.8.2      yamt #include <sys/kauth.h>
     54      1.1  christos 
     55      1.1  christos #include <compat/netbsd32/netbsd32.h>
     56      1.1  christos #include <compat/netbsd32/netbsd32_syscallargs.h>
     57      1.1  christos #include <compat/netbsd32/netbsd32_conv.h>
     58      1.1  christos 
     59      1.1  christos 
     60      1.1  christos int
     61      1.1  christos netbsd32_getdents(l, v, retval)
     62      1.1  christos 	struct lwp *l;
     63      1.1  christos 	void *v;
     64      1.1  christos 	register_t *retval;
     65      1.1  christos {
     66      1.1  christos 	struct netbsd32_getdents_args /* {
     67      1.1  christos 		syscallarg(int) fd;
     68      1.1  christos 		syscallarg(netbsd32_charp) buf;
     69      1.1  christos 		syscallarg(netbsd32_size_t) count;
     70      1.1  christos 	} */ *uap = v;
     71      1.1  christos 	struct file *fp;
     72      1.1  christos 	int error, done;
     73      1.1  christos 	char  *buf;
     74      1.1  christos 	struct proc *p = l->l_proc;
     75      1.1  christos 
     76      1.1  christos 	/* getvnode() will use the descriptor for us */
     77      1.1  christos 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
     78      1.1  christos 		return (error);
     79      1.1  christos 	if ((fp->f_flag & FREAD) == 0) {
     80      1.1  christos 		error = EBADF;
     81      1.1  christos 		goto out;
     82      1.1  christos 	}
     83      1.1  christos 	buf = malloc(SCARG(uap, count), M_TEMP, M_WAITOK);
     84      1.2  christos 	error = vn_readdir(fp, buf,
     85      1.4  christos 	    UIO_SYSSPACE, SCARG(uap, count), &done, l, 0, 0);
     86      1.1  christos 	if (error == 0) {
     87      1.1  christos 		*retval = netbsd32_to_dirent12(buf, done);
     88      1.1  christos 		error = copyout(buf, NETBSD32PTR64(SCARG(uap, buf)), *retval);
     89      1.1  christos 	}
     90      1.1  christos 	free(buf, M_TEMP);
     91      1.1  christos  out:
     92      1.4  christos 	FILE_UNUSE(fp, l);
     93      1.1  christos 	return (error);
     94      1.1  christos }
     95      1.1  christos 
     96      1.1  christos int
     97      1.1  christos netbsd32___stat13(l, v, retval)
     98      1.1  christos 	struct lwp *l;
     99      1.1  christos 	void *v;
    100      1.1  christos 	register_t *retval;
    101      1.1  christos {
    102      1.1  christos 	struct netbsd32___stat13_args /* {
    103      1.1  christos 		syscallarg(const netbsd32_charp) path;
    104      1.1  christos 		syscallarg(netbsd32_stat13p_t) ub;
    105      1.1  christos 	} */ *uap = v;
    106      1.2  christos 	struct netbsd32_stat13 sb32;
    107      1.1  christos 	struct stat sb;
    108      1.1  christos 	int error;
    109      1.1  christos 	struct nameidata nd;
    110      1.1  christos 	caddr_t sg;
    111      1.1  christos 	const char *path;
    112      1.1  christos 	struct proc *p = l->l_proc;
    113      1.1  christos 
    114      1.1  christos 	path = (char *)NETBSD32PTR64(SCARG(uap, path));
    115      1.1  christos 	sg = stackgap_init(p, 0);
    116      1.4  christos 	CHECK_ALT_EXIST(l, &sg, path);
    117      1.1  christos 
    118      1.4  christos 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, l);
    119      1.1  christos 	if ((error = namei(&nd)) != 0)
    120      1.1  christos 		return (error);
    121      1.4  christos 	error = vn_stat(nd.ni_vp, &sb, l);
    122      1.1  christos 	vput(nd.ni_vp);
    123      1.1  christos 	if (error)
    124      1.1  christos 		return (error);
    125      1.1  christos 	netbsd32_from___stat13(&sb, &sb32);
    126      1.1  christos 	error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
    127      1.1  christos 	    sizeof(sb32));
    128      1.1  christos 	return (error);
    129      1.1  christos }
    130      1.1  christos 
    131      1.1  christos int
    132      1.1  christos netbsd32___fstat13(l, v, retval)
    133      1.1  christos 	struct lwp *l;
    134      1.1  christos 	void *v;
    135      1.1  christos 	register_t *retval;
    136      1.1  christos {
    137      1.1  christos 	struct netbsd32___fstat13_args /* {
    138      1.1  christos 		syscallarg(int) fd;
    139      1.1  christos 		syscallarg(netbsd32_stat13p_t) sb;
    140      1.1  christos 	} */ *uap = v;
    141      1.1  christos 	int fd = SCARG(uap, fd);
    142      1.1  christos 	struct proc *p = l->l_proc;
    143      1.1  christos 	struct filedesc *fdp = p->p_fd;
    144      1.1  christos 	struct file *fp;
    145      1.2  christos 	struct netbsd32_stat13 sb32;
    146      1.1  christos 	struct stat ub;
    147      1.1  christos 	int error = 0;
    148      1.1  christos 
    149      1.1  christos 	if ((fp = fd_getfile(fdp, fd)) == NULL)
    150      1.1  christos 		return (EBADF);
    151      1.1  christos 
    152      1.1  christos 	FILE_USE(fp);
    153      1.4  christos 	error = (*fp->f_ops->fo_stat)(fp, &ub, l);
    154      1.4  christos 	FILE_UNUSE(fp, l);
    155      1.1  christos 
    156      1.1  christos 	if (error == 0) {
    157      1.1  christos 		netbsd32_from___stat13(&ub, &sb32);
    158      1.1  christos 		error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, sb)),
    159      1.1  christos 		    sizeof(sb32));
    160      1.1  christos 	}
    161      1.1  christos 	return (error);
    162      1.1  christos }
    163      1.1  christos 
    164      1.1  christos int
    165      1.1  christos netbsd32___lstat13(l, v, retval)
    166      1.1  christos 	struct lwp *l;
    167      1.1  christos 	void *v;
    168      1.1  christos 	register_t *retval;
    169      1.1  christos {
    170      1.1  christos 	struct netbsd32___lstat13_args /* {
    171      1.1  christos 		syscallarg(const netbsd32_charp) path;
    172      1.1  christos 		syscallarg(netbsd32_stat13p_t) ub;
    173      1.1  christos 	} */ *uap = v;
    174      1.2  christos 	struct netbsd32_stat13 sb32;
    175      1.1  christos 	struct stat sb;
    176      1.1  christos 	int error;
    177      1.1  christos 	struct nameidata nd;
    178      1.1  christos 	caddr_t sg;
    179      1.1  christos 	const char *path;
    180      1.1  christos 	struct proc *p = l->l_proc;
    181      1.1  christos 
    182      1.1  christos 	path = (char *)NETBSD32PTR64(SCARG(uap, path));
    183      1.1  christos 	sg = stackgap_init(p, 0);
    184      1.4  christos 	CHECK_ALT_EXIST(l, &sg, path);
    185      1.1  christos 
    186      1.4  christos 	NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, path, l);
    187      1.1  christos 	if ((error = namei(&nd)) != 0)
    188      1.1  christos 		return (error);
    189      1.4  christos 	error = vn_stat(nd.ni_vp, &sb, l);
    190      1.1  christos 	vput(nd.ni_vp);
    191      1.1  christos 	if (error)
    192      1.1  christos 		return (error);
    193      1.1  christos 	netbsd32_from___stat13(&sb, &sb32);
    194      1.1  christos 	error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
    195      1.1  christos 	    sizeof(sb32));
    196      1.1  christos 	return (error);
    197      1.1  christos }
    198  1.4.8.2      yamt 
    199  1.4.8.2      yamt int
    200  1.4.8.2      yamt compat_30_netbsd32_fhstat(l, v, retval)
    201  1.4.8.2      yamt 	struct lwp *l;
    202  1.4.8.2      yamt 	void *v;
    203  1.4.8.2      yamt 	register_t *retval;
    204  1.4.8.2      yamt {
    205  1.4.8.2      yamt 	struct compat_30_netbsd32_fhstat_args /* {
    206  1.4.8.2      yamt 		syscallarg(const netbsd32_fhandlep_t) fhp;
    207  1.4.8.2      yamt 		syscallarg(netbsd32_stat13p_t) sb);
    208  1.4.8.2      yamt 	} */ *uap = v;
    209  1.4.8.2      yamt 	struct proc *p = l->l_proc;
    210  1.4.8.2      yamt 	struct stat sb;
    211  1.4.8.2      yamt 	struct netbsd32_stat13 sb32;
    212  1.4.8.2      yamt 	int error;
    213  1.4.8.2      yamt 	fhandle_t fh;
    214  1.4.8.2      yamt 	struct mount *mp;
    215  1.4.8.2      yamt 	struct vnode *vp;
    216  1.4.8.2      yamt 
    217  1.4.8.2      yamt 	/*
    218  1.4.8.2      yamt 	 * Must be super user
    219  1.4.8.2      yamt 	 */
    220  1.4.8.2      yamt 	if ((error = kauth_authorize_generic(p->p_cred, KAUTH_GENERIC_ISSUSER,
    221  1.4.8.2      yamt 	    &p->p_acflag)))
    222  1.4.8.2      yamt 		return (error);
    223  1.4.8.2      yamt 
    224  1.4.8.2      yamt 	if ((error = copyin(NETBSD32PTR64(SCARG(uap, fhp)), &fh,
    225  1.4.8.2      yamt 	    sizeof(fhandle_t))) != 0)
    226  1.4.8.2      yamt 		return (error);
    227  1.4.8.2      yamt 
    228  1.4.8.2      yamt 	if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
    229  1.4.8.2      yamt 		return (ESTALE);
    230  1.4.8.2      yamt 	if (mp->mnt_op->vfs_fhtovp == NULL)
    231  1.4.8.2      yamt 		return EOPNOTSUPP;
    232  1.4.8.2      yamt 	if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
    233  1.4.8.2      yamt 		return (error);
    234  1.4.8.2      yamt 	error = vn_stat(vp, &sb, l);
    235  1.4.8.2      yamt 	vput(vp);
    236  1.4.8.2      yamt 	if (error)
    237  1.4.8.2      yamt 		return (error);
    238  1.4.8.2      yamt 	netbsd32_from___stat13(&sb, &sb32);
    239  1.4.8.2      yamt 	error = copyout(&sb32, NETBSD32PTR64(SCARG(uap, sb)), sizeof(sb));
    240  1.4.8.2      yamt 	return (error);
    241  1.4.8.2      yamt }
    242