Hard link

Hard link

In computing, a hard link is a directory reference, or pointer, to a file on a storage volume. The name associated with the file is simply a label stored in a directory structure that refers the operating system to the file data. As such, more than one name can be associated with the same file. When accessed through different names, any changes made will affect the same file data. Hard links can only refer to data that exists on the same file system.

On POSIX-compliant operating systems, such as all Unix-like systems, hard links are created with the link() system call, or the ln and link command-line utilities.

On Microsoft Windows, hard links can be created only on NTFS volumes. "mklink" under Vista, "fsutil hardlink", and the ln command from Cygwin are examples of tools that can be used to create them.

The process of "unlinking" disassociates a name from the data on the volume without destroying the associated data. 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 integer 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. If the link count becomes zero, the operating system usually automatically deallocates the data space of the file if no process has the file opened for access. The maintenance of this value assists users in preventing data loss. This is a simple method 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 POSIX-compliant operating systems, such as many Unix-variants, 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.


In the figure to the right, two hard links, named "LINK A.TXT" and "LINK B.TXT", point to the same physical data.

If the filename "LINK A.TXT" is opened in an editor, modified and saved, then those changes will be visible even if the filename "LINK B.TXT" is opened for viewing since both filenames point to the same data. The same is true if the file were opened as "LINK B.TXT" - or any other name associated with the data.

Any number of hard links to the physical data may be created. To access the data, a user only needs to specify the name of any existing link; the operating system will resolve the location of the actual data.

If one of the links is removed with the POSIX unlink function (for example, with the UNIX 'rm' command), then the data is still accessible through any other link that remains. If all of the links are removed and no process has the file open, then the space occupied by the data is freed, allowing it to be reused in the future. This semantic allows for deleting open files without affecting the process that uses them. This technique is commonly used to ensure that temporary files are deleted automatically on program termination, including the case of abnormal termination.

Limitations of hard links

Most modern operating systems don't allow hard links on directories to prevent endless recursion. A notable exception to this is Mac OS X v10.5 (Leopard). [Arstechnica [http://arstechnica.com/reviews/os/mac-os-x-10-5.ars/14 article ] about Mac OS X hard links to directories.]

Hard links can only be created to files on the same file system. If a link to a file on a different file system is needed, it may be created with a symbolic link.

ee also

*Symbolic link
*NTFS junction point
*alias (Mac OS)
*shadow (OS/2)
*ln (Unix)—The ln command, which is used to create new links on Unix-like systems.


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Hard link — Ein harter Link (engl. hard link, im deutschen Jargon auch Hardlink) ist ein Verzeichniseintrag in einem Dateisystem, der indirekt auf Dateien und Verzeichnisse verweist. Außer in Unix Systemen (also auch Mac OS X) können Hardlinks auch im… …   Deutsch Wikipedia

  • Hard link — Lien matériel En informatique, on nomme lien matériel (en anglais hard link) un pointeur sur des données physiques d un volume de stockage. Ce pointeur est relatif au volume physique ou logique considéré, ce qui permet le changement de support… …   Wikipédia en Français

  • Hard link — …   Википедия

  • Link — may refer to:ComputingInternet* Links (web browser), a web browser for Unix like systems * Reciprocal link, two way links to and from websites, also known as link swaps , link exchanges and link partners * Hyperlink, a reference in a hypertext… …   Wikipedia

  • Link (Unix) — link is a command line utility included with Solaris. It directly interfaces the system call link() and creates a hard link. It can be run only by privileged users in the case where the existing path refers to a directory. As described by the… …   Wikipedia

  • Hard (album) — Infobox Album | Name = Hard Type = Album Artist = Jagged Edge Released = October 7, 2003 (U.S.) Recorded = 2002 2003 Genre = R B Label = So So Def Records Sony Music Producer = Jermaine Dupri Bryan Michael Cox Jazze Pha Corna Boyz Reviews = *… …   Wikipedia

  • Hard-Fi — at the 2006 Hurricane Festival in Germany Background information Origin Staines, Surrey, England …   Wikipedia

  • Hard disk drive — Hard drive redirects here. For other uses, see Hard drive (disambiguation). Hard disk drive Mechanical interior of a modern hard disk drive Date invented 24 December 1954 [1] …   Wikipedia

  • Hard science fiction — is a category of science fiction characterized by an emphasis on scientific or technical detail, or on scientific accuracy, or on both.[1][2] The term was first used in print in 1957 by P. Schuyler Miller in a review of John W. Campbell, Jr. s… …   Wikipedia

  • Link (The Legend of Zelda) — Link (character) and Link (fictional character) redirect here. For other uses, see Link (disambiguation). Link Link, as he appears in official artwork for The Legend of Zelda Series The Leg …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”