diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2014-03-11 20:30:34 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2014-03-11 20:30:34 +0000 |
commit | 5ba2664a06e6b1b811174b043db1165026158b44 (patch) | |
tree | 68e67a282517d4fecae579e235271fc721193581 | |
parent | e502efd0513ff6dff43c91f2bb850d717627dde5 (diff) | |
download | sg3_utils-5ba2664a06e6b1b811174b043db1165026158b44.tar.gz |
sg_inq+sg_vpd: --inhex=FN --raw reads response in binary
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@559 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | doc/sg_inq.8 | 19 | ||||
-rw-r--r-- | doc/sg_vpd.8 | 20 | ||||
-rw-r--r-- | sg3_utils.spec | 2 | ||||
-rw-r--r-- | src/sg_inq.c | 69 | ||||
-rw-r--r-- | src/sg_vpd.c | 73 |
8 files changed, 137 insertions, 58 deletions
@@ -2,14 +2,15 @@ Each utility has its own version number, date of last change and some description at the top of its ".c" file. All utilities in the main directory have their own "man" pages. There is also a sg3_utils man page. -Changelog for sg3_utils-1.38 [20140308] [svn: r558] +Changelog for sg3_utils-1.38 [20140311] [svn: r559] - sg_ses: add --dev-slot-num= and --sas-addr= - fix --data=- problem with large buffers - new --data=@FN to read hex data from file FN - error and warning message cleanup - add --maxlen= option - sg_inq: add --block=0|1 option to control opens - - add --inhex=FN to read response in from a file + - add --inhex=FN to read response in ASCII hex from + a file; --inhex=FN --raw reads response in binary - make -HHH (-HHHH for '-p ai') output suitable for another sg_inq invocation to use --inhex - add LU_CONG to standard inquiry response output @@ -20,7 +21,8 @@ Changelog for sg3_utils-1.38 [20140308] [svn: r558] - fix overflow in encode_whitespaces - improve unit serial number display (VPD page 0x80) - sg_vpd: add LU_CONG to standard inquiry response output - - add --inhex=FN to read response in from a file + - add --inhex=FN to read response in ASCII hex from + a file; --inhex=FN --raw reads response in binary - decode Third Party Copy (tpc) page - add HAW_ZBC in block char. VPD page (14-018r02) - add LTO and DDS vendor pages @@ -403,4 +403,4 @@ See http://sg.danny.cz/sg/tools.html Douglas Gilbert -3rd March 2014 +11th March 2014 diff --git a/debian/changelog b/debian/changelog index f0d79b15..fbb1d094 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,7 +2,7 @@ sg3-utils (1.38-0.1) unstable; urgency=low * New upstream version - -- Douglas Gilbert <dgilbert@interlog.com> Mon, 03 Mar 2014 13:00:00 -0500 + -- Douglas Gilbert <dgilbert@interlog.com> Tue, 11 Mar 2014 21:00:00 +0100 sg3-utils (1.37-0.1) unstable; urgency=low diff --git a/doc/sg_inq.8 b/doc/sg_inq.8 index c5ad6a1a..a012d7af 100644 --- a/doc/sg_inq.8 +++ b/doc/sg_inq.8 @@ -1,4 +1,4 @@ -.TH SG_INQ "8" "February 2014" "sg3_utils\-1.38" SG3_UTILS +.TH SG_INQ "8" "March 2014" "sg3_utils\-1.38" SG3_UTILS .SH NAME sg_inq \- issue SCSI INQUIRY command and/or decode its response .SH SYNOPSIS @@ -134,13 +134,14 @@ prints the device identification VPD page [0x83]. .TP \fB\-I\fR, \fB\-\-inhex\fR=\fIFN\fR \fIFN\fR is expected to be a file name (or '\-' for stdin) which contains -ASCII hexadecimal respresenting an INQUIRY (including VPD page) response. -This utility will then decode that response. It is preferable to also -supply the \fI\-\-page=PG\fR option, if not this utulity will attempt +ASCII hexadecimal or binary representing an INQUIRY (including VPD page) +response. This utility will then decode that response. It is preferable to +also supply the \fI\-\-page=PG\fR option, if not this utility will attempt to guess which VPD page (or standard INQUIRY) the response is associated with. The hexadecimal should be arranged as 1 or 2 digits representing a byte each of which is whitespace or comma separated. Anything from and -including a hash mark to the end of line is ignored. +including a hash mark to the end of line is ignored. If the \fI\-\-raw\fR +option is also given then \fIFN\fR is treated as binary. .TP \fB\-l\fR, \fB\-\-len\fR=\fILEN\fR the number \fILEN\fR is the "allocation length" field in the INQUIRY cdb. @@ -171,8 +172,12 @@ can be used to override some guessing logic associated with the \fI\-\-inhex=FN\fR option. .TP \fB\-r\fR, \fB\-\-raw\fR -output the response in binary to stdout. Error messages and warnings, if -any, are sent to stderr. +in the absence of \fI\-\-inhex=FN\fR then output response in binary. +The output should be piped to a file or another utility when this option is +used. The binary is sent to stdout, and errors are sent to stderr. +.br +if used with \fI\-\-inhex=FN\fR then the contents of \fIFN\fR is treated as +binary. .TP \fB\-s\fR, \fB\-\-vendor\fR output a standard INQUIRY response's vendor specific field from offset 36 diff --git a/doc/sg_vpd.8 b/doc/sg_vpd.8 index bed417e8..cd0838d5 100644 --- a/doc/sg_vpd.8 +++ b/doc/sg_vpd.8 @@ -1,4 +1,4 @@ -.TH SG_VPD "8" "February 2014" "sg3_utils\-1.38" SG3_UTILS +.TH SG_VPD "8" "March 2014" "sg3_utils\-1.38" SG3_UTILS .SH NAME sg_vpd \- fetch SCSI VPD page and/or decode its response .SH SYNOPSIS @@ -62,13 +62,14 @@ the latter case this option has the same effect as '\-\-quiet \-\-page=di_lu'. .TP \fB\-I\fR, \fB\-\-inhex\fR=\fIFN\fR \fIFN\fR is expected to be a file name (or '\-' for stdin) which contains -ASCII hexadecimal respresenting a VPD page (or a standard INQUIRY) response. -This utility will then decode that response. It is preferable to also -supply the \fI\-\-page=PG\fR option, if not this utulity will attempt +ASCII hexadecimal or binary representing a VPD page (or a standard INQUIRY) +response. This utility will then decode that response. It is preferable to +also supply the \fI\-\-page=PG\fR option, if not this utility will attempt to guess which VPD page (or standard INQUIRY) the response is associated with. The hexadecimal should be arranged as 1 or 2 digits representing a byte each of which is whitespace or comma separated. Anything from and -including a hash mark to the end of line is ignored. +including a hash mark to the end of line is ignored. If the \fI\-\-raw\fR +option is also given then \fIFN\fR is treated as binary. .TP \fB\-l\fR, \fB\-\-long\fR when decoding some VPD pages, give a little more output. For example the ATA @@ -104,9 +105,12 @@ standard INQUIRY response is output. This option may also be used with the suppress the amount of decoding output. .TP \fB\-r\fR, \fB\-\-raw\fR -output requested VPD page in binary. The output should be piped to a -file or another utility when this option is used. The binary is -sent to stdout, and errors are sent to stderr. +if not used with \fI\-\-inhex=FN\fR then output requested VPD page in binary. +The output should be piped to a file or another utility when this option is +used. The binary is sent to stdout, and errors are sent to stderr. +.br +if used with \fI\-\-inhex=FN\fR then the contents of \fIFN\fR is treated as +binary. .TP \fB\-v\fR, \fB\-\-verbose\fR increases the level or verbosity. diff --git a/sg3_utils.spec b/sg3_utils.spec index 215ae323..50ee2c73 100644 --- a/sg3_utils.spec +++ b/sg3_utils.spec @@ -79,7 +79,7 @@ fi %{_libdir}/*.la %changelog -* Mon Mar 03 2014 - dgilbert at interlog dot com +* Tue Mar 11 2014 - dgilbert at interlog dot com - track t10 changes * sg3_utils-1.38 diff --git a/src/sg_inq.c b/src/sg_inq.c index b2eaf1ea..0e5aa1ea 100644 --- a/src/sg_inq.c +++ b/src/sg_inq.c @@ -41,7 +41,7 @@ #include "sg_cmds_basic.h" #include "sg_pt.h" -static const char * version_str = "1.31 20140303"; /* SPC-4 rev 36q */ +static const char * version_str = "1.32 20140311"; /* SPC-4 rev 36q */ /* INQUIRY notes: * It is recommended that the initial allocation length given to a @@ -301,8 +301,10 @@ usage() " --hex|-H output response in hex\n" " --id|-i decode device identification VPD page " "(0x83)\n" - " --inhex=FN|-I FN use ASCII hex in file FN instead of " - "DEVICE\n" + " --inhex=FN|-I FN read ASCII hex from file FN instead of " + "DEVICE;\n" + " if used with --raw then read binary " + "from FN\n" " --len=LEN|-l LEN requested response length (def: 0 " "-> fetch 36\n" " bytes first, then fetch again as " @@ -748,16 +750,17 @@ cl_process(struct opts_t * op, int argc, char * argv[]) #endif /* SG_SCSI_STRINGS */ -/* Read ASCII hex bytes from fname (a file named '-' taken as stdin). - * There should be either one entry per line or a comma, space or tab - * separated list of bytes. If no_space is set then a string of ACSII hex - * digits is expected, 2 per byte. Everything from and including a '#' - * on a line is ignored. Returns 0 if ok, or 1 if error. */ +/* Read ASCII hex bytes or binary from fname (a file named '-' taken as + * stdin). If reading ASCII hex then there should be either one entry per + * line or a comma, space or tab separated list of bytes. If no_space is + * set then a string of ACSII hex digits is expected, 2 per byte. Everything + * from and including a '#' on a line is ignored. Returns 0 if ok, or 1 if + * error. */ static int -f2hex_arr(const char * fname, int no_space, unsigned char * mp_arr, - int * mp_arr_len, int max_arr_len) +f2hex_arr(const char * fname, int as_binary, int no_space, + unsigned char * mp_arr, int * mp_arr_len, int max_arr_len) { - int fn_len, in_len, k, j, m, split_line; + int fn_len, in_len, k, j, m, split_line, fd, has_stdin; unsigned int h; const char * lcp; FILE * fp; @@ -770,14 +773,43 @@ f2hex_arr(const char * fname, int no_space, unsigned char * mp_arr, fn_len = strlen(fname); if (0 == fn_len) return 1; - if ((1 == fn_len) && ('-' == fname[0])) /* read from stdin */ - fp = stdin; - else { - fp = fopen(fname, "r"); - if (NULL == fp) { - pr2serr("Unable to open %s for reading\n", fname); + has_stdin = ((1 == fn_len) && ('-' == fname[0])); /* read from stdin */ + if (as_binary) { + if (has_stdin) + fd = STDIN_FILENO; + else { + fd = open(fname, O_RDONLY); + if (fd < 0) { + pr2serr("unable to open binary file %s: %s\n", fname, + safe_strerror(errno)); + return 1; + } + } + k = read(fd, mp_arr, max_arr_len); + if (k <= 0) { + if (0 == k) + pr2serr("read 0 bytes from binary file %s\n", fname); + else + pr2serr("read from binary file %s: %s\n", fname, + safe_strerror(errno)); + if (! has_stdin) + close(fd); return 1; } + *mp_arr_len = k; + if (! has_stdin) + close(fd); + return 0; + } else { /* So read the file as ASCII hex */ + if (has_stdin) + fp = stdin; + else { + fp = fopen(fname, "r"); + if (NULL == fp) { + pr2serr("Unable to open %s for reading\n", fname); + return 1; + } + } } carry_over[0] = 0; @@ -3572,9 +3604,10 @@ main(int argc, char * argv[]) pr2serr("Don't support --cmddt with --inhex= option\n"); return SG_LIB_SYNTAX_ERROR; } - if (f2hex_arr(op->inhex_fn, 0, rsp_buff, &inhex_len, + if (f2hex_arr(op->inhex_fn, op->do_raw, 0, rsp_buff, &inhex_len, sizeof(rsp_buff))) return SG_LIB_FILE_ERROR; + op->do_raw = 0; /* don't want raw on output with --inhex= */ if (-1 == op->page_num) { /* may be able to deduce VPD page */ if (op->page_pdt < 0) op->page_pdt = 0x1f & rsp_buff[0]; diff --git a/src/sg_vpd.c b/src/sg_vpd.c index be6250b9..8fe7b85e 100644 --- a/src/sg_vpd.c +++ b/src/sg_vpd.c @@ -15,6 +15,7 @@ #include <getopt.h> #define __STDC_FORMAT_MACROS 1 #include <inttypes.h> +#include <errno.h> #ifdef HAVE_CONFIG_H #include "config.h" @@ -32,7 +33,7 @@ */ -static const char * version_str = "0.80 20140303"; /* spc4r36 + sbc3r35 */ +static const char * version_str = "0.81 20140311"; /* spc4r36 + sbc3r35 */ /* And with sbc3r35, vale Mark Evans */ void svpd_enumerate_vendor(void); @@ -227,8 +228,10 @@ usage() "twice for\n" " short logical unit designator (equiv: " "'-qp di_lu')\n" - " --inhex=FN|-I FN use ASCII hex in file FN instead of " - "DEVICE\n" + " --inhex=FN|-I FN read ASCII hex from file FN instead of " + "DEVICE;\n" + " if used with --raw then read binary " + "from FN\n" " --long|-l perform extra decoding\n" " --maxlen=LEN|-m LEN max response length (allocation " "length in cdb)\n" @@ -247,16 +250,17 @@ usage() "response.\n"); } -/* Read ASCII hex bytes from fname (a file named '-' taken as stdin). - * There should be either one entry per line or a comma, space or tab - * separated list of bytes. If no_space is set then a string of ACSII hex - * digits is expected, 2 per byte. Everything from and including a '#' - * on a line is ignored. Returns 0 if ok, or 1 if error. */ +/* Read ASCII hex bytes or binary from fname (a file named '-' taken as + * stdin). If reading ASCII hex then there should be either one entry per + * line or a comma, space or tab separated list of bytes. If no_space is + * set then a string of ACSII hex digits is expected, 2 per byte. Everything + * from and including a '#' on a line is ignored. Returns 0 if ok, or 1 if + * error. */ static int -f2hex_arr(const char * fname, int no_space, unsigned char * mp_arr, - int * mp_arr_len, int max_arr_len) +f2hex_arr(const char * fname, int as_binary, int no_space, + unsigned char * mp_arr, int * mp_arr_len, int max_arr_len) { - int fn_len, in_len, k, j, m, split_line; + int fn_len, in_len, k, j, m, split_line, fd, has_stdin; unsigned int h; const char * lcp; FILE * fp; @@ -269,15 +273,44 @@ f2hex_arr(const char * fname, int no_space, unsigned char * mp_arr, fn_len = strlen(fname); if (0 == fn_len) return 1; - if ((1 == fn_len) && ('-' == fname[0])) /* read from stdin */ - fp = stdin; - else { - fp = fopen(fname, "r"); - if (NULL == fp) { - pr2serr("Unable to open %s for reading\n", fname); + has_stdin = ((1 == fn_len) && ('-' == fname[0])); /* read from stdin */ + if (as_binary) { + if (has_stdin) + fd = STDIN_FILENO; + else { + fd = open(fname, O_RDONLY); + if (fd < 0) { + pr2serr("unable to open binary file %s: %s\n", fname, + safe_strerror(errno)); + return 1; + } + } + k = read(fd, mp_arr, max_arr_len); + if (k <= 0) { + if (0 == k) + pr2serr("read 0 bytes from binary file %s\n", fname); + else + pr2serr("read from binary file %s: %s\n", fname, + safe_strerror(errno)); + if (! has_stdin) + close(fd); return 1; } - } + *mp_arr_len = k; + if (! has_stdin) + close(fd); + return 0; + } else { /* So read the file as ASCII hex */ + if (has_stdin) + fp = stdin; + else { + fp = fopen(fname, "r"); + if (NULL == fp) { + pr2serr("Unable to open %s for reading\n", fname); + return 1; + } + } + } carry_over[0] = 0; for (j = 0; j < 512; ++j) { @@ -3230,8 +3263,10 @@ main(int argc, char * argv[]) pr2serr("Cannot have both a DEVICE and --inhex= option\n"); return SG_LIB_SYNTAX_ERROR; } - if (f2hex_arr(inhex_fn, 0, rsp_buff, &inhex_len, sizeof(rsp_buff))) + if (f2hex_arr(inhex_fn, do_raw, 0, rsp_buff, &inhex_len, + sizeof(rsp_buff))) return SG_LIB_FILE_ERROR; + do_raw = 0; /* don't want raw on output with --inhex= */ if (NULL == page_str) { /* may be able to deduce VPD page */ if ((0x2 == (0xf & rsp_buff[3])) && (rsp_buff[2] > 2)) { if (do_verbose) |