[oclug] Hard linked directories with Linux.

dlinfordvcn.bc.ca at vcn.bc.ca dlinfordvcn.bc.ca at vcn.bc.ca
Sun Jan 28 20:18:52 EST 2001


>   David F. Skoll oclug at lists.oclug.on.ca 
>   Thu, 11 Jan 2001 07:21:38 -0500 (EST)

Caught this in the archive - I'm not on the list. 
Please let me know it this makes it to you...

>On Thu, 11 Jan 2001, Andrew Hutton wrote:
>
>> At the end of the last meeting someone was asking about why we couldn't
>> hardlink a directory in Linux.

That was me asking...

Maybe I read the code wrong, which is similar in _all_ fs drivers. 
I've appended the code snippet... 

>You can do it as root.  But read "Advanced Programming in the UNIX
>Environment" (W. Richard Stevens) for why UNIX has this restriction.
>(Basically, allowing hard links to directories is a great way to hose
>your file system in a virtually unrecoverable way.)

The word you are looking for is "cycle", and I do understand. 
Sometimes, though, it is the way to do things with a directed 
graph - and it's less error prone that coding around it... 

It makes wonder if there are bugs when mounting file-systems 
that do have hard linked directories in them.   :-(

/*
 *  linux/fs/ext2/namei.c

[...]

int ext2_link (struct dentry * old_dentry,
		struct inode * dir, struct dentry *dentry)
{
	struct inode *inode = old_dentry->d_inode;
	struct ext2_dir_entry_2 * de;
	struct buffer_head * bh;
	int err;

	if (S_ISDIR(inode->i_mode))
		return -EPERM;



More information about the OCLUG mailing list