Re: Question about hard links...

Robert de Bath (rd103980@home-box.demon.co.uk)
Fri, 13 Aug 1999 08:20:47 +0100 (BST)


On Thu, 12 Aug 1999, Micahel Zappe wrote:

> Does anyone out there see any problems with the second solution that could
> arise?
Yes.

if(link(oldfile, newfile) >= 0) unlink(oldfile); else perror("Rename failed");

> If it may cause problems, does anyone know of any popular
> applications that require hard links?
News demons use hard links.

Well really, you can do it but...

The only way to make symlinks reliably emulate hard links is to make it
something like this:

link()
{
if [ -f $1 ]
then
NEXTNAME= ...
mv $1 /linkdir/$NEXTNAME
ln -s /linkdir/$NEXTNAME $1
fi
LINKNAME=`readlink $1`
ln -s $LINKNAME $2
}

You'll also need to do something about keeping link counts so can move the
file out of the links directory when there's only one pointer at it.

UMSDOS doesn't do this so there are problems with empty directories that
aren't really ...

Of course this all defeats your purpose slightly :-)

Or perhaps not, they could have a quota on the links directory too.

-- 
Rob.                          (Robert de Bath <http://poboxes.com/rdebath>)
                    <rdebath @ poboxes.com> <http://www.cix.co.uk/~mayday>

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/