Node:Mount-Unmount-Remount, Previous:Mount Information, Up:Filesystem Handling
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 Mount Information.
The symbols in this section are declared in sys/mount.h
.
int mount (const char *special_file, const char *dir, const char *fstype, unsigned long int options, const void *data) | Function |
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"), 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 For a remount, 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 options is a bit string with bit fields defined using the following mask and masked value macros:
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 The return value is zero if the mount or remount is successful. Otherwise,
it is
|
int umount2 (const char *file, int flags) | Function |
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:
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, If the unmounting is successful, the return value is zero. Otherwise, it
is
This function is not available on all systems. |
int umount (const char *file) | Function |
|