Skip to content
Chethan Yadav_
Operating Systems

OS/Lesson 9 of 9/6 min read

File Systems, Disk Scheduling and I/O

Files, directories, allocation methods, inodes, free space management, journaling, disk scheduling algorithms, RAID, and I/O techniques.


On this page

File System

A file system organizes data on storage into files and directories and controls how it is stored and retrieved.

A file is a named collection of related data. Attributes: name, type, size, location, owner, permissions, timestamps.

File operations: create, open, read, write, seek, close, delete, truncate. The OS keeps an open file table per process (file descriptors) and a system-wide table.

Access methods

  • Sequential: read in order (logs, tapes).
  • Direct (random): jump to any block (databases).
  • Indexed: an index points to blocks (ISAM).

Directory structures

  • Single-level: one directory for everyone; name collisions.
  • Two-level: one directory per user.
  • Tree-structured: hierarchical directories with absolute and relative paths (most common).
  • Acyclic graph: allows sharing files via links.
  • General graph: allows cycles; needs garbage collection.

Allocation methods

How file blocks are placed on disk.

Contiguous File Allocation

Each file occupies consecutive blocks; the directory stores start block and length.

Linked Allocation

Each block points to the next block; the directory stores the first and last block.

  • No external fragmentation; files grow easily.
  • Random access is slow (must follow pointers); a broken pointer loses the rest of the file.
  • FAT (File Allocation Table) is a variant that keeps all next-pointers in one table at the start of the disk.

Indexed Allocation

Each file has an index block holding pointers to all its data blocks.

  • Fast random access, no external fragmentation.
  • Overhead of the index block; large files need linked or multilevel index blocks.

Inode

Unix file systems (ext4) use an inode per file. It stores metadata (owner, permissions, size, timestamps, link count) and block pointers, but not the file name. Names live in directory entries that map name to inode number.

Inode block pointers (ext2/ext3 style):

  • 12 direct pointers
  • 1 single indirect (points to a block of pointers)
  • 1 double indirect
  • 1 triple indirect

This gives fast access to small files and still supports huge ones.

A hard link is another directory entry pointing to the same inode. The file is deleted only when the link count reaches 0. Cannot cross file systems or link directories.

A symbolic (soft) link is a separate file containing a path to the target. Can cross file systems; breaks (dangles) if the target is deleted.

Free space management

  • Bit vector (bitmap): one bit per block, 1 = free. Easy to find contiguous free space.
  • Linked list: free blocks linked together.
  • Grouping / counting: store runs of free blocks as (start, count).

Journaling

A crash in the middle of an update (e.g. while creating a file) can leave the file system inconsistent. Journaling file systems (ext4, NTFS, XFS) first write the intended changes to a log (journal), then apply them. After a crash, the journal is replayed or discarded, so recovery is fast and does not need a full fsck. This is the same idea as write-ahead logging in databases.

Disk structure

A hard disk (HDD) has platters, tracks, sectors and cylinders. Access time:

access time = seek time + rotational latency + transfer time

Seek time (moving the arm) dominates, so disk scheduling minimizes head movement. SSDs have no moving parts, so seek-based scheduling matters much less there.

Disk Scheduling

Example: cylinders 0 to 199, head at 53, request queue 98, 183, 37, 122, 14, 124, 65, 67.

AlgorithmIdeaTotal head movement
FCFSServe in arrival order640
SSTFNearest request next236
SCANMove to one end serving requests, then reverse (elevator)236 (toward 0 first)
C-SCANMove one way to the end, jump back to start, continueMore uniform wait
LOOKSCAN but reverse at the last request, not the disk endLess than SCAN
C-LOOKC-SCAN but only to the last requestLess than C-SCAN

SSTF

Shortest Seek Time First: pick the closest request. Good throughput, but far requests can starve (like SJF).

SCAN

SCAN (elevator algorithm): the head sweeps in one direction serving requests, then reverses. No starvation.

C-SCAN

Circular SCAN: serves only in one direction; on reaching the end it returns to the start without serving. Gives more uniform waiting time than SCAN.

LOOK

LOOK and C-LOOK: like SCAN and C-SCAN, but the head only goes as far as the last request in that direction.

RAID

RAID (Redundant Array of Independent Disks) combines disks for performance and/or reliability.

LevelTechniqueMin disksFault toleranceNotes
RAID 0Striping2NoneFast, any disk failure loses everything
RAID 1Mirroring21 disk50% capacity, fast reads
RAID 5Striping + distributed parity31 diskGood balance, slow writes (parity update)
RAID 6Striping + double parity42 disksSafer for large arrays
RAID 10Mirroring + striping41 per mirror pairFast and safe, 50% capacity

RAID is not a backup: deleting a file or ransomware affects all copies.

I/O techniques

  • Programmed I/O: CPU polls the device; wastes cycles.
  • Interrupt-driven I/O: device interrupts when ready; CPU still moves each word.
  • DMA (Direct Memory Access): a DMA controller transfers whole blocks between device and memory; the CPU is interrupted only when done. Used for disks, network cards, GPUs. Details in I/O and parallelism.

Buffering, caching, spooling

  • Buffering: temporary storage to handle speed mismatches between producer and consumer (single, double, circular buffers).
  • Caching: keep copies of frequently used data in faster storage (page cache).
  • Spooling: Simultaneous Peripheral Operations On-Line. Output for a device that cannot interleave (a printer) is queued on disk and sent one job at a time.

Device drivers

A device driver is kernel code that knows how to talk to one device type, presenting a standard interface (block devices, character devices, network devices) to the rest of the OS.

Quick revision

  • Allocation: contiguous (fast, fragments), linked (no random access), indexed (inode).
  • Inode stores metadata and block pointers, not the name.
  • Hard link = same inode; soft link = path file.
  • SSTF can starve; SCAN/LOOK are fair; C-SCAN gives uniform wait.
  • RAID 5 survives one disk, RAID 6 two; RAID is not backup.