I am USB in Linux. I am a USB flash drive (18). Will it be far away in spring? (4)

Source: Internet
Author: User

 

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.

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.