xref: /freebsd/lib/libsys/mount.2 (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1.\" Copyright (c) 1980, 1989, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd March 30, 2020
29.Dt MOUNT 2
30.Os
31.Sh NAME
32.Nm mount ,
33.Nm nmount ,
34.Nm unmount
35.Nd mount or dismount a file system
36.Sh LIBRARY
37.Lb libc
38.Sh SYNOPSIS
39.In sys/param.h
40.In sys/mount.h
41.Ft int
42.Fn mount "const char *type" "const char *dir" "int flags" "void *data"
43.Ft int
44.Fn unmount "const char *dir" "int flags"
45.In sys/uio.h
46.Ft int
47.Fn nmount "struct iovec *iov" "u_int niov" "int flags"
48.Sh DESCRIPTION
49The
50.Fn mount
51system call grafts
52a file system object onto the system file tree
53at the point
54.Fa dir .
55The argument
56.Fa data
57describes the file system object to be mounted.
58The argument
59.Fa type
60tells the kernel how to interpret
61.Fa data
62(See
63.Fa type
64below).
65The contents of the file system
66become available through the new mount point
67.Fa dir .
68Any files in
69.Fa dir
70at the time
71of a successful mount are swept under the carpet so to speak, and
72are unavailable until the file system is unmounted.
73.Pp
74The
75.Fn nmount
76system call behaves similarly to
77.Fn mount ,
78except that the mount options (file system type name, device to mount,
79mount-point name, etc.) are passed as an array of name-value pairs
80in the array
81.Fa iov ,
82containing
83.Fa niov
84elements.
85The following options are required by all file systems:
86.Bl -column fstype -offset indent
87.It
88.Li fstype Ta file system type name (e.g., Dq Li procfs )
89.It
90.Li fspath Ta mount point pathname (e.g., Dq Li /proc )
91.El
92.Pp
93Depending on the file system type, other options may be
94recognized or required;
95for example, most disk-based file systems require a
96.Dq Li from
97option containing the pathname of a special device
98in addition to the options listed above.
99.Pp
100By default only the super-user may call the
101.Fn mount
102system call.
103This restriction can be removed by setting the
104.Va vfs.usermount
105.Xr sysctl 8
106variable
107to a non-zero value; see the BUGS section for more information.
108.Pp
109The following
110.Fa flags
111may be specified to
112suppress default semantics which affect file system access.
113.Bl -tag -width MNT_SYNCHRONOUS
114.It Dv MNT_RDONLY
115The file system should be treated as read-only;
116even the super-user may not write on it.
117Specifying MNT_UPDATE without this option will upgrade
118a read-only file system to read/write.
119.It Dv MNT_NOEXEC
120Do not allow files to be executed from the file system.
121.It Dv MNT_NOSUID
122Do not honor setuid or setgid bits on files when executing them.
123This flag is set automatically when the caller is not the super-user.
124.It Dv MNT_NOATIME
125Disable update of file access times.
126.It Dv MNT_SNAPSHOT
127Create a snapshot of the file system.
128This is currently only supported on UFS2 file systems, see
129.Xr mksnap_ffs 8
130for more information.
131.It Dv MNT_SUIDDIR
132Directories with the SUID bit set chown new files to their own owner.
133This flag requires the SUIDDIR option to have been compiled into the kernel
134to have any effect.
135See the
136.Xr mount 8
137and
138.Xr chmod 2
139pages for more information.
140.It Dv MNT_SYNCHRONOUS
141All I/O to the file system should be done synchronously.
142.It Dv MNT_ASYNC
143All I/O to the file system should be done asynchronously.
144.It Dv MNT_FORCE
145Force a read-write mount even if the file system appears to be unclean.
146Dangerous.
147Together with
148.Dv MNT_UPDATE
149and
150.Dv MNT_RDONLY ,
151specify that the file system is to be forcibly downgraded to a read-only
152mount even if some files are open for writing.
153.It Dv MNT_NOCLUSTERR
154Disable read clustering.
155.It Dv MNT_NOCLUSTERW
156Disable write clustering.
157.It Dv MNT_NOCOVER
158Do not mount over the root of another mount point.
159.It Dv MNT_EMPTYDIR
160Require an empty directory for the mount point directory.
161.El
162.Pp
163The flag
164.Dv MNT_UPDATE
165indicates that the mount command is being applied
166to an already mounted file system.
167This allows the mount flags to be changed without requiring
168that the file system be unmounted and remounted.
169Some file systems may not allow all flags to be changed.
170For example,
171many file systems will not allow a change from read-write to read-only.
172.Pp
173The flag
174.Dv MNT_RELOAD
175causes the vfs subsystem to update its data structures pertaining to
176the specified already mounted file system.
177.Pp
178The
179.Fa type
180argument names the file system.
181The types of file systems known to the system can be obtained with
182.Xr lsvfs 1 .
183.Pp
184The
185.Fa data
186argument
187is a pointer to a structure that contains the type
188specific arguments to mount.
189The format for these argument structures is described in the
190manual page for each file system.
191By convention file system manual pages are named
192by prefixing ``mount_'' to the name of the file system as returned by
193.Xr lsvfs 1 .
194Thus the
195.Tn NFS
196file system is described by the
197.Xr mount_nfs 8
198manual page.
199It should be noted that a manual page for default
200file systems, known as UFS and UFS2, does not exist.
201.Pp
202The
203.Fn unmount
204system call disassociates the file system from the specified
205mount point
206.Fa dir .
207.Pp
208The
209.Fa flags
210argument may include
211.Dv MNT_FORCE
212to specify that the file system should be forcibly unmounted
213even if files are still active.
214Active special devices continue to work,
215but any further accesses to any other active files result in errors
216even if the file system is later remounted.
217.Pp
218If the
219.Dv MNT_BYFSID
220flag is specified,
221.Fa dir
222should instead be a file system ID encoded as
223.Dq Li FSID : Ns Ar val0 : Ns Ar val1 ,
224where
225.Ar val0
226and
227.Ar val1
228are the contents of the
229.Vt fsid_t
230.Va val[]
231array in decimal.
232The file system that has the specified file system ID will be unmounted.
233.Sh RETURN VALUES
234.Rv -std
235.Sh ERRORS
236The
237.Fn mount
238and
239.Fn nmount
240system calls will fail when one of the following occurs:
241.Bl -tag -width Er
242.It Bq Er EPERM
243The caller is neither the super-user nor the owner of
244.Fa dir .
245.It Bq Er ENAMETOOLONG
246A component of a pathname exceeded 255 characters,
247or the entire length of a path name exceeded 1023 characters.
248.It Bq Er ELOOP
249Too many symbolic links were encountered in translating a pathname.
250.It Bq Er ENOENT
251A component of
252.Fa dir
253does not exist.
254.It Bq Er ENOTDIR
255A component of
256.Fa name
257is not a directory,
258or a path prefix of
259.Fa special
260is not a directory.
261.It Bq Er EBUSY
262Another process currently holds a reference to
263.Fa dir .
264.It Bq Er EBUSY
265The
266.Dv MNT_NOCOVER
267option was given, and the requested mount point
268is already the root of another mount point.
269.It Bq Er EFAULT
270The
271.Fa dir
272argument
273points outside the process's allocated address space.
274.It Bq Er EIO
275An I/O error occurred while reading data from
276.Fa special .
277.It Bq Er EINTEGRITY
278The backing store for
279.Fa special
280detected corrupted data while reading.
281.El
282.Pp
283The following errors can occur for a
284.Em ufs
285file system mount:
286.Bl -tag -width Er
287.It Bq Er ENODEV
288A component of ufs_args
289.Fa fspec
290does not exist.
291.It Bq Er ENOTBLK
292The
293.Fa fspec
294argument
295is not a block device.
296.It Bq Er ENOTEMPTY
297The
298.Dv MNT_EMPTYDIR
299option was specified, and the requested mount point
300is not an empty directory.
301.It Bq Er ENXIO
302The major device number of
303.Fa fspec
304is out of range (this indicates no device driver exists
305for the associated hardware).
306.It Bq Er EBUSY
307.Fa fspec
308is already mounted.
309.It Bq Er EMFILE
310No space remains in the mount table.
311.It Bq Er EINVAL
312The super block for the file system had a bad magic
313number or an out of range block size.
314.It Bq Er EINTEGRITY
315The super block for the file system had a bad check hash.
316The check hash can usually be corrected by running
317.Xr fsck 8 .
318.It Bq Er ENOMEM
319Not enough memory was available to read the cylinder
320group information for the file system.
321.It Bq Er EIO
322An I/O error occurred while reading the super block or
323cylinder group information.
324.It Bq Er EFAULT
325The
326.Fa fspec
327argument
328points outside the process's allocated address space.
329.El
330.Pp
331The following errors can occur for a
332.Em nfs
333file system mount:
334.Bl -tag -width Er
335.It Bq Er ETIMEDOUT
336.Em Nfs
337timed out trying to contact the server.
338.It Bq Er EFAULT
339Some part of the information described by nfs_args
340points outside the process's allocated address space.
341.El
342.Pp
343The
344.Fn unmount
345system call may fail with one of the following errors:
346.Bl -tag -width Er
347.It Bq Er EPERM
348The caller is neither the super-user nor the user who issued the corresponding
349.Fn mount
350call.
351.It Bq Er ENAMETOOLONG
352The length of the path name exceeded 1023 characters.
353.It Bq Er EINVAL
354The requested directory is not in the mount table.
355.It Bq Er ENOENT
356The file system ID specified using
357.Dv MNT_BYFSID
358was not found in the mount table.
359.It Bq Er EINVAL
360The file system ID specified using
361.Dv MNT_BYFSID
362could not be decoded.
363.It Bq Er EINVAL
364The specified file system is the root file system.
365.It Bq Er EBUSY
366A process is holding a reference to a file located
367on the file system.
368.It Bq Er EIO
369An I/O error occurred while writing cached file system information.
370.It Bq Er EFAULT
371The
372.Fa dir
373argument
374points outside the process's allocated address space.
375.El
376.Sh SEE ALSO
377.Xr lsvfs 1 ,
378.Xr mksnap_ffs 8 ,
379.Xr mount 8 ,
380.Xr umount 8
381.Sh HISTORY
382The
383.Fn mount
384and
385.Fn unmount
386functions appeared in
387.At v1 .
388The
389.Fn nmount
390system call first appeared in
391.Fx 5.0 .
392.Sh BUGS
393Some of the error codes need translation to more obvious messages.
394.Pp
395Allowing untrusted users to mount arbitrary media, e.g. by enabling
396.Va vfs.usermount ,
397should not be considered safe.
398Most file systems in
399.Fx
400were not built to safeguard against malicious devices.
401