overlay_vnops.c revision 1.2.6.2 1 1.2.6.2 bouyer /* $NetBSD: overlay_vnops.c,v 1.2.6.2 2000/11/20 18:09:48 bouyer Exp $ */
2 1.2.6.2 bouyer
3 1.2.6.2 bouyer /*
4 1.2.6.2 bouyer * Copyright (c) 1999, 2000 National Aeronautics & Space Administration
5 1.2.6.2 bouyer * All rights reserved.
6 1.2.6.2 bouyer *
7 1.2.6.2 bouyer * This software was written by William Studenmund of the
8 1.2.6.2 bouyer * Numerical Aerospace Similation Facility, NASA Ames Research Center.
9 1.2.6.2 bouyer *
10 1.2.6.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2.6.2 bouyer * modification, are permitted provided that the following conditions
12 1.2.6.2 bouyer * are met:
13 1.2.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2.6.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2.6.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2.6.2 bouyer * 3. Neither the name of the National Aeronautics & Space Administration
19 1.2.6.2 bouyer * nor the names of its contributors may be used to endorse or promote
20 1.2.6.2 bouyer * products derived from this software without specific prior written
21 1.2.6.2 bouyer * permission.
22 1.2.6.2 bouyer *
23 1.2.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24 1.2.6.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.2.6.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.2.6.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27 1.2.6.2 bouyer * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28 1.2.6.2 bouyer * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.2.6.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.2.6.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.2.6.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.2.6.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.2.6.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
34 1.2.6.2 bouyer */
35 1.2.6.2 bouyer /*
36 1.2.6.2 bouyer * Copyright (c) 1992, 1993
37 1.2.6.2 bouyer * The Regents of the University of California. All rights reserved.
38 1.2.6.2 bouyer *
39 1.2.6.2 bouyer * This code is derived from software contributed to Berkeley by
40 1.2.6.2 bouyer * John Heidemann of the UCLA Ficus project.
41 1.2.6.2 bouyer *
42 1.2.6.2 bouyer * Redistribution and use in source and binary forms, with or without
43 1.2.6.2 bouyer * modification, are permitted provided that the following conditions
44 1.2.6.2 bouyer * are met:
45 1.2.6.2 bouyer * 1. Redistributions of source code must retain the above copyright
46 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer.
47 1.2.6.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
48 1.2.6.2 bouyer * notice, this list of conditions and the following disclaimer in the
49 1.2.6.2 bouyer * documentation and/or other materials provided with the distribution.
50 1.2.6.2 bouyer * 3. All advertising materials mentioning features or use of this software
51 1.2.6.2 bouyer * must display the following acknowledgement:
52 1.2.6.2 bouyer * This product includes software developed by the University of
53 1.2.6.2 bouyer * California, Berkeley and its contributors.
54 1.2.6.2 bouyer * 4. Neither the name of the University nor the names of its contributors
55 1.2.6.2 bouyer * may be used to endorse or promote products derived from this software
56 1.2.6.2 bouyer * without specific prior written permission.
57 1.2.6.2 bouyer *
58 1.2.6.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.2.6.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.2.6.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.2.6.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.2.6.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.2.6.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.2.6.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.2.6.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.2.6.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.2.6.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.2.6.2 bouyer * SUCH DAMAGE.
69 1.2.6.2 bouyer *
70 1.2.6.2 bouyer * @(#)null_vnops.c 8.6 (Berkeley) 5/27/95
71 1.2.6.2 bouyer *
72 1.2.6.2 bouyer * Ancestors:
73 1.2.6.2 bouyer * @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92
74 1.2.6.2 bouyer * $Id: overlay_vnops.c,v 1.2.6.2 2000/11/20 18:09:48 bouyer Exp $
75 1.2.6.2 bouyer * ...and...
76 1.2.6.2 bouyer * @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
77 1.2.6.2 bouyer */
78 1.2.6.2 bouyer
79 1.2.6.2 bouyer /*
80 1.2.6.2 bouyer * Overlay Layer
81 1.2.6.2 bouyer *
82 1.2.6.2 bouyer * (See mount_overlay(8) for more information.)
83 1.2.6.2 bouyer *
84 1.2.6.2 bouyer * The overlay layer has two purposes. First, it serves as a demonstration
85 1.2.6.2 bouyer * of layering by proving a layer which really does nothing. (the null
86 1.2.6.2 bouyer * layer makes the underlying files appear elsewhere in the file hierarchy)
87 1.2.6.2 bouyer * Second, the overlay layer can serve as a prototype layer. Since it
88 1.2.6.2 bouyer * provides all necessary layer framework, new file system layers can be
89 1.2.6.2 bouyer * created very easily be starting with an overlay layer.
90 1.2.6.2 bouyer *
91 1.2.6.2 bouyer * The remainder of this comment examines the overlay layer as a basis
92 1.2.6.2 bouyer * for constructing new layers.
93 1.2.6.2 bouyer *
94 1.2.6.2 bouyer *
95 1.2.6.2 bouyer * INSTANTIATING NEW OVERLAY LAYERS
96 1.2.6.2 bouyer *
97 1.2.6.2 bouyer * New null layers are created with mount_overlay(8).
98 1.2.6.2 bouyer * Mount_overlay(8) takes two arguments, an ignored string
99 1.2.6.2 bouyer * and the pathname which the overlay will mount over. After
100 1.2.6.2 bouyer * the overlay layer is put into place, all access to the mount
101 1.2.6.2 bouyer * point path will proceede through the overlay layer.
102 1.2.6.2 bouyer *
103 1.2.6.2 bouyer *
104 1.2.6.2 bouyer * OPERATION OF AN OVERLAY LAYER
105 1.2.6.2 bouyer *
106 1.2.6.2 bouyer * The operation of an overlay layer is identical to that of a null
107 1.2.6.2 bouyer * layer. See the null layer (and layerfs) documentation for more info.
108 1.2.6.2 bouyer *
109 1.2.6.2 bouyer *
110 1.2.6.2 bouyer * CREATING OTHER FILE SYSTEM LAYERS
111 1.2.6.2 bouyer *
112 1.2.6.2 bouyer * One of the easiest ways to construct new file system layers is to make
113 1.2.6.2 bouyer * a copy of either the null layer or the overlay layer, rename all files
114 1.2.6.2 bouyer * and variables, and then begin modifing the copy. Sed can be used to
115 1.2.6.2 bouyer * easily rename all variables.
116 1.2.6.2 bouyer *
117 1.2.6.2 bouyer * The choice between using a null and an overlay layer depends on
118 1.2.6.2 bouyer * the desirability of retaining access to the underlying filestore.
119 1.2.6.2 bouyer * For instance, the umap filesystem presents both a uid-translated and an
120 1.2.6.2 bouyer * untranslaged view of the underlying files, and so it is based off of
121 1.2.6.2 bouyer * the null layer. However a layer implimenting Access Controll Lists
122 1.2.6.2 bouyer * might prefer to block access to the underlying filestore, for which
123 1.2.6.2 bouyer * the overlay layer is a better basis.
124 1.2.6.2 bouyer *
125 1.2.6.2 bouyer *
126 1.2.6.2 bouyer * INVOKING OPERATIONS ON LOWER LAYERS
127 1.2.6.2 bouyer *
128 1.2.6.2 bouyer * See the null layer documentation.
129 1.2.6.2 bouyer *
130 1.2.6.2 bouyer */
131 1.2.6.2 bouyer
132 1.2.6.2 bouyer #include <sys/param.h>
133 1.2.6.2 bouyer #include <sys/systm.h>
134 1.2.6.2 bouyer #include <sys/proc.h>
135 1.2.6.2 bouyer #include <sys/time.h>
136 1.2.6.2 bouyer #include <sys/types.h>
137 1.2.6.2 bouyer #include <sys/vnode.h>
138 1.2.6.2 bouyer #include <sys/mount.h>
139 1.2.6.2 bouyer #include <sys/namei.h>
140 1.2.6.2 bouyer #include <sys/malloc.h>
141 1.2.6.2 bouyer #include <sys/buf.h>
142 1.2.6.2 bouyer #include <miscfs/genfs/genfs.h>
143 1.2.6.2 bouyer #include <miscfs/overlay/overlay.h>
144 1.2.6.2 bouyer #include <miscfs/genfs/layer_extern.h>
145 1.2.6.2 bouyer
146 1.2.6.2 bouyer /*
147 1.2.6.2 bouyer * Global vfs data structures
148 1.2.6.2 bouyer */
149 1.2.6.2 bouyer int (**overlay_vnodeop_p) __P((void *));
150 1.2.6.2 bouyer struct vnodeopv_entry_desc overlay_vnodeop_entries[] = {
151 1.2.6.2 bouyer { &vop_default_desc, layer_bypass },
152 1.2.6.2 bouyer
153 1.2.6.2 bouyer { &vop_lookup_desc, layer_lookup },
154 1.2.6.2 bouyer { &vop_setattr_desc, layer_setattr },
155 1.2.6.2 bouyer { &vop_getattr_desc, layer_getattr },
156 1.2.6.2 bouyer { &vop_access_desc, layer_access },
157 1.2.6.2 bouyer { &vop_lock_desc, layer_lock },
158 1.2.6.2 bouyer { &vop_unlock_desc, layer_unlock },
159 1.2.6.2 bouyer { &vop_islocked_desc, layer_islocked },
160 1.2.6.2 bouyer { &vop_fsync_desc, layer_fsync },
161 1.2.6.2 bouyer { &vop_inactive_desc, layer_inactive },
162 1.2.6.2 bouyer { &vop_reclaim_desc, layer_reclaim },
163 1.2.6.2 bouyer { &vop_print_desc, layer_print },
164 1.2.6.2 bouyer
165 1.2.6.2 bouyer { &vop_open_desc, layer_open }, /* mount option handling */
166 1.2.6.2 bouyer
167 1.2.6.2 bouyer { &vop_strategy_desc, layer_strategy },
168 1.2.6.2 bouyer { &vop_bwrite_desc, layer_bwrite },
169 1.2.6.2 bouyer { &vop_bmap_desc, layer_bmap },
170 1.2.6.2 bouyer
171 1.2.6.2 bouyer { (struct vnodeop_desc*)NULL, (int(*)__P((void *)))NULL }
172 1.2.6.2 bouyer };
173 1.2.6.2 bouyer struct vnodeopv_desc overlay_vnodeop_opv_desc =
174 1.2.6.2 bouyer { &overlay_vnodeop_p, overlay_vnodeop_entries };
175