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

Some tips for using less in Vue projects

Table of contents Preface 1. Style penetration 1....

43 Web Design Mistakes Web Designers Should Watch Out For

This is an article about website usability. The a...

Unicode signature BOM (Byte Order Mark) issue for UTF-8 files

I recently encountered a strange thing when debug...

Detailed explanation of scp and sftp commands under Linux

Table of contents Preface 1. scp usage 2. Use sft...

Teach you how to build the vue3.0 project architecture step by step

Table of contents Preface: 1. Create a project wi...

Vue encapsulation component tool $attrs, $listeners usage

Table of contents Preface $attrs example: $listen...

How to clean up Alibaba Cloud MySQL space

Today I received a disk warning notification from...

CocosCreator learning modular script

Cocos Creator modular script Cocos Creator allows...

Detailed explanation of Vue's SSR server-side rendering example

Why use Server-Side Rendering (SSR) Better SEO, s...

How to use Docker to limit container resources

Problem Peeping In the server, assuming that the ...

Some CSS questions you may be asked during an interview

This article is just to commemorate those CSS que...

Learn more about the most commonly used JavaScript events

Table of contents JavaScript events: Commonly use...

Usage and description of HTML tag tbody

The tbody element should be used in conjunction wi...

MySQL database JDBC programming (Java connects to MySQL)

Table of contents 1. Basic conditions for databas...