Links

Links are used to establish connections between filesystem objects that do not fit into the classic tree model. There are two types of link — symbolic and hard.

J Inode | | Data area Figure 8-2: Lookup operation for /usr/bin/emacs.

Symbolic links can be regarded as ''direction pointers'' (at least by user programs) to indicate the presence of a file at a particular location, although — as we all know — the actual file resides somewhere else.

Sometimes the name soft link is used for links of this kind. This is because the link and link target are not tightly coupled with each other. A link can be imagined as a directory entry that does not contain any data but just a pointer to a filename. The link is retained when the target file is deleted. A separate inode is used for each symbolic link. The data segment of the inode contains a character string that gives the name of the link target.

With symbolic links, it is possible to distinguish between the original file and the link. This is not the case with hard links. Once a hard link has been created, it is no longer possible to establish which filename is the original and which is the hard link. When a hard link is created, a directory entry is generated whose associated inode uses an existing inode number.

Deleting a symbolic link is not difficult, but the situation with hard links is a little trickier. Let us assume that a hard link (b) shares the same inode with the original file (a). A user now wants to delete A; this normally destroys the associated inode together with its data segment so that it can be released and subsequently overwritten. Access to B is then no longer possible because the associated inode and file information no longer exists. Of course, this is not desirable behavior.

It can be prevented by a counter incorporated in the inode. The counter is incremented each time a hard link to the file is created. If one of the hard links or, indeed, the original file (because it is impossible to differentiate between the two) is deleted, the counter is decremented by 1. Only when the counter has reverted to 0 is it certain that the inode is no longer in use and can therefore be removed from the system.

Continue reading here: Programming Interface

Was this article helpful?

0 0