《现代操作系统4th》英文版阅读笔记 4.3.5章 实现文件共享

Each of these methods has its drawbacks. In the first method, at the moment that Blinks to the shared file, the i-node records the file’s owner asC. Creating a link does not change the ownership (see Fig. 4-17), but it does increase the link count in the i-node, so the system knows how many directory entries currently point to the file.

这些方法各自都有一些缺点。在第一种方法中,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

如果C随后尝试删除这个文件,系统就会遇到问题。如果删除了这个文件并且清除了i-node,那么B就会有一个目录项指向一个无效的i-node.如果这个i-node随后分配给另外一个文件,那B的链接就指向了一个错误文件。系统可以从i-node的count成员属性知道这个文件仍然在被使用,但是没有办法找到和这个文件相关的所有目录项从而删除它们。把指向这些目录的指针保存在i-node中也是不现实的,因为这些目录的数目是非常多的。


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 whichis 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 quotaswill 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》英文版下载地址



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值