LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 934|回复: 5

请问哪位大虾能给解释一下硬链接为何不能链接目录?

[复制链接]
发表于 2006-5-31 11:42:58 | 显示全部楼层 |阅读模式
请问哪位大虾能给解释一下硬链接为何不能链接目录?
发表于 2006-5-31 13:04:37 | 显示全部楼层
为什么?会出问题。目录间的循环。。

Linux中存在特殊的对目录的硬链接,"."和".."就是对目录自身和上层目录的硬链接。

在某些Unix系统中,root是可以对目录进行硬链接的。

POSIX 1003.1对此的解释:

RATIONALE

    Linking to a directory is restricted to the superuser in most historical implementations because this capability may produce loops in the file hierarchy or otherwise corrupt the file system. This volume of IEEE Std 1003.1-2001 continues that philosophy by prohibiting link() and unlink() from doing this. Other functions could do it if the implementor designed such an extension.

    Some historical implementations allow linking of files on different file systems. Wording was added to explicitly allow this optional behavior.

    The exception for cross-file system links is intended to apply only to links that are programmatically indistinguishable from "hard" links.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-31 13:31:14 | 显示全部楼层
谢谢,我原来只清楚不能跨文件系统的原因,从文件系统构成来看感觉硬链接目录似乎也没问题,这下清楚了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-31 13:32:43 | 显示全部楼层
是否可以理解为原理上是可以硬链接目录的?
回复 支持 反对

使用道具 举报

发表于 2006-5-31 14:07:39 | 显示全部楼层
我手头现在没有Linux,你检查一下ln(1)手册页,其中是否提到-d, -F选项,另外现有Linux文件系统没有能支持硬链接目录的(除了前面说的两个特例),所以Linux下是绝对不可能的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-5-31 15:03:09 | 显示全部楼层
我也不是专门针对Linux问的,是在学习solaris的过程中遇到的,很少有地方把它讲清楚.
谢了!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表