154841Sheideman.\"
262955Sbostic.\" Copyright (c) 1992, 1993
362955Sbostic.\"	The Regents of the University of California.  All rights reserved.
454841Sheideman.\"
554841Sheideman.\" This code is derived from software donated to Berkeley by
654953Sheideman.\" John Heidemann of the UCLA Ficus project.
754841Sheideman.\"
854841Sheideman.\"
954841Sheideman.\" %sccs.include.redist.roff%
1054841Sheideman.\"
11*65103Smckusick.\"     @(#)mount_null.8	8.2 (Berkeley) 12/11/93
1254841Sheideman.\"
1354841Sheideman.\"
1454841Sheideman.Dd
1554841Sheideman.Dt MOUNT_NULL 8
1654841Sheideman.Os BSD 4.4
1754841Sheideman.Sh NAME
1854841Sheideman.Nm mount_null
1954953Sheideman.Nd demonstrate the use of a null file system layer
2054841Sheideman.Sh SYNOPSIS
2154841Sheideman.Nm mount_null
2254841Sheideman.Op Fl F Ar fsoptions
2354841Sheideman.Ar target mount-point
2454953Sheideman.\"
2554953Sheideman.\"
2654841Sheideman.Sh DESCRIPTION
2754841SheidemanThe
2854841Sheideman.Nm mount_null
2954953Sheidemancommand creates a
3054953Sheidemannull layer, duplicating a sub-tree of the file system
3154953Sheidemanname space under another part of the global file system namespace.
3254953SheidemanIn this respect, it is
3354953Sheidemansimilar to the loopback file system (see
3454953Sheideman.Xr mount_lofs 8 ) .
3554953SheidemanIt differs from
3654953Sheidemanthe loopback file system in two respects:  it is implemented using
3754953Sheidemana stackable layers techniques, and it's
3854953Sheideman.Do
3954953Sheidemannull-node
4054953Sheideman.Dc s
4154953Sheidemanstack above
4254953Sheidemanall lower-layer vnodes, not just over directory vnodes.
4354841Sheideman.Pp
4454953SheidemanThe null layer has two purposes.  First, it serves as a demonstration
4554953Sheidemanof layering by proving a layer which does nothing.  (It actually
4654953Sheidemandoes everything the loopback file system does, which is slightly
4754953Sheidemanmore than nothing.)  Second, the null layer can serve as a prototype
4854953Sheidemanlayer.  Since it provides all necessary layer framework,
4954953Sheidemannew file system layers can be created very easily be starting
5054953Sheidemanwith a null layer.
5154841Sheideman.Pp
5254953SheidemanThe remainder of this man page examines the null layer as a basis
5354953Sheidemanfor constructing new layers.
5454953Sheideman.\"
5554953Sheideman.\"
5654953Sheideman.Sh INSTANTIATING NEW NULL LAYERS
5754953SheidemanNew null layers are created with
5854953Sheideman.Xr mount_null 8 .
5954953Sheideman.Xr Mount_null 8
6054953Sheidemantakes two arguments, the pathname
6154953Sheidemanof the lower vfs (target-pn) and the pathname where the null
6254953Sheidemanlayer will appear in the namespace (mount-point-pn).  After
6354953Sheidemanthe null layer is put into place, the contents
6454953Sheidemanof target-pn subtree will be aliased under mount-point-pn.
6554953Sheideman.\"
6654953Sheideman.\"
6754953Sheideman.Sh OPERATION OF A NULL LAYER
6854953SheidemanThe null layer is the minimum file system layer,
6954953Sheidemansimply bypassing all possible operations to the lower layer
7054953Sheidemanfor processing there.  The majority of its activity centers
7154953Sheidemanon the bypass routine, though which nearly all vnode operations
7254953Sheidemanpass.
7354953Sheideman.Pp
7454953SheidemanThe bypass routine accepts arbitrary vnode operations for
7554953Sheidemanhandling by the lower layer.  It begins by examing vnode
7654953Sheidemanoperation arguments and replacing any null-nodes by their
77*65103Smckusicklower-layer equivalants.  It then invokes the operation
7854953Sheidemanon the lower layer.  Finally, it replaces the null-nodes
79*65103Smckusickin the arguments and, if a vnode is returned by the operation,
8054953Sheidemanstacks a null-node on top of the returned vnode.
8154953Sheideman.Pp
8254953SheidemanAlthough bypass handles most operations,
8354953Sheideman.Em vop_getattr ,
8454953Sheideman.Em vop_inactive ,
8554953Sheideman.Em vop_reclaim ,
8654953Sheidemanand
8754953Sheideman.Em vop_print
8854953Sheidemanare not bypassed.
8954953Sheideman.Em Vop_getattr
9054953Sheidemanmust change the fsid being returned.
9154953Sheideman.Em Vop_inactive
9254953Sheidemanand vop_reclaim are not bypassed so that
9354953Sheidemanthey can handle freeing null-layer specific data.
9454953Sheideman.Em Vop_print
9554953Sheidemanis not bypassed to avoid excessive debugging
9654953Sheidemaninformation.
9754953Sheideman.\"
9854953Sheideman.\"
9954953Sheideman.Sh INSTANTIATING VNODE STACKS
10054953SheidemanMounting associates the null layer with a lower layer,
10154953Sheidemanin effect stacking two VFSes.  Vnode stacks are instead
10254953Sheidemancreated on demand as files are accessed.
10354953Sheideman.Pp
10454953SheidemanThe initial mount creates a single vnode stack for the
10554953Sheidemanroot of the new null layer.  All other vnode stacks
10654953Sheidemanare created as a result of vnode operations on
10754953Sheidemanthis or other null vnode stacks.
10854953Sheideman.Pp
10954953SheidemanNew vnode stacks come into existance as a result of
11054953Sheidemanan operation which returns a vnode.
11154953SheidemanThe bypass routine stacks a null-node above the new
11254953Sheidemanvnode before returning it to the caller.
11354953Sheideman.Pp
11454953SheidemanFor example, imagine mounting a null layer with
11554953Sheideman.Bd -literal -offset indent
11654953Sheidemanmount_null /usr/include /dev/layer/null
11754953Sheideman.Ed
11854953SheidemanChainging directory to
11954953Sheideman.Pa /dev/layer/null
12054953Sheidemanwill assign
12154953Sheidemanthe root null-node (which was created when the null layer was mounted).
12254953SheidemanNow consider opening
12354953Sheideman.Pa sys .
12454953SheidemanA vop_lookup would be
12554953Sheidemandone on the root null-node.  This operation would bypass through
12654953Sheidemanto the lower layer which would return a vnode representing
12754953Sheidemanthe UFS
12854953Sheideman.Pa sys .
12954953SheidemanNull_bypass then builds a null-node
13054953Sheidemanaliasing the UFS
13154953Sheideman.Pa sys
13254953Sheidemanand returns this to the caller.
13354953SheidemanLater operations on the null-node
13454953Sheideman.Pa sys
13554953Sheidemanwill repeat this
13654953Sheidemanprocess when constructing other vnode stacks.
13754953Sheideman.\"
13854953Sheideman.\"
13954953Sheideman.Sh CREATING OTHER FILE SYSTEM LAYERS
14054953SheidemanOne of the easiest ways to construct new file system layers is to make
14154953Sheidemana copy of the null layer, rename all files and variables, and
14254953Sheidemanthen begin modifing the copy.  Sed can be used to easily rename
14354953Sheidemanall variables.
14454953Sheideman.Pp
14554953SheidemanThe umap layer is an example of a layer descended from the
14654953Sheidemannull layer.
14754953Sheideman.\"
14854953Sheideman.\"
14954953Sheideman.Sh INVOKING OPERATIONS ON LOWER LAYERS
15054953SheidemanThere are two techniques to invoke operations on a lower layer
15154953Sheidemanwhen the operation cannot be completely bypassed.  Each method
15254953Sheidemanis appropriate in different situations.  In both cases,
15354953Sheidemanit is the responsibility of the aliasing layer to make
15454953Sheidemanthe operation arguments "correct" for the lower layer
15554953Sheidemanby mapping an vnode arguments to the lower layer.
15654953Sheideman.Pp
15754953SheidemanThe first approach is to call the aliasing layer's bypass routine.
15854953SheidemanThis method is most suitable when you wish to invoke the operation
159*65103Smckusickcurrently being handled on the lower layer.  It has the advantage
16054953Sheidemanthe the bypass routine already must do argument mapping.
16154953SheidemanAn example of this is
16254953Sheideman.Em null_getattrs
16354953Sheidemanin the null layer.
16454953Sheideman.Pp
16554953SheidemanA second approach is to directly invoked vnode operations on
16654953Sheidemanthe lower layer with the
16754953Sheideman.Em VOP_OPERATIONNAME
16854953Sheidemaninterface.
16954953SheidemanThe advantage of this method is that it is easy to invoke
17054953Sheidemanarbitrary operations on the lower layer.  The disadvantage
17154953Sheidemanis that vnodes arguments must be manualy mapped.
17254953Sheideman.\"
17354953Sheideman.\"
17454953Sheideman.Sh SEE ALSO
17554953SheidemanUCLA Technical Report CSD-910056,
17654953Sheideman.Em "Stackable Layers: an Architecture for File System Development" .
17754841Sheideman.Sh HISTORY
17854841SheidemanThe
17962954Sbostic.Nm mount_null
18062954Sbosticutility first appeared in 4.4BSD.
181