Creating hardlinks for directories.

Vikram Goyal vikigoyal at gmail.com
Sun Jan 15 16:52:23 UTC 2006


-----Original Message-----
From: "David L. Gehrt" <dlg at mail.inanity.net>
Sent: Sun, Jan 15, 2006 at 07:28:02AM -0800
To For users of Fedora Core releases
Subject: Re: Creating hardlinks for directories.


> > Hi,
> > 
> > I wanted to create hardlinks for directories on the same file system.
> > I know it's not allowed. But the man page for ln says one may. Now I
> > want to know how may one switch it on.
> > 
> > Also what could be the pitfalls.
> 
> Many years ago, with no previous experience with multiuser, general
> purpose computer systems designated as the system administrator for a
> shiny new DEC VAX running 4.1c (or was it 4.1a) BSD UNIX.  I decided
> that I needed to know about UNIX so I started learning-by-doing the
> various commands available at the command line while the actual users
> plowed ahead on the design of a network of early supercomputers and
> supporting devices.  Eventually I stumbled (tripped?) over the link
> command (ln).  I went into /usr/src/ and created the following:
> 
> /usr/src/a - a real directory
> /usr/src/b - a hard link to a
> /usr/src/c - a hard link to b
> /usr/src/d - a hard link to c
> /usr/src/e - a hard link to d
> /usr/src/f - a hard link to e
> 
> I thought, "This is pretty interesting."  I moved around this structure
> for a while, creating files, removing them using pathnames different
> from the one I used to create them.  Then I tried to remove the
> directories /usr/src/[abcdef].  No joy.  No matter what command or in
> what order the various forms of rmdir or "rm -r" I tried worked.  The OS
> reported that the target directory was not empty and so could not be
> removed in every case.
> 
> So looking around I discovered the clear inode command, and it seemed a
> perfect solution to my problem, after all I couldn't leave this bogus
> structure handing around in the file system, could I?  I cleared a few
> inodes then tried to verify the non-existence of the linked directories.
> The system crashed like a rock.  Oh, oh!  I was going to be exposed as
> an ignorant fool of a system administrator.  I had just thrown the other
> 15-20 users off.
> 
> So I lept to my feet, and shouted, "OK, who did that?" [The best defense
> being a good offense.]  When no one answered, I went about the task of
> overseeing the reboot.
> 
> I think this qualifies to illustrate a pitfall.
> 
> It was not long after my foolishness that hard links between directories
> was no longer possible with out extraordinary action, which I do not
> recall or even know if is still possible.
> 
> It is not clear to me why symbolic links would not work as well for you.
> After my little adventure I can think of very few occasions when I used
> hard as opposed to symbolic links, and symbolic links exclusively for
> directories. ;-)
> 
> dlg
> 
> > Thanks!

Ha! Ha! a nice episode from you. I came across a situaton where the only
solution which I could think of was creating hardlinks to some
directories in the users home directory. So the question of stashing the
system directories is out of the way.

Rummaging through the man pages and pondering over the problem I came
across ln man page. An excerpt:

       -d, -F, --directory
              allow the superuser to attempt to hard link directories
                (note: will probably fail due to system restrictions,
                                                 even for the superuser)

So I tried it as super user but failed miserably. Then I thought if the
option is there then there must exist a possible way of usage. Thinking
this and feeling very optimistic I googled and googled a lot. The only
piece of info which got dumped on my lap was that it was not possible
and one had to incant a magic spell to do it and it was piece of black
magic and should not be spoken of, well just like the name of You Know
Who.

Since the magic spell was not splattered on the screen so I went the way
many have trodden. I knocked the doors of the wise wizards to let me
know the magic spell and of course the pitfall if any, but alas my wish
does not seem to fullfill:)

Thanks!
-- 
vikram...
         ||||||||
         ||||||||
^^'''''^^||root||^^^'''''''^^
        // \\   ))
       //(( \\// \\
      // /\\ ||   \\
     || / )) ((    \\
-- 
Something's rotten in the state of Denmark.
		-- Shakespeare
-- 
 .
 *
~|~
 =
Registered Linux User #285795




More information about the fedora-list mailing list