netbsd32_compat_20.c revision 1.1.2.5 1 /* $NetBSD: netbsd32_compat_20.c,v 1.1.2.5 2004/09/21 13:25:53 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.5 2004/09/21 13:25:53 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
107 maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
108 sfsp = (caddr_t)NETBSD32PTR64(SCARG(uap, buf));
109 simple_lock(&mountlist_slock);
110 count = 0;
111 for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
112 if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
113 nmp = mp->mnt_list.cqe_next;
114 continue;
115 }
116 if (sfsp && count < maxcount) {
117 sp = &mp->mnt_stat;
118 /*
119 * If MNT_NOWAIT or MNT_LAZY is specified, do not
120 * refresh the fsstat cache. MNT_WAIT or MNT_LAXY
121 * overrides MNT_NOWAIT.
122 */
123 if (SCARG(uap, flags) != MNT_NOWAIT &&
124 SCARG(uap, flags) != MNT_LAZY &&
125 (SCARG(uap, flags) == MNT_WAIT ||
126 SCARG(uap, flags) == 0) &&
127 (error = VFS_STATVFS(mp, sp, l)) != 0) {
128 simple_lock(&mountlist_slock);
129 nmp = mp->mnt_list.cqe_next;
130 vfs_unbusy(mp);
131 continue;
132 }
133 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
134 compat_20_netbsd32_from_statvfs(sp, &sb32);
135 error = copyout(&sb32, sfsp, sizeof(sb32));
136 if (error) {
137 vfs_unbusy(mp);
138 return (error);
139 }
140 sfsp += sizeof(sb32);
141 }
142 count++;
143 simple_lock(&mountlist_slock);
144 nmp = mp->mnt_list.cqe_next;
145 vfs_unbusy(mp);
146 }
147 simple_unlock(&mountlist_slock);
148 if (sfsp && count > maxcount)
149 *retval = maxcount;
150 else
151 *retval = count;
152 return (0);
153 }
154
155 int
156 compat_20_netbsd32_statfs(l, v, retval)
157 struct lwp *l;
158 void *v;
159 register_t *retval;
160 {
161 struct compat_20_netbsd32_statfs_args /* {
162 syscallarg(const netbsd32_charp) path;
163 syscallarg(netbsd32_statfsp_t) buf;
164 } */ *uap = v;
165 struct mount *mp;
166 struct statvfs *sp;
167 struct netbsd32_statfs s32;
168 int error;
169 struct nameidata nd;
170
171 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
172 (char *)NETBSD32PTR64(SCARG(uap, path)), l);
173 if ((error = namei(&nd)) != 0)
174 return (error);
175 mp = nd.ni_vp->v_mount;
176 sp = &mp->mnt_stat;
177 vrele(nd.ni_vp);
178 if ((error = VFS_STATVFS(mp, sp, l)) != 0)
179 return (error);
180 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
181 compat_20_netbsd32_from_statvfs(sp, &s32);
182 return (copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
183 sizeof(s32)));
184 }
185
186 int
187 compat_20_netbsd32_fstatfs(l, v, retval)
188 struct lwp *l;
189 void *v;
190 register_t *retval;
191 {
192 struct compat_20_netbsd32_fstatfs_args /* {
193 syscallarg(int) fd;
194 syscallarg(netbsd32_statfsp_t) buf;
195 } */ *uap = v;
196 struct file *fp;
197 struct mount *mp;
198 struct statvfs *sp;
199 struct netbsd32_statfs s32;
200 int error;
201 struct proc *p = l->l_proc;
202
203 /* getvnode() will use the descriptor for us */
204 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
205 return (error);
206 mp = ((struct vnode *)fp->f_data)->v_mount;
207 sp = &mp->mnt_stat;
208 if ((error = VFS_STATVFS(mp, sp, l)) != 0)
209 goto out;
210 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
211 compat_20_netbsd32_from_statvfs(sp, &s32);
212 error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
213 sizeof(s32));
214 out:
215 FILE_UNUSE(fp, l);
216 return (error);
217 }
218
219 int
220 compat_20_netbsd32_fhstatfs(l, v, retval)
221 struct lwp *l;
222 void *v;
223 register_t *retval;
224 {
225 struct compat_20_netbsd32_fhstatfs_args /* {
226 syscallarg(const netbsd32_fhandlep_t) fhp;
227 syscallarg(struct statvfs *) buf;
228 } */ *uap = v;
229 struct sys_fhstatvfs1_args ua;
230
231 NETBSD32TOP_UAP(fhp, const fhandle_t);
232 NETBSD32TOP_UAP(buf, struct statvfs);
233 #ifdef notyet
234 NETBSD32TOP_UAP(flags, int);
235 #endif
236 return (sys_fhstatvfs1(l, &ua, retval));
237 }
238