xref: /freebsd/sys/fs/nullfs/null_vfsops.c (revision 1cfdefbb9f162da9aa9c045f07394f49aaef1db8)
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>
50fb919e4dSMark Murray #include <sys/lock.h>
51a1c995b6SPoul-Henning Kamp #include <sys/malloc.h>
52df8bae1dSRodney W. Grimes #include <sys/mount.h>
53df8bae1dSRodney W. Grimes #include <sys/namei.h>
54fb919e4dSMark Murray #include <sys/proc.h>
55fb919e4dSMark Murray #include <sys/vnode.h>
56fb919e4dSMark Murray 
5799d300a1SRuslan Ermilov #include <fs/nullfs/null.h>
58df8bae1dSRodney W. Grimes 
59a1c995b6SPoul-Henning Kamp static MALLOC_DEFINE(M_NULLFSMNT, "NULLFS mount", "NULLFS mount structure");
60a1c995b6SPoul-Henning Kamp 
617da1e3f0SBoris Popov static int	nullfs_fhtovp(struct mount *mp, struct fid *fidp,
627da1e3f0SBoris Popov 				   struct vnode **vpp);
637da1e3f0SBoris Popov static int	nullfs_checkexp(struct mount *mp, struct sockaddr *nam,
647da1e3f0SBoris Popov 				    int *extflagsp, struct ucred **credanonp);
659fcc512cSMaxime Henrion static int	nullfs_mount(struct mount *mp, struct nameidata *ndp,
669fcc512cSMaxime Henrion 				   struct thread *td);
677da1e3f0SBoris Popov static int	nullfs_quotactl(struct mount *mp, int cmd, uid_t uid,
68b40ce416SJulian Elischer 				     caddr_t arg, struct thread *td);
697da1e3f0SBoris Popov static int	nullfs_root(struct mount *mp, struct vnode **vpp);
70b40ce416SJulian Elischer static int	nullfs_start(struct mount *mp, int flags, struct thread *td);
717da1e3f0SBoris Popov static int	nullfs_statfs(struct mount *mp, struct statfs *sbp,
72b40ce416SJulian Elischer 				   struct thread *td);
737da1e3f0SBoris Popov static int	nullfs_sync(struct mount *mp, int waitfor,
74b40ce416SJulian Elischer 				 struct ucred *cred, struct thread *td);
75b40ce416SJulian Elischer static int	nullfs_unmount(struct mount *mp, int mntflags, struct thread *td);
76a0595d02SKirk McKusick static int	nullfs_vget(struct mount *mp, ino_t ino, int flags,
77a0595d02SKirk McKusick 				 struct vnode **vpp);
787da1e3f0SBoris Popov static int	nullfs_vptofh(struct vnode *vp, struct fid *fhp);
794451405fSBoris Popov static int	nullfs_extattrctl(struct mount *mp, int cmd,
8070f36851SRobert Watson 				       struct vnode *filename_vp,
8170f36851SRobert Watson 				       int namespace, const char *attrname,
82b40ce416SJulian Elischer 				       struct thread *td);
839b5e8b3aSBruce Evans 
84df8bae1dSRodney W. Grimes /*
85df8bae1dSRodney W. Grimes  * Mount null layer
86df8bae1dSRodney W. Grimes  */
87d4b7a369SPoul-Henning Kamp static int
889fcc512cSMaxime Henrion nullfs_mount(mp, ndp, td)
89df8bae1dSRodney W. Grimes 	struct mount *mp;
90df8bae1dSRodney W. Grimes 	struct nameidata *ndp;
91b40ce416SJulian Elischer 	struct thread *td;
92df8bae1dSRodney W. Grimes {
93df8bae1dSRodney W. Grimes 	int error = 0;
94df8bae1dSRodney W. Grimes 	struct vnode *lowerrootvp, *vp;
95df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp;
96df8bae1dSRodney W. Grimes 	struct null_mount *xmp;
979fcc512cSMaxime Henrion 	char *target;
98aa56d911SMatt Jacob 	size_t size;
999fcc512cSMaxime Henrion 	int isvnunlocked = 0, len;
100df8bae1dSRodney W. Grimes 
1018da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount(mp = %p)\n", (void *)mp);
102df8bae1dSRodney W. Grimes 
103df8bae1dSRodney W. Grimes 	/*
104df8bae1dSRodney W. Grimes 	 * Update is a no-op
105df8bae1dSRodney W. Grimes 	 */
106df8bae1dSRodney W. Grimes 	if (mp->mnt_flag & MNT_UPDATE) {
107df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
108b40ce416SJulian Elischer 		/* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, td);*/
109df8bae1dSRodney W. Grimes 	}
110df8bae1dSRodney W. Grimes 
111df8bae1dSRodney W. Grimes 	/*
112df8bae1dSRodney W. Grimes 	 * Get argument
113df8bae1dSRodney W. Grimes 	 */
1149fcc512cSMaxime Henrion 	error = vfs_getopt(mp->mnt_optnew, "target", (void **)&target, &len);
1159fcc512cSMaxime Henrion 	if (error || target[len - 1] != '\0')
1169fcc512cSMaxime Henrion 		return (EINVAL);
117df8bae1dSRodney W. Grimes 
118df8bae1dSRodney W. Grimes 	/*
119f85e8fc5SKATO Takenori 	 * Unlock lower node to avoid deadlock.
120f85e8fc5SKATO Takenori 	 * (XXX) VOP_ISLOCKED is needed?
121f85e8fc5SKATO Takenori 	 */
122f85e8fc5SKATO Takenori 	if ((mp->mnt_vnodecovered->v_op == null_vnodeop_p) &&
1236bdfe06aSEivind Eklund 		VOP_ISLOCKED(mp->mnt_vnodecovered, NULL)) {
124b40ce416SJulian Elischer 		VOP_UNLOCK(mp->mnt_vnodecovered, 0, td);
125f85e8fc5SKATO Takenori 		isvnunlocked = 1;
126f85e8fc5SKATO Takenori 	}
127f85e8fc5SKATO Takenori 	/*
128df8bae1dSRodney W. Grimes 	 * Find lower node
129df8bae1dSRodney W. Grimes 	 */
130df8bae1dSRodney W. Grimes 	NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
1319fcc512cSMaxime Henrion 		UIO_SYSSPACE, target, td);
1323a773ad0SPoul-Henning Kamp 	error = namei(ndp);
133f85e8fc5SKATO Takenori 	/*
134f85e8fc5SKATO Takenori 	 * Re-lock vnode.
135f85e8fc5SKATO Takenori 	 */
1366bdfe06aSEivind Eklund 	if (isvnunlocked && !VOP_ISLOCKED(mp->mnt_vnodecovered, NULL))
137b40ce416SJulian Elischer 		vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY, td);
138f85e8fc5SKATO Takenori 
1393a773ad0SPoul-Henning Kamp 	if (error)
140df8bae1dSRodney W. Grimes 		return (error);
141762e6b85SEivind Eklund 	NDFREE(ndp, NDF_ONLY_PNBUF);
142df8bae1dSRodney W. Grimes 
143df8bae1dSRodney W. Grimes 	/*
144df8bae1dSRodney W. Grimes 	 * Sanity check on lower vnode
145df8bae1dSRodney W. Grimes 	 */
146df8bae1dSRodney W. Grimes 	lowerrootvp = ndp->ni_vp;
147df8bae1dSRodney W. Grimes 
148df8bae1dSRodney W. Grimes 	vrele(ndp->ni_dvp);
149c5e17d9eSKATO Takenori 	ndp->ni_dvp = NULLVP;
150df8bae1dSRodney W. Grimes 
151f85e8fc5SKATO Takenori 	/*
152f85e8fc5SKATO Takenori 	 * Check multi null mount to avoid `lock against myself' panic.
153f85e8fc5SKATO Takenori 	 */
154f85e8fc5SKATO Takenori 	if (lowerrootvp == VTONULL(mp->mnt_vnodecovered)->null_lowervp) {
1558da80660SBoris Popov 		NULLFSDEBUG("nullfs_mount: multi null mount?\n");
1566716c905SBoris Popov 		vput(lowerrootvp);
157747e9157SKATO Takenori 		return (EDEADLK);
158f85e8fc5SKATO Takenori 	}
159f85e8fc5SKATO Takenori 
160df8bae1dSRodney W. Grimes 	xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
161a1c995b6SPoul-Henning Kamp 				M_NULLFSMNT, M_WAITOK);	/* XXX */
162df8bae1dSRodney W. Grimes 
163df8bae1dSRodney W. Grimes 	/*
164df8bae1dSRodney W. Grimes 	 * Save reference to underlying FS
165df8bae1dSRodney W. Grimes 	 */
166df8bae1dSRodney W. Grimes 	xmp->nullm_vfs = lowerrootvp->v_mount;
167df8bae1dSRodney W. Grimes 
168df8bae1dSRodney W. Grimes 	/*
169df8bae1dSRodney W. Grimes 	 * Save reference.  Each mount also holds
170df8bae1dSRodney W. Grimes 	 * a reference on the root vnode.
171df8bae1dSRodney W. Grimes 	 */
1721cfdefbbSSemen Ustimenko 	error = null_nodeget(mp, lowerrootvp, &vp);
173df8bae1dSRodney W. Grimes 	/*
174df8bae1dSRodney W. Grimes 	 * Unlock the node (either the lower or the alias)
175df8bae1dSRodney W. Grimes 	 */
176b40ce416SJulian Elischer 	VOP_UNLOCK(vp, 0, td);
177df8bae1dSRodney W. Grimes 	/*
178df8bae1dSRodney W. Grimes 	 * Make sure the node alias worked
179df8bae1dSRodney W. Grimes 	 */
180df8bae1dSRodney W. Grimes 	if (error) {
181df8bae1dSRodney W. Grimes 		vrele(lowerrootvp);
182a1c995b6SPoul-Henning Kamp 		free(xmp, M_NULLFSMNT);	/* XXX */
183df8bae1dSRodney W. Grimes 		return (error);
184df8bae1dSRodney W. Grimes 	}
185df8bae1dSRodney W. Grimes 
186df8bae1dSRodney W. Grimes 	/*
187df8bae1dSRodney W. Grimes 	 * Keep a held reference to the root vnode.
188df8bae1dSRodney W. Grimes 	 * It is vrele'd in nullfs_unmount.
189df8bae1dSRodney W. Grimes 	 */
190df8bae1dSRodney W. Grimes 	nullm_rootvp = vp;
191df8bae1dSRodney W. Grimes 	nullm_rootvp->v_flag |= VROOT;
192df8bae1dSRodney W. Grimes 	xmp->nullm_rootvp = nullm_rootvp;
193df8bae1dSRodney W. Grimes 	if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
194df8bae1dSRodney W. Grimes 		mp->mnt_flag |= MNT_LOCAL;
195df8bae1dSRodney W. Grimes 	mp->mnt_data = (qaddr_t) xmp;
196996c772fSJohn Dyson 	vfs_getnewfsid(mp);
197df8bae1dSRodney W. Grimes 
1989fcc512cSMaxime Henrion 	(void) copystr(target, mp->mnt_stat.f_mntfromname,
199aa56d911SMatt Jacob 	    MNAMELEN - 1, &size);
200df8bae1dSRodney W. Grimes 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
201b40ce416SJulian Elischer 	(void)nullfs_statfs(mp, &mp->mnt_stat, td);
2028da80660SBoris Popov 	NULLFSDEBUG("nullfs_mount: lower %s, alias at %s\n",
203df8bae1dSRodney W. Grimes 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
204df8bae1dSRodney W. Grimes 	return (0);
205df8bae1dSRodney W. Grimes }
206df8bae1dSRodney W. Grimes 
207df8bae1dSRodney W. Grimes /*
208df8bae1dSRodney W. Grimes  * VFS start.  Nothing needed here - the start routine
209df8bae1dSRodney W. Grimes  * on the underlying filesystem will have been called
210df8bae1dSRodney W. Grimes  * when that filesystem was mounted.
211df8bae1dSRodney W. Grimes  */
212d4b7a369SPoul-Henning Kamp static int
213b40ce416SJulian Elischer nullfs_start(mp, flags, td)
214df8bae1dSRodney W. Grimes 	struct mount *mp;
215df8bae1dSRodney W. Grimes 	int flags;
216b40ce416SJulian Elischer 	struct thread *td;
217df8bae1dSRodney W. Grimes {
218df8bae1dSRodney W. Grimes 	return (0);
219b40ce416SJulian Elischer 	/* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, td); */
220df8bae1dSRodney W. Grimes }
221df8bae1dSRodney W. Grimes 
222df8bae1dSRodney W. Grimes /*
223df8bae1dSRodney W. Grimes  * Free reference to null layer
224df8bae1dSRodney W. Grimes  */
225d4b7a369SPoul-Henning Kamp static int
226b40ce416SJulian Elischer nullfs_unmount(mp, mntflags, td)
227df8bae1dSRodney W. Grimes 	struct mount *mp;
228df8bae1dSRodney W. Grimes 	int mntflags;
229b40ce416SJulian Elischer 	struct thread *td;
230df8bae1dSRodney W. Grimes {
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 
2400864ef1eSIan Dowse 	/* There is 1 extra root vnode reference (nullm_rootvp). */
2410864ef1eSIan Dowse 	error = vflush(mp, 1, flags);
2423a773ad0SPoul-Henning Kamp 	if (error)
243df8bae1dSRodney W. Grimes 		return (error);
244df8bae1dSRodney W. Grimes 
245df8bae1dSRodney W. Grimes 	/*
246df8bae1dSRodney W. Grimes 	 * Finally, throw away the null_mount structure
247df8bae1dSRodney W. Grimes 	 */
2488da80660SBoris Popov 	mntdata = mp->mnt_data;
249df8bae1dSRodney W. Grimes 	mp->mnt_data = 0;
2504451405fSBoris Popov 	free(mntdata, M_NULLFSMNT);
251df8bae1dSRodney W. Grimes 	return 0;
252df8bae1dSRodney W. Grimes }
253df8bae1dSRodney W. Grimes 
254d4b7a369SPoul-Henning Kamp static int
255df8bae1dSRodney W. Grimes nullfs_root(mp, vpp)
256df8bae1dSRodney W. Grimes 	struct mount *mp;
257df8bae1dSRodney W. Grimes 	struct vnode **vpp;
258df8bae1dSRodney W. Grimes {
259b40ce416SJulian Elischer 	struct thread *td = curthread;	/* XXX */
260df8bae1dSRodney W. Grimes 	struct vnode *vp;
261df8bae1dSRodney W. Grimes 
2628da80660SBoris Popov 	NULLFSDEBUG("nullfs_root(mp = %p, vp = %p->%p)\n", (void *)mp,
26389785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
26489785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
265df8bae1dSRodney W. Grimes 
266df8bae1dSRodney W. Grimes 	/*
267df8bae1dSRodney W. Grimes 	 * Return locked reference to root.
268df8bae1dSRodney W. Grimes 	 */
269df8bae1dSRodney W. Grimes 	vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
270df8bae1dSRodney W. Grimes 	VREF(vp);
2714451405fSBoris Popov 
2728da80660SBoris Popov #ifdef NULLFS_DEBUG
2736bdfe06aSEivind Eklund 	if (VOP_ISLOCKED(vp, NULL)) {
2744451405fSBoris Popov 		Debugger("root vnode is locked.\n");
275747e9157SKATO Takenori 		vrele(vp);
276747e9157SKATO Takenori 		return (EDEADLK);
2778da80660SBoris Popov 	}
2788da80660SBoris Popov #endif
279b40ce416SJulian Elischer 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
280df8bae1dSRodney W. Grimes 	*vpp = vp;
281df8bae1dSRodney W. Grimes 	return 0;
282df8bae1dSRodney W. Grimes }
283df8bae1dSRodney W. Grimes 
284d4b7a369SPoul-Henning Kamp static int
285b40ce416SJulian Elischer nullfs_quotactl(mp, cmd, uid, arg, td)
286df8bae1dSRodney W. Grimes 	struct mount *mp;
287df8bae1dSRodney W. Grimes 	int cmd;
288df8bae1dSRodney W. Grimes 	uid_t uid;
289df8bae1dSRodney W. Grimes 	caddr_t arg;
290b40ce416SJulian Elischer 	struct thread *td;
291df8bae1dSRodney W. Grimes {
292b40ce416SJulian Elischer 	return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg, td);
293df8bae1dSRodney W. Grimes }
294df8bae1dSRodney W. Grimes 
295d4b7a369SPoul-Henning Kamp static int
296b40ce416SJulian Elischer nullfs_statfs(mp, sbp, td)
297df8bae1dSRodney W. Grimes 	struct mount *mp;
298df8bae1dSRodney W. Grimes 	struct statfs *sbp;
299b40ce416SJulian Elischer 	struct thread *td;
300df8bae1dSRodney W. Grimes {
301df8bae1dSRodney W. Grimes 	int error;
302df8bae1dSRodney W. Grimes 	struct statfs mstat;
303df8bae1dSRodney W. Grimes 
3048da80660SBoris Popov 	NULLFSDEBUG("nullfs_statfs(mp = %p, vp = %p->%p)\n", (void *)mp,
30589785a16SBruce Evans 	    (void *)MOUNTTONULLMOUNT(mp)->nullm_rootvp,
30689785a16SBruce Evans 	    (void *)NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp));
307df8bae1dSRodney W. Grimes 
308df8bae1dSRodney W. Grimes 	bzero(&mstat, sizeof(mstat));
309df8bae1dSRodney W. Grimes 
310b40ce416SJulian Elischer 	error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat, td);
311df8bae1dSRodney W. Grimes 	if (error)
312df8bae1dSRodney W. Grimes 		return (error);
313df8bae1dSRodney W. Grimes 
314df8bae1dSRodney W. Grimes 	/* now copy across the "interesting" information and fake the rest */
315df8bae1dSRodney W. Grimes 	sbp->f_type = mstat.f_type;
316df8bae1dSRodney W. Grimes 	sbp->f_flags = mstat.f_flags;
317df8bae1dSRodney W. Grimes 	sbp->f_bsize = mstat.f_bsize;
318df8bae1dSRodney W. Grimes 	sbp->f_iosize = mstat.f_iosize;
319df8bae1dSRodney W. Grimes 	sbp->f_blocks = mstat.f_blocks;
320df8bae1dSRodney W. Grimes 	sbp->f_bfree = mstat.f_bfree;
321df8bae1dSRodney W. Grimes 	sbp->f_bavail = mstat.f_bavail;
322df8bae1dSRodney W. Grimes 	sbp->f_files = mstat.f_files;
323df8bae1dSRodney W. Grimes 	sbp->f_ffree = mstat.f_ffree;
324df8bae1dSRodney W. Grimes 	if (sbp != &mp->mnt_stat) {
325df8bae1dSRodney W. Grimes 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
326df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
327df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
328df8bae1dSRodney W. Grimes 	}
329df8bae1dSRodney W. Grimes 	return (0);
330df8bae1dSRodney W. Grimes }
331df8bae1dSRodney W. Grimes 
332d4b7a369SPoul-Henning Kamp static int
333b40ce416SJulian Elischer nullfs_sync(mp, waitfor, cred, td)
334df8bae1dSRodney W. Grimes 	struct mount *mp;
335df8bae1dSRodney W. Grimes 	int waitfor;
336df8bae1dSRodney W. Grimes 	struct ucred *cred;
337b40ce416SJulian Elischer 	struct thread *td;
338df8bae1dSRodney W. Grimes {
339df8bae1dSRodney W. Grimes 	/*
340df8bae1dSRodney W. Grimes 	 * XXX - Assumes no data cached at null layer.
341df8bae1dSRodney W. Grimes 	 */
342df8bae1dSRodney W. Grimes 	return (0);
343df8bae1dSRodney W. Grimes }
344df8bae1dSRodney W. Grimes 
345d4b7a369SPoul-Henning Kamp static int
346a0595d02SKirk McKusick nullfs_vget(mp, ino, flags, vpp)
347df8bae1dSRodney W. Grimes 	struct mount *mp;
348df8bae1dSRodney W. Grimes 	ino_t ino;
349a0595d02SKirk McKusick 	int flags;
350df8bae1dSRodney W. Grimes 	struct vnode **vpp;
351df8bae1dSRodney W. Grimes {
3524451405fSBoris Popov 	int error;
353a0595d02SKirk McKusick 	error = VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, flags, vpp);
3544451405fSBoris Popov 	if (error)
3554451405fSBoris Popov 		return (error);
356df8bae1dSRodney W. Grimes 
3571cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
358df8bae1dSRodney W. Grimes }
359df8bae1dSRodney W. Grimes 
360d4b7a369SPoul-Henning Kamp static int
361c24fda81SAlfred Perlstein nullfs_fhtovp(mp, fidp, vpp)
362df8bae1dSRodney W. Grimes 	struct mount *mp;
363df8bae1dSRodney W. Grimes 	struct fid *fidp;
364df8bae1dSRodney W. Grimes 	struct vnode **vpp;
365c24fda81SAlfred Perlstein {
3664451405fSBoris Popov 	int error;
3674451405fSBoris Popov 	error = VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, vpp);
3684451405fSBoris Popov 	if (error)
3694451405fSBoris Popov 		return (error);
370c24fda81SAlfred Perlstein 
3711cfdefbbSSemen Ustimenko 	return (null_nodeget(mp, *vpp, vpp));
372c24fda81SAlfred Perlstein }
373c24fda81SAlfred Perlstein 
374c24fda81SAlfred Perlstein static int
375c24fda81SAlfred Perlstein nullfs_checkexp(mp, nam, extflagsp, credanonp)
376c24fda81SAlfred Perlstein 	struct mount *mp;
377c24fda81SAlfred Perlstein 	struct sockaddr *nam;
378c24fda81SAlfred Perlstein 	int *extflagsp;
379df8bae1dSRodney W. Grimes 	struct ucred **credanonp;
380df8bae1dSRodney W. Grimes {
381df8bae1dSRodney W. Grimes 
382c24fda81SAlfred Perlstein 	return VFS_CHECKEXP(MOUNTTONULLMOUNT(mp)->nullm_vfs, nam,
383c24fda81SAlfred Perlstein 		extflagsp, credanonp);
384df8bae1dSRodney W. Grimes }
385df8bae1dSRodney W. Grimes 
386d4b7a369SPoul-Henning Kamp static int
387df8bae1dSRodney W. Grimes nullfs_vptofh(vp, fhp)
388df8bae1dSRodney W. Grimes 	struct vnode *vp;
389df8bae1dSRodney W. Grimes 	struct fid *fhp;
390df8bae1dSRodney W. Grimes {
391df8bae1dSRodney W. Grimes 	return VFS_VPTOFH(NULLVPTOLOWERVP(vp), fhp);
392df8bae1dSRodney W. Grimes }
393df8bae1dSRodney W. Grimes 
39491f37dcbSRobert Watson static int
395b40ce416SJulian Elischer nullfs_extattrctl(mp, cmd, filename_vp, namespace, attrname, td)
39691f37dcbSRobert Watson 	struct mount *mp;
39791f37dcbSRobert Watson 	int cmd;
39870f36851SRobert Watson 	struct vnode *filename_vp;
39970f36851SRobert Watson 	int namespace;
4008f073875SRobert Watson 	const char *attrname;
401b40ce416SJulian Elischer 	struct thread *td;
40291f37dcbSRobert Watson {
40370f36851SRobert Watson 	return VFS_EXTATTRCTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, filename_vp,
404b40ce416SJulian Elischer 	    namespace, attrname, td);
40591f37dcbSRobert Watson }
40691f37dcbSRobert Watson 
40791f37dcbSRobert Watson 
408d4b7a369SPoul-Henning Kamp static struct vfsops null_vfsops = {
4099fcc512cSMaxime Henrion 	NULL,
410df8bae1dSRodney W. Grimes 	nullfs_start,
411df8bae1dSRodney W. Grimes 	nullfs_unmount,
412df8bae1dSRodney W. Grimes 	nullfs_root,
413df8bae1dSRodney W. Grimes 	nullfs_quotactl,
414df8bae1dSRodney W. Grimes 	nullfs_statfs,
415df8bae1dSRodney W. Grimes 	nullfs_sync,
416df8bae1dSRodney W. Grimes 	nullfs_vget,
417df8bae1dSRodney W. Grimes 	nullfs_fhtovp,
418c24fda81SAlfred Perlstein 	nullfs_checkexp,
419df8bae1dSRodney W. Grimes 	nullfs_vptofh,
420df8bae1dSRodney W. Grimes 	nullfs_init,
4218da80660SBoris Popov 	nullfs_uninit,
42291f37dcbSRobert Watson 	nullfs_extattrctl,
4239fcc512cSMaxime Henrion 	nullfs_mount,
424df8bae1dSRodney W. Grimes };
425c901836cSGarrett Wollman 
4261b2fbe6fSSheldon Hearn VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK);
427