.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH PATH_RESOLUTION 7 2009-12-05 "Linux" "Linux Programmer's Manual"
+.TH PATH_RESOLUTION 7 2017-11-26 "Linux" "Linux Programmer's Manual"
.SH NAME
path_resolution \- how a pathname is resolved to a file
.SH DESCRIPTION
.B CLONE_NEWNS
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.
It can be changed by use of the
.BR chdir (2)
system call.)
-
+.PP
Pathnames starting with a \(aq/\(aq character are called absolute pathnames.
Pathnames not starting with a \(aq/\(aq are called relative pathnames.
.SS Step 2: walk along the path
Now, for each nonfinal component of the pathname, where a component
is a substring delimited by \(aq/\(aq characters, this component is looked up
in the current lookup directory.
-
+.PP
If the process does not have search permission on
the current lookup directory,
an
.B EACCES
error is returned ("Permission denied").
-
+.PP
If the component is not found, an
.B ENOENT
error is returned
("No such file or directory").
-
+.PP
If the component is found, but is neither a directory nor a symbolic link,
an
.B ENOTDIR
error is returned ("Not a directory").
-
+.PP
If the component is found and is a directory, we set the
current lookup directory to that directory, and go to the
next component.
-
+.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).
If the resolution of the symlink 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 involves recursion.
+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
.B ELOOP
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
+As currently implemented on Linux, the maximum number
+.\" MAXSYMLINKS is 40
+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
+.\" MAX_NESTED_LINKS
+was raised to 8.
+In Linux 4.2,
+.\" commit 894bc8c4662ba9daceafe943a5ba0dd407da5cd3
+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.
.SS Step 3: find the final entry
The lookup of the final component of the pathname goes just like
that of all other components, as described in the previous step,
By convention, every directory has the entries "." and "..",
which refer to the directory itself and to its parent directory,
respectively.
-
+.PP
The path resolution process will assume that these entries have
their conventional meanings, regardless of whether they are
-actually present in the physical file system.
-
+actually present in the physical filesystem.
+.PP
One cannot walk down past the root: "/.." is the same as "/".
.SS Mount points
After a "mount dev path" command, the pathname "path" refers to
-the root of the file system hierarchy on the device "dev", and no
+the root of the filesystem hierarchy on the device "dev", and no
longer to whatever it referred to earlier.
-
-One can walk out of a mounted file system: "path/.." refers to
+.PP
+One can walk out of a mounted filesystem: "path/.." refers to
the parent directory of "path",
-outside of the file system hierarchy on "dev".
+outside of the filesystem hierarchy on "dev".
.SS Trailing slashes
If a pathname ends in a \(aq/\(aq, that forces resolution of the preceding
component as in Step 2: it has to exist and resolve to a directory.
-Otherwise a trailing \(aq/\(aq is ignored.
+Otherwise, a trailing \(aq/\(aq is ignored.
(Or, equivalently, a pathname with a trailing \(aq/\(aq is equivalent to
the pathname obtained by appending \(aq.\(aq to it.)
.SS Final symlink
.B ENOENT
in this case.
.SS Permissions
-The permission bits of a file consist of three groups of three bits, cf.\&
+The permission bits of a file consist of three groups of three bits; see
.BR chmod (1)
and
.BR stat (2).
supplementary group IDs of the calling process (as set by
.BR setgroups (2)).
When neither holds, the third group is used.
-
+.PP
Of the three bits used, the first bit determines read permission,
the second write permission, and the last execute permission
in case of ordinary files, or search permission in case of directories.
-
+.PP
Linux uses the fsuid instead of the effective user ID in permission checks.
Ordinarily the fsuid will equal the effective user ID, but the fsuid can be
changed by the system call
.BR setfsuid (2).
-
-(Here "fsuid" stands for something like "file system user ID".
+.PP
+(Here "fsuid" stands for something like "filesystem user ID".
The concept was required for the implementation of a user space
NFS server at a time when processes could send a signal to a process
with the same effective user ID.
It is obsolete now.
Nobody should use
.BR setfsuid (2).)
-
-Similarly, Linux uses the fsgid ("file system group ID")
+.PP
+Similarly, Linux uses the fsgid ("filesystem group ID")
instead of the effective group ID.
See
.BR setfsgid (2).
-.\" FIXME say something about file system mounted read-only ?
+.\" FIXME . say something about filesystem mounted read-only ?
.SS Bypassing permission checks: superuser and capabilities
On a traditional UNIX system, the superuser
.RI ( root ,
.\" 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)
-
+.PP
On Linux, superuser privileges are divided into capabilities (see
.BR capabilities (7)).
Two capabilities are relevant for file permissions checks:
-\fBCAP_DAC_OVERRIDE\fP and \fBCAP_DAC_READ_SEARCH\fP.
+.B CAP_DAC_OVERRIDE
+and
+.BR CAP_DAC_READ_SEARCH .
(A process has these capabilities if its fsuid is 0.)
-
-The \fBCAP_DAC_OVERRIDE\fP capability overrides all permission checking,
-but only grants execute permission when at least one
+.PP
+The
+.B CAP_DAC_OVERRIDE
+capability overrides all permission checking,
+but grants execute permission only when at least one
of the file's three execute permission bits is set.
-
-The \fBCAP_DAC_READ_SEARCH\fP capability grants read and search permission
+.PP
+The
+.B CAP_DAC_READ_SEARCH
+capability grants read and search permission
on directories, and read permission on ordinary files.
-.\" FIXME say something about immutable files
-.\" FIXME say something about ACLs
+.\" FIXME . say something about immutable files
+.\" FIXME . say something about ACLs
.SH SEE ALSO
.BR readlink (2),
.BR capabilities (7),