Contents

Computer Science › Operating Systems

File System

How files and directories are stored and organized.

Also known as: filesystem, ext4, NTFS

A file system is how an operating system stores, names and organizes data on a storage device. It turns a pile of numbered blocks on a disk into the files and folders you know.

/
├── home/
│   └── ana/
│       └── notes.txt
└── etc/
    └── hosts

What it does

  • Names and paths: /home/ana/notes.txt identifies a file, in a tree of directories.
  • Tracks where the data is: a file’s contents may be scattered in blocks, and the file system remembers which.
  • Stores metadata: size, timestamps, owner and permissions.
  • Allocates and frees space as files grow, shrink and are deleted.
  • Keeps things consistent after a crash, often with a journal of pending changes.

Common file systems

File systemWhere
ext4, XFS, BtrfsLinux
APFSmacOS
NTFSWindows
FAT32, exFATUSB sticks and memory cards (portable, simple)
tmpfsa file system in RAM
Network file systems (NFS, SMB)files on another machine

Different file systems differ in maximum file size, case sensitivity, supported features and speed.

Things developers run into

  • Case sensitivity: Linux treats File.txt and file.txt as different. Windows and macOS (by default) don’t, causing bugs that appear only after deployment.
  • Path separators: / on Unix, \ on Windows. Use your language’s path functions.
  • Running out of space or inodes: a disk can be “full” even with free bytes if it runs out of file entries (inodes).
  • Atomicity: writing a file isn’t atomic. A crash mid-write leaves it half-written. Write to a temp file and rename.
  • Slow with millions of files in one folder, in some file systems.
  • Containers and volumes mount file systems into places (Docker volumes).
  • Object storage (like S3) is not a file system, although it looks similar (object storage).

See Linux directory structure for where things live.