Hardlink for photos

Seth Lockwood

Honorable
Jan 19, 2014
10
0
10,510
I got a program that detects duplicate files and imagines. If I hardlink the duplicate images files, does that free up hard disk space ( SSD ). Or do I have to actually delete the duplicate image files to free up space. Thank You
 


If there are duplicate files, then they take up twice the space. Delete one of them.
 
I know if there are duplicates to delete one. But the software gives me the option to hardlink the duplicate images, and I just like to know that if I hardlink the duplicate imagines, does that free up space.
 


Without knowing exactly what program you are using, and what it does and says....'hardlink' may mean anything.
 
I am using Duplicate Cleaner Pro ( http://download.cnet.com/Duplicate-Cleaner-Pro/3000-2248_4-75650287.html ).

This is what it says in the manual,

"A hard link is a directory entry for a file. Every file can be considered to have at least one hard link. On NTFS volumes, each file can have multiple hard links, and thus a single file can appear in many directories (or even in the same directory with different names). Because all of the links reference the same file, programs can open any of the links and modify the file. A file is deleted from the file system only after all links to it have been deleted. After you create a hard link, programs can use it like any other file name.

You can only create hard links on NTFS volumes. You cannot create hard links between volumes (different hard drives or network shares). Duplicate Cleaner will only let you hard link same content files.

When creating Hard Links there needs to be at least one file in each duplicate group left unticked. This will be the 'original' file to which the other ticked files in the group are linked. Once linked there will appear to be no difference between the linked file and the original in Windows Explorer. In addition, hard linked files will appear again as duplicates if you re-scan, unless you have the 'Exclude hard linked files from duplicate list' menu option checked."
 
Can you hard link images, and thereby conserve space? The short answer appears to be no, although it ought to be yes.

It might help if we have a little background on how the New Technology File System works prior to answering the question in greater detail... When you navigate the directory structure you have files and folders within folders which are all hierarchically organized. However, this isn't how things are organized on the hard drive disk. The disk will be made up of sectors. where data is written. The directory structure is essentially a human convenience that gets mapped on to the hard drive. The map itself is a master file table that tells the system where a given path and file name resides on the hard drive.

What hard links do is create additional entries in the master file table for the same file. So if you create a hardlink, you aren't actually creating a separate file or copy. If you make changes to one "file" these get reflected in the other because they are actually the same file. Thus no additional space is used when you create a hardlink.

In a certain sense this is comparable to a shortcut link, or "soft link." A soft link is a special type of file that contains a string (text) encoding the file path to the target file. However, since these "soft links" are files of a special type, depending upon the software, a given program may or may not be able to read the file to determine its target. Furthermore, if you move the target file that the soft link refers to, then the soft link isn't automatically updated to reflect this and as a result the soft link is broken.

This isn't the case with a hard link. The hard link is the same file, but simply existing as a separate entry in the master file table. As such it is of the same type, and programs will treat it exactly the same way as "the original file." Furthermore, you can move the "original file" and the "hard link" independently of one another and they will continue to refer to the same data, such that changes in one are automatically reflected in the other.

Hard links can be created with the following code...

C++:
C++:
BOOL WINAPI CreateHardLink(_In_ LPCTSTR lpFileName, _In_ LPCTSTR lpExistingFileName, _Reserved_  LPSECURITY_ATTRIBUTES lpSecurityAttributes);
VBA:
Code:
Private Declare Function CreateHardLink Lib "kernel32.dll" Alias "CreateHardLinkA" (ByVal lpFileName As String, ByVal lpExistingFileName As String, ByRef lpSecurityAttributes As Any) As Long
cmd.exe:
Code:
mklink /h NewName, OldName

If you use these functions (commands) on a text file, a hard link will be created that will act as I have described. However, they don't work as they are supposed to on an image file. Likewise, they do not work as they should on, for example, an Excel file. If you try to create a hard link to an image file, then it will appear to work, that is, until you edit and save one file's image or the other. At that point you will see that changes in one file's image do not get reflected in the other file's image.

Therefore these would seem to be different files. But this isn't entirely true, either. If you right-click one file to bring up its properties window, then select the "details" tab, you will see that there are details that you can edit, such as the "Title" or "Subject". Change those in one file and they will get reflected in the other. Apparently the hard link isn't to the binary data but to the details - which exist in an alternate data stream within the same file, but as a stream of data separate from the primary data stream.

Anyway, I had certain problems that would have been easy to solve were it possible to create a hard link to an image. But it would appear that hard links apply to text files, not images.