1.\" $NetBSD: mount_null.8,v 1.16 2002/03/30 15:28:35 groo Exp $ 2.\" 3.\" Copyright (c) 1992, 1993, 1994 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software donated to Berkeley by 7.\" John Heidemann of the UCLA Ficus project. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the University of 20.\" California, Berkeley and its contributors. 21.\" 4. Neither the name of the University nor the names of its contributors 22.\" may be used to endorse or promote products derived from this software 23.\" without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35.\" SUCH DAMAGE. 36.\" 37.\" @(#)mount_null.8 8.6 (Berkeley) 5/1/95 38.\" 39.\" 40.Dd May 1, 1995 41.Dt MOUNT_NULL 8 42.Os 43.Sh NAME 44.Nm mount_null 45.Nd mount a loopback filesystem sub-tree; 46demonstrate the use of a null file system layer 47.Sh SYNOPSIS 48.Nm 49.Op Fl o Ar options 50.Ar target 51.Ar mount-point 52.Sh DESCRIPTION 53The 54.Nm 55command creates a 56null layer, duplicating a sub-tree of the file system 57name space under another part of the global file system namespace. 58This allows existing files and directories to be accessed 59using a different pathname. 60.Pp 61The primary differences between a virtual copy of the filesystem 62and a symbolic link are that 63.Xr getcwd 3 64functions correctly in the virtual copy, and that other filesystems 65may be mounted on the virtual copy without affecting the original. 66A different device number for the virtual copy is returned by 67.Xr stat 2 , 68but in other respects it is indistinguishable from the original. 69.Pp 70The 71.Nm 72filesystem differs from a traditional 73loopback file system in two respects: it is implemented using 74a stackable layers technique, and its 75.Do 76null-nodes 77.Dc 78stack above 79all lower-layer vnodes (not just above directory vnodes). 80.Pp 81The options are as follows: 82.Bl -tag -width indent 83.It Fl o 84Options are specified with a 85.Fl o 86flag followed by a comma separated string of options. 87See the 88.Xr mount 8 89man page for possible options and their meanings. 90.El 91.Pp 92The null layer has two purposes. 93First, it serves as a demonstration of layering by providing a layer 94which does nothing. 95Second, the null layer can serve as a prototype layer. 96Since it provides all necessary layer framework, 97new file system layers can be created very easily by starting 98with a null layer. 99.Pp 100The remainder of this man page examines the null layer as a basis 101for constructing new layers. 102.\" 103.\" 104.Sh INSTANTIATING NEW NULL LAYERS 105New null layers are created with 106.Nm "" . 107.Nm 108takes two arguments, the pathname 109of the lower vfs (target-pn) and the pathname where the null 110layer will appear in the namespace (mount-point-pn). After 111the null layer is put into place, the contents 112of target-pn subtree will be aliased under mount-point-pn. 113.\" 114.\" 115.Sh OPERATION OF A NULL LAYER 116The null layer is the minimum file system layer, 117simply passing all possible operations to the lower layer 118for processing there. The majority of its activity centers 119on the bypass routine, through which nearly all vnode operations 120pass. 121.Pp 122The bypass routine accepts arbitrary vnode operations for 123handling by the lower layer. It begins by examining vnode 124operation arguments and replacing any null-nodes by their 125lower-layer equivalents. It then invokes the operation 126on the lower layer. Finally, it replaces the null-nodes 127in the arguments and, if a vnode is returned by the operation, 128stacks a null-node on top of the returned vnode. 129.Pp 130Although bypass handles most operations, 131.Em vop_getattr , 132.Em vop_inactive , 133.Em vop_reclaim , 134and 135.Em vop_print 136are not bypassed. 137.Em vop_getattr 138must change the fsid being returned. 139.Em vop_inactive 140and vop_reclaim are not bypassed so that 141they can handle freeing null-layer specific data. 142.Em vop_print 143is not bypassed to avoid excessive debugging 144information. 145.\" 146.\" 147.Sh INSTANTIATING VNODE STACKS 148Mounting associates the null layer with a lower layer, 149in effect stacking two VFSes. Vnode stacks are instead 150created on demand as files are accessed. 151.Pp 152The initial mount creates a single vnode stack for the 153root of the new null layer. All other vnode stacks 154are created as a result of vnode operations on 155this or other null vnode stacks. 156.Pp 157New vnode stacks come into existence as a result of 158an operation which returns a vnode. 159The bypass routine stacks a null-node above the new 160vnode before returning it to the caller. 161.Pp 162For example, imagine mounting a null layer with 163.Bd -literal -offset indent 164mount_null /usr/include /dev/layer/null 165.Ed 166Changing directory to 167.Pa /dev/layer/null 168will assign 169the root null-node (which was created when the null layer was mounted). 170Now consider opening 171.Pa sys . 172A vop_lookup would be 173done on the root null-node. This operation would bypass through 174to the lower layer which would return a vnode representing 175the UFS 176.Pa sys . 177null_bypass then builds a null-node 178aliasing the UFS 179.Pa sys 180and returns this to the caller. 181Later operations on the null-node 182.Pa sys 183will repeat this 184process when constructing other vnode stacks. 185.\" 186.\" 187.Sh CREATING OTHER FILE SYSTEM LAYERS 188One of the easiest ways to construct new file system layers is to make 189a copy of the null layer, rename all files and variables, and 190then begin modifying the copy. 191.Xr sed 1 192can be used to easily rename all variables. 193.Pp 194The umap layer is an example of a layer descended from the 195null layer. 196.\" 197.\" 198.Sh INVOKING OPERATIONS ON LOWER LAYERS 199There are two techniques to invoke operations on a lower layer 200when the operation cannot be completely bypassed. Each method 201is appropriate in different situations. In both cases, 202it is the responsibility of the aliasing layer to make 203the operation arguments "correct" for the lower layer 204by mapping any vnode arguments to the lower layer. 205.Pp 206The first approach is to call the aliasing layer's bypass routine. 207This method is most suitable when you wish to invoke the operation 208currently being handled on the lower layer. It has the advantage 209that the bypass routine already must do argument mapping. 210An example of this is 211.Em null_getattrs 212in the null layer. 213.Pp 214A second approach is to directly invoke vnode operations on 215the lower layer with the 216.Em VOP_OPERATIONNAME 217interface. 218The advantage of this method is that it is easy to invoke 219arbitrary operations on the lower layer. The disadvantage 220is that vnode arguments must be manually mapped. 221.\" 222.\" 223.Sh SEE ALSO 224.Xr mount 8 225.sp 226UCLA Technical Report CSD-910056, 227.Em "Stackable Layers: an Architecture for File System Development" . 228.Sh HISTORY 229The 230.Nm 231utility first appeared in 232.Bx 4.4 . 233