OS Notes
Introduction to file systems — what they are, why we need them, basic concepts of files and directories, and how file systems organize data on storage devices.
Introduction
When you save a document, close your laptop, and open it again the next day, your document is still there. This persistence — data surviving beyond a single program execution or power cycle — is provided by the file system. Without it, every byte of data would vanish the moment you shut down your computer.
A file system is the OS component that manages how data is stored, organized, and retrieved on persistent storage devices (hard drives, SSDs, USB drives). It provides the abstraction of "files" and "directories" — hiding the raw complexity of disk sectors and blocks behind a clean, intuitive interface. Think of it as the librarian that organizes millions of books (data blocks) into a system where you can find any book by its title (filename) and location (directory path).
Why Do We Need File Systems?
Without a file system, a disk is just a flat array of billions of bytes with no structure. You would need to remember exact byte positions for every piece of data. The file system solves several problems:
- Naming: Give data meaningful names instead of sector numbers
- Organization: Group related files into directories (folders)
- Access control: Control who can read, modify, or delete each file
- Persistence: Ensure data survives reboots and power failures
- Sharing: Allow multiple programs to access the same data
- Space management: Track which disk blocks are free and which are used
- Integrity: Protect against data corruption from crashes
Basic File System Concepts
Files
A file is a named collection of related data stored on secondary storage. From the user perspective, it is the smallest unit of persistent storage. Files can contain anything — text, images, executables, databases.
Directories (Folders)
A directory is a special file that contains a list of other files and directories. It provides hierarchical organization — grouping related files and enabling navigation through the file system.
Path
A path specifies the location of a file in the directory hierarchy:
- Absolute path: Full path from root —
/home/student/documents/report.pdf - Relative path: Path from current directory —
documents/report.pdf
Metadata
Information about a file (not the data itself): name, size, creation date, permissions, owner, location on disk. Stored separately from file content.
File System Architecture
Common File Systems
| File System | OS | Features |
|---|---|---|
| ext4 | Linux | Journaling, extents, 16TB file limit |
| NTFS | Windows | ACLs, encryption, compression, journaling |
| APFS | macOS/iOS | Copy-on-write, snapshots, encryption |
| FAT32 | Universal | Simple, no permissions, 4GB file limit |
| exFAT | Universal | Like FAT32 but no 4GB limit |
| XFS | Linux | High-performance, large file support |
| Btrfs | Linux | Copy-on-write, snapshots, RAID |
File Operations
The OS provides these basic operations on files:
- Create: Allocate space, add directory entry
- Open: Find file, load metadata, return file descriptor
- Read: Copy data from file to process memory
- Write: Copy data from process memory to file
- Seek: Move the read/write position within the file
- Close: Release file descriptor, flush buffers
- Delete: Remove directory entry, free allocated blocks
// Basic file operations in C
int fd = open("data.txt", O_RDWR | O_CREAT, 0644); // Open/create
write(fd, "Hello", 5); // Write
lseek(fd, 0, SEEK_SET); // Seek to beginning
read(fd, buffer, 5); // Read
close(fd); // Close
unlink("data.txt"); // DeleteReal-World Analogy
A file system is like a filing cabinet system in an office. The cabinet (disk) has drawers (partitions), folders (directories), and papers (files). Each paper has a label (filename) and is organized by category (directory structure). The filing clerk (file system) knows where everything is, can find papers quickly (indexing), and ensures only authorized people access sensitive documents (permissions). Without this system, papers would be piled randomly and finding anything would be nearly impossible.
Key Takeaways
- File systems provide persistent, organized, named storage on disk devices
- They abstract raw disk blocks into files and directories for user convenience
- Key operations: create, open, read, write, seek, close, delete
- Different file systems (ext4, NTFS, APFS) offer different features and tradeoffs
- The Virtual File System (VFS) layer provides a uniform API across different file system types
- File systems manage space allocation, metadata, access control, and data integrity
- Understanding file systems helps you make informed choices about storage and data management
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for File System Introduction.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, file, system, introduction, file system introduction
Related Operating Systems Topics