Linux Programmer's Manual (7)
path_resolution - how a pathname is resolved to a file
Some UNIX/Linux system calls have as parameter one or more filenames.
A filename (or pathname) is resolved as follows.
Step 1: start of the resolution process
If the pathname starts with the '/' 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
A process may get an entirely private mount namespace in case
it---or one of its ancestors---was started by an invocation of the
system call that had the
This handles the '/' part of the pathname.
If the pathname does not start with the '/' character, the
starting lookup directory of the resolution process is the current working
directory of the process.
(This is also inherited from the parent.
It can be changed by use of the
Pathnames starting with a '/' character are called absolute pathnames.
Pathnames not starting with a '/' are called relative pathnames.
Step 2: walk along the path
Set the current lookup directory to the starting lookup directory.
Now, for each nonfinal component of the pathname, where a component
is a substring delimited by '/' characters, this component is looked up
in the current lookup directory.
If the process does not have search permission on
the current lookup directory,
error is returned ("Permission denied").
If the component is not found, an
error is returned
("No such file or directory").
If the component is found, but is neither a directory nor a symbolic link,
error is returned ("Not a directory").
If the component is found and is a directory, we set the
current lookup directory to that directory, and go to the
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
error is returned.
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.
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
error is returned when the maximum is
exceeded ("Too many levels of symbolic links").
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,
with two differences: (i) the final component need not be a
directory (at least as far as the path resolution process is
concerned---it may have to be a directory, or a nondirectory, because of
the requirements of the specific system call), and (ii) it
is not necessarily an error if the component is not found---maybe
we are just creating it.
The details on the treatment
of the final entry are described in the manual pages of the specific
. and ..
By convention, every directory has the entries "." and "..",
which refer to the directory itself and to its parent directory,
The path resolution process will assume that these entries have
their conventional meanings, regardless of whether they are
actually present in the physical filesystem.
One cannot walk down past the root: "/.." is the same as "/".
After a "mount dev path" command, the pathname "path" refers to
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 filesystem: "path/.." refers to
the parent directory of "path",
outside of the filesystem hierarchy on "dev".
If a pathname ends in a '/', that forces resolution of the preceding
component as in Step 2: it has to exist and resolve to a directory.
Otherwise, a trailing '/' is ignored.
(Or, equivalently, a pathname with a trailing '/' is equivalent to
the pathname obtained by appending '.' to it.)
If the last component of a pathname is a symbolic link, then it
depends on the system call whether the file referred to will be
the symbolic link or the result of path resolution on its contents.
For example, the system call
will operate on the symlink, while
operates on the file pointed to by the symlink.
There is a maximum length for pathnames.
If the pathname (or some
intermediate pathname obtained while resolving symbolic links)
is too long, an
error is returned ("Filename too long").
In the original UNIX, the empty pathname referred to the current directory.
Nowadays POSIX decrees that an empty pathname must not be resolved
in this case.
The permission bits of a file consist of three groups of three bits, cf.
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
When neither holds, the third group is used.
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.
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
(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
Similarly, Linux uses the fsgid ("filesystem group ID")
instead of the effective group ID.
Bypassing permission checks: superuser and capabilities
On a traditional UNIX system, the superuser
user ID 0) is all-powerful, and bypasses all permissions restrictions
when accessing files.
On Linux, superuser privileges are divided into capabilities (see
Two capabilities are relevant for file permissions checks:
(A process has these capabilities if its fsuid is 0.)
capability overrides all permission checking,
but grants execute permission only when at least one
of the file's three execute permission bits is set.
capability grants read and search permission
on directories, and read permission on ordinary files.
This page is part of release 3.66 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
- Step 1: start of the resolution process
- Step 2: walk along the path
- Step 3: find the final entry
- . and ..
- Mount points
- Trailing slashes
- Final symlink
- Length limit
- Empty pathname
- Bypassing permission checks: superuser and capabilities
- SEE ALSO
This document was created by
using the manual pages.
Time: 21:43:05 GMT, July 12, 2014