Hard link

In computing, a hard link is a directory entry (in a directory-based file system) that associates a name with a file. Thus, each file must have at least one hard link. Creating additional hard links for a file makes the contents of that file accessible via additional paths (i.e., via different names or in different directories).[1] This causes an alias effect: a process can open the file by any one of its paths and change its content. By contrast, a soft link or “shortcut” to a file is not a direct link to the data itself, but rather a reference to a hard link or another soft link.

Every directory is itself a special file on many systems, containing a list of file names instead of other data. Hence, multiple hard links to directories are possible, which could create a circular directory structure, rather than a branching structure like a tree. For that reason, some file systems forbid the creation of additional hard links to directories.

POSIX-compliant operating systems, such as Linux, Android, macOS, and the non POSIX compliant Windows NT family,[2] support multiple hard links to the same file, depending on the file system. For instance, NTFS and ReFS support hard links,[3] while FAT does not.

Operation

An illustration of the concept of hard linking

Let two hard links, named "LINK A.TXT" and "LINK B.TXT", point to the same physical data. A text editor opens "LINK A.TXT", modifies it and saves it. When the editor (or any other app) opens "LINK B.TXT", it can see those changes made to "LINK A.TXT", since both file names point to the same data. So from a user's point of view this is one file with several filenames. Editing any filename modifies "all" files, however deleting "any" filename except the last one keeps the file around.

However, some editors, such as GNU Emacs, break the hard link concept. When opening a file for editing, e.g., "LINK B.TXT", emacs renames "LINK B.TXT" to "LINK B.TXT~", loads "LINK B.TXT~" into the editor, and saves the modified contents to a newly created "LINK B.TXT". Now, "LINK A.TXT" and "LINK B.TXT" no longer shares the same data. (This behavior can be changed using the emacs variable backup-by-copying.)

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. Even if the user deletes one of the hard links, the data is still accessible through any other link that remains. Once the user deletes all of the links, if no process has the file open, the operating system frees the disk space that the file once occupied.

Reference counting

Simplified illustration of hard links on typical Unix filesystem. Note that files "A" and "D" both point to same index entry in filesystem's inode table, making its reference count 2.

Most file systems that support hard links use reference counting. The system stores an integer value with each logical data section that represents the total number of hard 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. When the counter becomes zero, the operating system frees the logical data section. (The OS may not to do so immediately, e.g., when there are outstanding file handles open, for performance reasons, or to enable the undelete command.)

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. The maintenance of this value guarantees that there will be no dangling hard links pointing nowhere. The data section and the associated inode are preserved as long as a single hard link (directory reference) points to it or any process keeps the associated file open.

On POSIX-compliant operating systems, 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.

Limitations

To prevent loops in the filesystem, and to keep the interpretation of the ".." file (parent directory) consistent, operating systems do not generally allow hard links to directories. UNIX System V allowed them, but only the superuser had permission to make such links.[4] Mac OS X v10.5 (Leopard) and newer use hard links on directories for the Time Machine backup mechanism only.[5]

Hard links can be created to files only on the same volume, i.e., within the same file system. (Different volumes may have different file systems. There is no guarantee that the target volume's file system is compatible with hard linking.)

The maximum number of hard links to a single file is limited by the size of the reference counter. On Unix-like systems the counter is 4,294,967,295 (on 32-bit machines) or 18,446,744,073,709,551,615 (on 64-bit machines). In some file systems, the number of hard links is limited more strictly by their on-disk format. For example, as of Linux 3.11, the ext4 file system limits the number of hard links on a file to 65,000.[6] Windows limits enforces a limit of 1024 hard links to a file on NTFS volumes.[7]

On Linux Weekly News, Neil Brown criticized hard links as high-maintenance, since they complicate the design of programs that handle directory trees, including archivers and disk usage tools. These apps must take care to de-duplicate files that are linked multiple times in a hierarchy. Brown notes that Plan 9 from Bell Labs, the intended successor to Unix, does not include the concept of a hard link.[8]

Platform support

Windows NT 3.1 and later support hard links on the NTFS file system.[9] Windows 2000 introduces a CreateHardLink() function to create hard links, but only for files, not directories.[10] The DeleteFile() function can remove them.

To create a hard link on Windows, end-users can use:

To interrogate a file for its hard links, end-users can use:

  • The fsutil utility[11]
  • The Get-Item and Get-ChildItem cmdlets of PowerShell. These cmdlets represent each file with an object; PowerShell adds a read-only LinkType property to each of them. This property contains the "HardLink" string if the associated file has multiple hard links.[14]

The Windows Component Store uses hard links to keep track of different versions of components stored on the hard disk drive.

On Unix-like systems, the link() system call can create additional hard links to existing files. To create hard links, end-users can use:

  • The ln utility
  • The link utility
  • The New-Item cmdlet of PowerShell[13]

To interrogate a file for its hard links, end-users can use:

  • The stat command
  • The ls -l command
  • The Get-Item and Get-ChildItem cmdlets of PowerShell (see above)[14]

Unix-like emulation or compatibility software running on Microsoft Windows, such as Cygwin and Subsystem for UNIX-based Applications, allow the use of POSIX interfaces.

OpenVMS supports hard links on the ODS-5 file system.[15] Unlike Unix, VMS can create hard links to directories.

See also

  • Symbolic link: Points to a hard link, not the file data itself; hence, it works across volumes and file systems.
  • NTFS links: Details the four link types that the NTFS supports—hard links, symbolic links, junction points, and volume mount points
  • Shortcut: A small file that points to another in a local or remote location
    • Alias: macOS implementation of a shortcut
    • Shadow: OS/2 implementation of a shortcut
  • freedup – The freedup command frees-up disk space by replacing duplicate data stores with automatically generated hard links

References

  1. ^ Pitcher, Lew. "Q & A: The difference between hard and soft links".
  2. ^ "Link Shell Extension".
  3. ^ "Resilient File System (ReFS) overview". Microsoft Learn. 26 October 2022 – via Microsoft Docs.
  4. ^ Bach, Maurice J. (1986). The Design of the UNIX Operating System. Prentice Hall. p. 128. ISBN 9780132017992.
  5. ^ Pond, James (August 31, 2013). "How Time Machine Works its Magic". File System Event Store, Hard Links. Archived from the original on June 21, 2019. Retrieved May 19, 2019.
  6. ^ "Linux kernel source tree, fs/ext4/ext4.h, line 229".
  7. ^ "CreateHardLinkA function (winbase.h)". Windows App Development. 13 October 2021 – via Microsoft Docs.
  8. ^ Brown, Neil (23 November 2010). "Ghosts of Unix past, part 4: High-maintenance designs". Linux Weekly News. Retrieved 20 April 2014.
  9. ^ "How hard links work". Microsoft Docs. 6 January 2011.
  10. ^ "CreateHardLink Function". Windows Development. Microsoft. 10 March 2011. Archived from the original on 2 July 2011 – via MSDN. Establishes a hard link between an existing file and a new file. This function is only supported on the NTFS file system, and only for files, not directories.{{cite web}}: CS1 maint: unfit URL (link)
  11. ^ a b "Fsutil hardlink". Windows App Development. Microsoft. 18 April 2012 – via Microsoft Docs.
  12. ^ "Mklink". Microsoft Docs. Microsoft. 18 April 2012.
  13. ^ a b "New-Item (PowerShell 3.0)". Microsoft Docs. Microsoft. 22 June 2020. If your location is in a FileSystem drive, the following values are allowed: If your location is in a FileSystem drive, the following values are allowed: File[,] Directory[,] Junction[,] HardLink
  14. ^ a b "FileSystemProvider.cs". PowerShell / PowerShell repo. Microsoft. 20 November 2021. Lines 8139–8234 – via GitHub.
  15. ^ "OpenVMS System Manager's Manual, Vol. I" (PDF). VSI. August 2019. Retrieved 2021-01-23.

Read other articles:

Untuk kegunaan lain, lihat Imron Rosyadi (disambiguasi). Imron Rosadi alias Liu Nyuk Siong (lahir 5 Maret 1944 di Pringsewu, Lampung) adalah atlet nasional angkat berat periode 1960 sampai 1970-an. Semasa aktif menjadi atlet, Imron mendapat julukan sebagai Gajah Lampung. Imron kini menekuni profesi sebagai pelatih angkat berat dan angkat besi di Pringsewu, Lampung. Prestasi Atlet Juara nasional 1965-1979 Medali emas PON VII, VIII, IX Juara Asia Pasifik di Australia 1972 Pelatih Pemilik Padepo...

 

 SP16 Stasiun LRT Sungai BesiStasiun Angkutan cepat Rute Sentul Timur-Sri PetalingKoordinat3°3′50″N 101°42′28″E / 3.06389°N 101.70778°E / 3.06389; 101.70778PemilikSyarikat Prasarana Negara (2002 hingga kini); diurus oleh RapidKL.JalurRute Sentul Timur-Sri PetalingJumlah peron2 peron tepiJumlah jalur2KonstruksiParkirAdaInformasi lainKode stasiun SP16 SejarahDibuka11 Juli 1998Operasi layanan Stasiun sebelumnya   Rel RapidKL   Sta...

 

Josh CampbellJosh Campbell in 2018Born (1983-08-31) August 31, 1983 (age 40)Austin, Texas, U.S.Alma materUniversity of Texas at AustinJohns Hopkins UniversityOccupation(s)Journalist, analystEmployerCNN Josh Campbell (born August 31, 1983) is an American correspondent with CNN,[1] former U.S. intelligence community official, and military veteran.[2] He serves as an adjunct senior fellow and national security policy researcher with the Center for a New American Securit...

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (أبريل 2016) La La - لا لا ألبوم إستوديو لـآشلي سمبسون الفنان آشلي سمبسون تاريخ الإصدار 24 يناير 2005 التسجيل 2004 النوع بوب، روك، بوب الشباب المدة 3:42 اللغة الإنجليزية العلامة ال...

 

Forest near Sydney, Australia This article is about the natural bushland area in suburban Lane Cove. For the National Park to the north west, see Lane Cove National Park. the creek at Bushland Park Lane Cove Bushland Park is located in suburban Lane Cove, 5 kilometres from the centre of Sydney, Australia. It is regarded as one of the more interesting areas of fungi in the country. In the year 2000, Bushland Park was placed on the Register of the National Estate, under the Australian Heritage ...

 

Stefan Uroš II Milutin Titre Roi de Serbie 1282 – 1321(39 ans) Prédécesseur Stefan Dragutin Successeur Stefan Uroš III Dečanski Biographie Dynastie Nemanjić Père Stefan Uroš Ier Mère Hélène d'Anjou Enfants Stefan Uroš III Dečanski, Stefan Konstantin, Zorica modifier  Stefan Uroš II Milutin Nemanjić, en serbe cyrillique Стефан Урош II Милутин Немањић, en français Étienne Milutine ou Miloutine, fut roi de Serbie de 1...

Balai kota Ichy. IchyNegaraPrancisArondisemenFontainebleauKantonChâteau-LandonAntarkomuneCommunauté de communes de la Campagne GâtinaisePemerintahan • Wali kota (2008-2014) Bernard Petit • Populasi1171Kode INSEE/pos77230 / 2 Population sans doubles comptes: penghitungan tunggal penduduk di komune lain (e.g. mahasiswa dan personil militer). Ichy merupakan sebuah komune di departemen Seine-et-Marne di region Île-de-France di utara-tengah Prancis. Demografi Pada ...

 

Questa voce sull'argomento festività è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Coniglietti pasquali ricamati su una tovaglia Coniglietti pasquali di cioccolato Il coniglio pasquale (in inglese Easter Bunny, lett. coniglietto di Pasqua; in tedesco Osterhase, lett. lepre di Pasqua), conosciuto anche come coniglio di primavera, coniglietto pasquale o coniglio di Pasqua nei paesi di lingua...

 

American industrialist This article is an orphan, as no other articles link to it. Please introduce links to this page from related articles; try the Find link tool for suggestions. (January 2022) Rudolph James Wig (October 3, 1883 – April 8, 1968) was an American industrialist, trustee of Pomona College, and layman of the Presbyterian Church.[1][2][3][4][5][6][7][8] References ^ Drury, Clifford Merrill (1968). Rud...

Eighth Sikh Guru from 1661 to 1664 This article may require copy editing for grammar, style, cohesion, tone, or spelling. You can assist by editing it. (October 2023) (Learn how and when to remove this message) Hari Krishnan redirects here. For the Indian actor, see Hari Krishnan (actor). Guru Har Krishanਗੁਰੂ ਹਰਿ ਕ੍ਰਿਸ਼ਨPainting of the eighth Guru of the Sikhs, Guru Har Krishan, seated on a platform and leaning against a bolster with a red-coloured backdropPersonal...

 

1994–96 invasion of the Chechen Republic of Ichkeria by the Russian Federation First Chechen WarPart of the Chechen–Russianconflict and post-Soviet conflictsA Russian Mil Mi-8 helicopter brought down by Chechen fighters near the Chechen capital of Grozny in 1994.Date11 December 1994 – 31 August 1996 (1 year, 8 months, 2 weeks and 6 days)LocationChechnya and parts of Ingushetia, Stavropol Krai and Dagestan, RussiaBelligerents  Chechen Republic of Ichkeria Foreign...

 

Majelis Persatuan ပြည်ထောင်စု လွှတ်တော်Pyidaungsu HluttawPyidaungsu Hluttaw ke-2JenisJenisDua kamar MajelisDewan Nasional Dewan Perwakilan RakyatSejarahDidirikan31 Januari 2011 (2011-01-31)Didahului olehMajelis Rakyat (1974-1988)PimpinanKetua Dewan NasionalMahn Win Khaing Than, NLD sejak 3 Februari 2016 Ketua Dewan Perwakilan RakyatWin Myint, NLD sejak 1 Februari 2016 Pemimpin OposisiKhin Aung Myint, USDP sejak 1 Februari 2016 Komp...

Legislative, executive and judiciary authority of India Government of IndiaEmblem of the Government of IndiaFormation28 August 1833; 190 years ago (1833-08-28)Current constitutionIndian Constitution of 1950Country Republic of IndiaWebsiteindia.gov.in Legislative branchLegislatureParliamentMeeting placeParliament HouseExecutive branchLeaderPresident of India along with Union Council of Ministers headed by the Prime Minister of IndiaHeadquartersCentral SecretariatDepartme...

 

أنور منسي معلومات شخصية تاريخ الميلاد 19 ديسمبر 1922   تاريخ الوفاة 9 يناير 1962 (39 سنة)   سبب الوفاة سُقُوط  مواطنة مصر  الأولاد هويدا منسي  الحياة الفنية المهنة موسيقي  اللغة الأم العربية  اللغات العربية  المواقع السينما.كوم صفحته على السينما.كوم  تعديل مص...

 

Mountain in the American state of Colorado Peak OneNorth aspect of Peak OneHighest pointElevation12,805 ft (3,903 m)[1][2]Prominence225 ft (69 m)[3]Parent peakTenmile Peak (12,938 ft)[3]Isolation0.49 mi (0.79 km)[3]Coordinates39°32′35″N 106°07′12″W / 39.5430027°N 106.1199036°W / 39.5430027; -106.1199036[4]GeographyPeak OneLocation in ColoradoShow map of ColoradoPeak OnePeak O...

This template does not require a rating on Wikipedia's content assessment scale.It is of interest to the following WikiProjects:Rowing This template is within the scope of WikiProject Rowing, a collaborative effort to improve the coverage of rowing on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.RowingWikipedia:WikiProject RowingTemplate:WikiProject Rowingrowing articlesTo-do list:edithistorywatchpur...

 

Lewis H. Morgan Född21 november 1818[1][2][3]Aurora, USADöd17 december 1881[1][2][3] (63 år)Rochester[4], USABegravdMount Hope Cemetery[5]Medborgare iUSAUtbildad vidUnion College, 1840 SysselsättningAntropolog, advokat, arkeolog, sociolog, historiker, politiker, författare[6]BefattningLedamot av New Yorks delstatssenatLedamot av New Yorks delstatsförsamlingPolitiskt partiRepublikanska partietFöräldrarJedediah Morgan[7]Harriet Morgan[7]NamnteckningRedigera Wikidata Lewis...

 

  هذه المقالة عن أرييل أورتيغا. لمعانٍ أخرى، طالع أورتيغا. أرييل أورتيغا (بالإسبانية: Ariel Ortega)‏ أورتيغا بقميص ريفر بليت عام 2013 معلومات شخصية الاسم الكامل أرييل أرنالدو أورتيغا الميلاد 4 مارس 1974 (العمر 50 سنة)[1]خوخوي، الأرجنتين الطول 1.70 م (5 قدم 7 بوصة)[1] مرك...

تم ضبط أذرع الدفع لطائرة إيرباص إيه 320 على وضع الدفع التلقائي أثناء مرحلة العبور الخانق التلقائي أو الخانق الأوتوماتيكي (autothrottle) والمعروف أيضًا باسم الدافع التلقائي (autothrust)، أو اختصاراً (A/T)، هو نظام يسمح للطيار بالتحكم في إعداد الطاقة لمحركات الطائرة من خلال تحديد خاصية ال...

 

Pour les articles homonymes, voir Creil (homonymie). Ne doit pas être confondu avec Créteil. Creil De haut en bas et de gauche à droite: la bras sud de l'Oise ; vue de l'Oise ; l'Hôtel-de-Ville ; le théâtre Le Lido ; l'église St-Médard; vestiges du château royal; la croix des mariniers ; la fontaine de la place Carnot ; façade de la gare. Blason Logo Administration Pays France Région Hauts-de-France Département Oise Arrondissement Senlis Intercommuna...