Monday, October 22, 2007

VFS explained

VFS stands for Virtual File System. VFS is an abstraction layer of a file system; it provides an interface or contract for anyone interested in implementing a real file system under Linux. With this pure abstraction, Linux OS can host multiple file systems without the client being aware of the differences. Many of the known file systems are: ext2, ext3, reiserfs, proc file system, nfs, etc...

To implement your own file system, one needs to create a kernel module and call during the module init the register_filesystem method with a file_system_type structure. It then adds the newly added file system to the list of file systems the kernel is aware of for mount or other syscalls. VFS makes specific file system call based on the registered file system mount point. The client or user is not aware of the VFS switch when traversing different mount point.

The file_system_type structure provides an entry point to setup the super block. A super block is created when our specific file system is mounted. The super block contains information of the entire file system and maintains a link to the root dentry mainly mount point entry.

After filling the file_system_type super block entry, the next step is to provide the specific file system operations for the: super operations, dentry operations, inode operations, file operations, export operations.

super operations provide file system handling operations like mount, remount. It also defines the inode handling such as read_inode, write_inode, delete_inode.

inode operations define the file or directory operations like create, lookup, mkdir, rename, getattr. A file or a directory is represented by an inode.

file operations implement the file specific operations like open, read, write, flush, lock.

dentry operations provide the dentry caching functionalities such as revalidate a dentry, hash, compare, delete, release. A dentry represents a directory entry that is maintained in the dcache. Each directory path component represents a dentry object. /hello/test contains the / dentry followed by hello dentry and test dentry.

No comments: