1PATH_RESOLUTION(7)         Linux Programmer's Manual        PATH_RESOLUTION(7)
2
3
4

NAME

6       path_resolution - how a pathname is resolved to a file
7

DESCRIPTION

9       Some  UNIX/Linux  system calls have as parameter one or more filenames.
10       A filename (or pathname) is resolved as follows.
11
12   Step 1: start of the resolution process
13       If the pathname starts with the  '/'  character,  the  starting  lookup
14       directory  is  the  root  directory of the calling process.  (A process
15       inherits its root directory from its parent.  Usually this will be  the
16       root  directory  of  the file hierarchy.  A process may get a different
17       root directory by use of the chroot(2) system call.  A process may  get
18       an entirely private mount namespace in case it—or one of its ancestors—
19       was started by an invocation of the clone(2) system call that  had  the
20       CLONE_NEWNS flag set.)  This handles the '/' part of the pathname.
21
22       If  the  pathname  does  not start with the '/' character, the starting
23       lookup directory of the  resolution  process  is  the  current  working
24       directory of the process.  (This is also inherited from the parent.  It
25       can be changed by use of the chdir(2) system call.)
26
27       Pathnames starting with a '/' character are called absolute  pathnames.
28       Pathnames not starting with a '/' are called relative pathnames.
29
30   Step 2: walk along the path
31       Set  the  current  lookup  directory  to the starting lookup directory.
32       Now, for each nonfinal component of the pathname, where a component  is
33       a substring delimited by '/' characters, this component is looked up in
34       the current lookup directory.
35
36       If the process does not have search permission on  the  current  lookup
37       directory, an EACCES error is returned ("Permission denied").
38
39       If  the  component  is not found, an ENOENT error is returned ("No such
40       file or directory").
41
42       If the component is found, but is neither a directory  nor  a  symbolic
43       link, an ENOTDIR error is returned ("Not a directory").
44
45       If the component is found and is a directory, we set the current lookup
46       directory to that directory, and go to the next component.
47
48       If the component is found and is a symbolic link  (symlink),  we  first
49       resolve this symbolic link (with the current lookup directory as start‐
50       ing lookup directory).  Upon error, that error  is  returned.   If  the
51       result  is not a directory, an ENOTDIR error is returned.  If the reso‐
52       lution of the symlink is successful and returns a directory, we set the
53       current  lookup  directory to that directory, and go to the next compo‐
54       nent.  Note that the resolution process here  involves  recursion.   In
55       order to protect the kernel against stack overflow, and also to protect
56       against denial of service, there are limits on  the  maximum  recursion
57       depth,  and on the maximum number of symbolic links followed.  An ELOOP
58       error is returned when the maximum is exceeded  ("Too  many  levels  of
59       symbolic links").
60
61   Step 3: find the final entry
62       The  lookup  of the final component of the pathname goes just like that
63       of all other components, as described in the previous  step,  with  two
64       differences:  (i) the final component need not be a directory (at least
65       as far as the path resolution process is concerned—it may have to be  a
66       directory,  or  a nondirectory, because of the requirements of the spe‐
67       cific system call), and (ii) it is not necessarily an error if the com