Multi-level indirect address calculation problems in operating system

We go directly to the topic.

[2010 Postgraduate Entrance Exam 408 Test Question] There are 7 address items in the file index node, among which 4 address items are direct address index, 2 address items are first-level indirect address index, and 1 address item is second-level indirect address index , The size of each address item is 4B. If the size of the disk index block and the disk data block are both 256B, the maximum length of a single file that can be represented?

[Answer]
In order to facilitate understanding, let's put the picture on
Insert picture description here

According to the description of the title, there are a total of 7 address items, the first 4 are direct address items, that is to say, if these disk blocks are used to load files, they are directly loaded, because the disk block size is 256 B, so the first four disk blocks We can install 4*256 B size files.

Let’s look at it again. There are 2 first-level indirect addresses (indirect addresses). In other words, disk blocks 5 and 6 are not used to store actual file data, but are used to store a set of indirect addresses, because An address item has a size of 4B, so a disk block can hold 256/4 B addresses, that is, a total of 5 and 6 disk blocks can hold 2*(256/4)B = 128B so many addresses, and these addresses ( Pointer) will ( one-to-one ) point to other empty disk blocks, just as we know a disk block 256B, so the first-level indirect address can hold 2*(256/4)*256 B files in total. That is to say, in a 128B address, a disk block pointed to by each address has 256B, which is a total of 2*(256/4)*256 B files.

The second-level indirect address and even the third-level indirect address are calculated in the same way. You can try it yourself first, and then look at the following solution.

ok, the title tells that there is a total of a secondary indirect address, that is to say, the disk block No. 7 is divided into 128B mounting addresses, and the disk blocks pointed to by these addresses are used to install addresses (only one disk block is used for the primary indirect address Storage address), that is, (256/4)*(256/4) so ​​many addresses, each address points to a disk block (256B), so the result is (256/4)*(256/4)*256

The largest single file in the question refers to the direct address, the first-level indirect address, and the total amount of space that can be used by the second-level indirect address, which is the sum of the values ​​calculated above: 4*256 B + 2*(256/4 )*256 B + (256/4)*(256/4)*256 = 1082368 B = 1057KB

Guess you like

Origin blog.csdn.net/qq_34902437/article/details/99616197