Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / osf1 / osf1_mount.c
blob693d1ed83aca4a59e78c6cc60a9d4f473d5300e7
1 /* $NetBSD: osf1_mount.c,v 1.45 2008/06/24 11:18:15 ad Exp $ */
3 /*
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
60 #include <sys/cdefs.h>
61 __KERNEL_RCSID(0, "$NetBSD: osf1_mount.c,v 1.45 2008/06/24 11:18:15 ad Exp $");
63 #if defined(_KERNEL_OPT)
64 #include "fs_nfs.h"
65 #endif
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/namei.h>
70 #include <sys/proc.h>
71 #include <sys/file.h>
72 #include <sys/filedesc.h>
73 #include <sys/kernel.h>
74 #include <sys/mount.h>
75 #include <sys/vnode.h>
76 #include <sys/syscallargs.h>
78 #include <compat/osf1/osf1.h>
79 #include <compat/osf1/osf1_syscallargs.h>
80 #include <compat/common/compat_util.h>
81 #include <compat/osf1/osf1_cvt.h>
83 #include <net/if.h>
84 #include <netinet/in.h>
86 #include <nfs/rpcv2.h>
87 #include <nfs/nfsproto.h>
88 #include <nfs/nfs.h>
89 #include <nfs/nfsmount.h>
91 #include <ufs/ufs/quota.h>
92 #include <ufs/ufs/ufsmount.h>
94 #include <machine/vmparam.h>
96 #define OSF1_MNT_WAIT 0x1
97 #define OSF1_MNT_NOWAIT 0x2
99 #define OSF1_MNT_FORCE 0x1
100 #define OSF1_MNT_NOFORCE 0x2
102 /* acceptable flags for various calls */
103 #define OSF1_GETFSSTAT_FLAGS (OSF1_MNT_WAIT|OSF1_MNT_NOWAIT)
104 #define OSF1_MOUNT_FLAGS 0xffffffff /* XXX */
105 #define OSF1_UNMOUNT_FLAGS (OSF1_MNT_FORCE|OSF1_MNT_NOFORCE)
108 static int osf1_mount_mfs(struct lwp *, const struct osf1_sys_mount_args *);
109 static int osf1_mount_nfs(struct lwp *, const struct osf1_sys_mount_args *);
112 osf1_sys_fstatfs(struct lwp *l, const struct osf1_sys_fstatfs_args *uap, register_t *retval)
114 file_t *fp;
115 struct mount *mp;
116 struct statvfs *sp;
117 struct osf1_statfs osfs;
118 int error;
120 /* fd_getvnode() will use the descriptor for us */
121 if ((error = fd_getvnode(SCARG(uap, fd), &fp)))
122 return (error);
123 mp = ((struct vnode *)fp->f_data)->v_mount;
124 sp = &mp->mnt_stat;
125 if ((error = VFS_STATVFS(mp, sp)))
126 goto out;
127 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
128 osf1_cvt_statfs_from_native(sp, &osfs);
129 error = copyout(&osfs, SCARG(uap, buf), min(sizeof osfs,
130 SCARG(uap, len)));
131 out:
132 fd_putfile(SCARG(uap, fd));
133 return (error);
137 osf1_sys_getfsstat(struct lwp *l, const struct osf1_sys_getfsstat_args *uap, register_t *retval)
139 struct mount *mp, *nmp;
140 struct statvfs *sp;
141 struct osf1_statfs osfs;
142 char *osf_sfsp;
143 long count, maxcount, error;
145 if (SCARG(uap, flags) & ~OSF1_GETFSSTAT_FLAGS)
146 return (EINVAL);
148 maxcount = SCARG(uap, bufsize) / sizeof(struct osf1_statfs);
149 osf_sfsp = (void *)SCARG(uap, buf);
150 mutex_enter(&mountlist_lock);
151 for (count = 0, mp = mountlist.cqh_first; mp != (void *)&mountlist;
152 mp = nmp) {
153 if (vfs_busy(mp, &nmp)) {
154 continue;
156 if (osf_sfsp && count < maxcount) {
157 sp = &mp->mnt_stat;
159 * If OSF1_MNT_NOWAIT is specified, do not refresh the
160 * fsstat cache. OSF1_MNT_WAIT overrides
161 * OSF1_MNT_NOWAIT.
163 if (((SCARG(uap, flags) & OSF1_MNT_NOWAIT) == 0 ||
164 (SCARG(uap, flags) & OSF1_MNT_WAIT)) &&
165 (error = VFS_STATVFS(mp, sp)) == 0) {
166 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
167 osf1_cvt_statfs_from_native(sp, &osfs);
168 if ((error = copyout(&osfs, osf_sfsp,
169 sizeof (struct osf1_statfs)))) {
170 vfs_unbusy(mp, false, NULL);
171 return (error);
173 osf_sfsp += sizeof (struct osf1_statfs);
176 count++;
177 vfs_unbusy(mp, false, &nmp);
179 mutex_exit(&mountlist_lock);
180 if (osf_sfsp && count > maxcount)
181 *retval = maxcount;
182 else
183 *retval = count;
184 return (0);
188 osf1_sys_mount(struct lwp *l, const struct osf1_sys_mount_args *uap, register_t *retval)
191 if (SCARG(uap, flags) & ~OSF1_MOUNT_FLAGS)
192 return (EINVAL);
194 /* XXX - xlate flags */
196 switch (SCARG(uap, type)) {
197 case OSF1_MOUNT_NFS:
198 return osf1_mount_nfs(l, uap);
199 break;
201 case OSF1_MOUNT_MFS:
202 return osf1_mount_mfs(l, uap);
204 default:
205 return (EINVAL);
210 osf1_sys_statfs(struct lwp *l, const struct osf1_sys_statfs_args *uap, register_t *retval)
212 struct mount *mp;
213 struct statvfs *sp;
214 struct osf1_statfs osfs;
215 int error;
216 struct vnode *vp;
218 error = namei_simple_user(SCARG(uap, path),
219 NSM_FOLLOW_TRYEMULROOT, &vp);
220 if (error != 0)
221 return (error);
222 mp = vp->v_mount;
223 sp = &mp->mnt_stat;
224 vrele(vp);
225 if ((error = VFS_STATVFS(mp, sp)))
226 return (error);
227 sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
228 osf1_cvt_statfs_from_native(sp, &osfs);
229 return copyout(&osfs, SCARG(uap, buf), min(sizeof osfs,
230 SCARG(uap, len)));
234 osf1_sys_unmount(struct lwp *l, const struct osf1_sys_unmount_args *uap, register_t *retval)
236 struct sys_unmount_args a;
238 SCARG(&a, path) = SCARG(uap, path);
240 if (SCARG(uap, flags) & ~OSF1_UNMOUNT_FLAGS)
241 return (EINVAL);
242 SCARG(&a, flags) = 0;
243 if ((SCARG(uap, flags) & OSF1_MNT_FORCE) &&
244 (SCARG(uap, flags) & OSF1_MNT_NOFORCE) == 0)
245 SCARG(&a, flags) |= MNT_FORCE;
247 return sys_unmount(l, &a, retval);
250 static int
251 osf1_mount_mfs(struct lwp *l, const struct osf1_sys_mount_args *uap)
253 struct osf1_mfs_args osf_ma;
254 struct mfs_args bsd_ma;
255 int error;
256 register_t dummy;
258 if ((error = copyin(SCARG(uap, data), &osf_ma, sizeof osf_ma)))
259 return error;
261 memset(&bsd_ma, 0, sizeof bsd_ma);
262 bsd_ma.fspec = osf_ma.name;
263 /* XXX export args */
264 bsd_ma.base = osf_ma.base;
265 bsd_ma.size = osf_ma.size;
267 return do_sys_mount(l, vfs_getopsbyname("mfs"), NULL, SCARG(uap, path),
268 SCARG(uap, flags), &bsd_ma, UIO_SYSSPACE, sizeof bsd_ma, &dummy);
271 static int
272 osf1_mount_nfs(struct lwp *l, const struct osf1_sys_mount_args *uap)
274 struct osf1_nfs_args osf_na;
275 struct nfs_args bsd_na;
276 int error;
277 unsigned long leftovers;
278 register_t dummy;
280 if ((error = copyin(SCARG(uap, data), &osf_na, sizeof osf_na)))
281 return error;
283 memset(&bsd_na, 0, sizeof bsd_na);
284 bsd_na.addr = (struct sockaddr *)osf_na.addr;
285 bsd_na.addrlen = sizeof (struct sockaddr_in);
286 bsd_na.fh = osf_na.fh;
288 /* translate flags */
289 bsd_na.flags = emul_flags_translate(osf1_nfs_mount_flags_xtab,
290 osf_na.flags, &leftovers);
291 if (leftovers & OSF1_NFSMNT_HOSTNAME) {
292 leftovers &= ~OSF1_NFSMNT_HOSTNAME;
293 bsd_na.hostname = osf_na.hostname;
294 } else {
295 /* XXX FILL IN HOST NAME WITH IPADDR? */
297 if (leftovers & OSF1_NFSMNT_TCP) {
298 leftovers &= ~OSF1_NFSMNT_TCP;
299 bsd_na.sotype = SOCK_DGRAM;
300 bsd_na.proto = 0;
301 } else {
302 bsd_na.sotype = SOCK_STREAM;
303 bsd_na.proto = 0;
305 if (leftovers != 0)
306 return (EINVAL);
308 /* copy structure elements based on flags */
309 if (bsd_na.flags & NFSMNT_WSIZE)
310 bsd_na.wsize = osf_na.wsize;
311 if (bsd_na.flags & NFSMNT_RSIZE)
312 bsd_na.rsize = osf_na.rsize;
313 if (bsd_na.flags & NFSMNT_TIMEO)
314 bsd_na.timeo = osf_na.timeo;
315 if (bsd_na.flags & NFSMNT_RETRANS)
316 bsd_na.retrans = osf_na.retrans;
318 return do_sys_mount(l, vfs_getopsbyname("nfs"), NULL, SCARG(uap, path),
319 SCARG(uap, flags), &bsd_na, UIO_SYSSPACE, sizeof bsd_na, &dummy);
321 return 0;