From: shirishpargaonkar@gmail.com
To: dgilbert@interlog.com
Cc: linux-scsi@vger.kernel.org, hare@suse.com,
Shirish Pargaonkar <spargaonkar@suse.com>
Subject: [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response
Date: Thu, 3 Apr 2014 12:07:15 -0500 [thread overview]
Message-ID: <1396544835-5912-1-git-send-email-spargaonkar@suse.com> (raw)
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;
next reply other threads:[~2014-04-03 17:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-03 17:07 shirishpargaonkar [this message]
2014-04-03 18:50 ` [PATCH] sg3_utils: Strip spaces at the end of various fields in INQUIRY response Douglas Gilbert
2014-04-03 19:44 ` Shirish Pargaonkar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1396544835-5912-1-git-send-email-spargaonkar@suse.com \
--to=shirishpargaonkar@gmail.com \
--cc=dgilbert@interlog.com \
--cc=hare@suse.com \
--cc=linux-scsi@vger.kernel.org \
--cc=spargaonkar@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox