《现代操作系统》(第4版)文件系统 课后习题解答
寫在前面: 本文為學(xué)習(xí)《現(xiàn)代操作系統(tǒng)》(第4版)的記錄,如有錯(cuò)誤,請指正交流。
文章目錄
- 上半部分 1-22題
- 下半部分 23~42題
- 編程題部分(略)
上半部分 1-22題
解答
You can go up and down the tree as often as you want using ‘‘…’’. Some of the many paths are
/etc/passwd
/./etc/passwd
/././etc/passwd
/./././etc/passwd
/etc/…/etc/passwd
/etc/…/etc/…/etc/passwd
/etc/…/etc/…/etc/…/etc/passwd
/etc/…/etc/…/etc/…/etc/…/etc/passwd
解答:
Windows的方法是使用文件擴(kuò)展名。每個(gè)擴(kuò)展名對應(yīng)于一個(gè)文件類型和一些處理該類型的程序。
另一種方法是記住是哪個(gè)程序創(chuàng)建了文件并運(yùn)行該程序。Macintosh就是這樣工作的。
The Windows way is to use the file extension. Each extension corresponds to a file type and to some program that handles that type. Another way is to remember which program created the file and run that program. The Macintosh works this way.
解答:
這些系統(tǒng)直接將程序加載到內(nèi)存中,并從字0(魔數(shù))開始執(zhí)行。為了避免試圖將文件頭作為代碼執(zhí)行,魔數(shù)是一個(gè)分支指令,目標(biāo)地址正好位于文件頭的正上方。這樣就可以直接將二進(jìn)制文件讀入新進(jìn)程的地址空間,并在0運(yùn)行它,甚至不用知道文件頭有多大。筆者注:換句話說,魔數(shù)為了跳過文件頭,直接跳轉(zhuǎn)到代碼部分執(zhí)行。
These systems loaded the program directly in memory and began executing at word 0, which was the magic number. To avoid trying to execute the header as code, the magic number was a BRANCH instruction with a target address just above the header. In this way it was possible to read the binary file directly into the new process’ address space and run it at 0, without even knowing how big the header was.
解答:
首先,如果沒有打開,每次讀取時(shí)都需要指定要打開的文件的名稱。然后,系統(tǒng)將必須為它獲取i節(jié)點(diǎn),盡管它可以被緩存。一個(gè)很快出現(xiàn)的問題是何時(shí)將i節(jié)點(diǎn)存回磁盤。不過,它可能會(huì)超時(shí)。這會(huì)有點(diǎn)笨拙,但可能會(huì)奏效。
筆者注: 每次讀取都要制定文件名稱,系統(tǒng)需要為它獲取i結(jié)點(diǎn);存回磁盤可能超時(shí)。
這里復(fù)習(xí)一下open 調(diào)用的目的: 把文件屬性和磁盤地址表裝入內(nèi)存,便于后續(xù)調(diào)用的快速訪問。
i結(jié)點(diǎn)的作用是什么呢? i結(jié)點(diǎn) 里出來文件屬性和文件塊的磁盤地址,給定i結(jié)點(diǎn),就能找到文件的所有塊。
To start with, if there were no open, on every read it would be necessary to specify the name of the file to be opened. The system would then have to fetch the i-node for it, although that could be cached. One issue that quickly arises is when to flush the i-node back to disk. It could time out, however. It would be a bit clumsy, but it might work.
解答:不。如果你想再次讀取文件,只需隨機(jī)訪問字節(jié)0。
筆者補(bǔ)充:順序存儲有一個(gè)回繞操作,是因?yàn)橐L問前面的地址時(shí),需要返回到起點(diǎn)(回繞)從頭開始遍歷。
No. If you want to read the file again, just randomly access byte 0.
解答:
rename調(diào)用不會(huì)更改創(chuàng)建時(shí)間或上次修改的時(shí)間,但創(chuàng)建新文件會(huì)使它獲得當(dāng)前時(shí)間,即創(chuàng)建時(shí)間和上次修改時(shí)間都會(huì)發(fā)生改變。另外,如果磁盤快滿了,復(fù)制可能會(huì)失敗。
Yes. The rename call does not change the creation time or the time of last modification, but creating a new file causes it to get the current time as both the creation time and the time of last modification. Also, if the disk is nearly full, the copy might fail.
解答:(思考思考)
文件的映射部分必須從頁邊界開始,長度為整數(shù)頁。每個(gè)映射頁都將文件本身用作后備存儲。未映射內(nèi)存使用暫存文件或分區(qū)作為備份存儲。
The mapped portion of the file must start at a page boundary and be an integral number of pages in length. Each mapped page uses the file itself as backing store. Unmapped memory uses a scratch file or partition as backing store.
解答:(思考思考)
文件命名的時(shí)候使用 路徑!!! 妙啊。
使用文件名,如/usr/ast/file。雖然它看起來像是一個(gè)層次化的路徑名,但實(shí)際上它只是一個(gè)包含嵌入斜杠的名稱。
Use file names such as /usr/ast/file. While it looks like a hierarchical path name, it is really just a single name containing embedded slashes.
解答:(思考思考)
一種方法是向read系統(tǒng)調(diào)用添加一個(gè)額外的參數(shù),該參數(shù)指示要從哪個(gè)地址讀取。實(shí)際上,每次讀取都有可能在文件中執(zhí)行查找。這種方案的缺點(diǎn)是(1)在每次讀取調(diào)用中都會(huì)增加一個(gè)參數(shù),(2)要求用戶跟蹤文件指針的位置。
One way is to add an extra parameter to the read system call that tells what address to read from. In effect, every read then has a potential for doing a seek within the file. The disadvantages of this scheme are (1) an extra parameter in every read call, and (2) requiring the user to keep track of where the file pointer is.
解答
". ."組件將搜索移動(dòng)到/usr,因此…/ast將其放入/usr/ast中。
因此…/ast/x與/usr/ast/x相同。
The dotdot component moves the search to /usr, so …/ast puts it in /usr/ast.
Thus …/ast/x is the same as /usr/ast/x.
11
解答
由于浪費(fèi)的存儲在分配單元(文件)之間,而不是在它們內(nèi)部,這是外部碎片。它與交換系統(tǒng)或使用純分段的系統(tǒng)發(fā)生的主存外部碎片化完全相似。
Since the wasted storage is between the allocation units (files), not inside them, this is external fragmentation. It is precisely analogous to the external fragmentation of main memory that occurs with a swapping system or a system using pure segmentation.
解答
如果一個(gè)數(shù)據(jù)塊在一個(gè)連續(xù)的分配系統(tǒng)中被損壞,那么只有這個(gè)塊會(huì)受到影響;文件的其余塊可以被讀取。在鏈接分配的情況下,無法讀取損壞的塊;此外,有關(guān)從該損壞塊開始的所有塊的位置數(shù)據(jù)也將丟失。在索引分配的情況下,只影響損壞的數(shù)據(jù)塊。
If a data block gets corrupted in a contiguous allocation system, then only this block is affected; the remainder of the file’s blocks can be read. In the case of linked allocation, the corrupted block cannot be read; also, location data about all blocks starting from this corrupted block is lost. In case of indexed allocation,only the corrupted data block is affected.
解答
開始傳輸需要9毫秒。以80 MB/秒的傳輸速率讀取2^13字節(jié)需要0.0977毫秒,總共9.0977毫秒。寫回去還需要9.0977毫秒。因此,復(fù)制一個(gè)文件需要18.1954毫秒。壓縮16 GB磁盤的一半需要復(fù)制8GB的存儲空間,即2^20個(gè)文件。在每個(gè)文件18.1954毫秒時(shí),這需要19079.25秒,即5.3個(gè)小時(shí)。很明顯,在每次刪除文件后壓縮磁盤不是一個(gè)好主意。
It takes 9 msec to start the transfer. To read 2^13 bytes at a transfer rate of 80 MB/sec requires 0.0977 msec, for a total of 9.0977 msec. Writing it back takes another 9.0977 msec. Thus, copying a file takes 18.1954 msec. To compact half of a 16-GB disk would involve copying 8 GB of storage, which is 2^20 files. At 18.1954 msec per file, this takes 19,079.25 sec, which is 5.3 hours.Clearly, compacting the disk after every file removal is not a great idea.
解答:
如果做得對,是有用的。在壓縮時(shí),每個(gè)文件都應(yīng)該組織起來,使其所有的塊都是連續(xù)的,以便快速訪問。Windows有一個(gè)程序可以對磁盤進(jìn)行碎片整理和重新組織。鼓勵(lì)用戶定期運(yùn)行它以提高系統(tǒng)性能。但考慮到它需要多長時(shí)間,一個(gè)月運(yùn)行一次可能是一個(gè)不錯(cuò)的頻率。
If done right, yes. While compacting, each file should be organized so that all of its blocks are consecutive, for fast access. Windows has a program that defragments and reorganizes the disk. Users are encouraged to run it periodically to improve system performance. But given how long it takes, running once a month might be a good frequency.
解答
數(shù)碼照相機(jī)按順序在非易失性存儲介質(zhì)(例如,閃存)上記錄一些照片。當(dāng)相機(jī)復(fù)位時(shí),介質(zhì)被清空。此后,按順序一次記錄一張照片,直到介質(zhì)已滿,此時(shí)將照片上載到硬盤上。對于這個(gè)應(yīng)用來說,攝像機(jī)內(nèi)部的一個(gè)連續(xù)的文件系統(tǒng)(例如圖片存儲介質(zhì))是理想的。
A digital still camera records some number of photographs in sequence on a nonvolatile storage medium (e.g., flash memory). When the camera is reset, the medium is emptied. Thereafter, pictures are recorded one at a time in sequence until the medium is full, at which time they are uploaded to a hard disk. For this application, a contiguous file system inside the camera (e.g., on the picture storage medium) is ideal.
解答:(沒看懂啊)
自己做:
10個(gè)直接地址, 1024KB /4B=256K個(gè)間接地址, 總共 256*1024+10=262154 個(gè)塊, 文件最大是 262154 * 1024KB =256GB
以下是原答案:
這題答案好像不對!!!數(shù)據(jù)不對。
間接塊可以保存128個(gè)磁盤地址。加上10個(gè)直接磁盤地址,最大文件有138個(gè)塊。因?yàn)槊總€(gè)塊是1MB,所以最大的文件是138MB。
The indirect block can hold 128 disk addresses. Together with the 10 direct disk addresses, the maximum file has 138 blocks. Since each block is 1 MB, the largest file is 138 MB.
解答
對于隨機(jī)訪問,table/indexed和continuous都是合適的,而linkedallocation則不是,因?yàn)樗ǔP枰獙σ粋€(gè)給定的記錄進(jìn)行多次磁盤讀取。
For random access, table/indexed and contiguous will be both appropriate, while linked allocation is not ,as it typically requires multiple disk reads for a given record.
解答
由于文件大小變化很大,連續(xù)分配將是低效的,當(dāng)文件增大時(shí)需要重新分配磁盤空間,當(dāng)文件縮小時(shí)壓縮空閑塊。鏈接和表/索引分配都是有效的;在這兩者之間,表/索引分配對于隨機(jī)訪問場景將更有效。
Since the file size changes a lot, contiguous allocation will be inefficient requiring reallocation of disk space as the file grows in size and compaction of free blocks as the file shrinks in size. Both linked and table/indexed allocation will be efficient; between the two, table/indexed allocation will be more efficient for random-access scenarios.
解答
必須有一種方法來指示地址塊指針保存數(shù)據(jù)。如果屬性中有一點(diǎn)剩余空間,就可以使用它。這就把所有九個(gè)指針都留給了數(shù)據(jù)。如果每個(gè)指針都是k字節(jié),則存儲的文件最長可達(dá)9k字節(jié)。如果屬性中沒有剩余的位,則第一個(gè)磁盤地址可以保存一個(gè)無效地址,以將以下字節(jié)標(biāo)記為數(shù)據(jù)而不是指針。在這種情況下,最大文件是8k字節(jié)。
There must be a way to signal that the address-block pointers hold data, rather than pointers. If there is a bit left over somewhere among the attributes, it can be used. This leaves all nine pointers for data. If the pointers are k bytes each, the stored file could be up to 9k bytes long. If no bit is left over among the attributes, the first disk address can hold an invalid address to mark the following bytes as data rather than pointers. In that case, the maximum file is 8k bytes.
解答
埃莉諾說得對。在表中同時(shí)擁有兩個(gè)i-node副本是一個(gè)災(zāi)難,除非這兩個(gè)副本都是只讀的。最壞的情況是兩者同時(shí)更新。當(dāng)i節(jié)點(diǎn)被寫回磁盤時(shí),無論哪個(gè)最后寫入的節(jié)點(diǎn)都將刪除另一個(gè)節(jié)點(diǎn)所做的更改,磁盤塊將丟失。
Elinor is right. Having two copies of the i-node in the table at the same time is a disaster, unless both are read only. The worst case is when both are being updated simultaneously. When the i-nodes are written back to the disk, whichever one gets written last will erase the changes made by the other one, and disk blocks will be lost.
解答
硬鏈接不需要任何額外的磁盤空間,只需要i節(jié)點(diǎn)中的一個(gè)計(jì)數(shù)器來跟蹤有多少磁盤空間。符號鏈接需要空間來存儲指向的文件名。
符號鏈接可以指向其他計(jì)算機(jī)上的文件,甚至可以通過Internet。硬鏈接僅限于指向自己分區(qū)內(nèi)的文件。
Hard links do not require any extra disk space, just a counter in the i-node to keep track of how many there are. Symbolic links need space to store the name of the file pointed to. Symbolic links can point to files on other machines,ev en over the Internet. Hard links are restricted to pointing to files within their own partition.
解答
給定文件的硬鏈接的所有目錄項(xiàng)都指向單個(gè)i節(jié)點(diǎn)。
在軟鏈接的情況下,為軟鏈接創(chuàng)建一個(gè)新的i節(jié)點(diǎn),該i節(jié)點(diǎn)基本上指向要鏈接的原始文件。
A single i-node is pointed to by all directory entries of hard links for a given file. In the case of soft-links, a new i-node is created for the soft link and this i-node essentially points to the original file being linked.
下半部分 23~42題
解答
磁盤上的塊數(shù)=4 TB/4 KB=2^30個(gè)。因此,每個(gè)塊地址可以是32位(4字節(jié)),最接近的2次冪。因此,每個(gè)塊可以存儲4KB/4B=1024個(gè)地址。
筆者理解: 最接近的2次冪,是最小的能夠滿足尋址的位數(shù)。 算出來每個(gè)塊地址的大小是4B, 一個(gè)塊大小 是4KB , 問:一個(gè)塊可以存放多少地址? 小學(xué)數(shù)學(xué)。
The number of blocks on the disk = 4 TB / 4 KB = 2^30. Thus, each block address can be 32 bits (4 bytes), the nearest power of 2. Thus, each block can store 4 KB / 4 = 1024 addresses.
解答
位圖需要B位。自由列表需要DF位。如果DF<B,則空閑列表需要更少的比特。或者,如果F/B<1/D,則空閑列表更短,其中F/B是空閑塊的分?jǐn)?shù)。對于16位磁盤地址,如果有6%(1/16=6.25%)或更少的磁盤可用,可用列表會(huì)更短。
評注:只要磁盤快滿的時(shí)候,空閑塊鏈表方案需要的塊才比位圖少。
The bitmap requires B bits. The free list requires DF bits. The free list requires fewer bits if DF < B. Alternatively, the free list is shorter if F/B < 1/D, where F/B is the fraction of blocks free. For 16-bit disk addresses, the free list is shorter if 6% or less of the disk is free.
解答
The beginning of the bitmap looks like:
(a) After writing file B: 1111 1111 1111 0000
(b) After deleting file A: 1000 0001 1111 0000
( c) After writing file C: 1111 1111 1111 1100
(d) After deleting file B: 1111 1110 0000 1100
評注:本題可以看出 每次需要寫入文件時(shí),都是從最小編號的盤塊開始尋找空閑塊,比如這里的C.
解答
這根本不是一個(gè)嚴(yán)重的問題。修復(fù)很簡單,只是需要時(shí)間。恢復(fù)算法是將所有文件中的所有塊弄一個(gè)列表,并將剩下的地方作為新的空閑列表。
在UNIX中,這可以通過掃描所有i節(jié)點(diǎn)來完成。
在FAT文件系統(tǒng)中,由于沒有空閑列表,所以不會(huì)出現(xiàn)問題。但即使有,要恢復(fù)它所要做的就是掃描FAT,尋找空閑的條目。
It is not a serious problem at all. Repair is straightforward; it just takes time. The recovery algorithm is to make a list of all the blocks in all the files and take the complement as the new free list. In UNIX this can be done by scanning all the i-nodes. In the FAT file system, the problem cannot occur because there is no free list. But even if there were, all that would have to be done to recover it is to scan the FAT looking for free entries.
解答
奧利的論文可能沒有如他希望那樣被備份。備份程序可能跳過當(dāng)前打開以供寫入的文件,因?yàn)樵撐募械臄?shù)據(jù)狀態(tài)可能不確定。
簡寫:正在打開的文件沒有被備份
Ollie’s thesis may not be backed up as reliably as he might wish. A backup program may pass over a file that is currently open for writing, as the state of the data in such a file may be indeterminate.
解答
它們必須跟蹤磁盤上的文件中最后一次轉(zhuǎn)儲的時(shí)間。每次轉(zhuǎn)儲時(shí),都會(huì)向該文件追加一個(gè)條目。在最后一次讀取文件時(shí)記錄轉(zhuǎn)儲。從那時(shí)起更改的任何文件都將被轉(zhuǎn)儲。
They must keep track of the time of the last dump in a file on disk. At every dump, an entry is appended to this file. At dump time, the file is read and the time of the last entry noted. Any file changed since that time is dumped.
解答
In (a) and (b), 21 would not be marked. In ?, there would be no change. In
(d), 21 would not be marked.
解答
許多UNIX文件都很短。如果整個(gè)文件與i 結(jié)點(diǎn)放在同一個(gè)塊中,那么只需要一個(gè)磁盤訪問來讀取該文件,而不是像現(xiàn)在這樣需要兩個(gè)磁盤訪問。即使是較長的文件也會(huì)有收益,因?yàn)?strong>需要的磁盤訪問次數(shù)會(huì)減少一次。
Many UNIX files are short. If the entire file fits in the same block as the inode, only one disk access would be needed to read the file, instead of two, as is presently the case. Even for longer files there would be a gain, since one fewer disk accesses would be needed.
問題:這個(gè)問題如何糾正?
解答
它不應(yīng)該發(fā)生,但由于某個(gè)地方的錯(cuò)誤,它可能發(fā)生。這意味著某些塊出現(xiàn)在兩個(gè)文件中,也出現(xiàn)在空閑列表中兩次。
修復(fù)錯(cuò)誤的第一步是從空閑列表中刪除這兩個(gè)副本。
下一步必須獲取一個(gè)空閑塊,并在那里復(fù)制出現(xiàn)問題的塊的內(nèi)容。
最后,塊在其中一個(gè)文件中的出現(xiàn)應(yīng)該更改為引用新獲取的塊副本。在這一點(diǎn)上,系統(tǒng)再次保持一致。
It should not happen, but due to a bug somewhere it could happen. It means that some block occurs in two files and also twice in the free list. The first step in repairing the error is to remove both copies from the free list. Next a free block has to be acquired and the contents of the sick block copied there. Finally, the occurrence of the block in one of the files should be changed to refer to the newly acquired copy of the block. At this point the system is once again consistent.
解答
分成兩部分即可,命中時(shí)花費(fèi)時(shí)間h* 1ms,沒有命中時(shí)需要到磁盤上讀取 ,花費(fèi)時(shí)間為(1-h)*40ms
The time needed is h + 40 × (1 ? h). The plot is just a straight line.
解答
在這種情況下,最好使用通寫高速緩存,因?yàn)樗鼤?huì)在更新緩存的同時(shí)將數(shù)據(jù)寫入硬盤驅(qū)動(dòng)器。這將確保更新的文件始終位于外部硬盤驅(qū)動(dòng)器上,即使用戶在磁盤同步完成之前意外拔掉了硬盤驅(qū)動(dòng)器(USB)。
In this case, it is better to use a write-through cache since it writes data to the hard drive while also updating the cache. This will ensure that the updated file is always on the external hard drive even if the user accidentally removes the hard drive before disk sync is completed.
解答
塊提前讀 不管用,因?yàn)?這種情況大多不是順序存儲。
The block read-ahead technique reads blocks sequentially, ahead of their use, in order to improve performance. In this application, the records will likely not be accessed sequentially since the user can input any student ID at a given instant. Thus, the read-ahead technique will not be very useful in this scenario.
解答
實(shí)質(zhì)是兩個(gè)鏈表,以-1結(jié)尾。
The blocks allotted to f1 are: 22, 19, 15, 17, 21.
The blocks allotted to f2 are: 16, 23, 14, 18, 20.
解答:
磁盤讀取時(shí)間= 尋道時(shí)間+旋轉(zhuǎn)延遲+傳送時(shí)間 ,其中旋轉(zhuǎn)延遲= 1/2*轉(zhuǎn)一圈的時(shí)間
rpm是Revolutions Per Minute的縮寫,即轉(zhuǎn)每分,表示設(shè)備每分鐘的旋轉(zhuǎn)次數(shù),題目中是15000 rpm(轉(zhuǎn)/分鐘), 除以60得到 250 轉(zhuǎn)/秒 則 1/250 *1000 = 4ms /轉(zhuǎn)
自己來做:
在15000轉(zhuǎn)/分時(shí),磁盤需要4毫秒才能轉(zhuǎn)一圈。讀取k字節(jié)的平均訪問時(shí)間(毫秒)是8+2+(k/262144)×4。對于1kb、2kb和4kb的塊,訪問時(shí)間分別約為10.0153毫秒、10.0305毫秒和10.0610毫秒(幾乎沒有任何不同)。這些速率分別為99.8472kb/sec、199.3919kb/sec和397.5748kb/sec。
經(jīng)過計(jì)算得到的結(jié)果,傳輸速率和磁盤塊大小正相關(guān),多多少少符合下圖虛線 磁盤數(shù)據(jù)率–塊大小關(guān)系圖。
注:
答案給的解析:其中假設(shè)磁盤平均尋道時(shí)間是6ms,轉(zhuǎn)速是15000rpm,每道 1048576 字節(jié),和這道題有出入,其實(shí)算是另外一道題目。
在15000轉(zhuǎn)/分時(shí),磁盤需要4毫秒才能轉(zhuǎn)一圈。讀取k字節(jié)的平均訪問時(shí)間(毫秒)是6+2+(k/1048576)×4。對于1kb、2kb和4kb的塊,訪問時(shí)間分別約為6.0039毫秒、6.0078毫秒和6.0156毫秒(幾乎沒有任何不同)。這些速率分別為170.556kb/sec、340.890kb/sec和680.896kb/sec。
At 15,000 rpm, the disk takes 4 msec to go around once. The average access time (in msec) to read k bytes is then 6 + 2 + (k/1, 048, 576) × 4. For blocks of 1 KB, 2 KB, and 4 KB, the access times are about 6.0039 msec, 6.0078 msec, and 6.0156 msec, respectively (hardly any different). These give rates of about 170.556 KB/sec, 340.890 KB/sec, and 680.896 KB/sec, respectively.
解答
自己做:
50% ,真正的系統(tǒng)所浪費(fèi)的空間比這個(gè)小,因?yàn)閷?shí)際文件大小 存在很大大文件。
注:答案給的是其他的數(shù)據(jù)計(jì)算的結(jié)果,塊的大小為4KB。
如果所有文件都是1KB,那么每個(gè)4KB塊將包含一個(gè)文件和3KB浪費(fèi)的空間。不允許嘗試將兩個(gè)文件放入一個(gè)塊中,因?yàn)橛脕砀檾?shù)據(jù)的單位是塊,而不是半塊。這導(dǎo)致75%浪費(fèi)空間。實(shí)際上,每個(gè)文件系統(tǒng)都有大文件以及很多小文件,這些文件使用磁盤的效率更高。例如,考慮到空間效率,32769字節(jié)的文件將使用9個(gè)磁盤塊進(jìn)行存儲其中32769/36864個(gè),占89%。
If all files were 1 KB, then each 4-KB block would contain one file and 3 KB of wasted space. Trying to put two files in a block is not allowed because the unit used to keep track of data is the block, not the semiblock. This leads to 75% wasted space. In practice, every file system has large files as well as many small ones, and these files use the disk much more efficiently. For example, a 32,769-byte file would use 9 disk blocks for storage, given a space efficiency of 32,769/36,864, which is about 89%.
解答
間接塊可以保存1024個(gè)地址(每個(gè)間接塊 大小 4KB,指針地址值4B,一個(gè)間接塊可以有 4KB/4B=1K=1024個(gè)地址)。加上10個(gè)直接地址,總共有1034個(gè)地址。因?yàn)槊總€(gè)文件都指向一個(gè)4KB的磁盤塊,所以最大的文件是4235264字節(jié)
The indirect block can hold 1024 addresses. Added to the 10 direct addresses,there are 1034 addresses in all. Since each one points to a 4-KB disk block, the largest file is 4,235,264 bytes
解答
它將所有文件長度之和限制為不大于磁盤。這不是一個(gè)非常嚴(yán)重的限制。如果這些文件總的比磁盤大,就沒有地方將它們?nèi)看鎯υ诖疟P上。
It constrains the sum of all the file lengths to being no larger than the disk. This is not a very serious constraint. If the files were collectively larger than the disk, there would be no place to store all of them on the disk.
解答
i節(jié)點(diǎn)有10個(gè)指針。單個(gè)間接塊包含1024個(gè)指針。雙間接塊有1024 ^2個(gè)指針。三重間接塊有1024 ^3個(gè)指針。加起來,我們得到的最大文件大小為1074791434個(gè)塊,大約是4100.0039GB=4.0039TB
The i-node holds 10 pointers. The single indirect block holds 1024 pointers. The double indirect block is good for 1024^2 pointers. The triple indirect block is good for 1024^3 pointers. Adding these up, we get a maximum file size of 1,074,791,434 blocks, which is about 16.06 GB.
解答
The following disk reads are needed:
directory for /
i-node for /usr
directory for /usr
i-node for /usr/ast
directory for /usr/ast
i-node for /usr/ast/courses
directory for /usr/ast/courses
i-node for /usr/ast/courses/os
directory for /usr/ast/courses/os
i-node for /usr/ast/courses/os/handout.t
In total, 10 disk reads are required.
解答
一些優(yōu)點(diǎn)如下。
首先,沒有磁盤空間浪費(fèi)在未使用的i節(jié)點(diǎn)上。
其次,不可能耗盡i節(jié)點(diǎn)。
第三,由于i節(jié)點(diǎn)和初始數(shù)據(jù)可以在一次操作中讀取,所以需要較少的磁盤移動(dòng)。
一些缺點(diǎn)如下。
首先,目錄條目現(xiàn)在需要一個(gè)32位的磁盤地址,而不是16位的i節(jié)點(diǎn)號。
其次,整個(gè)磁盤將用于不包含數(shù)據(jù)的文件(空文件、設(shè)備文件)。
第三,由于需要為每個(gè)i節(jié)點(diǎn)讀取整個(gè)塊,而且i節(jié)點(diǎn)將分散在整個(gè)磁盤上,因此文件系統(tǒng)完整性檢查的速度將變慢。
第四,由于i節(jié)點(diǎn)的原因,那些大小經(jīng)過精心設(shè)計(jì)以適合塊大小的文件將不再適合塊大小,從而擾亂了性能
Some pros are as follows. First, no disk space is wasted on unused i-nodes. Second, it is not possible to run out of i-nodes. Third, less disk movement is needed since the i-node and the initial data can be read in one operation. Some cons are as follows. First, directory entries will now need a 32-bit disk address instead of a 16-bit i-node number. Second, an entire disk will be used even for files which contain no data (empty files, device files). Third, file system integrity checks will be slower because of the need to read an entire block for each i-node and because i-nodes will be scattered all over the disk.Fourth, files whose size has been carefully designed to fit the block size will no longer fit the block size due to the i-node, messing up performance
編程題部分(略)
總結(jié)
以上是生活随笔為你收集整理的《现代操作系统》(第4版)文件系统 课后习题解答的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一道时间复杂度的题目
- 下一篇: 线性代数的问题:是否存在这样的矩阵,它满