xref: /netbsd/sys/miscfs/overlay/overlay_vnops.c (revision bf9ec67e)
1 /*	$NetBSD: overlay_vnops.c,v 1.9 2002/01/04 07:19:34 chs Exp $	*/
2 
3 /*
4  * Copyright (c) 1999, 2000 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
37  *	The Regents of the University of California.  All rights reserved.
38  *
39  * This code is derived from software contributed to Berkeley by
40  * John Heidemann of the UCLA Ficus project.
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  *	@(#)null_vnops.c	8.6 (Berkeley) 5/27/95
71  *
72  * Ancestors:
73  *	@(#)lofs_vnops.c	1.2 (Berkeley) 6/18/92
74  *	$Id: overlay_vnops.c,v 1.9 2002/01/04 07:19:34 chs Exp $
75  *	...and...
76  *	@(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
77  */
78 
79 /*
80  * Overlay Layer
81  *
82  * (See mount_overlay(8) for more information.)
83  *
84  * The overlay layer has two purposes.  First, it serves as a demonstration
85  * of layering by providing a layer which really does nothing (the null
86  * layer makes the underlying files appear elsewhere in the file hierarchy).
87  * Second, the overlay layer can serve as a prototype layer. Since it
88  * provides all necessary layer framework, new file system layers can be
89  * created very easily by starting with an overlay layer.
90  *
91  * The remainder of this comment examines the overlay layer as a basis
92  * for constructing new layers.
93  *
94  *
95  * INSTANTIATING NEW OVERLAY LAYERS
96  *
97  * New overlay layers are created with mount_overlay(8).
98  * mount_overlay(8) takes two arguments, an ignored string
99  * and the pathname which the overlay will mount over. After
100  * the overlay layer is put into place, all access to the mount
101  * point path will proceed through the overlay layer.
102  *
103  *
104  * OPERATION OF AN OVERLAY LAYER
105  *
106  * The operation of an overlay layer is identical to that of a null
107  * layer. See the null layer (and layerfs) documentation for more info.
108  *
109  *
110  * CREATING OTHER FILE SYSTEM LAYERS
111  *
112  * One of the easiest ways to construct new file system layers is to make
113  * a copy of either the null layer or the overlay layer, rename all files
114  * and variables, and then begin modifying the copy.  sed(1) can be used to
115  * easily rename all variables.
116  *
117  * The choice between using a null and an overlay layer depends on
118  * the desirability of retaining access to the underlying filestore.
119  * For instance, the umap filesystem presents both a uid-translated and an
120  * untranslated view of the underlying files, and so it is based off of
121  * the null layer. However a layer implementing Access Control Lists
122  * might prefer to block access to the underlying filestore, for which
123  * the overlay layer is a better basis.
124  *
125  *
126  * INVOKING OPERATIONS ON LOWER LAYERS
127  *
128  * See the null layer documentation.
129  *
130  */
131 
132 #include <sys/cdefs.h>
133 __KERNEL_RCSID(0, "$NetBSD: overlay_vnops.c,v 1.9 2002/01/04 07:19:34 chs Exp $");
134 
135 #include <sys/param.h>
136 #include <sys/systm.h>
137 #include <sys/proc.h>
138 #include <sys/time.h>
139 #include <sys/vnode.h>
140 #include <sys/mount.h>
141 #include <sys/namei.h>
142 #include <sys/malloc.h>
143 #include <sys/buf.h>
144 #include <miscfs/genfs/genfs.h>
145 #include <miscfs/overlay/overlay.h>
146 #include <miscfs/genfs/layer_extern.h>
147 
148 /*
149  * Global vfs data structures
150  */
151 int (**overlay_vnodeop_p) __P((void *));
152 const struct vnodeopv_entry_desc overlay_vnodeop_entries[] = {
153 	{ &vop_default_desc,  layer_bypass },
154 
155 	{ &vop_lookup_desc,   layer_lookup },
156 	{ &vop_setattr_desc,  layer_setattr },
157 	{ &vop_getattr_desc,  layer_getattr },
158 	{ &vop_access_desc,   layer_access },
159 	{ &vop_lock_desc,     layer_lock },
160 	{ &vop_unlock_desc,   layer_unlock },
161 	{ &vop_islocked_desc, layer_islocked },
162 	{ &vop_fsync_desc,    layer_fsync },
163 	{ &vop_inactive_desc, layer_inactive },
164 	{ &vop_reclaim_desc,  layer_reclaim },
165 	{ &vop_print_desc,    layer_print },
166 
167 	{ &vop_open_desc,     layer_open },	/* mount option handling */
168 
169 	{ &vop_strategy_desc, layer_strategy },
170 	{ &vop_bwrite_desc,   layer_bwrite },
171 	{ &vop_bmap_desc,     layer_bmap },
172 	{ &vop_getpages_desc, layer_getpages },
173 	{ &vop_putpages_desc, layer_putpages },
174 
175 	{ NULL, NULL }
176 };
177 const struct vnodeopv_desc overlay_vnodeop_opv_desc =
178 	{ &overlay_vnodeop_p, overlay_vnodeop_entries };
179