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