Commit 8d4f1c82 authored by Matthew Dharm's avatar Matthew Dharm Committed by Greg Kroah-Hartman

[PATCH] USB Storage: add sysfs info attribute

This patch adds a sysfs attribute to the usb-storage SCSI devices.  This
attribute (read-only) is basically a clone of the information available in
/proc/scsi/scsi -- since that interface is going away, adding a new sysfs
attribute seemed like a good idea.
parent b8f1529e
...@@ -237,13 +237,14 @@ static int bus_reset( Scsi_Cmnd *srb ) ...@@ -237,13 +237,14 @@ static int bus_reset( Scsi_Cmnd *srb )
#undef SPRINTF #undef SPRINTF
#define SPRINTF(args...) \ #define SPRINTF(args...) \
do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0) do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0)
#define DO_FLAG(a) \
do { if (us->flags & US_FL_##a) pos += sprintf(pos, " " #a); } while(0)
static int proc_info (struct Scsi_Host *hostptr, char *buffer, char **start, off_t offset, static int proc_info (struct Scsi_Host *hostptr, char *buffer, char **start, off_t offset,
int length, int inout) int length, int inout)
{ {
struct us_data *us; struct us_data *us;
char *pos = buffer; char *pos = buffer;
unsigned long f;
/* if someone is sending us data, just throw it away */ /* if someone is sending us data, just throw it away */
if (inout) if (inout)
...@@ -266,14 +267,11 @@ static int proc_info (struct Scsi_Host *hostptr, char *buffer, char **start, off ...@@ -266,14 +267,11 @@ static int proc_info (struct Scsi_Host *hostptr, char *buffer, char **start, off
/* show the device flags */ /* show the device flags */
if (pos < buffer + length) { if (pos < buffer + length) {
pos += sprintf(pos, " Quirks:"); pos += sprintf(pos, " Quirks:");
f = us->flags;
#define DO_FLAG(a) if (f & US_FL_##a) pos += sprintf(pos, " " #a)
DO_FLAG(SINGLE_LUN); DO_FLAG(SINGLE_LUN);
DO_FLAG(SCM_MULT_TARG); DO_FLAG(SCM_MULT_TARG);
DO_FLAG(FIX_INQUIRY); DO_FLAG(FIX_INQUIRY);
DO_FLAG(FIX_CAPACITY); DO_FLAG(FIX_CAPACITY);
#undef DO_FLAG
*(pos++) = '\n'; *(pos++) = '\n';
} }
...@@ -291,6 +289,53 @@ static int proc_info (struct Scsi_Host *hostptr, char *buffer, char **start, off ...@@ -291,6 +289,53 @@ static int proc_info (struct Scsi_Host *hostptr, char *buffer, char **start, off
return (length); return (length);
} }
/***********************************************************************
* Sysfs interface
***********************************************************************/
/* Output routine for the sysfs info file */
static ssize_t show_info(struct device *dev, char *buffer)
{
char *pos = buffer;
const int length = PAGE_SIZE;
struct scsi_device *sdev = to_scsi_device(dev);
struct us_data *us = (struct us_data*)sdev->host->hostdata[0];
/* print the controller name */
SPRINTF(" Host scsi%d: usb-storage\n", sdev->host->host_no);
/* print product, vendor, and serial number strings */
SPRINTF(" Vendor: %s\n", us->vendor);
SPRINTF(" Product: %s\n", us->product);
SPRINTF("Serial Number: %s\n", us->serial);
/* show the protocol and transport */
SPRINTF(" Protocol: %s\n", us->protocol_name);
SPRINTF(" Transport: %s\n", us->transport_name);
/* show the device flags */
if (pos < buffer + length) {
pos += sprintf(pos, " Quirks:");
DO_FLAG(SINGLE_LUN);
DO_FLAG(SCM_MULT_TARG);
DO_FLAG(FIX_INQUIRY);
DO_FLAG(FIX_CAPACITY);
*(pos++) = '\n';
}
return (pos - buffer);
}
static DEVICE_ATTR(info, S_IRUGO, show_info, NULL);
static struct device_attribute *sysfs_device_attr_list[] = {
&dev_attr_info,
NULL,
};
/* /*
* this defines our host template, with which we'll allocate hosts * this defines our host template, with which we'll allocate hosts
*/ */
...@@ -334,6 +379,9 @@ struct scsi_host_template usb_stor_host_template = { ...@@ -334,6 +379,9 @@ struct scsi_host_template usb_stor_host_template = {
/* emulated HBA */ /* emulated HBA */
.emulated = TRUE, .emulated = TRUE,
/* sysfs device attributes */
.sdev_attrs = sysfs_device_attr_list,
/* modify scsi_device bits on probe */ /* modify scsi_device bits on probe */
.flags = (BLIST_MS_SKIP_PAGE_08 | BLIST_MS_SKIP_PAGE_3F | .flags = (BLIST_MS_SKIP_PAGE_08 | BLIST_MS_SKIP_PAGE_3F |
BLIST_USE_10_BYTE_MS), BLIST_USE_10_BYTE_MS),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment