Virtual File System (VFS)
Relevant source files
The following files were used as context for generating this wiki page:
The Linux Virtual File System (VFS) provides an abstraction layer between the kernel and various concrete filesystem implementations. It allows user-space applications to access different filesystems using a uniform set of system calls, regardless of the underlying hardware or protocol. Every filesystem merged into the kernel becomes the collective responsibility of VFS maintainers.
VFS defines the standard interfaces that all filesystems must implement, including support for basic file operations like opening, reading, writing, and closing files. It manages core data structures such as inodes, dentries, and superblocks to maintain a consistent view of the file hierarchy across multiple mounted devices.
Sources: Documentation/filesystems/adding-new-filesystems.rst:12-20, Documentation/filesystems/api-summary.rst:7-12, Documentation/filesystems/nfs/nfsd-maintainer-entry-profile.rst:160-165
VFS Architecture and Components
The VFS architecture consists of several core objects that represent the state and structure of the filesystem.
Core Objects
| Component | Description |
|---|---|
| Superblock | Represents a mounted filesystem and contains metadata for the entire volume. |
| Inode | Represents an individual object within a filesystem (file, directory, etc.). |
| Dentry | Represents a directory entry, linking a filename to a specific Inode. |
| File Object | Represents an open file associated with a specific process. |
Sources: Documentation/filesystems/api-summary.rst:14-36
VFS Component Relationships
The following diagram illustrates how the core VFS components interact to resolve a file request.
This diagram shows the path from a process-specific file descriptor down to the filesystem type via VFS abstraction objects.
Sources: Documentation/filesystems/api-summary.rst:14-36, Documentation/filesystems/adding-new-filesystems.rst:110-115
Core APIs and Handling
VFS provides specialized APIs for handling metadata, directory caches, and locking.
Inode and Dentry Handling
VFS manages the lifecycle of inodes and dentries to optimize performance through caching.
- Directory Cache (dcache): VFS uses the dcache to quickly resolve pathnames to inodes.
- Inode Handling: Inodes are identified by numbers and contain file metadata. Functions in
fs/inode.chandle inode allocation and disposal.
Sources: Documentation/filesystems/api-summary.rst:18-32
System Call Interface
Standard system calls interact with VFS to perform I/O operations.
- Path Lookup: Resolves a string path into a dentry/inode pair using
fs/namei.c. - Read/Write: Handles data transfer between user space and the kernel via
fs/read_write.c. - Superblocks: Handles filesystem registration and mounting via
fs/super.c.
Sources: Documentation/filesystems/api-summary.rst:34-70
Implementation Requirements for New Filesystems
New filesystems must adhere to modern VFS interfaces to be accepted into the kernel.
Technical Standards
- Folios: Use folios instead of raw page operations for page cache management.
- iomap: Use the iomap framework for block mapping and I/O instead of legacy buffer heads.
- Netfs: Network filesystems should utilize the netfs library where applicable.
- Mount API: Implement new filesystems using the updated mount API.
Sources: Documentation/filesystems/adding-new-filesystems.rst:45-60
Testing and Utilities
Filesystems require supporting userspace tools and verification frameworks:
- mkfs: A tool to create the filesystem format.
- fsck: A recommended tool to verify consistency and repair corruption.
- xfstests: The standard testing infrastructure for Linux filesystems.
Sources: Documentation/filesystems/adding-new-filesystems.rst:62-75
VFS Operation Flow
When a user application performs a file operation, VFS coordinates the flow between different components.
This diagram illustrates the sequence of operations for opening a file through the VFS layer.
Sources: Documentation/filesystems/api-summary.rst:18-36, fs/namei.c
Conclusion
The VFS acts as a critical engine for protocol translation and hardware abstraction. By enforcing consistent interfaces for inodes, dentries, and superblocks, it ensures that diverse filesystems—ranging from local FAT volumes to network-based NFS shares—interoperate seamlessly within the Linux environment. Maintaining this layer involves ongoing adaptation to infrastructure changes like folio migration and mount API updates.
Sources: Documentation/filesystems/adding-new-filesystems.rst:140-150, Documentation/filesystems/nfs/nfsd-maintainer-entry-profile.rst:298-305