]>
git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/portal/portal_vfsops.c
2cdb39e788eb46446837819ade26009306179ed9
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1992, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
27 * This code is derived from software donated to Berkeley by
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
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.
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
58 * @(#)portal_vfsops.c 8.11 (Berkeley) 5/14/95
60 * @(#)portal_vfsops.c 8.6 (Berkeley) 1/21/94
67 #include <sys/param.h>
68 #include <sys/systm.h>
70 #include <sys/types.h>
72 #include <sys/filedesc.h>
74 #include <sys/vnode.h>
75 #include <sys/mount.h>
76 #include <sys/namei.h>
77 #include <sys/malloc.h>
79 #include <sys/socket.h>
80 #include <sys/socketvar.h>
81 #include <sys/protosw.h>
82 #include <sys/domain.h>
84 #include <miscfs/portal/portal.h>
95 * Mount the per-process file descriptors (/dev/fd)
98 portal_mount(mp
, path
, data
, ndp
, p
)
102 struct nameidata
*ndp
;
106 struct portal_args args
;
107 struct portalmount
*fmp
;
112 struct portalnode
*pnp
;
117 if (mp
->mnt_flag
& MNT_UPDATE
)
120 if (error
= copyin(data
, (caddr_t
) &args
, sizeof(struct portal_args
)))
123 if (error
= getsock(p
->p_fd
, args
.pa_socket
, &fp
))
125 so
= (struct socket
*) fp
->f_data
;
126 if (so
->so_proto
->pr_domain
->dom_family
!= AF_UNIX
)
127 return (ESOCKTNOSUPPORT
);
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 */
141 rvp
->v_flag
|= VROOT
;
142 VTOPORTAL(rvp
)->pt_arg
= 0;
143 VTOPORTAL(rvp
)->pt_size
= 0;
144 VTOPORTAL(rvp
)->pt_fileid
= PORTAL_ROOTFILEID
;
150 mp
->mnt_flag
|= MNT_LOCAL
;
151 mp
->mnt_data
= (qaddr_t
) fmp
;
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
);
161 bzero(mp
->mnt_stat
.f_mntfromname
, MNAMELEN
);
162 bcopy("portal", mp
->mnt_stat
.f_mntfromname
, sizeof("portal"));
169 portal_start(mp
, flags
, p
)
179 portal_unmount(mp
, mntflags
, p
)
184 struct vnode
*rootvp
= VFSTOPORTAL(mp
)->pm_root
;
185 int error
, flags
= 0;
188 if (mntflags
& MNT_FORCE
)
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...
198 if (mntinvalbuf(mp
, 1))
201 if (rootvp
->v_usecount
> 1)
203 if (error
= vflush(mp
, rootvp
, flags
))
207 * Release reference on underlying root vnode
211 * And blow it away for future re-use
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.
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
);
223 * Discard reference to underlying file. Must call closef because
224 * this may be the last reference.
226 closef(VFSTOPORTAL(mp
)->pm_server
, (struct proc
*) 0);
228 * Finally, throw away the portalmount structure
230 _FREE(mp
->mnt_data
, M_UFSMNT
); /* XXX */
240 struct proc
*p
= current_proc(); /* XXX */
244 * Return locked reference to root.
246 vp
= VFSTOPORTAL(mp
)->pm_root
;
248 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
, p
);
254 portal_statfs(mp
, sbp
, p
)
261 sbp
->f_bsize
= DEV_BSIZE
;
262 sbp
->f_iosize
= DEV_BSIZE
;
263 sbp
->f_blocks
= 2; /* 1K to keep df happy */
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
);
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 **))) \
287 #define portal_vptofh ((int (*) __P((struct vnode *, struct fid *)))eopnotsupp)
289 struct vfsops portal_vfsops
= {