Linux kernel device driver virtual file system notes

Linux kernel device driver virtual file system notes
/********************
 * Virtual File System VFS
 ********************/

(1) Introduction to VFS

As a subsystem of the kernel, the virtual file system VFS provides file system related interfaces for user space programs.

VFS allows users to directly use system calls such as open() without having to consider the specific file system and actual physical media.

VFS provides a common file system model that encompasses the common functions and behaviors of file systems that we can think of. Through this abstraction layer, it is possible to use a common interface to operate all types of new file systems.

a. Calling model

write(): user space -->

sys_write(): VFS -->

How to write to the file system: File system -->

Physical Media

(2) Main objects adopted by VFS

VFS adopts an object-oriented approach and uses a set of data structures to represent common file objects.

These structures contain not only data but also pointers to operate on these data.

There are four main object types included in VFS.

a.Super block object super_block

All file systems must implement a superblock, which is an object used to store information about a specific file system. It is usually stored in a specific sector of the disk. There is only one superblock per file system.

For non-disk-based file systems, such as the memory-based file system sysfs, Linux creates a superblock on-site and saves it in memory.

The structure of the super block is super_block, which is defined in <linux/fs.h>.

The super block operation method structure is super_operations, which is also defined in fs.h.

The code for creating, managing, and destroying superblock 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 fill its information into the super block object in memory.

b. Index node object inode

The index node object contains all the information the kernel needs to operate a file or directory, such as the file's access control permissions, size, owner, creation time, etc.

The system stores this information in a separate data structure called an inode.

A file has only one index node object in memory, and special files (such as pipes and device files) also have their corresponding index nodes.

The inode structure is defined in <linux/fs.h>, and its corresponding operation function structure is inode_operations

c. Directory entry object dentry

Each directory entry object represents a specific part of a path, such as the path /bin/vi, where /, bin, and vi all belong to directory entry objects.

Directory entry objects do not have a corresponding disk structure, and VFS creates them on-site based on the path name in string form. Each file corresponds to only one dentry object.

The dentry structure is defined in <linux/dcache.h>, and the corresponding directory entry operation function structure dentry_operations is also defined in <linux/dcache.h>.

d. File object file

A file object represents a file that a process has opened. This object is created when it is opened and destroyed when it is closed.

Because multiple processes can open and operate a file at the same time, a file may have multiple file objects in memory.

File objects are represented by the file structure, which is defined in <linux/fs.h>. The operation function structure of the file object is file_operations, which is defined in <linux/fs.h>.

This function set is very important, which includes the actual operation functions of the file. The user space calls write, which will eventually call write in file_operations.

We need to implement a character device of type char, that is, to implement the functions supported in file_operations.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Linux kernel device driver memory management notes
  • Linux kernel device driver kernel time management notes
  • Linux kernel device driver character device driver notes
  • Linux kernel device driver kernel debugging technical notes collation
  • Linux kernel device driver kernel linked list usage notes
  • Linux kernel device driver proc file system notes
  • Detailed explanation of Linux camera driver writing
  • Analysis of parameter transfer process of driver module in Linux

<<:  A brief discussion on several ways to pass parameters in react routing

>>:  Detailed tutorial for installing mysql5.7.18 on centos7.3

Recommend

XHTML Getting Started Tutorial: XHTML Hyperlinks

It is no exaggeration to say that hyperlinks conne...

CSS container background 10 color gradient Demo (linear-gradient())

grammar background: linear-gradient(direction,col...

Implementation of adding remark information to mysql

Preface Some people have asked me some MySQL note...

VUE+Canvas realizes the whole process of a simple Gobang game

Preface In terms of layout, Gobang is much simple...

HTML+VUE paging to achieve cool IoT large screen function

Effect demo.html <html> <head> <me...

js to realize a simple advertising window

This article shares the specific code of js to im...

Instructions for using the database connection pool Druid

Replace it with the optimal database connection p...

HTML table markup tutorial (28): cell border color attribute BORDERCOLOR

To beautify the table, you can set different bord...

Interpretation of 17 advertising effectiveness measures

1. 85% of ads go unread <br />Interpretatio...

Use a diagram to explain what Web2.0 is

Nowadays we often talk about Web2.0, so what is W...

Introduction to using data URI scheme to embed images in web pages

The data URI scheme allows us to include data in a...