Hard link

Hard link (English hardlink, the German jargon and hard link ) is a term from the field of file systems in computer science. In modern file systems, there is no fixed mapping between file names and the actual file. Instead, when creating the file - for example, on a hard drive - initially used just a number as a reference to the file (depending on the operating system inode or file record number called ) and creates a directory entry with the file name in a second step to this number refers to. In the strict sense refers to hard link this link from file name and file (the latter represented by inode or file record number). It is interesting - and that's usually meant when the term hard link is used - that multiple hard links can point to the same file, so they can more directory entries / file name for einunddieselbe file exist.

Introduction

The first hard link creates the operating system (more precisely: the filesystem handler ) automatically when you create the file, because without him no file name would exist and thus the application programs have no access to the file. With the creation of a hard link to a file that already exists one further name is established to the file; subsequently form both names equal access to the file; this is not to say easily, which name came first. This is in contrast to methods with similar goals, such as symbolic links (also called symbolic links ) in which there is an actual file and a link to the same. A file or directory can appear with this mechanism in different places in the directory structure simultaneously. At another hard link belongs just another name; other metadata associated with the file - such as modification date or privileges - only once exist and are in the inode, or file record stored. Hard links can also be created in the file system NTFS under Windows both in Unix and Linux systems (including Mac OS X) as well.

In general, it is called hard links when multiple entries refer to the same inode or file record that identifies the number filesystem internally a file or a directory. Multiple hard links to the same inode or file record are equivalent and can be renamed or deleted in any order. ( When deleting is checked whether just the last remaining hard link is deleted, the file itself is not deleted. ) Apart from the directory entries for the current and the parent directory ( and ".." ".") Refer hard links almost always on files. Since inode or file record numbers are managed within partitions, hard links are only possible within the same partition.

Structure ( Unix)

Each directory entry consists of a filename and the associated inode number. Each inode can almost be any number of file paths (directory entries ), so also different names for the same file.

One advantage of this approach is reflected in the removal of links:

There are Unix systems, strictly speaking, no surgery to remove a file, but only an unlink operation for deleting links. In the inode file of the current number of links is stored. Only when the last link is deleted to a file, the counter in the inode so has the value zero, the file itself ( inode and data cluster) is released for rewriting and hence logically deleted.

Noteworthy is the behavior of hard links when a user tries to delete a file that holds a program already open: Since opening a file increases the counter by one, the attempted deletion leads to the " disappearance" of the file (more precisely, of the deleted links ), but not to release the disk space - this is not released until after the file is closed by all applications.

To avoid consistency problems, ordinary users may not create additional directories for hard links: The links are automatically managed by a directory inode, and the unique actual directory name appears as a link exactly once in the parent directory. In addition there are in each directory always following two links: "." Link called, which represents the directory itself, and thus linking to it, as well as the parent directory, represented by a link named "..".

Application Examples

Unix

Other ways to create hard links are cp - link and rsync - link - dest.

The command stat can be determined how many hard links point to a file. The ls - l command displays on many Unix systems in the second column shows the number of hard links to the associated file.

Windows

NTFS partitions (not FAT and FAT32 ) support up to 1023 hard links per file. To create hard links, for example, the program suitable fsutil hardlink utility (for Windows XP), the mklink command ( from Vista) or programs from other companies.

To fsutil with the Microsoft tool to create the hard link "New Linkdatei.txt ", the " Zieldatei.txt " refers to the file, the following command is entered:

Or from Vista:

Unlike Unix can not hard link will be deleted as long as the referenced file opened by an application, that is, a file handle is set to it.

Comments

  • A typical operation on a computer is to open a file, modify and save - for example, to change a letter in a word processor and then securing it. Depending on how the application software - here the word processor - is designed internally, either the old content in the opened file is overwritten with the changed content - or it is a new file created with temporary names, the old deleted and then the new file the old name provided. According to the presented properties of hard links to the new content will appear on all links of the file in the former method; the second method, however, is abolished by the deletion of only one of the links, and the new content will appear in a new file without additional hard links. The other links of the original file point to be on precisely those original file with the old content; there are now so both version levels on the disk - an effect which may be intentional or not.
  • Hard links are in data protection ( backup ) is usually replaced by copies of the linked files.
  • Hard additional links are not very often used for "normal" files, since symbolic links are also available for multiple references to a file.
  • A widespread use of hard links is the creation of snapshots. It will take a complete copy of all data (complete backup) secured only new or changed files ( incremental backup) and older files as hard links to already previously backed up files ( backup set) represents. Since hard links do not require much space, compared to a full backup accordingly significantly less memory is required, although all changes in a directory tree can be reconstructed.
  • The version control system Git uses hard links when cloning local repositories. Since Git the entire history of a project keeps available locally usually, can be saved in this way space.
  • Under NTFS junction points satisfy ( junctions ) a function similar to hard links when directories are to be linked to various partitions or hard disks of the same computer. However, junction points do not allow linking of filenames or links on network drives.
375662
de