Linux allows different filesystems to be accessed via a kernel software layer called Virtual File System (VFS). VFS handles all the system calls related to a standard Unix filesystem. The actual file systems implemented underneath the VFS need not use the exact same abstractions and operations internally. However, they must implement filesystem operations semantically equivalent to those specified with the VFS objects.
Any filesystem operation will go through:
- The system calls are invoked to access the VFS data structures and determine the filesystem where the accessed file belongs.
- The file is represented by a file data structure in kernel memory. This data structure contains a field called f_op that contains pointers to functions corresponding to different operations. The system call handler finds the pointer to the right function and invokes it.
VFS supported 3 groups of filesystem:
- Disk-based filesystems, i.e. etx2. etx4
- Network filesystems, i.e. NFS, AFS
- Special filesystems, /proc
VFS supports 4 filesystem data structures:
- Superblock stores the information of the filesystem. For disk-based filesystems, it is filesystem control block that store number of Inodes, disk blocks, start of the list of free disk blocks, etc. Destruction of the superblock will render the file system unreadable.
- File represents an open file, and is created in response to the open system call. It supports operations such as read, write, sendfile, lock, etc.
- Inode: we discussed in this post. For disk-based filesystems, this object corresponds to a file control block stored on disk.
- Dentry represents a directory entry that stores the mapping between file names and inode numbers because kernel does not understand filename*.
- Directory entries are cached in what is called the dentry cache - a type of disk cache which is a software mechanism that allows the kernel to keep in RAM some information that is normally stored on a disk, so that further accesses to that data can be quickly without a slow access to the disk.