Why are hard links not allowed for directories?


They allow you to create loops

A hard link to a directory can link to a parent of itself, which creates a file system loop. For example, these commands could create a loop with the back link l:

mkdir -p /tmp/a/b cd /tmp/a/b ln -d /tmp/a l

A filesystem with a directory loop has infinite depth:

cd /tmp/a/b/l/b/l/b/l/b/l/b

Any find command without the -maxdepth predicate will run into an infinite loop. That means you can no longer use find, which is an important command, in a consistent way. Similar for the equally important locate command.

A tree, by definition, has no loops, so the file system is no longer a tree.

They break the unambiguity of parent directories

With a filesystem loop, multiple parent directories exist:

cd /tmp/a/b cd /tmp/a/b/l/b

In the first case, /tmp/a is the parent directory of /tmp/a/b.
In the second case, /tmp/a/b/l is the parent directory of /tmp/a/b/l/b, which is the same as /tmp/a/b.
So it has...

0 0

Hardlinks are not permitted because they would lead to cycles. Once you allow cycles to form, you must perform a mark-and-sweep garbage collection to detect when isolated cycles of directories (no longer reachable from the root) can be finally deleted - this is extremely expensive on disk.

Soft links do not cause this problem because they do not raise the reference count of the targeted directory; thus you can still get away with reference counting (with a maximum of one reference :).

The other issue is that programs which traverse the file system (eg, find) need to avoid cycles. They could do this by remembering every inode number they've seen, but this is expensive - if they can distinguish between links which could lead to cycles (ie, softlinks) and links which will not lead to cycles (normal directory entries), and skip the softlinks, they don't need to track inode numbers...

0 0

I am using Ubuntu 12.04 and I am pretty new Linux world. I am really amazed when I try to create hard link for any directory and fail. I can create hard links for files inside file system boundary. I know the reason why we cannot create hardlinks for files beyond file system.

I tried these commands:

$ ln /Some/Direcoty /home/nischay/Hard-Directory hard link not allowed for directory $ sudo ln /Some/Direcoty /home/nischay/Hard-Directory [sudo] password for nischay: hard link not allowed for directory

I just want to know the reason behind this. Is it same for all GNU/Linux distros and Unix flavours (BSD, Solaris, HP-UX, IBM AIX) or only in Ubuntu or Linux.

"You generally should not use hard links anyway" is over-broad. You need to understand the difference between hard links and symlinks, and use each as appropriate. Each comes with its own set of advantages and disadvantages:

Symlinks can:

Point to directories Point to non-existent objects Point to...
0 0

How to make read-only file system writable?

I am not sure since when the filesystem on my digital audio player has been changed to be read-only. I cannot copy files into it or remove files on it.

Are there some possible reasons for the player's file system to change the permission of its file system?

I tried chmod:

$ sudo chmod a+rw SGTL\ MSCN/ chomd: changing permissions of `SGTL MSCN/': Read-only file system

where "SGTL MSCN" is the mounted point of the digital audio player.

I was wondering how to make it writable?

Thanks and regards!

Source: (StackOverflow)

How can I use RAM storage for the /tmp directory and how to set a maximum amount of RAM usage for it?

After seeing the comment by Anonymous on the question How is the /tmp directory cleaned up?, I found that it would be a great idea to implement on my system, since I have 16GB of RAM and I never used all of it.

My temporary files never get written to...

0 0


(forgive me if this is not the right place to post this. It was a tricky one to place.)

I have a really big music collection and some of it I don't even really care about. So I've decided to downsize, however I still want to keep all the music and artists I've amassed.

So my solution was to:


$ sudo ln library/artist -t .complete/

That way I'd have the same directory structure under library as in .complete. Expect of course I'd only cherry pick handful of files from .complete to include in library. From there I could easily drop the library directory to an mp3 player or wherever.

But of course, I got the error:

ln: ‘link’: hard link not allowed for directory

Is it possible to do something like this? I know of "mount -bind" and use it quite a bit for sticking stuff in my home directory but I don't want to drop a 50-100 mount commands in my fstab.

If you have any ideas or solutions for what I am trying to accomplish...

0 0

Wow! I just ran afoul of this crazy "feature". Try
$ ln -s /c /foo
and you are hosed!
Why would ln ever copy files?!! ("I am shocked, shocked!")

Your "solution" to makefiles using "ln -s" to copy it all over drops a big bomb on the unsuspecting user.
It would, in my opinion, be far better to error out of ln -s with a decent explanation of why you "can't do that" in Windows.
Then the makefile can be modified to avoid that feature. Using cp, if that is a viable solution. But leaving such a dangerous, wasteful, unexpected operation in "ls -s" is surely far more trouble.

The MSYS=winsymlinks:nativestrict option is said to require admin privileges, which I don't have on this computer, so that's a non-starter for...

0 0

On Fri, Feb 12, 2010 at 5:41 AM, Patrick O'Callaghan

[hidden email]

> wrote:

> Since it's just a name, there are no restrictions on what it

> contains, in fact it may not point at anything that actually exists, and

> of course can actually create a circular structure.

A Good Time Can Be Had By All, by symbolically linking a file that
does not *yet* exist, but will in the future.

The "ln -s" command requires the path of the file to which the link
will point, and the path of the link itself. But it doesn't care one
whit whether the linked-to file actually exists. If you can supply a
path to it, you could symbolically link to anywhere.

> Once the last hard link
> is broken, the file disappears. Note also that the inode maintains a
> count of hard links, but not of symlinks, i.e. symlinks are in some ways
> second-class citizens.

Actually that is not quite true. A seemingly bizarre...

0 0
0 0