xref: /freebsd/sbin/mount_nullfs/mount_nullfs.8 (revision a259b98fa211ed87bfee58c575de4e2de94ee0fa)
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.Dd August 24, 2026
34.Dt MOUNT_NULLFS 8
35.Os
36.Sh NAME
37.Nm mount_nullfs
38.Nd "mount a loopback file system sub-tree; demonstrate the use of a null file system layer"
39.Sh SYNOPSIS
40.Nm
41.Op Fl o Ar options
42.Ar target
43.Ar mount-point
44.Sh DESCRIPTION
45The
46.Nm
47utility creates a
48.Xr nullfs 4
49layer, duplicating a sub-tree of the file system
50name space under another part of the global file system namespace.
51This allows existing files and directories to be accessed
52using a different pathname.
53.Pp
54The primary differences between a virtual copy of the file system
55and a symbolic link are that the
56.Xr getcwd 3
57functions work correctly in the virtual copy, and that other file systems
58may be mounted on the virtual copy without affecting the original.
59A different device number for the virtual copy is returned by
60.Xr stat 2 ,
61but in other respects it is indistinguishable from the original.
62.Pp
63The
64.Nm
65utility supports mounting directories, regular files and
66.Xr unix 4
67sockets.
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 nounixbypass
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.It Cm cache
102Force enable metadata caching.
103.It Cm nounixbypass
104Disable bypassing
105.Xr unix 4
106socket files used for
107.Xr bind 2
108and
109.Xr connect 2 ,
110to the lower (mounted-from) filesystem layer.
111.Pp
112The effect is that lower and upper (bypassed) unix sockets
113are separate.
114.It Cm unixbypass
115Enable the bypass of unix socket file to lower filesystem layer.
116This is default.
117.Pp
118The effect is that
119.Xr bind 2
120and
121.Xr connect 2
122operations on a unix socket done from either the upper (nullfs) or lower
123layer path are performed on same unix socket.
124For instance, if a server
125.Xr bind 2
126is done on a socket in the lower layer, then
127.Xr connect 2
128on the socket file accessed via the nullfs mount, connects to the server.
129.El
130.El
131.Pp
132The
133.Dv vfs.nullfs.cache_vnodes
134sysctl specifies global default for mount-specific cache/nocache option.
135.Pp
136The null layer has two purposes.
137First, it serves as a demonstration of layering by providing a layer
138which does nothing.
139(It actually does everything the loopback file system does,
140which is slightly more than nothing.)
141Second, the null layer can serve as a prototype layer.
142Since it provides all necessary layer framework,
143new file system layers can be created very easily by starting
144with a null layer.
145.Pp
146The remainder of this man page examines the null layer as a basis
147for constructing new layers.
148.\"
149.\"
150.Sh INSTANTIATING NEW NULL LAYERS
151New null layers are created with
152.Nm .
153The
154.Nm
155utility takes two arguments, the pathname
156of the lower vfs (target-pn) and the pathname where the null
157layer will appear in the namespace (mount-point-pn).
158After
159the null layer is put into place, the contents
160of target-pn subtree will be aliased under mount-point-pn.
161.\"
162.\"
163.Sh OPERATION OF A NULL LAYER
164The null layer is the minimum file system layer,
165simply bypassing all possible operations to the lower layer
166for processing there.
167The majority of its activity centers
168on the bypass routine, through which nearly all vnode operations
169pass.
170.Pp
171The bypass routine accepts arbitrary vnode operations for
172handling by the lower layer.
173It begins by examining vnode
174operation arguments and replacing any null-nodes by their
175lower-layer equivalents.
176It then invokes the operation
177on the lower layer.
178Finally, it replaces the null-nodes
179in the arguments and, if a vnode is returned by the operation,
180stacks a null-node on top of the returned vnode.
181.Pp
182Although bypass handles most operations,
183.Em vop_getattr ,
184.Em vop_inactive ,
185.Em vop_reclaim ,
186and
187.Em vop_print
188are not bypassed.
189.Em Vop_getattr
190must change the fsid being returned.
191.Em Vop_inactive
192and
193.Em vop_reclaim
194are not bypassed so that
195they can handle freeing null-layer specific data.
196.Em Vop_print
197is not bypassed to avoid excessive debugging
198information.
199.\"
200.\"
201.Sh INSTANTIATING VNODE STACKS
202Mounting associates the null layer with a lower layer,
203in effect stacking two VFSes.
204Vnode stacks are instead
205created on demand as files are accessed.
206.Pp
207The initial mount creates a single vnode stack for the
208root of the new null layer.
209All other vnode stacks
210are created as a result of vnode operations on
211this or other null vnode stacks.
212.Pp
213New vnode stacks come into existence as a result of
214an operation which returns a vnode.
215The bypass routine stacks a null-node above the new
216vnode before returning it to the caller.
217.Pp
218For example, imagine mounting a null layer with
219.Bd -literal -offset indent
220mount_nullfs /usr/include /dev/layer/null
221.Ed
222.Pp
223Changing directory to
224.Pa /dev/layer/null
225will assign
226the root null-node (which was created when the null layer was mounted).
227Now consider opening
228.Pa sys .
229A vop_lookup would be
230done on the root null-node.
231This operation would bypass through
232to the lower layer which would return a vnode representing
233the UFS
234.Pa sys .
235Null_bypass then builds a null-node
236aliasing the UFS
237.Pa sys
238and returns this to the caller.
239Later operations on the null-node
240.Pa sys
241will repeat this
242process when constructing other vnode stacks.
243.\"
244.\"
245.Sh CREATING OTHER FILE SYSTEM LAYERS
246One of the easiest ways to construct new file system layers is to make
247a copy of the null layer, rename all files and variables, and
248then begin modifying the copy.
249The
250.Xr sed 1
251utility can be used to easily rename
252all variables.
253.Pp
254The umap layer is an example of a layer descended from the
255null layer.
256.\"
257.\"
258.Sh INVOKING OPERATIONS ON LOWER LAYERS
259There are two techniques to invoke operations on a lower layer
260when the operation cannot be completely bypassed.
261Each method
262is appropriate in different situations.
263In both cases,
264it is the responsibility of the aliasing layer to make
265the operation arguments "correct" for the lower layer
266by mapping a vnode argument to the lower layer.
267.Pp
268The first approach is to call the aliasing layer's bypass routine.
269This method is most suitable when you wish to invoke the operation
270currently being handled on the lower layer.
271It has the advantage that
272the bypass routine already must do argument mapping.
273An example of this is
274.Em null_getattrs
275in the null layer.
276.Pp
277A second approach is to directly invoke vnode operations on
278the lower layer with the
279.Em VOP_OPERATIONNAME
280interface.
281The advantage of this method is that it is easy to invoke
282arbitrary operations on the lower layer.
283The disadvantage
284is that vnode arguments must be manually mapped.
285.\"
286.\"
287.Sh SEE ALSO
288.Xr nullfs 4 ,
289.Xr mount 8
290.Pp
291UCLA Technical Report CSD-910056,
292.Em "Stackable Layers: an Architecture for File System Development" .
293.Sh HISTORY
294The
295.Nm mount_null
296utility first appeared in
297.Bx 4.4 .
298It was renamed to
299.Nm
300in
301.Fx 5.0 .
302