File, VFS (Virtual FileSystem), and Filesystem Abstraction

The Virtual File System (VFS) is a kernel-level abstraction layer that provides a unified interface to different filesystem implementations. It allows applications to use standard system calls (open, read, write, close) regardless of the underlying storage type—whether it is a local ext4 partition, an NFS mount, a tmpfs ramdisk, or a procfs pseudo-filesystem.

The File Abstraction

In Unix-like systems, "everything is a file." This is not just a slogan—it is a design principle implemented through the VFS. The file abstraction unifies:

  • Regular files: Stored on disk with byte-oriented content.
  • Directories: Special files that map names to other files.
  • Device files: Representing hardware devices (e.g., /dev/sda, /dev/null).
  • Pipes: Unnamed communication channels between processes.
  • Sockets: Network communication endpoints.
  • Symbolic links: References to other files by path.
  • Pseudo-filesystems: Dynamic views of kernel data (procfs, sysfs, debugfs).

VFS Architecture

The VFS sits between system calls and concrete filesystem implementations:

Application
    |
System Calls (open, read, write...)
    |
    V
VFS Layer
    |
    +---> ext4 driver
    +---> NFS client
    +---> tmpfs driver
    +---> procfs driver
    +---> ...
    |
    V
Block layer / Network / Kernel

When an application calls open("/etc/passwd", O_RDONLY):

  1. The VFS resolves the pathname, walking the directory tree.
  2. It identifies that /etc is a directory on the root filesystem (ext4).
  3. It looks up passwd in that directory's inode table.
  4. It returns a file descriptor (integer) representing the open file.

The application never knows or cares that ext4 is the underlying filesystem. It simply reads from the file descriptor.

Inodes and dentries

The VFS represents files using:

  • inode (index node): Contains metadata (owner, permissions, timestamps) and pointers to data blocks. Each inode has a unique number.
  • dentry (directory entry): Caches pathname components for fast resolution. The dentry cache stores recently traversed paths.

This separation allows the VFS to manage files by their inode number internally while presenting pathnames to applications.

Filesystem Types

Linux supports numerous filesystem types, each optimised for different use cases:

  • ext4: The default for many distributions. Journaled, reliable, mature.
  • XFS: High-performance, scalable, good for large files and parallel workloads.
  • Btrfs: Copy-on-write, snapshotting, checksumming, RAID support.
  • ZFS: Advanced features including checksums, compression, deduplication, and snapshots.
  • tmpfs: RAM-backed filesystem for temporary storage.
  • procfs/sysfs: Pseudo-filesystems exposing kernel and process information.
  • NFS/CIFS: Network filesystems for sharing files across machines.

Mounting

Filesystems are attached to the VFS namespace using the mount system call. The root filesystem is mounted at /. Other filesystems are mounted at mount points (empty directories).

The mount command and /etc/fstab control persistent mounts. The mount syscall accepts a filesystem type, device, and mount point, returning a superblock that the VFS uses to route subsequent operations.