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