Open In App

Virtual File System

Last Updated : 09 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The virtual file system is one of the best features of Linux that makes Linux an operating system of choice. Format a pen drive in any Linux flavor operating system and try to see the contents in windows OS. Windows OS does not show anything. What is the problem?

Now try doing the same in windows i.e format a Pendrive in the windows operating system to store some files and then try to view these files through any Linux operating system. we will be able to see the contents. we will also be able to open and read file content easily.

How is that possible? The answer to these questions lies in the concept of the virtual file system that Linux support. VFX is a file system interface for a user process. VFS has the capability of conceiving features and behavior of any file system regardless of processor type memory format as well as hardware.

Two mapping functions are used that transform the properties of the real-time system to the characteristics required by VFS.

Virtual file system

Virtual File System

As shown in the diagram:

The user process initiates the execution of the system call with the help of the VFS method. VFS interprets this stimulus into an appropriate internal file system call which in turn activates the concerned mapping function of the specified file system.

In the case of an operating system that demands structural changes, all required constructs are created dynamically to meet the requirements. Ex: In FAT-compatible systems, directories are not treated as files so such characteristics are dynamically created since they cannot be mapped. The target file system is then activated to take control so that results can be delivered to the user of the system.

As seen in the above diagram actions and reactions are observed as a role of VFS:

The user initiates a file-oriented system call.

  1. Kernel calls function in VFS.
  2. Execution of file system independent manipulation and initiation of target file system call.
  3. mapping of calls from VFS to the target file system.
  4. The target file system converts the request into device driver execution.
  5. Appropriate action is completed as per the guidance of the device driver function and the results are obtained.
  6. Since VFS objects are implemented as C data structures. Every object is attached with data and pointers.

Primary Types in VFS

  1. Superblock object: point out specific mount points.
  2. inode object: Relates specific file.
  3. Directory: Shows entry to a specific directory.
  4. File object: Depicts an open file that is used by the process.

1. Tmpfs virtual file system: A virtual file system for Linux called tmpfs stores data in the system’s virtual memory. The internal caches of the kernel serve as temporary storage for all files, much like any other virtual file system.

2. Sysfs virtual file system: When a device is added or withdrawn, the sysfs virtual file system dynamically updates the user-specified view of the system’s devices. The global, bus, and device discovery levels are represented by the directory hierarchy beneath /sys. The files on the global layer record the device’s power state, which is also programmable. The files in the bus layer report details about each device’s resources and IRQ number. The file system contains files that a device driver can use to access data or configurable interfaces.

The filesystem type, which is specified in include/linux/fs.h (and abbreviated here for brevity), must be known by the kernel in order to use a filesystem:

Example 1:

C++




struct file_system_type {
    const char* name;
    int fs_flags;
    int (*init_fs_context)(struct fs_context*);
    const struct fs_parameter_spec* parameters;
    struct dentry* (*mount)(struct file_system_type*, int,
                            const char*, void*);
    void (*kill_sb)(struct super_block*);
    struct module* owner;
    struct file_system_type* next;
    struct hlist_head fs_supers;
};


  • struct file_system_type maintains data related to a filesystem but is not associated with any particular ‘instance of a filesystem’.
  • The userspace command cat /proc/filesystems can be used to inspect the linked list of known filesystem types that the VFS keeps.
  • Filesystem types are unregistered and registered in the kernel through these functions in include/linux/fs.h: 
  • A filesystem of a certain type may be mounted to a place in the directory tree if the kernel is aware of it (i.e., it has been registered).


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads