1 /* $NetBSD: netbsd32_compat_30.c,v 1.5 2006/03/07 03:32:06 thorpej 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.5 2006/03/07 03:32:06 thorpej Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/malloc.h> 37 #include <sys/mount.h> 38 #include <sys/socket.h> 39 #include <sys/socketvar.h> 40 #include <sys/stat.h> 41 #include <sys/time.h> 42 #include <sys/ktrace.h> 43 #include <sys/resourcevar.h> 44 #include <sys/vnode.h> 45 #include <sys/file.h> 46 #include <sys/filedesc.h> 47 #include <sys/namei.h> 48 #include <sys/sa.h> 49 #include <sys/statvfs.h> 50 #include <sys/syscallargs.h> 51 #include <sys/proc.h> 52 #include <sys/dirent.h> 53 54 #include <compat/netbsd32/netbsd32.h> 55 #include <compat/netbsd32/netbsd32_syscallargs.h> 56 #include <compat/netbsd32/netbsd32_conv.h> 57 58 59 int 60 netbsd32_getdents(l, v, retval) 61 struct lwp *l; 62 void *v; 63 register_t *retval; 64 { 65 struct netbsd32_getdents_args /* { 66 syscallarg(int) fd; 67 syscallarg(netbsd32_charp) buf; 68 syscallarg(netbsd32_size_t) count; 69 } */ *uap = v; 70 struct file *fp; 71 int error, done; 72 char *buf; 73 struct proc *p = l->l_proc; 74 75 /* getvnode() will use the descriptor for us */ 76 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) 77 return (error); 78 if ((fp->f_flag & FREAD) == 0) { 79 error = EBADF; 80 goto out; 81 } 82 buf = malloc(SCARG(uap, count), M_TEMP, M_WAITOK); 83 error = vn_readdir(fp, buf, 84 UIO_SYSSPACE, SCARG(uap, count), &done, l, 0, 0); 85 if (error == 0) { 86 *retval = netbsd32_to_dirent12(buf, done); 87 error = copyout(buf, NETBSD32PTR64(SCARG(uap, buf)), *retval); 88 } 89 free(buf, M_TEMP); 90 out: 91 FILE_UNUSE(fp, l); 92 return (error); 93 } 94 95 int 96 netbsd32___stat13(l, v, retval) 97 struct lwp *l; 98 void *v; 99 register_t *retval; 100 { 101 struct netbsd32___stat13_args /* { 102 syscallarg(const netbsd32_charp) path; 103 syscallarg(netbsd32_stat13p_t) ub; 104 } */ *uap = v; 105 struct netbsd32_stat13 sb32; 106 struct stat sb; 107 int error; 108 struct nameidata nd; 109 caddr_t sg; 110 const char *path; 111 struct proc *p = l->l_proc; 112 113 path = (char *)NETBSD32PTR64(SCARG(uap, path)); 114 sg = stackgap_init(p, 0); 115 CHECK_ALT_EXIST(l, &sg, path); 116 117 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, l); 118 if ((error = namei(&nd)) != 0) 119 return (error); 120 error = vn_stat(nd.ni_vp, &sb, l); 121 vput(nd.ni_vp); 122 if (error) 123 return (error); 124 netbsd32_from___stat13(&sb, &sb32); 125 error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)), 126 sizeof(sb32)); 127 return (error); 128 } 129 130 int 131 netbsd32___fstat13(l, v, retval) 132 struct lwp *l; 133 void *v; 134 register_t *retval; 135 { 136 struct netbsd32___fstat13_args /* { 137 syscallarg(int) fd; 138 syscallarg(netbsd32_stat13p_t) sb; 139 } */ *uap = v; 140 int fd = SCARG(uap, fd); 141 struct proc *p = l->l_proc; 142 struct filedesc *fdp = p->p_fd; 143 struct file *fp; 144 struct netbsd32_stat13 sb32; 145 struct stat ub; 146 int error = 0; 147 148 if ((fp = fd_getfile(fdp, fd)) == NULL) 149 return (EBADF); 150 151 FILE_USE(fp); 152 error = (*fp->f_ops->fo_stat)(fp, &ub, l); 153 FILE_UNUSE(fp, l); 154 155 if (error == 0) { 156 netbsd32_from___stat13(&ub, &sb32); 157 error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, sb)), 158 sizeof(sb32)); 159 } 160 return (error); 161 } 162 163 int 164 netbsd32___lstat13(l, v, retval) 165 struct lwp *l; 166 void *v; 167 register_t *retval; 168 { 169 struct netbsd32___lstat13_args /* { 170 syscallarg(const netbsd32_charp) path; 171 syscallarg(netbsd32_stat13p_t) ub; 172 } */ *uap = v; 173 struct netbsd32_stat13 sb32; 174 struct stat sb; 175 int error; 176 struct nameidata nd; 177 caddr_t sg; 178 const char *path; 179 struct proc *p = l->l_proc; 180 181 path = (char *)NETBSD32PTR64(SCARG(uap, path)); 182 sg = stackgap_init(p, 0); 183 CHECK_ALT_EXIST(l, &sg, path); 184 185 NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, path, l); 186 if ((error = namei(&nd)) != 0) 187 return (error); 188 error = vn_stat(nd.ni_vp, &sb, l); 189 vput(nd.ni_vp); 190 if (error) 191 return (error); 192 netbsd32_from___stat13(&sb, &sb32); 193 error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)), 194 sizeof(sb32)); 195 return (error); 196 } 197