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