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 exceeded ("Too  many  levels  of  symbolic
69       links").
70
71       As currently implemented on Linux, the maximum number of symbolic links
72       that will be followed while resolving a pathname is 40.   Before  Linux
73       2.6.18,  the  limit  on the recursion depth was 5.  Starting with Linux
74       2.6.18, this limit was raised to 8.  In Linux 4.2, the  kernel's  path‐
75       name-resolution code was reworked to eliminate the use of recursion, so
76       that the only limit that remains is the maximum of 40  resolutions  for
77       the entire pathname.
78
79       The  resolution  of  symbolic links during this stage can be blocked by
80       using openat2(2), with the RESOLVE_NO_SYMLINKS flag set.
81
82   Step 3: find the final entry
83       The lookup of the final component of the pathname goes just  like  that
84       of  all  other  components, as described in the previous step, with two
85       differences: (i) the final component need not be a directory (at  least
86       as  far as the path resolution process is concerned—it may have to be a
87       directory, or a nondirectory, because of the requirements of  the  spe‐
88       cific system call), and (ii) it is not necessarily an error if the com‐
89       ponent is not found—maybe we are just creating it.  The details on  the
90       treatment  of  the final entry are described in the manual pages of the
91       specific system calls.
92
93   . and ..
94       By convention, every directory has the entries "." and "..", which  re‐
95       fer to the directory itself and to its parent directory, respectively.
96
97       The  path  resolution process will assume that these entries have their
98       conventional meanings, regardless of whether they are actually  present
99       in the physical filesystem.
100
101       One cannot walk up past the root: "/.." is the same as "/".
102
103   Mount points
104       After  a mount dev path command, the pathname "path" refers to the root
105       of the filesystem hierarchy on the device "dev", and no longer to what‐
106       ever it referred to earlier.
107
108       One  can walk out of a mounted filesystem: "path/.." refers to the par‐
109       ent directory of "path", outside of the filesystem hierarchy on "dev".
110
111       Traversal of mount points can be blocked by using openat2(2), with  the
112       RESOLVE_NO_XDEV  flag  set  (though  note that this also restricts bind
113       mount traversal).
114
115   Trailing slashes
116       If a pathname ends in a '/', that forces resolution  of  the  preceding
117       component as in Step 2: the component preceding the slash either exists
118       and resolves to a directory or it names a directory that is to be  cre‐
119       ated immediately after the pathname is resolved.  Otherwise, a trailing
120       '/' is ignored.
121
122   Final symbolic link
123       If the last component of a pathname is a symbolic link, then it depends
124       on  the  system  call whether the file referred to will be the symbolic
125       link or the result of path resolution on its  contents.   For  example,
126       the  system  call  lstat(2)  will  operate  on the symbolic link, while
127       stat(2) operates on the file pointed to by the symbolic link.
128
129   Length limit
130       There is a maximum length for pathnames.  If the pathname (or some  in‐
131       termediate  pathname  obtained  while  resolving symbolic links) is too
132       long, an ENAMETOOLONG error is returned ("Filename too long").
133
134   Empty pathname
135       In the original UNIX, the empty pathname referred to the current direc‐
136       tory.   Nowadays  POSIX  decrees that an empty pathname must not be re‐
137       solved successfully.  Linux returns ENOENT in this case.
138
139   Permissions
140       The permission bits of a file consist of three groups  of  three  bits;
141       see  chmod(1)  and  stat(2).  The first group of three is used when the
142       effective user ID of the calling process equals the  owner  ID  of  the
143       file.   The second group of three is used when the group ID of the file
144       either equals the effective group ID of the calling process, or is  one
145       of  the  supplementary group IDs of the calling process (as set by set‐
146       groups(2)).  When neither holds, the third group is used.
147
148       Of the three bits used, the first bit determines read  permission,  the
149       second write permission, and the last execute permission in case of or‐
150       dinary files, or search permission in case of directories.
151
152       Linux uses the fsuid instead of the effective  user  ID  in  permission
153       checks.  Ordinarily the fsuid will equal the effective user ID, but the
154       fsuid can be changed by the system call setfsuid(2).
155
156       (Here "fsuid" stands for something like "filesystem user ID".  The con‐
157       cept  was required for the implementation of a user space NFS server at
158       a time when processes could send a signal to a process  with  the  same
159       effective  user  ID.   It  is  obsolete  now.   Nobody should use setf‐
160       suid(2).)
161
162       Similarly, Linux uses the fsgid ("filesystem group ID") instead of  the
163       effective group ID.  See setfsgid(2).
164
165   Bypassing permission checks: superuser and capabilities
166       On  a  traditional UNIX system, the superuser (root, user ID 0) is all-
167       powerful, and bypasses  all  permissions  restrictions  when  accessing
168       files.
169
170       On Linux, superuser privileges are divided into capabilities (see capa‐
171       bilities(7)).  Two  capabilities  are  relevant  for  file  permissions
172       checks: CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH.  (A process has these
173       capabilities if its fsuid is 0.)
174
175       The CAP_DAC_OVERRIDE capability overrides all permission checking,  but
176       grants  execute  permission  only when at least one of the file's three
177       execute permission bits is set.
178
179       The CAP_DAC_READ_SEARCH capability grants read and search permission on
180       directories, and read permission on ordinary files.
181

SEE ALSO

183       readlink(2), capabilities(7), credentials(7), symlink(7)
184
185
186
187Linux man-pages 6.05              2023-02-05                path_resolution(7)
Impressum