07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

432 US_DEBUGP("-- %s\n", __FUNCTION__);<br />

433<br />

434 /* Fill in the device-related fields */<br />

435 us->pusb_dev = interface_to_usbdev(intf);<br />

436 us->pusb_intf = intf;<br />

437 us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;<br />

438 US_DEBUGP("Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n",<br />

439 us->pusb_dev->descriptor.idVendor,<br />

440 us->pusb_dev->descriptor.idProduct,<br />

441 us->pusb_dev->descriptor.bcdDevice);<br />

442 US_DEBUGP("Interface Subclass: 0x%02x, Protocol: 0x%02x\n",<br />

443 intf->cur_altsetting->desc.bInterfaceSubClass,<br />

444 intf->cur_altsetting->desc.bInterfaceProtocol);<br />

445<br />

446 /* Store our private data in the interface */<br />

447 usb_set_intfdata(intf, us);<br />

448<br />

449 /* Allocate the device-related DMA-mapped buffers */<br />

450 us->cr = usb_buffer_alloc(us->pusb_dev, size<strong>of</strong>(*us->cr),<br />

451 GFP_KERNEL, &us->cr_dma);<br />

452 if (!us->cr) {<br />

453 US_DEBUGP("usb_ctrlrequest allocation failed\n");<br />

454 return -ENOMEM;<br />

455 }<br />

456<br />

457 us->iobuf = usb_buffer_alloc(us->pusb_dev, US_IOBUF_SIZE,<br />

458 GFP_KERNEL, &us->iobuf_dma);<br />

459 if (!us->iobuf) {<br />

460 US_DEBUGP("I/O buffer allocation failed\n");<br />

461 return -ENOMEM;<br />

462 }<br />

463 return 0;<br />

464 }<br />

我们首先来关注函数associate_dev 的参数, struct us_data *us,传递给它的是us,这个不用多说了<br />

吧,此前刚刚为它申请了内存,并且初始化各成员为0. 这个us将一直陪伴我们走下去,直到我们的故事结束.<br />

所以其重要性不言而喻. struct usb_interface *intf,这个也不用说,storage_probe()函数传进来的两个<br />

参数之一.总之,此处郑重申明一次,struct us_data 的结构体指针us,struct usb_interface 结构体的指<br />

针intf,以及struct usb_device 结构体和struct usb_device_id 结构体在整个U 盘驱动的故事中是唯<br />

一的,每次提到都是那个. 而以后我们会遇上的几个重要的数据结构,struct urb urb,struct scsi_cmnd<br />

34<br />

srb 这也非常重要,但是它们并不唯一,也许每次遇上都不一样,就像演戏一样.前边这几个数据结构的变量<br />

就像那些主角,而之后遇见的urb 啊,srb 啊,虽然频繁露面,但是只是群众演员,只不过这次是路人甲,下次<br />

是<br />

路人乙. 所以,以后我们将只说us,不再说struct us_data *us,struct usb_interface * intf 也将只用

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!