There's a homework question I need to answer and I can't make heads or tails of it. I've looked over what I think are the pertinent sections in the book (Operating Systems Concepts 9th edition) a couple of times, and I'm not sure where this comes from.
The Question:
Consider a file system on a disk that has both logical and physical block sizes of 512 bytes. Assume that the information about each file is already in memory. For each of the three allocation strategies (contiguous, linked, and indexed), answer these questions:
a. How is the logical-to-physical address mapping accomplished in this system? (For the indexed allocation, assume that a file is always less than 512 blocks long.)
b. If we are currently at logical block 10 (the last block accessed was block 10) and want to access logical block 4, how many physical blocks must be read from the disk?
The homework is slightly modified (starting at logical block 12, and wanting to access logical block 3 rather than 10 and 4, respectively).
The answers:
Answer: Let Z be the starting file address (block number).
a. Contiguous.
Divide the logical address by 512 with X and Y the resulting quotient and remainder respectively.
i. Add X to Z to obtain the physical block number. Y is the displacement into that block.
ii. 1
b. Linked.
Divide the logical physical address by 511 with X and Y the resulting quo-tient and remainder respectively.
i. Chase down the linked list (getting X + 1 blocks). Y + 1 is the displacement into the last physical block.
ii. 4
c.Indexed.
Divide the logical address by 512 with X and Y the resulting quotient and remainder respectively.
i. Get the index block into memory. Physical block address is contained in the index block at location X. Y is the displacement into the desired physical block.
ii. 2
I have no idea where these answers come from, and every online resource simply regurgitates these over and over. Can anyone provide a more thorough explanation?