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
1
vote
1 answer

Overriding SCons Cache Copy Function

I'm trying to figure out how to override the behaviour when SCons copies artifacts from the cache directory (given by CacheDir) to used hard-links. My current try def link_or_copy_file(class_instance, src, dst): # do hardlinking…
Nordlöw
  • 11,838
  • 10
  • 52
  • 99
1
vote
2 answers

How do I determine that two paths are hard links to the same file in Cocoa?

I need to create hard links at runtime for file at paths longer than 255 characters (this is a workaround for an infuriating Excel/Word 2011 limitation). But since the same file may be opened later again, I don't want to recreate the hard link if I…
charles
  • 11,212
  • 3
  • 31
  • 46
1
vote
1 answer

Trying to run newaliases: newaliases: fatal: /etc/: file has 85 hard links

I just updated my /etc/aliases file like so: postmaster: root mailer-daemon: postmaster nobody: root hostmaster: root usenet: root news: root webmaster: root www: root ftp: root abuse: root root: myusername However now I am getting an error while…
Sunjay Varma
  • 5,007
  • 6
  • 34
  • 51
1
vote
1 answer

[kernel32.dll]CreateHardLink fails with "Cannot create a file when that file already exists" on Azure Website during RavenDb Embedded backup

I'm running RavenDb.Embedded v2.0.2370 inside an Azure Web site. All of this is working as expected except for the backup. The backup routine initiated with EmbeddableDocumentStore.DocumentDatabase.StartBackup(...) used to work perfectly until I…
cgijbels
  • 5,994
  • 1
  • 17
  • 21
1
vote
1 answer

How file deletion mechanism works on Unix?

I am wondering how the internal mechanism of file deletion works on Unix. If there are some hard links pointing to an actual file, do I need to delete all links in order to delete the file? If I delete the file, will the hard links be destroyed or…
mgus
  • 808
  • 4
  • 17
  • 39
1
vote
1 answer

cheapest way to create marker file on unix

I need to create (lots of) files whose sole purpose is to signify a boolean condition by their mere existence. These files have no content, and their access/mod time or ownership doesn't matter. Only their existence matters. I figured the cheapest…
Benito Ciaro
  • 1,718
  • 12
  • 25
1
vote
1 answer

MSWord breaking Hard Link

Question: Is there any option to work on an MSWORD file with a Hard Link (mklink /h) to another directory? What I've experienced: After creating a Hard Link of a .docx file onto a different directory, modifying either the original document or the…
j4nSolo
  • 342
  • 1
  • 14
1
vote
2 answers

link() operation not permitted

This is strange, sometimes works, sometimes it doesnt. I've put var_dumps of the link()'s arguments. string(35) "/printbox/web/repo/docusearch/5.pdf" string(82) "/printbox/web/repo/hardlink/Oleaginosa Moreno Hnos.…
JorgeeFG
  • 5,651
  • 12
  • 59
  • 92
1
vote
1 answer

Rsnapshot without hard links?

I'm using Rsnapshot to backup all my servers on an EncFS encrypted partition. The partition has been created with the default paranoia mode offered by EncFS, thus it doesn't support hard links. I'm able to run Rsnapshot the first time (creating…
fradeve
  • 284
  • 4
  • 15
1
vote
2 answers

Data corruption of a mercurial repository

I have a mercurial repository at c:\Dropbox\code. I've created a clone of this repo locally using: hg clone -U c:\Dropbox\code c:\GoogleDrive\codeBackup This bare repo serves the purpose of backup only. I regularly push changes to codeBackup.…
user
  • 17,781
  • 20
  • 98
  • 124
1
vote
2 answers

.htaccess rewrite dynamically soft link hidden directory

I was not sure how to phrase this question but hopefully my description will make more sense as to what I wish to achieve. I am currently building a framework which supports multiple applications. The directory structure is like…
Ozzy
  • 10,285
  • 26
  • 94
  • 138
1
vote
2 answers

Cheap Copy(hard link) in SVN branch

I read that 'branch' of SVN uses a cheap copy(hard link) of a revision. Here is the link. http://svnbook.red-bean.com/en/1.7/svn.branchmerge.using.html The 'Creating a branch' chapter deals with that. But the book also says 'As far as Subversion is…
hanmomhanda
  • 305
  • 1
  • 2
  • 15
1
vote
1 answer

Is there an easy way to determine if a file is a hard link using Java in Windows?

I noticed that Java 7 has added a lot of new useful file operations with the new Paths and Files etc. classes in NIO. However, it seems that Java 7 has only added file operations to handle soft links or created hard links. Is there a way to…
Fz3
  • 33
  • 8
1
vote
3 answers

Hardlink the contents of a whole directory in windows 7

Which is the best way to archieve this? I was thinking on a batch script that takes a source folder and a destination folder as inputs, and then iterates recursively over the source folder and for each file creates a hard link to that file (with the…
Pablo Mescher
  • 26,057
  • 6
  • 30
  • 33
1
vote
1 answer

Mercurial repository & MSVS - two projects & shared files

I am currently developping an application in MS VS2010 that's based on a client-server architecture with one project for each part in VS. Until recently, they both had their own repositories in Hg, but I decided to move them together as there are…