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