A file system controls how data is stored, organized, and retrieved on storage devices. It provides the abstraction of files and directories over raw disk blocks.
File Metadata (Inode in Unix/Linux)
Every file has metadata — data about the file. In Unix, this is stored in the inode (index node):
| Inode field | Description |
|---|---|
| File size | In bytes |
| Owner UID/GID | User and group ownership |
| Permissions | rwx bits for user/group/others |
| Timestamps | Access, modify, change times |
| Link count | Number of directory entries pointing to this inode |
| Block pointers | Direct, indirect, double-indirect pointers to data blocks |
Important: The inode does NOT store the filename. Filenames are stored in directory entries (dentries), which map filenames to inode numbers.
File Allocation Methods
| Method | How it works | Random access | Growth | Fragmentation |
|---|---|---|---|---|
| Contiguous | File occupies consecutive blocks | Fast — direct calculation | Difficult — need to move file | External |
| Linked | Each block points to the next | Slow — must traverse chain | Easy | None |
| Indexed | Index block holds all pointers | Fast — index block | Moderate | None (index overhead) |
Extents (Modern approach)
Used by ext4, NTFS. A file is described by a list of extents — contiguous block ranges. Combines contiguous allocation’s speed with indexed allocation’s flexibility.
Directory Structures
- Single-level: all files in one directory — naming conflicts
- Two-level: one directory per user
- Tree-structured: hierarchical directories — most common (Unix, Windows)
- Acyclic graph: directories can link to subdirectories (hard links)
Hard Links vs Soft Links
| Hard Link | Soft Link (Symlink) | |
|---|---|---|
| Points to | Same inode number | Path to target file |
| Survives target deletion? | Yes (inode still exists) | No (dangling link) |
| Across filesystems? | No | Yes |
| Directory link? | Typically no | Yes |
Q: What information is stored in an inode?
A: Size, owner, permissions, timestamps, link count, and pointers to data blocks. The filename is NOT stored in the inode — it’s stored in directory entries.
Q: Compare contiguous, linked, and indexed allocation.
A: Contiguous is fast for sequential access but hard to grow. Linked supports growth but no random access. Indexed supports both random access and growth but has index block overhead. Modern systems use extents (a hybrid approach).
Q: What’s the difference between a hard link and a symbolic link?
A: A hard link is another directory entry pointing to the same inode — deleting the original doesn’t affect it. A symbolic link is a special file containing the path to the target — if the target is deleted, the link breaks.
Q: How does the OS track free space?
A: Two common methods: (1) Bit vector — a bitmap where each bit represents a block (1 = free). (2) Linked list — each free block points to the next. Bit vectors are more efficient for locating contiguous free space.
Premium Content
Unlock File Systems & Inodes and all premium lessons with a subscription.
From ₹199.99/year — See plans