Вопрос

So I'm doing some exam review problems, and one of them states "In UNIX system V, the length of a block is 1 KB and each block can hold a total of 256 block addresses. Using the inode scheme, what is the maximum size of the file?"

Now the irony here is the professor's provided solutions, and I understand the math/logic behind single, double, and triple indirect allocation, it's the direct allocation that's messing me up.

According to the solution, the direct allocation scheme uses 10 blocks, because 2^10 bytes = 1 KB. Why? What's the reasoning behind this formula? Is is just some arbitrary number the inventors of the UNIX System V inode dreamed up? Because it makes no sense to me to have 10 pointers for 1024 byes, as 1024/10 = one address every 102.4 bytes, would be much more logical to have 8 or some other number.

The professor's hinted there may very well be a question like this on our final, and I'd rather not risk using a cookie-cutter formula I don't understand.

Это было полезно?

Решение

I'm sure google could have given you a very complete answer far more quickly and easily than asking it here, and indeed even here I get 3,145 search results for posts containing "inode indirect blocks", but since you did ask here, here goes a reply:

Well, an inode structure, on disk, has room for only a certain number of block addresses, along with all the other information it must contain, if it is to fit inside one block itself.

In the case of SysV inodes there's room for 40 bytes of data block addresses, and that was broken down into 13 3-byte addresses and one byte left over for the "file generation number" (which you can ignore here).

So, you have 13 addresses, how are you going to use them efficiently to address file data blocks for files that contain many more than just 13 data blocks?

The decision was to use the first 10 as direct addresses -- i.e. they directly identify which block is the 1-10'th data block of the file. The 11'th, 12'th, and 13'th addresses point to indirect blocks: a single indirect block, a double-indirect block, and a triple-indirect block respectively.

As the question notes, each indirect block can hold 256 addresses. So, you just have to multiply them out and add them up, considering that the first indirect block's set of addresses point directly at data blocks, and the double-indirect blocks point first at more blocks of data-block addresses, and the triple-indirect blocks point at blocks of pointers to more blocks of pointers to data-block addresses.

This page has a nice diagram, and in this case perhaps your confusion will not be cleared up without such a diagram. Note this page talks about details that differ slightly from the strict SysV on-disk format (it has more direct blocks, and :

Understanding Indirect Blocks in Unix File Systems

Другие советы

With a single block of 1024 bytes and 4-byte pointers, you can store 1024 / 4 = 256 pointers. If each file has a single block for i-nodes then you get 256 * 1024, i.e., 256KB files. I don't know where that 10 blocks come from though.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top