Skip to main content
Be Bitwise

Filesystem Architectures

Operating System Fundamentals Compared · Operating Systems track

10 min read

In this module

How Operating Systems Store Your Data

File systems sit between the abstract world of files and folders and the gritty reality of disk sectors and flash cells. Each big OS has wrestled with that translation differently, picking its own trade-offs around workloads, reliability, and features. Look closely at three of them — ext4, NTFS, APFS — and you'll see entire design philosophies in miniature.

ext4: The Linux Workhorse

ext4 (Fourth Extended Filesystem) is the default on most Linux distros. It grew out of ext2 and ext3, keeping enough backward compatibility to upgrade in place while bolting on the modern features users now expect.

Inode-Based Design

ext4 is built around inodes (index nodes). Every file and directory gets one, and it holds every scrap of metadata about that object — except, oddly, the filename:

Filenames live separately, in directory entries that map a name to an inode number. That separation is exactly why hard links work — multiple entries can point at the same inode:

Directory "mydir" (inode 1000):

NameInodeNotes
.1000self
..500parent
hello.txt2001
data.bin2002
link.txt2001hard link to same inode as hello.txt

Here are the first 64 bytes of inode 2001 as they sit on disk (values illustrative, layout exact). Hunt for the filename; you won't find it.

First 64 bytes of an ext4 inode

0000........(..e(..e
0010(..e............
0020................
0030............A...

Click a coloured byte or a field name to decode it

Extents

ext4 uses extents rather than the old indirect block pointer scheme. An extent describes a contiguous range of physical blocks:

c
struct ext4_extent {
__le32 ee_block; // First logical block
__le16 ee_len; // Number of blocks
__le16 ee_start_hi; // Upper 16 bits of physical block
__le32 ee_start_lo; // Lower 32 bits of physical block
};

A single extent can describe up to 128 MB of contiguous data — 32,768 four-KB blocks. Huge files get a tree of extents instead of one flat list. The whole scheme is dramatically tidier than the old indirect-pointer mess, especially when files actually are contiguous on disk.

Journaling

ext4 uses a write-ahead journal to keep things consistent across crashes. Every change passes through the journal first, before any on-disk structure gets touched:

text
1. Write transaction to journal (metadata + optionally data)
2. Commit the journal transaction
3. Write actual changes to their final locations
4. Mark journal transaction as complete

ext4 supports three journaling modes:

  • journal: Both metadata and data are journaled (safest, slowest)
  • ordered (default): Only metadata is journaled, but data is written before metadata
  • writeback: Only metadata is journaled, data may be written in any order (fastest, risk of stale data after crash)
Journaling

A technique where file system changes are first recorded in a separate log (journal) before being applied. If the system crashes mid-operation, the journal can be replayed to complete or roll back the interrupted operation, preventing file system corruption. The trade-off is additional write overhead.

NTFS: The Windows File System

NTFS (New Technology File System) shipped with Windows NT and went a different direction from ext4 entirely.

Master File Table (MFT)

Forget inodes. NTFS organises itself around the Master File Table, a database-like structure where every entity on the volume is a file — including the MFT itself, recursively:

Master File Table:

MFT#Description
0$MFT (the MFT itself)
1$MFTMirr (MFT mirror copy)
2$LogFile (transaction log)
3$Volume (volume information)
4$AttrDef (attribute definitions)
5. (root directory)
6$Bitmap (cluster allocation bitmap)
7$Boot (boot sector)
8$BadClus (bad clusters)
9$Secure (security descriptors)
10$UpCase (uppercase table)
11$Extend (extensions directory)
12+User files and directories

Each MFT record is typically 1 KB and contains a set of attributes:

Every record starts with the same header. These are the first 64 bytes of one, up to the start of its first attribute (values illustrative):

First 64 bytes of an NTFS MFT record

0000FILE0.....?*....
0010....8...........
0020............@...
0030............`...

Click a coloured byte or a field name to decode it

One neat NTFS trick: tiny files (under roughly 700 bytes) can stash their entire contents inline inside the MFT record. No second disk seek needed.

NTFS Alternate Data Streams

NTFS lets a single file carry multiple data attributes — what Microsoft calls named data streams:

text
file.txt: (default stream - the normal file data)
file.txt:hidden:$DATA (alternate data stream named "hidden")
file.txt:notes:$DATA (alternate data stream named "notes")

Legitimate uses exist (storing macOS resource forks on NTFS shares, for example). So do plenty of dodgy ones, since most file viewers won't even show you the alternate streams sitting alongside a file.

NTFS Journaling

NTFS journals differently from ext4. It keeps two separate logs:

  • $LogFile: a redo/undo transaction log for metadata, structured rather like a database transaction log
  • $UsnJrnl (Update Sequence Number Journal): a stream of every change to files and directories, the kind of thing search indexers and backup tools live on

The $LogFile is what lets NTFS promise metadata consistency across crashes. Each operation gets wrapped in a transaction with both redo and undo records, so the recovery path can replay or roll back as needed.

APFS: Apple's Modern File System

APFS (Apple File System) shipped in 2017, finally retiring the venerable HFS+ across every Apple platform. It was designed from scratch with flash in mind, free of the assumptions a 1980s spinning-disk filesystem had to carry.

Copy-on-Write

ext4 and NTFS happily overwrite blocks in place. APFS doesn't. It's copy-on-write all the way for metadata, and for file data whenever blocks are shared with a clone or a snapshot. Change a block and the new version lands somewhere else, then a pointer flips atomically:

text
Before write: After write:
Superblock → Block A Superblock' → Block A'
(new data)
Block A still exists
(available for snapshots)

That design makes snapshots practically free. A snapshot is just a saved copy of the old superblock pointer, and you only pay storage for blocks that actually diverge after it's taken.

Space Sharing

APFS adds container-level space sharing. Several volumes (each its own filesystem) can pool the same physical storage between them:

Volumes don't have fixed sizes. They expand and shrink inside the container as the data demands, which makes partition-resizing rituals largely obsolete.

APFS Clones

APFS clones files and folders instantly. A fresh clone shares every data block with the original; nothing physically copies until somebody actually edits something:

text
Original file (10 GB): blocks [A, B, C, D, ...]
Clone: blocks [A, B, C, D, ...] (shared!)
After modifying clone's block B:
Original: blocks [A, B, C, D, ...]
Clone: blocks [A, B', C, D, ...] (only B' is new)

Duplicate a 10 GB file and you're done in milliseconds, with no real disk usage until the two copies start to drift apart.

File Permissions: Three Models

POSIX DAC (Linux)

Linux still runs on classic Unix DAC: three permission sets (owner, group, others) crossed with three permission types (read, write, execute):

text
-rwxr-xr-- 1 alice developers 4096 Jan 15 10:30 script.sh
│├─┤├─┤├─┤
│ │ │ └── Others: read only
│ │ └───── Group: read + execute
│ └──────── Owner: read + write + execute
└────────── File type: regular file

It's an elegantly simple model that hits a wall fast. You can't grant user "bob" read access without also handing it to every other member of the group. POSIX ACLs (setfacl/getfacl) bolt on richer permissions, but they're patchy in adoption.

Windows ACLs (NTFS)

Windows uses Access Control Lists with fine-grained permissions:

File: report.docx

DACL (Discretionary Access Control List):

ACETypePrincipalPermissions
1DenyDOMAIN\bobWrite (explicit deny overrides allow)
2AllowBUILTIN\AdministratorsFull Control
3AllowDOMAIN\aliceRead, Write, Execute
4AllowDOMAIN\ProjectTeamRead, Read Extended Attributes

SACL (System Access Control List):

AuditPrincipalAction
AuditDOMAIN\EveryoneSuccessful writes (for compliance)

Windows ACLs split apart concerns Linux lumps together:

  • DACL: who can do what to the object
  • SACL: which actions show up in the audit log
  • Deny ACEs: hard refusals. Windows checks ACEs in order and stops at the first one that settles the request, so tools keep the list in canonical order, with explicit denies ahead of explicit allows, as in the table above
  • Inheritance: parent directory ACEs propagate down to children
Key Concept
ACL Inheritance

Windows ACLs support inheritance - permissions set on a directory can automatically propagate to new files and subdirectories created within it. Each ACE has flags controlling whether it applies to the object itself, child files, child directories, or some combination. This creates a hierarchical permission model that simplifies administration of complex directory trees.

Each OS handles file references differently:

FeatureLinuxWindowsmacOS
Symbolic linkln -s target linkmklink link target (requires privilege)ln -s target link
Hard linkln target linkmklink /H link targetln target link
JunctionN/Amklink /J link target (directories only, local volumes)N/A
Shortcut.desktop files (application level).lnk files (shell level, not filesystem).alias files (Finder level)

One detail trips people up. Symbolic links get resolved at the filesystem layer — open the link and the kernel transparently follows it to the target. Windows shortcuts (.lnk) live a layer up, in Explorer's parsing logic. To NTFS, a .lnk is just a regular file. A program that opens it gets the shortcut metadata, not the file the user thought they were clicking on.

Performance Comparison

No filesystem wins everywhere, and benchmark results swing so much with the hardware and the workload that a league table would mislead. The design choices behind those results are easier to pin down:

Design choiceext4NTFSAPFS
Directory indexHTree (hashed tree)B+ treeB-tree
Designed aroundSpinning disks, works well on SSDsSpinning disksFlash and SSDs
SnapshotsNone built in (LVM or btrfs provide them)Not in the file system (Volume Shadow Copy works below it)Built in
Copying a fileFull copy of the dataFull copy of the dataInstant clone, blocks shared until one copy changes

Filesystem internals aren't optional knowledge if you do performance tuning, forensics, data recovery, or security research. Every one of these designs is a snapshot of its era's priorities and limits — what mattered, what hardware existed, what the platform was trying to be.