xref: /dragonfly/sbin/mount_null/mount_null.8 (revision e293de53)
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. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"	This product includes software developed by the University of
20.\"	California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\"    may be used to endorse or promote products derived from this software
23.\"    without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
36.\"
37.\"     @(#)mount_null.8	8.6 (Berkeley) 5/1/95
38.\" $FreeBSD: src/sbin/mount_null/mount_null.8,v 1.11.2.6 2001/12/20 16:40:00 ru Exp $
39.\" $DragonFly: src/sbin/mount_null/mount_null.8,v 1.8 2008/10/26 00:05:24 swildner Exp $
40.\"
41.Dd September 28, 2008
42.Dt MOUNT_NULL 8
43.Os
44.Sh NAME
45.Nm mount_null
46.Nd "mount a loopback filesystem sub-tree; demonstrate the use of a null file system layer"
47.Sh SYNOPSIS
48.Nm
49.Op Fl o Ar options
50.Ar target
51.Ar mount-point
52.Sh DESCRIPTION
53The
54.Nm
55command creates a
56null layer, duplicating a sub-tree of the file system
57name space under another part of the global file system namespace.
58This allows existing files and directories to be accessed
59using a different pathname.
60.Pp
61The primary differences between a virtual copy of the filesystem
62and a symbolic link are that the
63.Xr getcwd 3
64functions work correctly in the virtual copy, and that other filesystems
65may be mounted on the virtual copy without affecting the original.
66A different device number for the virtual copy is returned by
67.Xr stat 2 ,
68but in other respects it is indistinguishable from the original.
69.Pp
70The
71.Nm null
72filesystem differs from a traditional
73loopback file system in two respects: it is implemented using
74a stackable layers techniques, and its
75.Do null-node Dc Ns s
76stack above
77all lower-layer vnodes, not just over directory vnodes.
78.Pp
79The options are as follows:
80.Bl -tag -width indent
81.It Fl o
82Options are specified with a
83.Fl o
84flag followed by a comma separated string of options.
85See the
86.Xr mount 8
87man page for possible options and their meanings.
88.El
89.Pp
90The null layer has three purposes.
91First, it serves as a demonstration of layering by providing a layer
92which does nothing.
93(It actually does everything the loopback file system does,
94which is slightly more than nothing.)
95Second, it is used for NFS exporting
96.Nm HAMMER
97PFSs.
98Third, the null layer can serve as a prototype layer.
99Since it provides all necessary layer framework,
100new file system layers can be created very easily by starting
101with a null layer.
102.Pp
103The remainder of this man page examines the null layer as a basis
104for constructing new layers.
105.\"
106.\"
107.Sh INSTANTIATING NEW NULL LAYERS
108New null layers are created with
109.Nm .
110.Nm Mount_null
111takes two arguments, the pathname
112of the lower vfs (target-pn) and the pathname where the null
113layer will appear in the namespace (mount-point-pn).  After
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.  The majority of its activity centers
122on the bypass routine, through which nearly all vnode operations
123pass.
124.Pp
125The bypass routine accepts arbitrary vnode operations for
126handling by the lower layer.  It begins by examining vnode
127operation arguments and replacing any null-nodes by their
128lower-layer equivalents.  It then invokes the operation
129on the lower layer.  Finally, it replaces the null-nodes
130in the arguments and, if a vnode is returned by the operation,
131stacks a null-node on top of the returned vnode.
132.Pp
133Although bypass handles most operations,
134.Em vop_getattr ,
135.Em vop_inactive ,
136.Em vop_reclaim ,
137and
138.Em vop_print
139are not bypassed.
140.Em Vop_getattr
141must change the fsid being returned.
142.Em Vop_inactive
143and
144.Em vop_reclaim
145are not bypassed so that
146they can handle freeing null-layer specific data.
147.Em Vop_print
148is not bypassed to avoid excessive debugging
149information.
150.\"
151.\"
152.Sh INSTANTIATING VNODE STACKS
153Mounting associates the null layer with a lower layer,
154in effect stacking two VFSes.  Vnode stacks are instead
155created on demand as files are accessed.
156.Pp
157The initial mount creates a single vnode stack for the
158root of the new null layer.  All other vnode stacks
159are created as a result of vnode operations on
160this or other null vnode stacks.
161.Pp
162New vnode stacks come into existence as a result of
163an operation which returns a vnode.
164The bypass routine stacks a null-node above the new
165vnode before returning it to the caller.
166.Pp
167For example, imagine mounting a null layer with
168.Bd -literal -offset indent
169mount_null /usr/include /dev/layer/null
170.Ed
171.Pp
172Changing directory to
173.Pa /dev/layer/null
174will assign
175the root null-node (which was created when the null layer was mounted).
176Now consider opening
177.Pa sys .
178A
179.Em vop_lookup
180would be
181done on the root null-node.  This operation would bypass through
182to the lower layer which would return a vnode representing
183the
184.Xr UFS 5
185.Pa sys
186(assuming that the lower layer is an
187.Xr UFS 5
188file system).
189Null_bypass then builds a null-node
190aliasing the
191.Xr UFS 5
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.
204.Xr Sed 1
205can be used to easily rename
206all variables.
207.\"
208.\"
209.Sh INVOKING OPERATIONS ON LOWER LAYERS
210There are two techniques to invoke operations on a lower layer
211when the operation cannot be completely bypassed.  Each method
212is appropriate in different situations.  In both cases,
213it is the responsibility of the aliasing layer to make
214the operation arguments "correct" for the lower layer
215by mapping a vnode argument to the lower layer.
216.Pp
217The first approach is to call the aliasing layer's bypass routine.
218This method is most suitable when you wish to invoke the operation
219currently being handled on the lower layer.
220It has the advantage that
221the bypass routine already must do argument mapping.
222An example of this is
223.Em null_getattrs
224in the null layer.
225.Pp
226A second approach is to directly invoke vnode operations on
227the lower layer with the
228.Em VOP_OPERATIONNAME
229interface.
230The advantage of this method is that it is easy to invoke
231arbitrary operations on the lower layer.  The disadvantage
232is that vnode arguments must be manually mapped.
233.\"
234.\"
235.Sh SEE ALSO
236.Xr HAMMER 5 ,
237.Xr mount 8
238.Pp
239UCLA Technical Report CSD-910056,
240.Em "Stackable Layers: an Architecture for File System Development" .
241.Sh HISTORY
242The
243.Nm
244utility first appeared in
245.Bx 4.4 .
246.An Matthew Dillon
247made
248.Nm
249work in
250.Dx 1.7 ,
251after it had been broken for some time.
252