After successfully creating a hard link called bar to the ordinary file foo, foo is deleted from the filesystem. Which of the following describes the resulting situation?
A. foo and bar would both be removed.
B. foo would be removed while bar would remain accessible.
C. foo would be removed. bar would still exist but would be unusable.
D. Both foo and bar would remain accessible.
E. The user is prompted whether bar should be removed, too.
题解
实体链接(hard link)会在目录的 block 下创建一个文件名链接,来指到同样的 inode。假设原先的「foo」文件内容存在于 block 的第 5 个位置,「foo」文件的实体链接(hard link)「bar」文件创建时,会在「bar」文件所在目录的 block 下创建一个「bar」的文件名链接,并且将链接指向到「foo」文件的 inode。删除「foo」文件时,只会移除掉「foo」文件所在目录的文件名链接,并不会删除掉「foo」文件存在于 block 中的文件内容或是 inode,因此使用「bar」文件还是可以借由链接 inode 来访问到原先「foo」文件的文件内容。所以答案是选项 B。
