You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
25<br />
938 if (!us) {<br />
939 printk(KERN_WARNING USB_STORAGE "Out <strong>of</strong> memory\n");<br />
940 return -ENOMEM;<br />
941 }<br />
942 memset(us, 0, size<strong>of</strong>(struct us_data));<br />
首先先贴出这么几行,两个参数不用多说了,struct usb_interface 和struct usb_device_id 的<br />
这两个指针都是前面介绍过的,来自usb core 那一层,我们整个故事里用到的就是这么一个,不是<br />
说一会指向你,一会指向他,这两个指针的指向是定下来的.<br />
930 行,最重要的一个数据结构终于在这种神不知鬼不觉的地方惊艳亮相了.整个usb-storage<br />
模块里边自己定义的数据结构不多,但是us_data 算一个.这个数据结构是跟随我们的代码一直<br />
走下去的,如影随形,几乎处处都可以看见她的身影.先把它的代码贴出来,来自<br />
drivers/usb/storage/usb.h:<br />
105 /* we allocate one <strong>of</strong> these for every device that we remember */<br />
106 struct us_data {<br />
107 /* The device we're working with<br />
108 * It's important to note:<br />
109 * (o) you must hold dev_semaphore to change pusb_dev<br />
110 */<br />
111 struct semaphore dev_semaphore; /* protect pusb_dev */<br />
112 struct usb_device *pusb_dev; /* this usb_device */<br />
113 struct usb_interface *pusb_intf; /* this interface */<br />
114 struct us_unusual_dev *unusual_dev; /* device-filter entry */<br />
115 unsigned long flags; /* from filter initially */<br />
116 unsigned int send_bulk_pipe; /* cached pipe values */<br />
117 unsigned int recv_bulk_pipe;<br />
118 unsigned int send_ctrl_pipe;<br />
119 unsigned int recv_ctrl_pipe;<br />
120 unsigned int recv_intr_pipe;<br />
121<br />
122 /* information about the device */<br />
123 char vendor[USB_STOR_STRING_LEN];<br />
124 char product[USB_STOR_STRING_LEN];<br />
125 char serial[USB_STOR_STRING_LEN];<br />
126 char *transport_name;<br />
127 char *protocol_name;<br />
128 u8 subclass;<br />
129 u8 protocol;<br />
130 u8 max_lun;<br />
131<br />
132 u8 ifnum; /* interface number */<br />
133 u8 ep_bInterval; /* interrupt interval */<br />
134<br />
135 /* function pointers for this device */