Thursday, May 26, 2011

Link Shell Extension, Hard Links and Sorting Pictures For Upload

Here’s the scenario:  We want to upload a large selection of pictures to Facebook or an online photo printing service and keep a local reference copy of that selection but we don’t want to take up hard drive space with duplicates of our pictures.

It’s tedious to choose the photos manually from the uploader interface and that way we don’t have a record of what’s been uploaded without going online.  We want to have a folder that includes all the pictures that we will be uploading.

Our photos are stored in a subfolder tree based on year, month and date taken.  If we just drag and drop them to a folder of selected pictures we lose them in their original date sorted folders.  If we copy and paste them we have duplicate copies using up hard drive space.

Enter Link Shell Extension and hard links.  Link Shell Extension (LSE) is a third party program that adds context menus to Windows Explorer to allow easy access to NTFS native support for hard links.  Right click on the folder you want to duplicate, left click on Pick Link Source, go to your destination folder, right click again, highlight Drop As… and select Hardlink Clone.

It looks like you’ve made a duplicate copy of your original picture folder but if you look closely there is a little red shortcut arrow on both the originals and the duplicate copies showing that they are hard linked.  If you check the properties of each folder they will be the same size but the duplicates will not actually be taking up real space on your hard drive since they are only pointers to the location the original file is stored.  If you wanted you should be able to make a duplicate copy this way of all the folders on your computer and it won’t actually write another copy of the files.

In this case we have an apparently full copy of all our pictures and we can either drag and drop them to a selection folder or just delete the pictures we don’t want.  The original picture folders are unaffected.

Hard linked files can be treated exactly like they were the real file.  Edit the file and the file in the original folder will be changed too.  You can create up to 1023 hard links per file.  The interesting bit is that both the original and duplicates of hard link files are just pointers to where the content of that file is stored.  If you delete the duplicate the original is still there.  If you delete the original the duplicate is still there.  If you delete both of them then the file is really gone and you’d have to use an undelete program to get it back.  NTFS has a counter for how many file names refer to the actual file.  When that number drops to zero the file is gone from the file system.  If the red shortcut arrow icon disappears you’ll know that’s the last link to that file.

Hard linked files can be very handy but they can cause some interesting side effects.  On a client’s computer a backup program (I believe it was Nero BackItUp) backed up selected data folders to a backup folder in C:\ (the same physical disk was not a great location choice for a backup).  C: drive was 1 TB and the backup folder reported it was over 2 TB in size.  Apparently the backup program created an actual duplicate of the data files the first time it ran.  Subsequent backups created in a date named folder actual duplicates of any files that were new or changed, but just hard links for all the files that were the same.  That’s handy insofar as you have an apparently complete copy in each subsequent backup folder.  Unfortunately, the antivirus program (AVG 9, I think) saw them all as unique files not as hard links and in scanning every hard link it wasn’t completing its nightly full scan before the start of work the next day.

With LSE installed you will also see different icons for Junction Points which function like a shortcut to a folder but in a way that is transparent to the user.  The My Pictures and My Music folders in the Documents folder in Vista or Windows 7 are just junction points that redirect the user to the folders named Pictures and Music that are actually located in their username folder.  In Windows XP the My Pictures and My Music folders are actually contained in the My Documents folder.

Tech Tech Tech Tech Boom

The post title alludes to the fact that I’ve been meaning to get this blog started for quite awhile now and finally here it is.

I intend for this blog to function as both a scratch pad for myself and a resource for anyone who cares to read it.

In the course of fixing a computer or trying to accomplish a task in a better (usually more automated) way, I find myself coming across handy software, useful techniques and valuable web sites that I’d like to remember and that could be of benefit to others dealing with something similar.  I’ll post about those here along with any general tech comments that come to mind.

Bryan