This section describes the functions for mounting, unmounting, and remounting filesystems.
Only the superuser can mount, unmount, or remount a filesystem.
These functions do not access the `fstab' and `mtab' files. You should maintain and use these separately. See section Mount Information.
The symbols in this section are declared in `sys/mount.h'.
mount
mounts or remounts a filesystem. The two operations are
quite different and are merged rather unnnaturally into this one function.
The MS_REMOUNT
option, explained below, determines whether
mount
mounts or remounts.
For a mount, the filesystem on the block device represented by the device special file named special_file gets mounted over the mount point dir. This means that the directory dir (along with any files in it) is no longer visible; in its place (and still with the name dir) is the root directory of the filesystem on the device.
As an exception, if the filesystem type (see below) is one which is not
based on a device (e.g. "proc"), mount
instantiates a
filesystem and mounts it over dir and ignores special_file.
For a remount, dir specifies the mount point where the filesystem to be remounted is (and remains) mounted and special_file is ignored. Remounting a filesystem means changing the options that control operations on the filesystem while it is mounted. It does not mean unmounting and mounting again.
For a mount, you must identify the type of the filesystem as
fstype. This type tells the kernel how to access the filesystem
and can be thought of as the name of a filesystem driver. The
acceptable values are system dependent. On a system with a Linux kernel
and the proc
filesystem, the list of possible values is in the
file `filesystems' in the proc
filesystem (e.g. type
cat /proc/filesystems to see the list). With a Linux kernel, the
types of filesystems that mount
can mount, and their type names,
depends on what filesystem drivers are configured into the kernel or
loaded as loadable kernel modules. An example of a common value for
fstype is ext2
.
For a remount, mount
ignores fstype.
options specifies a variety of options that apply until the
filesystem is unmounted or remounted. The precise meaning of an option
depends on the filesystem and with some filesystems, an option may have
no effect at all. Furthermore, for some filesystems, some of these
options (but never MS_RDONLY
) can be overridden for individual
file accesses via ioctl
.
options is a bit string with bit fields defined using the following mask and masked value macros:
MS_MGC_MASK
MS_MGC_VAL
, mount
assumes all the following bits are zero and
the data argument is a null string, regardless of their actual values.
MS_REMOUNT
MS_RDONLY
ioctl
. This
option is available on nearly all filesystems.
S_IMMUTABLE
ioctl
.
This option is a relatively new invention and is not available on many
filesystems.
S_APPEND
ioctl
. This is a relatively new invention and is not
available on many filesystems.
MS_NOSUID
MS_NOEXEC
MS_NODEV
MS_SYNCHRONOUS
MS_MANDLOCK
MS_NOATIME
MS_NODIRATIME
Any bits not covered by the above masks should be set off; otherwise, results are undefined.
The meaning of data depends on the filesystem type and is controlled entirely by the filesystem driver in the kernel.
Example:
#include <sys/mount.h> mount("/dev/hdb", "/cdrom", MS_MGC_VAL | MS_RDONLY | MS_NOSUID, ""); mount("/dev/hda2", "/mnt", MS_MGC_VAL | MS_REMOUNT, "");
Appropriate arguments for mount
are conventionally recorded in
the `fstab' table. See section Mount Information.
The return value is zero if the mount or remount is successful. Otherwise,
it is -1
and errno
is set appropriately. The values of
errno
are filesystem dependent, but here is a general list:
EPERM
ENODEV
ENOTBLK
EBUSY
EINVAL
EACCESS
MS_RDONLY
bit off).
MS_NODEV
option.
EM_FILE
mount
needs to create a
dummy device (aka "unnamed" device) if the filesystem being mounted is
not one that uses a device.
umount2
unmounts a filesystem.
You can identify the filesystem to unmount either by the device special file that contains the filesystem or by the mount point. The effect is the same. Specify either as the string file.
flags contains the one-bit field identified by the following mask macro:
MNT_FORCE
umount2
fails with errno
= EBUSY
. Depending
on the filesystem, this may override all, some, or no busy conditions.
All other bits in flags should be set to zero; otherwise, the result is undefined.
Example:
#include <sys/mount.h> umount2("/mnt", MNT_FORCE); umount2("/dev/hdd1", 0);
After the filesystem is unmounted, the directory that was the mount point is visible, as are any files in it.
As part of unmounting, umount2
syncs the filesystem.
If the unmounting is successful, the return value is zero. Otherwise, it
is -1
and errno
is set accordingly:
EPERM
EBUSY
MNT_FORCE
option.
EINVAL
This function is not available on all systems.
umount
does the same thing as umount2
with flags set
to zeroes. It is more widely available than umount2
but since it
lacks the possibility to forcefully unmount a filesystem is deprecated
when umount2
is also available.
Go to the first, previous, next, last section, table of contents.