这些方法各自都有一些缺点。在第一种方法中,B链接到共享文件,共享文件的i-node记录文件的拥有者是C。创建一个链接并不会改变文件的拥有关系,只是增加i-node中的link count值,用这样的方法系统可以知道当前有多少个目录执行这个文件。
If Csubsequently tries to remove the file, the system is faced with a problem. If it removes the file and clears the i-node,Bwill have a directory entry pointing to an invalid i-node. If the i-node is later reassigned to another file,B’s link will point to the wrong file. The system can see from the count in the i-node that the file is still in use, but there is no easy way for it to find all the directory entries for the file, in order to erase them. Pointers to the directories cannot be stored in the inode because there can be an unlimited number of directories
The only thing to do is remove C’s directory entry, but leave the i-node intact, with count set to 1, as shown in Fig. 4-17(c). We now have a situation in whichB is the only user having a directory entry for a file owned by C. If the system does
accounting or has quotas,Cwill continue to be billed for the file until Bdecides to remove it, if ever, at which time the count goes to 0 and the file is deleted.
唯一可行的办法就是去掉C的目录项,完整保留i-node的信息,只是把count的值设为1,正如图4-17(c)所示。我们现在得到了一种情况,属于C的文件的唯一一个使用者是B。如果系统有记录或者配额,C仍然对这个文件负责,直到B决定删除这个文件,这个时候i-node的count值变为0,文件被删除。
PS "If the system does accounting or has quotas, C will continue to be billed for the file"该如何翻译和理解?
The problem with symbolic links is the extra overhead required. The file containing the path must be read, then the path must be parsed and followed, component by component, until the i-node is reached. All of this activity may require a considerable number of extra disk accesses. Furthermore, an extra i-node is needed for each symbolic link, as is an extra disk block to store the path, although if the path name is short, the system could store it in the i-node itself, as a kind of optimization. Symbolic links have the advantage that they can be used to link to files on machines anywhere in the world, by simply providing the network address of the machine where the file resides in addition to its path on that machine.
符号链接的另外一个问题就是需要额外的负载。包含文件路径名的文件需要读取,然后这个文件需要进行分析和跟踪,一层一层直到找到顶端文件的i-node。所有这些操作可能需要相当数量的额外磁盘访问。此外,对每一个符号链接都需要一个额外的i-node,也就需要一个额外的磁盘块来存储路径,尽管有时候路径名可能很短,系统可以把它存储在i-node本身,作为一种优化方法。符号链接的优势在于可以用来链接在世界上任何一个地方的文件,仅仅需要提供这个文件所在机器的网络地址以及这个文件在这个机子上的路径。
There is also another problem introduced by links, symbolic or otherwise. When links are allowed, files can have two or more paths. Programs that start at a given directory and find all the files in that directory and its subdirectories will locate a linked file multiple times. For example, a program that dumps all the files in a directory and its subdirectories onto a tape may make multiple copies of a linked file. Furthermore, if the tape is then read into another machine, unless the dump program is clever, the linked file will be copied twice onto the disk, instead of being linked.
链接或符号链接还会引入另外一个问题。当存在链接时,一个文件就具有多个路径。一个程序从一个特定目录开始然后搜索这个目录中的所有文件和子目录中的文件,由于链接的存在会多次定位一个文件。举例来说,一个程序把一个目录以及子目录中的所有文件复制到一个磁带中,可能会把一个链接文件复制多次。此外,如果这个磁带复制到另外一台机器上,除非这个复制程序非常聪明,否者这个链接文件会复制两次到磁盘上,而不是进行链接。
《现代操作系统4th》英文版下载地址