I am USB in Linux, I am a USB flash drive (4) I want to leave tomorrow.

Source: Internet
Author: User
Now that you know how to write the module, writing the device driver is naturally not difficult. I believe that no one who writes a module will find it difficult to write a device driver. Really, I'm not telling you the truth. writing a driver is not difficult. you can say with confidence that you can already write a device drive... Info & nbsp

Now that you know how to write the module, writing the device driver is naturally not difficult. I believe that no one who writes a module will find it difficult to write a device driver.
Really, it's not difficult for me to write a driver. you can say with confidence that you can write a device driver. Yes, that's right. "Rejoice, so confident ."
As mentioned above, every module starts with module_init and ends with module_exit. let's take a look at the U Drive module. In the vast sea of people, we can easily find this file drivers/usb/storage/usb. c. It is not difficult to find the following section in this file:
1068 static int _ init usb_stor_init (void)

1069 {

1070 int retval;

1071 printk (KERN_INFO "Initializing USB Mass Storage driver.../n ");

1072

1073/* register the driver, return usb_register return code if err or */

1074 retval = usb_register (& usb_storage_driver );

1075 if (retval = 0 ){

1076 printk (KERN_INFO "USB Mass Storage support registered./n ");

1077 USB _usual_set_present (USB_US_TYPE_STOR );

1078}

1079 return retval;

1080}

1081

1082 static void _ exit usb_stor_exit (void)

1083 {

1084 US_DEBUGP ("usb_stor_exit () called/n ");

1085

1086/* Deregister the driver

1087 * This will cause disconnect () to be called for each

1088 * attached unit

1089 */

1090 US_DEBUGP ("-- calling usb_deregister ()/n ");

1091 usb_deregister (& usb_storage_driver );

1092

1093/* Don't return until all of our control and scanning threads

1094 * have exited. Since each thread signals threads_gone as its

1095 * last act, we have to call wait_for_completion the right number

1096 * of times.

1097 */

1098 while (atomic_read (& total_threads)> 0 ){

1099 wait_for_completion (& threads_gone );

1100 atomic_dec (& total_threads );

1101}

1102

1103 USB _usual_clear_present (USB_US_TYPE_STOR );

1104}

1105

1106 module_init (usb_stor_init );

1107 module_exit (usb_stor_exit );

In fact, module_init/module_exit is just a macro. generally, to show your own personality, the module writer will name their own initialization function and deregister function. for example, module_init (usb_stor_init) and module_exit (usb_stor_exit) is actually telling the world that the real functions are usb_stor_init and usb_stor_exit. This kind of trick is not uncommon in Linux kernel code, so you don't have to worry about it when you get too much. if it rains, you need to marry and let her go. Next we will start our exploration journey from usb_stor_init.

 

*****************************

From Linux, I am USB.

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.