xref: /freebsd-14.2/lib/libc/sys/mount.2 (revision 9b50d902)
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.2 (Berkeley) 12/11/93
33.\"
34.Dd December 11, 1993
35.Dt MOUNT 2
36.Os BSD 4
37.Sh NAME
38.Nm mount ,
39.Nm unmount
40.Nd mount or dismount a filesystem
41.Sh SYNOPSIS
42.Fd #include <sys/param.h>
43.Fd #include <sys/mount.h>
44.Ft int
45.Fn mount "int type" "const char *dir" "int flags" "caddr_t data"
46.Ft int
47.Fn unmount "const char *dir" "int flags"
48.Sh DESCRIPTION
49The
50.Fn mount
51function grafts
52a filesystem object onto the system file tree
53at the point
54.Ar dir .
55The argument
56.Ar data
57describes the filesystem object to be mounted.
58The argument
59.Ar type
60tells the kernel how to interpret
61.Ar data
62(See
63.Ar type
64below).
65The contents of the filesystem
66become available through the new mount point
67.Ar dir .
68Any files in
69.Ar dir
70at the time
71of a successful mount are swept under the carpet so to speak, and
72are unavailable until the filesystem is unmounted.
73.Pp
74The following
75.Ar flags
76may be specified to
77suppress default semantics which affect filesystem access.
78.Bl -tag -width MNT_SYNCHRONOUS
79.It Dv MNT_RDONLY
80The filesystem should be treated as read-only;
81Even the super-user may not write on it.
82.It Dv MNT_NOEXEC
83Do not allow files to be executed from the filesystem.
84.It Dv MNT_NOSUID
85Do not honor setuid or setgid bits on files when executing them.
86.It Dv MNT_NODEV
87Do not interpret special files on the filesystem.
88.It Dv MNT_SYNCHRONOUS
89All I/O to the filesystem should be done synchronously.
90.El
91.Pp
92The flag
93.Dv MNT_UPDATE
94indicates that the mount command is being applied
95to an already mounted filesystem.
96This allows the mount flags to be changed without requiring
97that the filesystem be unmounted and remounted.
98Some filesystems may not allow all flags to be changed.
99For example,
100most filesystems will not allow a change from read-write to read-only.
101.Pp
102The
103.Fa type
104argument defines the type of the filesystem.
105The types of filesystems known to the system are defined in
106.Aq Pa sys/mount.h .
107.Fa Data
108is a pointer to a structure that contains the type
109specific arguments to mount.
110The currently supported types of filesystems and
111their type specific data are:
112.Pp
113.Dv MOUNT_UFS
114.Bd -literal -offset indent -compact
115struct ufs_args {
116      char	*fspec;  /* Block special file to mount */
117      int	exflags; /* export related flags */
118      uid_t	exroot;  /* mapping for root uid */
119};
120.Ed
121.Pp
122.Dv MOUNT_NFS
123.Bd -literal -offset indent -compact
124struct nfs_args {
125      struct sockaddr_in *addr; /* file server address */
126      nfsv2fh_t *fh;       /* File handle to be mounted */
127      int       flags;     /* flags */
128      int       wsize;     /* write size in bytes */
129      int       rsize;     /* read size in bytes */
130      int       timeo;     /* initial timeout 0.1 secs */
131      int       retrans;   /* times to retry send */
132      char      *hostname; /* server's name */
133};
134.Ed
135.Pp
136.Dv MOUNT_MFS
137.Bd -literal -offset indent -compact
138struct mfs_args {
139      char	*name;	/* name of backing process */
140      caddr_t	base;	/* base address of the filesystem */
141      u_long	size;	/* size of the filesystem */
142};
143.Ed
144.Pp
145The
146.Fn umount
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 even if files are
156still active.
157Active special devices continue to work,
158but any further accesses to any other active files result in errors
159even if the filesystem is later remounted.
160.Sh RETURN VALUES
161The
162.Fn mount
163returns the value 0 if the mount was successful, otherwise -1 is returned
164and the variable
165.Va errno
166is set to indicate the error.
167.Pp
168.Nm Umount
169returns the value 0 if the umount succeeded; otherwise -1 is returned
170and the variable
171.Va errno
172is set to indicate the error.
173.Sh ERRORS
174.Fn Mount
175will fail when one of the following occurs:
176.Bl -tag -width [ENOTBLK]
177.It Bq Er EPERM
178The caller is not the super-user.
179.It Bq Er ENAMETOOLONG
180A component of a pathname exceeded 255 characters,
181or the entire length of a path name exceeded 1023 characters.
182.It Bq Er ELOOP
183Too many symbolic links were encountered in translating a pathname.
184.It Bq Er ENOENT
185A component of
186.Fa dir
187does not exist.
188.It Bq Er ENOTDIR
189A component of
190.Ar name
191is not a directory,
192or a path prefix of
193.Ar special
194is not a directory.
195.It Bq Er EINVAL
196A pathname contains a character with the high-order bit set.
197.It Bq Er EBUSY
198Another process currently holds a reference to
199.Fa dir .
200.It Bq Er EFAULT
201.Fa Dir
202points outside the process's allocated address space.
203.El
204.Pp
205The following errors can occur for a
206.Em ufs
207filesystem mount:
208.Bl -tag -width [ENOTBLK]
209.It Bq Er ENODEV
210A component of ufs_args
211.Ar fspec
212does not exist.
213.It Bq Er ENOTBLK
214.Ar Fspec
215is not a block device.
216.It Bq Er ENXIO
217The major device number of
218.Ar fspec
219is out of range (this indicates no device driver exists
220for the associated hardware).
221.It Bq Er EBUSY
222.Ar Fspec
223is already mounted.
224.It Bq Er EMFILE
225No space remains in the mount table.
226.It Bq Er EINVAL
227The super block for the filesystem had a bad magic
228number or an out of range block size.
229.It Bq Er ENOMEM
230Not enough memory was available to read the cylinder
231group information for the filesystem.
232.It Bq Er EIO
233An I/O error occurred while reading the super block or
234cylinder group information.
235.It Bq Er EFAULT
236.Ar Fspec
237points outside the process's allocated address space.
238.El
239.Pp
240The following errors can occur for a
241.Em nfs
242filesystem mount:
243.Bl -tag -width [ENOTBLK]
244.It Bq Er ETIMEDOUT
245.Em Nfs
246timed out trying to contact the server.
247.It Bq Er EFAULT
248Some part of the information described by nfs_args
249points outside the process's allocated address space.
250.El
251.Pp
252The following errors can occur for a
253.Em mfs
254filesystem mount:
255.Bl -tag -width [ENOTBLK]
256.It Bq Er EMFILE
257No space remains in the mount table.
258.It Bq Er EINVAL
259The super block for the filesystem had a bad magic
260number or an out of range block size.
261.It Bq Er ENOMEM
262Not enough memory was available to read the cylinder
263group information for the filesystem.
264.It Bq Er EIO
265A paging error occurred while reading the super block or
266cylinder group information.
267.It Bq Er EFAULT
268.Em Name
269points outside the process's allocated address space.
270.El
271.Pp
272.Nm Umount
273may fail with one of the following errors:
274.Bl -tag -width [ENOTBLK]
275.It Bq Er EPERM
276The caller is not the super-user.
277.It Bq Er ENOTDIR
278A component of the path is not a directory.
279.It Bq Er EINVAL
280The pathname contains a character with the high-order bit set.
281.It Bq Er ENAMETOOLONG
282A component of a pathname exceeded 255 characters,
283or an entire path name exceeded 1023 characters.
284.It Bq Er ELOOP
285Too many symbolic links were encountered in translating the pathname.
286.It Bq Er EINVAL
287The requested directory is not in the mount table.
288.It Bq Er EBUSY
289A process is holding a reference to a file located
290on the filesystem.
291.It Bq Er EIO
292An I/O error occurred while writing cached filesystem information.
293.It Bq Er EFAULT
294.Fa Dir
295points outside the process's allocated address space.
296.El
297.Pp
298A
299.Em ufs
300or
301.Em mfs
302mount can also fail if the maximum number of filesystems are currently
303mounted.
304.Sh SEE ALSO
305.Xr mount 8 ,
306.Xr umount 8 ,
307.Xr mfs 8
308.Sh BUGS
309Some of the error codes need translation to more obvious messages.
310.Sh HISTORY
311.Fn Mount
312and
313.Fn umount
314function calls appeared in Version 6 AT&T UNIX.
315