Chapter 2.4 - Virtual File System (VFS)
Learning Objectives
By the end of this chapter, you will be able to:
- Understand the role of the VFS
- Explain how VFS unifies different file systems
- Understand inodes and data structures
- Identify different types of file systems
What is the VFS?
The VFS (Virtual File System) is an abstraction layer in the Linux Kernel that provides a unified interface for accessing different types of file systems, whether they are local (ext4, xfs) or network (NFS, CIFS).
Roles of the VFS
1. Unified Interface
The VFS provides a single interface for:
- Opening, reading, writing, closing files
- Creating, deleting, renaming files
- Managing directories
- Managing permissions
2. Abstraction
Applications do not need to know:
- The type of file system
- The location (local or network)
- Implementation details
3. Performance
The VFS maintains caches:
- Inode cache: File metadata
- Dentry cache: File names and paths
- Buffer cache: File data
Inodes
An inode (index node) is a data structure that stores a file's metadata:
Stored information:
- File type (file, directory, link, etc.)
- Permissions (owner, group, others)
- File size
- Timestamps (creation, modification, access)
- Pointers to data blocks
- Number of links
Types of File Systems
Local File Systems
ext4 (Fourth Extended File System):
- Standard on most distributions
- Journaled (crash-resistant)
- Supports files up to 16TB
xfs:
- High performance for large files
- Used in enterprise
- Good for databases
btrfs:
- Advanced features (snapshots, compression)
- Copy-on-write
- Actively developed
Network File Systems
NFS (Network File System):
- File sharing over network
- Unix/Linux standard
CIFS/SMB:
- Windows compatible
- Cross-platform file sharing
Special File Systems
tmpfs:
- In memory (RAM)
- Fast but temporary
/tmp,/dev/shm
procfs:
- Interface to the kernel
/proc
sysfs:
- System information
/sys
Directory Structure
The VFS maintains a unified hierarchy:
/
├── bin/ # Essential binaries
├── etc/ # Configuration
├── home/ # Users
├── proc/ # Kernel interface (procfs)
├── sys/ # System interface (sysfs)
├── tmp/ # Temporary (tmpfs)
├── var/ # Variable data
└── ...
Useful Commands
# View mounted file systems
mount
df -h
# View inodes
ls -li
stat file
# View inode usage
df -i
# View file system types
mount | grep -E '^/dev'
Summary
In this chapter, you learned:
VFS: Unified interface for all file systems
Inodes: File metadata
Caches: Inode, Dentry, Buffer for performance
FS Types: Local (ext4, xfs), network (NFS), special (tmpfs, procfs)
Hierarchy: Unified structure with / as root
Next Steps
Chapter 2.5: Process Management
Chapter 2.6: Init Process and systemd
Chapter created on: December 2024