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