1.\" $NetBSD: mount.2,v 1.45 2010/05/31 12:16:20 njoly Exp $ 2.\" 3.\" Copyright (c) 1980, 1989, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)mount.2 8.3 (Berkeley) 5/24/95 31.\" 32.Dd April 10, 2009 33.Dt MOUNT 2 34.Os 35.Sh NAME 36.Nm mount , 37.Nm unmount 38.Nd mount or dismount a file system 39.Sh LIBRARY 40.Lb libc 41.Sh SYNOPSIS 42.In sys/param.h 43.In sys/mount.h 44.Ft int 45.Fn mount "const char *type" "const char *dir" "int flags" "void *data" "size_t data_len" 46.Ft int 47.Fn unmount "const char *dir" "int flags" 48.Sh DESCRIPTION 49The 50.Fn mount 51function grafts 52a file system object onto the system file tree 53at the point 54.Ar dir . 55The argument 56.Ar data 57describes the file system object to be mounted, and is 58.Ar data_len 59bytes long. 60The argument 61.Ar type 62tells the kernel how to interpret 63.Ar data 64(See 65.Ar type 66below). 67The contents of the file system 68become available through the new mount point 69.Ar dir . 70Any files in 71.Ar 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 following 77.Ar flags 78may be specified to 79suppress default semantics which affect file system access. 80.Bl -tag -width MNT_SYNCHRONOUS 81.It Dv MNT_RDONLY 82The file system should be treated as read-only; 83even the super-user may not write on it. 84.It Dv MNT_UNION 85Union with underlying filesystem instead of obscuring it. 86.It Dv MNT_HIDDEN 87Cause the 88.Xr df 1 89program, and perhaps others, to, by default, 90exclude this filesystem from its output. 91.It Dv MNT_NOEXEC 92Do not allow files to be executed from the file system. 93.It Dv MNT_NOSUID 94Do not honor setuid or setgid bits on files when executing them. 95.It Dv MNT_NODEV 96Do not interpret special files on the file system. 97.It Dv MNT_NOCOREDUMP 98Do not allow programs to dump core files on the file system. 99.It Dv MNT_NOATIME 100Never update access time in the file system. 101.It Dv MNT_NODEVMTIME 102Never update modification time of device files. 103.It Dv MNT_SYMPERM 104Recognize the permission of symbolic link when reading or traversing. 105.It Dv MNT_SYNCHRONOUS 106All I/O to the file system should be done synchronously. 107This will slow I/O performance considerably, but 108enhances overall filesystem reliability. 109.It Dv MNT_ASYNC 110All I/O to the file system should be done asynchronously. 111This vastly improves I/O throughput, 112but at a cost of making the filesystem likely to be 113completely unrecoverable should the system crash while 114unwritten data is pending in kernel buffers. 115.It Dv MNT_LOG 116Use a filesystem journal. 117.Dv MNT_LOG 118causes a journal (or log) to be created in the 119filesystem, creating a record of meta-data writes to be 120performed, allowing the actual writes to be deferred. 121This improves performance in most cases. 122.El 123.Pp 124The 125.Dv MNT_UPDATE , 126.Dv MNT_RELOAD , 127and 128.Dv MNT_GETARGS 129flags indicate that the mount command is being applied 130to an already mounted file system. 131The 132.Dv MNT_UPDATE 133flag allows the mount flags to be changed without requiring 134that the file system be unmounted and remounted. 135A conversion from read-write to read-only will fail if any files 136are currently open for writing on the filesystem, unless the 137.Dv MNT_FORCE 138flag is also applied. 139Some file systems may not allow all flags to be changed. 140For example, 141some file systems will not allow a change from read-write to read-only. 142The 143.Dv MNT_RELOAD 144flag causes kernel filesystem data to be reloaded from 145the filesystem device. 146It is only permitted on filesystems mounted read-only. 147Its purpose is to notify the system that the filesystem 148data has been modified by some external process. 149The 150.Dv MNT_GETARGS 151flag does not alter any of the mounted filesystem's properties, 152but returns the filesystem-specific arguments for the currently mounted 153filesystem. 154.Pp 155The 156.Fa type 157argument defines the type of the file system. 158The types of file systems known to the system are defined in 159.In sys/mount.h , 160and those supported by the current running kernel obtained 161using 162.Xr sysctl 8 163to obtain the node 164.\" .Bd -literal -offset indent 165vfs.generic.fstypes. 166.\" XXX from lite-2: 167.\" The types of filesystems known to the system can be obtained with 168.\" .Xr sysctl 8 169.\" by using the command: 170.\" .Bd -literal -offset indent 171.\" sysctl vfs 172.\" .Ed 173.\" .Pp 174.Fa data 175is a pointer to a structure that contains the type 176specific arguments to mount. 177Some of the currently supported types of file systems and 178their type specific data are: 179.Pp 180.Dv MOUNT_FFS 181.Bd -literal -offset indent -compact 182struct ufs_args { 183 char *fspec; /* block special file to mount */ 184}; 185.Ed 186.Pp 187.Dv MOUNT_NFS 188.Bd -literal -offset indent -compact 189struct nfs_args { 190 int version; /* args structure version */ 191 struct sockaddr *addr; /* file server address */ 192 int addrlen; /* length of address */ 193 int sotype; /* Socket type */ 194 int proto; /* and Protocol */ 195 u_char *fh; /* File handle to be mounted */ 196 int fhsize; /* Size, in bytes, of fh */ 197 int flags; /* flags */ 198 int wsize; /* write size in bytes */ 199 int rsize; /* read size in bytes */ 200 int readdirsize; /* readdir size in bytes */ 201 int timeo; /* initial timeout in .1 secs */ 202 int retrans; /* times to retry send */ 203 int maxgrouplist; /* Max. size of group list */ 204 int readahead; /* # of blocks to readahead */ 205 int leaseterm; /* Term (sec) of lease */ 206 int deadthresh; /* Retrans threshold */ 207 char *hostname; /* server's name */ 208}; 209.Ed 210.Pp 211.Dv MOUNT_MFS 212.Bd -literal -offset indent -compact 213struct mfs_args { 214 char *fspec; /* name to export for statfs */ 215 struct export_args30 pad; /* unused */ 216 caddr_t base; /* base of file system in mem */ 217 u_long size; /* size of file system */ 218}; 219.Ed 220.\" XXX from lite-2: 221.\" The format for these argument structures is described in the 222.\" manual page for each filesystem. 223.\" By convention filesystem manual pages are named 224.\" by prefixing ``mount_'' to the name of the filesystem as returned by 225.\" .Xr sysctl 8 . 226.\" Thus the 227.\" .Nm NFS 228.\" filesystem is described by the 229.\" .Xr mount_nfs 8 230.\" manual page. 231.Pp 232The 233.Fn unmount 234function call disassociates the file system from the specified 235mount point 236.Fa dir . 237.Pp 238The 239.Fa flags 240argument may specify 241.Dv MNT_FORCE 242to specify that the file system should be forcibly unmounted even if files are 243still active. 244Active special devices continue to work, 245but any further accesses to any other active files result in errors 246even if the file system is later remounted. 247.Sh RETURN VALUES 248.Fn mount 249returns the value 0 if the mount was successful, 250the number of bytes written to 251.Ar data 252for 253.Dv MNT_GETARGS , 254otherwise \-1 is returned and the variable 255.Va errno 256is set to indicate the error. 257.Pp 258.Fn unmount 259returns the value 0 if the unmount succeeded; otherwise \-1 is returned 260and the variable 261.Va errno 262is set to indicate the error. 263.Sh ERRORS 264.Fn mount 265will fail when one of the following occurs: 266.Bl -tag -width Er 267.It Bq Er EBUSY 268Another process currently holds a reference to 269.Fa dir , 270or for an update from read-write to read-only 271there are files on the filesystem open for writes. 272.It Bq Er EFAULT 273.Fa dir 274points outside the process's allocated address space. 275.It Bq Er ELOOP 276Too many symbolic links were encountered in translating a pathname. 277.It Bq Er ENAMETOOLONG 278A component of a pathname exceeded 279.Brq Dv NAME_MAX 280characters, or an entire path name exceeded 281.Brq Dv PATH_MAX 282characters. 283.It Bq Er ENOENT 284A component of 285.Fa dir 286does not exist. 287.It Bq Er ENOTDIR 288A component of 289.Ar name 290is not a directory, 291or a path prefix of 292.Ar special 293is not a directory. 294.It Bq Er EPERM 295The caller is not the super-user, 296and ordinary user mounts are not permitted or 297this particular request violates the rules. 298.El 299.Pp 300The following errors can occur for a 301.Em ufs 302file system mount: 303.Bl -tag -width Er 304.It Bq Er EBUSY 305.Ar Fspec 306is already mounted. 307.It Bq Er EFAULT 308.Ar Fspec 309points outside the process's allocated address space. 310.It Bq Er EINVAL 311The super block for the file system had a bad magic 312number or an out of range block size. 313.It Bq Er EIO 314An I/O error occurred while reading the super block or 315cylinder group information. 316.It Bq Er EMFILE 317No space remains in the mount table. 318.It Bq Er ENODEV 319A component of ufs_args 320.Ar fspec 321does not exist. 322.It Bq Er ENOMEM 323Not enough memory was available to read the cylinder 324group information for the file system. 325.It Bq Er ENOTBLK 326.Ar Fspec 327is not a block device. 328.It Bq Er ENXIO 329The major device number of 330.Ar fspec 331is out of range (this indicates no device driver exists 332for the associated hardware). 333.El 334.Pp 335The following errors can occur for a 336.Em nfs 337file system mount: 338.Bl -tag -width Er 339.It Bq Er EFAULT 340Some part of the information described by nfs_args 341points outside the process's allocated address space. 342.It Bq Er ETIMEDOUT 343.Em Nfs 344timed out trying to contact the server. 345.El 346.Pp 347The following errors can occur for a 348.Em mfs 349file system mount: 350.Bl -tag -width Er 351.It Bq Er EFAULT 352.Em Name 353points outside the process's allocated address space. 354.It Bq Er EINVAL 355The super block for the file system had a bad magic 356number or an out of range block size. 357.It Bq Er EIO 358A paging error occurred while reading the super block or 359cylinder group information. 360.It Bq Er EMFILE 361No space remains in the mount table. 362.It Bq Er ENOMEM 363Not enough memory was available to read the cylinder 364group information for the file system. 365.El 366.Pp 367.Fn unmount 368may fail with one of the following errors: 369.Bl -tag -width Er 370.It Bq Er EBUSY 371A process is holding a reference to a file located 372on the file system. 373.It Bq Er EFAULT 374.Fa dir 375points outside the process's allocated address space. 376.It Bq Er EINVAL 377The requested directory is not in the mount table. 378.It Bq Er EIO 379An I/O error occurred while writing cached file system information. 380.It Bq Er ELOOP 381Too many symbolic links were encountered in translating the pathname. 382.It Bq Er ENAMETOOLONG 383A component of a pathname exceeded 384.Brq Dv NAME_MAX 385characters, or an entire path name exceeded 386.Brq Dv PATH_MAX 387characters. 388.It Bq Er ENOTDIR 389A component of the path is not a directory. 390.It Bq Er EPERM 391The caller is not the super-user. 392.El 393.Pp 394A 395.Em ufs 396or 397.Em mfs 398mount can also fail if the maximum number of file systems are currently 399mounted. 400.Sh SEE ALSO 401.Xr df 1 , 402.Xr getvfsstat 2 , 403.Xr nfssvc 2 , 404.Xr getmntinfo 3 , 405.Xr symlink 7 , 406.Xr mount 8 , 407.Xr sysctl 8 , 408.Xr umount 8 409.Sh HISTORY 410The 411.Fn mount 412and 413.Fn umount 414(now 415.Fn unmount ) 416function calls were all present in 417.At v6 . 418.Pp 419Prior to 420.Nx 4.0 421the 422.Nm 423call was used to export NFS filesystems. 424This is now done through 425.Fn nfssvc . 426.Pp 427The 428.Dv data_len 429argument was added for 430.Nx 5.0 . 431.Sh BUGS 432Some of the error codes need translation to more obvious messages. 433.Pp 434Far more filesystems are supported than those those listed. 435