OSDN Git Service

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