notesonly.in

One notebook for every subject — open it anywhere.

Log in

File Systems: Complete Beginner's Guide With easy examples.

A file system is the software that organizes data on a disk into named files and folders, tracking where every byte lives and who may access it. Without one, a disk would be an unlabeled pile of blocks. A file system provides file names, directories, permissions, and a map from each file to the disk blocks holding its data.

This matters because everything on a computer — documents, photos, apps, the operating system itself — is stored through a file system. A well-designed file system keeps files safe when the power fails, finds data quickly, and wastes as little space as possible. Understanding inodes, allocation, and journaling explains why your disk behaves the way it does.

Key Concepts

  • Block/cluster: the smallest unit the disk allocates, typically 4 KB.
  • Inode: a data structure storing a file's metadata (size, owner, permissions, timestamps) plus pointers to its data blocks; the file name lives in the directory, not the inode.
  • Directory: a special file mapping names to inode numbers.
  • Allocation methods: contiguous (file occupies consecutive blocks — fast but fragments), linked (blocks chained by pointers — no fragmentation but slow random access), indexed (an index block lists all data blocks — the Unix inode approach).
  • Journaling: before changing the disk, the file system writes its plan to a journal (a write-ahead log); after a crash it replays the journal instead of scanning the whole disk.
  • Mount point: where a file system attaches into the directory tree, like / or D:.
  • Fragmentation: a file's blocks scattered across the disk, slowing down reads.

Formulas

  • Volume size = bytes_per_block × number_of_blocks.
  • With an indexed inode using 4 KB blocks and 4-byte block pointers: pointers_per_block = 4096 ÷ 4 = 1024.
  • Maximum file size ≈ 12 direct blocks + 1 single-indirect + 1 double-indirect + 1 triple-indirect block (the classic Unix inode layout).

Worked Example

An inode has 12 direct pointers plus single, double, and triple indirect pointers; block size 4096 bytes; each pointer 4 bytes.

  1. Pointers per block = 4096 ÷ 4 = 1024.
  2. Direct data = 12 × 4096 = 49,152 bytes = 48 KB.
  3. Single indirect = 1024 × 4096 = 4,194,304 bytes = 4 MB.
  4. Double indirect = 1024 × 1024 × 4096 = 4,294,967,296 bytes = 4 GB.
  5. Triple indirect = 1024³ × 4096 = 4 TB (theoretical; other limits apply first).

Total ≈ 48 KB + 4 MB + 4 GB + 4 TB — far more than most files need, which is why small files use only direct blocks and big files automatically grow through the indirect levels.

Common Misconceptions

  • "Deleting a file erases its data." Deleting only removes the directory entry and marks blocks free; the bytes remain until overwritten, which is why recovery tools work.
  • "Journaling makes a disk faster." Journaling adds writes; its payoff is fast, safe recovery after crashes, not speed.
  • "Defragmentation helps SSDs." SSDs have no seek time, so defragmenting them brings no benefit and only wears the drive.

Real-World Applications

  • ext4 on Linux servers, NTFS on Windows, APFS on Apple devices.
  • Journaling protects databases and prevents corruption on power loss.
  • Forensic tools recover "deleted" files from unoverwritten blocks.
  • Network file systems (NFS, SMB) share files across machines using the same concepts.

A file system maps names to inodes and inodes to disk blocks, with journaling guarding against crashes. The inode math shows how a few pointers scale from kilobytes to terabytes. Knowing this, you understand what delete really does — and why backups still matter.