CS FundamentalsHardGATE CS (PYQ pattern)

A Unix-style file system has 1 KB blocks, 4-byte block pointers and inodes with 12 direct, one single-indirect and one double-indirect pointer. The inode is in memory. A program reads one byte at each offset 0, 100,000, 200,000, ..., 1,000,000 (11 reads, in that order). Every index (indirect) block, once read, stays cached; data blocks are never reused. How many disk-block reads occur in total?

  1. A. 29
  2. B. 15
  3. C. 16
  4. D. 17

Correct answer: C. 16

Block = offset / 1024: 0, 97, 195, 292, 390, 488, 585, 683, 781, 878, 976. Block 0 is direct; 97 and 195 use the single-indirect block (blocks 12-267, read once). Blocks 268 and up use the double-indirect block (read once) plus second-level index (b - 268) / 256: 292-488 use child 0, 585-683 use child 1, 781-976 use child 2. Index reads = 1 + 1 + 3 = 5, data reads = 11, total 16. Without caching it would be 29.

More Operating Systems questions

Exams that ask this topic