xref: /netbsd/sys/miscfs/overlay/overlay_vnops.c (revision b9c1fd7f)
1 /*	$NetBSD: overlay_vnops.c,v 1.25 2020/05/16 18:31:51 christos 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. Neither the name of the University nor the names of its contributors
51  *    may be used to endorse or promote products derived from this software
52  *    without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  *
66  *	@(#)null_vnops.c	8.6 (Berkeley) 5/27/95
67  *
68  * Ancestors:
69  *	@(#)lofs_vnops.c	1.2 (Berkeley) 6/18/92
70  *	$Id: overlay_vnops.c,v 1.25 2020/05/16 18:31:51 christos Exp $
71  *	...and...
72  *	@(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
73  */
74 
75 /*
76  * Overlay Layer
77  *
78  * (See mount_overlay(8) for more information.)
79  *
80  * The overlay layer has two purposes.  First, it serves as a demonstration
81  * of layering by providing a layer which really does nothing (the null
82  * layer makes the underlying files appear elsewhere in the file hierarchy).
83  * Second, the overlay layer can serve as a prototype layer. Since it
84  * provides all necessary layer framework, new file system layers can be
85  * created very easily by starting with an overlay layer.
86  *
87  * The remainder of this comment examines the overlay layer as a basis
88  * for constructing new layers.
89  *
90  *
91  * INSTANTIATING NEW OVERLAY LAYERS
92  *
93  * New overlay layers are created with mount_overlay(8).
94  * mount_overlay(8) takes two arguments, an ignored string
95  * and the pathname which the overlay will mount over. After
96  * the overlay layer is put into place, all access to the mount
97  * point path will proceed through the overlay layer.
98  *
99  *
100  * OPERATION OF AN OVERLAY LAYER
101  *
102  * The operation of an overlay layer is identical to that of a null
103  * layer. See the null layer (and layerfs) documentation for more info.
104  *
105  *
106  * CREATING OTHER FILE SYSTEM LAYERS
107  *
108  * One of the easiest ways to construct new file system layers is to make
109  * a copy of either the null layer or the overlay layer, rename all files
110  * and variables, and then begin modifying the copy.  sed(1) can be used to
111  * easily rename all variables.
112  *
113  * The choice between using a null and an overlay layer depends on
114  * the desirability of retaining access to the underlying filestore.
115  * For instance, the umap filesystem presents both a uid-translated and an
116  * untranslated view of the underlying files, and so it is based off of
117  * the null layer. However a layer implementing Access Control Lists
118  * might prefer to block access to the underlying filestore, for which
119  * the overlay layer is a better basis.
120  *
121  *
122  * INVOKING OPERATIONS ON LOWER LAYERS
123  *
124  * See the null layer documentation.
125  *
126  */
127 
128 #include <sys/cdefs.h>
129 __KERNEL_RCSID(0, "$NetBSD: overlay_vnops.c,v 1.25 2020/05/16 18:31:51 christos Exp $");
130 
131 #include <sys/param.h>
132 #include <sys/systm.h>
133 #include <sys/proc.h>
134 #include <sys/time.h>
135 #include <sys/vnode.h>
136 #include <sys/mount.h>
137 #include <sys/namei.h>
138 #include <sys/buf.h>
139 #include <miscfs/genfs/genfs.h>
140 #include <miscfs/overlay/overlay.h>
141 #include <miscfs/genfs/layer_extern.h>
142 
143 /*
144  * Global vfs data structures
145  */
146 int (**overlay_vnodeop_p)(void *);
147 const struct vnodeopv_entry_desc overlay_vnodeop_entries[] = {
148 	{ &vop_default_desc,  layer_bypass },
149 
150 	{ &vop_lookup_desc,   layer_lookup },
151 	{ &vop_setattr_desc,  layer_setattr },
152 	{ &vop_getattr_desc,  layer_getattr },
153 	{ &vop_access_desc,   layer_access },
154 	{ &vop_accessx_desc,  genfs_accessx },
155 	{ &vop_fsync_desc,    layer_fsync },
156 	{ &vop_inactive_desc, layer_inactive },
157 	{ &vop_reclaim_desc,  layer_reclaim },
158 	{ &vop_print_desc,    layer_print },
159 	{ &vop_remove_desc,   layer_remove },
160 	{ &vop_rename_desc,   layer_rename },
161 	{ &vop_revoke_desc,   layer_revoke },
162 	{ &vop_rmdir_desc,    layer_rmdir },
163 
164 	{ &vop_open_desc,     layer_open },	/* mount option handling */
165 	{ &vop_close_desc,    layer_close },
166 
167 	{ &vop_bmap_desc,     layer_bmap },
168 	{ &vop_getpages_desc, layer_getpages },
169 	{ &vop_putpages_desc, layer_putpages },
170 
171 	{ NULL, NULL }
172 };
173 const struct vnodeopv_desc overlay_vnodeop_opv_desc =
174 	{ &overlay_vnodeop_p, overlay_vnodeop_entries };
175