summaryrefslogtreecommitdiff
path: root/extras/scsi_id
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2006-10-10 16:56:09 +0200
committerKay Sievers <kay.sievers@suse.de>2006-10-10 16:56:09 +0200
commit11678eff6a40b05d192be65146a66d5e1e8252ec (patch)
treeea4a9aa8228fb3001c9c4de2948e546278609837 /extras/scsi_id
parent5ac285437500a857f69d8b883d5aac3692662d0f (diff)
scsi_id: export ID_SERIAL_SHORT without vendor/product
Diffstat (limited to 'extras/scsi_id')
-rw-r--r--extras/scsi_id/scsi_id.c17
-rw-r--r--extras/scsi_id/scsi_id.h2
-rw-r--r--extras/scsi_id/scsi_serial.c48
3 files changed, 34 insertions, 33 deletions
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index c64e203aff..7fd6066c01 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -614,11 +614,12 @@ static int scsi_id(const char *devpath, char *maj_min_dev)
{
int retval;
int dev_type = 0;
- char *serial, *unaligned_buf;
struct sysfs_device *dev;
struct sysfs_device *dev_scsi;
int good_dev;
int page_code;
+ char serial[MAX_SERIAL_LEN];
+ char serial_short[MAX_SERIAL_LEN];
dbg("devpath %s\n", devpath);
@@ -650,29 +651,25 @@ static int scsi_id(const char *devpath, char *maj_min_dev)
retval = per_dev_options(dev_scsi, &good_dev, &page_code);
dbg("per dev options: good %d; page code 0x%x", good_dev, page_code);
-#define ALIGN 512
- unaligned_buf = malloc(MAX_SERIAL_LEN + ALIGN);
- serial = (char*) (((unsigned long) unaligned_buf + (ALIGN - 1))
- & ~(ALIGN - 1));
- dbg("buffer unaligned 0x%p; aligned 0x%p\n", unaligned_buf, serial);
-#undef ALIGN
-
if (!good_dev) {
retval = 1;
} else if (scsi_get_serial(dev_scsi, maj_min_dev, page_code,
- serial, MAX_SERIAL_LEN)) {
+ serial, serial_short, MAX_SERIAL_LEN)) {
retval = always_info?0:1;
} else {
retval = 0;
}
if (!retval) {
if (export) {
- static char serial_str[64];
+ char serial_str[MAX_SERIAL_LEN];
+
printf("ID_VENDOR=%s\n", vendor_str);
printf("ID_MODEL=%s\n", model_str);
printf("ID_REVISION=%s\n", revision_str);
set_str(serial_str, serial, sizeof(serial_str));
printf("ID_SERIAL=%s\n", serial_str);
+ set_str(serial_str, serial_short, sizeof(serial_str));
+ printf("ID_SERIAL_SHORT=%s\n", serial_str);
printf("ID_TYPE=%s\n", type_str);
printf("ID_BUS=scsi\n");
} else {
diff --git a/extras/scsi_id/scsi_id.h b/extras/scsi_id/scsi_id.h
index 64ea349064..d7f675fa0b 100644
--- a/extras/scsi_id/scsi_id.h
+++ b/extras/scsi_id/scsi_id.h
@@ -31,7 +31,7 @@
#define MAX_BUFFER_LEN 256
extern int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
- int page_code, char *serial, int len);
+ int page_code, char *serial, char *serial_short, int len);
/*
* Page code values.
diff --git a/extras/scsi_id/scsi_serial.c b/extras/scsi_id/scsi_serial.c
index a0a3ae97d8..513d922559 100644
--- a/extras/scsi_id/scsi_serial.c
+++ b/extras/scsi_id/scsi_serial.c
@@ -433,9 +433,9 @@ static int prepend_vendor_model(struct sysfs_device *dev_scsi, char *serial)
static int check_fill_0x83_id(struct sysfs_device *dev_scsi,
unsigned char *page_83,
const struct scsi_id_search_values
- *id_search, char *serial, int max_len)
+ *id_search, char *serial, char *serial_short, int max_len)
{
- int i, j, len;
+ int i, j, s, len;
/*
* ASSOCIATION must be with the device (value 0)
@@ -469,7 +469,7 @@ static int check_fill_0x83_id(struct sysfs_device *dev_scsi,
*/
len *= 2;
- /*
+ /*
* Add one byte for the NUL termination, and one for the id_type.
*/
len += 2;
@@ -497,7 +497,7 @@ static int check_fill_0x83_id(struct sysfs_device *dev_scsi,
}
i = 4; /* offset to the start of the identifier */
- j = strlen(serial);
+ s = j = strlen(serial);
if ((page_83[0] & 0x0f) == SCSI_ID_ASCII) {
/*
* ASCII descriptor.
@@ -515,6 +515,8 @@ static int check_fill_0x83_id(struct sysfs_device *dev_scsi,
i++;
}
}
+
+ strcpy(serial_short, &serial[s]);
return 0;
}
@@ -522,10 +524,11 @@ static int check_fill_0x83_id(struct sysfs_device *dev_scsi,
static int check_fill_0x83_prespc3(struct sysfs_device *dev_scsi,
unsigned char *page_83,
const struct scsi_id_search_values
- *id_search, char *serial, int max_len)
+ *id_search, char *serial, char *serial_short, int max_len)
{
int i, j;
-
+
+ dbg("using pre-spc3-83 for %s.\n", dev_scsi->kernel);
serial[0] = hex_str[id_search->id_type];
/* serial has been memset to zero before */
j = strlen(serial); /* j = 1; */
@@ -534,14 +537,14 @@ static int check_fill_0x83_prespc3(struct sysfs_device *dev_scsi,
serial[j++] = hex_str[(page_83[4+i] & 0xf0) >> 4];
serial[j++] = hex_str[ page_83[4+i] & 0x0f];
}
- dbg("using pre-spc3-83 for %s.\n", dev_scsi->kernel);
+ strcpy(serial_short, serial);
return 0;
}
/* Get device identification VPD page */
static int do_scsi_page83_inquiry(struct sysfs_device *dev_scsi, int fd,
- char *serial, int len)
+ char *serial, char *serial_short, int len)
{
int retval;
unsigned int id_ind, j;
@@ -588,8 +591,8 @@ static int do_scsi_page83_inquiry(struct sysfs_device *dev_scsi, int fd,
*/
if (page_83[6] != 0)
- return check_fill_0x83_prespc3(dev_scsi, page_83,
- id_search_list, serial, len);
+ return check_fill_0x83_prespc3(dev_scsi, page_83, id_search_list,
+ serial, serial_short, len);
/*
* Search for a match in the prioritized id_search_list.
@@ -604,7 +607,7 @@ static int do_scsi_page83_inquiry(struct sysfs_device *dev_scsi, int fd,
for (j = 4; j <= (unsigned int)page_83[3] + 3; j += page_83[j + 3] + 4) {
retval = check_fill_0x83_id(dev_scsi, &page_83[j],
&id_search_list[id_ind],
- serial, len);
+ serial, serial_short, len);
dbg("%s id desc %d/%d/%d\n", dev_scsi->kernel,
id_search_list[id_ind].id_type,
id_search_list[id_ind].naa_type,
@@ -631,7 +634,7 @@ static int do_scsi_page83_inquiry(struct sysfs_device *dev_scsi, int fd,
* conformant to the SCSI-2 format.
*/
static int do_scsi_page83_prespc3_inquiry(struct sysfs_device *dev_scsi, int fd,
- char *serial, int len)
+ char *serial, char *serial_short, int len)
{
int retval;
int i, j;
@@ -693,7 +696,7 @@ static int do_scsi_page83_prespc3_inquiry(struct sysfs_device *dev_scsi, int fd,
/* Get unit serial number VPD page */
static int do_scsi_page80_inquiry(struct sysfs_device *dev_scsi, int fd,
- char *serial, int max_len)
+ char *serial, char *serial_short, int max_len)
{
int retval;
int ser_ind;
@@ -728,11 +731,12 @@ static int do_scsi_page80_inquiry(struct sysfs_device *dev_scsi, int fd,
len = buf[3];
for (i = 4; i < len + 4; i++, ser_ind++)
serial[ser_ind] = buf[i];
+ memcpy(serial_short, &buf[4], len);
return 0;
}
int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
- int page_code, char *serial, int len)
+ int page_code, char *serial, char *serial_short, int len)
{
unsigned char page0[SCSI_INQ_BUFF_LEN];
int fd;
@@ -749,7 +753,7 @@ int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
}
if (page_code == PAGE_80) {
- if (do_scsi_page80_inquiry(dev_scsi, fd, serial, len)) {
+ if (do_scsi_page80_inquiry(dev_scsi, fd, serial, serial_short, len)) {
retval = 1;
goto completed;
} else {
@@ -757,7 +761,7 @@ int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
goto completed;
}
} else if (page_code == PAGE_83) {
- if (do_scsi_page83_inquiry(dev_scsi, fd, serial, len)) {
+ if (do_scsi_page83_inquiry(dev_scsi, fd, serial, serial_short, len)) {
retval = 1;
goto completed;
} else {
@@ -765,7 +769,7 @@ int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
goto completed;
}
} else if (page_code == PAGE_83_PRE_SPC3) {
- retval = do_scsi_page83_prespc3_inquiry(dev_scsi, fd, serial, len);
+ retval = do_scsi_page83_prespc3_inquiry(dev_scsi, fd, serial, serial_short, len);
if (retval) {
/*
* Fallback to servicing a SPC-2/3 compliant page 83
@@ -773,7 +777,7 @@ int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
* conform to pre-SPC3 expectations.
*/
if (retval == 2) {
- if (do_scsi_page83_inquiry(dev_scsi, fd, serial, len)) {
+ if (do_scsi_page83_inquiry(dev_scsi, fd, serial, serial_short, len)) {
retval = 1;
goto completed;
} else {
@@ -812,8 +816,8 @@ int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
for (ind = 4; ind <= page0[3] + 3; ind++)
if (page0[ind] == PAGE_83)
- if (!do_scsi_page83_inquiry(dev_scsi, fd, serial,
- len)) {
+ if (!do_scsi_page83_inquiry(dev_scsi, fd,
+ serial, serial_short, len)) {
/*
* Success
*/
@@ -823,8 +827,8 @@ int scsi_get_serial (struct sysfs_device *dev_scsi, const char *devname,
for (ind = 4; ind <= page0[3] + 3; ind++)
if (page0[ind] == PAGE_80)
- if (!do_scsi_page80_inquiry(dev_scsi, fd, serial,
- len)) {
+ if (!do_scsi_page80_inquiry(dev_scsi, fd,
+ serial, serial_short, len)) {
/*
* Success
*/