xref: /freebsd/lib/libsys/mount.2 (revision 8a7df6c58d549bd2eaa5cad30b2ef93c3eca3c18)
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 -tag -width "check_fsid" -offset indent
87.It Li fstype
88file system type name
89.Pq e.g., Dq Li procfs
90.It Li fspath
91mount point pathname
92.Pq e.g., Dq Li /proc
93.El
94.Pp
95The following options may be specified when mounting any file system:
96.Bl -tag -width "check_fsid" -offset indent
97.It Li check_fsid
98FSID of a mount point being covered by the mount in the
99.Dq Li FSID:%d:%d
100format
101.El
102.Pp
103If the
104.Dq Li check_fsid
105option is specified, and the FSID of the mount point the covered vnode belongs
106to does not match the passed value, the
107.Fn nmount
108call will fail.
109.Dq Li check_fsid
110may also be passed when doing a mount update, in which case the caller should
111pass a FSID of the FS being updated, not the one covered.
112.Pp
113Depending on the file system type, other options may be
114recognized or required;
115for example, most disk-based file systems require a
116.Dq Li from
117option containing the pathname of a special device
118in addition to the options listed above.
119.Pp
120By default only the super-user may call the
121.Fn mount
122system call.
123This restriction can be removed by setting the
124.Va vfs.usermount
125.Xr sysctl 8
126variable
127to a non-zero value; see the BUGS section for more information.
128.Pp
129The following
130.Fa flags
131may be specified to
132suppress default semantics which affect file system access.
133.Bl -tag -width MNT_SYNCHRONOUS
134.It Dv MNT_RDONLY
135The file system should be treated as read-only;
136even the super-user may not write on it.
137Specifying MNT_UPDATE without this option will upgrade
138a read-only file system to read/write.
139.It Dv MNT_NOEXEC
140Do not allow files to be executed from the file system.
141.It Dv MNT_NOSUID
142Do not honor setuid or setgid bits on files when executing them.
143This flag is set automatically when the caller is not the super-user.
144.It Dv MNT_NOATIME
145Disable update of file access times.
146.It Dv MNT_SNAPSHOT
147Create a snapshot of the file system.
148This is currently only supported on UFS2 file systems, see
149.Xr mksnap_ffs 8
150for more information.
151.It Dv MNT_SUIDDIR
152Directories with the SUID bit set chown new files to their own owner.
153This flag requires the SUIDDIR option to have been compiled into the kernel
154to have any effect.
155See the
156.Xr mount 8
157and
158.Xr chmod 2
159pages for more information.
160.It Dv MNT_SYNCHRONOUS
161All I/O to the file system should be done synchronously.
162.It Dv MNT_ASYNC
163All I/O to the file system should be done asynchronously.
164.It Dv MNT_FORCE
165Force a read-write mount even if the file system appears to be unclean.
166Dangerous.
167Together with
168.Dv MNT_UPDATE
169and
170.Dv MNT_RDONLY ,
171specify that the file system is to be forcibly downgraded to a read-only
172mount even if some files are open for writing.
173.It Dv MNT_NOCLUSTERR
174Disable read clustering.
175.It Dv MNT_NOCLUSTERW
176Disable write clustering.
177.It Dv MNT_NOCOVER
178Do not mount over the root of another mount point.
179.It Dv MNT_EMPTYDIR
180Require an empty directory for the mount point directory.
181.El
182.Pp
183The flag
184.Dv MNT_UPDATE
185indicates that the mount command is being applied
186to an already mounted file system.
187This allows the mount flags to be changed without requiring
188that the file system be unmounted and remounted.
189Some file systems may not allow all flags to be changed.
190For example,
191many file systems will not allow a change from read-write to read-only.
192.Pp
193The flag
194.Dv MNT_RELOAD
195causes the vfs subsystem to update its data structures pertaining to
196the specified already mounted file system.
197.Pp
198The
199.Fa type
200argument names the file system.
201The types of file systems known to the system can be obtained with
202.Xr lsvfs 1 .
203.Pp
204The
205.Fa data
206argument
207is a pointer to a structure that contains the type
208specific arguments to mount.
209The format for these argument structures is described in the
210manual page for each file system.
211By convention file system manual pages are named
212by prefixing ``mount_'' to the name of the file system as returned by
213.Xr lsvfs 1 .
214Thus the
215.Tn NFS
216file system is described by the
217.Xr mount_nfs 8
218manual page.
219It should be noted that a manual page for default
220file systems, known as UFS and UFS2, does not exist.
221.Pp
222The
223.Fn unmount
224system call disassociates the file system from the specified
225mount point
226.Fa dir .
227.Pp
228The
229.Fa flags
230argument may include
231.Dv MNT_FORCE
232to specify that the file system should be forcibly unmounted
233even if files are still active.
234Active special devices continue to work,
235but any further accesses to any other active files result in errors
236even if the file system is later remounted.
237.Pp
238If the
239.Dv MNT_BYFSID
240flag is specified,
241.Fa dir
242should instead be a file system ID encoded as
243.Dq Li FSID : Ns Ar val0 : Ns Ar val1 ,
244where
245.Ar val0
246and
247.Ar val1
248are the contents of the
249.Vt fsid_t
250.Va val[]
251array in decimal.
252The file system that has the specified file system ID will be unmounted.
253.Sh RETURN VALUES
254.Rv -std
255.Sh ERRORS
256The
257.Fn mount
258and
259.Fn nmount
260system calls will fail when one of the following occurs:
261.Bl -tag -width Er
262.It Bq Er EPERM
263The caller is neither the super-user nor the owner of
264.Fa dir .
265.It Bq Er ENAMETOOLONG
266A component of a pathname exceeded 255 characters,
267or the entire length of a path name exceeded 1023 characters.
268.It Bq Er ELOOP
269Too many symbolic links were encountered in translating a pathname.
270.It Bq Er ENOENT
271A component of
272.Fa dir
273does not exist.
274.It Bq Er ENOTDIR
275A component of
276.Fa name
277is not a directory,
278or a path prefix of
279.Fa special
280is not a directory.
281.It Bq Er EBUSY
282Another process currently holds a reference to
283.Fa dir .
284.It Bq Er EBUSY
285The
286.Dv MNT_NOCOVER
287option was given, and the requested mount point
288is already the root of another mount point.
289.It Bq Er EFAULT
290The
291.Fa dir
292argument
293points outside the process's allocated address space.
294.It Bq Er EIO
295An I/O error occurred while reading data from
296.Fa special .
297.It Bq Er EINTEGRITY
298The backing store for
299.Fa special
300detected corrupted data while reading.
301.It Bq Er ENOENT
302The file system ID specified using
303.Fa check_fsid
304did not match the target path.
305.El
306.Pp
307The following errors can occur for a
308.Em ufs
309file system mount:
310.Bl -tag -width Er
311.It Bq Er ENODEV
312A component of ufs_args
313.Fa fspec
314does not exist.
315.It Bq Er ENOTBLK
316The
317.Fa fspec
318argument
319is not a block device.
320.It Bq Er ENOTEMPTY
321The
322.Dv MNT_EMPTYDIR
323option was specified, and the requested mount point
324is not an empty directory.
325.It Bq Er ENXIO
326The major device number of
327.Fa fspec
328is out of range (this indicates no device driver exists
329for the associated hardware).
330.It Bq Er EBUSY
331.Fa fspec
332is already mounted.
333.It Bq Er EMFILE
334No space remains in the mount table.
335.It Bq Er EINVAL
336The super block for the file system had a bad magic
337number or an out of range block size.
338.It Bq Er EINTEGRITY
339The super block for the file system had a bad check hash.
340The check hash can usually be corrected by running
341.Xr fsck 8 .
342.It Bq Er ENOMEM
343Not enough memory was available to read the cylinder
344group information for the file system.
345.It Bq Er EIO
346An I/O error occurred while reading the super block or
347cylinder group information.
348.It Bq Er EFAULT
349The
350.Fa fspec
351argument
352points outside the process's allocated address space.
353.El
354.Pp
355The following errors can occur for a
356.Em nfs
357file system mount:
358.Bl -tag -width Er
359.It Bq Er ETIMEDOUT
360.Em Nfs
361timed out trying to contact the server.
362.It Bq Er EFAULT
363Some part of the information described by nfs_args
364points outside the process's allocated address space.
365.El
366.Pp
367The
368.Fn unmount
369system call may fail with one of the following errors:
370.Bl -tag -width Er
371.It Bq Er EPERM
372The caller is neither the super-user nor the user who issued the corresponding
373.Fn mount
374call.
375.It Bq Er ENAMETOOLONG
376The length of the path name exceeded 1023 characters.
377.It Bq Er EINVAL
378The requested directory is not in the mount table.
379.It Bq Er ENOENT
380The file system ID specified using
381.Dv MNT_BYFSID
382was not found in the mount table.
383.It Bq Er EINVAL
384The file system ID specified using
385.Dv MNT_BYFSID
386could not be decoded.
387.It Bq Er EINVAL
388The specified file system is the root file system.
389.It Bq Er EBUSY
390A process is holding a reference to a file located
391on the file system.
392.It Bq Er EIO
393An I/O error occurred while writing cached file system information.
394.It Bq Er EFAULT
395The
396.Fa dir
397argument
398points outside the process's allocated address space.
399.El
400.Sh SEE ALSO
401.Xr lsvfs 1 ,
402.Xr mksnap_ffs 8 ,
403.Xr mount 8 ,
404.Xr umount 8
405.Sh HISTORY
406The
407.Fn mount
408and
409.Fn unmount
410functions appeared in
411.At v1 .
412The
413.Fn nmount
414system call first appeared in
415.Fx 5.0 .
416.Sh BUGS
417Some of the error codes need translation to more obvious messages.
418.Pp
419Allowing untrusted users to mount arbitrary media, e.g. by enabling
420.Va vfs.usermount ,
421should not be considered safe.
422Most file systems in
423.Fx
424were not built to safeguard against malicious devices.
425