There's a good blog about VFS http://www.ibm.com/developerworks/cn/linux/l-vfs/
It is recommended that you read this article first, and then continue reading the article.
VFS, a virtual file system, provides users with a file-and file-system-related interface.
These interfaces can be executed across various file systems and different media.
VFS provides a common file system model that encompasses the common feature sets and behaviors of any file system.
This model is biased towards UNIX-style file systems.
Data structure relationships
For example, describes the relationship between VFS-related data structures
UNIX File System
UNIX uses 4 traditional concepts related to file system: file , directory entry , index node , mount point
File
Simple byte-stream-oriented abstraction
Catalog items
Files are organized by directory, each part of the directory is a directory entry,/home/wolfman/butter,/, home, Wolfman, butter are directory entries, collectively referred to as catalog items
Index node
UNIX file system, separating the relevant information of a file from the file itself. File control information, such as permissions, owner, size, creation time, and so on "metadata", is stored in a separate data structure called the index node Inode
Mount point/Mount point
The entry directory for the disk file system in Linux, similar to the C:, D:, E:, and so on, used to access different partitions in Windows. [Baidu Encyclopedia entry]
File system information is stored in the Super block, which sets up separate file information and file system information.
For Fat,ntfs this, although it can also work on Linux, but must be encapsulated. For example, a file system does not support an index node, and the index node structure must be assembled in memory as if it were contained.
VFS objects and data structures
Super Block Object
- Represents a specific installed file system, represented by the super_block structure, defined in
<linux/fs.h>
- Contains the operand Super_operations object, including the method that the kernel can invoke for a particular file system, defined in
<linux/fs.h>
- The Super Block object is created and initialized with the Alloc_super () function. When the file system is installed, the file system calls the function to read the file system Super block from the disk and populate it with information into the in-memory super-block object
- Various file systems must implement a super Block object, which is used to store specific file system information, usually corresponding to a file system Super block or a system control block that resides on a disk-specific sector.
Super_block
http://lxr.free-electrons.com/source/include/linux/fs.h?v=3.11#L1242
Super_operations
http://lxr.free-electrons.com/source/include/linux/fs.h?v=3.11#L1604
- The
-
Index node object
- represents a specific file that contains all the information the kernel needs to manipulate a file or directory, represented by the inode struct, and defined in
<linux/fs.h>
The
- UNIX-style file system can be read directly from the Disk index node, and if a file system does not have an index node, the filesystem needs to extract the relevant information from disk (the file system with no inode usually takes the file description information as part of the file)
- index nodes must be created in memory for file system use
The
- contains the Action object Inode_operations object, including the method that can be called for a particular file, as defined in
<linux/fs.h>
The
- index node represents a file in the file system (but the index node is created in memory only when the file is accessed), or it can be a special file such as a device or pipeline
Inode
http://lxr.free-electrons.com/source/include/linux/fs.h?v=3.11#L523
Inode_operations
http://lxr.free-electrons.com/source/include/linux/fs.h?v=3.11#L1559
- Catalog Item Object
- represents a directory entry, which is an integral part of the path, represented by the dentry struct, and defined in
<linux/dcache.h>
- contains Dentry_ The operations object, which includes the method that the kernel can invoke for a particular directory, defines
<linux/dcache.h>
- VFS treats the directory as a file, Each component in the path is represented by an index node object. To facilitate the lookup operation, VFS introduces directory entries, each dentry represents a specific part of the path,/BIN/VI, this path, and/,bin,vi (file) are directory item objects.
- Catalog items can also include mount points,/mnt/cdrom/foo, constituent elements/,mnt,cdrom,foo are catalog items
- VFS When performing directory operations, if necessary, the catalog item objects are created on-site.
- The directory does not have a corresponding disk data structure, and VFS creates a
- directory entry in the directory item cache Dcache based on the string pathname to speed up the find operation
Dentry
/http lxr.free-electrons.com/source/include/linux/dcache.h?v=3.11#l106
Dentry_operations
/http// lxr.free-electrons.com/source/include/linux/dcache.h?v=3.11#l148
- File Object
- Represents a file opened by a process, represented by the file struct, defined in
<linux/fs.h>
- Contains the File_operations object, which includes a method that the process can invoke against a file that has already been opened, defined in
<linux/fs.h>
- Multiple processes can open and manipulate the same file at the same time, so the same file may correspond to multiple file objects.
- The file object represents the open file only in the process view, which in turn points to dentry (which in turn points to the inode), and only the directory entry represents the open actual file. File objects corresponding to the files are not unique, but the corresponding index nodes and directory item objects and files are unique.
File
http://lxr.free-electrons.com/source/include/linux/fs.h?v=3.11#L765
File_operations
http://lxr.free-electrons.com/source/include/linux/fs.h?v=3.11#L1528
Because the VFS handles the directory as a file, there is no directory object.
Other related data structures and file system-related data structures
- File_system_type
- Used to describe various specific file systems, as defined in
<linux/fs.h>
, for example, EXT3,EXT4
- Each file system, whether or not installed, has only one file_system_type structure
Kernel 3.11
structFile_system_type {Const Char*name;intFs_flags;#define FS_REQUIRES_DEV 1#define FS_BINARY_MOUNTDATA 2#define FS_HAS_SUBTYPE 4#define Fs_userns_mount 8 //can is mounted by userns root #define Fs_userns_dev_mount //A userns MOUNT does not imply Mnt_nodev #define FS_RENAME_DOES_D_MOVE 32768/* FS would handle d_move () during RENAME () internally. * / structDentry * (*mount) (structFile_system_type *,int,Const Char*,void*);void(*KILL_SB) (structSuper_block *);structModule *owner;structFile_system_type * NEXT;structHlist_head fs_supers;structLock_class_key S_lock_key;structLock_class_key S_umount_key;structLock_class_key S_vfs_rename_key;structLock_class_key S_writers_key[sb_freeze_levels];structLock_class_key I_lock_key;structLock_class_key I_mutex_key;structLock_class_key I_mutex_dir_key;};
- Vfsmont
- Used to describe an instance of an installation file system, defined in
<linux/mount.h>
- When a file system is actually installed, a VFSMOUNT structure is created at the mount point, representing an instance of the file system, in other words, representing the mount point.
struct vfsmount { struct dentry *mnt_root;/* root of the mounted tree */ struct super_block *mnt_sb;/* pointer to superblock */ int mnt_flags;};
and process-related data structures
File_struct
Information that is defined in relation to <linux/fdtable.h>
a single process is included
Fs_struct
Defined to <linux/fs_struct.h>
include file system and process related information
Namespace
Defined in <linux/mnt_namespace.h>
Enables each process to see the unique installation file system in the system, not only the root directory, but the unique file system hierarchy
Linux Storage Stacks
[Https://www.thomaskrenn.com/en/wiki/Linux_Storage_Stack_Diagram]
"Linux kernel design and implementation" Note--VFS