Scroll to navigation

UMOUNT(2) Linux Programmer's Manual UMOUNT(2)

名前

umount, umount2 - ファイルシステムをアンマウントする

書式

#include <sys/mount.h>
int umount(const char *target);
int umount2(const char *target, int flags);

説明

umount() と umount2() は target にマウントされている (最上位の) ファイルシステムを外す。

ファイルシステムのアンマウントを行うには、 適切な権限 (Linux では CAP_SYS_ADMIN ケーパビリティ) が必要である。

Linux 2.1.116 から、 umount2() システムコールが追加された。これは umount() と同様に target をアンマウントするが、 flags が追加されており、操作時の振る舞いを制御できる。

Ask the filesystem to abort pending requests before attempting the unmount. This may allow the unmount to complete without waiting for an inaccessible server, but could cause data loss. If, after aborting requests, some processes still have active references to the filesystem, the unmount will still fail. As at Linux 4.12, MNT_FORCE is supported only on the following filesystems: 9p (since Linux 2.6.16), ceph (since Linux 2.6.34), cifs (since Linux 2.6.12), fuse (since Linux 2.6.16), lustre (since Linux 3.11), and NFS (since Linux 2.1.116).
Perform a lazy unmount: make the mount point unavailable for new accesses, immediately disconnect the filesystem and all filesystems mounted below it from each other and from the mount table, and actually perform the unmount when the mount point ceases to be busy.
マウントポイントに期限切れの印をつける。 マウントポイントが現在使用中でない場合、このフラグをつけて umount2() を初めて呼び出すと EAGAIN エラーで失敗するが、マウントポイントには期限切れ (expire) の印がつけられる。 そのマウントポイントはいずれかのプロセスがアクセスしない限り 期限切れの印がついたままとなる。 もう一度 MNT_EXPIRE をつけて umount2() を呼び出すと、期限切れの印のついたマウントポイントが アンマウントされる。 このフラグを MNT_FORCE もしくは MNT_DETACH と同時に指定することはできない。
target がシンボリックリンクの場合に、シンボリックリンクの展開を行わない。 このフラグを使うと、 root に set-user-ID されたプログラムにおいて、 非特権ユーザーがファイルシステムのアンマウントをできてしまうという セキュリティ問題を回避することができる。

返り値

成功した場合、0 が返される。 失敗した場合、 -1 が返され、 errno に適切な値がセットされる。

エラー

以下に示すエラーは、ファイルシステムに依存しないものである。 それぞれのファイルシステムタイプには固有のエラーが存在する場合があり、 独自の動作をすることもある。詳しくは Linux カーネルのソースを見て欲しい。

MNT_EXPIRE を指定した umount2() の呼び出しで、正常に未使用のファイルシステムに期限切れの印を つけることができた。
使用中 (busy) のため、 target をアンマウントできなかった。
target がユーザーアドレス空間の外を指している。
target がマウントポイントではない。
MNT_EXPIRE が指定された umount2() で、 MNT_DETACHMNT_FORCE が同時に指定された。
flags に無効なフラグが指定されて umount2() が呼び出された。
パス名の長さが MAXPATHLEN より長かった。
パス名が空である。もしくは指定されたパスが存在しない。
カーネルがファイル名やデータをコピーするための空きページを確保できなかった。
呼び出し元が必要な権限を持っていない。

バージョン

MNT_DETACHMNT_EXPIRE はバージョン 2.11 以降の glibc で利用できる。

準拠

この関数は Linux 固有の関数であり、移植を考慮したプログラムでは 使用すべきでない。

注意

umount() and shared mount points

Shared mount points cause any mount activity on a mount point, including umount() operations, to be forwarded to every shared mount point in the peer group and every slave mount of that peer group. This means that umount() of any peer in a set of shared mounts will cause all of its peers to be unmounted and all of their slaves to be unmounted as well.

This propagation of unmount activity can be particularly surprising on systems where every mount point is shared by default. On such systems, recursively bind mounting the root directory of the filesystem onto a subdirectory and then later unmounting that subdirectory with MNT_DETACH will cause every mount in the mount namespace to be lazily unmounted.

To ensure umount() does not propagate in this fashion, the mount point may be remounted using a mount(2) call with a mount_flags argument that includes both MS_REC and MS_PRIVATE prior to umount() being called.

Historical details

元々の umount() 関数は umount(device) の形で呼び出され、 ブロックデバイス以外を指定して呼び出すと ENOTBLK を返した。 Linux 0.98p4 で、無名デバイス (anonymous device) に対応するために umount(dir) の形での呼び出しが加えられた。 Linux 2.3.99-pre7 で、umount(device) は削除され、 umount(dir) だけが残された (一つのデバイスを複数の位置にマウント出来るようになったため、 デバイスを指定しただけでは不十分だからである)。

関連項目

mount(2), mount_namespaces(7), path_resolution(7), mount(8), umount(8)

この文書について

この man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

2020-06-09 Linux