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

NAME

6       Unix/Linux path resolution - find the file referred to by a filename
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 ances‐
19       tors — was started by an invocation of the clone(2)  system  call  that
20       had  the CLONE_NEWNS flag set.)  This handles the '/' part of the path‐
21       name.
22
23       If the pathname does not start with the  '/'  character,  the  starting
24       lookup  directory  of  the  resolution  process  is the current working
25       directory of the process.  (This is also inherited from the parent.  It
26       can be changed by use of the chdir(2) system call.)
27
28       Pathnames  starting with a '/' character are called absolute pathnames.
29       Pathnames not starting with a '/' are called relative pathnames.
30
31   Step 2: Walk along the path
32       Set the current lookup directory  to  the  starting  lookup  directory.
33       Now, for each non-final component of the pathname, where a component is
34       a substring delimited by '/' characters, this component is looked up in
35       the current lookup directory.
36
37       If  the  process  does not have search permission on the current lookup
38       directory, an EACCES error is returned ("Permission denied").
39
40       If the component is not found, an ENOENT error is  returned  ("No  such
41       file or directory").
42
43       If  the  component  is found, but is neither a directory nor a symbolic
44       link, an ENOTDIR error is returned ("Not a directory").
45
46       If the component is found and is a directory, we set the current lookup
47       directory to that directory, and go to the next component.
48
49       If  the  component  is found and is a symbolic link (symlink), we first
50       resolve this symbolic link (with the current lookup directory as start‐
51       ing  lookup  directory).   Upon  error, that error is returned.  If the
52       result is not a directory, an ENOTDIR error is returned.  If the  reso‐
53       lution of the symlink is successful and returns a directory, we set the
54       current lookup directory to that directory, and go to the  next  compo‐
55       nent.   Note  that  the resolution process here involves recursion.  In
56       order to protect the kernel against stack overflow, and also to protect
57       against  denial  of  service, there are limits on the maximum recursion
58       depth, and on the maximum number of symbolic links followed.  An  ELOOP
59       error  is  returned  when  the maximum is exceeded ("Too many levels of
60       symbolic links").
61
62   Step 3: Find the final entry
63       The lookup of the final component of the pathname goes just  like  that
64       of  all  other  components, as described in the previous step, with two
65       differences: (i) the final component need not be a directory (at  least
66       as  far as the path resolution process is concerned — it may have to be
67       a directory, or a non-directory, because of  the  requirements  of  the
68       specific  system  call), and (ii) it