[OT] Hardlinks and directories
jdow at earthlink.net
Sat Feb 13 20:03:47 UTC 2010
From: "Marko Vojinovic" <vvmarko at gmail.com>
Sent: Saturday, 2010/February/13 05:44
> On Saturday 13 February 2010 06:30:55 jdow wrote:
>> It's even worse than that, Marko.
>> You have a directory tree /a/b/c/d. You create a hard link to directory
>> /a/b inside of d. You get /a/b/c/d/b/c/d/b/c/d....
>> NOW you unlink /a/b. Now when you do an ls on /a you get . and .. only.
>> Now, I challenge you to delete the /b/c/d loop and everything it contains
>> without reformatting the disk or using low level disk edit functions.
> I'm not sure I understand your point. The system will not allow you to
> /a/b before it is empty. And it never is, since it contains a loop to
> OTOH, if you manage to persuade the kernel to remove it regardless, then
> the b/c/d loop gets cut off from the rest of the filesystem, and there is
> no way
> to claim back that disk space.
> But unlinking nonempty directories leaks disk space even if there are no
> inside, so you always need to have the "unlink only empty dirs" rule
> implemented in the kernel. This is analogous to losing a pointer before
> free()-ing it in, say, C --- memory leaks. :-)
> Best, :-)
What you are saying, Marko, is just as bad as the looping disconnected
directory structure. Once a hard link to a directory is created it can
never be destroyed because there is always something in the directory.
You have created an entity that cannot be deleted. Same problem, different
manifestation. That is another perfectly good reason to prohibit hard
If the created hard link can be deleted then so can the original "link".
There's no reasonable way to distinguish my deleting the link in d to b
from deleting the link in a to b. They appear identical to the OS. So you
get chaos either way.
More information about the users