OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man7 / path_resolution.7
1 .\" Copyright (C) 2003 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH PATH_RESOLUTION 7 2009-12-05 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 path_resolution \- how a pathname is resolved to a file
28 .SH DESCRIPTION
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,
33 the starting lookup directory
34 is the root directory of the calling process.
35 (A process inherits its
36 root directory from its parent.
37 Usually this will be the root directory
38 of the file hierarchy.
39 A process may get a different root directory
40 by use of the
41 .BR chroot (2)
42 system call.
43 A process may get an entirely private mount namespace in case
44 it\(emor one of its ancestors\(emwas started by an invocation of the
45 .BR clone (2)
46 system call that had the
47 .B CLONE_NEWNS
48 flag set.)
49 This handles the \(aq/\(aq part of the pathname.
50
51 If the pathname does not start with the \(aq/\(aq character, the
52 starting lookup directory of the resolution process is the current working
53 directory of the process.
54 (This is also inherited from the parent.
55 It can be changed by use of the
56 .BR chdir (2)
57 system call.)
58
59 Pathnames starting with a \(aq/\(aq character are called absolute pathnames.
60 Pathnames not starting with a \(aq/\(aq are called relative pathnames.
61 .SS Step 2: walk along the path
62 Set the current lookup directory to the starting lookup directory.
63 Now, for each nonfinal component of the pathname, where a component
64 is a substring delimited by \(aq/\(aq characters, this component is looked up
65 in the current lookup directory.
66
67 If the process does not have search permission on
68 the current lookup directory,
69 an
70 .B EACCES
71 error is returned ("Permission denied").
72
73 If the component is not found, an
74 .B ENOENT
75 error is returned
76 ("No such file or directory").
77
78 If the component is found, but is neither a directory nor a symbolic link,
79 an
80 .B ENOTDIR
81 error is returned ("Not a directory").
82
83 If the component is found and is a directory, we set the
84 current lookup directory to that directory, and go to the
85 next component.
86
87 If the component is found and is a symbolic link (symlink), we first
88 resolve this symbolic link (with the current lookup directory
89 as starting lookup directory).
90 Upon error, that error is returned.
91 If the result is not a directory, an
92 .B ENOTDIR
93 error is returned.
94 If the resolution of the symlink is successful and returns a directory,
95 we set the current lookup directory to that directory, and go to
96 the next component.
97 Note that the resolution process here involves recursion.
98 In order to protect the kernel against stack overflow, and also
99 to protect against denial of service, there are limits on the
100 maximum recursion depth, and on the maximum number of symbolic links
101 followed.
102 An
103 .B ELOOP
104 error is returned when the maximum is
105 exceeded ("Too many levels of symbolic links").
106 .\"
107 .\" presently: max recursion depth during symlink resolution: 5
108 .\" max total number of symbolic links followed: 40
109 .\" _POSIX_SYMLOOP_MAX is 8
110 .SS Step 3: find the final entry
111 The lookup of the final component of the pathname goes just like
112 that of all other components, as described in the previous step,
113 with two differences: (i) the final component need not be a
114 directory (at least as far as the path resolution process is
115 concerned\(emit may have to be a directory, or a nondirectory, because of
116 the requirements of the specific system call), and (ii) it
117 is not necessarily an error if the component is not found\(emmaybe
118 we are just creating it.
119 The details on the treatment
120 of the final entry are described in the manual pages of the specific
121 system calls.
122 .SS . and ..
123 By convention, every directory has the entries "." and "..",
124 which refer to the directory itself and to its parent directory,
125 respectively.
126
127 The path resolution process will assume that these entries have
128 their conventional meanings, regardless of whether they are
129 actually present in the physical filesystem.
130
131 One cannot walk down past the root: "/.." is the same as "/".
132 .SS Mount points
133 After a "mount dev path" command, the pathname "path" refers to
134 the root of the filesystem hierarchy on the device "dev", and no
135 longer to whatever it referred to earlier.
136
137 One can walk out of a mounted filesystem: "path/.." refers to
138 the parent directory of "path",
139 outside of the filesystem hierarchy on "dev".
140 .SS Trailing slashes
141 If a pathname ends in a \(aq/\(aq, that forces resolution of the preceding
142 component as in Step 2: it has to exist and resolve to a directory.
143 Otherwise, a trailing \(aq/\(aq is ignored.
144 (Or, equivalently, a pathname with a trailing \(aq/\(aq is equivalent to
145 the pathname obtained by appending \(aq.\(aq to it.)
146 .SS Final symlink
147 If the last component of a pathname is a symbolic link, then it
148 depends on the system call whether the file referred to will be
149 the symbolic link or the result of path resolution on its contents.
150 For example, the system call
151 .BR lstat (2)
152 will operate on the symlink, while
153 .BR stat (2)
154 operates on the file pointed to by the symlink.
155 .SS Length limit
156 There is a maximum length for pathnames.
157 If the pathname (or some
158 intermediate pathname obtained while resolving symbolic links)
159 is too long, an
160 .B ENAMETOOLONG
161 error is returned ("Filename too long").
162 .SS Empty pathname
163 In the original UNIX, the empty pathname referred to the current directory.
164 Nowadays POSIX decrees that an empty pathname must not be resolved
165 successfully.
166 Linux returns
167 .B ENOENT
168 in this case.
169 .SS Permissions
170 The permission bits of a file consist of three groups of three bits, cf.\&
171 .BR chmod (1)
172 and
173 .BR stat (2).
174 The first group of three is used when the effective user ID of
175 the calling process equals the owner ID of the file.
176 The second group
177 of three is used when the group ID of the file either equals the
178 effective group ID of the calling process, or is one of the
179 supplementary group IDs of the calling process (as set by
180 .BR setgroups (2)).
181 When neither holds, the third group is used.
182
183 Of the three bits used, the first bit determines read permission,
184 the second write permission, and the last execute permission
185 in case of ordinary files, or search permission in case of directories.
186
187 Linux uses the fsuid instead of the effective user ID in permission checks.
188 Ordinarily the fsuid will equal the effective user ID, but the fsuid can be
189 changed by the system call
190 .BR setfsuid (2).
191
192 (Here "fsuid" stands for something like "filesystem user ID".
193 The concept was required for the implementation of a user space
194 NFS server at a time when processes could send a signal to a process
195 with the same effective user ID.
196 It is obsolete now.
197 Nobody should use
198 .BR setfsuid (2).)
199
200 Similarly, Linux uses the fsgid ("filesystem group ID")
201 instead of the effective group ID.
202 See
203 .BR setfsgid (2).
204 .\" FIXME . say something about filesystem mounted read-only ?
205 .SS Bypassing permission checks: superuser and capabilities
206 On a traditional UNIX system, the superuser
207 .RI ( root ,
208 user ID 0) is all-powerful, and bypasses all permissions restrictions
209 when accessing files.
210 .\" (but for exec at least one x bit must be set) -- AEB
211 .\" but there is variation across systems on this point: for
212 .\" example, HP-UX and Tru64 are as described by AEB.  However,
213 .\" on some implementations (e.g., Solaris, FreeBSD),
214 .\" access(X_OK) by superuser will report success, regardless
215 .\" of the file's execute permission bits. -- MTK (Oct 05)
216
217 On Linux, superuser privileges are divided into capabilities (see
218 .BR capabilities (7)).
219 Two capabilities are relevant for file permissions checks:
220 .B CAP_DAC_OVERRIDE
221 and
222 .BR CAP_DAC_READ_SEARCH .
223 (A process has these capabilities if its fsuid is 0.)
224
225 The
226 .B CAP_DAC_OVERRIDE
227 capability overrides all permission checking,
228 but grants execute permission only when at least one
229 of the file's three execute permission bits is set.
230
231 The
232 .B CAP_DAC_READ_SEARCH
233 capability grants read and search permission
234 on directories, and read permission on ordinary files.
235 .\" FIXME . say something about immutable files
236 .\" FIXME . say something about ACLs
237 .SH SEE ALSO
238 .BR readlink (2),
239 .BR capabilities (7),
240 .BR credentials (7),
241 .BR symlink (7)
242 .SH COLOPHON
243 This page is part of release 3.79 of the Linux
244 .I man-pages
245 project.
246 A description of the project,
247 information about reporting bugs,
248 and the latest version of this page,
249 can be found at
250 \%http://www.kernel.org/doc/man\-pages/.