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