In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the Linux kernel device driver of the virtual file system example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!
/ * * Virtual file system VFS * /
(1) introduction to VFS
Virtual file system VFS, as a subsystem of the kernel, provides a file system-related interface for user space programs.
VFS allows users to directly use system calls such as open (), regardless of the specific file system and actual physical media.
VFS provides a general file system model that includes the common functions and behaviors of the file system that we can think of. Through this abstraction layer, it is possible to use a common interface to operate on new file systems of all classes.
a. Invocation model
Write (): user space-- >
Sys_write (): VFS->
How to write a file system: file system-- >
Physical medium
(2) the main objects adopted by VFS
VFS adopts the idea of object-oriented and uses a set of data structures to represent general file objects.
These structures contain pointers to manipulate the data as well as data.
Four main object types are included in VFS.
a. Super Block object super_block
All file systems must implement a super block, which is used to store information about a specific file system, usually in a specific sector of the disk, and there is only one super block per file system.
For non-disk-based file systems, such as the memory-based file system sysfs,linux, superblocks are created and saved in memory in the usage site.
The structure of the superblock is super_block, which is defined in.
The operation method structure of the superblock is super_operations, which is also defined in fs.h.
The code to create, manage, and destroy super block objects is located in / fs/super.c.
When the file system is installed, the kernel calls the alloc_super () function to read the file system super block from disk and populate its information into the super block object in memory.
b. Inode object inode
The Inode object contains all the information that the kernel needs to manipulate files or directories, such as file access control permissions, size, owner, creation time, and so on.
The system stores this information in a separate data structure, called an index node.
A file has only one Inode object in memory, and special files (such as pipe and device files) also have their corresponding Inode.
The inode structure is defined in, and its corresponding operation function structure is inode_operations
c. Catalog item object dentry
Each directory item object represents a specific part of a path, such as path / bin/vi,/, bin, and vi all belong to the directory item object.
The directory item object does not have a corresponding disk structure, and the VFS is created on the spot based on the pathname in the form of a string. Each file corresponds to only one dentry object.
The dentry structure is defined in, and the corresponding directory item operation function structure dentry_operations is also defined in.
d. File object file
The file object represents a file that has been opened by the process. This object is created at open and destroyed at close.
Because multiple processes can open and manipulate a file at the same time, a file may have multiple file objects in memory.
The file object is represented by the file structure and is defined in. The operation function structure of the file object is file_operations, which is defined in.
This set of functions is very important, including the actual operation functions on the file, calling write in user space, and eventually calling write in file_operations.
We are going to implement a character device of type char, that is, to implement the functions supported in file_operations.
The above is all the contents of the article "sample Analysis of Virtual File system for Linux Kernel device drivers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.