1th Linux driver ___ to driver module on account (ii)

Source: Internet
Author: User

From this blog post, we can finally give our driver module First_drv a formal compilation, now he has filled out his account registration information form, from the account of the child only one step!


Inside the kernel has its own set of methods to install the driver module, like the Civil Affairs Bureau staff know how to run an account for a person, for an ordinary citizen, the staff did what the operation of the hukou, not ordinary citizens need to care about, We are most concerned about how to put our completed account information registration form to the staff, how to show the staff that we have the account request.


In the Linux system, for the character device driver, we register the driver module to the kernel by Register_chrdev this function, we want to execute Insmod First_drv.ko, which is called first_drv_ init function is the time to complete the registration of the driver module, after all, this is the driver initialization function, in this function "to complete the task of registering the driver module to the kernel" is not its responsibility.


Let's take a look at how the previous first_drv_init was written:


static int __init first_drv_init (void) {PRINTK (kern_info "Hello world!\n"); return 0;}


We know that we will add a register_chrdev function inside, but we do not understand the use of this function, in the source insight of the linux-2.6.22.6 kernel source engineering Search, see how others use it, such as I searched for example:


int ret;

···

ret = Register_chrdev (Vfc_major, Vfcstr, &vfc_fops);

if (ret) {

PRINTK (kern_err "Unable to get major number%d\n", vfc_major);

Kfree (VFC_DEV_LST);

Return-eio;

}

···

return 0;


We focus on the color line,vfc_major is a macro definition,


We add the Register_chrdev function inside, and change the following:


static int __init first_drv_init (void) {int ret =-1;    Register_chrdev () printk (kern_info "Hello world!\n"); return 0;}


This article is from the "12253782" blog, please be sure to keep this source http://12263782.blog.51cto.com/12253782/1873993

1th Linux driver ___ to driver module on account (ii)

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.