Patchwork [v4,10/32] usb storage: serial number support

login
register
mail settings
Submitter Gerd Hoffmann
Date Jan. 12, 2011, 11:19 a.m.
Message ID <1294831214-4499-11-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/78575/
State New
Headers show

Comments

Gerd Hoffmann - Jan. 12, 2011, 11:19 a.m.
If a serial number is present for the drive fill it into the usb
serialnumber string descriptor.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-msd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 20ab886..9aa8888 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -482,6 +482,7 @@  static int usb_msd_initfn(USBDevice *dev)
 {
     MSDState *s = DO_UPCAST(MSDState, dev, dev);
     BlockDriverState *bs = s->conf.bs;
+    DriveInfo *dinfo;
 
     if (!bs) {
         error_report("usb-msd: drive property not set");
@@ -500,6 +501,11 @@  static int usb_msd_initfn(USBDevice *dev)
     bdrv_detach(bs, &s->dev.qdev);
     s->conf.bs = NULL;
 
+    dinfo = drive_get_by_blockdev(bs);
+    if (dinfo && dinfo->serial) {
+        usb_desc_set_string(dev, STR_SERIALNUMBER, dinfo->serial);
+    }
+
     s->dev.speed = USB_SPEED_FULL;
     scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, usb_msd_command_complete);
     s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0);