|
From: Nao N. <nao...@hi...> - 2011-02-25 15:31:05
|
This is just a concept code and must be rewritten.
Signed-off-by: Nao Nishijima <nao...@hi...>
---
drivers/scsi/scsi_unnamed.c | 21 ++++++++++++++++++++-
1 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/drivers/scsi/scsi_unnamed.c b/drivers/scsi/scsi_unnamed.c
index 330a52f..6857ca0 100644
--- a/drivers/scsi/scsi_unnamed.c
+++ b/drivers/scsi/scsi_unnamed.c
@@ -10,9 +10,12 @@
#include <linux/kdev_t.h>
#include <linux/sysdev.h>
#include <linux/list.h>
+#include <linux/usb.h>
#include <scsi/scsi_driver.h>
#include <scsi/scsi_device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi.h>
#define MAX_BUFFER_LEN 256
#define DISK_NAME_LEN 32
@@ -37,6 +40,18 @@ struct scsi_unnamed {
#define to_scsi_unnamed(d) \
container_of(d, struct scsi_unnamed, dev)
+static int get_usb_serial(struct scsi_device *sdev, char *byid)
+{
+ struct Scsi_Host *shost = sdev->host;
+ struct usb_interface *intf =
+ to_usb_interface(shost->shost_gendev.parent);
+ struct usb_device *udev = interface_to_usbdev(intf);
+ strncpy(byid, udev->serial, MAX_BUFFER_LEN);
+ if (byid[0] == '\0')
+ return -EFAULT;
+ return 0;
+}
+
static int get_byid(struct scsi_device *sdev, char *byid)
{
char *buf;
@@ -132,8 +147,12 @@ int scsi_unnamed_probe(struct device *dev)
su->dev.class = &su_sysfs_class;
dev_set_name(&su->dev, "su%d", i++);
- if (sdev->type == TYPE_DISK)
+ if (sdev->type == TYPE_DISK) {
ret = get_byid(sdev, su->byid);
+ if (ret < 0)
+ ret = get_usb_serial(sdev, su->byid);
+ }
+
if (ret < 0)
strncpy(su->byid, dev_name(dev), MAX_BUFFER_LEN);
|