Skip to content
GATEiit

GATE CSE · Operating System

File systems

How an OS stores files on disk: directories and links, contiguous, linked, FAT and indexed allocation, UNIX inodes with indirect blocks, free-space management and disk access time, with the size and access-count numericals GATE asks.

Before you start

  • Disk scheduling →

    Seek time and head movement are the costs that file layout tries to reduce.

  • Linked lists and index arrays →

    Linked allocation is a linked list of blocks; indexed allocation is an array of block pointers.

  • Powers of two

    Disk, block and pointer sizes are powers of two, and every size calculation is done in exponents.

Concept notes

1. Files, directories and links

A file is a named sequence of bytes with attributes (name, type, size, owner, permissions, timestamps, location of its blocks). In UNIX the attributes and block pointers live in an inode; the directory entry holds only the name and the inode number.

When a file is opened, the OS copies its metadata into an in-memory open-file table; later reads and writes use that entry instead of searching the directory again.

Directory structures: single-level (one directory for all files; name clashes), two-level (one directory per user), tree (subdirectories, absolute and relative path names) and acyclic graph (a file may appear in several directories through links).

Hard link Symbolic (soft) link
What it is another directory entry for the same inode a small file that stores a path name
Inode link count increases by 1 target's count unchanged
After the original name is deleted data still reachable link dangles
Across file systems no yes
To a directory usually not allowed allowed

A file's data is freed only when its link count drops to 0 (and no process has it open).

2. Allocation methods

The disk is divided into fixed-size blocks. The allocation method decides which blocks a file gets and how the OS finds its k-th block.

Method How the k-th block is found Good Bad
Contiguous start +k fast sequential and random access, 1 read external fragmentation, files hard to grow
Linked follow k pointers from the first block no external fragmentation, easy growth random access needs k reads; a lost pointer loses the rest; pointer space in each block
FAT follow the chain in the File Allocation Table linked allocation with all links in one table; if the table is cached, random access needs no extra disk reads the table itself is large: one entry per disk block
Indexed look up entry k of the file's index block random access, no external fragmentation an index block per file, wasted for tiny files; one block limits file size

To read block k (counting from 1) with the directory entry in memory and nothing else cached: contiguous needs 1 read, linked needs k reads, indexed needs 2 (index block, then data).

All methods waste on average half a block at the end of each file (internal fragmentation). Bigger blocks mean fewer pointers and faster transfers but more internal fragmentation.

3. UNIX inode: multilevel indexing

An inode keeps a few direct pointers plus one single indirect, one double indirect and one triple indirect pointer. An indirect pointer leads to an index block full of pointers.

With block size B and pointer size p, one index block holds P=B/p pointers. So the inode can reach

(d+P+P2+P3) blocks,max file size=(d+P+P2+P3) B

for d direct pointers. Small files use only direct pointers, so they need no extra reads; large files still fit.

Which pointer serves byte offset x? Its block number is b=⌊x/B⌋ (from 0). Blocks 0 to d−1 are direct; the next P are under the single indirect; the next P2 under the double indirect; then triple.

Disk reads for that byte, with the inode in memory: direct 1, single indirect 2, double 3, triple 4 (one per index level plus the data block).

The maximum file size can also be capped by the size field or by the number of bits in a block address: with a-bit block addresses the disk has at most 2a blocks.

mode, owner, size10 directdatasingle indirectindexdatadouble indirectindexindexdatatriple indirectindexindexindexdataEach index block holds (block size / pointer size) pointers.
A UNIX inode: direct pointers reach data at once; each indirect level adds one index block on the way

4. Free-space management

The file system must track which blocks are free.

  • Bitmap (bit vector): one bit per block. Size = number of blocks bits. Finding a run of free blocks is easy, and the bitmap can be kept in memory for small disks.
  • Linked free list: each free block points to the next free block. No extra space, but finding many free blocks needs many reads.
  • Grouping: the first free block stores the addresses of n free blocks; the last of these stores the next n, and so on.
  • Counting: store (first free block, number of contiguous free blocks) pairs; good when free space comes in runs.

For comparison, a FAT also has one entry per block, but each entry is a block address (for example 4 bytes), so it is 32 times the size of a bitmap with the same number of blocks.

Working rule for any size question: number of blocks = disk size / block size, then multiply by bits (or bytes) per entry. Keep everything as powers of two.

5. Disk structure and access time

A disk has several platters, each with two surfaces; each surface has tracks, and each track has sectors. The same track on all surfaces forms a cylinder.

capacity=surfaces×tracks per surface×sectors per track×bytes per sector

The number of bits needed to address a sector is log⁡2 of the total number of sectors.

Time to read a block:

  • Seek time: move the head to the right track (use the given average).
  • Rotational latency: wait for the sector to come under the head. On average half a rotation: 12×60rpm seconds.
  • Transfer time: the fraction of the track read, times one rotation time. Equivalently, bytes read / transfer rate, where the rate is (bytes per track) / (rotation time).

Taccess=Tseek+12Trot+Ttransfer

When a file's blocks are scattered, every block pays seek and latency again. That is why contiguous layout reads large files much faster than a scattered linked layout.

Formulas to remember

Pointers per index blockB = block size, p = pointer size
P=Bp
Max file size with an inoded direct pointers; drop terms for missing indirect levels
(d+P+P2+P3)×B
Block holding byte offset xBlocks numbered from 0
b=⌊xB⌋
Bitmap size
disk sizeblock size bits
Disk capacity
surfaces×tracks×sectors×bytes per sector
Rotation time
Trot=60rpm s
Average access time
Taccess=Tseek+Trot2+Ttransfer

Common mistakes

  • Forgetting the direct pointers (or the single indirect term) when adding up the maximum file size.
  • Using the full rotation time as the average rotational latency; the average is half a rotation.
  • Counting blocks from 1 in one place and from 0 in another when finding which pointer serves an offset.
  • Mixing bits and bytes in bitmap sizes: one bit per block, so divide by 8 for bytes.
  • Saying a symbolic link increases the target's link count, or that a hard link can cross file systems.
  • Counting 1 read for the k-th block under linked allocation; every earlier block must be read for its pointer.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Maximum file size with an inode

numerical

An inode has 10 direct pointers and one single, one double and one triple indirect pointer. Blocks are 1 KB and a block pointer is 4 bytes. Find the maximum file size.

  1. Step 1: How many pointers fit in one index block?

    Try it on paper first.

Example 2: Which pointer, and how many reads?

numerical

Same file system with 1 KB blocks and 256 pointers per index block: 10 direct pointers, then single and double indirect. The inode is in memory and nothing else is cached. How many disk reads does it take to read the byte at offset 300,000?

  1. Step 1: Find the block number.

    Try it on paper first.

Example 3: Average time to read one block

numerical

A disk spins at 7500 rpm, has an average seek time of 4 ms, and stores 256 KB per track. Find the average time to read one 4 KB block.

  1. Step 1: Find the time for one rotation.

    Try it on paper first.

Example 4: Bitmap vs FAT size

numerical

A 16 GB disk (234 bytes) uses 4 KB blocks. Find the size of a free-space bitmap, and of a FAT with 4-byte entries.

  1. Step 1: Count the blocks.

    Try it on paper first.

Previous year questions

8 official GATE CSE questions on this topic, newest first.

Practise these 8 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.