We already said that inode system lets same file live under different names. In UNIX parlance, we say that there are several hard links to the file.

Hard links

Hard links provide many advantages. They let many users have easy access to the same file, without duplication. They allow one file to have several aliases. Note that all links are equal: the file does not have a 'real' name or a 'real' location in the directory tree, it has several names and several locations. There are a few issues:

  1. Only works with inodes... Hard links work because several directory entries can refer to one inode. When the file info is actually stored as a record embedded in the directory, multiple links to the file involve multiple copies of the directory record, which may easily get out of date (and other problems). When directory entry just contains name and inode, names may change (but this is a benefit; it allows each hard link to have a different name). The inode of a particular file never changes anyway. (To some extent, the inode is the file.)
  2. Only within same filesystem... Since the link is based on inode numbers, you can only create hard links to a file from directories of the same filesystem. You can't have a link from a directory on a different disk (usually). This is because inode numbers are only unique within a single filesystem. Each filesystem is self-consistant, which is hard enough to arrange as it is without requiring consistancy across multiple filesystems.
  3. Must count references... When the user tells the filesystem to 'delete' a file, there may be remaining hard links to it. Filesystem must keep a reference count for each file, so that it is only deallocated when the last hard link is deleted. (Possible security issue thingie if owner thinks that the file has been deleted when in fact there are still links to it.)
  4. Backup software... or any software which trawls through many directories and does something to each file it finds. There is a danger that the backup software will back up the file multiple times, which might be disasterous if the file is large. Simple solution is for backup software to remember all the inodes it has traversed, and only dump the file once (with appropriate information to let it reconstruct all the hard links to the file at a later date).
  5. Threat to directory hierarchy... If hard links to directories are allowed, we open up a potential can of worms. No longer is the directory structure a hierarchy---now it is an acyclic graph---or worse still, a general graph. Simplest approach is just to live with it. Unfortunately many programs (specially on DOS/Windows, which does not allow links of any sort) assume that the filesystem is a simple tree, with no hard links. UNIX requires that its filesystem be an acyclic graph, so it restricts the use of hard links on directories.
  6. Where's my parent?... In UNIX, every directory stores a link to its parent directory. If there are several hard links to the same directory, however, it is no longer clear which is its 'parent'.

last updated 27 March 1998