Questions tagged [hardlink]

Links a name with actual data (file). Hard-linking allows the file to have multiple names (handles). Present in POSIX-compliant systems (also only partially!): GNU/Linux, Android, Apple Mac OS X and even Windows, though with limitations. Allows for slightly different aliasing than soft-linking (aka symbolic linking) - there are trade-offs to each methods.

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

  1. The minimum client and server Windows OS supporting hardlinks are - correspondingly - XP and Server 2003.
  2. Windows hard links are NTFS-only.
  3. NTFS uses 10 bits for the filename counter, so there can be only 1023 distinct names per file.

MSDN page on Hard Links

Windows API for CreateHardLink function

192 questions
0
votes
1 answer

Windows hard links disk usage inconsistency

I'm using Windows 8.1. There appears to be an inconsistency. Windows states adding hardlinks to a file doesn't use much disk space, and this makes sense since you're only creating a pointer. However, the file system doesn't reflect this. If I create…
Wes
  • 1,183
  • 3
  • 23
  • 51
0
votes
2 answers

minidlna doesn't like hardlinks

I have a video files in: /home/private/movies/video1.mkv /home/private/movies/video2.mkv /home/private/movies/video3.mkv I have hardlinks to those mkv files…
0
votes
1 answer

Why in Unix system with hardlinks we use DAG structure?

My question is that why do we need to make it acyclic? In textbook, it says because we need to detect cycle in the structure if it's not acyclic. But why do we have to detect them? I don't see any need to detect them.
0
votes
2 answers

keep hard link connection after erasing a file

I try to achieve something that I imagined very simple, but which is finally harder than expected. I have a folder : source/. I have a second one : target/. I create a file test.jar in my first folder. Then, I want this file to appear and be…
Sharcoux
  • 5,546
  • 7
  • 45
  • 78
0
votes
1 answer

Is there a utility for creating hard link backup?

I need to create a clone of a directory tree so I can clean up duplicate files. I don't need copies of the files, I just need the files, so I want to create a matching tree with hard links. I threw this together in a couple of minutes when I…
user939857
  • 377
  • 5
  • 19
0
votes
1 answer

gerrit ssh login issue

I am having an issue with my ssh login to gerrit. When I use one key file it works, but with the other it does not. ssh gerrit_admin@ -p 29418 -i ~/.ssh/project/prod_rsa **** Welcome to Gerrit Code Review **** ..... ssh…
Nick Ellis
  • 1,048
  • 11
  • 24
0
votes
1 answer

How to determine whether a drive supports hard links in Windows XP?

I found the following solution to determine whether a drive supports hard links: CString strDrive = _T("C:\\"); DWORD dwSysFlags; if(GetVolumeInformation(strDrive, NULL, 0, NULL, NULL, &dwSysFlags, NULL, 0)) { if((dwSysFlags &…
honk
  • 9,137
  • 11
  • 75
  • 83
0
votes
1 answer

Does rsync -L tag use target name or host name

I have a directory on a files on 2 different partitions, as i need these hardlinked rather than symlinked when they are rsync'd to my client server, does the -L option use the target name or the host name of the file .. i.e. my symlink looks…
Charabon
  • 737
  • 2
  • 11
  • 23
0
votes
1 answer

Hard linking to file in Git tag (To include file in another project)

so I have a few small files that I use in a lot of different projects. For example, I have a MySQL wrapper for PHP and a class for managing buffers in C++ among others. Up to now, I've been keeping them in one SVN repository. Then, when I'll use it…
user2443357
  • 127
  • 1
  • 1
  • 11
0
votes
1 answer

Difference between a Hard Link and its Program in C

I'm writing a program that does something similar to the disk usage utility on Linux, and I'm having trouble when it comes to Hard links. I currently have the program running, and it determines whether a program has hard links. I use stat() on the…
Clark Kent
  • 1,178
  • 1
  • 12
  • 26
0
votes
1 answer

How does(or doesn't) .apk handle hardlinks

Does the .apk format handle hardlinks? Or does it simply copy the same file over and over? I've some a simple test and it seems like hardlinks are not handled, meaning that the size of the generated .apk increases significantly when you have…
Bakuriu
  • 98,325
  • 22
  • 197
  • 231
0
votes
2 answers

call linux command within python

Possible Duplicate: Equivalent of Backticks in Python I am looking for the best way to run a terminal command (ls -l) within Python. I have read about subprocess but I do not understand it fully, if someone could try and make me understand what…
bigl
  • 1,063
  • 3
  • 13
  • 23
0
votes
1 answer

How to change one file in Java, while keep the content in another hard link unchanged?

I have one file with another hardlink. How to change the first file in Java, while keep the content in another hardlink unchanged? This behavior is like gVim in Windows: C:\Users\atry\break-hard-link>echo Hello, World >…
Yang Bo
  • 3,586
  • 3
  • 22
  • 35
0
votes
1 answer

windows hard link - protect against writes

I have a bunch of files that I download at some point and then customize. I want to keep the originals, but also allow modifications, and I want to do this using hard links. I figure I first download the batch of files into some sort of repository,…
CosminB
  • 173
  • 8
0
votes
1 answer

Does windows support link system call?

In linux&unix we can call link(name1, name2) to make name1 and name2 to reference to the same inode, I wonder does windows platform support this? Thank you.
wangshuaijie
  • 1,821
  • 3
  • 21
  • 37
1 2 3
12
13