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