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