umount() — Remove a virtual file system

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both  

Format

#include <sys/stat.h>

int umount(const char *filesystem, mtm_t mtm);

General description

Removes a file system from the file hierarchy, or changes the mount mode of a mounted file system between read-only and read/write. The filesystem argument is a NULL-terminated string containing the file-system name. This is the same name that was specified when the file system was mounted.

In order to umount a file system, the caller must be an authorized program, or must be running for a user with appropriate privileges.

The mtm argument can be one of the following:
MTM_UMOUNT
A normal unmount request. If the files in the named file system are not in use, the unmount is done. Otherwise, the request is rejected.
MTM_DRAIN
An unmount drain request. The requester is willing to wait for all uses of this file system to be ended normally before the file system is unmounted.
MTM_IMMED
An immediate unmount request. The file system is unmounted immediately, forcing any users of files in the specified file system to fail. All data changes that were made up to the time of the request are saved. If there is a problem saving the data, the unmount request fails.
MTM_FORCE
A forced unmount request. The file system is unmounted immediately, forcing any users of any files in the specified file system to fail. All data changes that were made up to the time of the request are saved. If there is a problem saving the data, the request continues, and the data may be lost. To prevent lost data, issue an immediate umount() request before issuing a forced umount() request.
MTM_RESET
A reset unmount request. This allows a previous unmount drain request to be stopped.
MTM_REMOUNT
A remount request. This changes the mount mode of a file system from read-only to read/write or from read/write to read-only. If neither MTM_RDONLY nor MTM_RDWR is specified, the mode is set to the opposite of its current state. If a mode is specified, it must be the opposite of the current state.
MTM_SAMEMODE
A remount request to unmount and mount back without changing the mount mode. If either MTM_RDONLY or MTM_RDWR is also specified, it must be the current state. This can be used to attempt to regain use of a file system that has had I/O errors.

Returned value

If successful, umount() returns 0.

If unsuccessful, umount() returns -1 and sets errno to one of the following values:
Error Code
Description
EBUSY
The file system is busy, for one of these reasons:
  • A umount() (MTM_UMOUNT) was requested, and the file system still has open files or other file systems mounted under it.
  • A file system is currently mounted on the requested file system.
  • A RESET was requested, and the previous umount() request was either immediate or forced, instead of a drain request.
  • There is a umount() request already in progress for the specified file system.
  • A umount() drain request is being reset.
EINTR
umount() was interrupted by a signal.
EINVAL
A parameter was incorrectly specified. Verify the spelling of the file-system name and the setting of mtm.
EIO
An I/O error occurred.
EPERM
Superuser authority is required to issue an unmount.

Example

CELEBU02
/* CELEBU02

   This example removes a file, using umount().

 */
#define _OPEN_SYS 1
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>

main() {
  char HFS[]="POSIX.NEW.HFS";
  char filesystype[9]="HFS     ";
  setvbuf(stdout, NULL, _IOLBF, 0);
  puts("before umount()");
  system("df -Pk");
  if (umount(HFS, MTM_UMOUNT) != 0)
    perror("umount() error");
  else {
    puts("After umount()");
    system("df -Pk");
  }
}
Output
before umount()
Filesystem   1024-blocks        Used  Available  Capacity     Mounted on
POSIX.NEW.HFS        200          20        180       10%     /new_fs
POSIX.ROOT.FS       9600        8180       1420       85%     /

After umount()
Filesystem   1024-blocks        Used  Available  Capacity     Mounted on
POSIX.ROOT.FS       9600        8180       1420       85%     /