One of the reasons Linux can support many different file systems is its use of the Virtual File System (VFS). The VFS provides a common interface between user applications and the various file systems supported by the Linux kernel. Whether a file resides on an ext4 partition, an XFS volume, a network share, or a virtual file system such as procfs, applications access files using the same system calls.
This tutorial introduces the Virtual File System, explains why it exists, and describes how it allows Linux to work with many different file systems through a unified interface.
What Is the Virtual File System?
The Virtual File System (VFS) is a kernel subsystem that provides a standardized interface for file operations.
Instead of applications communicating directly with specific file system implementations, they interact with the VFS.
The VFS then forwards requests to the appropriate file system driver.
This design allows applications to work with many different file systems without needing to know their internal details.
Why the VFS Exists
Before the VFS abstraction layer, supporting multiple file systems would have been much more complicated.
Without a VFS:
- Applications would need file-system-specific code.
- Every file system would require its own programming interface.
- Software portability would suffer.
With a VFS:
- Applications use a single interface.
- File systems can be added without modifying applications.
- Linux can support local, network, and virtual file systems consistently.
The Role of the VFS
The VFS sits between user applications and actual file systems.
A simplified view looks like this:
Applications
|
v
System Calls
|
v
Virtual File System (VFS)
|
+------------------+
| |
v v
ext4 XFS
| |
v v
Storage Devices Storage Devices
The VFS hides implementation details and presents a uniform interface.
System Calls and the VFS
Applications interact with files through system calls.
Examples include:
open()
read()
write()
close()
stat()
Consider the following operation:
fd = open("report.txt", O_RDONLY);
The process works as follows:
- The application calls
open(). - The system call enters the kernel.
- The VFS receives the request.
- The VFS determines which file system contains the file.
- The appropriate file system driver handles the request.
- A file descriptor is returned to the application.
The application never needs to know whether the file resides on ext4, XFS, NFS, or another file system.
Supported File Systems
Linux supports many file systems through the VFS layer.
Examples include:
Native Linux File Systems
- ext2
- ext3
- ext4
- XFS
- Btrfs
Network File Systems
- NFS
- SMB/CIFS
- SSHFS
Virtual File Systems
- procfs
- sysfs
- tmpfs
Compatibility File Systems
- FAT32
- exFAT
- NTFS
All are accessed through the same VFS interface.
The VFS Object Model
Internally, the VFS uses several important data structures.
The most important are:
Superblock
A superblock represents a mounted file system.
It contains information such as:
- File system type
- Size information
- Status information
- File system operations
Every mounted file system has a corresponding superblock.
Inode
An inode represents an individual file.
It contains:
- File size
- Ownership
- Permissions
- Timestamps
- Pointers to file data
In Linux, every file has an associated inode.
Dentry
A directory entry (dentry) connects file names to inodes.
For example:
report.txt
|
v
inode
The dentry cache helps improve performance by reducing disk lookups.
File Object
A file object represents an open file.
When a process opens a file, the kernel creates a file object that tracks:
- Current file position
- Access mode
- Associated inode
Understanding Mount Points
Linux organizes all mounted file systems into a single directory tree.
For example:
/
├── home
├── var
├── usr
└── mnt
A file system can be mounted anywhere:
mount /dev/sdb1 /mnt/data
Once mounted, the VFS makes the file system appear as part of the unified directory hierarchy.
Applications do not need to know where one file system ends and another begins.
Virtual File Systems
Some Linux file systems do not store data on disk at all.
Instead, they provide information generated by the kernel.
procfs
Mounted at:
/proc
Provides process and kernel information.
Examples:
cat /proc/cpuinfo
cat /proc/meminfo
sysfs
Mounted at:
/sys
Provides information about hardware devices and kernel objects.
Examples:
ls /sys/class
ls /sys/block
These file systems exist entirely in memory.
The VFS and Network File Systems
The VFS also enables transparent access to remote storage.
For example:
mount -t nfs server:/share /mnt/share
Applications use ordinary file operations:
cat file.txt
The application sees a normal file.
The VFS handles communication with the network file system driver behind the scenes.
Caching in the VFS
To improve performance, the VFS uses several caches.
Examples include:
Dentry Cache
Stores recently used directory entries.
Inode Cache
Stores recently used inode information.
Page Cache
Stores file contents in memory.
Caching reduces disk access and improves overall system performance.
Benefits of the VFS
The Virtual File System provides many advantages:
Uniform Interface
Applications use the same system calls regardless of file system type.
Extensibility
New file systems can be added without changing applications.
Portability
Software works across many storage technologies.
Performance
Caching mechanisms improve efficiency.
Transparency
Local, network, and virtual file systems appear identical to applications.
Viewing Mounted File Systems
Display mounted file systems:
mount
Or:
df -T
Example output:
Filesystem Type
/dev/sda1 ext4
/dev/sdb1 xfs
tmpfs tmpfs
The VFS manages all of these file systems through the same interface.
VFS and Kernel Development
When developers create a new file system for Linux, they do not need to redesign file access mechanisms.
Instead, they implement the required VFS operations.
Examples include:
- Open
- Read
- Write
- Create
- Delete
The VFS connects these operations to standard Linux system calls.
This modular design has helped Linux support dozens of file systems over the years.
Conclusion
The Virtual File System (VFS) is one of the most important abstractions in the Linux kernel. It provides a uniform interface that allows applications to access many different file systems using the same system calls. By managing objects such as superblocks, inodes, dentries, and file objects, the VFS hides the complexity of underlying storage technologies and presents a consistent view of files and directories. Understanding the VFS is an important step toward understanding how the Linux kernel manages storage and why Linux can support such a wide variety of local, network, and virtual file systems.