1 /* $NetBSD: netbsd32_compat_30.c,v 1.28 2009/01/11 02:45:49 christos Exp $ */
4 * Copyright (c) 1998, 2001 Matthew R. Green
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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>
40 #include <sys/ktrace.h>
41 #include <sys/resourcevar.h>
42 #include <sys/vnode.h>
44 #include <sys/filedesc.h>
45 #include <sys/namei.h>
46 #include <sys/statvfs.h>
47 #include <sys/syscallargs.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>
60 compat_30_netbsd32_getdents(struct lwp
*l
, const struct compat_30_netbsd32_getdents_args
*uap
, register_t
*retval
)
64 syscallarg(netbsd32_charp) buf;
65 syscallarg(netbsd32_size_t) count;
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)
78 if ((fp
->f_flag
& FREAD
) == 0) {
82 buf
= malloc(count
, M_TEMP
, M_WAITOK
);
83 error
= vn_readdir(fp
, buf
, UIO_SYSSPACE
, count
, &done
, l
, 0, 0);
85 *retval
= netbsd32_to_dirent12(buf
, done
);
86 error
= copyout(buf
, SCARG_P32(uap
, buf
), *retval
);
90 fd_putfile(SCARG(uap
, fd
));
95 compat_30_netbsd32___stat13(struct lwp
*l
, const struct compat_30_netbsd32___stat13_args
*uap
, register_t
*retval
)
98 syscallarg(const netbsd32_charp) path;
99 syscallarg(netbsd32_stat13p_t) ub;
101 struct netbsd32_stat13 sb32
;
106 path
= SCARG_P32(uap
, path
);
108 error
= do_sys_stat(path
, FOLLOW
, &sb
);
111 netbsd32_from___stat13(&sb
, &sb32
);
112 error
= copyout(&sb32
, SCARG_P32(uap
, ub
), sizeof(sb32
));
117 compat_30_netbsd32___fstat13(struct lwp
*l
, const struct compat_30_netbsd32___fstat13_args
*uap
, register_t
*retval
)
121 syscallarg(netbsd32_stat13p_t) sb;
123 struct netbsd32_stat13 sb32
;
127 error
= do_sys_fstat(SCARG(uap
, fd
), &ub
);
129 netbsd32_from___stat13(&ub
, &sb32
);
130 error
= copyout(&sb32
, SCARG_P32(uap
, sb
), sizeof(sb32
));
136 compat_30_netbsd32___lstat13(struct lwp
*l
, const struct compat_30_netbsd32___lstat13_args
*uap
, register_t
*retval
)
139 syscallarg(const netbsd32_charp) path;
140 syscallarg(netbsd32_stat13p_t) ub;
142 struct netbsd32_stat13 sb32
;
147 path
= SCARG_P32(uap
, path
);
149 error
= do_sys_stat(path
, NOFOLLOW
, &sb
);
152 netbsd32_from___stat13(&sb
, &sb32
);
153 error
= copyout(&sb32
, SCARG_P32(uap
, ub
), sizeof(sb32
));
158 compat_30_netbsd32_fhstat(struct lwp
*l
, const struct compat_30_netbsd32_fhstat_args
*uap
, register_t
*retval
)
161 syscallarg(const netbsd32_fhandlep_t) fhp;
162 syscallarg(netbsd32_stat13p_t) sb;
165 struct netbsd32_stat13 sb32
;
167 struct compat_30_fhandle fh
;
174 if ((error
= kauth_authorize_system(l
->l_cred
,
175 KAUTH_SYSTEM_FILEHANDLE
, 0, NULL
, NULL
, NULL
)))
178 if ((error
= copyin(SCARG_P32(uap
, fhp
), &fh
, sizeof(fh
))) != 0)
181 if ((mp
= vfs_getvfs(&fh
.fh_fsid
)) == NULL
)
183 if (mp
->mnt_op
->vfs_fhtovp
== NULL
)
185 if ((error
= VFS_FHTOVP(mp
, (struct fid
*)&fh
.fh_fid
, &vp
)))
187 error
= vn_stat(vp
, &sb
);
191 netbsd32_from___stat13(&sb
, &sb32
);
192 error
= copyout(&sb32
, SCARG_P32(uap
, sb
), sizeof(sb
));
197 compat_30_netbsd32_fhstatvfs1(struct lwp
*l
, const struct compat_30_netbsd32_fhstatvfs1_args
*uap
, register_t
*retval
)
200 syscallarg(const netbsd32_fhandlep_t) fhp;
201 syscallarg(netbsd32_statvfsp_t) buf;
202 syscallarg(int) flags;
204 struct statvfs
*sbuf
;
205 struct netbsd32_statvfs
*s32
;
208 sbuf
= STATVFSBUF_GET();
209 error
= do_fhstatvfs(l
, SCARG_P32(uap
, fhp
), FHANDLE_SIZE_COMPAT
, sbuf
,
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
);
218 STATVFSBUF_PUT(sbuf
);
224 compat_30_netbsd32_socket(struct lwp
*l
, const struct compat_30_netbsd32_socket_args
*uap
, register_t
*retval
)
227 syscallarg(int) domain;
228 syscallarg(int) type;
229 syscallarg(int) protocol;
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
)
243 syscallarg(const netbsd32_charp) fname;
244 syscallarg(netbsd32_compat_30_fhandlep_t) fhp;
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
)
259 syscallarg(const netbsd32_fhandlep_t) fhp;
260 syscallarg(netbsd32_statp_t) sb;
263 struct netbsd32_stat50 sb32
;
266 error
= do_fhstat(l
, SCARG_P32(uap
, fhp
), FHANDLE_SIZE_COMPAT
, &sb
);
270 netbsd32_from___stat50(&sb
, &sb32
);
271 error
= copyout(&sb32
, SCARG_P32(uap
, sb
), sizeof(sb32
));
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
)
285 syscallarg(const fhandle_t *) fhp;
286 syscallarg(int) flags;
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
));