netbsd32_compat_30.c revision 1.8.4.7 1 1.8.4.7 yamt /* $NetBSD: netbsd32_compat_30.c,v 1.8.4.7 2008/03/24 09:38:41 yamt Exp $ */
2 1.8.4.2 yamt
3 1.8.4.2 yamt /*
4 1.8.4.2 yamt * Copyright (c) 1998, 2001 Matthew R. Green
5 1.8.4.2 yamt * All rights reserved.
6 1.8.4.2 yamt *
7 1.8.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.8.4.2 yamt * modification, are permitted provided that the following conditions
9 1.8.4.2 yamt * are met:
10 1.8.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.8.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.8.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.8.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.8.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.8.4.2 yamt * 3. The name of the author may not be used to endorse or promote products
16 1.8.4.2 yamt * derived from this software without specific prior written permission.
17 1.8.4.2 yamt *
18 1.8.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.8.4.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.8.4.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.8.4.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.8.4.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.8.4.2 yamt * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.8.4.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.8.4.2 yamt * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.8.4.2 yamt * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.8.4.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.8.4.2 yamt * SUCH DAMAGE.
29 1.8.4.2 yamt */
30 1.8.4.2 yamt
31 1.8.4.2 yamt #include <sys/cdefs.h>
32 1.8.4.7 yamt __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.8.4.7 2008/03/24 09:38:41 yamt Exp $");
33 1.8.4.3 yamt
34 1.8.4.3 yamt #include "opt_nfsserver.h"
35 1.8.4.2 yamt
36 1.8.4.2 yamt #include <sys/param.h>
37 1.8.4.2 yamt #include <sys/systm.h>
38 1.8.4.2 yamt #include <sys/malloc.h>
39 1.8.4.2 yamt #include <sys/mount.h>
40 1.8.4.2 yamt #include <sys/socket.h>
41 1.8.4.2 yamt #include <sys/socketvar.h>
42 1.8.4.2 yamt #include <sys/stat.h>
43 1.8.4.2 yamt #include <sys/time.h>
44 1.8.4.2 yamt #include <sys/ktrace.h>
45 1.8.4.2 yamt #include <sys/resourcevar.h>
46 1.8.4.2 yamt #include <sys/vnode.h>
47 1.8.4.2 yamt #include <sys/file.h>
48 1.8.4.2 yamt #include <sys/filedesc.h>
49 1.8.4.2 yamt #include <sys/namei.h>
50 1.8.4.2 yamt #include <sys/statvfs.h>
51 1.8.4.2 yamt #include <sys/syscallargs.h>
52 1.8.4.2 yamt #include <sys/proc.h>
53 1.8.4.2 yamt #include <sys/dirent.h>
54 1.8.4.2 yamt #include <sys/kauth.h>
55 1.8.4.5 yamt #include <sys/vfs_syscalls.h>
56 1.8.4.2 yamt
57 1.8.4.2 yamt #include <compat/netbsd32/netbsd32.h>
58 1.8.4.2 yamt #include <compat/netbsd32/netbsd32_syscallargs.h>
59 1.8.4.2 yamt #include <compat/netbsd32/netbsd32_conv.h>
60 1.8.4.3 yamt #include <compat/sys/mount.h>
61 1.8.4.2 yamt
62 1.8.4.2 yamt
63 1.8.4.2 yamt int
64 1.8.4.6 yamt compat_30_netbsd32_getdents(struct lwp *l, const struct compat_30_netbsd32_getdents_args *uap, register_t *retval)
65 1.8.4.2 yamt {
66 1.8.4.6 yamt /* {
67 1.8.4.2 yamt syscallarg(int) fd;
68 1.8.4.2 yamt syscallarg(netbsd32_charp) buf;
69 1.8.4.2 yamt syscallarg(netbsd32_size_t) count;
70 1.8.4.6 yamt } */
71 1.8.4.7 yamt file_t *fp;
72 1.8.4.2 yamt int error, done;
73 1.8.4.2 yamt char *buf;
74 1.8.4.2 yamt netbsd32_size_t count;
75 1.8.4.2 yamt
76 1.8.4.2 yamt /* Limit the size on any kernel buffers used by VOP_READDIR */
77 1.8.4.2 yamt count = min(MAXBSIZE, SCARG(uap, count));
78 1.8.4.2 yamt
79 1.8.4.2 yamt /* getvnode() will use the descriptor for us */
80 1.8.4.7 yamt if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
81 1.8.4.2 yamt return (error);
82 1.8.4.2 yamt if ((fp->f_flag & FREAD) == 0) {
83 1.8.4.2 yamt error = EBADF;
84 1.8.4.2 yamt goto out;
85 1.8.4.2 yamt }
86 1.8.4.2 yamt buf = malloc(count, M_TEMP, M_WAITOK);
87 1.8.4.2 yamt error = vn_readdir(fp, buf, UIO_SYSSPACE, count, &done, l, 0, 0);
88 1.8.4.2 yamt if (error == 0) {
89 1.8.4.2 yamt *retval = netbsd32_to_dirent12(buf, done);
90 1.8.4.5 yamt error = copyout(buf, SCARG_P32(uap, buf), *retval);
91 1.8.4.2 yamt }
92 1.8.4.2 yamt free(buf, M_TEMP);
93 1.8.4.2 yamt out:
94 1.8.4.7 yamt fd_putfile(SCARG(uap, fd));
95 1.8.4.2 yamt return (error);
96 1.8.4.2 yamt }
97 1.8.4.2 yamt
98 1.8.4.2 yamt int
99 1.8.4.6 yamt compat_30_netbsd32___stat13(struct lwp *l, const struct compat_30_netbsd32___stat13_args *uap, register_t *retval)
100 1.8.4.2 yamt {
101 1.8.4.6 yamt /* {
102 1.8.4.2 yamt syscallarg(const netbsd32_charp) path;
103 1.8.4.2 yamt syscallarg(netbsd32_stat13p_t) ub;
104 1.8.4.6 yamt } */
105 1.8.4.2 yamt struct netbsd32_stat13 sb32;
106 1.8.4.2 yamt struct stat sb;
107 1.8.4.2 yamt int error;
108 1.8.4.2 yamt const char *path;
109 1.8.4.2 yamt
110 1.8.4.5 yamt path = SCARG_P32(uap, path);
111 1.8.4.2 yamt
112 1.8.4.7 yamt error = do_sys_stat(path, FOLLOW, &sb);
113 1.8.4.2 yamt if (error)
114 1.8.4.2 yamt return (error);
115 1.8.4.2 yamt netbsd32_from___stat13(&sb, &sb32);
116 1.8.4.5 yamt error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
117 1.8.4.2 yamt return (error);
118 1.8.4.2 yamt }
119 1.8.4.2 yamt
120 1.8.4.2 yamt int
121 1.8.4.6 yamt compat_30_netbsd32___fstat13(struct lwp *l, const struct compat_30_netbsd32___fstat13_args *uap, register_t *retval)
122 1.8.4.2 yamt {
123 1.8.4.6 yamt /* {
124 1.8.4.2 yamt syscallarg(int) fd;
125 1.8.4.2 yamt syscallarg(netbsd32_stat13p_t) sb;
126 1.8.4.6 yamt } */
127 1.8.4.2 yamt int fd = SCARG(uap, fd);
128 1.8.4.7 yamt file_t *fp;
129 1.8.4.2 yamt struct netbsd32_stat13 sb32;
130 1.8.4.2 yamt struct stat ub;
131 1.8.4.2 yamt int error = 0;
132 1.8.4.2 yamt
133 1.8.4.7 yamt if ((fp = fd_getfile(fd)) == NULL)
134 1.8.4.2 yamt return (EBADF);
135 1.8.4.7 yamt error = (*fp->f_ops->fo_stat)(fp, &ub);
136 1.8.4.7 yamt fd_putfile(fd);
137 1.8.4.2 yamt
138 1.8.4.2 yamt if (error == 0) {
139 1.8.4.2 yamt netbsd32_from___stat13(&ub, &sb32);
140 1.8.4.5 yamt error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
141 1.8.4.2 yamt }
142 1.8.4.2 yamt return (error);
143 1.8.4.2 yamt }
144 1.8.4.2 yamt
145 1.8.4.2 yamt int
146 1.8.4.6 yamt compat_30_netbsd32___lstat13(struct lwp *l, const struct compat_30_netbsd32___lstat13_args *uap, register_t *retval)
147 1.8.4.2 yamt {
148 1.8.4.6 yamt /* {
149 1.8.4.2 yamt syscallarg(const netbsd32_charp) path;
150 1.8.4.2 yamt syscallarg(netbsd32_stat13p_t) ub;
151 1.8.4.6 yamt } */
152 1.8.4.2 yamt struct netbsd32_stat13 sb32;
153 1.8.4.2 yamt struct stat sb;
154 1.8.4.2 yamt int error;
155 1.8.4.2 yamt const char *path;
156 1.8.4.2 yamt
157 1.8.4.5 yamt path = SCARG_P32(uap, path);
158 1.8.4.2 yamt
159 1.8.4.7 yamt error = do_sys_stat(path, NOFOLLOW, &sb);
160 1.8.4.2 yamt if (error)
161 1.8.4.2 yamt return (error);
162 1.8.4.2 yamt netbsd32_from___stat13(&sb, &sb32);
163 1.8.4.5 yamt error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
164 1.8.4.2 yamt return (error);
165 1.8.4.2 yamt }
166 1.8.4.2 yamt
167 1.8.4.2 yamt int
168 1.8.4.6 yamt compat_30_netbsd32_fhstat(struct lwp *l, const struct compat_30_netbsd32_fhstat_args *uap, register_t *retval)
169 1.8.4.2 yamt {
170 1.8.4.6 yamt /* {
171 1.8.4.2 yamt syscallarg(const netbsd32_fhandlep_t) fhp;
172 1.8.4.5 yamt syscallarg(netbsd32_stat13p_t) sb;
173 1.8.4.6 yamt } */
174 1.8.4.2 yamt struct stat sb;
175 1.8.4.2 yamt struct netbsd32_stat13 sb32;
176 1.8.4.2 yamt int error;
177 1.8.4.3 yamt struct compat_30_fhandle fh;
178 1.8.4.2 yamt struct mount *mp;
179 1.8.4.2 yamt struct vnode *vp;
180 1.8.4.2 yamt
181 1.8.4.2 yamt /*
182 1.8.4.2 yamt * Must be super user
183 1.8.4.2 yamt */
184 1.8.4.3 yamt if ((error = kauth_authorize_system(l->l_cred,
185 1.8.4.3 yamt KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)))
186 1.8.4.2 yamt return (error);
187 1.8.4.2 yamt
188 1.8.4.5 yamt if ((error = copyin(SCARG_P32(uap, fhp), &fh, sizeof(fh))) != 0)
189 1.8.4.2 yamt return (error);
190 1.8.4.2 yamt
191 1.8.4.2 yamt if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
192 1.8.4.2 yamt return (ESTALE);
193 1.8.4.2 yamt if (mp->mnt_op->vfs_fhtovp == NULL)
194 1.8.4.2 yamt return EOPNOTSUPP;
195 1.8.4.3 yamt if ((error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, &vp)))
196 1.8.4.2 yamt return (error);
197 1.8.4.7 yamt error = vn_stat(vp, &sb);
198 1.8.4.2 yamt vput(vp);
199 1.8.4.2 yamt if (error)
200 1.8.4.2 yamt return (error);
201 1.8.4.2 yamt netbsd32_from___stat13(&sb, &sb32);
202 1.8.4.5 yamt error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
203 1.8.4.2 yamt return (error);
204 1.8.4.2 yamt }
205 1.8.4.3 yamt
206 1.8.4.3 yamt int
207 1.8.4.6 yamt compat_30_netbsd32_fhstatvfs1(struct lwp *l, const struct compat_30_netbsd32_fhstatvfs1_args *uap, register_t *retval)
208 1.8.4.3 yamt {
209 1.8.4.6 yamt /* {
210 1.8.4.3 yamt syscallarg(const netbsd32_fhandlep_t) fhp;
211 1.8.4.3 yamt syscallarg(netbsd32_statvfsp_t) buf;
212 1.8.4.3 yamt syscallarg(int) flags;
213 1.8.4.6 yamt } */
214 1.8.4.3 yamt struct statvfs *sbuf;
215 1.8.4.3 yamt struct netbsd32_statvfs *s32;
216 1.8.4.3 yamt int error;
217 1.8.4.3 yamt
218 1.8.4.5 yamt sbuf = STATVFSBUF_GET();
219 1.8.4.5 yamt error = do_fhstatvfs(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, sbuf,
220 1.8.4.5 yamt SCARG(uap, flags));
221 1.8.4.5 yamt
222 1.8.4.5 yamt if (error != 0) {
223 1.8.4.5 yamt s32 = malloc(sizeof *s32, M_TEMP, M_WAITOK);
224 1.8.4.5 yamt netbsd32_from_statvfs(sbuf, s32);
225 1.8.4.5 yamt error = copyout(s32, SCARG_P32(uap, buf), sizeof *s32);
226 1.8.4.5 yamt free(s32, M_TEMP);
227 1.8.4.5 yamt }
228 1.8.4.5 yamt STATVFSBUF_PUT(sbuf);
229 1.8.4.3 yamt
230 1.8.4.3 yamt return (error);
231 1.8.4.3 yamt }
232 1.8.4.3 yamt
233 1.8.4.3 yamt int
234 1.8.4.6 yamt compat_30_netbsd32_socket(struct lwp *l, const struct compat_30_netbsd32_socket_args *uap, register_t *retval)
235 1.8.4.3 yamt {
236 1.8.4.6 yamt /* {
237 1.8.4.3 yamt syscallarg(int) domain;
238 1.8.4.3 yamt syscallarg(int) type;
239 1.8.4.3 yamt syscallarg(int) protocol;
240 1.8.4.6 yamt } */
241 1.8.4.3 yamt struct compat_30_sys_socket_args ua;
242 1.8.4.3 yamt
243 1.8.4.3 yamt NETBSD32TO64_UAP(domain);
244 1.8.4.3 yamt NETBSD32TO64_UAP(type);
245 1.8.4.3 yamt NETBSD32TO64_UAP(protocol);
246 1.8.4.3 yamt return (compat_30_sys_socket(l, &ua, retval));
247 1.8.4.3 yamt }
248 1.8.4.3 yamt
249 1.8.4.3 yamt int
250 1.8.4.6 yamt compat_30_netbsd32_getfh(struct lwp *l, const struct compat_30_netbsd32_getfh_args *uap, register_t *retval)
251 1.8.4.3 yamt {
252 1.8.4.6 yamt /* {
253 1.8.4.3 yamt syscallarg(const netbsd32_charp) fname;
254 1.8.4.3 yamt syscallarg(netbsd32_compat_30_fhandlep_t) fhp;
255 1.8.4.6 yamt } */
256 1.8.4.3 yamt struct compat_30_sys_getfh_args ua;
257 1.8.4.3 yamt
258 1.8.4.3 yamt NETBSD32TOP_UAP(fname, const char);
259 1.8.4.3 yamt NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
260 1.8.4.3 yamt /* Lucky for us a fhandle_t doesn't change sizes */
261 1.8.4.3 yamt return (compat_30_sys_getfh(l, &ua, retval));
262 1.8.4.3 yamt }
263 1.8.4.3 yamt
264 1.8.4.3 yamt
265 1.8.4.6 yamt int
266 1.8.4.6 yamt compat_30_netbsd32_sys___fhstat30(struct lwp *l, const struct compat_30_netbsd32_sys___fhstat30_args *uap, register_t *retval)
267 1.8.4.3 yamt {
268 1.8.4.6 yamt /* {
269 1.8.4.3 yamt syscallarg(const netbsd32_fhandlep_t) fhp;
270 1.8.4.3 yamt syscallarg(netbsd32_statp_t) sb;
271 1.8.4.6 yamt } */
272 1.8.4.3 yamt struct stat sb;
273 1.8.4.3 yamt struct netbsd32_stat sb32;
274 1.8.4.3 yamt int error;
275 1.8.4.3 yamt
276 1.8.4.5 yamt error = do_fhstat(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
277 1.8.4.5 yamt if (error)
278 1.8.4.3 yamt return error;
279 1.8.4.3 yamt
280 1.8.4.3 yamt netbsd32_from___stat30(&sb, &sb32);
281 1.8.4.5 yamt error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
282 1.8.4.3 yamt return error;
283 1.8.4.3 yamt }
284 1.8.4.3 yamt
285 1.8.4.3 yamt /*
286 1.8.4.3 yamt * Open a file given a file handle.
287 1.8.4.3 yamt *
288 1.8.4.3 yamt * Check permissions, allocate an open file structure,
289 1.8.4.3 yamt * and call the device open routine if any.
290 1.8.4.3 yamt */
291 1.8.4.3 yamt int
292 1.8.4.6 yamt compat_30_netbsd32_fhopen(struct lwp *l, const struct compat_30_netbsd32_fhopen_args *uap, register_t *retval)
293 1.8.4.3 yamt {
294 1.8.4.6 yamt /* {
295 1.8.4.3 yamt syscallarg(const fhandle_t *) fhp;
296 1.8.4.3 yamt syscallarg(int) flags;
297 1.8.4.6 yamt } */
298 1.8.4.3 yamt struct compat_30_sys_fhopen_args ua;
299 1.8.4.3 yamt
300 1.8.4.3 yamt NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
301 1.8.4.3 yamt NETBSD32TO64_UAP(flags);
302 1.8.4.3 yamt return (compat_30_sys_fhopen(l, &ua, retval));
303 1.8.4.3 yamt }
304