1path_resolution(7)     Miscellaneous Information 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  di‐
14       rectory is the root directory of the calling process.  A process inher‐
15       its its root directory from its parent.  Usually this will be the  root
16       directory  of  the  file hierarchy.  A process may get a different root
17       directory by use of the chroot(2) system call, or may temporarily use a
18       different  root  directory by using openat2(2) with the RESOLVE_IN_ROOT
19       flag set.
20
21       A process may get an entirely private mount namespace in case it—or one
22       of  its  ancestors—was  started by an invocation of the clone(2) system
23       call that had the CLONE_NEWNS flag set.  This handles the '/'  part  of
24       the pathname.
25
26       If  the  pathname  does  not start with the '/' character, the starting
27       lookup directory of the resolution process is the current  working  di‐
28       rectory  of  the  process  —  or  in the case of openat(2)-style system
29       calls, the dfd argument (or the current working directory  if  AT_FDCWD
30       is  passed  as the dfd argument).  The current working directory is in‐
31       herited from the parent, and can be changed by use of the chdir(2) sys‐
32       tem call.
33
34       Pathnames  starting with a '/' character are called absolute pathnames.
35       Pathnames not starting with a '/' are called relative pathnames.
36
37   Step 2: walk along the path
38       Set the current lookup directory  to  the  starting  lookup  directory.
39       Now,  for each nonfinal component of the pathname, where a component is
40       a substring delimited by '/' characters, this component is looked up in
41       the current lookup directory.
42
43       If  the  process  does not have search permission on the current lookup
44       directory, an EACCES error is returned ("Permission denied").
45
46       If the component is not found, an ENOENT error is  returned  ("No  such
47       file or directory").
48
49       If  the  component  is found, but is neither a directory nor a symbolic
50       link, an ENOTDIR error is returned ("Not a directory").
51
52       If the component is found and is a directory, we set the current lookup
53       directory to that directory, and go to the next component.
54
55       If the component is found and is a symbolic link, we first resolve this
56       symbolic link (with the current lookup directory as starting lookup di‐
57       rectory).   Upon error, that error is returned.  If the result is not a
58       directory, an ENOTDIR error is returned.  If the resolution of the sym‐
59       bolic  link  is  successful and returns a directory, we set the current
60       lookup directory to that directory, and go to the next component.  Note
61       that  the  resolution  process here can involve recursion if the prefix
62       ('dirname') component of a pathname contains a filename that is a  sym‐
63       bolic  link that resolves to a directory (where the prefix component of
64       that directory may contain a symbolic link, and so on).   In  order  to
65       protect  the kernel against stack overflow, and also to protect against
66       denial of service, there are limits on the maximum recursion depth, and
67       on  the  maximum  number of symbolic links followed.  An ELOOP error is
68       returned when the maximum is