Skip to content
Official PYQ · 2022

GATE CS 2022 Q53 — File Systems

Explain with AI
Consider two files systems A\text{A} and B\text{B}, that use contiguous allocation and linked allocation, respectively. A file of size 100100 blocks is already stored in A\text{A} and also in B\text{B}. Now, consider inserting a new block in the middle of the file (between 50th50^{th} and 51st51^{st} block), whose data is already available in the memory. Assume that there are enough free blocks at the end of the file and that the file control blocks are already in memory. Let the number of disk accesses required to insert a block in the middle of the file in A\text{A} and B\text{B} are nAn_{A} and nBn_{B}, respectively, then the value of nA+nBn_{A} + n_{B} is__________________.
View worked solution

Answer: 153

To find the total number of disk accesses, we calculate the disk reads and writes required for both allocation strategies.

1. Contiguous Allocation (nAn_A):

  • The file has 100100 blocks. Inserting a new block between the 50th50^{\text{th}} and 51th51^{\text{th}} block means the new block becomes the 51th51^{\text{th}} block.
  • The existing blocks from 5151 to 100100 (a total of 5050 blocks) must be shifted one position to the right.
  • Shifting these 5050 blocks requires reading them from disk and writing them back to their new locations: Reads=50,Writes=50\text{Reads} = 50, \quad \text{Writes} = 50
  • We then write the new block (which is already in memory) to the disk at the 51th51^{\text{th}} position: Writes=1\text{Writes} = 1
  • Thus, nA=50 (reads)+50 (writes)+1 (write)=101n_A = 50 \text{ (reads)} + 50 \text{ (writes)} + 1 \text{ (write)} = 101.

2. Linked Allocation (nBn_B):

  • To insert a block after the 50th50^{\text{th}} block, we must traverse the linked chain from the start to locate the 50th50^{\text{th}} block.
  • This requires reading blocks 11 through 5050: Reads=50\text{Reads} = 50
  • The pointer of the 50th50^{\text{th}} block (which points to the 51st51^{\text{st}} block) is copied to the new block's pointer in memory.
  • We write the new block to disk: Writes=1\text{Writes} = 1
  • We update the 50th50^{\text{th}} block's pointer to point to the new block and write it back to disk: Writes=1\text{Writes} = 1
  • Thus, nB=50 (reads)+1 (write for new block)+1 (write for 50th block)=52n_B = 50 \text{ (reads)} + 1 \text{ (write for new block)} + 1 \text{ (write for } 50^{\text{th}} \text{ block)} = 52.

Total Disk Accesses:

nA+nB=101+52=153n_A + n_B = 101 + 52 = 153

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore File Systems questions