1PATH_RESOLUTION(7)         Linux Programmer's 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
14       directory  is  the  root  directory of the calling process.  (A process
15       inherits its root directory from its parent.  Usually this will be  the
16       root  directory  of  the file hierarchy.  A process may get a different
17       root directory by use of the chroot(2) system call.  A process may  get
18       an entirely private mount namespace in case it—or one of its ancestors—
19       was started by an invocation of the clone(2) system call that  had  the
20       CLONE_NEWNS flag set.)  This handles the '/' part of the pathname.
21
22       If  the  pathname  does  not start with the '/' character, the starting
23       lookup directory of the  resolution  process  is  the  current  working
24       directory of the process.  (This is also inherited from the parent.  It
25       can be changed by use of the chdir(2) system call.)
26
27       Pathnames starting with a '/' character are called absolute  pathnames.
28       Pathnames not starting with a '/' are called relative pathnames.
29
30   Step 2: walk along the path
31       Set  the  current  lookup  directory  to the starting lookup directory.
32       Now, for each nonfinal component of the pathname, where a component  is
33       a substring delimited by '/' characters, this component is looked up in
34       the current lookup directory.
35
36       If the process does not have search permission on  the  current  lookup
37       directory, an EACCES error is returned ("Permission denied").
38
39       If  the  component  is not found, an ENOENT error is returned ("No such
40       file or directory").
41
42       If the component is found, but is neither a directory  nor  a  symbolic
43       link, an ENOTDIR error is returned ("Not a directory").
44
45       If the component is found and is a directory, we set the current lookup
46       directory to that directory, and go to the next component.
47
48       If the component is found and is a symbolic link  (symlink),  we  first
49       resolve this symbolic link (with the current lookup directory as start‐
50       ing lookup directory).  Upon error, that error  is  returned.   If  the
51       result  is not a directory, an ENOTDIR error is returned.  If the reso‐
52       lution of the symlink is successful and returns a directory, we set the
53       current  lookup  directory to that directory, and go to the next compo‐
54       nent.  Note that the resolution process here  involves  recursion.   In
55       order to protect the kernel against stack overflow, and also to protect
56       against denial of service, there are limits on  the  maximum  recursion
57       depth,  and on the maximum number of symbolic links followed.  An ELOOP
58       error is returned when the maximum is exceeded  ("Too  many  levels  of
59       symbolic links").
60
61   Step 3: find the final entry
62       The  lookup  of the final component of the pathname goes just like that
63       of all other components, as described in the previous  step,  with  two
64       differences:  (i) the final component need not be a directory (at least
65       as far as the path resolution process is concerned—it may have to be  a
66       directory,  or  a nondirectory, because of the requirements of the spe‐
67       cific system call), and (ii) it is not necessarily an error if the com‐
68       ponent  is not found—maybe we are just creating it.  The details on the
69       treatment of the final entry are described in the manual pages  of  the
70       specific system calls.
71
72   . and ..
73       By  convention,  every  directory  has  the entries "." and "..", which
74       refer to the directory itself and  to  its  parent  directory,  respec‐
75       tively.
76
77       The  path  resolution process will assume that these entries have their
78       conventional meanings, regardless of whether they are actually  present
79       in the physical file system.
80
81       One cannot walk down past the root: "/.." is the same as "/".
82
83   Mount points
84       After  a  "mount  dev  path" command, the pathname "path" refers to the
85       root of the file system hierarchy on the device "dev", and no longer to
86       whatever it referred to earlier.
87
88       One can walk out of a mounted file system: "path/.." refers to the par‐
89       ent directory of "path", outside of the file system hierarchy on "dev".
90
91   Trailing slashes
92       If a pathname ends in a '/', that forces resolution  of  the  preceding
93       component  as  in  Step  2: it has to exist and resolve to a directory.
94       Otherwise a trailing '/' is ignored.   (Or,  equivalently,  a  pathname
95       with a trailing '/' is equivalent to the pathname obtained by appending
96       '.' to it.)
97
98   Final symlink
99       If the last component of a pathname is a symbolic link, then it depends
100       on  the  system  call whether the file referred to will be the symbolic
101       link or the result of path resolution on its  contents.   For  example,
102       the  system  call  lstat(2)  will operate on the symlink, while stat(2)
103       operates on the file pointed to by the symlink.
104
105   Length limit
106       There is a maximum length for pathnames.   If  the  pathname  (or  some
107       intermediate  pathname  obtained while resolving symbolic links) is too
108       long, an ENAMETOOLONG error is returned ("Filename too long").
109
110   Empty pathname
111       In the original UNIX, the empty pathname referred to the current direc‐
112       tory.   Nowadays  POSIX  decrees  that  an  empty  pathname must not be
113       resolved successfully.  Linux returns ENOENT in this case.
114
115   Permissions
116       The permission bits of a file consist of three groups  of  three  bits,
117       cf.  chmod(1)  and  stat(2).  The first group of three is used when the
118       effective user ID of the calling process equals the  owner  ID  of  the
119       file.   The second group of three is used when the group ID of the file
120       either equals the effective group ID of the calling process, or is  one
121       of  the  supplementary group IDs of the calling process (as set by set‐
122       groups(2)).  When neither holds, the third group is used.
123
124       Of the three bits used, the first bit determines read  permission,  the
125       second  write  permission,  and  the last execute permission in case of
126       ordinary files, or search permission in case of directories.
127
128       Linux uses the fsuid instead of the effective  user  ID  in  permission
129       checks.  Ordinarily the fsuid will equal the effective user ID, but the
130       fsuid can be changed by the system call setfsuid(2).
131
132       (Here "fsuid" stands for something like "file  system  user  ID".   The
133       concept  was required for the implementation of a user space NFS server
134       at a time when processes could send a signal to a process with the same
135       effective  user  ID.   It  is  obsolete  now.   Nobody should use setf‐
136       suid(2).)
137
138       Similarly, Linux uses the fsgid ("file system group ID") instead of the
139       effective group ID.  See setfsgid(2).
140
141   Bypassing permission checks: superuser and capabilities
142       On  a  traditional UNIX system, the superuser (root, user ID 0) is all-
143       powerful, and bypasses  all  permissions  restrictions  when  accessing
144       files.
145
146       On Linux, superuser privileges are divided into capabilities (see capa‐
147       bilities(7)).  Two  capabilities  are  relevant  for  file  permissions
148       checks: CAP_DAC_OVERRIDE and CAP_DAC_READ_SEARCH.  (A process has these
149       capabilities if its fsuid is 0.)
150
151       The CAP_DAC_OVERRIDE capability overrides all permission checking,  but
152       grants  execute  permission  only when at least one of the file's three
153       execute permission bits is set.
154
155       The CAP_DAC_READ_SEARCH capability grants read and search permission on
156       directories, and read permission on ordinary files.
157

SEE ALSO

159       readlink(2), capabilities(7), credentials(7), symlink(7)
160

COLOPHON

162       This  page  is  part of release 3.53 of the Linux man-pages project.  A
163       description of the project, and information about reporting  bugs,  can
164       be found at http://www.kernel.org/doc/man-pages/.
165
166
167
168Linux                             2009-12-05                PATH_RESOLUTION(7)
Impressum