xref: /netbsd-src/sys/miscfs/genfs/layer_vfsops.c (revision 001c68bd94f75ce9270b69227c4199fbf34ee396)
1 /*	$NetBSD: layer_vfsops.c,v 1.9 2003/06/29 22:31:41 fvdl Exp $	*/
2 
3 /*
4  * Copyright (c) 1999 National Aeronautics & Space Administration
5  * All rights reserved.
6  *
7  * This software was written by William Studenmund of the
8  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the National Aeronautics & Space Administration
19  *    nor the names of its contributors may be used to endorse or promote
20  *    products derived from this software without specific prior written
21  *    permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*
36  * Copyright (c) 1992, 1993, 1995
37  *	The Regents of the University of California.  All rights reserved.
38  *
39  * This code is derived from software donated to Berkeley by
40  * Jan-Simon Pendry.
41  *
42  * Redistribution and use in source and binary forms, with or without
43  * modification, are permitted provided that the following conditions
44  * are met:
45  * 1. Redistributions of source code must retain the above copyright
46  *    notice, this list of conditions and the following disclaimer.
47  * 2. Redistributions in binary form must reproduce the above copyright
48  *    notice, this list of conditions and the following disclaimer in the
49  *    documentation and/or other materials provided with the distribution.
50  * 3. All advertising materials mentioning features or use of this software
51  *    must display the following acknowledgement:
52  *	This product includes software developed by the University of
53  *	California, Berkeley and its contributors.
54  * 4. Neither the name of the University nor the names of its contributors
55  *    may be used to endorse or promote products derived from this software
56  *    without specific prior written permission.
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68  * SUCH DAMAGE.
69  *
70  *	from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
71  *	from: @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
72  *	@(#)null_vfsops.c	8.7 (Berkeley) 5/14/95
73  */
74 
75 /*
76  * generic layer vfs ops.
77  */
78 
79 #include <sys/cdefs.h>
80 __KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.9 2003/06/29 22:31:41 fvdl Exp $");
81 
82 #include <sys/param.h>
83 #include <sys/systm.h>
84 #include <sys/time.h>
85 #include <sys/proc.h>
86 #include <sys/vnode.h>
87 #include <sys/mount.h>
88 #include <sys/namei.h>
89 #include <sys/malloc.h>
90 #include <miscfs/genfs/layer.h>
91 #include <miscfs/genfs/layer_extern.h>
92 
93 /*
94  * VFS start.  Nothing needed here - the start routine
95  * on the underlying filesystem will have been called
96  * when that filesystem was mounted.
97  */
98 int
99 layerfs_start(mp, flags, p)
100 	struct mount *mp;
101 	int flags;
102 	struct proc *p;
103 {
104 
105 	return (0);
106 	/* return VFS_START(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, flags, p); */
107 }
108 
109 int
110 layerfs_root(mp, vpp)
111 	struct mount *mp;
112 	struct vnode **vpp;
113 {
114 	struct vnode *vp;
115 
116 #ifdef LAYERFS_DIAGNOSTIC
117 	printf("layerfs_root(mp = %p, vp = %p->%p)\n", mp,
118 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
119 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
120 #endif
121 
122 	/*
123 	 * Return locked reference to root.
124 	 */
125 	vp = MOUNTTOLAYERMOUNT(mp)->layerm_rootvp;
126 	if (vp == NULL) {
127 		*vpp = NULL;
128 		return (EINVAL);
129 	}
130 	VREF(vp);
131 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
132 	*vpp = vp;
133 	return 0;
134 }
135 
136 int
137 layerfs_quotactl(mp, cmd, uid, arg, p)
138 	struct mount *mp;
139 	int cmd;
140 	uid_t uid;
141 	caddr_t arg;
142 	struct proc *p;
143 {
144 
145 	return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp)->layerm_vfs,
146 				cmd, uid, arg, p);
147 }
148 
149 int
150 layerfs_statfs(mp, sbp, p)
151 	struct mount *mp;
152 	struct statfs *sbp;
153 	struct proc *p;
154 {
155 	int error;
156 	struct statfs mstat;
157 
158 #ifdef LAYERFS_DIAGNOSTIC
159 	printf("layerfs_statfs(mp = %p, vp = %p->%p)\n", mp,
160 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
161 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
162 #endif
163 
164 	memset(&mstat, 0, sizeof(mstat));
165 
166 	error = VFS_STATFS(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, &mstat, p);
167 	if (error)
168 		return (error);
169 
170 	/* now copy across the "interesting" information and fake the rest */
171 	sbp->f_type = mstat.f_type;
172 	sbp->f_flags = mstat.f_flags;
173 	sbp->f_bsize = mstat.f_bsize;
174 	sbp->f_iosize = mstat.f_iosize;
175 	sbp->f_blocks = mstat.f_blocks;
176 	sbp->f_bfree = mstat.f_bfree;
177 	sbp->f_bavail = mstat.f_bavail;
178 	sbp->f_files = mstat.f_files;
179 	sbp->f_ffree = mstat.f_ffree;
180 	copy_statfs_info(sbp, mp);
181 	return (0);
182 }
183 
184 int
185 layerfs_sync(mp, waitfor, cred, p)
186 	struct mount *mp;
187 	int waitfor;
188 	struct ucred *cred;
189 	struct proc *p;
190 {
191 
192 	/*
193 	 * XXX - Assumes no data cached at layer.
194 	 */
195 	return (0);
196 }
197 
198 int
199 layerfs_vget(mp, ino, vpp)
200 	struct mount *mp;
201 	ino_t ino;
202 	struct vnode **vpp;
203 {
204 	int error;
205 	struct vnode *vp;
206 
207 	if ((error = VFS_VGET(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, ino, &vp))) {
208 		*vpp = NULL;
209 		return (error);
210 	}
211 	if ((error = layer_node_create(mp, vp, vpp))) {
212 		vput(vp);
213 		*vpp = NULL;
214 		return (error);
215 	}
216 
217 	return (0);
218 }
219 
220 int
221 layerfs_fhtovp(mp, fidp, vpp)
222 	struct mount *mp;
223 	struct fid *fidp;
224 	struct vnode **vpp;
225 {
226 	int error;
227 	struct vnode *vp;
228 
229 	if ((error = VFS_FHTOVP(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, fidp, &vp)))
230 		return (error);
231 
232 	if ((error = layer_node_create(mp, vp, vpp))) {
233 		vput(vp);
234 		*vpp = NULL;
235 		return (error);
236 	}
237 
238 	return (0);
239 }
240 
241 int
242 layerfs_checkexp(mp, nam, exflagsp, credanonp)
243 	struct mount *mp;
244 	struct mbuf *nam;
245 	int *exflagsp;
246 	struct ucred**credanonp;
247 {
248 	struct	netcred *np;
249 	struct	layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
250 
251 	/*
252 	 * get the export permission structure for this <mp, client> tuple.
253 	 */
254 	if ((np = vfs_export_lookup(mp, &lmp->layerm_export, nam)) == NULL)
255 		return (EACCES);
256 
257 	*exflagsp = np->netc_exflags;
258 	*credanonp = &np->netc_anon;
259 	return (0);
260 }
261 
262 int
263 layerfs_vptofh(vp, fhp)
264 	struct vnode *vp;
265 	struct fid *fhp;
266 {
267 
268 	return (VFS_VPTOFH(LAYERVPTOLOWERVP(vp), fhp));
269 }
270 
271 int
272 layerfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
273 	int *name;
274 	u_int namelen;
275 	void *oldp;
276 	size_t *oldlenp;
277 	void *newp;
278 	size_t newlen;
279 	struct proc *p;
280 {
281 	return (EOPNOTSUPP);
282 }
283