You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
944 init_MUTEX_LOCKED(&(us->sema));<br />
945 init_completion(&(us->notify));<br />
946 init_waitqueue_head(&us->dev_reset_wait);<br />
947 init_waitqueue_head(&us->scsi_scan_wait);<br />
948 init_completion(&us->scsi_scan_done);<br />
949<br />
950 /* Associate the us_data structure with the USB device */<br />
951 result = associate_dev(us, intf);<br />
952 if (result)<br />
953 goto BadDevice;<br />
954<br />
955 /*<br />
956 * Get the unusual_devs entries and the descriptors<br />
957 *<br />
958 * id_index is calculated in the declaration to be the index number<br />
959 * <strong>of</strong> the match from the usb_device_id table, so we can find the<br />
960 * corresponding entry in the private table.<br />
961 */<br />
962 get_device_info(us, id_index);<br />
storage_probe 这个函数之所以短小,是因为它调用了大量的函数.所以,看起来短短一段代码,实际上却<br />
要<br />
花费我们读代码的人好几个小时,想想真是觉得不划算,难怪朱自清先生看到这个storage_probe 函数的<br />
时候,不禁感慨,燕子去了,有再来的时候,杨柳枯了,有再青的时候,桃花谢了,有再开的时候,但是,聪明的你<br />
告诉我,我们读这段不足100 行的函数花掉的时间为何一去不复返呢?<br />
其实我们不知道id_index 也不影响对后面问题的理解,甚至某种意义上来说,花太多笔墨去讲这个<br />
id_index 有一点喧宾夺主的感觉,但是,有时候,有些事情,你明知它是无奈的事,无奈的心情,却还要无奈的<br />
面对,无奈的去选择,有时想无奈的逃避都不可能,因为我们都被无奈禁锢了.比如这里,注意到962 行出现了<br />
一个get_device_info 的函数,它的一个参数就是id_index,所以,我们别无选择,只能看看这个id_index<br />
究竟是干嘛的.<br />
上节我们注意到id_index=id-storage_usb_ids,id 我们知道,storage_probe 函数的两个形参之一,而<br />
storage_usb_ids,不是别人,正是我们曾经赋给usb_storage_driver 的成员id_table 的值.忘记了<br />
id_table 的可以回去看.它实际上就是一张表格,告诉全世界我这个driver 支持怎样的一些设<br />
备.storage_usb_ids 同样来自drivers/usb/storage/usb.c 中,<br />
111 /* The entries in this table, except for final ones here<br />
112 * (USB_MASS_STORAGE_CLASS and the empty entry), correspond,<br />
113 * line for line with the entries <strong>of</strong> us_unsuaul_dev_list[].<br />
114 */<br />
115<br />
116 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \<br />
117 vendorName, productName,useProtocol, useTransport, \<br />
118 initFunction, flags) \<br />
29<br />
119 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax) }<br />
120