umap_vnops.c revision 1.21 1 1.21 chs /* $NetBSD: umap_vnops.c,v 1.21 2001/12/06 04:29:23 chs Exp $ */
2 1.2 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1992, 1993
5 1.1 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * This code is derived from software donated to Berkeley by
8 1.1 mycroft * the UCLA Ficus project.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer.
15 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.1 mycroft * documentation and/or other materials provided with the distribution.
18 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.1 mycroft * must display the following acknowledgement:
20 1.1 mycroft * This product includes software developed by the University of
21 1.1 mycroft * California, Berkeley and its contributors.
22 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
23 1.1 mycroft * may be used to endorse or promote products derived from this software
24 1.1 mycroft * without specific prior written permission.
25 1.1 mycroft *
26 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 mycroft * SUCH DAMAGE.
37 1.1 mycroft *
38 1.10 fvdl * @(#)umap_vnops.c 8.6 (Berkeley) 5/22/95
39 1.1 mycroft */
40 1.1 mycroft
41 1.1 mycroft /*
42 1.1 mycroft * Umap Layer
43 1.1 mycroft */
44 1.19 lukem
45 1.19 lukem #include <sys/cdefs.h>
46 1.21 chs __KERNEL_RCSID(0, "$NetBSD: umap_vnops.c,v 1.21 2001/12/06 04:29:23 chs Exp $");
47 1.1 mycroft
48 1.1 mycroft #include <sys/param.h>
49 1.1 mycroft #include <sys/systm.h>
50 1.1 mycroft #include <sys/time.h>
51 1.1 mycroft #include <sys/vnode.h>
52 1.1 mycroft #include <sys/mount.h>
53 1.1 mycroft #include <sys/namei.h>
54 1.1 mycroft #include <sys/malloc.h>
55 1.1 mycroft #include <sys/buf.h>
56 1.1 mycroft #include <miscfs/umapfs/umap.h>
57 1.10 fvdl #include <miscfs/genfs/genfs.h>
58 1.15 wrstuden #include <miscfs/genfs/layer_extern.h>
59 1.1 mycroft
60 1.15 wrstuden int umap_lookup __P((void *));
61 1.5 christos int umap_getattr __P((void *));
62 1.5 christos int umap_print __P((void *));
63 1.5 christos int umap_rename __P((void *));
64 1.10 fvdl
65 1.5 christos /*
66 1.5 christos * Global vfs data structures
67 1.5 christos */
68 1.5 christos /*
69 1.5 christos * XXX - strategy, bwrite are hand coded currently. They should
70 1.5 christos * go away with a merged buffer/block cache.
71 1.5 christos *
72 1.5 christos */
73 1.5 christos int (**umap_vnodeop_p) __P((void *));
74 1.18 jdolecek const struct vnodeopv_entry_desc umap_vnodeop_entries[] = {
75 1.15 wrstuden { &vop_default_desc, umap_bypass },
76 1.5 christos
77 1.15 wrstuden { &vop_lookup_desc, umap_lookup },
78 1.15 wrstuden { &vop_getattr_desc, umap_getattr },
79 1.15 wrstuden { &vop_print_desc, umap_print },
80 1.15 wrstuden { &vop_rename_desc, umap_rename },
81 1.15 wrstuden
82 1.15 wrstuden { &vop_lock_desc, layer_lock },
83 1.15 wrstuden { &vop_unlock_desc, layer_unlock },
84 1.15 wrstuden { &vop_islocked_desc, layer_islocked },
85 1.15 wrstuden { &vop_fsync_desc, layer_fsync },
86 1.15 wrstuden { &vop_inactive_desc, layer_inactive },
87 1.15 wrstuden { &vop_reclaim_desc, layer_reclaim },
88 1.15 wrstuden { &vop_open_desc, layer_open },
89 1.15 wrstuden { &vop_setattr_desc, layer_setattr },
90 1.15 wrstuden { &vop_access_desc, layer_access },
91 1.15 wrstuden
92 1.15 wrstuden { &vop_strategy_desc, layer_strategy },
93 1.15 wrstuden { &vop_bwrite_desc, layer_bwrite },
94 1.15 wrstuden { &vop_bmap_desc, layer_bmap },
95 1.21 chs { &vop_putpages_desc, layer_putpages },
96 1.5 christos
97 1.21 chs { NULL, NULL }
98 1.5 christos };
99 1.18 jdolecek const struct vnodeopv_desc umapfs_vnodeop_opv_desc =
100 1.5 christos { &umap_vnodeop_p, umap_vnodeop_entries };
101 1.5 christos
102 1.1 mycroft /*
103 1.15 wrstuden * This is the 08-June-1999 bypass routine.
104 1.15 wrstuden * See layer_vnops.c:layer_bypass for more details.
105 1.1 mycroft */
106 1.1 mycroft int
107 1.5 christos umap_bypass(v)
108 1.5 christos void *v;
109 1.5 christos {
110 1.1 mycroft struct vop_generic_args /* {
111 1.1 mycroft struct vnodeop_desc *a_desc;
112 1.1 mycroft <other random data follows, presumably>
113 1.5 christos } */ *ap = v;
114 1.1 mycroft struct ucred **credpp = 0, *credp = 0;
115 1.5 christos struct ucred *savecredp = 0, *savecompcredp = 0;
116 1.1 mycroft struct ucred *compcredp = 0;
117 1.1 mycroft struct vnode **this_vp_p;
118 1.15 wrstuden int error, error1;
119 1.15 wrstuden int (**our_vnodeop_p) __P((void *));
120 1.15 wrstuden struct vnode *old_vps[VDESC_MAX_VPS], *vp0;
121 1.1 mycroft struct vnode **vps_p[VDESC_MAX_VPS];
122 1.1 mycroft struct vnode ***vppp;
123 1.1 mycroft struct vnodeop_desc *descp = ap->a_desc;
124 1.15 wrstuden int reles, i, flags;
125 1.1 mycroft struct componentname **compnamepp = 0;
126 1.1 mycroft
127 1.1 mycroft #ifdef SAFETY
128 1.1 mycroft /*
129 1.1 mycroft * We require at least one vp.
130 1.1 mycroft */
131 1.1 mycroft if (descp->vdesc_vp_offsets == NULL ||
132 1.1 mycroft descp->vdesc_vp_offsets[0] == VDESC_NO_OFFSET)
133 1.1 mycroft panic ("umap_bypass: no vp's in map.\n");
134 1.1 mycroft #endif
135 1.15 wrstuden vps_p[0] = VOPARG_OFFSETTO(struct vnode**,descp->vdesc_vp_offsets[0],
136 1.15 wrstuden ap);
137 1.15 wrstuden vp0 = *vps_p[0];
138 1.15 wrstuden flags = MOUNTTOUMAPMOUNT(vp0->v_mount)->umapm_flags;
139 1.15 wrstuden our_vnodeop_p = vp0->v_op;
140 1.15 wrstuden
141 1.15 wrstuden if (flags & LAYERFS_MBYPASSDEBUG)
142 1.15 wrstuden printf("umap_bypass: %s\n", descp->vdesc_name);
143 1.1 mycroft
144 1.1 mycroft /*
145 1.1 mycroft * Map the vnodes going in.
146 1.1 mycroft * Later, we'll invoke the operation based on
147 1.1 mycroft * the first mapped vnode's operation vector.
148 1.1 mycroft */
149 1.1 mycroft reles = descp->vdesc_flags;
150 1.1 mycroft for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
151 1.1 mycroft if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
152 1.1 mycroft break; /* bail out at end of list */
153 1.1 mycroft vps_p[i] = this_vp_p =
154 1.1 mycroft VOPARG_OFFSETTO(struct vnode**, descp->vdesc_vp_offsets[i], ap);
155 1.1 mycroft
156 1.1 mycroft /*
157 1.1 mycroft * We're not guaranteed that any but the first vnode
158 1.1 mycroft * are of our type. Check for and don't map any
159 1.1 mycroft * that aren't. (Must map first vp or vclean fails.)
160 1.1 mycroft */
161 1.1 mycroft
162 1.15 wrstuden if (i && ((*this_vp_p)==NULL ||
163 1.15 wrstuden (*this_vp_p)->v_op != our_vnodeop_p)) {
164 1.1 mycroft old_vps[i] = NULL;
165 1.1 mycroft } else {
166 1.1 mycroft old_vps[i] = *this_vp_p;
167 1.1 mycroft *(vps_p[i]) = UMAPVPTOLOWERVP(*this_vp_p);
168 1.1 mycroft if (reles & 1)
169 1.1 mycroft VREF(*this_vp_p);
170 1.1 mycroft }
171 1.1 mycroft
172 1.1 mycroft }
173 1.1 mycroft
174 1.1 mycroft /*
175 1.1 mycroft * Fix the credentials. (That's the purpose of this layer.)
176 1.1 mycroft */
177 1.1 mycroft
178 1.1 mycroft if (descp->vdesc_cred_offset != VDESC_NO_OFFSET) {
179 1.1 mycroft
180 1.1 mycroft credpp = VOPARG_OFFSETTO(struct ucred**,
181 1.1 mycroft descp->vdesc_cred_offset, ap);
182 1.1 mycroft
183 1.1 mycroft /* Save old values */
184 1.1 mycroft
185 1.1 mycroft savecredp = *credpp;
186 1.1 mycroft if (savecredp != NOCRED)
187 1.1 mycroft *credpp = crdup(savecredp);
188 1.1 mycroft credp = *credpp;
189 1.1 mycroft
190 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && credp->cr_uid != 0)
191 1.8 christos printf("umap_bypass: user was %d, group %d\n",
192 1.1 mycroft credp->cr_uid, credp->cr_gid);
193 1.1 mycroft
194 1.1 mycroft /* Map all ids in the credential structure. */
195 1.1 mycroft
196 1.15 wrstuden umap_mapids(vp0->v_mount, credp);
197 1.1 mycroft
198 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && credp->cr_uid != 0)
199 1.8 christos printf("umap_bypass: user now %d, group %d\n",
200 1.1 mycroft credp->cr_uid, credp->cr_gid);
201 1.1 mycroft }
202 1.1 mycroft
203 1.1 mycroft /* BSD often keeps a credential in the componentname structure
204 1.1 mycroft * for speed. If there is one, it better get mapped, too.
205 1.1 mycroft */
206 1.1 mycroft
207 1.1 mycroft if (descp->vdesc_componentname_offset != VDESC_NO_OFFSET) {
208 1.1 mycroft
209 1.1 mycroft compnamepp = VOPARG_OFFSETTO(struct componentname**,
210 1.1 mycroft descp->vdesc_componentname_offset, ap);
211 1.1 mycroft
212 1.1 mycroft savecompcredp = (*compnamepp)->cn_cred;
213 1.1 mycroft if (savecompcredp != NOCRED)
214 1.1 mycroft (*compnamepp)->cn_cred = crdup(savecompcredp);
215 1.1 mycroft compcredp = (*compnamepp)->cn_cred;
216 1.1 mycroft
217 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp->cr_uid != 0)
218 1.8 christos printf("umap_bypass: component credit user was %d, group %d\n",
219 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
220 1.1 mycroft
221 1.1 mycroft /* Map all ids in the credential structure. */
222 1.1 mycroft
223 1.15 wrstuden umap_mapids(vp0->v_mount, compcredp);
224 1.1 mycroft
225 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp->cr_uid != 0)
226 1.8 christos printf("umap_bypass: component credit user now %d, group %d\n",
227 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
228 1.1 mycroft }
229 1.1 mycroft
230 1.1 mycroft /*
231 1.1 mycroft * Call the operation on the lower layer
232 1.1 mycroft * with the modified argument structure.
233 1.1 mycroft */
234 1.1 mycroft error = VCALL(*(vps_p[0]), descp->vdesc_offset, ap);
235 1.1 mycroft
236 1.1 mycroft /*
237 1.1 mycroft * Maintain the illusion of call-by-value
238 1.1 mycroft * by restoring vnodes in the argument structure
239 1.1 mycroft * to their original value.
240 1.1 mycroft */
241 1.1 mycroft reles = descp->vdesc_flags;
242 1.1 mycroft for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
243 1.1 mycroft if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
244 1.1 mycroft break; /* bail out at end of list */
245 1.1 mycroft if (old_vps[i]) {
246 1.1 mycroft *(vps_p[i]) = old_vps[i];
247 1.15 wrstuden if (reles & VDESC_VP0_WILLUNLOCK)
248 1.15 wrstuden LAYERFS_UPPERUNLOCK(*(vps_p[i]), 0, error1);
249 1.15 wrstuden if (reles & VDESC_VP0_WILLRELE)
250 1.1 mycroft vrele(*(vps_p[i]));
251 1.1 mycroft };
252 1.1 mycroft };
253 1.1 mycroft
254 1.1 mycroft /*
255 1.1 mycroft * Map the possible out-going vpp
256 1.1 mycroft * (Assumes that the lower layer always returns
257 1.1 mycroft * a VREF'ed vpp unless it gets an error.)
258 1.1 mycroft */
259 1.1 mycroft if (descp->vdesc_vpp_offset != VDESC_NO_OFFSET &&
260 1.1 mycroft !(descp->vdesc_flags & VDESC_NOMAP_VPP) &&
261 1.1 mycroft !error) {
262 1.1 mycroft if (descp->vdesc_flags & VDESC_VPP_WILLRELE)
263 1.1 mycroft goto out;
264 1.1 mycroft vppp = VOPARG_OFFSETTO(struct vnode***,
265 1.1 mycroft descp->vdesc_vpp_offset, ap);
266 1.15 wrstuden error = layer_node_create(old_vps[0]->v_mount, **vppp, *vppp);
267 1.1 mycroft };
268 1.1 mycroft
269 1.1 mycroft out:
270 1.1 mycroft /*
271 1.1 mycroft * Free duplicate cred structure and restore old one.
272 1.1 mycroft */
273 1.1 mycroft if (descp->vdesc_cred_offset != VDESC_NO_OFFSET) {
274 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && credp &&
275 1.15 wrstuden credp->cr_uid != 0)
276 1.8 christos printf("umap_bypass: returning-user was %d\n",
277 1.7 christos credp->cr_uid);
278 1.1 mycroft
279 1.1 mycroft if (savecredp != NOCRED) {
280 1.1 mycroft crfree(credp);
281 1.1 mycroft *credpp = savecredp;
282 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && credpp &&
283 1.15 wrstuden (*credpp)->cr_uid != 0)
284 1.8 christos printf("umap_bypass: returning-user now %d\n\n",
285 1.1 mycroft savecredp->cr_uid);
286 1.1 mycroft }
287 1.1 mycroft }
288 1.1 mycroft
289 1.1 mycroft if (descp->vdesc_componentname_offset != VDESC_NO_OFFSET) {
290 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp &&
291 1.15 wrstuden compcredp->cr_uid != 0)
292 1.8 christos printf("umap_bypass: returning-component-user was %d\n",
293 1.7 christos compcredp->cr_uid);
294 1.1 mycroft
295 1.1 mycroft if (savecompcredp != NOCRED) {
296 1.1 mycroft crfree(compcredp);
297 1.1 mycroft (*compnamepp)->cn_cred = savecompcredp;
298 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && savecompcredp &&
299 1.15 wrstuden savecompcredp->cr_uid != 0)
300 1.8 christos printf("umap_bypass: returning-component-user now %d\n",
301 1.1 mycroft savecompcredp->cr_uid);
302 1.1 mycroft }
303 1.1 mycroft }
304 1.1 mycroft
305 1.1 mycroft return (error);
306 1.1 mycroft }
307 1.1 mycroft
308 1.10 fvdl /*
309 1.15 wrstuden * This is based on the 08-June-1999 bypass routine.
310 1.15 wrstuden * See layer_vnops.c:layer_bypass for more details.
311 1.15 wrstuden */
312 1.10 fvdl int
313 1.15 wrstuden umap_lookup(v)
314 1.10 fvdl void *v;
315 1.10 fvdl {
316 1.15 wrstuden struct vop_lookup_args /* {
317 1.15 wrstuden struct vnodeop_desc *a_desc;
318 1.15 wrstuden struct vnode * a_dvp;
319 1.15 wrstuden struct vnode ** a_vpp;
320 1.15 wrstuden struct componentname * a_cnp;
321 1.15 wrstuden } */ *ap = v;
322 1.15 wrstuden struct componentname *cnp = ap->a_cnp;
323 1.15 wrstuden struct ucred *savecompcredp = NULL;
324 1.15 wrstuden struct ucred *compcredp = NULL;
325 1.15 wrstuden struct vnode *dvp, *vp, *ldvp;
326 1.15 wrstuden struct mount *mp;
327 1.15 wrstuden int error;
328 1.15 wrstuden int i, flags, cnf = cnp->cn_flags;
329 1.15 wrstuden
330 1.15 wrstuden dvp = ap->a_dvp;
331 1.15 wrstuden mp = dvp->v_mount;
332 1.15 wrstuden
333 1.15 wrstuden if ((cnf & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
334 1.15 wrstuden (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
335 1.15 wrstuden return (EROFS);
336 1.15 wrstuden
337 1.15 wrstuden flags = MOUNTTOUMAPMOUNT(mp)->umapm_flags;
338 1.15 wrstuden ldvp = UMAPVPTOLOWERVP(dvp);
339 1.15 wrstuden
340 1.15 wrstuden if (flags & LAYERFS_MBYPASSDEBUG)
341 1.15 wrstuden printf("umap_lookup\n");
342 1.15 wrstuden
343 1.15 wrstuden /*
344 1.15 wrstuden * Fix the credentials. (That's the purpose of this layer.)
345 1.15 wrstuden *
346 1.15 wrstuden * BSD often keeps a credential in the componentname structure
347 1.15 wrstuden * for speed. If there is one, it better get mapped, too.
348 1.15 wrstuden */
349 1.15 wrstuden
350 1.15 wrstuden if ((savecompcredp = cnp->cn_cred)) {
351 1.15 wrstuden compcredp = crdup(savecompcredp);
352 1.15 wrstuden cnp->cn_cred = compcredp;
353 1.15 wrstuden
354 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp->cr_uid != 0)
355 1.15 wrstuden printf("umap_lookup: component credit user was %d, group %d\n",
356 1.15 wrstuden compcredp->cr_uid, compcredp->cr_gid);
357 1.10 fvdl
358 1.15 wrstuden /* Map all ids in the credential structure. */
359 1.15 wrstuden umap_mapids(mp, compcredp);
360 1.15 wrstuden }
361 1.10 fvdl
362 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp->cr_uid != 0)
363 1.15 wrstuden printf("umap_lookup: component credit user now %d, group %d\n",
364 1.15 wrstuden compcredp->cr_uid, compcredp->cr_gid);
365 1.10 fvdl
366 1.15 wrstuden ap->a_dvp = ldvp;
367 1.15 wrstuden error = VCALL(ldvp, ap->a_desc->vdesc_offset, ap);
368 1.16 wrstuden vp = *ap->a_vpp;
369 1.12 sommerfe
370 1.15 wrstuden if (error == EJUSTRETURN && (cnf & ISLASTCN) &&
371 1.15 wrstuden (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
372 1.15 wrstuden (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
373 1.15 wrstuden error = EROFS;
374 1.15 wrstuden
375 1.15 wrstuden /* Do locking fixup as appropriate. See layer_lookup() for info */
376 1.15 wrstuden if ((cnp->cn_flags & PDIRUNLOCK)) {
377 1.15 wrstuden LAYERFS_UPPERUNLOCK(dvp, 0, i);
378 1.15 wrstuden }
379 1.15 wrstuden if (ldvp == vp) {
380 1.15 wrstuden *ap->a_vpp = dvp;
381 1.15 wrstuden VREF(dvp);
382 1.15 wrstuden vrele(vp);
383 1.15 wrstuden } else if (vp != NULL) {
384 1.15 wrstuden error = layer_node_create(mp, vp, ap->a_vpp);
385 1.15 wrstuden }
386 1.12 sommerfe
387 1.15 wrstuden /*
388 1.15 wrstuden * Free duplicate cred structure and restore old one.
389 1.15 wrstuden */
390 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp &&
391 1.15 wrstuden compcredp->cr_uid != 0)
392 1.15 wrstuden printf("umap_lookup: returning-component-user was %d\n",
393 1.15 wrstuden compcredp->cr_uid);
394 1.12 sommerfe
395 1.15 wrstuden if (savecompcredp != NOCRED) {
396 1.15 wrstuden crfree(compcredp);
397 1.15 wrstuden cnp->cn_cred = savecompcredp;
398 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && savecompcredp &&
399 1.15 wrstuden savecompcredp->cr_uid != 0)
400 1.15 wrstuden printf("umap_lookup: returning-component-user now %d\n",
401 1.15 wrstuden savecompcredp->cr_uid);
402 1.15 wrstuden }
403 1.12 sommerfe
404 1.15 wrstuden return (error);
405 1.10 fvdl }
406 1.1 mycroft
407 1.1 mycroft /*
408 1.1 mycroft * We handle getattr to change the fsid.
409 1.1 mycroft */
410 1.1 mycroft int
411 1.5 christos umap_getattr(v)
412 1.5 christos void *v;
413 1.5 christos {
414 1.1 mycroft struct vop_getattr_args /* {
415 1.1 mycroft struct vnode *a_vp;
416 1.1 mycroft struct vattr *a_vap;
417 1.1 mycroft struct ucred *a_cred;
418 1.1 mycroft struct proc *a_p;
419 1.5 christos } */ *ap = v;
420 1.1 mycroft uid_t uid;
421 1.1 mycroft gid_t gid;
422 1.15 wrstuden int error, tmpid, nentries, gnentries, flags;
423 1.4 cgd u_long (*mapdata)[2];
424 1.4 cgd u_long (*gmapdata)[2];
425 1.1 mycroft struct vnode **vp1p;
426 1.17 jdolecek const struct vnodeop_desc *descp = ap->a_desc;
427 1.1 mycroft
428 1.5 christos if ((error = umap_bypass(ap)) != 0)
429 1.1 mycroft return (error);
430 1.1 mycroft /* Requires that arguments be restored. */
431 1.1 mycroft ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0];
432 1.1 mycroft
433 1.15 wrstuden flags = MOUNTTOUMAPMOUNT(ap->a_vp->v_mount)->umapm_flags;
434 1.1 mycroft /*
435 1.1 mycroft * Umap needs to map the uid and gid returned by a stat
436 1.1 mycroft * into the proper values for this site. This involves
437 1.1 mycroft * finding the returned uid in the mapping information,
438 1.1 mycroft * translating it into the uid on the other end,
439 1.1 mycroft * and filling in the proper field in the vattr
440 1.1 mycroft * structure pointed to by ap->a_vap. The group
441 1.1 mycroft * is easier, since currently all groups will be
442 1.1 mycroft * translate to the NULLGROUP.
443 1.1 mycroft */
444 1.1 mycroft
445 1.1 mycroft /* Find entry in map */
446 1.1 mycroft
447 1.1 mycroft uid = ap->a_vap->va_uid;
448 1.1 mycroft gid = ap->a_vap->va_gid;
449 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG))
450 1.8 christos printf("umap_getattr: mapped uid = %d, mapped gid = %d\n", uid,
451 1.1 mycroft gid);
452 1.1 mycroft
453 1.1 mycroft vp1p = VOPARG_OFFSETTO(struct vnode**, descp->vdesc_vp_offsets[0], ap);
454 1.1 mycroft nentries = MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_nentries;
455 1.1 mycroft mapdata = (MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_mapdata);
456 1.1 mycroft gnentries = MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_gnentries;
457 1.1 mycroft gmapdata = (MOUNTTOUMAPMOUNT((*vp1p)->v_mount)->info_gmapdata);
458 1.1 mycroft
459 1.1 mycroft /* Reverse map the uid for the vnode. Since it's a reverse
460 1.1 mycroft map, we can't use umap_mapids() to do it. */
461 1.1 mycroft
462 1.1 mycroft tmpid = umap_reverse_findid(uid, mapdata, nentries);
463 1.1 mycroft
464 1.1 mycroft if (tmpid != -1) {
465 1.1 mycroft ap->a_vap->va_uid = (uid_t) tmpid;
466 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG))
467 1.8 christos printf("umap_getattr: original uid = %d\n", uid);
468 1.1 mycroft } else
469 1.1 mycroft ap->a_vap->va_uid = (uid_t) NOBODY;
470 1.1 mycroft
471 1.1 mycroft /* Reverse map the gid for the vnode. */
472 1.1 mycroft
473 1.1 mycroft tmpid = umap_reverse_findid(gid, gmapdata, gnentries);
474 1.1 mycroft
475 1.1 mycroft if (tmpid != -1) {
476 1.1 mycroft ap->a_vap->va_gid = (gid_t) tmpid;
477 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG))
478 1.8 christos printf("umap_getattr: original gid = %d\n", gid);
479 1.1 mycroft } else
480 1.1 mycroft ap->a_vap->va_gid = (gid_t) NULLGROUP;
481 1.1 mycroft
482 1.1 mycroft return (0);
483 1.13 bouyer }
484 1.13 bouyer
485 1.1 mycroft int
486 1.5 christos umap_print(v)
487 1.5 christos void *v;
488 1.5 christos {
489 1.1 mycroft struct vop_print_args /* {
490 1.1 mycroft struct vnode *a_vp;
491 1.5 christos } */ *ap = v;
492 1.1 mycroft struct vnode *vp = ap->a_vp;
493 1.8 christos printf("\ttag VT_UMAPFS, vp=%p, lowervp=%p\n", vp,
494 1.6 cgd UMAPVPTOLOWERVP(vp));
495 1.1 mycroft return (0);
496 1.1 mycroft }
497 1.1 mycroft
498 1.1 mycroft int
499 1.5 christos umap_rename(v)
500 1.5 christos void *v;
501 1.5 christos {
502 1.1 mycroft struct vop_rename_args /* {
503 1.1 mycroft struct vnode *a_fdvp;
504 1.1 mycroft struct vnode *a_fvp;
505 1.1 mycroft struct componentname *a_fcnp;
506 1.1 mycroft struct vnode *a_tdvp;
507 1.1 mycroft struct vnode *a_tvp;
508 1.1 mycroft struct componentname *a_tcnp;
509 1.5 christos } */ *ap = v;
510 1.15 wrstuden int error, flags;
511 1.1 mycroft struct componentname *compnamep;
512 1.1 mycroft struct ucred *compcredp, *savecompcredp;
513 1.1 mycroft struct vnode *vp;
514 1.1 mycroft
515 1.1 mycroft /*
516 1.1 mycroft * Rename is irregular, having two componentname structures.
517 1.1 mycroft * We need to map the cre in the second structure,
518 1.1 mycroft * and then bypass takes care of the rest.
519 1.1 mycroft */
520 1.1 mycroft
521 1.1 mycroft vp = ap->a_fdvp;
522 1.15 wrstuden flags = MOUNTTOUMAPMOUNT(vp->v_mount)->umapm_flags;
523 1.1 mycroft compnamep = ap->a_tcnp;
524 1.1 mycroft compcredp = compnamep->cn_cred;
525 1.1 mycroft
526 1.1 mycroft savecompcredp = compcredp;
527 1.1 mycroft compcredp = compnamep->cn_cred = crdup(savecompcredp);
528 1.1 mycroft
529 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp->cr_uid != 0)
530 1.8 christos printf("umap_rename: rename component credit user was %d, group %d\n",
531 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
532 1.1 mycroft
533 1.1 mycroft /* Map all ids in the credential structure. */
534 1.1 mycroft
535 1.1 mycroft umap_mapids(vp->v_mount, compcredp);
536 1.1 mycroft
537 1.15 wrstuden if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp->cr_uid != 0)
538 1.8 christos printf("umap_rename: rename component credit user now %d, group %d\n",
539 1.1 mycroft compcredp->cr_uid, compcredp->cr_gid);
540 1.1 mycroft
541 1.1 mycroft error = umap_bypass(ap);
542 1.1 mycroft
543 1.1 mycroft /* Restore the additional mapped componentname cred structure. */
544 1.1 mycroft
545 1.1 mycroft crfree(compcredp);
546 1.1 mycroft compnamep->cn_cred = savecompcredp;
547 1.1 mycroft
548 1.1 mycroft return error;
549 1.1 mycroft }
550