Thread overview
Re: Entry (main) method inside a class?
Mar 17, 2007
Stewart Gordon
Mar 18, 2007
Daniel Keep
Mar 18, 2007
Stewart Gordon
OT: Hard links (Was re: Entry (main) method inside a class?)
Mar 18, 2007
Joel C. Salomon
March 17, 2007
Daniel Keep Wrote:

> Manfred Nowak wrote:
<snip>
>> XP supports hard links.
> 
> Yeah, but they suck.  You need to download a third-party tool to use them, for starters.  Secondly, almost nothing written for Windows even knows about them, not even *Explorer*, so it's impossible to tell if something is a link or not.  And of course, they can't span drives.

Nor can Unix hard links.  It would conflict somewhat with the way hard links work.

> I'm fairly sure that one version of Windows could only hard-link folders, but not files.  Not sure if that was 2k or XP.
> 
> I once planned on using hard links to make migrating stuff between drives easier.  Obviously I couldn't do that, but what really scared me was when I realised that deleting the link deleted the original as well; I just backed away slowly, avoiding eye contact.
<snip>

Strange.  I wonder just how these hard links work.  Does deleting one of them delete the whole lot in one fell swoop, or produce loads of dead links?  Or do they disappear as and when you try to determine their existence?

Stewart.

March 18, 2007

Stewart Gordon wrote:
> Daniel Keep Wrote:
> 
>> Manfred Nowak wrote:
> <snip>
>>> XP supports hard links.
>> Yeah, but they suck.  You need to download a third-party tool to use them, for starters.  Secondly, almost nothing written for Windows even knows about them, not even *Explorer*, so it's impossible to tell if something is a link or not.  And of course, they can't span drives.
> 
> Nor can Unix hard links.  It would conflict somewhat with the way hard links work.
> 
>> I'm fairly sure that one version of Windows could only hard-link folders, but not files.  Not sure if that was 2k or XP.
>>
>> I once planned on using hard links to make migrating stuff between drives easier.  Obviously I couldn't do that, but what really scared me was when I realised that deleting the link deleted the original as well; I just backed away slowly, avoiding eye contact.
> <snip>
> 
> Strange.  I wonder just how these hard links work.  Does deleting one of them delete the whole lot in one fell swoop, or produce loads of dead links?  Or do they disappear as and when you try to determine their existence?
> 
> Stewart.

This is speculation, but I think that UNIX hard links are like... ref-counted objects in Python, whereas Windows hard links are like un-counted objects in C++.  In UNIX, deleting one ref doesn't affect the others, deleting an object in C++... well, you get the idea :P

I realise that UNIX hard links share many of the same limitations, but the difference is that soft symlinks aren't available on Windows as an alternative.

Interesting side note: Cygwin actually uses normal Windows shortcuts for its soft symlinks: Cygwin actually does a better job of supporting shortcuts than Windows itself does!

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/
March 18, 2007
Daniel Keep Wrote:

<snip>
> This is speculation, but I think that UNIX hard links are like... ref-counted objects in Python,
<snip>

I'm not familiar with Python, but ref-counted objects is correct.  On Unix there are three aspects to a file: the path (hard link), the inode and the contents.  A hard link points to an inode, which contains the reference count; the inode in turn points to the file contents.  No two inodes can point to the same contents, but a given inode can have many hard links to it.

Interesting fact: The Unix rm command, in at least some versions, has a flag to zero the file's contents.  (Well, it either sets all bits to 0, then 1, then 0, or the other way round, I'm not sure which.)  But it doesn't check for multiple hard links, and so any that remain will just point to the blankness it has created.

I once wrote a C++ vector class that works in much the same way - having a class Vector, which the user works with, and VectorData, which stores the data itself and the reference count.

Stewart.
March 18, 2007
Stewart Gordon wrote:
> Strange.  I wonder just how these hard links work.  Does deleting one of them delete the whole lot in one fell swoop, or produce loads of dead links?  Or do they disappear as and when you try to determine their existence?

On UNIX and Windows (NTFS), hard links are reference-counted; the directory entry (the datum that has the file’s name and position in the directory tree) has a “link” to the actual file data.  The “delete” operation is called “unlink” under UNIX because it unlinks a directory entry from a file — and, if there are no other links to the file, deletes the file.

--Joel