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