Topic Overview
File Systems (EXT4, NTFS, FAT32)
Compare file systems: EXT4 (Linux), NTFS (Windows), FAT32 and their characteristics, features, and use cases.
File Systems (EXT4, NTFS, FAT32)
Why This Matters
Think of file systems like the organization system in a library. You could just throw all books in a pile (raw storage), but that would be chaos. Instead, you organize them by category, use a catalog system, and track which books are checked out. File systems do the same for storage—they organize data into files and directories, track metadata, and manage space.
This matters because the file system affects performance, reliability, and features. EXT4 has journaling (can recover from crashes), NTFS has advanced permissions, FAT32 is simple but limited. Understanding file systems helps you choose the right one for your use case and troubleshoot storage issues.
In interviews, when someone asks "How does the OS store files?", they're testing whether you understand file systems. Do you know how files are organized on disk? Do you understand journaling and recovery? Most engineers don't. They just save files and wonder why the system slows down.
What Engineers Usually Get Wrong
Most engineers think "all file systems are the same." But file systems have different features: journaling (EXT4, NTFS), permissions (NTFS), file size limits (FAT32 limited to 4GB), and performance characteristics. Understanding these helps you choose the right file system and troubleshoot issues.
Engineers also don't understand that file systems can fail. Disk corruption, power failures, or bugs can corrupt the file system. Journaling file systems (EXT4, NTFS) can recover from some failures, but not all. Always have backups, and understand your file system's recovery capabilities.
How This Breaks Systems in the Real World
A service was using FAT32 on a USB drive. Users tried to copy a 5GB file, but FAT32 has a 4GB file size limit. The copy failed. Users were confused—they had plenty of space, but the file was too large. The fix? Use a file system that supports large files (EXT4, NTFS). Or split large files into smaller chunks.
Another story: A service was using a non-journaling file system. When the server crashed during a write operation, the file system became corrupted. The system couldn't boot. Data was lost. The fix? Use a journaling file system (EXT4, NTFS). Journaling records changes before applying them, allowing recovery from crashes.
What is a File System?
File system organizes data on storage:
- File organization: How files are stored
- Directory structure: How directories are organized
- Metadata: File attributes, permissions, timestamps
- Allocation: How disk space is allocated
Functions:
- File management: Create, read, write, delete files
- Directory management: Organize files in directories
- Access control: Permissions, security
- Data integrity: Journaling, checksums
EXT4 (Fourth Extended File System)
EXT4 is the default file system for Linux.
Features
- Journaling: Logs changes before writing (faster recovery)
- Large files: Supports files up to 16TB
- Large volumes: Supports volumes up to 1EB (exabyte)
- Extents: Efficient allocation for large files
- Delayed allocation: Improves performance
- Backward compatible: Can mount EXT2/EXT3
Characteristics
File size: Up to 16TB
Volume size: Up to 1EB
Block size: 1KB, 2KB, 4KB
Journaling: Yes
Case sensitive: Yes
NTFS (New Technology File System)
NTFS is the default file system for Windows.
Features
- Journaling: NTFS log for recovery
- Large files: Supports files up to 16EB
- Large volumes: Supports volumes up to 16EB
- Permissions: ACLs (Access Control Lists)
- Compression: Built-in file compression
- Encryption: EFS (Encrypting File System)
Characteristics
File size: Up to 16EB
Volume size: Up to 16EB
Block size: 4KB (default)
Journaling: Yes
Case sensitive: No (case preserving)
FAT32 (File Allocation Table 32)
FAT32 is a legacy file system.
Features
- Simple: Simple structure, widely supported
- Compatibility: Works on all operating systems
- No journaling: No recovery mechanism
- Limited: Small file and volume sizes
Characteristics
File size: Up to 4GB
Volume size: Up to 2TB (theoretical), 32GB (practical)
Block size: Variable
Journaling: No
Case sensitive: No
Comparison
| Feature | EXT4 | NTFS | FAT32 |
|---|---|---|---|
| OS | Linux | Windows | All |
| File size | 16TB | 16EB | 4GB |
| Volume size | 1EB | 16EB | 32GB (practical) |
| Journaling | Yes | Yes | No |
| Permissions | Unix permissions | ACLs | Limited |
| Case sensitive | Yes | No | No |
| Compression | No | Yes | No |
| Encryption | No | Yes (EFS) | No |
Examples
File System Operations
// Create file (EXT4)
int fd = open("/path/to/file", O_CREAT | O_WRONLY, 0644);
write(fd, "Hello", 5);
close(fd);
// Read file
fd = open("/path/to/file", O_RDONLY);
char buffer[100];
read(fd, buffer, 100);
close(fd);
File System Information
import os
import stat
def get_file_info(filepath):
"""Get file system information"""
stat_info = os.stat(filepath)
return {
'size': stat_info.st_size,
'mode': stat(stat_info.st_mode),
'uid': stat_info.st_uid,
'gid': stat_info.st_gid,
'atime': stat_info.st_atime,
'mtime': stat_info.st_mtime,
'ctime': stat_info.st_ctime
}
Common Pitfalls
- File size limits: FAT32 4GB limit. Fix: Use NTFS or EXT4 for large files
- Case sensitivity: EXT4 case sensitive, NTFS not. Fix: Be aware of differences
- Permissions: FAT32 no permissions. Fix: Use NTFS or EXT4 for security
- Journaling: FAT32 no journaling, data loss risk. Fix: Use journaling file systems
Interview Questions
Beginner
Q: What are the differences between EXT4, NTFS, and FAT32 file systems?
A:
EXT4 (Linux):
- OS: Linux
- File size: Up to 16TB
- Volume size: Up to 1EB
- Journaling: Yes
- Permissions: Unix permissions
- Case sensitive: Yes
NTFS (Windows):
- OS: Windows
- File size: Up to 16EB
- Volume size: Up to 16EB
- Journaling: Yes
- Permissions: ACLs
- Case sensitive: No
FAT32 (Legacy):
- OS: All (universal)
- File size: Up to 4GB
- Volume size: Up to 32GB (practical)
- Journaling: No
- Permissions: Limited
- Case sensitive: No
Key Differences:
| Feature | EXT4 | NTFS | FAT32 |
|---|---|---|---|
| File size | 16TB | 16EB | 4GB |
| Journaling | Yes | Yes | No |
| Permissions | Unix | ACLs | Limited |
When to use:
- EXT4: Linux systems
- NTFS: Windows systems, large files
- FAT32: USB drives, compatibility
Intermediate
Q: Explain journaling in file systems. How does it improve reliability?
A:
Journaling logs changes before writing to disk.
How it works:
-
Write to journal
Transaction: Write file A Journal: Log "Write file A" (metadata + data) -
Write to disk
Apply changes to actual file system -
Commit
Mark transaction as complete in journal
Benefits:
- Faster recovery: Replay journal instead of full fsck
- Data integrity: Know what was being written
- Atomic operations: Transactions all-or-nothing
Example:
Without journaling:
Crash during write → File system inconsistent
Recovery: Full fsck (slow, may lose data)
With journaling:
Crash during write → Journal has record
Recovery: Replay journal (fast, consistent)
EXT4 Journaling:
- Metadata journaling: Logs metadata changes
- Full journaling: Logs data + metadata (slower, safer)
NTFS Journaling:
- NTFS log: Transaction log for recovery
- MFT (Master File Table): Tracks all files
Senior
Q: Design a file system that handles millions of files efficiently. How do you optimize directory structure, metadata storage, and file allocation?
A:
class HighPerformanceFileSystem {
private inodeTable: InodeTable;
private directoryIndex: DirectoryIndex;
private allocationManager: AllocationManager;
constructor() {
this.inodeTable = new InodeTable();
this.directoryIndex = new DirectoryIndex();
this.allocationManager = new AllocationManager();
}
// 1. Inode Structure
class Inode {
// Compact metadata
private metadata: {
mode: number; // Permissions
uid: number; // User ID
gid: number; // Group ID
size: bigint; // File size
blocks: number; // Number of blocks
atime: number; // Access time
mtime: number; // Modify time
ctime: number; // Change time
};
// Extents for large files
private extents: Extent[];
}
// 2. Directory Indexing
class DirectoryIndex {
// B-tree for fast lookup
private index: BTree;
async lookup(filename: string): Promise<Inode> {
// O(log n) lookup instead of O(n)
return await this.index.search(filename);
}
async createEntry(filename: string, inode: number): Promise<void> {
await this.index.insert(filename, inode);
}
}
// 3. Extent-Based Allocation
class AllocationManager {
// Extents: (start_block, length) instead of individual blocks
allocate(size: number): Extent[] {
// Find contiguous blocks
const extent = this.findContiguousBlocks(size);
return [extent];
}
}
// 4. Performance Optimization
optimizePerformance(): void {
// Delayed allocation: Allocate on write
// Prefetch: Read ahead
// Caching: Cache frequently accessed files
}
}
Features:
- Inode table: Efficient metadata storage
- Directory indexing: B-tree for fast lookup
- Extent allocation: Efficient for large files
- Performance: Delayed allocation, prefetch, caching
Failure Stories You'll Recognize
The File Size Limit: A service was using FAT32 on a USB drive. Users tried to copy a 5GB file, but FAT32 has a 4GB file size limit. The copy failed. Users were confused—they had plenty of space, but the file was too large. The fix? Use a file system that supports large files (EXT4, NTFS). Or split large files into smaller chunks.
The Corrupted File System: A service was using a non-journaling file system. When the server crashed during a write operation, the file system became corrupted. The system couldn't boot. Data was lost. The fix? Use a journaling file system (EXT4, NTFS). Journaling records changes before applying them, allowing recovery from crashes.
The Permission Denied: A service was trying to write files but got "permission denied" errors. The file system (NTFS) had strict permissions, and the service account didn't have write access. The fix? Understand file system permissions. Grant appropriate permissions to service accounts. Or use a file system with simpler permissions (FAT32) if permissions aren't needed.
What Interviewers Are Really Testing
They want to hear you talk about file systems as a choice with trade-offs, not just a given. Junior engineers say "EXT4 is for Linux, NTFS is for Windows." Senior engineers say "file systems have different features: journaling (EXT4, NTFS), permissions (NTFS), file size limits (FAT32 limited to 4GB). Choose based on your needs. Use journaling file systems for reliability. Understand file size limits and permissions."
When they ask "How does the OS store files?", they're testing:
-
Do you understand how file systems organize data?
-
Do you know the trade-offs between different file systems?
-
Can you choose the right file system for a use case?
-
File systems: Organize data on storage devices
-
EXT4: Linux default, journaling, large files (16TB)
-
NTFS: Windows default, journaling, very large files (16EB), ACLs
-
FAT32: Legacy, universal compatibility, limited (4GB files, 32GB volumes)
-
Journaling: Logs changes for faster recovery and data integrity
-
Best practices: Use journaling file systems, consider file size limits, understand permissions
How InterviewCrafted Will Teach This
We'll teach this through production failures, not definitions. Instead of memorizing "EXT4 is for Linux," you'll learn through scenarios like "why did our file copy fail even though we had space?"
You'll see how file systems affect reliability, performance, and features. When an interviewer asks "how does the OS store files?", you'll think about file system organization, journaling, and trade-offs—not just "files are stored on disk."
- Inodes - How file systems use inodes to store file metadata and organize data
- I/O Management - How file systems interact with I/O management and device drivers
- Disk Scheduling (SCAN, C-SCAN) - How disk scheduling optimizes file system I/O operations
- System Calls - How file operations are requested through system calls
- Memory Management - How file systems use memory for caching and buffering
Key Takeaways
File systems: Organize data on storage devices
EXT4: Linux default, journaling, large files (16TB)
NTFS: Windows default, journaling, very large files (16EB), ACLs
FAT32: Legacy, universal compatibility, limited (4GB files, 32GB volumes)
Journaling: Logs changes for faster recovery and data integrity
Best practices: Use journaling file systems, consider file size limits, understand permissions
Related Topics
Inodes
How file systems use inodes to store file metadata and organize data
I/O Management
How file systems interact with I/O management and device drivers
Disk Scheduling (SCAN, C-SCAN)
How disk scheduling optimizes file system I/O operations
System Calls
How file operations are requested through system calls
Memory Management
How file systems use memory for caching and buffering
What's next?