MOUNT(2) BSD Programmer's Manual MOUNT(2)NAME
mount, unmount - mount or dismount a filesystem
SYNOPSIS
#include <sys/param.h>
#include <sys/mount.h>
int
mount(const char *type, const char *dir, int flags, caddr_t data);
int
unmount(const char *dir, int flags);
DESCRIPTION
The mount() function grafts a filesystem object onto the system file tree
at the point dir. The argument data describes the filesystem object to be
mounted. The argument type tells the kernel how to interpret data (see
type below). The contents of the filesystem become available through the
new mount point dir. Any files in dir at the time of a successful mount
are swept under the carpet so to speak, and are unavailable until the
filesystem is unmounted.
The following flags modify the mount() operation:
MNT_DELEXPORT Reset the export state of the filesystem. The system
discards the list of hosts that may access the filesys-
tem remotely, and clears the MNT_EXPORTED and
MNT_DEFEXPORTED flags.
MNT_RELOAD Reload filesystem data. All cached data for the
filesystem, both metadata and file data, are invalidat-
ed and re-fetched. The meaning of this flag is unde-
fined unless it is also used with MNT_UPDATE. The sys-
tem will return an error if MNT_RELOAD is used on a
filesystem that is not currently mounted read-only.
MNT_UPDATE Indicates that the operation is being applied to an al-
ready mounted filesystem. This allows the mount flags
to be changed without requiring that the filesystem be
unmounted and remounted. Some filesystems may not al-
low all flags to be changed. For example, most
filesystems will not allow a change from read-write to
read-only.
The following flags may be specified to alter semantics which affect
filesystem access:
MNT_ASYNC Perform all I/O to the filesystem asynchronously, in-
cluding metadata updates. Filesystems mounted with
this flag face serious risks. If a crash occurs while a
filesystem is mounted with MNT_ASYNC, filesystem meta-
data may be inconsistent with file data and with it-
self. The sync(2) function should be used to force
cached data to disk.
MNT_AUTOFS Hide this mount point by default in df(1) output. Used
by the automounter to hide it's mount points.
MNT_DEFEXPORTED Export the filesystem for both reading and writing to
any Internet host.
MNT_EXKERB Export the filesystem with Kerberos UID mapping.
MNT_EXPORTANON Map all remote accesses to the anonymous user.
MNT_EXPORTED Export the filesystem for reading and writing.
MNT_EXRDONLY Export the filesystem read-only.
MNT_NOATIME Suppress updating of file access times on read/write
filesystems.
MNT_NODEV Do not interpret special files on the filesystem.
MNT_NOEXEC Do not allow files to be executed from the filesystem.
MNT_NOSUID Do not honor setuid or setgid bits on files when exe-
cuting them.
MNT_RDONLY Treat the filesystem as read-only. Even the super-user
may not write on it.
MNT_SYNCHRONOUS Perform all I/O to the filesystem synchronously.
The type argument names the filesystem. The types of filesystems known
to the system can be obtained with sysctl(8) by using the command:
sysctl -a vfs
The type is specified as the second component listed by sysctl(8). Thus,
sysctl(8) reports the local filesystem as ``vfs.ufs''; the type argument
for the local filesystem is
Data is a pointer to a structure that contains the type specific argu-
ments to mount. The format for these argument structures is described in
the manual page for each filesystem. By convention filesystem manual
pages are named by prefixing ``mount_'' to the name of the filesystem as
returned by sysctl(8). Thus the NFS filesystem is described by the
mount_nfs(8) manual page.
The unmount() function call disassociates the filesystem from the speci-
fied mount point dir.
The flags argument may specify:
MNT_FORCE Forcibly unmount the filesystem even if files are still
active. Active special devices continue to work, but
any further accesses to any other active files result
in errors even if the filesystem is later remounted.
RETURN VALUES
The mount() function returns the value 0 if the mount was successful;
otherwise -1 is returned and the variable errno is set to indicate the
error.
The unmount() function returns the value 0 if the unmount succeeded; oth-
erwise -1 is returned and the variable errno is set to indicate the er-
ror.
ERRORSMount() will fail when one of the following occurs:
[EPERM] The caller is not the super-user and does not have the neces-
sary read and/or write permissions on the mounted from device
or does not own the mount point.
[ENAMETOOLONG]
A component of a pathname exceeded 255 characters, or the en-
tire length of a path name exceeded 1023 characters.
[ELOOP] Too many symbolic links were encountered in translating a
pathname.
[ENOENT] A component of dir does not exist.
[ENOTDIR] A component of name is not a directory, or a path prefix of
filesystem-specific special file is not a directory.
[EINVAL] A pathname contains a character with the high-order bit set,
or a pathname containing a symbolic link was specified.
[EBUSY] Another process currently holds a reference to dir.
[EFAULT] Dir points outside the process's allocated address space.
The following errors can occur for a ufs filesystem mount:
[ENODEV] A component of ufs_args fspec does not exist.
[ENOTBLK] Fspec is not a block device.
[ENXIO] The major device number of fspec is out of range (this indi-
cates no device driver exists for the associated hardware).
[EBUSY] Fspec is already mounted.
[EMFILE] No space remains in the mount table.
[EINVAL] The super block for the filesystem had a bad magic number or
an out of range block size. If doing an update to set the
root device, the incorrect device has been specified.
[ENOMEM] Not enough memory was available to read the cylinder group in-
formation for the filesystem.
[EIO] An I/O error occurred while reading the super block or cylin-
der group information.
[ENOSPC] An attempt has been made to mount an unclean filesystem for
writing.
[EROFS] An attempt has been made to mount a filesystem for writing
from a device that currently supports only reading.
[EFAULT] Fspec points outside the process's allocated address space.
The following errors can occur for a nfs filesystem mount:
[ETIMEDOUT]
NFS timed out trying to contact the server.
[EFAULT] Some part of the information described by nfs_args points out-
side the process's allocated address space.
The following errors can occur for a mfs filesystem mount:
[EMFILE] No space remains in the mount table.
[EINVAL] The super block for the filesystem had a bad magic number or
an out of range block size.
[ENOMEM] Not enough memory was available to read the cylinder group in-
formation for the filesystem.
[EIO] A paging error occurred while reading the super block or
cylinder group information.
[EFAULT] Name points outside the process's allocated address space.
The unmount() function may fail with one of the following errors:
[EPERM] The caller is not the super-user or is not the user that did
the mount.
[ENOTDIR] A component of the path is not a directory.
[EINVAL] The pathname contains a character with the high-order bit set.
[ENAMETOOLONG]
A component of a pathname exceeded 255 characters, or an en-
tire path name exceeded 1023 characters.
[ELOOP] Too many symbolic links were encountered in translating the
pathname.
[EINVAL] The requested directory is not in the mount table.
[EBUSY] A process is holding a reference to a file located on the
filesystem.
[EIO] An I/O error occurred while writing cached filesystem informa-
tion.
[EFAULT] Dir points outside the process's allocated address space.
A ufs or mfs mount can also fail if the maximum number of filesystems are
currently mounted.
SEE ALSOmount(8), umount(8), statfs(2), sysctl(8)BUGS
Some of the error codes need translation to more obvious messages.
MNT_ASYNC and MNT_SYNCHRONOUS are annoyingly inconsistent names.
HISTORYMount() and unmount() function calls appeared in Version 6 AT&T UNIX.
4th Berkeley Distribution January 27, 1997 4