xref: /netbsd-src/sbin/mount_null/mount_null.8 (revision eceb233b9bd0dfebb902ed73b531ae6964fa3f9b)
1.\"	$NetBSD: mount_null.8,v 1.21 2005/01/31 05:19:19 erh Exp $
2.\"
3.\" Copyright (c) 1992, 1993, 1994
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software donated to Berkeley by
7.\" John Heidemann of the UCLA Ficus project.
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.\"
35.\"
36.Dd May 1, 1995
37.Dt MOUNT_NULL 8
38.Os
39.Sh NAME
40.Nm mount_null
41.Nd mount a loopback filesystem sub-tree;
42demonstrate the use of a null file system layer
43.Sh SYNOPSIS
44.Nm
45.Op Fl o Ar options
46.Ar target
47.Ar mount-point
48.Sh DESCRIPTION
49The
50.Nm
51command creates a
52null layer, 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 filesystem
58and a symbolic link are that
59.Xr getcwd 3
60functions correctly in the virtual copy, and that other filesystems
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
68filesystem differs from a traditional
69loopback file system in two respects: it is implemented using
70a stackable layers technique, and its
71.Do
72null-nodes
73.Dc
74stack above
75all lower-layer vnodes (not just above directory vnodes).
76.Pp
77Both
78.Ar target
79and
80.Ar mount-point
81are converted to absolute paths before use.
82.Pp
83The options are as follows:
84.Bl -tag -width indent
85.It Fl o
86Options are specified with a
87.Fl o
88flag followed by a comma separated string of options.
89See the
90.Xr mount 8
91man page for possible options and their meanings.
92.El
93.Pp
94The null layer has two purposes.
95First, it serves as a demonstration of layering by providing a layer
96which does nothing.
97Second, the null layer can serve as a prototype layer.
98Since it provides all necessary layer framework,
99new file system layers can be created very easily by starting
100with a null layer.
101.Pp
102The remainder of this man page examines the null layer as a basis
103for constructing new layers.
104.\"
105.\"
106.Sh INSTANTIATING NEW NULL LAYERS
107New null layers are created with
108.Nm .
109.Nm
110takes 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 the null layer is put into place, the contents
114of target-pn subtree will be aliased under mount-point-pn.
115.\"
116.\"
117.Sh OPERATION OF A NULL LAYER
118The null layer is the minimum file system layer,
119simply passing all possible operations to the lower layer
120for processing there.
121The majority of its activity centers on the bypass routine,
122through which nearly all vnode operations pass.
123.Pp
124The bypass routine accepts arbitrary vnode operations for
125handling by the lower layer.
126It begins by examining vnode operation arguments and replacing
127any null-nodes by their lower-layer equivalents.
128It then invokes the operation on the lower layer.
129Finally, 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 vop_reclaim are not bypassed so that
144they can handle freeing null-layer specific data.
145.Em vop_print
146is not bypassed to avoid excessive debugging
147information.
148.\"
149.\"
150.Sh INSTANTIATING VNODE STACKS
151Mounting associates the null layer with a lower layer,
152in effect stacking two VFSes.
153Vnode stacks are instead
154created on demand as files are accessed.
155.Pp
156The initial mount creates a single vnode stack for the
157root of the new null layer.
158All 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
171Changing directory to
172.Pa /dev/layer/null
173will assign
174the root null-node (which was created when the null layer was mounted).
175Now consider opening
176.Pa sys .
177A vop_lookup would be done on the root null-node.
178This operation would bypass through to the lower layer
179which would return a vnode representing the UFS
180.Pa sys .
181null_bypass then builds a null-node aliasing the UFS
182.Pa sys
183and returns this to the caller.
184Later operations on the null-node
185.Pa sys
186will repeat this process when constructing other vnode stacks.
187.\"
188.\"
189.Sh CREATING OTHER FILE SYSTEM LAYERS
190One of the easiest ways to construct new file system layers is to make
191a copy of the null layer, rename all files and variables, and
192then begin modifying the copy.
193.Xr sed 1
194can be used to easily rename all variables.
195.Pp
196The umap layer is an example of a layer descended from the
197null layer.
198.\"
199.\"
200.Sh INVOKING OPERATIONS ON LOWER LAYERS
201There are two techniques to invoke operations on a lower layer
202when the operation cannot be completely bypassed.
203Each method is appropriate in different situations.
204In both cases, it is the responsibility of the aliasing layer to make
205the operation arguments "correct" for the lower layer
206by mapping any vnode arguments to the lower layer.
207.Pp
208The first approach is to call the aliasing layer's bypass routine.
209This method is most suitable when you wish to invoke the operation
210currently being handled on the lower layer.
211It has the advantage that the bypass routine already must do argument mapping.
212An example of this is
213.Em null_getattrs
214in the null layer.
215.Pp
216A second approach is to directly invoke vnode operations on
217the lower layer with the
218.Em VOP_OPERATIONNAME
219interface.
220The advantage of this method is that it is easy to invoke
221arbitrary operations on the lower layer.
222The disadvantage is that vnode arguments must be manually mapped.
223.\"
224.\"
225.Sh SEE ALSO
226.Xr mount 8
227.Pp
228UCLA Technical Report CSD-910056,
229.Em "Stackable Layers: an Architecture for File System Development" .
230.Sh HISTORY
231The
232.Nm
233utility first appeared in
234.Bx 4.4 .
235