Fast and slow symlinks

symlink

From http://en.wikipedia.org/wiki/Symbolic_link#Storage_of_symbolic_links

Early implementations of symbolic links stored the symbolic link
information as data in regular files. The file contained the textual
reference to the link’s target, and an indicator[clarification needed]
denoting it as a symbolic link.

This method was slow and an inefficient use of disk-space on small
systems. An improvement, called fast symlinks, allowed storage of the
target path within the data structures used for storing file
information on disk (inodes)
. This space normally stores a list of
disk block addresses allocated to a file. Thus, symlinks with short
target paths are accessed quickly. Systems with fast symlinks often
fall back to using the original method if the target path exceeds the
available inode space
. The original style is retroactively termed a
slow symlink. It is also used for disk compatibility with other or
older versions of operating systems.

  1. Does "allowed storage of the target path within the data structures
    used for storing file information on disk (inodes)" mean that a fast
    symlink stores the path of the linked file inside the inode of the
    fast symlink

    Does a fast symlink, as a file itself, actually only have an inode
    and has no file content?

    Does a slow symlink, as a file itself, have an inode and some file
    content which is the target path?

  2. What does "if the target path exceeds the available inode space"
    mean?

    Is it correct that if a symlink to a file is a fast symlink, if and
    only if the symlink and the file are on the same file system?

  3. Is there any command that can check if a symlink is a fast or slow
    one?

  4. When a symlink has file content, what is the command to show the
    content of the symlink? (So that if a fast symlink doesn't have file
    content and a slow one has, we can verfiy that.)

Best Answer

Does "allowed storage of the target path within the data structures used for storing file information on disk (inodes)" mean that a fast symlink stores the path of the linked file inside the inode of the fast symlink

Yes

Does a fast symlink, as a file itself, actually only have an inode and has no file content?

Depends what you mean by "has file content". No symlinks have file content in the sense that you cannot open() them and read() from them. But in the meaning implied by the text you quoted, "The file contained the textual reference to the link’s target". So, yes, that textual reference can be considered the file's "content".

This content is the same regardless of whether the symlink is a fast symlink or a slow symlink. How and where the filesystem choses to store that information in its on-disk data structures is an implementation detail and does not affect this.

Does a slow symlink, as a file itself, have an inode and some file content which is the target path?

From that same point of view, yes!

What does "if the target path exceeds the available inode space" mean?

Depends on the filesystem and the kind of data structures it used to store inodes and how much spare space is in those data structures and whether they are variable-sized or fixed size. The maximum length of the target path of a symlink before it has to fall back to being stored as a slow symlink is an filesystem implementation detail.

By the way, nothing prevents a particular filesystem from using the same trick to store the contents of a short regular file to save space and disk access.

Is there any command that can check if a symlink is a fast or slow one?

At best, filesystem debugging or dumping tools. And it will be completely dependent on the type of filesystem you are interested in (xfs, ext*, btrfs, etc...)

When a symlink has file content, what is the command to show the content of the symlink? (So that if a fast symlink doesn't have file content and a slow one has, we can verfiy that.)

You can obtain the target path (contents) of a symlink with readlink, but ls -l will work too.

Related Question