Computer Science and IT‹›⌂ 0:00 studied

Module 9 · 16 min read · Free chapter

File systems and disk scheduling

In short

Indexed allocation gives direct access without external fragmentation, and an inode with 4 KB blocks and 4-byte addresses reaches about 4 TB. Disk access time is seek time plus rotational latency plus transfer time. SSTF cuts head movement but can starve requests, SCAN and C-SCAN sweep the disk, and RAID 5 survives one disk failure.

See it in 3DHard disk: platters, heads, seek time and disk scheduling. Turn it, cut it open, or just press Watch.
What are you preparing for? We show the practice and previous year questions of your exam.

Start from zero: the office record room

Walk into the record room of a government office. Thousands of files sit in numbered almirahs, and on the clerk's desk is an index register that says, for each file, which almirah, which shelf and which position it is in. Without that register, nobody could find anything, and new files would be pushed wherever a gap was left.

A disk is that record room, and the file system is the clerk with the register. It gives every file a name, remembers which disk blocks hold it, keeps track of the free blocks, and arranges files in folders so that people can find them.

There is one more problem. The disk has a single moving arm, like a clerk who must walk to each almirah, so the order in which requests are served decides how much walking is done. In this chapter we study files, directories, the ways blocks are allocated, the inside of a hard disk, disk scheduling and RAID.

Why it matters. Your photos, exam forms and bank statements all live in files. A good file system keeps them safe and quick to reach, and a poor one loses space, time or even data.

Files and directories

A file is a named collection of related data on secondary storage. The OS keeps its attributes: name, a unique identifier, type, location on disk, size, protection (who may read, write or execute) and timestamps. The basic operations are create, open, read, write, reposition (seek), delete and truncate.

Opening a file is a separate step for speed. The OS finds the file once, copies its details into an open-file table in memory, and returns a small handle, so later reads need no directory search. Files are read either by sequential access, one record after another like a tape, or by direct access, jumping straight to record number n, as a reservation system does.

A directory maps names to files, and its shape has changed over the years.

Structure Idea Limitation
Single-level one directory for everyone names clash; no grouping
Two-level one directory per user users cannot easily share files
Tree folders inside folders, with path names a file has exactly one parent
Acyclic graph a file or folder can appear in several places through links deletion and cycles need care

In a tree, an absolute path starts from the root, such as /home/asha/notes.txt, and a relative path starts from the current directory. Sharing is done with links. A hard link is a second directory entry pointing to the same inode, and the file is removed only when its link count drops to zero. A symbolic (soft) link is a tiny file that stores a path, so it can cross file systems, but it dangles if the target is deleted.

Why it matters. Every command that copies, moves or shares a file works on these structures. The hard-link and soft-link difference is a common one-mark question.

Allocation methods: contiguous, linked and indexed

A disk is divided into fixed-size blocks, and the file system must decide which blocks each file gets. There are three basic methods.

Contiguous allocation gives a file a run of consecutive blocks, so the directory stores only the start block and the length. Reading is very fast and direct access is easy: block i of a file starting at b is simply block b+ib + i. But it suffers external fragmentation, as in memory, and a file cannot grow if the next block is taken.

Linked allocation lets a file's blocks lie anywhere, with each block holding a pointer to the next. There is no external fragmentation and files grow freely. But reaching block i needs i disk reads, so only sequential access is efficient, some space in each block goes to the pointer, and one damaged pointer loses the rest of the file.

A file-allocation table (FAT) improves linked allocation by moving all the pointers into one table at the start of the disk, with one entry per block. The table can be cached in memory, so following the chain becomes fast.

Indexed allocation collects all the block addresses of a file into one index block. The directory points to the index block, and block i is found by reading entry i, so direct access is fast and there is no external fragmentation. The cost is a whole index block even for a tiny file, and a large file needs more than one index block.

Method Direct access External fragmentation File growth
Contiguous fast yes hard
Linked slow: follow the chain no easy
Indexed fast no easy, up to the index size

Why it matters. The choice decides how fast a database can jump to a record and how well a disk copes with files that grow. Real file systems mix these ideas, using runs of contiguous blocks inside an indexed scheme.

Inodes and free-space management

Unix-like systems use a smart form of indexed allocation. Each file has an inode holding its attributes and 15 block addresses: 12 direct addresses, one single indirect address pointing to a block full of addresses, one double indirect address and one triple indirect address. Small files use only the direct addresses, while huge files use the indirect ones.

Worked example 1 (maximum file size). Let blocks be 4 KB and addresses 4 bytes, so one index block holds 40964=1024=210\dfrac{4096}{4} = 1024 = 2^{10} addresses. The inode can then reach

12+210+220+230 blocks12 + 2^{10} + 2^{20} + 2^{30} \text{ blocks}

Multiplying by 4 KB gives 48 KB from direct blocks, 4 MB from single indirect, 4 GB from double indirect and 4 TB from triple indirect. So the largest file is a little over 4 TB, and the triple indirect part dominates.

Worked example 2 (index blocks for one file). A 100 MB file has 100×220212=25,600\dfrac{100 \times 2^{20}}{2^{12}} = 25{,}600 data blocks. The direct and single indirect addresses cover 12+1024=103612 + 1024 = 1036 blocks, leaving 25,600−1036=24,56425{,}600 - 1036 = 24{,}564 blocks for the double indirect part.

Those need ⌈24,5641024⌉=24\lceil \dfrac{24{,}564}{1024} \rceil = 24 second-level index blocks plus the one double indirect block itself. With the single indirect block, the file uses 1+1+24=261 + 1 + 24 = 26 index blocks besides the inode.

Free-space management. The file system must also know which blocks are free, and there are four common ways.

  • A bit vector keeps one bit per block, so finding a run of free blocks is fast with bit operations.
  • A linked list chains free blocks together, which wastes no extra space but is slow to scan.
  • Grouping stores the addresses of n free blocks in the first free block, so many free blocks are found with one read.
  • Counting stores a start address and a count for each run of free blocks, which suits contiguous allocation.

Worked example 3. A 1 TB disk with 4 KB blocks has 240212=228\dfrac{2^{40}}{2^{12}} = 2^{28} blocks. Its bit vector needs 2282^{28} bits, which is 2252^{25} bytes, or 32 MB.

Why it matters. Inode numericals appear in GATE almost every year, usually as maximum file size or as the count of index blocks. The method is always to find the number of addresses per block first.

Inside a hard disk: structure and access time

A hard disk drive stacks several metal platters on a spindle that spins them at a constant speed, such as 7200 rpm. Each platter has two surfaces, and each surface has its own read/write head on an arm; all arms move together on one actuator. The heads fly a tiny distance above the surface on a cushion of air and never touch it in normal use.

Each surface is divided into concentric rings called tracks, and each track into sectors, traditionally 512 bytes each. The set of tracks at the same arm position on all surfaces is a cylinder, and data in one cylinder can be read without moving the arm.

Worked example 4 (capacity). A disk has 4 platters (8 surfaces), 10,000 tracks per surface, 500 sectors per track and 512 bytes per sector. Its capacity is

8×10,000×500×512=20,480,000,000 bytes8 \times 10{,}000 \times 500 \times 512 = 20{,}480{,}000{,}000 \text{ bytes}

which is 20.48 GB in decimal units.

Reading a sector takes three steps. The arm must seek to the right cylinder, the head must wait for the sector to rotate underneath, which is rotational latency, and then the data passes under the head, which is transfer time. So access time is seek time plus rotational latency plus transfer time.

Worked example 5 (access time). At 7200 rpm, one rotation takes 607200\dfrac{60}{7200} s, which is 8.33 ms, so the average rotational latency is half of that, about 4.17 ms. With an average seek of 5 ms and a 4 KB transfer at 100 MB/s, which takes about 0.04 ms, the average access time is about 5+4.17+0.04≈9.25 + 4.17 + 0.04 \approx 9.2 ms.

Seek time dominates, and it depends on how far the arm moves. That is why the OS orders disk requests to reduce total arm movement.

Why it matters. A disk access takes milliseconds while a memory access takes nanoseconds, a gap of about a million times. This gap explains page-fault costs, disk scheduling and the value of caching.

Disk scheduling: FCFS, SSTF, SCAN, C-SCAN and LOOK

Many processes send requests to one disk, and the OS chooses the order. The aim is to reduce total head movement, measured in cylinders, while still being fair. We use one example throughout: cylinders 0 to 199, the head at 50 and moving towards higher numbers, and the queue 82, 170, 43, 140, 24, 16, 190.

FCFS serves requests in arrival order: 50 → 82 → 170 → 43 → 140 → 24 → 16 → 190. The movement is 32+88+127+97+116+8+174=64232 + 88 + 127 + 97 + 116 + 8 + 174 = 642 cylinders. It is fair but wild, swinging back and forth across the disk.

SSTF (shortest seek time first) always goes to the nearest pending request. From 50 the nearest is 43, then 24, 16, 82, 140, 170 and 190, giving 7+19+8+66+58+30+20=2087 + 19 + 8 + 66 + 58 + 30 + 20 = 208 cylinders. It is much better, but like SJF it can starve requests far from the head if new nearby ones keep arriving.

SCAN (the elevator method) moves the head in one direction to the end of the disk, serving requests on the way, then reverses. Going up: 50 → 82 → 140 → 170 → 190 → 199, then down to 43, 24, 16, giving (199−50)+(199−16)=149+183=332(199 - 50) + (199 - 16) = 149 + 183 = 332 cylinders.

LOOK is SCAN that turns at the last request instead of the disk end. It goes up to 190 and back down to 16, giving (190−50)+(190−16)=140+174=314(190 - 50) + (190 - 16) = 140 + 174 = 314 cylinders.

C-SCAN (circular SCAN) serves requests in one direction only. It goes up to 199, jumps back to 0 without serving anything, and goes up again to 43. Counting the return jump, the movement is 149+199+43=391149 + 199 + 43 = 391; without it, 149+43=192149 + 43 = 192. C-LOOK turns at 190, jumps to 16 and goes up to 43: 140+174+27=341140 + 174 + 27 = 341 with the jump, or 140+27=167140 + 27 = 167 without it.

Method Order served Head movement
FCFS 82, 170, 43, 140, 24, 16, 190 642
SSTF 43, 24, 16, 82, 140, 170, 190 208
SCAN 82, 140, 170, 190, (199), 43, 24, 16 332
LOOK 82, 140, 170, 190, 43, 24, 16 314
C-SCAN 82, 140, 170, 190, (199, 0), 16, 24, 43 391, or 192 without the jump
C-LOOK 82, 140, 170, 190, 16, 24, 43 341, or 167 without the jump

Why prefer C-SCAN over SCAN? Just after SCAN passes a cylinder, a new request there must wait for a full trip out and back, while requests at the far end wait less. C-SCAN treats the disk as a circle, so waiting times are more uniform.

Why it matters. Disk scheduling numericals are short, exact and frequent in GATE and ISRO papers. The only real trap is the convention: read the direction of movement and whether the return jump is counted.

RAID levels: the basics

A single disk can fail and lose everything, and it can deliver only so much speed. RAID (redundant array of independent disks) combines several disks so that they act as one, faster or safer or both. Two ideas are used: striping, which spreads consecutive blocks over several disks so they can be read in parallel, and redundancy, which stores extra copies or parity so that a failed disk can be rebuilt.

Parity is the key trick. For a stripe of data blocks, the parity block is their bitwise XOR. If any one block is lost, XOR of all the survivors, including the parity, gives it back.

Level Idea Usable capacity with n disks Survives
RAID 0 block striping, no redundancy n disks no failure
RAID 1 mirroring: every block written twice half of the raw capacity one disk of each pair
RAID 4 striping with parity on one dedicated disk n−1n - 1 disks one failure
RAID 5 striping with parity spread over all disks n−1n - 1 disks one failure
RAID 6 striping with two independent parities n−2n - 2 disks two failures

Worked example 6. Five 2 TB disks give 10 TB under RAID 0. Under RAID 1, four of them form two mirrored pairs and give 4 TB, with one disk left as a spare. Under RAID 5 they give (5−1)×2=8(5 - 1) \times 2 = 8 TB, and under RAID 6 they give (5−2)×2=6(5 - 2) \times 2 = 6 TB.

RAID 4 has a bottleneck: every write must update the single parity disk. RAID 5 spreads the parity blocks over all disks, removing that bottleneck, which is why it is the common choice for file servers. RAID 0 is fastest but the least safe, since losing any one disk loses the whole array.

Why it matters. Bank and railway servers run on RAID so that a dead disk does not stop service. RAID is not a backup, though; a file deleted by mistake is deleted on every disk at once.

Descriptive lens: how written papers ask this

Written papers for IT officer posts, state Assistant Programmer exams and university-level tests ask about file systems and disks in four ways:

  1. Compare the allocation methods, or the directory structures, with their merits and drawbacks.
  2. Compute inode limits, disk capacity, access time or bit-vector size from given figures.
  3. Trace disk-scheduling methods on a request queue and compare the head movements.
  4. Explain RAID levels and recommend one for a stated need such as speed or safety.

Practice questions (our own, not previous-year questions).

  1. Compare contiguous, linked and indexed allocation of disk blocks with a diagram of each, and state which supports direct access efficiently. (15 marks)
  2. A disk has cylinders 0 to 299 and the head is at 120 moving outward. For the queue 45, 260, 130, 10, 190, 75, 285, find the total head movement under FCFS, SSTF, SCAN and C-LOOK. (15 marks)
  3. Explain RAID levels 0, 1 and 5 and recommend a level for a bank's transaction server, giving reasons. (10 marks)

Answer plan for question 3.

  • Define RAID as the use of several disks together for speed through striping and for safety through redundancy.
  • Explain that RAID 0 stripes blocks across all disks, gives the full capacity and the best speed, but loses everything if one disk fails.
  • Explain that RAID 1 mirrors every disk, survives a disk failure and gives fast reads, but uses half the raw capacity.
  • Explain that RAID 5 stripes data with parity spread across the disks, gives n−1n - 1 disks of capacity and survives one failure.
  • Recommend RAID 5, or RAID 6 for very large arrays, for a bank server, because it balances safety, capacity and read speed.
  • Add that RAID must be combined with regular backups, because it does not protect against deletion or corruption.

Quick revision

  • A file is a named collection of data with attributes, operations and sequential or direct access.
  • A hard link shares the inode, while a soft link stores a path and breaks if the target goes.
  • Contiguous allocation is fast but fragments, linked allocation has no direct access, and indexed allocation gives direct access through an index block.
  • With 4 KB blocks and 4-byte addresses, an index block holds 1024 addresses and an inode reaches a little over 4 TB.
  • A bit vector needs one bit per block, so a 1 TB disk with 4 KB blocks needs 32 MB.
  • Capacity is surfaces × tracks × sectors × bytes per sector, and a cylinder is the same track on all surfaces.
  • Access time is seek time plus rotational latency plus transfer time, and average latency is half a rotation.
  • For the chapter's queue the movements are FCFS 642, SSTF 208, SCAN 332, LOOK 314, C-SCAN 391 and C-LOOK 341.
  • SSTF can starve requests, and C-SCAN gives the most uniform waiting.
  • RAID 0 stripes, RAID 1 mirrors, RAID 5 has distributed parity with n−1n - 1 capacity, and RAID 6 survives two failures.

Check yourself

Exam-style questions on this chapter. Pick an answer to see the explanation. 0 of 15 answered

  1. Jumping straight to record number n of a file without reading the earlier records is:

  2. A file has two hard links. One name is deleted. Then:

  3. Which allocation method has no external fragmentation but supports only efficient sequential access?

  4. The file-allocation table (FAT) is a variant of:

  5. Blocks are 4 KB and disk addresses are 4 bytes. One index block holds how many addresses?

  6. An inode has 12 direct, one single, one double and one triple indirect address; blocks 4 KB, addresses 4 bytes. The largest file is about:

  7. A 1 TB disk with 4 KB blocks uses a bit vector for free space. Its size is:

  8. 8 surfaces, 10,000 tracks per surface, 500 sectors per track, 512 bytes per sector. Capacity is:

  9. The set of tracks at the same arm position on all surfaces is a:

  10. The average rotational latency of a 7200 rpm disk is about:

  11. Head at 50 (cylinders 0–199), queue 82, 170, 43, 140, 24, 16, 190. Total head movement under SSTF is:

  12. Same queue, head at 50 moving towards 199. Total head movement under SCAN is:

  13. Which disk-scheduling method can starve requests far from the head?

  14. Five 2 TB disks in RAID 5 give usable capacity of:

  15. Which RAID level has no redundancy?

Previous year questions

Previous year questions for UPSC CSE will appear here once each one is checked word for word against the official question paper.

Learn with AI

A tutor that asks instead of telling, a partner that argues the other side, and this chapter told through your own district.

Tell the tutor what you are stuck on. It will guide you with questions and give the answer after a few tries.

🙋 Raise a doubt or feedback

Stuck somewhere, or spotted a mistake? Write to the ExamHike team. We usually reply within a day, and you will see the reply on My progress.

Log in to ask a doubt or send feedback →

Frequently asked questions

What is the maximum file size with a Unix inode?

With 4 KB blocks and 4-byte addresses it is (12 + 2¹⁰ + 2²⁰ + 2³⁰) blocks of 4 KB, a little over 4 TB.

What is the difference between SCAN and LOOK?

SCAN moves the head to the physical end of the disk before reversing, while LOOK reverses at the last pending request.

What is the average rotational latency of a 7200 rpm disk?

One rotation takes 8.33 ms, so the average latency, half a rotation, is about 4.17 ms.

How much capacity does RAID 5 give?

With n equal disks RAID 5 gives the capacity of n − 1 disks, because one disk's worth of space holds distributed parity.

More in this module: Operating systems

Official sources

Facts in this chapter were checked against these official sources.

  1. GATE 2026 Computer Science and Information Technology (CS) syllabus, IIT Guwahati
  2. NPTEL Operating Systems (IIT Madras, 106106144): file systems and disk management