]> git.saurik.com Git - apple/xnu.git/blame - bsd/miscfs/portal/portal_vfsops.c
xnu-201.42.3.tar.gz
[apple/xnu.git] / bsd / miscfs / portal / portal_vfsops.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23/*
24 * Copyright (c) 1992, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
26 *
27 * This code is derived from software donated to Berkeley by
28 * Jan-Simon Pendry.
29 *
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
45 *
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 *
58 * @(#)portal_vfsops.c 8.11 (Berkeley) 5/14/95
59 *
60 * @(#)portal_vfsops.c 8.6 (Berkeley) 1/21/94
61 */
62
63/*
64 * Portal Filesystem
65 */
66
67#include <sys/param.h>
68#include <sys/systm.h>
69#include <sys/time.h>
70#include <sys/types.h>
71#include <sys/proc.h>
72#include <sys/filedesc.h>
73#include <sys/file.h>
74#include <sys/vnode.h>
75#include <sys/mount.h>
76#include <sys/namei.h>
77#include <sys/malloc.h>
78#include <sys/mbuf.h>
79#include <sys/socket.h>
80#include <sys/socketvar.h>
81#include <sys/protosw.h>
82#include <sys/domain.h>
83#include <sys/un.h>
84#include <miscfs/portal/portal.h>
85
86int
87portal_init(vfsp)
88 struct vfsconf *vfsp;
89{
90
91 return (0);
92}
93
94/*
95 * Mount the per-process file descriptors (/dev/fd)
96 */
97int
98portal_mount(mp, path, data, ndp, p)
99 struct mount *mp;
100 char *path;
101 caddr_t data;
102 struct nameidata *ndp;
103 struct proc *p;
104{
105 struct file *fp;
106 struct portal_args args;
107 struct portalmount *fmp;
108 struct socket *so;
109 struct vnode *rvp;
110 u_int size;
111 int error;
112 struct portalnode *pnp;
113
114 /*
115 * Update is a no-op
116 */
117 if (mp->mnt_flag & MNT_UPDATE)
118 return (EOPNOTSUPP);
119
120 if (error = copyin(data, (caddr_t) &args, sizeof(struct portal_args)))
121 return (error);
122
123 if (error = getsock(p->p_fd, args.pa_socket, &fp))
124 return (error);
125 so = (struct socket *) fp->f_data;
126 if (so->so_proto->pr_domain->dom_family != AF_UNIX)
127 return (ESOCKTNOSUPPORT);
128
129 fmp = (struct portalmount *) _MALLOC(sizeof(struct portalmount),
130 M_UFSMNT, M_WAITOK); /* XXX */
131 MALLOC(pnp, void *, sizeof(struct portalnode), M_TEMP, M_WAITOK);
132 error = getnewvnode(VT_PORTAL, mp, portal_vnodeop_p, &rvp); /* XXX */
133 if (error) {
134 FREE(pnp, M_TEMP);
135 FREE(fmp, M_UFSMNT);
136 return (error);
137 }
138 rvp->v_data = pnp;
139
140 rvp->v_type = VDIR;
141 rvp->v_flag |= VROOT;
142 VTOPORTAL(rvp)->pt_arg = 0;
143 VTOPORTAL(rvp)->pt_size = 0;
144 VTOPORTAL(rvp)->pt_fileid = PORTAL_ROOTFILEID;
145 fmp->pm_root = rvp;
146 fmp->pm_server = fp;
147
148 (void)fref(fp);
149
150 mp->mnt_flag |= MNT_LOCAL;
151 mp->mnt_data = (qaddr_t) fmp;
152 vfs_getnewfsid(mp);
153
154 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
155 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
156 (void)copyinstr(args.pa_config,
157 mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
158 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
159
160#ifdef notdef
161 bzero(mp->mnt_stat.f_mntfromname, MNAMELEN);
162 bcopy("portal", mp->mnt_stat.f_mntfromname, sizeof("portal"));
163#endif
164
165 return (0);
166}
167
168int
169portal_start(mp, flags, p)
170 struct mount *mp;
171 int flags;
172 struct proc *p;
173{
174
175 return (0);
176}
177
178int
179portal_unmount(mp, mntflags, p)
180 struct mount *mp;
181 int mntflags;
182 struct proc *p;
183{
184 struct vnode *rootvp = VFSTOPORTAL(mp)->pm_root;
185 int error, flags = 0;
186
187
188 if (mntflags & MNT_FORCE)
189 flags |= FORCECLOSE;
190
191 /*
192 * Clear out buffer cache. I don't think we
193 * ever get anything cached at this level at the
194 * moment, but who knows...
195 */
196#ifdef notyet
197 mntflushbuf(mp, 0);
198 if (mntinvalbuf(mp, 1))
199 return (EBUSY);
200#endif
201 if (rootvp->v_usecount > 1)
202 return (EBUSY);
203 if (error = vflush(mp, rootvp, flags))
204 return (error);
205
206 /*
207 * Release reference on underlying root vnode
208 */
209 vrele(rootvp);
210 /*
211 * And blow it away for future re-use
212 */
213 vgone(rootvp);
214 /*
215 * Shutdown the socket. This will cause the select in the
216 * daemon to wake up, and then the accept will get ECONNABORTED
217 * which it interprets as a request to go and bury itself.
218 */
219 thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
220 soshutdown((struct socket *) VFSTOPORTAL(mp)->pm_server->f_data, 2);
221 thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
222 /*
223 * Discard reference to underlying file. Must call closef because
224 * this may be the last reference.
225 */
226 closef(VFSTOPORTAL(mp)->pm_server, (struct proc *) 0);
227 /*
228 * Finally, throw away the portalmount structure
229 */
230 _FREE(mp->mnt_data, M_UFSMNT); /* XXX */
231 mp->mnt_data = 0;
232 return (0);
233}
234
235int
236portal_root(mp, vpp)
237 struct mount *mp;
238 struct vnode **vpp;
239{
240 struct proc *p = current_proc(); /* XXX */
241 struct vnode *vp;
242
243 /*
244 * Return locked reference to root.
245 */
246 vp = VFSTOPORTAL(mp)->pm_root;
247 VREF(vp);
248 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
249 *vpp = vp;
250 return (0);
251}
252
253int
254portal_statfs(mp, sbp, p)
255 struct mount *mp;
256 struct statfs *sbp;
257 struct proc *p;
258{
259
260 sbp->f_flags = 0;
261 sbp->f_bsize = DEV_BSIZE;
262 sbp->f_iosize = DEV_BSIZE;
263 sbp->f_blocks = 2; /* 1K to keep df happy */
264 sbp->f_bfree = 0;
265 sbp->f_bavail = 0;
266 sbp->f_files = 1; /* Allow for "." */
267 sbp->f_ffree = 0; /* See comments above */
268 if (sbp != &mp->mnt_stat) {
269 sbp->f_type = mp->mnt_vfc->vfc_typenum;
270 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
271 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
272 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
273 }
274 return (0);
275}
276
277#define portal_fhtovp ((int (*) __P((struct mount *, struct fid *, \
278 struct mbuf *, struct vnode **, int *, struct ucred **)))eopnotsupp)
279#define portal_quotactl ((int (*) __P((struct mount *, int, uid_t, caddr_t, \
280 struct proc *)))eopnotsupp)
281#define portal_sync ((int (*) __P((struct mount *, int, struct ucred *, \
282 struct proc *)))nullop)
283#define portal_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \
284 size_t, struct proc *)))eopnotsupp)
285#define portal_vget ((int (*) __P((struct mount *, ino_t, struct vnode **))) \
286 eopnotsupp)
287#define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
288
289struct vfsops portal_vfsops = {
290 portal_mount,
291 portal_start,
292 portal_unmount,
293 portal_root,
294 portal_quotactl,
295 portal_statfs,
296 portal_sync,
297 portal_vget,
298 portal_fhtovp,
299 portal_vptofh,
300 portal_init,
301 portal_sysctl,
302};