netbsd32_compat_20.c revision 1.1.2.4 1 /* $NetBSD: netbsd32_compat_20.c,v 1.1.2.4 2004/09/18 14:43:58 skrll 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_20.c,v 1.1.2.4 2004/09/18 14:43:58 skrll 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/stat.h>
43 #include <sys/time.h>
44 #include <sys/ktrace.h>
45 #include <sys/vnode.h>
46 #include <sys/file.h>
47 #include <sys/filedesc.h>
48 #include <sys/namei.h>
49 #include <sys/sa.h>
50 #include <sys/syscallargs.h>
51 #include <sys/proc.h>
52
53 #include <compat/netbsd32/netbsd32.h>
54 #include <compat/netbsd32/netbsd32_syscallargs.h>
55 #include <compat/netbsd32/netbsd32_conv.h>
56
57 static __inline void compat_20_netbsd32_from_statvfs(struct statvfs *,
58 struct netbsd32_statfs *);
59
60 static __inline void
61 compat_20_netbsd32_from_statvfs(sbp, sb32p)
62 struct statvfs *sbp;
63 struct netbsd32_statfs *sb32p;
64 {
65 sb32p->f_flags = sbp->f_flag;
66 sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
67 sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
68 sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
69 sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
70 sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
71 sb32p->f_files = (netbsd32_long)sbp->f_files;
72 sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
73 sb32p->f_fsid = sbp->f_fsidx;
74 sb32p->f_owner = sbp->f_owner;
75 sb32p->f_spare[0] = 0;
76 sb32p->f_spare[1] = 0;
77 sb32p->f_spare[2] = 0;
78 sb32p->f_spare[3] = 0;
79 #if 1
80 /* May as well do the whole batch in one go */
81 memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
82 #else
83 /* If we want to be careful */
84 memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
85 memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
86 memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
87 #endif
88 }
89
90 int
91 compat_20_netbsd32_getfsstat(l, v, retval)
92 struct lwp *l;
93 void *v;
94 register_t *retval;
95 {
96 struct compat_20_netbsd32_getfsstat_args /* {
97 syscallarg(netbsd32_statfsp_t) buf;
98 syscallarg(netbsd32_long) bufsize;
99 syscallarg(int) flags;
100 } */ *uap = v;
101 struct mount *mp, *nmp;
102 struct statvfs *sp;
103 struct netbsd32_statfs sb32;
104 caddr_t sfsp;
105 long count, maxcount, error;
106 struct proc *p = l->l_proc;
107
108 maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
109 sfsp = (caddr_t)NETBSD32PTR64(SCARG(uap, buf));
110 simple_lock(&mountlist_slock);
111 count = 0;
112 for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
113 if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
114 nmp = mp->mnt_list.cqe_next;
115 continue;
116 }
117 if (sfsp && count < maxcount) {
118 sp = &mp->mnt_stat;
119 /*
120 * If MNT_NOWAIT or MNT_LAZY is specified, do not
121 * refresh the fsstat cache. MNT_WAIT or MNT_LAXY
122 * overrides MNT_NOWAIT.
123 */
124 if (SCARG(uap, flags) != MNT_NOWAIT &&
125 SCARG(uap, flags) != MNT_LAZY &&
126 (SCARG(uap, flags) == MNT_WAIT ||
127 SCARG(uap, flags) == 0) &&
128 (error = VFS_STATVFS(mp, sp, p)) != 0) {
129 simple_lock(&mountlist_slock);
130 nmp = mp->mnt_list.cqe_next;
131 vfs_unbusy(mp);
132 continue;
133 }
134 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
135 compat_20_netbsd32_from_statvfs(sp, &sb32);
136 error = copyout(&sb32, sfsp, sizeof(sb32));
137 if (error) {
138 vfs_unbusy(mp);
139 return (error);
140 }
141 sfsp += sizeof(sb32);
142 }
143 count++;
144 simple_lock(&mountlist_slock);
145 nmp = mp->mnt_list.cqe_next;
146 vfs_unbusy(mp);
147 }
148 simple_unlock(&mountlist_slock);
149 if (sfsp && count > maxcount)
150 *retval = maxcount;
151 else
152 *retval = count;
153 return (0);
154 }
155
156 int
157 compat_20_netbsd32_statfs(l, v, retval)
158 struct lwp *l;
159 void *v;
160 register_t *retval;
161 {
162 struct compat_20_netbsd32_statfs_args /* {
163 syscallarg(const netbsd32_charp) path;
164 syscallarg(netbsd32_statfsp_t) buf;
165 } */ *uap = v;
166 struct mount *mp;
167 struct statvfs *sp;
168 struct netbsd32_statfs s32;
169 int error;
170 struct nameidata nd;
171 struct proc *p = l->l_proc;
172
173 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
174 (char *)NETBSD32PTR64(SCARG(uap, path)), p);
175 if ((error = namei(&nd)) != 0)
176 return (error);
177 mp = nd.ni_vp->v_mount;
178 sp = &mp->mnt_stat;
179 vrele(nd.ni_vp);
180 if ((error = VFS_STATVFS(mp, sp, p)) != 0)
181 return (error);
182 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
183 compat_20_netbsd32_from_statvfs(sp, &s32);
184 return (copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
185 sizeof(s32)));
186 }
187
188 int
189 compat_20_netbsd32_fstatfs(l, v, retval)
190 struct lwp *l;
191 void *v;
192 register_t *retval;
193 {
194 struct compat_20_netbsd32_fstatfs_args /* {
195 syscallarg(int) fd;
196 syscallarg(netbsd32_statfsp_t) buf;
197 } */ *uap = v;
198 struct file *fp;
199 struct mount *mp;
200 struct statvfs *sp;
201 struct netbsd32_statfs s32;
202 int error;
203 struct proc *p = l->l_proc;
204
205 /* getvnode() will use the descriptor for us */
206 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
207 return (error);
208 mp = ((struct vnode *)fp->f_data)->v_mount;
209 sp = &mp->mnt_stat;
210 if ((error = VFS_STATVFS(mp, sp, p)) != 0)
211 goto out;
212 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
213 compat_20_netbsd32_from_statvfs(sp, &s32);
214 error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
215 sizeof(s32));
216 out:
217 FILE_UNUSE(fp, p);
218 return (error);
219 }
220
221 int
222 compat_20_netbsd32_fhstatfs(l, v, retval)
223 struct lwp *l;
224 void *v;
225 register_t *retval;
226 {
227 struct compat_20_netbsd32_fhstatfs_args /* {
228 syscallarg(const netbsd32_fhandlep_t) fhp;
229 syscallarg(struct statvfs *) buf;
230 } */ *uap = v;
231 struct sys_fhstatvfs1_args ua;
232
233 NETBSD32TOP_UAP(fhp, const fhandle_t);
234 NETBSD32TOP_UAP(buf, struct statvfs);
235 #ifdef notyet
236 NETBSD32TOP_UAP(flags, int);
237 #endif
238 return (sys_fhstatvfs1(l, &ua, retval));
239 }
240