Scsi - Index of

Scsi - Index of Scsi - Index of

07.06.2013 Views

月有关,友情,并非总与疯斗打闹有关.这几个函数应该说是给后面做铺垫,红花总要有绿叶配,没有这段代码 的铺垫,到了后面usb 设备恐怕也无法正常工作吧.不过,一个利好消息是,这几个函数我们只会遇见这一次, 它们在整个故事中就这么一次露脸的机会,像我们每个人的青春,只有一次,无法回头.和我们每个人的青春 一样,都是绝版的.所以,让我们享受这段平淡无奇的代码吧. get_device_info, 这个函数定义于drivers/usb/storage/usb.c 中: 466 /* Get the unusual_devs entries and the string descriptors */ 467 static void get_device_info(struct us_data *us, int id_index) 468 { 469 struct usb_device *dev = us->pusb_dev; 470 struct usb_interface_descriptor *idesc = 471 &us->pusb_intf->cur_altsetting->desc; 472 struct us_unusual_dev *unusual_dev = &us_unusual_dev_list[id_index]; 473 struct usb_device_id *id = &storage_usb_ids[id_index]; 474 475 /* Store the entries */ 476 us->unusual_dev = unusual_dev; 477 us->subclass = (unusual_dev->useProtocol == US_SC_DEVICE) ? 478 idesc->bInterfaceSubClass : 479 unusual_dev->useProtocol; 480 us->protocol = (unusual_dev->useTransport == US_PR_DEVICE) ? 481 idesc->bInterfaceProtocol : 482 unusual_dev->useTransport; 483 us->flags = unusual_dev->flags; 484 485 /* Log a message if a non-generic unusual_dev entry contains an 486 * unnecessary subclass or protocol override. This may stimulate 487 * reports from users that will help us remove unneeded entries 488 * from the unusual_devs.h table. 489 */ 490 if (id->idVendor || id->idProduct) { 491 static char *msgs[3] = { 492 "an unneeded SubClass entry", 493 "an unneeded Protocol entry", 494 "unneeded SubClass and Protocol entries"}; 38 495 struct usb_device_descriptor *ddesc = &dev->descriptor; 496 int msg = -1; 497 498 if (unusual_dev->useProtocol != US_SC_DEVICE && 499 us->subclass == idesc->bInterfaceSubClass) 500 msg += 1; 501 if (unusual_dev->useTransport != US_PR_DEVICE && 502 us->protocol == idesc->bInterfaceProtocol) 503 msg += 2;

504 if (msg >= 0 && !(unusual_dev->flags & US_FL_NEED_OVERRIDE)) 505 printk(KERN_NOTICE USB_STORAGE "This device " 506 "(%04x,%04x,%04x S %02x P %02x)" 507 " has %s in unusual_devs.h\n" 508 " Please send a copy of this message to " 509 "\n", 510 ddesc->idVendor, ddesc->idProduct, 511 ddesc->bcdDevice, 512 idesc->bInterfaceSubClass, 513 idesc->bInterfaceProtocol, 514 msgs[msg]); 515 } 516 517 /* Read the device's string descriptors */ 518 if (dev->descriptor.iManufacturer) 519 usb_string(dev, dev->descriptor.iManufacturer, 520 us->vendor, sizeof(us->vendor)); 521 if (dev->descriptor.iProduct) 522 usb_string(dev, dev->descriptor.iProduct, 523 us->product, sizeof(us->product)); 524 if (dev->descriptor.iSerialNumber) 525 usb_string(dev, dev->descriptor.iSerialNumber, 526 us->serial, sizeof(us->serial)); 527 528 /* Use the unusual_dev strings if the device didn't provide them */ 529 if (strlen(us->vendor) == 0) { 530 if (unusual_dev->vendorName) 531 strlcpy(us->vendor, unusual_dev->vendorName, 532 sizeof(us->vendor)); 533 else 534 strcpy(us->vendor, "Unknown"); 535 } 536 if (strlen(us->product) == 0) { 537 if (unusual_dev->productName) 538 strlcpy(us->product, unusual_dev->productName, 39 539 sizeof(us->product)); 540 else 541 strcpy(us->product, "Unknown"); 542 } 543 if (strlen(us->serial) == 0) 544 strcpy(us->serial, "None"); 545 546 US_DEBUGP("Vendor: %s, Product: %s\n", us->vendor, us->product);

504 if (msg >= 0 && !(unusual_dev->flags & US_FL_NEED_OVERRIDE))<br />

505 printk(KERN_NOTICE USB_STORAGE "This device "<br />

506 "(%04x,%04x,%04x S %02x P %02x)"<br />

507 " has %s in unusual_devs.h\n"<br />

508 " Please send a copy <strong>of</strong> this message to "<br />

509 "\n",<br />

510 ddesc->idVendor, ddesc->idProduct,<br />

511 ddesc->bcdDevice,<br />

512 idesc->bInterfaceSubClass,<br />

513 idesc->bInterfaceProtocol,<br />

514 msgs[msg]);<br />

515 }<br />

516<br />

517 /* Read the device's string descriptors */<br />

518 if (dev->descriptor.iManufacturer)<br />

519 usb_string(dev, dev->descriptor.iManufacturer,<br />

520 us->vendor, size<strong>of</strong>(us->vendor));<br />

521 if (dev->descriptor.iProduct)<br />

522 usb_string(dev, dev->descriptor.iProduct,<br />

523 us->product, size<strong>of</strong>(us->product));<br />

524 if (dev->descriptor.iSerialNumber)<br />

525 usb_string(dev, dev->descriptor.iSerialNumber,<br />

526 us->serial, size<strong>of</strong>(us->serial));<br />

527<br />

528 /* Use the unusual_dev strings if the device didn't provide them */<br />

529 if (strlen(us->vendor) == 0) {<br />

530 if (unusual_dev->vendorName)<br />

531 strlcpy(us->vendor, unusual_dev->vendorName,<br />

532 size<strong>of</strong>(us->vendor));<br />

533 else<br />

534 strcpy(us->vendor, "Unknown");<br />

535 }<br />

536 if (strlen(us->product) == 0) {<br />

537 if (unusual_dev->productName)<br />

538 strlcpy(us->product, unusual_dev->productName,<br />

39<br />

539 size<strong>of</strong>(us->product));<br />

540 else<br />

541 strcpy(us->product, "Unknown");<br />

542 }<br />

543 if (strlen(us->serial) == 0)<br />

544 strcpy(us->serial, "None");<br />

545<br />

546 US_DEBUGP("Vendor: %s, Product: %s\n", us->vendor, us->product);

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

Saved successfully!

Ooh no, something went wrong!