Описание тега hardlink
In a nutshell
Files contain data. Filenames point to files. If you have more than one name pointing to the same file, you have a hard link.
Most file systems support hard links, but not all (FAT, for one, doesn't). Usually this means keeping track of the number of distinct filenames used for a particular file; the filesystem then continues to make file content available for access as long as at least one hard link is left. If you ever wondered why C uses unlink
to remove files, that's the reason: it doesn't remove the file, it removes the fileNAME and decreases the aforementioned reference counter.
Hard vs soft linking
Two hard links to a given set of content will reference the same inode. In other words, they are different names for the same file. A soft link to a file is a different file (its own inode) which contains data pointing to a target.
MyFile
in (say) inode 3333 can have "my text" as its data.MyHardLink
will point to the same inode, 3333 and thus will have same data.MySoftLink
will be a different file, occupying a different inode (say, 3334) and its data will be a pointer to the name MyFile
.
Illuminating and illustrated! explanation of both concepts by Lew Pitcher, from Linux Gazette.
Limitations
Hardlinks cannot point to a parent of the directory containing them. This avoids endless recursion. There is also generally a limit on how many hard links can be made to the same inode, stemming from the reference counter stored by the filesystem; if too many hardlinks were to be created to one inode, the reference count would overflow. These limits are usually are worked around with symbolic links, and are very well described on Wikipedia.
Additional Windows limitations
- The minimum client and server Windows OS supporting hardlinks are - correspondingly - XP and Server 2003.
- Windows hard links are NTFS-only.
- NTFS uses 10 bits for the filename counter, so there can be only 1023 distinct names per file.