netbsd32_compat_20.c revision 1.5.2.2 1 1.5.2.2 thorpej /* $NetBSD: netbsd32_compat_20.c,v 1.5.2.2 2006/03/07 03:32:07 thorpej Exp $ */
2 1.5.2.2 thorpej
3 1.5.2.2 thorpej /*
4 1.5.2.2 thorpej * Copyright (c) 1998, 2001 Matthew R. Green
5 1.5.2.2 thorpej * All rights reserved.
6 1.5.2.2 thorpej *
7 1.5.2.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.5.2.2 thorpej * modification, are permitted provided that the following conditions
9 1.5.2.2 thorpej * are met:
10 1.5.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.5.2.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.5.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.5.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.5.2.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.5.2.2 thorpej * 3. The name of the author may not be used to endorse or promote products
16 1.5.2.2 thorpej * derived from this software without specific prior written permission.
17 1.5.2.2 thorpej *
18 1.5.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.5.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.5.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.5.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.5.2.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.5.2.2 thorpej * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.5.2.2 thorpej * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.5.2.2 thorpej * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.5.2.2 thorpej * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.5.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.5.2.2 thorpej * SUCH DAMAGE.
29 1.5.2.2 thorpej */
30 1.5.2.2 thorpej
31 1.5.2.2 thorpej #include <sys/cdefs.h>
32 1.5.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.5.2.2 2006/03/07 03:32:07 thorpej Exp $");
33 1.5.2.2 thorpej
34 1.5.2.2 thorpej #include <sys/param.h>
35 1.5.2.2 thorpej #include <sys/systm.h>
36 1.5.2.2 thorpej #include <sys/malloc.h>
37 1.5.2.2 thorpej #include <sys/mount.h>
38 1.5.2.2 thorpej #include <sys/stat.h>
39 1.5.2.2 thorpej #include <sys/time.h>
40 1.5.2.2 thorpej #include <sys/ktrace.h>
41 1.5.2.2 thorpej #include <sys/vnode.h>
42 1.5.2.2 thorpej #include <sys/file.h>
43 1.5.2.2 thorpej #include <sys/filedesc.h>
44 1.5.2.2 thorpej #include <sys/namei.h>
45 1.5.2.2 thorpej #include <sys/sa.h>
46 1.5.2.2 thorpej #include <sys/syscallargs.h>
47 1.5.2.2 thorpej #include <sys/proc.h>
48 1.5.2.2 thorpej #include <sys/dirent.h>
49 1.5.2.2 thorpej
50 1.5.2.2 thorpej #include <compat/netbsd32/netbsd32.h>
51 1.5.2.2 thorpej #include <compat/netbsd32/netbsd32_syscallargs.h>
52 1.5.2.2 thorpej #include <compat/netbsd32/netbsd32_conv.h>
53 1.5.2.2 thorpej
54 1.5.2.2 thorpej static inline void compat_20_netbsd32_from_statvfs(struct statvfs *,
55 1.5.2.2 thorpej struct netbsd32_statfs *);
56 1.5.2.2 thorpej
57 1.5.2.2 thorpej static inline void
58 1.5.2.2 thorpej compat_20_netbsd32_from_statvfs(sbp, sb32p)
59 1.5.2.2 thorpej struct statvfs *sbp;
60 1.5.2.2 thorpej struct netbsd32_statfs *sb32p;
61 1.5.2.2 thorpej {
62 1.5.2.2 thorpej sb32p->f_flags = sbp->f_flag;
63 1.5.2.2 thorpej sb32p->f_bsize = (netbsd32_long)sbp->f_bsize;
64 1.5.2.2 thorpej sb32p->f_iosize = (netbsd32_long)sbp->f_iosize;
65 1.5.2.2 thorpej sb32p->f_blocks = (netbsd32_long)sbp->f_blocks;
66 1.5.2.2 thorpej sb32p->f_bfree = (netbsd32_long)sbp->f_bfree;
67 1.5.2.2 thorpej sb32p->f_bavail = (netbsd32_long)sbp->f_bavail;
68 1.5.2.2 thorpej sb32p->f_files = (netbsd32_long)sbp->f_files;
69 1.5.2.2 thorpej sb32p->f_ffree = (netbsd32_long)sbp->f_ffree;
70 1.5.2.2 thorpej sb32p->f_fsid = sbp->f_fsidx;
71 1.5.2.2 thorpej sb32p->f_owner = sbp->f_owner;
72 1.5.2.2 thorpej sb32p->f_spare[0] = 0;
73 1.5.2.2 thorpej sb32p->f_spare[1] = 0;
74 1.5.2.2 thorpej sb32p->f_spare[2] = 0;
75 1.5.2.2 thorpej sb32p->f_spare[3] = 0;
76 1.5.2.2 thorpej #if 1
77 1.5.2.2 thorpej /* May as well do the whole batch in one go */
78 1.5.2.2 thorpej memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN+MNAMELEN+MNAMELEN);
79 1.5.2.2 thorpej #else
80 1.5.2.2 thorpej /* If we want to be careful */
81 1.5.2.2 thorpej memcpy(sb32p->f_fstypename, sbp->f_fstypename, MFSNAMELEN);
82 1.5.2.2 thorpej memcpy(sb32p->f_mntonname, sbp->f_mntonname, MNAMELEN);
83 1.5.2.2 thorpej memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, MNAMELEN);
84 1.5.2.2 thorpej #endif
85 1.5.2.2 thorpej }
86 1.5.2.2 thorpej
87 1.5.2.2 thorpej int
88 1.5.2.2 thorpej compat_20_netbsd32_getfsstat(l, v, retval)
89 1.5.2.2 thorpej struct lwp *l;
90 1.5.2.2 thorpej void *v;
91 1.5.2.2 thorpej register_t *retval;
92 1.5.2.2 thorpej {
93 1.5.2.2 thorpej struct compat_20_netbsd32_getfsstat_args /* {
94 1.5.2.2 thorpej syscallarg(netbsd32_statfsp_t) buf;
95 1.5.2.2 thorpej syscallarg(netbsd32_long) bufsize;
96 1.5.2.2 thorpej syscallarg(int) flags;
97 1.5.2.2 thorpej } */ *uap = v;
98 1.5.2.2 thorpej struct mount *mp, *nmp;
99 1.5.2.2 thorpej struct statvfs *sp;
100 1.5.2.2 thorpej struct netbsd32_statfs sb32;
101 1.5.2.2 thorpej caddr_t sfsp;
102 1.5.2.2 thorpej long count, maxcount, error;
103 1.5.2.2 thorpej
104 1.5.2.2 thorpej maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statfs);
105 1.5.2.2 thorpej sfsp = (caddr_t)NETBSD32PTR64(SCARG(uap, buf));
106 1.5.2.2 thorpej simple_lock(&mountlist_slock);
107 1.5.2.2 thorpej count = 0;
108 1.5.2.2 thorpej for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
109 1.5.2.2 thorpej if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
110 1.5.2.2 thorpej nmp = mp->mnt_list.cqe_next;
111 1.5.2.2 thorpej continue;
112 1.5.2.2 thorpej }
113 1.5.2.2 thorpej if (sfsp && count < maxcount) {
114 1.5.2.2 thorpej sp = &mp->mnt_stat;
115 1.5.2.2 thorpej /*
116 1.5.2.2 thorpej * If MNT_NOWAIT or MNT_LAZY is specified, do not
117 1.5.2.2 thorpej * refresh the fsstat cache. MNT_WAIT or MNT_LAXY
118 1.5.2.2 thorpej * overrides MNT_NOWAIT.
119 1.5.2.2 thorpej */
120 1.5.2.2 thorpej if (SCARG(uap, flags) != MNT_NOWAIT &&
121 1.5.2.2 thorpej SCARG(uap, flags) != MNT_LAZY &&
122 1.5.2.2 thorpej (SCARG(uap, flags) == MNT_WAIT ||
123 1.5.2.2 thorpej SCARG(uap, flags) == 0) &&
124 1.5.2.2 thorpej (error = VFS_STATVFS(mp, sp, l)) != 0) {
125 1.5.2.2 thorpej simple_lock(&mountlist_slock);
126 1.5.2.2 thorpej nmp = mp->mnt_list.cqe_next;
127 1.5.2.2 thorpej vfs_unbusy(mp);
128 1.5.2.2 thorpej continue;
129 1.5.2.2 thorpej }
130 1.5.2.2 thorpej sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
131 1.5.2.2 thorpej compat_20_netbsd32_from_statvfs(sp, &sb32);
132 1.5.2.2 thorpej error = copyout(&sb32, sfsp, sizeof(sb32));
133 1.5.2.2 thorpej if (error) {
134 1.5.2.2 thorpej vfs_unbusy(mp);
135 1.5.2.2 thorpej return (error);
136 1.5.2.2 thorpej }
137 1.5.2.2 thorpej sfsp += sizeof(sb32);
138 1.5.2.2 thorpej }
139 1.5.2.2 thorpej count++;
140 1.5.2.2 thorpej simple_lock(&mountlist_slock);
141 1.5.2.2 thorpej nmp = mp->mnt_list.cqe_next;
142 1.5.2.2 thorpej vfs_unbusy(mp);
143 1.5.2.2 thorpej }
144 1.5.2.2 thorpej simple_unlock(&mountlist_slock);
145 1.5.2.2 thorpej if (sfsp && count > maxcount)
146 1.5.2.2 thorpej *retval = maxcount;
147 1.5.2.2 thorpej else
148 1.5.2.2 thorpej *retval = count;
149 1.5.2.2 thorpej return (0);
150 1.5.2.2 thorpej }
151 1.5.2.2 thorpej
152 1.5.2.2 thorpej int
153 1.5.2.2 thorpej compat_20_netbsd32_statfs(l, v, retval)
154 1.5.2.2 thorpej struct lwp *l;
155 1.5.2.2 thorpej void *v;
156 1.5.2.2 thorpej register_t *retval;
157 1.5.2.2 thorpej {
158 1.5.2.2 thorpej struct compat_20_netbsd32_statfs_args /* {
159 1.5.2.2 thorpej syscallarg(const netbsd32_charp) path;
160 1.5.2.2 thorpej syscallarg(netbsd32_statfsp_t) buf;
161 1.5.2.2 thorpej } */ *uap = v;
162 1.5.2.2 thorpej struct mount *mp;
163 1.5.2.2 thorpej struct statvfs *sp;
164 1.5.2.2 thorpej struct netbsd32_statfs s32;
165 1.5.2.2 thorpej int error;
166 1.5.2.2 thorpej struct nameidata nd;
167 1.5.2.2 thorpej
168 1.5.2.2 thorpej NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
169 1.5.2.2 thorpej (char *)NETBSD32PTR64(SCARG(uap, path)), l);
170 1.5.2.2 thorpej if ((error = namei(&nd)) != 0)
171 1.5.2.2 thorpej return (error);
172 1.5.2.2 thorpej mp = nd.ni_vp->v_mount;
173 1.5.2.2 thorpej sp = &mp->mnt_stat;
174 1.5.2.2 thorpej vrele(nd.ni_vp);
175 1.5.2.2 thorpej if ((error = VFS_STATVFS(mp, sp, l)) != 0)
176 1.5.2.2 thorpej return (error);
177 1.5.2.2 thorpej sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
178 1.5.2.2 thorpej compat_20_netbsd32_from_statvfs(sp, &s32);
179 1.5.2.2 thorpej return (copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
180 1.5.2.2 thorpej sizeof(s32)));
181 1.5.2.2 thorpej }
182 1.5.2.2 thorpej
183 1.5.2.2 thorpej int
184 1.5.2.2 thorpej compat_20_netbsd32_fstatfs(l, v, retval)
185 1.5.2.2 thorpej struct lwp *l;
186 1.5.2.2 thorpej void *v;
187 1.5.2.2 thorpej register_t *retval;
188 1.5.2.2 thorpej {
189 1.5.2.2 thorpej struct compat_20_netbsd32_fstatfs_args /* {
190 1.5.2.2 thorpej syscallarg(int) fd;
191 1.5.2.2 thorpej syscallarg(netbsd32_statfsp_t) buf;
192 1.5.2.2 thorpej } */ *uap = v;
193 1.5.2.2 thorpej struct file *fp;
194 1.5.2.2 thorpej struct mount *mp;
195 1.5.2.2 thorpej struct statvfs *sp;
196 1.5.2.2 thorpej struct netbsd32_statfs s32;
197 1.5.2.2 thorpej int error;
198 1.5.2.2 thorpej struct proc *p = l->l_proc;
199 1.5.2.2 thorpej
200 1.5.2.2 thorpej /* getvnode() will use the descriptor for us */
201 1.5.2.2 thorpej if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
202 1.5.2.2 thorpej return (error);
203 1.5.2.2 thorpej mp = ((struct vnode *)fp->f_data)->v_mount;
204 1.5.2.2 thorpej sp = &mp->mnt_stat;
205 1.5.2.2 thorpej if ((error = VFS_STATVFS(mp, sp, l)) != 0)
206 1.5.2.2 thorpej goto out;
207 1.5.2.2 thorpej sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
208 1.5.2.2 thorpej compat_20_netbsd32_from_statvfs(sp, &s32);
209 1.5.2.2 thorpej error = copyout(&s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
210 1.5.2.2 thorpej sizeof(s32));
211 1.5.2.2 thorpej out:
212 1.5.2.2 thorpej FILE_UNUSE(fp, l);
213 1.5.2.2 thorpej return (error);
214 1.5.2.2 thorpej }
215 1.5.2.2 thorpej
216 1.5.2.2 thorpej int
217 1.5.2.2 thorpej compat_20_netbsd32_fhstatfs(l, v, retval)
218 1.5.2.2 thorpej struct lwp *l;
219 1.5.2.2 thorpej void *v;
220 1.5.2.2 thorpej register_t *retval;
221 1.5.2.2 thorpej {
222 1.5.2.2 thorpej struct compat_20_netbsd32_fhstatfs_args /* {
223 1.5.2.2 thorpej syscallarg(const netbsd32_fhandlep_t) fhp;
224 1.5.2.2 thorpej syscallarg(struct statvfs *) buf;
225 1.5.2.2 thorpej } */ *uap = v;
226 1.5.2.2 thorpej struct sys_fhstatvfs1_args ua;
227 1.5.2.2 thorpej
228 1.5.2.2 thorpej NETBSD32TOP_UAP(fhp, const fhandle_t);
229 1.5.2.2 thorpej NETBSD32TOP_UAP(buf, struct statvfs);
230 1.5.2.2 thorpej #ifdef notyet
231 1.5.2.2 thorpej NETBSD32TOP_UAP(flags, int);
232 1.5.2.2 thorpej #endif
233 1.5.2.2 thorpej return (sys_fhstatvfs1(l, &ua, retval));
234 1.5.2.2 thorpej }
235