Linux general technology-Linux programming and kernel information for the device model of Linux kernel. The following is a detailed description. Source: Linux community
An important feature of the Linux 2.6 kernel is the provision of a unified kernel device model. With the continuous advancement of technology, the topology structure of the system becomes more and more complex, and the requirements for intelligent power management, hot swapping, and support for plug and play are also increasing. The 2.4 kernel is hard to meet these requirements. To meet the needs of this situation, the 2.6 kernel has developed a new device model.
1. Sysfs File System
Sysfs is a special file system similar to the proc file system. It organizes devices in the system into hierarchies and provides detailed kernel data structure information to user mode programs.
Its top-level directories mainly include:
Block Directory: contains all Block devices
Devices Directory: contains all the Devices in the system, and is organized into hierarchies according to the bus type attached to the device.
Bus Directory: contains all Bus types in the system
Drivers directory: includes all registered device Drivers in the kernel
Class Directory: the types of devices in the system (such as NIC devices and sound card devices)
2. Key data structures of the kernel object mechanism
2.1 kobject Kernel Object
Kobject is a new device management mechanism introduced in Linux 2.6. It is represented by struct kobject in the kernel. Through this data structure, all devices have a unified interface at the underlying layer. kobject provides basic object management, which is the core structure of the Linux 2.6 device model. It is closely associated with the sysfs file system, each kobject object registered in the kernel corresponds to a directory in the sysfs file system.
The Kobject structure is defined: