Skip to main content

Operating Systems

File Systems

File-system questions are short and mechanical: choose an allocation scheme, compute the maximum file size from an inode layout or count head movement in disk scheduling. A small formula sheet is enough.

~4 hrs ~0.5–1 marks · Moderate 10 samples · 8 practice · 8 cards

GATE CSE file systems — file attributes and access methods, directory structures, contiguous / linked / indexed allocation, inode and maximum file size, free-space management and disk scheduling (FCFS, SSTF, SCAN, C-SCAN, LOOK), with worked examples, samples and drills.

Learning outcomes

  • Compare sequential, direct and indexed access and the common directory structures
  • Contrast contiguous, linked (FAT) and indexed allocation, and compute inode maximum file size
  • Work out bitmap size and other free-space-management numbers
  • Calculate total head movement for FCFS, SSTF, SCAN, C-SCAN and LOOK, and disk access time

Files, access methods and directory structures

  • A FILE is a named collection of related information on secondary storage. Attributes: name, identifier, type, location, size, protection, time and date. Operations: create, write, read, reposition (seek), delete, truncate, open and close.
  • ACCESS methods: SEQUENTIAL (read next / write next, tape-like), DIRECT or RELATIVE (read block n, needed by databases), and INDEXED (an index maps keys to record positions, as in ISAM).
  • A DIRECTORY maps file names to file control blocks. Operations: search, create, delete, list, rename, traverse. Goals: efficiency, naming (convenience, same name for different users) and grouping.
  • Directory structures: SINGLE-LEVEL (all files in one directory; naming problems, no grouping); TWO-LEVEL (a master directory with one user directory per user; path = user + file name, no grouping beyond that); TREE-STRUCTURED (arbitrary depth, absolute and relative paths, the current directory concept — the common structure); ACYCLIC-GRAPH (allows shared subdirectories/files via links); GENERAL GRAPH (cycles possible, needs cycle detection or garbage collection).
  • LINKS: a HARD link is another directory entry pointing to the same inode (the file is removed when the link count reaches 0); a SOFT (symbolic) link is a separate file containing a path name and can dangle if the target is deleted. Hard links cannot cross file systems.
  • MOUNTING attaches a file system to a point in the directory tree. PROTECTION in UNIX is by owner/group/other with read/write/execute bits: for example rwxr-xr-- = 754 octal.
  • The OPEN-FILE tables: a system-wide table (one entry per open file) and a per-process table with the file pointer and access mode; the open() system call returns an index (file descriptor).
  • Typical file-system layers: application programs → logical file system (directories, protection) → file-organization module (logical to physical blocks, free space) → basic file system → I/O control (drivers) → devices.
  • Directory implementation: a LINEAR LIST is simple but searching is O(n); a HASH TABLE gives fast lookup but needs collision handling and has a fixed size. A directory in UNIX is just a file containing (name, inode number) pairs.
  • PATH RESOLUTION cost: reading /usr/ast/mbox needs the root directory’s inode, the root directory block, the inode of usr, the usr directory block, the inode of ast, the ast directory block and finally the inode of mbox — each step is an inode read plus a directory-block read (up to 2 per component, plus the file’s data).
  • The FILE CONTROL BLOCK (inode in UNIX) holds permissions, dates, owner, size and block pointers. open() copies the FCB into the system-wide open-file table and returns an entry of the per-process table; close() decrements the open count and removes the system entry at 0.
  • Protection: the access-control list (ACL) attaches users and rights to each file; UNIX shortens it to owner/group/other. The setuid bit makes a program run with its owner’s rights. Octal for rwxr-xr-- is 754; rw-r--r-- is 644.
Directory structureFeatureDrawback
Single-levelsimple, fast searchunique names, no grouping
Two-levelseparate user directoriesusers cannot easily share
Treehierarchy, paths, groupingsharing needs extras
Acyclic graphshared files via linksdangling links, deletion issues
General graphmaximum flexibilitycycles, need garbage collection

Worked example

Problem. A file has permission bits rwxr-xr--. What is the octal value and who can write the file?

Solution. User rwx = 7, group r-x = 5, others r-- = 4 → 754. Only the owner can write.

Allocation methods, inodes and free space

  • CONTIGUOUS allocation: a file occupies consecutive blocks; the directory holds the starting block and length. Supports sequential and DIRECT access efficiently (block i is at start + i, minimal seeks) but suffers from EXTERNAL fragmentation and the difficulty of growing a file; the file size must be known in advance (extents help).
  • LINKED allocation: each block contains a pointer to the next; the directory points to the first (and last) block. No external fragmentation and files can grow, but direct access is slow (reading the i-th block takes i disk reads), pointers waste space (e.g. 4 bytes of a 512-byte block), and one lost pointer breaks the file. The FAT (file allocation table) keeps the links in a table at the start of the volume (cached in memory), so direct access is fast again.
  • INDEXED allocation: an index block holds all the block pointers of a file; the directory points to the index block. Supports direct access with no external fragmentation; overhead is the index block (even for tiny files). For large files use a LINKED index scheme, MULTILEVEL index or the COMBINED scheme.
  • UNIX INODE (combined scheme): an inode stores attributes (owner, permissions, sizes, times, link count) and, for example, 12 DIRECT block pointers, 1 SINGLE-indirect, 1 DOUBLE-indirect and 1 TRIPLE-indirect pointer. The inode does NOT contain the file name — that is in the directory entry (name → inode number).
  • Maximum file size with block size B and pointer size P: pointers per block = B / P = n. Max blocks = D + n + n^2 + n^3 (D direct, one single, double and triple indirect). Max size = blocks × B. Example: B = 1 KB, P = 4 B → n = 256; with 10 direct, one single and one double indirect pointer: 10 + 256 + 65536 = 65802 blocks = 65802 KB.
  • Single-level index only: with a 512-byte block and 4-byte pointers the index block holds 128 pointers, so the maximum file is 128 × 512 B = 64 KB.
  • FREE-SPACE management: BITMAP / bit vector (1 bit per block; size = number of blocks / 8 bytes; easy to find contiguous runs), LINKED LIST of free blocks, GROUPING (first free block holds n addresses), COUNTING (start + length). For a 1 GB disk with 4 KB blocks: 2^18 blocks → bitmap = 2^18 bits = 32 KB.
  • Block size trade-off: large blocks give higher throughput but more internal fragmentation; small blocks waste less space but need more pointers and seeks.
  • Linked allocation payload: with a 512-byte block and a 4-byte next pointer only 508 bytes of data fit per block; a file of 5080 bytes needs 10 blocks, and reaching byte 4000 needs reading block number 4000 div 508 = 7 (eighth block), i.e. 8 reads from the start.
  • FAT size: FAT has one entry per disk block, wide enough to hold a block number. A 1 GB volume with 4 KB blocks has 2^18 blocks, so each entry needs 18 bits (stored as 4 bytes in FAT32-style layout) and the table is about 2^18 × 4 B = 1 MB; keeping it in memory makes random access cheap.
  • EXTENTS (contiguous chunks plus a link between chunks) keep most of the speed of contiguous allocation while allowing growth; modern file systems (ext4, NTFS) use them.

Formulas to remember

  • pointers per block n = block size / pointer size
  • max file size = (direct + n + n^2 + n^3) × block size (all levels present)
  • bitmap size (bytes) = (disk size / block size) / 8
MethodDirect accessExternal fragmentationGrowth
Contiguousexcellentyeshard
Linkedpoor (i reads for block i)noeasy
FATgood (table in memory)noeasy
Indexed / inodegoodnobounded by index scheme

Worked example

Problem. An inode has 12 direct pointers, 1 single-indirect, 1 double-indirect and 1 triple-indirect pointer. Block size is 4 KB and a pointer is 4 bytes. What is the maximum file size?

Solution. Pointers per block n = 4096 / 4 = 1024 = 2^10. Blocks = 12 + 2^10 + 2^20 + 2^30. The triple-indirect term dominates: 2^30 blocks × 4 KB = 2^42 bytes = 4 TB, plus about 4 GB + 4 MB + 48 KB from the other levels, so the maximum is slightly more than 4 TB.

Three rows of sixteen disk blocks showing contiguous allocation of two files, a linked chain 1 to 4 to 7 to 12, and an index block 6 listing blocks 3, 9, 10 and 13.
Contiguous, linked and indexed allocation compared on a 16-block disk.

Inodes, directory entries and block-lookup numericals

  • To find which pointer covers a byte offset X: block index b = X div B. Direct pointers cover blocks 0 … D - 1; the single-indirect block covers the next n blocks (D … D + n - 1); the double-indirect covers the next n^2, and so on, where n = B / P.
  • Worked lookup: B = 1 KB, P = 4 B (n = 256), 10 direct + 1 single + 1 double. Byte 300,000 lies in block 300,000 div 1024 = 292. Direct covers 0-9, single covers 10-265, so block 292 is in the double-indirect range with offset 292 - 266 = 26: first-level index 26 div 256 = 0, second-level index 26 mod 256 = 26. Reading it takes the double-indirect block, one second-level block and the data block = 3 block reads (inode assumed in memory).
  • Counting all blocks of a file including index blocks: for a file of 5000 data blocks with the same inode, 10 are direct, 256 are under the single-indirect block (1 index block) and the remaining 4734 are under the double-indirect block: 1 top-level block + ceil(4734 / 256) = 19 second-level blocks. Total = 5000 + 1 + 1 + 19 = 5021 blocks.
  • Hard link count: creating a hard link increments the inode’s link count; the data blocks are freed only when the count reaches 0 and no process has the file open. Deleting the original name of a file that has another hard link does not delete the data.
  • An inode table is created at format time, so the maximum NUMBER of files is fixed (inodes exhausted although disk space remains is possible). The inode does not store the name, but the file’s size, owner, permissions, timestamps and the pointers.
  • Small files are very cheap in the inode scheme (12 direct pointers need no extra block), while contiguous and linked schemes need no index at all; indexed allocation with a plain index block wastes a block even for a 1-block file.
SchemeDisk reads to fetch logical block i (inode/directory cached)Fragmentation
Contiguous1external
Linkedi + 1 (follow i pointers)none (internal only)
FAT (table in memory)1 data readnone
Single index block2 (index + data)none
inode: direct / single / double / triple1 / 2 / 3 / 4none

Worked example

Problem. An inode has 10 direct pointers, 1 single-indirect and 1 double-indirect pointer. Block size is 1 KB and a pointer is 4 bytes. (a) Maximum file size? (b) Which pointer is used for byte 300,000 and how many block reads are needed?

Solution. (a) n = 1024 / 4 = 256. Blocks = 10 + 256 + 256^2 = 10 + 256 + 65,536 = 65,802 blocks = 65,802 KB ≈ 64.26 MB. (b) Block index = 300,000 div 1024 = 292, which is beyond 10 + 256 = 266 blocks, so the double-indirect pointer is used (first-level entry 0, second-level entry 26). Reads: double-indirect block, second-level index block, data block = 3.

A directory maps file names to inode numbers; the inode holds attributes and twelve direct, one single-indirect, one double-indirect and one triple-indirect pointer.
Directory entry (name, inode number) → inode → direct and indirect blocks. The file name is not in the inode.

Disk structure and disk scheduling

  • DISK ACCESS TIME = SEEK time (move the head to the cylinder) + ROTATIONAL LATENCY (wait for the sector; average = half a rotation) + TRANSFER time (data size / transfer rate). Seek time usually dominates, so schedulers minimise head movement.
  • Rotation time = 60 / RPM seconds, so a 6000 RPM disk rotates in 10 ms and has an average latency of 5 ms; a 7200 RPM disk has a 8.33 ms rotation and 4.17 ms average latency.
  • FCFS: serve in arrival order — fair but lots of head movement. SSTF (shortest seek time first): serve the closest request next — good average but can STARVE far requests. SCAN (elevator): the head sweeps in one direction to the end of the disk, then reverses; C-SCAN: sweeps in one direction only, and then returns to the start without serving (more uniform waiting time); LOOK and C-LOOK go only as far as the last request in each direction.
  • Example (cylinders 0-199, head at 53, queue 98, 183, 37, 122, 14, 124, 65, 67): FCFS = 640 cylinders; SSTF = 236; SCAN moving toward 0 first = 53 + 183 = 236; LOOK toward 0 first = (53 - 14) + (183 - 14) = 208; C-SCAN toward the high end = (199 - 53) + 199 + 37 = 382 including the return seek.
  • Which to choose: SSTF or LOOK are common defaults; for heavy load SCAN/C-SCAN avoid starvation. Performance of all schedulers depends on the number and type of requests and on the file-allocation method.
  • Other disk topics: RAID (striping for performance, mirroring or parity for reliability), disk formatting (low-level sectors, partitions, logical formatting), boot blocks, bad-block handling and swap space management.
  • Disk data transfer rate = data per track / rotation time. Example: 200 sectors × 512 B per track at 6000 RPM (10 ms) = 102400 B per 10 ms ≈ 10.24 MB/s.
  • Buffer cache and read-ahead make sequential reads faster; journaling file systems log metadata updates for fast crash recovery.
  • Totals for the standard queue (head at 53): FCFS 640, SSTF 236, SCAN toward 0 first 236 (53 + 183), LOOK toward 0 first 208, C-SCAN toward the high end 382 (including the return seek of 199), C-LOOK toward the high end 322 (130 + 169 + 23, including the jump 183 → 14).
  • Direction matters: SCAN or LOOK starting toward the HIGH end first would go 53 → 199 (146) and then back to 14 (185), total 331 for SCAN and 53 → 183 (130) then back to 14 (169) = 299 for LOOK. Always read which way the head is moving.
  • Worked access-time example: 7200 RPM disk, 400 sectors per track of 512 B, average seek 8 ms, read 4 KB (8 sectors). Rotation = 60 / 7200 = 8.33 ms; average latency 4.17 ms; transfer = 8 / 400 × 8.33 = 0.17 ms. Total ≈ 8 + 4.17 + 0.17 = 12.34 ms. Seek and latency dominate, so large sequential transfers are far cheaper per byte.
  • Starvation: SSTF can starve distant requests; SCAN, C-SCAN, LOOK and C-LOOK cannot because every request is reached on a sweep. FCFS is fair but slow. C-SCAN gives the most uniform waiting time because each sweep takes the same direction.

Formulas to remember

  • access time = seek + rotational latency + transfer time
  • rotation time = 60 / RPM seconds; average rotational latency = rotation time / 2
  • transfer time = bytes to read / transfer rate
AlgorithmIdeaRemark
FCFSarrival orderfair, high movement
SSTFnearest request firstlow movement, starvation possible
SCANsweep to the end, reverseelevator, no starvation
C-SCANsweep one way, jump backuniform wait
LOOK / C-LOOKSCAN but only to last requestless movement than SCAN

Worked example

Problem. Head at cylinder 53, queue 98, 183, 37, 122, 14, 124, 65, 67 (0-199). Find the total head movement for FCFS and SSTF.

Solution. FCFS: 53→98 (45), →183 (85), →37 (146), →122 (85), →14 (108), →124 (110), →65 (59), →67 (2) = 640. SSTF: 53→65 (12), →67 (2), →37 (30), →14 (23), →98 (84), →122 (24), →124 (2), →183 (59) = 236.

Three plots of head position for FCFS (640), SSTF (236) and SCAN toward cylinder 0 (236) on the queue 98 183 37 122 14 124 65 67 starting at cylinder 53.
Head movement for the standard queue: FCFS 640, SSTF 236, SCAN (to 0 first) 236, LOOK 208.

Exam tips

  • Max file size: pointers per block = B / P; add direct + single + double + triple (n, n^2, n^3 blocks) and multiply by B.
  • Contiguous = fast direct access but external fragmentation; linked = no fragmentation but slow direct access; FAT improves linked; indexed gives direct access without fragmentation.
  • The inode holds attributes and block pointers, NOT the file name; the directory maps names to inode numbers.
  • Disk scheduling: write the head path and add the absolute differences; remember whether SCAN goes to the physical end (0 / last cylinder) and LOOK only to the last request.
  • Average rotational latency = half of 60 / RPM seconds.
Exam pattern · 10 questions

GATE sample questions & answers

10 GATE-style MCQs for File Systems with full explanations. Attempt each question before revealing the answer.

Q1 GATE inode maximum-size pattern

An inode has 10 direct pointers, 1 single-indirect and 1 double-indirect pointer. The block size is 1 KB and a pointer is 4 bytes. The maximum file size is:

  • A) 10 KB
  • B) 266 KB
  • C) 65802 KB
  • D) 16 MB
Show answer & explanation

Answer: C

n = 1024 / 4 = 256. Blocks = 10 + 256 + 256^2 = 10 + 256 + 65536 = 65802; size = 65802 KB.

Q2

Which file-allocation method suffers from external fragmentation and needs the file size in advance?

  • A) contiguous
  • B) linked
  • C) indexed
  • D) FAT
Show answer & explanation

Answer: A

Contiguous allocation needs a hole large enough for the whole file, causing external fragmentation and growth problems.

Q3

In linked allocation, how many disk reads are needed to read the 5th block of a file (the directory gives the first block)?

  • A) 1
  • B) 4
  • C) 5
  • D) 6
Show answer & explanation

Answer: C

Blocks 1, 2, 3, 4 and 5 must be read in turn to follow the pointers: 5 reads.

Q4

The file allocation table (FAT) method improves linked allocation by:

  • A) storing the file in contiguous blocks
  • B) keeping the link pointers in a table at the start of the volume that can be cached
  • C) removing the directory
  • D) using triple-indirect blocks
Show answer & explanation

Answer: B

FAT holds the next-block links in a table, so following the chain needs memory lookups rather than disk reads for each block.

Q5

A 1 GB disk has 4 KB blocks. The size of the free-space bitmap is:

  • A) 4 KB
  • B) 32 KB
  • C) 256 KB
  • D) 1 MB
Show answer & explanation

Answer: B

Blocks = 2^30 / 2^12 = 2^18; one bit each = 2^18 bits = 2^15 bytes = 32 KB.

Q6 Textbook disk-scheduling example

Cylinders 0-199, head at 53, queue 98, 183, 37, 122, 14, 124, 65, 67. The total head movement under FCFS is:

  • A) 208
  • B) 236
  • C) 640
  • D) 382
Show answer & explanation

Answer: C

45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640 cylinders.

Q7

For the same queue and head position (53), the total head movement under SSTF is:

  • A) 208
  • B) 236
  • C) 382
  • D) 640
Show answer & explanation

Answer: B

Order 65, 67, 37, 14, 98, 122, 124, 183 with moves 12 + 2 + 30 + 23 + 84 + 24 + 2 + 59 = 236.

Q8

For the same queue and head at 53 moving toward cylinder 0 first, SCAN (to the physical end) gives a total movement of:

  • A) 208
  • B) 236
  • C) 382
  • D) 640
Show answer & explanation

Answer: B

The head goes 53 → 0 (53 cylinders) and then 0 → 183 (183 cylinders): 236. LOOK would reverse at 14 and give 208.

Q9

After the original file name of a file is deleted, which kind of link still gives access to the file’s data?

  • A) a soft (symbolic) link
  • B) a hard link
  • C) both
  • D) neither
Show answer & explanation

Answer: B

A hard link is another directory entry for the same inode; the data is freed only when the link count falls to zero. A soft link only stores a path and dangles.

Q10

Which directory structure permits sharing of files and subdirectories without allowing cycles?

  • A) single-level
  • B) two-level
  • C) acyclic-graph
  • D) general graph
Show answer & explanation

Answer: C

An acyclic-graph directory allows several paths to the same file through links but forbids cycles.

Topic drill · 8 questions

8 practice questions — File Systems

Extra page-specific practice beyond the GATE samples. Attempt all 8, then reveal answers to check your reasoning.

P1

The average rotational latency of a disk rotating at 6000 RPM is:

  • A) 2.5 ms
  • B) 5 ms
  • C) 10 ms
  • D) 20 ms
Show answer & explanation

Answer: B) 5 ms

One rotation takes 60 / 6000 = 10 ms; the average latency is half: 5 ms.

P2

Disk (0-199), head at 50, queue 82, 170, 43, 140, 24, 16, 190. The total head movement under FCFS is:

  • A) 208
  • B) 480
  • C) 642
  • D) 708
Show answer & explanation

Answer: C) 642

32 + 88 + 127 + 97 + 116 + 8 + 174 = 642.

P3

For the same disk and queue, the total head movement under SSTF is:

  • A) 208
  • B) 236
  • C) 332
  • D) 642
Show answer & explanation

Answer: A) 208

Order 43, 24, 16, 82, 140, 170, 190 with moves 7 + 19 + 8 + 66 + 58 + 30 + 20 = 208.

P4

A file system uses 512-byte blocks and 4-byte pointers with a single-level index block per file. The maximum file size is:

  • A) 512 B
  • B) 16 KB
  • C) 64 KB
  • D) 256 KB
Show answer & explanation

Answer: C) 64 KB

Pointers per index block = 512 / 4 = 128; 128 × 512 B = 64 KB.

P5

The octal permission for rwxr-xr-- is:

  • A) 644
  • B) 754
  • C) 755
  • D) 777
Show answer & explanation

Answer: B) 754

rwx = 7, r-x = 5, r-- = 4.

P6

In a UNIX file system the file name is stored in:

  • A) the inode
  • B) the directory entry
  • C) the data block of the file
  • D) the boot block
Show answer & explanation

Answer: B) the directory entry

A directory entry maps a name to an inode number; the inode holds attributes and block pointers only.

P7

Which allocation method is best suited for random (direct) access to blocks with no external fragmentation?

  • A) contiguous
  • B) linked
  • C) indexed
  • D) none
Show answer & explanation

Answer: C) indexed

An index block gives direct access to any block and any free block can be used, so there is no external fragmentation.

P8

A track has 200 sectors of 512 bytes and the disk rotates at 6000 RPM. The transfer rate is about:

  • A) 1 MB/s
  • B) 5 MB/s
  • C) 10 MB/s
  • D) 50 MB/s
Show answer & explanation

Answer: C) 10 MB/s

One track (102400 bytes) is read in one rotation of 10 ms: 102400 / 0.01 s ≈ 10.24 MB/s.

Topic FAQs

How do I find the maximum file size from an inode description?

Compute pointers per block = block size / pointer size. Count blocks as direct + n + n^2 + n^3 (include only the levels the inode has), then multiply by the block size.

Why is linked allocation slow for direct access?

To reach block i you must follow i pointers, each needing a disk read. FAT keeps all pointers in a table that is cached in memory, which removes most of that cost.

What is the difference between SCAN and LOOK?

SCAN moves the head all the way to the end of the disk before reversing; LOOK reverses at the last pending request in that direction, so it moves less.

How much of file-systems theory does GATE ask?

Usually one short question: an allocation-method comparison, an inode maximum file size, a bitmap/FAT size or a disk-scheduling head-movement count. The weightage is small but the questions are quick marks.

Quick revision · 8 cards

8 flashcards — File Systems

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 Contiguous vs linked vs indexed allocation?
Q2 What does an inode contain?
Q3 Maximum file size formula for an inode?
Q4 Bitmap size for a disk?
Q5 Average rotational latency?
Q6 SCAN vs LOOK?
Q7 Which disk-scheduling algorithm can starve requests?
Q8 Hard link vs soft link?