"Linux Textbook" Reading notes Chapter 17th module

Source: Internet
Author: User

Equipment and modules:

Device type: Block Device (Blkdev), character device (CDEV), network device;

Module:

Analyze the Hello,world module code. Hello_init is the entry point of the module, registered to the system via Module_init (), called when the kernel is loaded, is a macro call, and the only parameter is the initialization function of the module. Module initialization function Format: int my_init (void), can be marked as static type. The initialization succeeds with a return value of 0 and does not successfully return a non-0 value. The INIT function also registers resources, initializes hardware, allocates data structures, and so on.

The Hello_exit () function is the Exit function of the module, which is registered to the system by the Module_exit () routine, and the kernel calls Hello_exit () when the module is unloaded from memory. Exit functions must conform to the following form: void My_exit (void), Module_license (), and Module_author () are brief descriptions of the modules.

Building the module:

1, placed in the kernel source tree (This is not detailed introduction)

2, placed outside the kernel code:

To create a makefile file in your own source tree directory, you only need one line of instruction: obj-m: = XX.O (if there are multiple source files, use obj-m: = XX.O Xx-objs: = XX-MAIN.O xx-line.o), compile to generate Xx.ko. Also, tell make how to find the kernel source file and the underlying makefile file: make–c/kernel/source/location subdirs= $PWD Modules

Installation module: Make

Loading module: Insmod Xx.ko

Unload module: Rmmod Xx.ko

Module parameters: Module_param (name,type,perm);

Export symbol table: Export_symbol () and EXPORT_SYMBOL_GPL (). The Exported kernel symbol table is considered an exported kernel interface, even called the kernel API.

Device Model:

Kobject (Kernel object) is a struct kobject struct. Kobject is a hierarchy in which objects can be created. Ktype is a Kobject object that is associated to a particular type. The existence of Ktype is to describe the universal characteristics of a family of kobject. Kset is a collection of Kobject objects. Kobject, Kytpe, kset relationship: Kobject is associated with a special Ktype object, and Kobject is grouped into a collection called Kset.

Managing and manipulating Kobject:

Kobject is initialized through the function Kobject_init, and next calls Kobject_create () to create Kobject.

Reference count:

The main function of Kobject is to provide a unified reference counting system.

SYSFS:

The Sysfs file system is an in-memory virtual file system that gives us a view of the hierarchy of Kobject objects.

"Linux Textbook" Reading notes Chapter 17th module

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.