Understanding Symlinks

When you create a symbolic links,an inode is consumed.One additional data block will be consumed if and only if target filename length is greater than 64 bytes.
If filename length less than 64 bytes,the path of the file is embedded into the inode itself. Thus it save one data block and one read call during access.(thus its is called fast symlinks)
If filename length greater than 64 bytes,the path of the file is stored on a data block.You have to access this data block to know the target file.

Example :
created a file system using commands like
dd if=/dev/zero of=ext2 bs=1M count=10 && mkfs.ext2 ext2
and mount it 
mount ext2 /test - loop

created file 'file.txt' and symlink for it. As you can see below - since its embedded in inode itself.debugfs shows its target (file.txt) with stat command.


debugfs:  stat symlink
Inode: 13   Type: symlink    Mode:  0777   Flags: 0x0
Generation: 2787519395    Version: 0x00000001
User:     0   Group:     0   Size: 8
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 0
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x501a6663 -- Thu Aug  2 17:07:07 2012
atime: 0x501a6664 -- Thu Aug  2 17:07:08 2012
mtime: 0x501a6663 -- Thu Aug  2 17:07:07 2012
Fast_link_dest: file.txt

Now created a file greater than 64 bytes (file0123456789012345678901234567890123456789012345678901234567890123456789.txt) and created symlink2 . Here is the stat output


debugfs:  stat symlink2
Inode: 15   Type: symlink    Mode:  0777   Flags: 0x0
Generation: 1272766837    Version: 0x00000001
User:     0   Group:     0   Size: 78
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 2
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x501a7245 -- Thu Aug  2 17:57:49 2012
atime: 0x501a7245 -- Thu Aug  2 17:57:49 2012
mtime: 0x501a7245 -- Thu Aug  2 17:57:49 2012
BLOCKS:
(0):218
TOTAL: 1

As you can see above one block (218) is consumed. Now you can view the block content via command like :


# dd if=ext2 of=blk218.txt skip=218 ibs=1024 bs=1024 count=1
1+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 7.5281e-05 s, 13.6 MB/s

# cat blk218.txt 
file0123456789012345678901234567890123456789012345678901234567890123456789.txt

That's our filename with length greater than 64 bytes stored in block 218.