NivaarExam PrepOfficial exam papers ↗

25-Comp-A5 Operating Systems · May 2015

Question 7 of 7: Contiguous File Block Operations; Fragmentation; Disk Reliability; File Protection

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

98-COMP A-5 Operating Systems — National Examinations, May 2015. 3 hours, closed book (approved calculators only), 100 marks. Candidates were instructed to answer any five of the seven questions; all seven are answered below as a complete study resource.

Reference texts: Silberschatz, Galvin & Gagne, Operating System Concepts (10th ed.) — scheduling (ch. 5), process synchronization/monitors (ch. 6–7), deadlocks (ch. 8), memory management/paging (ch. 9–10), file systems and disk scheduling (ch. 11–12); Tanenbaum, Modern Operating Systems (5th ed.), corroborating chapters on scheduling and file systems.

Question 7: Contiguous File Block Operations; Fragmentation; Disk Reliability; File Protection (20 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given (a). A 125-block file under contiguous allocation; the directory and the file's known length reside entirely in main memory (free, uncounted); no room to extend the file at the beginning, room to extend at the end; ignore free-space bookkeeping.

Find. The minimum disk-operation count (1 op = 1 block read or 1 block write) for cases (A), (B), (C).

Approach. (A) and (B) are plain in-place content operations on blocks that already belong to the file — no shifting is needed since neither changes the file's length or block count. (C) inserts into the middle of a contiguous run, which (with room only at the end) forces every block after the insertion point to physically shift one slot toward the end before the new content can be written in.

  1. (A) Copy block 100's contents to block 2. Both blocks already belong to the file; this is a plain overwrite — read the source, write the destination. $$\boxed{\text{Ops}_A = 1\ \text{read} + 1\ \text{write} = 2}$$
  2. (B) Exchange the contents of blocks 110 and 101. Both original contents must be preserved in memory simultaneously while the swap happens: read block 110 into a buffer, read block 101 into a second buffer, write the first buffer into block 101, write the second buffer into block 110. $$\boxed{\text{Ops}_B = 2\ \text{reads} + 2\ \text{writes} = 4}$$
  3. (C) Insert a new block after block 90 (contents = block 89's contents). The new block must occupy position 91, pushing what were blocks 91–125 (that is, $125-90=35$ blocks) each one slot toward the end (only possible because room exists there). Each of those 35 blocks must be individually read from its old position and written to its new position, one slot higher: $35 \times 2 = 70$ operations. The new block's own content (a copy of block 89, which is not shifted, since it sits before the insertion point) must then be produced: read block 89, write that content into the now-vacated slot 91: $2$ more operations. $$\text{Shift 35 blocks: } 35\times(1\text{ read}+1\text{ write}) = 70$$ $$\text{Write new content: } 1\text{ read (block 89)} + 1\text{ write (slot 91)} = 2$$ $$\boxed{\text{Ops}_C = 70 + 2 = 72}$$
Final Results — Question 7(a)
CaseOperationMinimum disk operations
(A)Copy block 100 → block 22
(B)Exchange blocks 110 and 1014
(C)Insert new block after block 90 (35 blocks shift)72

(b) How disk fragmentation occurs, and a control technique

Under contiguous (variable-partition) allocation, files of different sizes are repeatedly created, extended, and deleted; each deletion leaves behind a hole exactly the size of the file that vacated it, and over time these holes end up as many small, scattered gaps — external fragmentation — where the sum of all free space may be large, yet no single hole is big enough to satisfy the next request (exactly the mechanism behind Question 2(b)'s blocked Job 3, whose 204K request could not be met even though 100+42+85+76+70+91+125+150K of scattered free space existed in aggregate). A standard control technique is compaction: periodically relocate all currently-allocated files so that every hole is coalesced into one single contiguous free region at one end of the disk/partition — though on a physical disk (as opposed to main memory) compaction is expensive, since it means physically copying large amounts of data across the platters, so it is normally done rarely (e.g. offline defragmentation) rather than continuously. A more structural alternative used by nearly all modern file systems is to abandon contiguous allocation altogether in favour of linked or indexed (block-based) allocation, where a file's blocks need not be physically adjacent at all — external fragmentation is then eliminated by construction, since any free block anywhere on the disk can satisfy any request.

(c) Multiple disks for reliability

The standard technique is RAID (Redundant Array of Independent Disks). The simplest form, mirroring (RAID 1), duplicates every block written onto a second physical disk, so a single-disk failure is survived by simply redirecting all reads to the surviving copy, at the cost of 100% extra storage and doubled write traffic. Parity-based schemes (RAID 4/5) instead dedicate the equivalent of one disk's capacity across the array to a parity block computed (via XOR) across the corresponding blocks of every other disk; if any single disk fails, its data is reconstructed by XOR-ing the surviving disks together with the parity, at a much lower storage cost ($1/N$ extra) but a "small write penalty" (a single-block write requires reading the old data and old parity, then writing new data and new parity — four operations for what would be one operation on an unprotected disk). Both schemes tolerate exactly one simultaneous disk failure; surviving two at once requires a higher-redundancy scheme (e.g. RAID 6, dual parity).

(d) Goals of file-system protection in a multi-user system

A multi-user system stores many different users' files on shared physical storage, so without protection any user's process could read, alter, or destroy any other user's data, whether by an honest mistake (a wrong path, a buggy script) or deliberate malice. The goals of file-system protection are therefore: confidentiality — preventing unauthorized users from reading a file's contents; integrity — preventing unauthorized users from modifying or deleting a file; controlled sharing — letting an owner grant specific other users or groups exactly the subset of access (read/write/execute) intended, no more and no less, rather than an all-or-nothing choice; and availability — ensuring one user's (or process's) actions cannot deny legitimate access to another user's own files. Mechanisms such as owner/group/other permission bits, access-control lists, and capability lists all exist to serve these same four goals with different trade-offs in flexibility, storage cost, and revocation ease.

Back to the paper →