Directories and Links 343
Figure 18-2: Representation of hard and symbolic links
Since a symbolic link refers to a filename, rather than an i-node number, it can be
used to link to a file in a different file system. Symbolic links also do not suffer the
other limitation of hard links: we can create symbolic links to directories. Tools
such as find and tar can tell the difference between hard and symbolic links, and
either don’t follow symbolic links by default, or avoid getting trapped in circular
references created using symbolic links.
It is possible to chain symbolic links (e.g., a is a symbolic link to b, which is a
symbolic link to c). When a symbolic link is specified in various file-related system
calls, the kernel dereferences the series of links to arrive at the final file.
SUSv3 requires that an implementation allow at least _POSIX_SYMLOOP_MAX deref-
erences of each symbolic link component of a pathname. The specified value for
_POSIX_SYMLOOP_MAX is 8. However, before kernel 2.6.18, Linux imposed a limit of 5
dereferences when following a chain of symbolic links. Starting with kernel 2.6.18,
Linux implements the SUSv3-specified minimum of 8 dereferences. Linux also
imposes a total of 40 dereferences for an entire pathname. These limits are
required to prevent extremely long symbolic link chains, as well as symbolic link
loops, from causing stack overflows in the kernel code that resolves symbolic links.
i-node
number
61
...
this 61
/home/erena directory
“/home/erena/
this”
data for soft link
/home/kiran/other
I-node table File data
... ...
that 61
... ...
regular file
file data
UID=kiran GID=users
type=symlink
perm=rwxrwxrwx
...
Data block pointers
link count = 1 size=16
UID=erena GID=users
type=file
perm=rw-r--r--
...
Data block pointers
link count = 2 size=518
/home/allyn directory
309
...
... ...
... ...
other 309
... ...
/home/kiran directory
Two hard
links to the
same file
A symbolic
link