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

A brief discussion on the use and analysis of nofollow tags

Controversy over nofollow There was a dispute bet...

How to install and configure GitLab on Ubuntu 20.04

introduce GitLab CE or Community Edition is an op...

A brief talk about cloning JavaScript

Table of contents 1. Shallow cloning 2. Deep clon...

40 web page designs with super large fonts

Today's web designs tend to display very larg...

Steps to create a CentOS container through Docker

Table of contents Preface Create a bridge network...

Introduction to root directory expansion under Linux system

1. Check Linux disk status df -lh The lsblk comma...

3 methods to restore table structure from frm file in mysql [recommended]

When mysql is running normally, it is not difficu...

MySQL Daemon failed to start error solution

MySQL Daemon failed to start error solution A few...

How to quickly build your own server detailed tutorial (Java environment)

1. Purchase of Server 1. I chose Alibaba Cloud...

mysql installer web community 5.7.21.0.msi installation graphic tutorial

This article example shares the specific code for...

How to change the website accessed by http to https in nginx

Table of contents 1. Background 2. Prerequisites ...

The docker-maven-plugin plugin cannot pull the corresponding jar package

When using the docker-maven-plugin plug-in, Maven...

Token verification login in Vue project (front-end part)

This article example shares the specific code of ...

Javascript to achieve the drag effect of the login box

This article shares the specific code of Javascri...

Detailed explanation of MySql data type tutorial examples

Table of contents 1. Brief Overview 2. Detailed e...