xref: /freebsd/sys/fs/nullfs/null_vfsops.c (revision 6716c905c903b832cdd31a727619ae005e5e427a)
1df8bae1dSRodney W. Grimes /*
2996c772fSJohn Dyson  * Copyright (c) 1992, 1993, 1995
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software donated to Berkeley by
6df8bae1dSRodney W. Grimes  * Jan-Simon Pendry.
7df8bae1dSRodney W. Grimes  *
8df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
9df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
10df8bae1dSRodney W. Grimes  * are met:
11df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
12df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
13df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
15df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
16df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
17df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
18df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
19df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
20df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  *
36df8bae1dSRodney W. Grimes  *	@(#)null_vfsops.c	8.2 (Berkeley) 1/21/94
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  * @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
39c3aac50fSPeter Wemm  * $FreeBSD$
40df8bae1dSRodney W. Grimes  */
41df8bae1dSRodney W. Grimes 
42df8bae1dSRodney W. Grimes /*
43df8bae1dSRodney W. Grimes  * Null Layer
44df8bae1dSRodney W. Grimes  * (See null_vnops.c for a description of what this does.)
45df8bae1dSRodney W. Grimes  */
46df8bae1dSRodney W. Grimes 
47df8bae1dSRodney W. Grimes #include <sys/param.h>
48df8bae1dSRodney W. Grimes #include <sys/systm.h>
49fdc0430eSMike Pritchard #include <sys/kernel.h>
50996c772fSJohn Dyson #include <sys/proc.h>
51a1c995b6SPoul-Henning Kamp #include <sys/malloc.h>
52df8bae1dSRodney W. Grimes #include <sys/vnode.h>
53df8bae1dSRodney W. Grimes #include <sys/mount.h>
54df8bae1dSRodney W. Grimes #include <sys/namei.h>
55df8bae1dSRodney W. Grimes #include <miscfs/nullfs/null.h>
56df8bae1dSRodney W. Grimes 
57a1c995b6SPoul-Henning Kamp static MALLOC_DEFINE(M_NULLFSMNT, "NULLFS mount", "NULLFS mount structure");
58a1c995b6SPoul-Henning Kamp 
597da1e3f0SBoris Popov static int	nullfs_fhtovp(struct mount *mp, struct fid *fidp,
607da1e3f0SBoris Popov 				   struct vnode **vpp);
617da1e3f0SBoris Popov static int	nullfs_checkexp(struct mount *mp, struct sockaddr *nam,
627da1e3f0SBoris Popov 				    int *extflagsp, struct ucred **credanonp);
637da1e3f0SBoris Popov static int	nullfs_mount(struct mount *mp, char *path, caddr_t data,
647da1e3f0SBoris Popov 				  struct nameidata *ndp, struct proc *p);
657da1e3f0SBoris Popov static int	nullfs_quotactl(struct mount *mp, int cmd, uid_t uid,
667da1e3f0SBoris Popov 				     caddr_t arg, struct proc *p);
677da1e3f0SBoris Popov static int	nullfs_root(struct mount *mp, struct vnode **vpp);
687da1e3f0SBoris Popov static int	nullfs_start(struct mount *mp, int flags, struct proc *p);
697da1e3f0SBoris Popov static int	nullfs_statfs(struct mount *mp, struct statfs *sbp,
707da1e3f0SBoris Popov 				   struct proc *p);
717da1e3f0SBoris Popov static int	nullfs_sync(struct mount *mp, int waitfor,
727da1e3f0SBoris Popov 				 struct ucred *cred, struct proc *p);
737da1e3f0SBoris Popov static int	nullfs_unmount(struct mount *mp, int mntflags, struct proc *p);
747da1e3f0SBoris Popov static int	nullfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp);
757da1e3f0SBoris Popov static int	nullfs_vptofh(struct vnode *vp, struct fid *fhp);
764451405fSBoris Popov static int	nullfs_extattrctl(struct mount *mp, int cmd,
774451405fSBoris Popov 			const char *attrname, caddr_t arg, struct proc *p);
789b5e8b3aSBruce Evans 
79df8bae1dSRodney W. Grimes /*
80df8bae1dSRodney W. Grimes  * Mount null layer
81df8bae1dSRodney W. Grimes  */
82d4b7a369SPoul-Henning Kamp static int
83df8bae1dSRodney W. Grimes nullfs_mount(mp, path, data, ndp, p)
84df8bae1dSRodney W. Grimes 	struct mount *mp;
85df8bae1dSRodney W. Grimes 	char *path;
86df8bae1dSRodney W. Grimes 	caddr_t data;
87df8bae1dSRodney W. Grimes 	struct nameidata *ndp;
88df8bae1dSRodney W. Grimes 	struct proc *p;
89df8bae1dSRodney W. Grimes {
90df8bae1dSRodney W. Grimes 	int error = 0;
91df8bae1dSRodney W. Grimes 	struct null_args args;
92df8bae1dSRodney W. Grimes 	struct vnode *lowerrootvp, *vp;
93df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp;
94df8bae1dSRodney W. Grimes 	struct null_mount *xmp;
95df8bae1dSRodney W. Grimes 	u_int size;
96f85e8fc5SKATO Takenori 	int isvnunlocked = 0;
97df8bae1dSRodney W. Grimes 
988da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp);
99df8bae1dSRodney W. Grimes 
100df8bae1dSRodney W. Grimes 	/*
101df8bae1dSRodney W. Grimes 	 * Update is a no-op
102df8bae1dSRodney W. Grimes 	 */
103df8bae1dSRodney W. Grimes 	if (mp->mnt_flag & MNT_UPDATE) {
104df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
105df8bae1dSRodney W. Grimes 		/* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, p);*/
106df8bae1dSRodney W. Grimes 	}
107df8bae1dSRodney W. Grimes 
108df8bae1dSRodney W. Grimes 	/*
109df8bae1dSRodney W. Grimes 	 * Get argument
110df8bae1dSRodney W. Grimes 	 */
1113a773ad0SPoul-Henning Kamp 	error = copyin(data, (caddr_t)&args, sizeof(struct null_args));
1123a773ad0SPoul-Henning Kamp 	if (error)
113df8bae1dSRodney W. Grimes 		return (error);
114df8bae1dSRodney W. Grimes 
115df8bae1dSRodney W. Grimes 	/*
116f85e8fc5SKATO Takenori 	 * Unlock lower node to avoid deadlock.
117f85e8fc5SKATO Takenori 	 * (XXX) VOP_ISLOCKED is needed?
118f85e8fc5SKATO Takenori 	 */
119f85e8fc5SKATO Takenori 	if ((mp->mnt_vnodecovered->v_op == null_vnodeop_p) &&
1206bdfe06aSEivind Eklund 		VOP_ISLOCKED(mp->mnt_vnodecovered, NULL)) {
121f85e8fc5SKATO Takenori 		VOP_UNLOCK(mp->mnt_vnodecovered, 0, p);
122f85e8fc5SKATO Takenori 		isvnunlocked = 1;
123f85e8fc5SKATO Takenori 	}
124f85e8fc5SKATO Takenori 	/*
125df8bae1dSRodney W. Grimes 	 * Find lower node
126df8bae1dSRodney W. Grimes 	 */
127df8bae1dSRodney W. Grimes 	NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
128df8bae1dSRodney W. Grimes 		UIO_USERSPACE, args.target, p);
1293a773ad0SPoul-Henning Kamp 	error = namei(ndp);
130f85e8fc5SKATO Takenori 	/*
131f85e8fc5SKATO Takenori 	 * Re-lock vnode.
132f85e8fc5SKATO Takenori 	 */
1336bdfe06aSEivind Eklund 	if (isvnunlocked && !VOP_ISLOCKED(mp->mnt_vnodecovered, NULL))
134f85e8fc5SKATO Takenori 		vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY, p);
135f85e8fc5SKATO Takenori 
1363a773ad0SPoul-Henning Kamp 	if (error)
137df8bae1dSRodney W. Grimes 		return (error);
138762e6b85SEivind Eklund 	NDFREE(ndp, NDF_ONLY_PNBUF);
139df8bae1dSRodney W. Grimes 
140df8bae1dSRodney W. Grimes 	/*
141df8bae1dSRodney W. Grimes 	 * Sanity check on lower vnode
142df8bae1dSRodney W. Grimes 	 */
143df8bae1dSRodney W. Grimes 	lowerrootvp = ndp->ni_vp;
144df8bae1dSRodney W. Grimes 
145df8bae1dSRodney W. Grimes 	vrele(ndp->ni_dvp);
146c5e17d9eSKATO Takenori 	ndp->ni_dvp = NULLVP;
147df8bae1dSRodney W. Grimes 
148f85e8fc5SKATO Takenori 	/*
149f85e8fc5SKATO Takenori 	 * Check multi null mount to avoid `lock against myself' panic.
150f85e8fc5SKATO Takenori 	 */
151f85e8fc5SKATO Takenori 	if (lowerrootvp == VTONULL(mp->mnt_vnodecovered)->null_lowervp) {
1528da80660SBoris Popov 		NULLFSDEBUG("nullfs_mount: multi null mount?\n");
1536716c905SBoris Popov 		vput(lowerrootvp);
154747e9157SKATO Takenori 		return (EDEADLK);
155f85e8fc5SKATO Takenori 	}
156f85e8fc5SKATO Takenori 
157df8bae1dSRodney W. Grimes 	xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
158a1c995b6SPoul-Henning Kamp 				M_NULLFSMNT, M_WAITOK);	/* XXX */
159df8bae1dSRodney W. Grimes 
160df8bae1dSRodney W. Grimes 	/*
161df8bae1dSRodney W. Grimes 	 * Save reference to underlying FS
162df8bae1dSRodney W. Grimes 	 */
163df8bae1dSRodney W. Grimes 	xmp->nullm_vfs = lowerrootvp->v_mount;
164df8bae1dSRodney W. Grimes 
165df8bae1dSRodney W. Grimes 	/*
166df8bae1dSRodney W. Grimes 	 * Save reference.  Each mount also holds
167df8bae1dSRodney W. Grimes 	 * a reference on the root vnode.
168df8bae1dSRodney W. Grimes 	 */
169df8bae1dSRodney W. Grimes 	error = null_node_create(mp, lowerrootvp, &vp);
170df8bae1dSRodney W. Grimes 	/*
171df8bae1dSRodney W. Grimes 	 * Unlock the node (either the lower or the alias)
172df8bae1dSRodney W. Grimes 	 */
173996c772fSJohn Dyson 	VOP_UNLOCK(vp, 0, p);
174df8bae1dSRodney W. Grimes 	/*
175df8bae1dSRodney W. Grimes 	 * Make sure the node alias worked
176df8bae1dSRodney W. Grimes 	 */
177df8bae1dSRodney W. Grimes 	if (error) {
178df8bae1dSRodney W. Grimes 		vrele(lowerrootvp);
179a1c995b6SPoul-Henning Kamp 		free(xmp, M_NULLFSMNT);	/* XXX */
180df8bae1dSRodney W. Grimes 		return (error);
181df8bae1dSRodney W. Grimes 	}
182df8bae1dSRodney W. Grimes 
183df8bae1dSRodney W. Grimes 	/*
184df8bae1dSRodney W. Grimes 	 * Keep a held reference to the root vnode.
185df8bae1dSRodney W. Grimes 	 * It is vrele'd in nullfs_unmount.
186df8bae1dSRodney W. Grimes 	 */
187df8bae1dSRodney W. Grimes 	nullm_rootvp = vp;
188df8bae1dSRodney W. Grimes 	nullm_rootvp->v_flag |= VROOT;
189df8bae1dSRodney W. Grimes 	xmp->nullm_rootvp = nullm_rootvp;
190df8bae1dSRodney W. Grimes 	if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
191df8bae1dSRodney W. Grimes 		mp->mnt_flag |= MNT_LOCAL;
192df8bae1dSRodney W. Grimes 	mp->mnt_data = (qaddr_t) xmp;
193996c772fSJohn Dyson 	vfs_getnewfsid(mp);
194df8bae1dSRodney W. Grimes 
195df8bae1dSRodney W. Grimes 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
196df8bae1dSRodney W. Grimes 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
197df8bae1dSRodney W. Grimes 	(void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
198df8bae1dSRodney W. Grimes 	    &size);
199df8bae1dSRodney W. Grimes 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
200cf6347f7SBruce Evans 	(void)nullfs_statfs(mp, &mp->mnt_stat, p);
2018da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount: lower %s, alias at %s\n",
202df8bae1dSRodney W. Grimes 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
203df8bae1dSRodney W. Grimes 	return (0);
204df8bae1dSRodney W. Grimes }
205df8bae1dSRodney W. Grimes 
206df8bae1dSRodney W. Grimes /*
207df8bae1dSRodney W. Grimes  * VFS start.  Nothing needed here - the start routine
208df8bae1dSRodney W. Grimes  * on the underlying filesystem will have been called
209df8bae1dSRodney W. Grimes  * when that filesystem was mounted.
210df8bae1dSRodney W. Grimes  */
211d4b7a369SPoul-Henning Kamp static int
212df8bae1dSRodney W. Grimes nullfs_start(mp, flags, p)
213df8bae1dSRodney W. Grimes 	struct mount *mp;
214df8bae1dSRodney W. Grimes 	int flags;
215df8bae1dSRodney W. Grimes 	struct proc *p;
216df8bae1dSRodney W. Grimes {
217df8bae1dSRodney W. Grimes 	return (0);
218df8bae1dSRodney W. Grimes 	/* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, p); */
219df8bae1dSRodney W. Grimes }
220df8bae1dSRodney W. Grimes 
221df8bae1dSRodney W. Grimes /*
222df8bae1dSRodney W. Grimes  * Free reference to null layer
223df8bae1dSRodney W. Grimes  */
224d4b7a369SPoul-Henning Kamp static int
225df8bae1dSRodney W. Grimes nullfs_unmount(mp, mntflags, p)
226df8bae1dSRodney W. Grimes 	struct mount *mp;
227df8bae1dSRodney W. Grimes 	int mntflags;
228df8bae1dSRodney W. Grimes 	struct proc *p;
229df8bae1dSRodney W. Grimes {
2304451405fSBoris Popov 	struct vnode *vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
2318da80660SBoris Popov 	void *mntdata;
232df8bae1dSRodney W. Grimes 	int error;
233df8bae1dSRodney W. Grimes 	int flags = 0;
234df8bae1dSRodney W. Grimes 
2358da80660SBoris Popov 	NULLFSDEBUG("nullfs_unmount: mp = %p\n", (void *)mp);
236df8bae1dSRodney W. Grimes 
237996c772fSJohn Dyson 	if (mntflags & MNT_FORCE)
238df8bae1dSRodney W. Grimes 		flags |= FORCECLOSE;
239df8bae1dSRodney W. Grimes 
2404451405fSBoris Popov 	error = VFS_ROOT(mp, &vp);
2414451405fSBoris Popov 	if (error)
2424451405fSBoris Popov 		return (error);
2434451405fSBoris Popov 	if (vp->v_usecount > 2) {
2444451405fSBoris Popov 		NULLFSDEBUG("nullfs_unmount: rootvp is busy(%d)\n",
2454451405fSBoris Popov 		    vp->v_usecount);
2464451405fSBoris Popov 		vput(vp);
247df8bae1dSRodney W. Grimes 		return (EBUSY);
2484451405fSBoris Popov 	}
2494451405fSBoris Popov 	error = vflush(mp, vp, flags);
2503a773ad0SPoul-Henning Kamp 	if (error)
251df8bae1dSRodney W. Grimes 		return (error);
252df8bae1dSRodney W. Grimes 
2538da80660SBoris Popov #ifdef NULLFS_DEBUG
2544451405fSBoris Popov 	vprint("alias root of lower", vp);
255df8bae1dSRodney W. Grimes #endif
2564451405fSBoris Popov 	vput(vp);
257df8bae1dSRodney W. Grimes 	/*
258df8bae1dSRodney W. Grimes 	 * Release reference on underlying root vnode
259df8bae1dSRodney W. Grimes 	 */
2604451405fSBoris Popov 	vrele(vp);
261df8bae1dSRodney W. Grimes 	/*
262df8bae1dSRodney W. Grimes 	 * And blow it away for future re-use
263df8bae1dSRodney W. Grimes 	 */
2644451405fSBoris Popov 	vgone(vp);
265df8bae1dSRodney W. Grimes 	/*
266df8bae1dSRodney W. Grimes 	 * Finally, throw away the null_mount structure
267df8bae1dSRodney W. Grimes 	 */
2688da80660SBoris Popov 	mntdata = mp->mnt_data;
269df8bae1dSRodney W. Grimes 	mp->mnt_data = 0;
2704451405fSBoris Popov 	free(mntdata, M_NULLFSMNT);
271df8bae1dSRodney W. Grimes 	return 0;
272df8bae1dSRodney W. Grimes }
273df8bae1dSRodney W. Grimes 
274d4b7a369SPoul-Henning Kamp static int
275df8bae1dSRodney W. Grimes nullfs_root(mp, vpp)
276df8bae1dSRodney W. Grimes 	struct mount *mp;
277df8bae1dSRodney W. Grimes 	struct vnode **vpp;
278df8bae1dSRodney W. Grimes {
279996c772fSJohn Dyson 	struct proc *p = curproc;	/* XXX */
280df8bae1dSRodney W. Grimes 	struct vnode *vp;
281df8bae1dSRodney W. Grimes 
2828da80660SBoris Popov 	NULLFSDEBUG("nullfs_root(mp = %p, vp = %p->%p)\n", (void *)mp,
28389785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
28489785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
285df8bae1dSRodney W. Grimes 
286df8bae1dSRodney W. Grimes 	/*
287df8bae1dSRodney W. Grimes 	 * Return locked reference to root.
288df8bae1dSRodney W. Grimes 	 */
289df8bae1dSRodney W. Grimes 	vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
290df8bae1dSRodney W. Grimes 	VREF(vp);
2914451405fSBoris Popov 
2928da80660SBoris Popov #ifdef NULLFS_DEBUG
2936bdfe06aSEivind Eklund 	if (VOP_ISLOCKED(vp, NULL)) {
2944451405fSBoris Popov 		Debugger("root vnode is locked.\n");
295747e9157SKATO Takenori 		vrele(vp);
296747e9157SKATO Takenori 		return (EDEADLK);
2978da80660SBoris Popov 	}
2988da80660SBoris Popov #endif
299996c772fSJohn Dyson 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
300df8bae1dSRodney W. Grimes 	*vpp = vp;
301df8bae1dSRodney W. Grimes 	return 0;
302df8bae1dSRodney W. Grimes }
303df8bae1dSRodney W. Grimes 
304d4b7a369SPoul-Henning Kamp static int
305df8bae1dSRodney W. Grimes nullfs_quotactl(mp, cmd, uid, arg, p)
306df8bae1dSRodney W. Grimes 	struct mount *mp;
307df8bae1dSRodney W. Grimes 	int cmd;
308df8bae1dSRodney W. Grimes 	uid_t uid;
309df8bae1dSRodney W. Grimes 	caddr_t arg;
310df8bae1dSRodney W. Grimes 	struct proc *p;
311df8bae1dSRodney W. Grimes {
312df8bae1dSRodney W. Grimes 	return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg, p);
313df8bae1dSRodney W. Grimes }
314df8bae1dSRodney W. Grimes 
315d4b7a369SPoul-Henning Kamp static int
316df8bae1dSRodney W. Grimes nullfs_statfs(mp, sbp, p)
317df8bae1dSRodney W. Grimes 	struct mount *mp;
318df8bae1dSRodney W. Grimes 	struct statfs *sbp;
319df8bae1dSRodney W. Grimes 	struct proc *p;
320df8bae1dSRodney W. Grimes {
321df8bae1dSRodney W. Grimes 	int error;
322df8bae1dSRodney W. Grimes 	struct statfs mstat;
323df8bae1dSRodney W. Grimes 
3248da80660SBoris Popov 	NULLFSDEBUG("nullfs_statfs(mp = %p, vp = %p->%p)\n", (void *)mp,
32589785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
32689785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
327df8bae1dSRodney W. Grimes 
328df8bae1dSRodney W. Grimes 	bzero(&mstat, sizeof(mstat));
329df8bae1dSRodney W. Grimes 
330df8bae1dSRodney W. Grimes 	error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat, p);
331df8bae1dSRodney W. Grimes 	if (error)
332df8bae1dSRodney W. Grimes 		return (error);
333df8bae1dSRodney W. Grimes 
334df8bae1dSRodney W. Grimes 	/* now copy across the "interesting" information and fake the rest */
335df8bae1dSRodney W. Grimes 	sbp->f_type = mstat.f_type;
336df8bae1dSRodney W. Grimes 	sbp->f_flags = mstat.f_flags;
337df8bae1dSRodney W. Grimes 	sbp->f_bsize = mstat.f_bsize;
338df8bae1dSRodney W. Grimes 	sbp->f_iosize = mstat.f_iosize;
339df8bae1dSRodney W. Grimes 	sbp->f_blocks = mstat.f_blocks;
340df8bae1dSRodney W. Grimes 	sbp->f_bfree = mstat.f_bfree;
341df8bae1dSRodney W. Grimes 	sbp->f_bavail = mstat.f_bavail;
342df8bae1dSRodney W. Grimes 	sbp->f_files = mstat.f_files;
343df8bae1dSRodney W. Grimes 	sbp->f_ffree = mstat.f_ffree;
344df8bae1dSRodney W. Grimes 	if (sbp != &mp->mnt_stat) {
345df8bae1dSRodney W. Grimes 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
346df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
347df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
348df8bae1dSRodney W. Grimes 	}
349df8bae1dSRodney W. Grimes 	return (0);
350df8bae1dSRodney W. Grimes }
351df8bae1dSRodney W. Grimes 
352d4b7a369SPoul-Henning Kamp static int
353df8bae1dSRodney W. Grimes nullfs_sync(mp, waitfor, cred, p)
354df8bae1dSRodney W. Grimes 	struct mount *mp;
355df8bae1dSRodney W. Grimes 	int waitfor;
356df8bae1dSRodney W. Grimes 	struct ucred *cred;
357df8bae1dSRodney W. Grimes 	struct proc *p;
358df8bae1dSRodney W. Grimes {
359df8bae1dSRodney W. Grimes 	/*
360df8bae1dSRodney W. Grimes 	 * XXX - Assumes no data cached at null layer.
361df8bae1dSRodney W. Grimes 	 */
362df8bae1dSRodney W. Grimes 	return (0);
363df8bae1dSRodney W. Grimes }
364df8bae1dSRodney W. Grimes 
365d4b7a369SPoul-Henning Kamp static int
366df8bae1dSRodney W. Grimes nullfs_vget(mp, ino, vpp)
367df8bae1dSRodney W. Grimes 	struct mount *mp;
368df8bae1dSRodney W. Grimes 	ino_t ino;
369df8bae1dSRodney W. Grimes 	struct vnode **vpp;
370df8bae1dSRodney W. Grimes {
3714451405fSBoris Popov 	int error;
3724451405fSBoris Popov 	error = VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, vpp);
3734451405fSBoris Popov 	if (error)
3744451405fSBoris Popov 		return (error);
375df8bae1dSRodney W. Grimes 
3764451405fSBoris Popov 	return (null_node_create(mp, *vpp, vpp));
377df8bae1dSRodney W. Grimes }
378df8bae1dSRodney W. Grimes 
379d4b7a369SPoul-Henning Kamp static int
380c24fda81SAlfred Perlstein nullfs_fhtovp(mp, fidp, vpp)
381df8bae1dSRodney W. Grimes 	struct mount *mp;
382df8bae1dSRodney W. Grimes 	struct fid *fidp;
383df8bae1dSRodney W. Grimes 	struct vnode **vpp;
384c24fda81SAlfred Perlstein {
3854451405fSBoris Popov 	int error;
3864451405fSBoris Popov 	error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, vpp);
3874451405fSBoris Popov 	if (error)
3884451405fSBoris Popov 		return (error);
389c24fda81SAlfred Perlstein 
3904451405fSBoris Popov 	return (null_node_create(mp, *vpp, vpp));
391c24fda81SAlfred Perlstein }
392c24fda81SAlfred Perlstein 
393c24fda81SAlfred Perlstein static int
394c24fda81SAlfred Perlstein nullfs_checkexp(mp, nam, extflagsp, credanonp)
395c24fda81SAlfred Perlstein 	struct mount *mp;
396c24fda81SAlfred Perlstein 	struct sockaddr *nam;
397c24fda81SAlfred Perlstein 	int *extflagsp;
398df8bae1dSRodney W. Grimes 	struct ucred **credanonp;
399df8bae1dSRodney W. Grimes {
400df8bae1dSRodney W. Grimes 
401c24fda81SAlfred Perlstein 	return VFS_CHECKEXP(MOUNTTONULLMOUNT(mp)->nullm_vfs, nam,
402c24fda81SAlfred Perlstein 		extflagsp, credanonp);
403df8bae1dSRodney W. Grimes }
404df8bae1dSRodney W. Grimes 
405d4b7a369SPoul-Henning Kamp static int
406df8bae1dSRodney W. Grimes nullfs_vptofh(vp, fhp)
407df8bae1dSRodney W. Grimes 	struct vnode *vp;
408df8bae1dSRodney W. Grimes 	struct fid *fhp;
409df8bae1dSRodney W. Grimes {
410df8bae1dSRodney W. Grimes 	return VFS_VPTOFH(NULLVPTOLOWERVP(vp), fhp);
411df8bae1dSRodney W. Grimes }
412df8bae1dSRodney W. Grimes 
41391f37dcbSRobert Watson static int
41491f37dcbSRobert Watson nullfs_extattrctl(mp, cmd, attrname, arg, p)
41591f37dcbSRobert Watson 	struct mount *mp;
41691f37dcbSRobert Watson 	int cmd;
4178f073875SRobert Watson 	const char *attrname;
41891f37dcbSRobert Watson 	caddr_t arg;
41991f37dcbSRobert Watson 	struct proc *p;
42091f37dcbSRobert Watson {
42191f37dcbSRobert Watson 	return VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, attrname,
42291f37dcbSRobert Watson 	    arg, p);
42391f37dcbSRobert Watson }
42491f37dcbSRobert Watson 
42591f37dcbSRobert Watson 
426d4b7a369SPoul-Henning Kamp static struct vfsops null_vfsops = {
427df8bae1dSRodney W. Grimes 	nullfs_mount,
428df8bae1dSRodney W. Grimes 	nullfs_start,
429df8bae1dSRodney W. Grimes 	nullfs_unmount,
430df8bae1dSRodney W. Grimes 	nullfs_root,
431df8bae1dSRodney W. Grimes 	nullfs_quotactl,
432df8bae1dSRodney W. Grimes 	nullfs_statfs,
433df8bae1dSRodney W. Grimes 	nullfs_sync,
434df8bae1dSRodney W. Grimes 	nullfs_vget,
435df8bae1dSRodney W. Grimes 	nullfs_fhtovp,
436c24fda81SAlfred Perlstein 	nullfs_checkexp,
437df8bae1dSRodney W. Grimes 	nullfs_vptofh,
438df8bae1dSRodney W. Grimes 	nullfs_init,
4398da80660SBoris Popov 	nullfs_uninit,
44091f37dcbSRobert Watson 	nullfs_extattrctl,
441df8bae1dSRodney W. Grimes };
442c901836cSGarrett Wollman 
4431b2fbe6fSSheldon Hearn VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK);
444