|
In computing, a hard link is a reference, or pointer, to physical data on a storage volume. On most file systems, all named files are hard links. The name associated with the file is simply a label that refers the operating system to the actual data. As such, more than one name can be associated with the same data. Though called by different names, any changes made will affect the actual data, regardless of how the file is called at a later time. Hard links can only refer to data that exists on the same file system. On Unix, hard links can be created with the link() system call. In Windows XP, hard links can be created with the fsutil utility. The process of unlinking disassociates a name from the data on the volume. The data is still accessible as long as at least one link that points to it still exists. When the last link is removed, the space is considered free. A process ambiguously called undeleting allows the recreation of links to data that is no longer associated with a name. However, this process is not available on all systems and is often not reliable.
Link counter Most file systems that support hard links use reference counting. An integral value is stored with each physical data section. This integer represents the total number of links that have been created to point to the data. When a new link is created, this value is increased by one. When a link is removed, the value is decreased by one. The maintenance of this value assists users in preventing data loss. It is also the simplest way for the file system to track the use of a given area of storage, as zero values indicate free space and nonzero values indicate used space. On Unix, the reference count for a file or directory is returned by the stat() or fstat() system calls in the st_nlink field of struct stat. In contrast, programming language implementations that use reference counting rarely expose the reference count to the program being executed, since this information is just an implementation detail.Example Drawbacks of hard links There are some issues with hard links that can sometimes make them unsuitable. First of all, because the link is identitical to the thing it points to, it becomes difficult to give a command such as "list all the contents of this directory recursively but ignore any links". To ignore links is sometimes necessary to avoid endless recursion. Another drawback of hard links is that they have to be located within the same file system, and most large systems today consist of multiple file systems. See also | ||||||||
|
| |||||||||
![]() |
|
| |