mount
mount filesystem
- Provided by: manpages-dev (Version: 3.54-1ubuntu1)
- Source: manpages
- Report a bug
mount filesystem
#include <sys/mount.h>
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
mount() attaches the filesystem specified by source (which is often a device name, but can also be a directory name or a dummy) to the directory specified by target.
Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to mount filesystems.
Since Linux 2.4 a single filesystem can be visible at multiple mount points, and multiple mounts can be stacked on the same mount point.
Values for the filesystemtype argument supported by the kernel are listed in /proc/filesystems (e.g., "minix", "ext2", "ext3", "jfs", "xfs", "reiserfs", "msdos", "proc", "nfs", "iso9660"). Further types may become available when the appropriate modules are loaded.
The mountflags argument may have the magic number 0xC0ED (MS_MGC_VAL) in the top 16 bits (this was required in kernel versions prior to 2.4, but is no longer required and ignored if specified), and various mount flags in the low order 16 bits:
The following mountflags can be changed: MS_RDONLY, MS_SYNCHRONOUS, MS_MANDLOCK; before kernel 2.6.16, the following could also be changed: MS_NOATIME and MS_NODIRATIME; and, additionally, before kernel 2.4.10, the following could also be changed: MS_NOSUID, MS_NODEV, MS_NOEXEC.
From Linux 2.4 onward, the MS_NODEV, MS_NOEXEC, and MS_NOSUID flags are settable on a per-mount-point basis. From kernel 2.6.16 onward, MS_NOATIME and MS_NODIRATIME are also settable on a per-mount-point basis. The MS_RELATIME flag is also settable on a per-mount-point basis.
The data argument is interpreted by the different filesystems. Typically it is a string of comma-separated options understood by this filesystem. See mount(8) for details of the options available for each filesystem type.
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
The error values given below result from filesystem type independent errors. Each filesystem type may have its own special errors and its own special behavior. See the Linux kernel source code for details.
The definitions of MS_DIRSYNC, MS_MOVE, MS_REC, MS_RELATIME, and MS_STRICTATIME were added to glibc headers in version 2.12.
This function is Linux-specific and should not be used in programs intended to be portable.
The original MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69 when a different MS_SYNC was added to <mman.h>.
Before Linux 2.4 an attempt to execute a set-user-ID or set-group-ID program on a filesystem mounted with MS_NOSUID would fail with EPERM. Since Linux 2.4 the set-user-ID and set-group-ID bits are just silently ignored in this case.
Starting with kernel 2.4.19, Linux provides per-process mount namespaces. A mount namespace is the set of filesystem mounts that are visible to a process. Mount-point namespaces can be (and usually are) shared between multiple processes, and changes to the namespace (i.e., mounts and unmounts) by one process are visible to all other processes sharing the same namespace. (The pre-2.4.19 Linux situation can be considered as one in which a single namespace was shared by every process on the system.)
A child process created by fork(2) shares its parent's mount namespace; the mount namespace is preserved across an execve(2).
A process can obtain a private mount namespace if: it was created using the clone(2) CLONE_NEWNS flag, in which case its new namespace is initialized to be a copy of the namespace of the process that called clone(2); or it calls unshare(2) with the CLONE_NEWNS flag, which causes the caller's mount namespace to obtain a private copy of the namespace that it was previously sharing with other processes, so that future mounts and unmounts by the caller are invisible to other processes (except child processes that the caller subsequently creates) and vice versa.
The Linux-specific /proc/PID/mounts file exposes the list of mount points in the mount namespace of the process with the specified ID; see proc(5) for details.
umount(2), namespaces(7), path_resolution(7), mount(8), umount(8)
This page is part of release 3.54 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/.