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.
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 -th block.
Method
How the -th block is found
Good
Bad
Contiguous
start
fast sequential and random access, 1 read
external fragmentation, files hard to grow
Linked
follow pointers from the first block
no external fragmentation, easy growth
random access needs 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 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 (counting from 1) with the directory entry in memory and nothing else cached: contiguous needs 1 read, linked needs 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 and pointer size , one index block holds pointers. So the inode can reach
for direct pointers. Small files use only direct pointers, so they need no extra reads; large files still fit.
Which pointer serves byte offset ? Its block number is (from 0). Blocks to are direct; the next are under the single indirect; the next 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 -bit block addresses the disk has at most blocks.
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 free blocks; the last of these stores the next , 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.
The number of bits needed to address a sector is 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: 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).
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 block = block size, = pointer size
Max file size with an inode direct pointers; drop terms for missing indirect levels
Block holding byte offset xBlocks numbered from 0
Bitmap size
Disk capacity
Rotation time
Average access time
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 -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.
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?
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.
Step 1: Find the time for one rotation.
Try it on paper first.
Example 4: Bitmap vs FAT size
numerical
A 16 GB disk ( bytes) uses 4 KB blocks. Find the size of a free-space bitmap, and of a FAT with 4-byte entries.
Step 1: Count the blocks.
Try it on paper first.
Previous year questions
8 official GATE CSE questions on this topic, newest first.
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.