Connection between linux characters cdev and inode

Source: Internet
Author: User
Article Title: connection between linux characters cdev and inode. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

I haven't read much for a long time. Recently I reviewed the driver part of the character device and wrote a note.

Char Device Driver

Related Data Structure:

Struct cdev {

Struct kobject kobj;

Struct module * owner;

Const struct file_operations * ops;

Struct list_head list;

Dev_t dev;

Unsigned int count;

};

Struct kobj_map {

Struct probe {

Struct probe * next;

Dev_t dev;

Unsigned long range;

Struct module * owner;

Kobj_probe_t * get;

Int (* lock) (dev_t, void *);

Void * data;

} * Probes [255];

Struct mutex * lock;

};

Static struct char_device_struct {

Struct char_device_struct * next;

Unsigned int major;

Unsigned int baseminor;

Int minorct;

Char name [64];

Struct file_operations * fops;

Struct cdev * cdev;/* will die */

} * Chrdevs [CHRDEV_MAJOR_HASH_SIZE];

# Define CHRDEV_MAJOR_HASH_SIZE 255

The following article describes the character device driver in three aspects and their association:

1. Character-driven model

2. device Number of the character device

3. Access to character device files in the file system

1. Character-driven model

Each character driver is represented by a cdev structure.

In the device driver model, the kobject mapping domain is used to record the device driver.

This is represented by the struct kobj_map structure. It is embedded with an array of 255 struct probe pointers.

Kobj_map is referenced by the global variable cdev_map: static struct kobj_map * cdev_map;

Function Description:

Cdev_alloc () is used to create a cdev object.

Cdev_add () is used to add the cdev object to the driver model. It is implemented through kobj_map.

Kobj_map () creates a probe object, inserts it into an item in cdev_map, and associates probe-> data with cdev

Struct kobject * kobj_lookup (struct kobj_map * domain, dev_t dev, int * index)

Search for the built-in kobject. (probe-> data-> kobj) of the cdev object in cdev_map Based on the device number, and return the kobject of cdev.

[1] [2] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.