.\" Copyright (C) 2003 Andries Brouwer (aeb@cwi.nl) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2005 Yuichi SATO .\" all rights reserved. .\" Translated 2005-01-26, Yuichi SATO .\" Updated and Modified 2005-10-27, Akihiro MOTOKI .\" Updated and Modified 2005-11-04, Akihiro MOTOKI .\" .TH PATH_RESOLUTION 7 2020\-04\-11 Linux "Linux Programmer's Manual" .SH 名前 path_resolution \- ファイルのパス名の解決方法 .SH 説明 いくつかの UNIX/Linux システムコールは、 1 つ以上のファイル名を引数として持つ。 ファイル名 (またはパス名) は以下のようにして解決される。 .SS "ステップ 1: 解決過程を開始する" If the pathname starts with the \(aq/\(aq character, the starting lookup directory is the root directory of the calling process. A process inherits its root directory from its parent. Usually this will be the root directory of the file hierarchy. A process may get a different root directory by use of the \fBchroot\fP(2) system call, or may temporarily use a different root directory by using \fBopenat2\fP(2) with the \fBRESOLVE_IN_ROOT\fP flag set. .PP A process may get an entirely private mount namespace in case it\(emor one of its ancestors\(emwas started by an invocation of the \fBclone\fP(2) system call that had the \fBCLONE_NEWNS\fP flag set. This handles the \(aq/\(aq part of the pathname. .PP If the pathname does not start with the \(aq/\(aq character, the starting lookup directory of the resolution process is the current working directory of the process \(em or in the case of \fBopenat\fP(2)\-style system calls, the \fIdfd\fP argument (or the current working directory if \fBAT_FDCWD\fP is passed as the \fIdfd\fP argument). The current working directory is inherited from the parent, and can be changed by use of the \fBchdir\fP(2) system call.) .PP \(aq/\(aq 文字で始まるパス名は絶対パス名と呼ばれ、 \(aq/\(aq 文字で始まらないパス名は相対パス名と呼ばれる。 .SS "ステップ 2: パスを辿る" 現在の検索ディレクトリをディレクトリ検索の開始点とする。 そして、パス名の最後の構成要素 (component) でない各構成要素について、 現在の検索ディレクトリで検索を行う。 ここで構成要素は \(aq/\(aq で区切られた部分文字列である。 .PP プロセスが現在の検索ディレクトリの検索許可を持たない場合、 \fBEACCES\fP エラーが返される ("Permission denied")。 .PP 構成要素が見つからない場合、 \fBENOENT\fP エラーが返される ("No such file or directory")。 .PP 構成要素は見つかったが、ディレクトリでもシンボリックリンクでもない場合、 \fBENOTDIR\fP エラーが返される ("Not a directory")。 .PP 構成要素が見つかって、かつディレクトリである場合、 現在の検索ディレクトリをそのディレクトリに設定し、 次の構成要素に移動する。 .PP If the component is found and is a symbolic link (symlink), we first resolve this symbolic link (with the current lookup directory as starting lookup directory). Upon error, that error is returned. If the result is not a directory, an \fBENOTDIR\fP error is returned. If the resolution of the symbolic link is successful and returns a directory, we set the current lookup directory to that directory, and go to the next component. Note that the resolution process here can involve recursion if the prefix ('dirname') component of a pathname contains a filename that is a symbolic link that resolves to a directory (where the prefix component of that directory may contain a symbolic link, and so on). In order to protect the kernel against stack overflow, and also to protect against denial of service, there are limits on the maximum recursion depth, and on the maximum number of symbolic links followed. An \fBELOOP\fP error is returned when the maximum is exceeded ("Too many levels of symbolic links"). .PP .\" .\" presently: max recursion depth during symlink resolution: 5 .\" max total number of symbolic links followed: 40 .\" _POSIX_SYMLOOP_MAX is 8 .\" MAXSYMLINKS is 40 .\" MAX_NESTED_LINKS .\" commit 894bc8c4662ba9daceafe943a5ba0dd407da5cd3 As currently implemented on Linux, the maximum number of symbolic links that will be followed while resolving a pathname is 40. In kernels before 2.6.18, the limit on the recursion depth was 5. Starting with Linux 2.6.18, this limit was raised to 8. In Linux 4.2, the kernel's pathname\-resolution code was reworked to eliminate the use of recursion, so that the only limit that remains is the maximum of 40 resolutions for the entire pathname. .PP The resolution of symbolic links during this stage can be blocked by using \fBopenat2\fP(2), with the \fBRESOLVE_NO_SYMLINKS\fP flag set. .SS "ステップ 3: 最後のエントリーを見つける" パス名の最後の構成要素の検索は、前のステップで説明した 他の全ての構成要素と同じように実行されるが、2 つの違いがある。 (i) 最後の構成要素はディレクトリである必要がない (パス解決過程に関する限りはどちらでも構わない \(em 特定のシステムコールが要求するものによって、 ディレクトリでなければならない場合もあるし、 ディレクトリ以外でなければならない場合もある)。 (ii) 構成要素が見つからない場合にエラーにする必要はない \(em その構成要素を作成するだけでよい場合もある。 最後のエントリーの詳細な扱いは、 特定のシステムコールの man ページで説明されている。 .SS ". と .." 慣習として、全てのディレクトリはエントリー "." と ".." を持つ。 これらはそれぞれ、そのディレクトリ自身とその親ディレクトリを参照する。 .PP パス解決過程では、これらのエントリーが物理的なファイルシステムに 実際に存在するか否かに関わらず、慣習的な意味を持つと仮定する。 .PP ルートより上に辿ることはできない: "/.." は "/" と同じである。 .SS マウント位置 "mount dev path" コマンドを実行した後、 パス名 "path" はデバイス "dev" 上のファイルシステム階層の ルートディレクトリを参照するようになり、以前の位置を参照しない。 .PP マウントされたファイルシステムの外に出ることができる: "path/.." は "dev" 上のファイルシステム階層の外である "path" の親ディレクトリを参照する。 .PP Traversal of mount points can be blocked by using \fBopenat2\fP(2), with the \fBRESOLVE_NO_XDEV\fP flag set (though note that this also restricts bind mount traversal). .SS 末尾のスラッシュ パス名が \(aq/\(aq で終わっている場合、 ステップ 2 において、その前にある構成要素の解決法を次のように強制する: その構成要素が存在しなければならず、ディレクトリとして解決される。 存在しない場合は、末尾の \(aq/\(aq が無視される。 (また同様に、末尾に \(aq/\(aq があるパス名は、 \(aq.\(aq を末尾に加えて得られるパス名と等しい。) .SS 最後がシンボリックリンクのとき パス名の最後の構成要素がシンボリックリンクである場合、 参照されるファイルをシンボリックリンクとするか、 その内容についてパスを解決した結果とするかは、 システムコールに依存する。 たとえば、システムコール \fBlstat\fP(2) はシンボリックリンクに作用する。 一方、 \fBstat\fP(2) はシンボリックリンクで指されたファイルに作用する。 .SS 長さの制限 パス名には最大長がある。 パス名 (またはシンボリックリンクを解決するときに得られる中間パス名) が 長すぎる場合、 \fBENAMETOOLONG\fP エラーが返される ("Filename too long")。 .SS 空のパス名 元々の UNIX では、空のパス名は現在のディレクトリを参照していた。 最近、POSIX では空のパス名を解決するべきではないという決定がなされた。 この場合、Linux は \fBENOENT\fP を返す。 .SS 許可 The permission bits of a file consist of three groups of three bits; see \fBchmod\fP(1) and \fBstat\fP(2). The first group of three is used when the effective user ID of the calling process equals the owner ID of the file. The second group of three is used when the group ID of the file either equals the effective group ID of the calling process, or is one of the supplementary group IDs of the calling process (as set by \fBsetgroups\fP(2)). When neither holds, the third group is used. .PP 3 ビットが使われる場合、最初のビットは読み込み許可を決定し、 2 番目のビットは書き込み許可を決定する。 また 3 番目のビットは、通常のファイルの場合は実行許可を表し、 ディレクトリの場合は検索許可を表す。 .PP Linux は、許可のチェックにおいて、実効ユーザー ID ではなく fsuid を使う。 通常は fsuid は実効ユーザー ID と等しいが、fsuid はシステムコール \fBsetfsuid\fP(2) で変更することができる。 .PP (ここで "fsuid" は "file system user ID" を表している。 この概念は「プロセスが同じ実効ユーザー ID を持つプロセスに 同時にシグナルを送ることができる」というユーザー空間 NFS サーバを 実装する際に必要であった。 これは今では廃れてしまった。 \fBsetfsuid\fP(2) を使うべきではない。 .PP .\" FIXME . say something about filesystem mounted read-only ? 同様に、Linux では実効グループ ID の代わりに fsgid ("ファイルシステムグループID") を使う。 \fBsetfsgid\fP(2) を参照すること。 .SS "許可の確認をスキップする: スーパーユーザーとケーパビリティ" .\" (but for exec at least one x bit must be set) -- AEB .\" but there is variation across systems on this point: for .\" example, HP-UX and Tru64 are as described by AEB. However, .\" on some implementations (e.g., Solaris, FreeBSD), .\" access(X_OK) by superuser will report success, regardless .\" of the file's execute permission bits. -- MTK (Oct 05) 伝統的な UNIX システムでは、スーパーユーザー (\fIroot\fP, ユーザー ID 0) は非常に強力であり、ファイルアクセス時の 許可による制限を全てスキップする。 .PP Linux では、スーパーユーザー権限が複数のケーパビリティに分割されている (\fBcapabilities\fP(7) 参照)。ファイルの許可の確認には、 \fBCAP_DAC_OVERRIDE\fP と \fBCAP_DAC_READ_SEARCH\fP の 2つのケーパビリティが関係する (プロセスの fsuid が 0 の場合、そのプロセスはこれらのケーパビリティを持つ)。 .PP \fBCAP_DAC_OVERRIDE\fP ケーパビリティは全ての許可チェックを上書きする。 実際には、対象となるファイルの 3 つの実行許可ビットのうちの 少なくとも 1 つが設定されている場合のみ、実行を許可する。 .PP .\" FIXME . say something about immutable files .\" FIXME . say something about ACLs \fBCAP_DAC_READ_SEARCH\fP ケーパビリティは、ディレクトリに対して読み込みと検索を許可し、 通常のファイルに対して読み込みを許可する。 .SH 関連項目 \fBreadlink\fP(2), \fBcapabilities\fP(7), \fBcredentials\fP(7), \fBsymlink\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。