xref: /freebsd/sys/fs/nullfs/null_vfsops.c (revision a1c995b626fc56226f7c279f087b50769ff8df18)
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
39a1c995b6SPoul-Henning Kamp  * $Id: null_vfsops.c,v 1.19 1997/08/16 19:15:16 wollman Exp $
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 
59d4b7a369SPoul-Henning Kamp static int	nullfs_fhtovp __P((struct mount *mp, struct fid *fidp,
6057bf258eSGarrett Wollman 				   struct sockaddr *nam, struct vnode **vpp,
619b5e8b3aSBruce Evans 				   int *exflagsp, struct ucred **credanonp));
62d4b7a369SPoul-Henning Kamp static int	nullfs_mount __P((struct mount *mp, char *path, caddr_t data,
639b5e8b3aSBruce Evans 				  struct nameidata *ndp, struct proc *p));
64d4b7a369SPoul-Henning Kamp static int	nullfs_quotactl __P((struct mount *mp, int cmd, uid_t uid,
659b5e8b3aSBruce Evans 				     caddr_t arg, struct proc *p));
66d4b7a369SPoul-Henning Kamp static int	nullfs_root __P((struct mount *mp, struct vnode **vpp));
67d4b7a369SPoul-Henning Kamp static int	nullfs_start __P((struct mount *mp, int flags, struct proc *p));
68d4b7a369SPoul-Henning Kamp static int	nullfs_statfs __P((struct mount *mp, struct statfs *sbp,
699b5e8b3aSBruce Evans 				   struct proc *p));
70d4b7a369SPoul-Henning Kamp static int	nullfs_sync __P((struct mount *mp, int waitfor,
719b5e8b3aSBruce Evans 				 struct ucred *cred, struct proc *p));
72d4b7a369SPoul-Henning Kamp static int	nullfs_unmount __P((struct mount *mp, int mntflags,
739b5e8b3aSBruce Evans 				    struct proc *p));
74d4b7a369SPoul-Henning Kamp static int	nullfs_vget __P((struct mount *mp, ino_t ino,
759b5e8b3aSBruce Evans 				 struct vnode **vpp));
76d4b7a369SPoul-Henning Kamp static int	nullfs_vptofh __P((struct vnode *vp, struct fid *fhp));
779b5e8b3aSBruce Evans 
78df8bae1dSRodney W. Grimes /*
79df8bae1dSRodney W. Grimes  * Mount null layer
80df8bae1dSRodney W. Grimes  */
81d4b7a369SPoul-Henning Kamp static int
82df8bae1dSRodney W. Grimes nullfs_mount(mp, path, data, ndp, p)
83df8bae1dSRodney W. Grimes 	struct mount *mp;
84df8bae1dSRodney W. Grimes 	char *path;
85df8bae1dSRodney W. Grimes 	caddr_t data;
86df8bae1dSRodney W. Grimes 	struct nameidata *ndp;
87df8bae1dSRodney W. Grimes 	struct proc *p;
88df8bae1dSRodney W. Grimes {
89df8bae1dSRodney W. Grimes 	int error = 0;
90df8bae1dSRodney W. Grimes 	struct null_args args;
91df8bae1dSRodney W. Grimes 	struct vnode *lowerrootvp, *vp;
92df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp;
93df8bae1dSRodney W. Grimes 	struct null_mount *xmp;
94df8bae1dSRodney W. Grimes 	u_int size;
95f85e8fc5SKATO Takenori 	int isvnunlocked = 0;
96df8bae1dSRodney W. Grimes 
97df8bae1dSRodney W. Grimes #ifdef NULLFS_DIAGNOSTIC
98df8bae1dSRodney W. Grimes 	printf("nullfs_mount(mp = %x)\n", mp);
99df8bae1dSRodney W. Grimes #endif
100df8bae1dSRodney W. Grimes 
101df8bae1dSRodney W. Grimes 	/*
102df8bae1dSRodney W. Grimes 	 * Update is a no-op
103df8bae1dSRodney W. Grimes 	 */
104df8bae1dSRodney W. Grimes 	if (mp->mnt_flag & MNT_UPDATE) {
105df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
106df8bae1dSRodney W. Grimes 		/* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, p);*/
107df8bae1dSRodney W. Grimes 	}
108df8bae1dSRodney W. Grimes 
109df8bae1dSRodney W. Grimes 	/*
110df8bae1dSRodney W. Grimes 	 * Get argument
111df8bae1dSRodney W. Grimes 	 */
1123a773ad0SPoul-Henning Kamp 	error = copyin(data, (caddr_t)&args, sizeof(struct null_args));
1133a773ad0SPoul-Henning Kamp 	if (error)
114df8bae1dSRodney W. Grimes 		return (error);
115df8bae1dSRodney W. Grimes 
116df8bae1dSRodney W. Grimes 	/*
117f85e8fc5SKATO Takenori 	 * Unlock lower node to avoid deadlock.
118f85e8fc5SKATO Takenori 	 * (XXX) VOP_ISLOCKED is needed?
119f85e8fc5SKATO Takenori 	 */
120f85e8fc5SKATO Takenori 	if ((mp->mnt_vnodecovered->v_op == null_vnodeop_p) &&
121f85e8fc5SKATO Takenori 		VOP_ISLOCKED(mp->mnt_vnodecovered)) {
122f85e8fc5SKATO Takenori 		VOP_UNLOCK(mp->mnt_vnodecovered, 0, p);
123f85e8fc5SKATO Takenori 		isvnunlocked = 1;
124f85e8fc5SKATO Takenori 	}
125f85e8fc5SKATO Takenori 	/*
126df8bae1dSRodney W. Grimes 	 * Find lower node
127df8bae1dSRodney W. Grimes 	 */
128df8bae1dSRodney W. Grimes 	NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
129df8bae1dSRodney W. Grimes 		UIO_USERSPACE, args.target, p);
1303a773ad0SPoul-Henning Kamp 	error = namei(ndp);
131f85e8fc5SKATO Takenori 	/*
132f85e8fc5SKATO Takenori 	 * Re-lock vnode.
133f85e8fc5SKATO Takenori 	 */
134f85e8fc5SKATO Takenori 	if (isvnunlocked && !VOP_ISLOCKED(mp->mnt_vnodecovered))
135f85e8fc5SKATO Takenori 		vn_lock(mp->mnt_vnodecovered, LK_EXCLUSIVE | LK_RETRY, p);
136f85e8fc5SKATO Takenori 
1373a773ad0SPoul-Henning Kamp 	if (error)
138df8bae1dSRodney W. Grimes 		return (error);
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) {
152747e9157SKATO Takenori #ifdef DIAGNOSTIC
153747e9157SKATO Takenori 		printf("nullfs_mount: multi null mount?\n");
154747e9157SKATO Takenori #endif
155747e9157SKATO Takenori 		return (EDEADLK);
156f85e8fc5SKATO Takenori 	}
157f85e8fc5SKATO Takenori 
158df8bae1dSRodney W. Grimes 	xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
159a1c995b6SPoul-Henning Kamp 				M_NULLFSMNT, M_WAITOK);	/* XXX */
160df8bae1dSRodney W. Grimes 
161df8bae1dSRodney W. Grimes 	/*
162df8bae1dSRodney W. Grimes 	 * Save reference to underlying FS
163df8bae1dSRodney W. Grimes 	 */
164df8bae1dSRodney W. Grimes 	xmp->nullm_vfs = lowerrootvp->v_mount;
165df8bae1dSRodney W. Grimes 
166df8bae1dSRodney W. Grimes 	/*
167df8bae1dSRodney W. Grimes 	 * Save reference.  Each mount also holds
168df8bae1dSRodney W. Grimes 	 * a reference on the root vnode.
169df8bae1dSRodney W. Grimes 	 */
170df8bae1dSRodney W. Grimes 	error = null_node_create(mp, lowerrootvp, &vp);
171df8bae1dSRodney W. Grimes 	/*
172df8bae1dSRodney W. Grimes 	 * Unlock the node (either the lower or the alias)
173df8bae1dSRodney W. Grimes 	 */
174996c772fSJohn Dyson 	VOP_UNLOCK(vp, 0, p);
175df8bae1dSRodney W. Grimes 	/*
176df8bae1dSRodney W. Grimes 	 * Make sure the node alias worked
177df8bae1dSRodney W. Grimes 	 */
178df8bae1dSRodney W. Grimes 	if (error) {
179df8bae1dSRodney W. Grimes 		vrele(lowerrootvp);
180a1c995b6SPoul-Henning Kamp 		free(xmp, M_NULLFSMNT);	/* XXX */
181df8bae1dSRodney W. Grimes 		return (error);
182df8bae1dSRodney W. Grimes 	}
183df8bae1dSRodney W. Grimes 
184df8bae1dSRodney W. Grimes 	/*
185df8bae1dSRodney W. Grimes 	 * Keep a held reference to the root vnode.
186df8bae1dSRodney W. Grimes 	 * It is vrele'd in nullfs_unmount.
187df8bae1dSRodney W. Grimes 	 */
188df8bae1dSRodney W. Grimes 	nullm_rootvp = vp;
189df8bae1dSRodney W. Grimes 	nullm_rootvp->v_flag |= VROOT;
190df8bae1dSRodney W. Grimes 	xmp->nullm_rootvp = nullm_rootvp;
191df8bae1dSRodney W. Grimes 	if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
192df8bae1dSRodney W. Grimes 		mp->mnt_flag |= MNT_LOCAL;
193df8bae1dSRodney W. Grimes 	mp->mnt_data = (qaddr_t) xmp;
194996c772fSJohn Dyson 	vfs_getnewfsid(mp);
195df8bae1dSRodney W. Grimes 
196df8bae1dSRodney W. Grimes 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
197df8bae1dSRodney W. Grimes 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
198df8bae1dSRodney W. Grimes 	(void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
199df8bae1dSRodney W. Grimes 	    &size);
200df8bae1dSRodney W. Grimes 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
201df8bae1dSRodney W. Grimes #ifdef NULLFS_DIAGNOSTIC
202df8bae1dSRodney W. Grimes 	printf("nullfs_mount: lower %s, alias at %s\n",
203df8bae1dSRodney W. Grimes 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
204df8bae1dSRodney W. Grimes #endif
205df8bae1dSRodney W. Grimes 	return (0);
206df8bae1dSRodney W. Grimes }
207df8bae1dSRodney W. Grimes 
208df8bae1dSRodney W. Grimes /*
209df8bae1dSRodney W. Grimes  * VFS start.  Nothing needed here - the start routine
210df8bae1dSRodney W. Grimes  * on the underlying filesystem will have been called
211df8bae1dSRodney W. Grimes  * when that filesystem was mounted.
212df8bae1dSRodney W. Grimes  */
213d4b7a369SPoul-Henning Kamp static int
214df8bae1dSRodney W. Grimes nullfs_start(mp, flags, p)
215df8bae1dSRodney W. Grimes 	struct mount *mp;
216df8bae1dSRodney W. Grimes 	int flags;
217df8bae1dSRodney W. Grimes 	struct proc *p;
218df8bae1dSRodney W. Grimes {
219df8bae1dSRodney W. Grimes 	return (0);
220df8bae1dSRodney W. Grimes 	/* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, p); */
221df8bae1dSRodney W. Grimes }
222df8bae1dSRodney W. Grimes 
223df8bae1dSRodney W. Grimes /*
224df8bae1dSRodney W. Grimes  * Free reference to null layer
225df8bae1dSRodney W. Grimes  */
226d4b7a369SPoul-Henning Kamp static int
227df8bae1dSRodney W. Grimes nullfs_unmount(mp, mntflags, p)
228df8bae1dSRodney W. Grimes 	struct mount *mp;
229df8bae1dSRodney W. Grimes 	int mntflags;
230df8bae1dSRodney W. Grimes 	struct proc *p;
231df8bae1dSRodney W. Grimes {
232df8bae1dSRodney W. Grimes 	struct vnode *nullm_rootvp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
233df8bae1dSRodney W. Grimes 	int error;
234df8bae1dSRodney W. Grimes 	int flags = 0;
235df8bae1dSRodney W. Grimes 
236df8bae1dSRodney W. Grimes #ifdef NULLFS_DIAGNOSTIC
237df8bae1dSRodney W. Grimes 	printf("nullfs_unmount(mp = %x)\n", mp);
238df8bae1dSRodney W. Grimes #endif
239df8bae1dSRodney W. Grimes 
240996c772fSJohn Dyson 	if (mntflags & MNT_FORCE)
241df8bae1dSRodney W. Grimes 		flags |= FORCECLOSE;
242df8bae1dSRodney W. Grimes 
243df8bae1dSRodney W. Grimes 	/*
244df8bae1dSRodney W. Grimes 	 * Clear out buffer cache.  I don't think we
245df8bae1dSRodney W. Grimes 	 * ever get anything cached at this level at the
246df8bae1dSRodney W. Grimes 	 * moment, but who knows...
247df8bae1dSRodney W. Grimes 	 */
248df8bae1dSRodney W. Grimes #if 0
249df8bae1dSRodney W. Grimes 	mntflushbuf(mp, 0);
250df8bae1dSRodney W. Grimes 	if (mntinvalbuf(mp, 1))
251df8bae1dSRodney W. Grimes 		return (EBUSY);
252df8bae1dSRodney W. Grimes #endif
253df8bae1dSRodney W. Grimes 	if (nullm_rootvp->v_usecount > 1)
254df8bae1dSRodney W. Grimes 		return (EBUSY);
2553a773ad0SPoul-Henning Kamp 	error = vflush(mp, nullm_rootvp, flags);
2563a773ad0SPoul-Henning Kamp 	if (error)
257df8bae1dSRodney W. Grimes 		return (error);
258df8bae1dSRodney W. Grimes 
259df8bae1dSRodney W. Grimes #ifdef NULLFS_DIAGNOSTIC
260df8bae1dSRodney W. Grimes 	vprint("alias root of lower", nullm_rootvp);
261df8bae1dSRodney W. Grimes #endif
262df8bae1dSRodney W. Grimes 	/*
263df8bae1dSRodney W. Grimes 	 * Release reference on underlying root vnode
264df8bae1dSRodney W. Grimes 	 */
265df8bae1dSRodney W. Grimes 	vrele(nullm_rootvp);
266df8bae1dSRodney W. Grimes 	/*
267df8bae1dSRodney W. Grimes 	 * And blow it away for future re-use
268df8bae1dSRodney W. Grimes 	 */
269df8bae1dSRodney W. Grimes 	vgone(nullm_rootvp);
270df8bae1dSRodney W. Grimes 	/*
271df8bae1dSRodney W. Grimes 	 * Finally, throw away the null_mount structure
272df8bae1dSRodney W. Grimes 	 */
273a1c995b6SPoul-Henning Kamp 	free(mp->mnt_data, M_NULLFSMNT);	/* XXX */
274df8bae1dSRodney W. Grimes 	mp->mnt_data = 0;
275df8bae1dSRodney W. Grimes 	return 0;
276df8bae1dSRodney W. Grimes }
277df8bae1dSRodney W. Grimes 
278d4b7a369SPoul-Henning Kamp static int
279df8bae1dSRodney W. Grimes nullfs_root(mp, vpp)
280df8bae1dSRodney W. Grimes 	struct mount *mp;
281df8bae1dSRodney W. Grimes 	struct vnode **vpp;
282df8bae1dSRodney W. Grimes {
283996c772fSJohn Dyson 	struct proc *p = curproc;	/* XXX */
284df8bae1dSRodney W. Grimes 	struct vnode *vp;
285df8bae1dSRodney W. Grimes 
286df8bae1dSRodney W. Grimes #ifdef NULLFS_DIAGNOSTIC
287df8bae1dSRodney W. Grimes 	printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp,
288df8bae1dSRodney W. Grimes 			MOUNTTONULLMOUNT(mp)->nullm_rootvp,
289df8bae1dSRodney W. Grimes 			NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp)
290df8bae1dSRodney W. Grimes 			);
291df8bae1dSRodney W. Grimes #endif
292df8bae1dSRodney W. Grimes 
293df8bae1dSRodney W. Grimes 	/*
294df8bae1dSRodney W. Grimes 	 * Return locked reference to root.
295df8bae1dSRodney W. Grimes 	 */
296df8bae1dSRodney W. Grimes 	vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
297df8bae1dSRodney W. Grimes 	VREF(vp);
298747e9157SKATO Takenori 	if (VOP_ISLOCKED(vp)) {
299747e9157SKATO Takenori 		/*
300747e9157SKATO Takenori 		 * XXX
301747e9157SKATO Takenori 		 * Should we check type of node?
302747e9157SKATO Takenori 		 */
303747e9157SKATO Takenori #ifdef DIAGNOSTIC
304747e9157SKATO Takenori 		printf("nullfs_root: multi null mount?\n");
305747e9157SKATO Takenori #endif
306747e9157SKATO Takenori 		vrele(vp);
307747e9157SKATO Takenori 		return (EDEADLK);
308747e9157SKATO Takenori 	} else
309996c772fSJohn Dyson 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
310df8bae1dSRodney W. Grimes 	*vpp = vp;
311df8bae1dSRodney W. Grimes 	return 0;
312df8bae1dSRodney W. Grimes }
313df8bae1dSRodney W. Grimes 
314d4b7a369SPoul-Henning Kamp static int
315df8bae1dSRodney W. Grimes nullfs_quotactl(mp, cmd, uid, arg, p)
316df8bae1dSRodney W. Grimes 	struct mount *mp;
317df8bae1dSRodney W. Grimes 	int cmd;
318df8bae1dSRodney W. Grimes 	uid_t uid;
319df8bae1dSRodney W. Grimes 	caddr_t arg;
320df8bae1dSRodney W. Grimes 	struct proc *p;
321df8bae1dSRodney W. Grimes {
322df8bae1dSRodney W. Grimes 	return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg, p);
323df8bae1dSRodney W. Grimes }
324df8bae1dSRodney W. Grimes 
325d4b7a369SPoul-Henning Kamp static int
326df8bae1dSRodney W. Grimes nullfs_statfs(mp, sbp, p)
327df8bae1dSRodney W. Grimes 	struct mount *mp;
328df8bae1dSRodney W. Grimes 	struct statfs *sbp;
329df8bae1dSRodney W. Grimes 	struct proc *p;
330df8bae1dSRodney W. Grimes {
331df8bae1dSRodney W. Grimes 	int error;
332df8bae1dSRodney W. Grimes 	struct statfs mstat;
333df8bae1dSRodney W. Grimes 
334df8bae1dSRodney W. Grimes #ifdef NULLFS_DIAGNOSTIC
335df8bae1dSRodney W. Grimes 	printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp,
336df8bae1dSRodney W. Grimes 			MOUNTTONULLMOUNT(mp)->nullm_rootvp,
337df8bae1dSRodney W. Grimes 			NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp)
338df8bae1dSRodney W. Grimes 			);
339df8bae1dSRodney W. Grimes #endif
340df8bae1dSRodney W. Grimes 
341df8bae1dSRodney W. Grimes 	bzero(&mstat, sizeof(mstat));
342df8bae1dSRodney W. Grimes 
343df8bae1dSRodney W. Grimes 	error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat, p);
344df8bae1dSRodney W. Grimes 	if (error)
345df8bae1dSRodney W. Grimes 		return (error);
346df8bae1dSRodney W. Grimes 
347df8bae1dSRodney W. Grimes 	/* now copy across the "interesting" information and fake the rest */
348df8bae1dSRodney W. Grimes 	sbp->f_type = mstat.f_type;
349df8bae1dSRodney W. Grimes 	sbp->f_flags = mstat.f_flags;
350df8bae1dSRodney W. Grimes 	sbp->f_bsize = mstat.f_bsize;
351df8bae1dSRodney W. Grimes 	sbp->f_iosize = mstat.f_iosize;
352df8bae1dSRodney W. Grimes 	sbp->f_blocks = mstat.f_blocks;
353df8bae1dSRodney W. Grimes 	sbp->f_bfree = mstat.f_bfree;
354df8bae1dSRodney W. Grimes 	sbp->f_bavail = mstat.f_bavail;
355df8bae1dSRodney W. Grimes 	sbp->f_files = mstat.f_files;
356df8bae1dSRodney W. Grimes 	sbp->f_ffree = mstat.f_ffree;
357df8bae1dSRodney W. Grimes 	if (sbp != &mp->mnt_stat) {
358df8bae1dSRodney W. Grimes 		bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
359df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
360df8bae1dSRodney W. Grimes 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
361df8bae1dSRodney W. Grimes 	}
362df8bae1dSRodney W. Grimes 	return (0);
363df8bae1dSRodney W. Grimes }
364df8bae1dSRodney W. Grimes 
365d4b7a369SPoul-Henning Kamp static int
366df8bae1dSRodney W. Grimes nullfs_sync(mp, waitfor, cred, p)
367df8bae1dSRodney W. Grimes 	struct mount *mp;
368df8bae1dSRodney W. Grimes 	int waitfor;
369df8bae1dSRodney W. Grimes 	struct ucred *cred;
370df8bae1dSRodney W. Grimes 	struct proc *p;
371df8bae1dSRodney W. Grimes {
372df8bae1dSRodney W. Grimes 	/*
373df8bae1dSRodney W. Grimes 	 * XXX - Assumes no data cached at null layer.
374df8bae1dSRodney W. Grimes 	 */
375df8bae1dSRodney W. Grimes 	return (0);
376df8bae1dSRodney W. Grimes }
377df8bae1dSRodney W. Grimes 
378d4b7a369SPoul-Henning Kamp static int
379df8bae1dSRodney W. Grimes nullfs_vget(mp, ino, vpp)
380df8bae1dSRodney W. Grimes 	struct mount *mp;
381df8bae1dSRodney W. Grimes 	ino_t ino;
382df8bae1dSRodney W. Grimes 	struct vnode **vpp;
383df8bae1dSRodney W. Grimes {
384df8bae1dSRodney W. Grimes 
385df8bae1dSRodney W. Grimes 	return VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, vpp);
386df8bae1dSRodney W. Grimes }
387df8bae1dSRodney W. Grimes 
388d4b7a369SPoul-Henning Kamp static int
389df8bae1dSRodney W. Grimes nullfs_fhtovp(mp, fidp, nam, vpp, exflagsp, credanonp)
390df8bae1dSRodney W. Grimes 	struct mount *mp;
391df8bae1dSRodney W. Grimes 	struct fid *fidp;
39257bf258eSGarrett Wollman 	struct sockaddr *nam;
393df8bae1dSRodney W. Grimes 	struct vnode **vpp;
394df8bae1dSRodney W. Grimes 	int *exflagsp;
395df8bae1dSRodney W. Grimes 	struct ucred**credanonp;
396df8bae1dSRodney W. Grimes {
397df8bae1dSRodney W. Grimes 
39857bf258eSGarrett Wollman 	return VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, nam,
39957bf258eSGarrett Wollman 			  vpp, exflagsp, credanonp);
400df8bae1dSRodney W. Grimes }
401df8bae1dSRodney W. Grimes 
402d4b7a369SPoul-Henning Kamp static int
403df8bae1dSRodney W. Grimes nullfs_vptofh(vp, fhp)
404df8bae1dSRodney W. Grimes 	struct vnode *vp;
405df8bae1dSRodney W. Grimes 	struct fid *fhp;
406df8bae1dSRodney W. Grimes {
407df8bae1dSRodney W. Grimes 	return VFS_VPTOFH(NULLVPTOLOWERVP(vp), fhp);
408df8bae1dSRodney W. Grimes }
409df8bae1dSRodney W. Grimes 
410d4b7a369SPoul-Henning Kamp static struct vfsops null_vfsops = {
411df8bae1dSRodney W. Grimes 	nullfs_mount,
412df8bae1dSRodney W. Grimes 	nullfs_start,
413df8bae1dSRodney W. Grimes 	nullfs_unmount,
414df8bae1dSRodney W. Grimes 	nullfs_root,
415df8bae1dSRodney W. Grimes 	nullfs_quotactl,
416df8bae1dSRodney W. Grimes 	nullfs_statfs,
417df8bae1dSRodney W. Grimes 	nullfs_sync,
418df8bae1dSRodney W. Grimes 	nullfs_vget,
419df8bae1dSRodney W. Grimes 	nullfs_fhtovp,
420df8bae1dSRodney W. Grimes 	nullfs_vptofh,
421df8bae1dSRodney W. Grimes 	nullfs_init,
422df8bae1dSRodney W. Grimes };
423c901836cSGarrett Wollman 
424bbf3a566SGarrett Wollman VFS_SET(null_vfsops, null, MOUNT_NULL, VFCF_LOOPBACK);
425