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