Linux – Are there any filesystems for which `ln -d` succeeds

directoryfilesystemshard linklinux

From the manpage for ln:

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

Are there any filesystem drivers that actually allow this, or is the only option mount --bind <src> <dest>?
Or is this kind of behavior blocked by the kernel before it even gets to the filesystem-specific driver?

NOTE: I'm not actually planning on doing this on any machines, just curious.

Best Answer

First a note: the ln command does not have options like -d, -F, --directory, this is a non-portable GNUism.

The feature you are looking for, is implemented by the link(1)command.

Back to your original question:

On a typical UNIX system the decision, whether hard links on directories are possible, is made in the filesystem driver.

The Solaris UFS driver supports hard links on directories, the ZFS driver does not.

The reason why UFS on Solaris supports hard links is that AT&T was interested in this feature - UFS from BSD does not support hard linked directories.

The reason why ZFS does not support hardlinked directories is that Jeff Bonwick does not like that feature.

Regarding Linux, I would guess that Linux blocks attempts to created hard links on directories in the upper kernel layers. The reason for this assumption is that Linus Torvalds wrote code for GIT that did shred directories when git clone was called as root on a platform that supports hard linked directories.

Note that a filesystem that supports to create hard linked directories also needs to support unlink(1) to remove non-empty directories as root.

So if we assume that Torvalds knows how Linux works and if Linux did support hard linked directories, Torvalds should have known that calling unlink(2) on a directory while being root, will not return with an error but shred that directory. IN other words, it is unlikely that Linux permits a file system driver to implement hard linked directories.