1 .\" Copyright (C) 2003 Andries Brouwer (aeb@cwi.nl)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH PATH_RESOLUTION 7 2021-08-27 "Linux" "Linux Programmer's Manual"
27 path_resolution \- how a pathname is resolved to a file
29 Some UNIX/Linux system calls have as parameter one or more filenames.
30 A filename (or pathname) is resolved as follows.
31 .SS Step 1: start of the resolution process
32 If the pathname starts with the \(aq/\(aq character, the starting lookup
33 directory is the root directory of the calling process.
34 A process inherits its root directory from its parent.
35 Usually this will be the root directory of the file hierarchy.
36 A process may get a different root directory by use of the
38 system call, or may temporarily use a different root directory by using
44 A process may get an entirely private mount namespace in case
45 it\(emor one of its ancestors\(emwas started by an invocation of the
47 system call that had the
50 This handles the \(aq/\(aq part of the pathname.
52 If the pathname does not start with the \(aq/\(aq character, the starting
53 lookup directory of the resolution process is the current working directory of
54 the process \(em or in the case of
58 argument (or the current working directory if
63 The current working directory is inherited from the parent, and can
64 be changed by use of the
68 Pathnames starting with a \(aq/\(aq character are called absolute pathnames.
69 Pathnames not starting with a \(aq/\(aq are called relative pathnames.
70 .SS Step 2: walk along the path
71 Set the current lookup directory to the starting lookup directory.
72 Now, for each nonfinal component of the pathname, where a component
73 is a substring delimited by \(aq/\(aq characters, this component is looked up
74 in the current lookup directory.
76 If the process does not have search permission on
77 the current lookup directory,
80 error is returned ("Permission denied").
82 If the component is not found, an
85 ("No such file or directory").
87 If the component is found, but is neither a directory nor a symbolic link,
90 error is returned ("Not a directory").
92 If the component is found and is a directory, we set the
93 current lookup directory to that directory, and go to the
96 If the component is found and is a symbolic link (symlink), we first
97 resolve this symbolic link (with the current lookup directory
98 as starting lookup directory).
99 Upon error, that error is returned.
100 If the result is not a directory, an
103 If the resolution of the symbolic link is successful and returns a directory,
104 we set the current lookup directory to that directory, and go to
106 Note that the resolution process here can involve recursion if the
107 prefix ('dirname') component of a pathname contains a filename
108 that is a symbolic link that resolves to a directory (where the
109 prefix component of that directory may contain a symbolic link, and so on).
110 In order to protect the kernel against stack overflow, and also
111 to protect against denial of service, there are limits on the
112 maximum recursion depth, and on the maximum number of symbolic links
116 error is returned when the maximum is
117 exceeded ("Too many levels of symbolic links").
120 .\" presently: max recursion depth during symlink resolution: 5
121 .\" max total number of symbolic links followed: 40
122 .\" _POSIX_SYMLOOP_MAX is 8
123 As currently implemented on Linux, the maximum number
124 .\" MAXSYMLINKS is 40
125 of symbolic links that will be followed while resolving a pathname is 40.
126 In kernels before 2.6.18, the limit on the recursion depth was 5.
127 Starting with Linux 2.6.18, this limit
131 .\" commit 894bc8c4662ba9daceafe943a5ba0dd407da5cd3
132 the kernel's pathname-resolution code
133 was reworked to eliminate the use of recursion,
134 so that the only limit that remains is the maximum of 40
135 resolutions for the entire pathname.
137 The resolution of symbolic links during this stage can be blocked by using
140 .B RESOLVE_NO_SYMLINKS
142 .SS Step 3: find the final entry
143 The lookup of the final component of the pathname goes just like
144 that of all other components, as described in the previous step,
145 with two differences: (i) the final component need not be a
146 directory (at least as far as the path resolution process is
147 concerned\(emit may have to be a directory, or a nondirectory, because of
148 the requirements of the specific system call), and (ii) it
149 is not necessarily an error if the component is not found\(emmaybe
150 we are just creating it.
151 The details on the treatment
152 of the final entry are described in the manual pages of the specific
155 By convention, every directory has the entries "." and "..",
156 which refer to the directory itself and to its parent directory,
159 The path resolution process will assume that these entries have
160 their conventional meanings, regardless of whether they are
161 actually present in the physical filesystem.
163 One cannot walk up past the root: "/.." is the same as "/".
165 After a "mount dev path" command, the pathname "path" refers to
166 the root of the filesystem hierarchy on the device "dev", and no
167 longer to whatever it referred to earlier.
169 One can walk out of a mounted filesystem: "path/.." refers to
170 the parent directory of "path",
171 outside of the filesystem hierarchy on "dev".
173 Traversal of mount points can be blocked by using
177 flag set (though note that this also restricts bind mount traversal).
179 If a pathname ends in a \(aq/\(aq, that forces resolution of the preceding
180 component as in Step 2:
181 the component preceding the slash either exists and resolves to a directory
182 or it names a directory that is to be created
183 immediately after the pathname is resolved.
184 Otherwise, a trailing \(aq/\(aq is ignored.
186 If the last component of a pathname is a symbolic link, then it
187 depends on the system call whether the file referred to will be
188 the symbolic link or the result of path resolution on its contents.
189 For example, the system call
191 will operate on the symlink, while
193 operates on the file pointed to by the symlink.
195 There is a maximum length for pathnames.
196 If the pathname (or some
197 intermediate pathname obtained while resolving symbolic links)
200 error is returned ("Filename too long").
202 In the original UNIX, the empty pathname referred to the current directory.
203 Nowadays POSIX decrees that an empty pathname must not be resolved
209 The permission bits of a file consist of three groups of three bits; see
213 The first group of three is used when the effective user ID of
214 the calling process equals the owner ID of the file.
216 of three is used when the group ID of the file either equals the
217 effective group ID of the calling process, or is one of the
218 supplementary group IDs of the calling process (as set by
220 When neither holds, the third group is used.
222 Of the three bits used, the first bit determines read permission,
223 the second write permission, and the last execute permission
224 in case of ordinary files, or search permission in case of directories.
226 Linux uses the fsuid instead of the effective user ID in permission checks.
227 Ordinarily the fsuid will equal the effective user ID, but the fsuid can be
228 changed by the system call
231 (Here "fsuid" stands for something like "filesystem user ID".
232 The concept was required for the implementation of a user space
233 NFS server at a time when processes could send a signal to a process
234 with the same effective user ID.
239 Similarly, Linux uses the fsgid ("filesystem group ID")
240 instead of the effective group ID.
243 .\" FIXME . say something about filesystem mounted read-only ?
244 .SS Bypassing permission checks: superuser and capabilities
245 On a traditional UNIX system, the superuser
247 user ID 0) is all-powerful, and bypasses all permissions restrictions
248 when accessing files.
249 .\" (but for exec at least one x bit must be set) -- AEB
250 .\" but there is variation across systems on this point: for
251 .\" example, HP-UX and Tru64 are as described by AEB. However,
252 .\" on some implementations (e.g., Solaris, FreeBSD),
253 .\" access(X_OK) by superuser will report success, regardless
254 .\" of the file's execute permission bits. -- MTK (Oct 05)
256 On Linux, superuser privileges are divided into capabilities (see
257 .BR capabilities (7)).
258 Two capabilities are relevant for file permissions checks:
261 .BR CAP_DAC_READ_SEARCH .
262 (A process has these capabilities if its fsuid is 0.)
266 capability overrides all permission checking,
267 but grants execute permission only when at least one
268 of the file's three execute permission bits is set.
271 .B CAP_DAC_READ_SEARCH
272 capability grants read and search permission
273 on directories, and read permission on ordinary files.
274 .\" FIXME . say something about immutable files
275 .\" FIXME . say something about ACLs
278 .BR capabilities (7),