Hardlink sub-directories and files

Ned Deily nad at acm.org
Wed Aug 3 15:57:23 EDT 2011


In article <j1blk1$gvo$1 at reader1.panix.com>,
 Grant Edwards <invalid at invalid.invalid> wrote:
> On 2011-08-03, Kushal Kumaran <kushal.kumaran+python at gmail.com> wrote:
> > On Wed, Aug 3, 2011 at 7:29 AM, Dan Stromberg <drsalists at gmail.com> wrote:
> >>
> >> On Tue, Aug 2, 2011 at 3:13 AM, Thomas Jollans <t at jollybox.de> wrote:
> >>>
> >>> On 02/08/11 11:32, loial wrote:
> >>> > I am trying to hardlink all files in a directory structure using
> >>> > os.link.
> >>> >
> >>> > However I do not think it is possible to hard link directories ?
> >>
> >> That is pretty true.?? I've heard of hardlinked directories on Solaris, but
> >> that's kind of an exception to the general rule.
> >
> > In APUE, Richard Stevens says only root could do this,
> 
> Yep, in early versions of Solaris root could hard-link directories.
> I did it once, and it's not something one did a second time.  fsck
> couldn't deal with it and pretty much fell over.  IIRC, the only way
> to recover was to clear several inodes manually and then let fsck
> salvage things.
> 
> > if it is supported by the system at all.  In a footnote, he
> > additionally mentions he screwed up his filesystem by creating a loop
> > of hardlinked directories while writing that section of the book.
> 
> That sounds about right.
> 
> > I suppose it is a good thing systems don't allow that now.
> 
> It wouldn't be a problem, except there are some important places in
> Unix where it is assume that filesystems are trees.  Hard linking
> directories causes that assumption to be false.

FWIW, Apple implemented directory hard links for HFS+ file systems in 
Mac OS X 10.5 specifically to make the Time Machine incremental backup 
system work efficiently.  The hard directory links are, of course, not 
meant to be used by the casual user.  The section "Directory Hard Links" 
in this blog entry from Amit Singh explains what restrictions are 
enforced on directory hard links to prevent cycles:

http://osxbook.com/blog/2008/11/09/hfsdebug-40-and-new-hfs-features/

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list