After get_device_info is completed, we continue to go down the storage_probe step by step. Continue, This is the three functions we mentioned earlier, get_transport, get_protocol, and get_pipes. Once these three functions are completed, we will enter the climax of this story. Before that, we can only look at it one by one. Fortunately, although these functions are not short, there is only a little useful information, so you can read them quickly.
993/* Get the transport, protocol, and pipe settings */
994 result = get_transport (US );
995 if (result)
996 goto baddevice;
997 result = get_protocol (US );
998 if (result)
999 goto baddevice;
1000 result = get_pipes (US );
1001 if (result)
1002 goto baddevice;
1st, get_transport (us ).
557 static int get_transport (struct us_data * US)
558 {
559 switch (US-> protocol ){
560 caseus_pr_cb:
561 US-> transport_name = "control/bulk ";
562 US-> transport = usb_stor_cb_transport;
563 US-> transport_reset = usb_stor_cb_reset;
564 US-> max_lun = 7;
565 break;
566
567 case us_pr_cbi:
568 US-> transport_name = "control/bulk/interrupt ";
569 US-> transport = usb_stor_cbi_transport;
570 US-> transport_reset = usb_stor_cb_reset;
571 US-> max_lun = 7;
572 break;
573
574 case us_pr_bulk:
575 US-> transport_name = "Bulk ";
576 US-> transport = usb_stor_bulk_transport;
577 US-> transport_reset = usb_stor_bulk_reset;
578 break;
579
580 # ifdef config_usb_storage_usbat
581 caseus_pr_usbat:
582 US-> transport_name = "shuttle Usbat ";
583 US-> transport = usbat_transport;
584 US-> transport_reset = usb_stor_cb_reset;
585 US-> max_lun = 1;
586 break;
587 # endif
588
589 # ifdef config_usb_storage_sddr09
590 caseus_pr_eusb_sddr09:
591 US-> transport_name = "eusb/sddr09 ";
592 US-> transport = sddr09_transport;
593 US-> transport_reset = usb_stor_cb_reset;
594 US-> max_lun = 0;
595 break;
596 # endif
597
598 # ifdef config_usb_storage_sddr55
599 case us_pr_sddr55:
600 US-> transport_name = "sddr55 ";
601 US-> transport = sddr55_transport;
602 US-> transport_reset = sddr55_reset;
603 US-> max_lun = 0;
604 break;
605 # endif
606
607 # ifdef config_usb_storage_dpcm
608 caseus_pr_dpcm_usb:
609 US-> transport_name = "control/bulk-eusb/sddr09 ";
610 US-> transport = dpcm_transport;
611 US-> transport_reset = usb_stor_cb_reset;
612 US-> max_lun = 1;
613 break;
614 # endif
615
616 # ifdef config_usb_storage_freecom
617 case us_pr_freecom:
618 US-> transport_name = "freecom ";
619 US-> transport = freecom_transport;
620 US-> transport_reset = usb_stor_freecom_reset;
621 US-> max_lun = 0;
622 break;
623 # endif
624
625 # ifdef config_usb_storage_datafab
626 case us_pr_datafab:
627 US-> transport_name = "datafab bulk-only ";
628 US-> transport = datafab_transport;
629 US-> transport_reset = usb_stor_bulk_reset;
630 US-> max_lun = 1;
631 break;
632 # endif
633
634 # ifdef config_usb_storage_jumpshot
635 case us_pr_jumpshot:
636 US-> transport_name = "lexar jumpshot control/bulk ";
637 US-> transport = jumpshot_transport;
638 US-> transport_reset = usb_stor_bulk_reset;
639 US-> max_lun = 1;
640 break;
641 # endif
642
643 # ifdef config_usb_storage_alauda
644 case us_pr_alauda:
645 US-> transport_name = "Alauda control/bulk ";
646 US-> transport = alauda_transport;
647 US-> transport_reset = usb_stor_bulk_reset;
648 US-> max_lun = 1;
649 break;
650 # endif
651
652 # ifdef config_usb_storage_karma
653 caseus_pr_karma:
654 US-> transport_name = "Rio karma/bulk ";
655 US-> transport = rio_karma_transport;
656 US-> transport_reset = usb_stor_bulk_reset;
657 break;
658 # endif
659
Default 660:
661 return-EIO;
662}
663 us_debugp ("Transport: % s \ n", US-> transport_name );
664
665/* fix for single-lun devices */
666 if (US-> flags & us_fl_single_lun)
667 US-> max_lun = 0;
668 return 0;
669}
At first glance, this is a long period of time, but the discerning person knows it at first glance. It is mainly a switch. The syntax for selecting a statement is very simple, so it is not difficult for us to understand this code. However, what I want to say is that although it is not difficult to make a choice here, different choices mean that later the story will have a different ending. When the birds choose to fasten gold on the wings, it means that it gives up its wings and fly high; choosing cloud-sky fight means giving up the burden of being out of the body.
So here, we need to carefully check the path we have chosen. Obviously, we have already said that for a USB flash drive, spec specifies that it belongs to the bulk-only transmission mode, that is, its US-> protocol is us_pr_bulk. This is just determined in get_device_info. Therefore, in the entire switch section, we only execute the us_pr_bulk section, that is, the transport_name of us is assigned as "Bulk", the transport is assigned as usb_stor_bulk_transport, And the transport_reset is assigned as usb_stor_bulk. Among them, we need to remember that the US member transport and transport_reset are two function pointers. Programmers call this a "Hook ". We need to remember these two values. We will definitely use them in the future, because they are exactly what we call during data transmission. The two functions of usb_stor_bulk _ * will be called later. Now we only need to know that we will definitely look back at this assignment in the future.
Lines 580 to 658 are unnecessary. Here are some compilation switches related to a variety of specific products. They have some defined transmission functions, while others share common functions.
Row 3: judge us-> flags. Remember the flags we mentioned when talking about the unusual_devs.h file. It was used for the first time. Some devices have set the flag us_fl_single_lun, indicating that it only has one Lun. There are a lot of devices like this, just grab one from unusual_devs.h:
596 unusual_dev (0x054c, 0x002d, 0x0100, 0x0100,
597 "Sony ",
598 "memorystick MSAC-US1 ",
599 us_ SC _device, us_pr_device, null,
600 us_fl_single_lun ),
For example, memorystick of Sony. The Chinese name is "memory stick", which is the same size as chewing gum and is also a storage chip. It is launched by Sony and is widely used in Sony's various digital products, such as digital cameras and digital cameras.
Lun is the logical unit number. Lun is usually used when talking about SCSI devices. A Lun engineer from Novell who was involved in developing the USB subsystem in the Linux Kernel told me that a Lun is a driver in the device. The following is an example of the purpose of introducing Lun in USB. Some card readers can have multiple slots, such as two, one supporting the CF card and the other supporting the SD card. In this case, distinguish the devices in these two slots, you have to introduce the Lun concept, that is, the logical unit. Obviously, the Lun of a simple device such as a USB flash disk must be one. Sometimes, a partition in a USB flash drive is often treated as a Lun, but it should not be understood as this.
After knowing the Lun, you will naturally know what us_fl_single_lun is. This flag is of obvious significance and tells you straight away that this device has only one Lun and does not support multiple Luns. What does max_lun mean? The max_lun member in us is equal to the maximum Lun number supported by a device. That is, if a device supports four Luns, the numbers of these four Luns are 0, 1, 2, and 3, while that of max_lun is 3. If a device does not support multiple Luns, its max_lun is 0. So here max_lun is set to 0.
Note that the us_pr_bulk statements are different from those of other cases, and the US-> max_lun is set in other cases, in the case corresponding to the bulk-only protocol, it does not set us-> max_lun. The reason is that the value is determined by the device and must be queried by the device, this is what the bulk-only protocol stipulates. A usb_stor_bulk_max_lun () function is defined in drivers/USB/storage/transport. C and will be responsible for obtaining this Max Lun. I still want to declare it once. This function has no significance for our USB flash drive. The value must be 0, so we will ignore this function.
So far, get_transport () is over, just like get_device_info. All the functions we have seen have to face the reality. For them, fading is the final result, and blooming is just a process. For us, to reach the end, we will not be spared when we encounter these functions. However, no matter how important this part of code is, it's just that we have to leave for another flight no matter how long we 've been on a long journey.