I'm trying to better understand why directory hardlinks are not possible. Roughly, I think of directories and files as follows:
directory
---------
inode # exposed as .
inode_of_parent # exposed as ..
content:
mapping from names to inodes
a hardlink is just another name->inode entry in the mapping
file
----
inode
content
My understanding of directory symlinks is that they are something like:
symlink
-------
inode # exposed as . but only if the symlink can be followed
inode_of_parent # exposed as .. but only if the symlink can be followed
target:
a named path that, effectively, points to another inode's content
Notably, the target for the symlink does not point to another inode and so it does not increment the link count of any inode. If what the target resolves to is invalid, then the symlink is simply invalid.
I've read Why are hard links to directories not allowed in UNIX/Linux? and it seems to come down mostly to convenience (and presumably performance). [Aside: it seems like '..' effectively breaks the DAG structure anyway, but I guess it does so in a predictable manner, one that hard links would make more complicated.] Some of the comments on that question suggest that it is possible to deal with loops, but for the purposes of discussion, I'm willing to accept that we want to avoid them. Given that, then why could you not have a different kind of symlink that pointed to an inode instead:
alternative symlink
-------------------
inode # exposed as .
inode_of_parent # exposed as ..
inode_of_target
is_symlink # this marks it as special and distinct from a directory
This symlink would have to increment the link count of the target, which makes it robust to moves and renames of the target. So it's basically a hard link, but due to its special flag, it will never be confused as a real directory and so it causes no concerns for loops. The situation seems as manageable.
Obviously, this must be too simple-minded. So I'd like to know why this is not possible. Likely, the story I've told is not sophisticated enough, and so please, complicate it as necessary.