No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / netbsd32 / netbsd32_compat_30.c
blob720ba91976769316d3e5e16ad27487cc04f74120
1 /* $NetBSD: netbsd32_compat_30.c,v 1.28 2009/01/11 02:45:49 christos Exp $ */
3 /*
4 * Copyright (c) 1998, 2001 Matthew R. Green
5 * All rights reserved.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.28 2009/01/11 02:45:49 christos Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/malloc.h>
35 #include <sys/mount.h>
36 #include <sys/socket.h>
37 #include <sys/socketvar.h>
38 #include <sys/stat.h>
39 #include <sys/time.h>
40 #include <sys/ktrace.h>
41 #include <sys/resourcevar.h>
42 #include <sys/vnode.h>
43 #include <sys/file.h>
44 #include <sys/filedesc.h>
45 #include <sys/namei.h>
46 #include <sys/statvfs.h>
47 #include <sys/syscallargs.h>
48 #include <sys/proc.h>
49 #include <sys/dirent.h>
50 #include <sys/kauth.h>
51 #include <sys/vfs_syscalls.h>
53 #include <compat/netbsd32/netbsd32.h>
54 #include <compat/netbsd32/netbsd32_syscallargs.h>
55 #include <compat/netbsd32/netbsd32_conv.h>
56 #include <compat/sys/mount.h>
59 int
60 compat_30_netbsd32_getdents(struct lwp *l, const struct compat_30_netbsd32_getdents_args *uap, register_t *retval)
62 /* {
63 syscallarg(int) fd;
64 syscallarg(netbsd32_charp) buf;
65 syscallarg(netbsd32_size_t) count;
66 } */
67 file_t *fp;
68 int error, done;
69 char *buf;
70 netbsd32_size_t count;
72 /* Limit the size on any kernel buffers used by VOP_READDIR */
73 count = min(MAXBSIZE, SCARG(uap, count));
75 /* fd_getvnode() will use the descriptor for us */
76 if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
77 return (error);
78 if ((fp->f_flag & FREAD) == 0) {
79 error = EBADF;
80 goto out;
82 buf = malloc(count, M_TEMP, M_WAITOK);
83 error = vn_readdir(fp, buf, UIO_SYSSPACE, count, &done, l, 0, 0);
84 if (error == 0) {
85 *retval = netbsd32_to_dirent12(buf, done);
86 error = copyout(buf, SCARG_P32(uap, buf), *retval);
88 free(buf, M_TEMP);
89 out:
90 fd_putfile(SCARG(uap, fd));
91 return (error);
94 int
95 compat_30_netbsd32___stat13(struct lwp *l, const struct compat_30_netbsd32___stat13_args *uap, register_t *retval)
97 /* {
98 syscallarg(const netbsd32_charp) path;
99 syscallarg(netbsd32_stat13p_t) ub;
100 } */
101 struct netbsd32_stat13 sb32;
102 struct stat sb;
103 int error;
104 const char *path;
106 path = SCARG_P32(uap, path);
108 error = do_sys_stat(path, FOLLOW, &sb);
109 if (error)
110 return (error);
111 netbsd32_from___stat13(&sb, &sb32);
112 error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
113 return (error);
117 compat_30_netbsd32___fstat13(struct lwp *l, const struct compat_30_netbsd32___fstat13_args *uap, register_t *retval)
119 /* {
120 syscallarg(int) fd;
121 syscallarg(netbsd32_stat13p_t) sb;
122 } */
123 struct netbsd32_stat13 sb32;
124 struct stat ub;
125 int error;
127 error = do_sys_fstat(SCARG(uap, fd), &ub);
128 if (error == 0) {
129 netbsd32_from___stat13(&ub, &sb32);
130 error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
132 return (error);
136 compat_30_netbsd32___lstat13(struct lwp *l, const struct compat_30_netbsd32___lstat13_args *uap, register_t *retval)
138 /* {
139 syscallarg(const netbsd32_charp) path;
140 syscallarg(netbsd32_stat13p_t) ub;
141 } */
142 struct netbsd32_stat13 sb32;
143 struct stat sb;
144 int error;
145 const char *path;
147 path = SCARG_P32(uap, path);
149 error = do_sys_stat(path, NOFOLLOW, &sb);
150 if (error)
151 return (error);
152 netbsd32_from___stat13(&sb, &sb32);
153 error = copyout(&sb32, SCARG_P32(uap, ub), sizeof(sb32));
154 return (error);
158 compat_30_netbsd32_fhstat(struct lwp *l, const struct compat_30_netbsd32_fhstat_args *uap, register_t *retval)
160 /* {
161 syscallarg(const netbsd32_fhandlep_t) fhp;
162 syscallarg(netbsd32_stat13p_t) sb;
163 } */
164 struct stat sb;
165 struct netbsd32_stat13 sb32;
166 int error;
167 struct compat_30_fhandle fh;
168 struct mount *mp;
169 struct vnode *vp;
172 * Must be super user
174 if ((error = kauth_authorize_system(l->l_cred,
175 KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)))
176 return (error);
178 if ((error = copyin(SCARG_P32(uap, fhp), &fh, sizeof(fh))) != 0)
179 return (error);
181 if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
182 return (ESTALE);
183 if (mp->mnt_op->vfs_fhtovp == NULL)
184 return EOPNOTSUPP;
185 if ((error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, &vp)))
186 return (error);
187 error = vn_stat(vp, &sb);
188 vput(vp);
189 if (error)
190 return (error);
191 netbsd32_from___stat13(&sb, &sb32);
192 error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb));
193 return (error);
197 compat_30_netbsd32_fhstatvfs1(struct lwp *l, const struct compat_30_netbsd32_fhstatvfs1_args *uap, register_t *retval)
199 /* {
200 syscallarg(const netbsd32_fhandlep_t) fhp;
201 syscallarg(netbsd32_statvfsp_t) buf;
202 syscallarg(int) flags;
203 } */
204 struct statvfs *sbuf;
205 struct netbsd32_statvfs *s32;
206 int error;
208 sbuf = STATVFSBUF_GET();
209 error = do_fhstatvfs(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, sbuf,
210 SCARG(uap, flags));
212 if (error != 0) {
213 s32 = malloc(sizeof *s32, M_TEMP, M_WAITOK);
214 netbsd32_from_statvfs(sbuf, s32);
215 error = copyout(s32, SCARG_P32(uap, buf), sizeof *s32);
216 free(s32, M_TEMP);
218 STATVFSBUF_PUT(sbuf);
220 return (error);
224 compat_30_netbsd32_socket(struct lwp *l, const struct compat_30_netbsd32_socket_args *uap, register_t *retval)
226 /* {
227 syscallarg(int) domain;
228 syscallarg(int) type;
229 syscallarg(int) protocol;
230 } */
231 struct compat_30_sys_socket_args ua;
233 NETBSD32TO64_UAP(domain);
234 NETBSD32TO64_UAP(type);
235 NETBSD32TO64_UAP(protocol);
236 return (compat_30_sys_socket(l, &ua, retval));
240 compat_30_netbsd32_getfh(struct lwp *l, const struct compat_30_netbsd32_getfh_args *uap, register_t *retval)
242 /* {
243 syscallarg(const netbsd32_charp) fname;
244 syscallarg(netbsd32_compat_30_fhandlep_t) fhp;
245 } */
246 struct compat_30_sys_getfh_args ua;
248 NETBSD32TOP_UAP(fname, const char);
249 NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
250 /* Lucky for us a fhandle_t doesn't change sizes */
251 return (compat_30_sys_getfh(l, &ua, retval));
256 compat_30_netbsd32___fhstat30(struct lwp *l, const struct compat_30_netbsd32___fhstat30_args *uap, register_t *retval)
258 /* {
259 syscallarg(const netbsd32_fhandlep_t) fhp;
260 syscallarg(netbsd32_statp_t) sb;
261 } */
262 struct stat sb;
263 struct netbsd32_stat50 sb32;
264 int error;
266 error = do_fhstat(l, SCARG_P32(uap, fhp), FHANDLE_SIZE_COMPAT, &sb);
267 if (error)
268 return error;
270 netbsd32_from___stat50(&sb, &sb32);
271 error = copyout(&sb32, SCARG_P32(uap, sb), sizeof(sb32));
272 return error;
276 * Open a file given a file handle.
278 * Check permissions, allocate an open file structure,
279 * and call the device open routine if any.
282 compat_30_netbsd32_fhopen(struct lwp *l, const struct compat_30_netbsd32_fhopen_args *uap, register_t *retval)
284 /* {
285 syscallarg(const fhandle_t *) fhp;
286 syscallarg(int) flags;
287 } */
288 struct compat_30_sys_fhopen_args ua;
290 NETBSD32TOP_UAP(fhp, struct compat_30_fhandle);
291 NETBSD32TO64_UAP(flags);
292 return (compat_30_sys_fhopen(l, &ua, retval));