Wednesday, April 2, 2008

ext3: symlinks

Everybody uses symlinks in linux. Very interesting thing about the internals of symlinks I have recently discovered. Symlink may store path to original location in two ways. Symlink is represented as usual inode in ext3 filesystem. Its definition is in ext3_inode structure. The length of the string is given in i_size. If path to original location including terminating '\0' symbol is less than size of the i_block(EXT3_N_BLOCKS * 4 bytes = 60 bytes usually) array then the path is stored in the i_block. Otherwise i_blocks will be 1 and i_block[0] will point to a block containing the target name. When the string has to be contained in i_block[0], fs driver has to resolve the block and read its contents. This reduces performance a bit. You should be aware that lots of symlinks that point to the full path may get some extra cycles of your cpu. Solution: use relative paths for symlinks.

No comments: