xref: /freebsd-12.1/lib/libc/sys/mount.2 (revision 7d0fc2f4)
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 March 16, 2004
36.Dt MOUNT 2
37.Os
38.Sh NAME
39.Nm mount ,
40.Nm nmount ,
41.Nm unmount
42.Nd mount or dismount a file system
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In sys/param.h
47.In sys/mount.h
48.Ft int
49.Fn mount "const char *type" "const char *dir" "int flags" "void *data"
50.Ft int
51.Fn unmount "const char *dir" "int flags"
52.In sys/uio.h
53.Ft int
54.Fn nmount "struct iovec *iov" "u_int niov" "int flags"
55.Sh DESCRIPTION
56The
57.Fn mount
58system call grafts
59a file system object onto the system file tree
60at the point
61.Fa dir .
62The argument
63.Fa data
64describes the file system object to be mounted.
65The argument
66.Fa type
67tells the kernel how to interpret
68.Fa data
69(See
70.Fa type
71below).
72The contents of the file system
73become available through the new mount point
74.Fa dir .
75Any files in
76.Fa dir
77at the time
78of a successful mount are swept under the carpet so to speak, and
79are unavailable until the file system is unmounted.
80.Pp
81The
82.Fn nmount
83system call behaves similarly to
84.Fn mount ,
85except that the mount options (file system type name, device to mount,
86mount-point name, etc.) are passed as an array of name-value pairs
87in the array
88.Fa iov ,
89containing
90.Fa niov
91elements.
92The following options are required by all file systems:
93.Bl -item -offset indent -compact
94.It
95.Li fstype Ta file system type name (e.g., Dq Li procfs )
96.It
97.Li fspath Ta mount point pathname (e.g., Dq Li /proc )
98.El
99.Pp
100Depending on the file system type, other options may be
101recognized or required;
102for example, most disk-based file systems require a
103.Dq Li from
104option containing the pathname of a special device
105in addition to the options listed above.
106.Pp
107By default only the super-user may call the
108.Fn mount
109system call.
110This restriction can be removed by setting the
111.Va vfs.usermount
112.Xr sysctl 8
113variable
114to a non-zero value.
115.Pp
116The following
117.Fa flags
118may be specified to
119suppress default semantics which affect file system access.
120.Bl -tag -width MNT_SYNCHRONOUS
121.It Dv MNT_RDONLY
122The file system should be treated as read-only;
123even the super-user may not write on it.
124Specifying MNT_UPDATE without this option will upgrade
125a read-only file system to read/write.
126.It Dv MNT_NOEXEC
127Do not allow files to be executed from the file system.
128.It Dv MNT_NOSUID
129Do not honor setuid or setgid bits on files when executing them.
130This flag is set automatically when the caller is not the super-user.
131.It Dv MNT_NOATIME
132Disable update of file access times.
133.It Dv MNT_NODEV
134Do not interpret special files on the file system.
135This flag is set automatically when the caller is not the super-user.
136.It Dv MNT_SUIDDIR
137Directories with the SUID bit set chown new files to their own owner.
138This flag requires the SUIDDIR option to have been compiled into the kernel
139to have any effect.
140See the
141.Xr mount 8
142and
143.Xr chmod 2
144pages for more information.
145.It Dv MNT_SYNCHRONOUS
146All I/O to the file system should be done synchronously.
147.It Dv MNT_ASYNC
148All I/O to the file system should be done asynchronously.
149.It Dv MNT_FORCE
150Force a read-write mount even if the file system appears to be unclean.
151Dangerous.
152Together with
153.Dv MNT_UPDATE
154and
155.Dv MNT_RDONLY ,
156specify that the file system is to be forcibly downgraded to a read-only
157mount even if some files are open for writing.
158.It Dv MNT_NOCLUSTERR
159Disable read clustering.
160.It Dv MNT_NOCLUSTERW
161Disable write clustering.
162.El
163.Pp
164The flag
165.Dv MNT_UPDATE
166indicates that the mount command is being applied
167to an already mounted file system.
168This allows the mount flags to be changed without requiring
169that the file system be unmounted and remounted.
170Some file systems may not allow all flags to be changed.
171For example,
172many file systems will not allow a change from read-write to read-only.
173.Pp
174The flag
175.Dv MNT_RELOAD
176causes the vfs subsystem to update its data structures pertaining to
177the specified already mounted file system.
178.Pp
179The
180.Fa type
181argument names the file system.
182The types of file systems known to the system can be obtained with
183.Xr lsvfs 1 .
184.Pp
185The
186.Fa data
187argument
188is a pointer to a structure that contains the type
189specific arguments to mount.
190The format for these argument structures is described in the
191manual page for each file system.
192By convention file system manual pages are named
193by prefixing ``mount_'' to the name of the file system as returned by
194.Xr lsvfs 1 .
195Thus the
196.Tn NFS
197file system is described by the
198.Xr mount_nfs 8
199manual page.
200.Pp
201The
202.Fn unmount
203system call disassociates the file system from the specified
204mount point
205.Fa dir .
206.Pp
207The
208.Fa flags
209argument may include
210.Dv MNT_FORCE
211to specify that the file system should be forcibly unmounted
212even if files are still active.
213Active special devices continue to work,
214but any further accesses to any other active files result in errors
215even if the file system is later remounted.
216.Pp
217If the
218.Dv MNT_BYFSID
219flag is specified,
220.Fa dir
221should instead be a file system ID encoded as
222.Dq Li FSID : Ns Ar val0 : Ns Ar val1 ,
223where
224.Ar val0
225and
226.Ar val1
227are the contents of the
228.Vt fsid_t
229.Va val[]
230array in decimal.
231The file system that has the specified file system ID will be unmounted.
232.Sh RETURN VALUES
233.Rv -std
234.Sh ERRORS
235The
236.Fn mount
237and
238.Fn nmount
239system calls will fail when one of the following occurs:
240.Bl -tag -width Er
241.It Bq Er EPERM
242The caller is neither the super-user nor the owner of
243.Fa dir .
244.It Bq Er ENAMETOOLONG
245A component of a pathname exceeded 255 characters,
246or the entire length of a path name exceeded 1023 characters.
247.It Bq Er ELOOP
248Too many symbolic links were encountered in translating a pathname.
249.It Bq Er ENOENT
250A component of
251.Fa dir
252does not exist.
253.It Bq Er ENOTDIR
254A component of
255.Fa name
256is not a directory,
257or a path prefix of
258.Fa special
259is not a directory.
260.It Bq Er EBUSY
261Another process currently holds a reference to
262.Fa dir .
263.It Bq Er EFAULT
264The
265.Fa dir
266argument
267points outside the process's allocated address space.
268.El
269.Pp
270The following errors can occur for a
271.Em ufs
272file system mount:
273.Bl -tag -width Er
274.It Bq Er ENODEV
275A component of ufs_args
276.Fa fspec
277does not exist.
278.It Bq Er ENOTBLK
279The
280.Fa fspec
281argument
282is not a block device.
283.It Bq Er ENXIO
284The major device number of
285.Fa fspec
286is out of range (this indicates no device driver exists
287for the associated hardware).
288.It Bq Er EBUSY
289.Fa fspec
290is already mounted.
291.It Bq Er EMFILE
292No space remains in the mount table.
293.It Bq Er EINVAL
294The super block for the file system had a bad magic
295number or an out of range block size.
296.It Bq Er ENOMEM
297Not enough memory was available to read the cylinder
298group information for the file system.
299.It Bq Er EIO
300An I/O error occurred while reading the super block or
301cylinder group information.
302.It Bq Er EFAULT
303The
304.Fa fspec
305argument
306points outside the process's allocated address space.
307.El
308.Pp
309The following errors can occur for a
310.Em nfs
311file system mount:
312.Bl -tag -width Er
313.It Bq Er ETIMEDOUT
314.Em Nfs
315timed out trying to contact the server.
316.It Bq Er EFAULT
317Some part of the information described by nfs_args
318points outside the process's allocated address space.
319.El
320.Pp
321The
322.Fn unmount
323system call may fail with one of the following errors:
324.Bl -tag -width Er
325.It Bq Er EPERM
326The caller is neither the super-user nor the user who issued the corresponding
327.Fn mount
328call.
329.It Bq Er ENAMETOOLONG
330The length of the path name exceeded 1023 characters.
331.It Bq Er EINVAL
332The requested directory is not in the mount table.
333.It Bq Er ENOENT
334The file system ID specified using
335.Dv MNT_BYFSID
336was not found in the mount table.
337.It Bq Er EINVAL
338The file system ID specified using
339.Dv MNT_BYFSID
340could not be decoded.
341.It Bq Er EINVAL
342The specified file system is the root file system.
343.It Bq Er EBUSY
344A process is holding a reference to a file located
345on the file system.
346.It Bq Er EIO
347An I/O error occurred while writing cached file system information.
348.It Bq Er EFAULT
349The
350.Fa dir
351argument
352points outside the process's allocated address space.
353.El
354.Pp
355A
356.Em ufs
357mount can also fail if the maximum number of file systems are currently
358mounted.
359.Sh SEE ALSO
360.Xr lsvfs 1 ,
361.Xr mount 8 ,
362.Xr umount 8
363.Sh BUGS
364Some of the error codes need translation to more obvious messages.
365.Sh HISTORY
366The
367.Fn mount
368and
369.Fn unmount
370functions appeared in
371.At v6 .
372