Are symbolic links stored as files or just entries in directories?

My question is related to the way symbolic links are implemented in Linux file systems.

  1. Are they regular files stored (inodes used) or are they just special entries in directories?
  2. If they are stored in file systems, how are they distinguished from binary files? Do symbolic links have special magic number assigned?
Asked By: mrn

||

"It depends".

It depends on the filesystem implementation, and on the length of the link.

For example, on ext4 if the target of the symlink is small enough (60 bytes, or something like that) then it is stored in the inode itself and doesn’t use a data block. However if the target is larger then a data block is allocated and the content stored there.

Other filesystems may not have this "store in inode" option.

Traditionally, a symlink is determined by bits in the "mode" (st_mode) field of the inode, in the same way that "directory", "character device", "block device", "FIFO", "Socket" are. Typically an application could do a stat() on the filename (or similar) and then test with S_ISLNK() on the result’s st_mode field.

Answered By: Stephen Harris
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.