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