xref: /freebsd/sbin/mount_nullfs/mount_nullfs.8 (revision 690b7ea081790eef2c890f63a4fe7e195cf51df0)
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. 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 April 22, 2022
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.
83Additionally the following option is supported:
84.Bl -tag -width indent
85.It Cm nocache
86Disable caching in the null layer.
87Some lower-layer file systems may force this option.
88.El
89.El
90.Pp
91The null layer has two purposes.
92First, it serves as a demonstration of layering by providing a layer
93which does nothing.
94(It actually does everything the loopback file system does,
95which is slightly more than nothing.)
96Second, the null layer can serve as a prototype layer.
97Since it provides all necessary layer framework,
98new file system layers can be created very easily by starting
99with a null layer.
100.Pp
101The remainder of this man page examines the null layer as a basis
102for constructing new layers.
103.\"
104.\"
105.Sh INSTANTIATING NEW NULL LAYERS
106New null layers are created with
107.Nm .
108The
109.Nm
110utility takes two arguments, the pathname
111of the lower vfs (target-pn) and the pathname where the null
112layer will appear in the namespace (mount-point-pn).
113After
114the null layer is put into place, the contents
115of target-pn subtree will be aliased under mount-point-pn.
116.\"
117.\"
118.Sh OPERATION OF A NULL LAYER
119The null layer is the minimum file system layer,
120simply bypassing all possible operations to the lower layer
121for processing there.
122The majority of its activity centers
123on the bypass routine, through which nearly all vnode operations
124pass.
125.Pp
126The bypass routine accepts arbitrary vnode operations for
127handling by the lower layer.
128It begins by examining vnode
129operation arguments and replacing any null-nodes by their
130lower-layer equivalents.
131It then invokes the operation
132on the lower layer.
133Finally, it replaces the null-nodes
134in the arguments and, if a vnode is returned by the operation,
135stacks a null-node on top of the returned vnode.
136.Pp
137Although bypass handles most operations,
138.Em vop_getattr ,
139.Em vop_inactive ,
140.Em vop_reclaim ,
141and
142.Em vop_print
143are not bypassed.
144.Em Vop_getattr
145must change the fsid being returned.
146.Em Vop_inactive
147and
148.Em vop_reclaim
149are not bypassed so that
150they can handle freeing null-layer specific data.
151.Em Vop_print
152is not bypassed to avoid excessive debugging
153information.
154.\"
155.\"
156.Sh INSTANTIATING VNODE STACKS
157Mounting associates the null layer with a lower layer,
158in effect stacking two VFSes.
159Vnode stacks are instead
160created on demand as files are accessed.
161.Pp
162The initial mount creates a single vnode stack for the
163root of the new null layer.
164All other vnode stacks
165are created as a result of vnode operations on
166this or other null vnode stacks.
167.Pp
168New vnode stacks come into existence as a result of
169an operation which returns a vnode.
170The bypass routine stacks a null-node above the new
171vnode before returning it to the caller.
172.Pp
173For example, imagine mounting a null layer with
174.Bd -literal -offset indent
175mount_nullfs /usr/include /dev/layer/null
176.Ed
177.Pp
178Changing directory to
179.Pa /dev/layer/null
180will assign
181the root null-node (which was created when the null layer was mounted).
182Now consider opening
183.Pa sys .
184A vop_lookup would be
185done on the root null-node.
186This operation would bypass through
187to the lower layer which would return a vnode representing
188the UFS
189.Pa sys .
190Null_bypass then builds a null-node
191aliasing the UFS
192.Pa sys
193and returns this to the caller.
194Later operations on the null-node
195.Pa sys
196will repeat this
197process when constructing other vnode stacks.
198.\"
199.\"
200.Sh CREATING OTHER FILE SYSTEM LAYERS
201One of the easiest ways to construct new file system layers is to make
202a copy of the null layer, rename all files and variables, and
203then begin modifying the copy.
204The
205.Xr sed 1
206utility can be used to easily rename
207all variables.
208.Pp
209The umap layer is an example of a layer descended from the
210null layer.
211.\"
212.\"
213.Sh INVOKING OPERATIONS ON LOWER LAYERS
214There are two techniques to invoke operations on a lower layer
215when the operation cannot be completely bypassed.
216Each method
217is appropriate in different situations.
218In both cases,
219it is the responsibility of the aliasing layer to make
220the operation arguments "correct" for the lower layer
221by mapping a vnode argument to the lower layer.
222.Pp
223The first approach is to call the aliasing layer's bypass routine.
224This method is most suitable when you wish to invoke the operation
225currently being handled on the lower layer.
226It has the advantage that
227the bypass routine already must do argument mapping.
228An example of this is
229.Em null_getattrs
230in the null layer.
231.Pp
232A second approach is to directly invoke vnode operations on
233the lower layer with the
234.Em VOP_OPERATIONNAME
235interface.
236The advantage of this method is that it is easy to invoke
237arbitrary operations on the lower layer.
238The disadvantage
239is that vnode arguments must be manually mapped.
240.\"
241.\"
242.Sh SEE ALSO
243.Xr mount 8
244.Pp
245UCLA Technical Report CSD-910056,
246.Em "Stackable Layers: an Architecture for File System Development" .
247.Sh HISTORY
248The
249.Nm mount_null
250utility first appeared in
251.Bx 4.4 .
252It was renamed to
253.Nm
254in
255.Fx 5.0 .
256