* [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response
@ 2014-04-03 17:07 shirishpargaonkar
2014-04-03 18:50 ` Douglas Gilbert
0 siblings, 1 reply; 3+ messages in thread
From: shirishpargaonkar @ 2014-04-03 17:07 UTC (permalink / raw)
To: dgilbert; +Cc: linux-scsi, hare, Shirish Pargaonkar
From: Shirish Pargaonkar <spargaonkar@suse.com>
sginfo <device> prints out various fields such as Vendor and Product in
INQUIRY response with spaces (0x20) characters.
This can confuse scripts some users have.
A change to sysfs attributes such that it now includes spaces caused
this problem.
Strip out those trailing spaces (if any).
Signed-off-by: Shirish Pargaonkar <spargaonkar@suse.com>
---
Index: src/sginfo.c
===================================================================
--- src.orig/sginfo.c 2014-04-02 22:36:13.779692431 -0500
+++ src/sginfo.c 2014-04-02 22:51:36.028265615 -0500
@@ -155,6 +155,7 @@
#define MAX_BUFFER_SIZE MAX_RESP10_SIZE
#define INQUIRY_RESP_INITIAL_LEN 36
+#define MAX_INQFIELD_LEN 17
#define MAX_HEADS 127
#define HEAD_SORT_TOKEN 0x55
@@ -3139,11 +3140,23 @@
return status;
}
+static void
+inqfieldname(unsigned char *deststr, const unsigned char *srcbuf, int maxlen)
+{
+ int i;
+
+ memset(deststr, '\0', MAX_INQFIELD_LEN);
+ for (i = maxlen - 1; i >= 0 && isspace(srcbuf[i]); --i)
+ ;
+ memcpy(deststr, srcbuf, i + 1);
+}
+
static int
do_inquiry(int * peri_type, int * resp_byte6, int inquiry_verbosity)
{
int status;
unsigned char cmd[6];
+ unsigned char fieldname[MAX_INQFIELD_LEN];
unsigned char *pagestart;
struct scsi_cmnd_io sci;
@@ -3214,14 +3227,18 @@
}
if (x_interface)
printf("\n");
- printf("%s%.8s\n", (!x_interface ? "Vendor: " : ""),
- pagestart + 8);
-
- printf("%s%.16s\n", (!x_interface ? "Product: " : ""),
- pagestart + 16);
- printf("%s%.4s\n", (!x_interface ? "Revision level: " : ""),
- pagestart + 32);
+ inqfieldname(fieldname, pagestart + 8, 8);
+ printf("%s%s\n", (!x_interface ? "Vendor: " : ""),
+ fieldname);
+
+ inqfieldname(fieldname, pagestart + 16, 16);
+ printf("%s%s\n", (!x_interface ? "Product: " : ""),
+ fieldname);
+
+ inqfieldname(fieldname, pagestart + 32, 4);
+ printf("%s%s\n", (!x_interface ? "Revision level: " : ""),
+ fieldname);
printf("\n");
return status;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response
2014-04-03 17:07 [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response shirishpargaonkar
@ 2014-04-03 18:50 ` Douglas Gilbert
2014-04-03 19:44 ` Shirish Pargaonkar
0 siblings, 1 reply; 3+ messages in thread
From: Douglas Gilbert @ 2014-04-03 18:50 UTC (permalink / raw)
To: shirishpargaonkar; +Cc: linux-scsi, hare, Shirish Pargaonkar
Hi,
scsiinfo:
>>> Eric Youngdale ** - 11/1/93. Version 1.0.
Version 1.81 was ported to sginfo in 1998 and placed in the
sg_utils package. For more than 10 years I have been trying
to discourage people from using it. It contains next to no
modern VPD or mode pages and many of the standard INQUIRY
response fields it lists are now obsolete.
Curious about what sginfo and sysfs have in common. Oh well,
looks like I have my first patch for sg3_utils version 1.39 .
Doug Gilbert
** Did Eric wear bow ties?
On 14-04-03 01:07 PM, shirishpargaonkar@gmail.com wrote:
> From: Shirish Pargaonkar <spargaonkar@suse.com>
>
> sginfo <device> prints out various fields such as Vendor and Product in
> INQUIRY response with spaces (0x20) characters.
> This can confuse scripts some users have.
>
> A change to sysfs attributes such that it now includes spaces caused
> this problem.
>
> Strip out those trailing spaces (if any).
>
>
> Signed-off-by: Shirish Pargaonkar <spargaonkar@suse.com>
> ---
> Index: src/sginfo.c
> ===================================================================
> --- src.orig/sginfo.c 2014-04-02 22:36:13.779692431 -0500
> +++ src/sginfo.c 2014-04-02 22:51:36.028265615 -0500
> @@ -155,6 +155,7 @@
> #define MAX_BUFFER_SIZE MAX_RESP10_SIZE
>
> #define INQUIRY_RESP_INITIAL_LEN 36
> +#define MAX_INQFIELD_LEN 17
>
> #define MAX_HEADS 127
> #define HEAD_SORT_TOKEN 0x55
> @@ -3139,11 +3140,23 @@
> return status;
> }
>
> +static void
> +inqfieldname(unsigned char *deststr, const unsigned char *srcbuf, int maxlen)
> +{
> + int i;
> +
> + memset(deststr, '\0', MAX_INQFIELD_LEN);
> + for (i = maxlen - 1; i >= 0 && isspace(srcbuf[i]); --i)
> + ;
> + memcpy(deststr, srcbuf, i + 1);
> +}
> +
> static int
> do_inquiry(int * peri_type, int * resp_byte6, int inquiry_verbosity)
> {
> int status;
> unsigned char cmd[6];
> + unsigned char fieldname[MAX_INQFIELD_LEN];
> unsigned char *pagestart;
> struct scsi_cmnd_io sci;
>
> @@ -3214,14 +3227,18 @@
> }
> if (x_interface)
> printf("\n");
> - printf("%s%.8s\n", (!x_interface ? "Vendor: " : ""),
> - pagestart + 8);
> -
> - printf("%s%.16s\n", (!x_interface ? "Product: " : ""),
> - pagestart + 16);
>
> - printf("%s%.4s\n", (!x_interface ? "Revision level: " : ""),
> - pagestart + 32);
> + inqfieldname(fieldname, pagestart + 8, 8);
> + printf("%s%s\n", (!x_interface ? "Vendor: " : ""),
> + fieldname);
> +
> + inqfieldname(fieldname, pagestart + 16, 16);
> + printf("%s%s\n", (!x_interface ? "Product: " : ""),
> + fieldname);
> +
> + inqfieldname(fieldname, pagestart + 32, 4);
> + printf("%s%s\n", (!x_interface ? "Revision level: " : ""),
> + fieldname);
>
> printf("\n");
> return status;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response
2014-04-03 18:50 ` Douglas Gilbert
@ 2014-04-03 19:44 ` Shirish Pargaonkar
0 siblings, 0 replies; 3+ messages in thread
From: Shirish Pargaonkar @ 2014-04-03 19:44 UTC (permalink / raw)
To: dgilbert; +Cc: linux-scsi, hare, Shirish Pargaonkar
Sorry, should retract "A change to sysfs attributes such that it now
includes spaces caused
this problem.".
Regards,
Shirish
On Thu, Apr 3, 2014 at 1:50 PM, Douglas Gilbert <dgilbert@interlog.com> wrote:
> Hi,
> scsiinfo:
>>>> Eric Youngdale ** - 11/1/93. Version 1.0.
>
> Version 1.81 was ported to sginfo in 1998 and placed in the
> sg_utils package. For more than 10 years I have been trying
> to discourage people from using it. It contains next to no
> modern VPD or mode pages and many of the standard INQUIRY
> response fields it lists are now obsolete.
>
> Curious about what sginfo and sysfs have in common. Oh well,
> looks like I have my first patch for sg3_utils version 1.39 .
>
> Doug Gilbert
>
> ** Did Eric wear bow ties?
>
>
> On 14-04-03 01:07 PM, shirishpargaonkar@gmail.com wrote:
>>
>> From: Shirish Pargaonkar <spargaonkar@suse.com>
>>
>> sginfo <device> prints out various fields such as Vendor and Product in
>> INQUIRY response with spaces (0x20) characters.
>> This can confuse scripts some users have.
>>
>> A change to sysfs attributes such that it now includes spaces caused
>> this problem.
>>
>> Strip out those trailing spaces (if any).
>>
>>
>> Signed-off-by: Shirish Pargaonkar <spargaonkar@suse.com>
>> ---
>> Index: src/sginfo.c
>> ===================================================================
>> --- src.orig/sginfo.c 2014-04-02 22:36:13.779692431 -0500
>> +++ src/sginfo.c 2014-04-02 22:51:36.028265615 -0500
>> @@ -155,6 +155,7 @@
>> #define MAX_BUFFER_SIZE MAX_RESP10_SIZE
>>
>> #define INQUIRY_RESP_INITIAL_LEN 36
>> +#define MAX_INQFIELD_LEN 17
>>
>> #define MAX_HEADS 127
>> #define HEAD_SORT_TOKEN 0x55
>> @@ -3139,11 +3140,23 @@
>> return status;
>> }
>>
>> +static void
>> +inqfieldname(unsigned char *deststr, const unsigned char *srcbuf, int
>> maxlen)
>> +{
>> + int i;
>> +
>> + memset(deststr, '\0', MAX_INQFIELD_LEN);
>> + for (i = maxlen - 1; i >= 0 && isspace(srcbuf[i]); --i)
>> + ;
>> + memcpy(deststr, srcbuf, i + 1);
>> +}
>> +
>> static int
>> do_inquiry(int * peri_type, int * resp_byte6, int inquiry_verbosity)
>> {
>> int status;
>> unsigned char cmd[6];
>> + unsigned char fieldname[MAX_INQFIELD_LEN];
>> unsigned char *pagestart;
>> struct scsi_cmnd_io sci;
>>
>> @@ -3214,14 +3227,18 @@
>> }
>> if (x_interface)
>> printf("\n");
>> - printf("%s%.8s\n", (!x_interface ? "Vendor: " :
>> ""),
>> - pagestart + 8);
>> -
>> - printf("%s%.16s\n", (!x_interface ? "Product: " :
>> ""),
>> - pagestart + 16);
>>
>> - printf("%s%.4s\n", (!x_interface ? "Revision level: " :
>> ""),
>> - pagestart + 32);
>> + inqfieldname(fieldname, pagestart + 8, 8);
>> + printf("%s%s\n", (!x_interface ? "Vendor: " : ""),
>> + fieldname);
>> +
>> + inqfieldname(fieldname, pagestart + 16, 16);
>> + printf("%s%s\n", (!x_interface ? "Product: " : ""),
>> + fieldname);
>> +
>> + inqfieldname(fieldname, pagestart + 32, 4);
>> + printf("%s%s\n", (!x_interface ? "Revision level: " : ""),
>> + fieldname);
>>
>> printf("\n");
>> return status;
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-03 19:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-03 17:07 [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response shirishpargaonkar
2014-04-03 18:50 ` Douglas Gilbert
2014-04-03 19:44 ` Shirish Pargaonkar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox