xref: /freebsd-14.2/lib/libc/sys/mount.2 (revision fffcbbcd)
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. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)mount.2	8.3 (Berkeley) 5/24/95
33.\" $FreeBSD$
34.\"
35.Dd May 24, 1995
36.Dt MOUNT 2
37.Os
38.Sh NAME
39.Nm mount ,
40.Nm unmount
41.Nd mount or dismount a filesystem
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.Fd #include <sys/param.h>
46.Fd #include <sys/mount.h>
47.Ft int
48.Fn mount "const char *type" "const char *dir" "int flags" "void *data"
49.Ft int
50.Fn unmount "const char *dir" "int flags"
51.Sh DESCRIPTION
52The
53.Fn mount
54function grafts
55a filesystem object onto the system file tree
56at the point
57.Ar dir .
58The argument
59.Ar data
60describes the filesystem object to be mounted.
61The argument
62.Ar type
63tells the kernel how to interpret
64.Ar data
65(See
66.Ar type
67below).
68The contents of the filesystem
69become available through the new mount point
70.Ar dir .
71Any files in
72.Ar dir
73at the time
74of a successful mount are swept under the carpet so to speak, and
75are unavailable until the filesystem is unmounted.
76.Pp
77The following
78.Ar flags
79may be specified to
80suppress default semantics which affect filesystem access.
81.Bl -tag -width MNT_SYNCHRONOUS
82.It Dv MNT_RDONLY
83The filesystem should be treated as read-only;
84Even the super-user may not write on it.
85Specifying MNT_UPDATE without this option will upgrade
86a read-only filesystem to read/write.
87.It Dv MNT_NOEXEC
88Do not allow files to be executed from the filesystem.
89.It Dv MNT_NOSUID
90Do not honor setuid or setgid bits on files when executing them.
91.It Dv MNT_NOATIME
92Disable update of file access times.
93.It Dv MNT_NODEV
94Do not interpret special files on the filesystem.
95.It Dv MNT_SUIDDIR
96Directories with the SUID bit set chown new files to their own owner.
97.It Dv MNT_SYNCHRONOUS
98All I/O to the filesystem should be done synchronously.
99.It Dv MNT_ASYNC
100All I/O to the filesystem should be done asynchronously.
101.It Dv MNT_FORCE
102Force a read-write mount even if the filesystem appears to be unclean.
103Dangerous.
104.It Dv MNT_NOCLUSTERR
105Disable read clustering.
106.It Dv MNT_NOCLUSTERW
107Disable write clustering.
108.El
109.Pp
110The flag
111.Dv MNT_UPDATE
112indicates that the mount command is being applied
113to an already mounted filesystem.
114This allows the mount flags to be changed without requiring
115that the filesystem be unmounted and remounted.
116Some filesystems may not allow all flags to be changed.
117For example,
118many filesystems will not allow a change from read-write to read-only.
119.Pp
120The flag
121.Dv MNT_RELOAD
122causes the vfs subsystem to update its data structures pertaining to
123the specified already mounted filesystem.
124.Pp
125The
126.Fa type
127argument names the filesystem.
128The types of filesystems known to the system can be obtained with
129.Xr lsvfs 1 .
130.Pp
131.Fa Data
132is a pointer to a structure that contains the type
133specific arguments to mount.
134The format for these argument structures is described in the
135manual page for each filesystem.
136By convention filesystem manual pages are named
137by prefixing ``mount_'' to the name of the filesystem as returned by
138.Xr lsvfs 1 .
139Thus the
140.Nm NFS
141filesystem is described by the
142.Xr mount_nfs 8
143manual page.
144.Pp
145The
146.Fn unmount
147function call disassociates the filesystem from the specified
148mount point
149.Fa dir .
150.Pp
151The
152.Fa flags
153argument may specify
154.Dv MNT_FORCE
155to specify that the filesystem should be forcibly unmounted or made read-only
156(if MNT_UPDATE and MNT_RDONLY are also specified)
157even if files are still active.
158Active special devices continue to work,
159but any further accesses to any other active files result in errors
160even if the filesystem is later remounted.
161.Pp
162The
163.Dv MNT_SUIDDIR
164option requires the SUIDDIR option to have been compiled into the kernel
165to have any effect.
166See the
167.Xr mount 8
168and
169.Xr chmod 2
170pages for more information.
171.Sh RETURN VALUES
172The
173.Fn mount
174returns the value 0 if the mount was successful, otherwise -1 is returned
175and the variable
176.Va errno
177is set to indicate the error.
178.Pp
179The
180.Fn unmount
181function returns the value 0 if the umount succeeded; otherwise -1 is returned
182and the variable
183.Va errno
184is set to indicate the error.
185.Sh ERRORS
186The
187.Fn mount
188function will fail when one of the following occurs:
189.Bl -tag -width Er
190.It Bq Er EPERM
191The caller is not the super-user.
192.It Bq Er ENAMETOOLONG
193A component of a pathname exceeded 255 characters,
194or the entire length of a path name exceeded 1023 characters.
195.It Bq Er ELOOP
196Too many symbolic links were encountered in translating a pathname.
197.It Bq Er ENOENT
198A component of
199.Fa dir
200does not exist.
201.It Bq Er ENOTDIR
202A component of
203.Ar name
204is not a directory,
205or a path prefix of
206.Ar special
207is not a directory.
208.It Bq Er EBUSY
209Another process currently holds a reference to
210.Fa dir .
211.It Bq Er EFAULT
212.Fa Dir
213points outside the process's allocated address space.
214.El
215.Pp
216The following errors can occur for a
217.Em ufs
218filesystem mount:
219.Bl -tag -width Er
220.It Bq Er ENODEV
221A component of ufs_args
222.Ar fspec
223does not exist.
224.It Bq Er ENOTBLK
225.Ar Fspec
226is not a block device.
227.It Bq Er ENXIO
228The major device number of
229.Ar fspec
230is out of range (this indicates no device driver exists
231for the associated hardware).
232.It Bq Er EBUSY
233.Ar Fspec
234is already mounted.
235.It Bq Er EMFILE
236No space remains in the mount table.
237.It Bq Er EINVAL
238The super block for the filesystem had a bad magic
239number or an out of range block size.
240.It Bq Er ENOMEM
241Not enough memory was available to read the cylinder
242group information for the filesystem.
243.It Bq Er EIO
244An I/O error occurred while reading the super block or
245cylinder group information.
246.It Bq Er EFAULT
247.Ar Fspec
248points outside the process's allocated address space.
249.El
250.Pp
251The following errors can occur for a
252.Em nfs
253filesystem mount:
254.Bl -tag -width Er
255.It Bq Er ETIMEDOUT
256.Em Nfs
257timed out trying to contact the server.
258.It Bq Er EFAULT
259Some part of the information described by nfs_args
260points outside the process's allocated address space.
261.El
262.Pp
263The
264.Fn unmount
265function may fail with one of the following errors:
266.Bl -tag -width Er
267.It Bq Er EPERM
268The caller is not the super-user.
269.It Bq Er ENOTDIR
270A component of the path is not a directory.
271.It Bq Er ENAMETOOLONG
272A component of a pathname exceeded 255 characters,
273or an entire path name exceeded 1023 characters.
274.It Bq Er ELOOP
275Too many symbolic links were encountered in translating the pathname.
276.It Bq Er EINVAL
277The requested directory is not in the mount table.
278.It Bq Er EBUSY
279A process is holding a reference to a file located
280on the filesystem.
281.It Bq Er EIO
282An I/O error occurred while writing cached filesystem information.
283.It Bq Er EFAULT
284.Fa Dir
285points outside the process's allocated address space.
286.El
287.Pp
288A
289.Em ufs
290mount can also fail if the maximum number of filesystems are currently
291mounted.
292.Sh SEE ALSO
293.Xr lsvfs 1 ,
294.Xr mount 8 ,
295.Xr umount 8
296.Sh BUGS
297Some of the error codes need translation to more obvious messages.
298.Sh HISTORY
299.Fn Mount
300and
301.Fn unmount
302function calls appeared in
303.At v6 .
304