aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-03-09 15:52:27 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-03-09 15:52:27 +0000
commit6498c8fa92b6ecfce411679af47064a6fd80ff33 (patch)
tree3a9ff8d3f4117965d82fe9105949e23dae93a023 /lib
parentd4e94e36b445985f8618ed048c98787ad0edfdf1 (diff)
downloadsg3_utils-6498c8fa92b6ecfce411679af47064a6fd80ff33.tar.gz
sg_logs: add --exclude and --undefined options, improve 'last_n' log pages; add inhex/logs_last_n.hex
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@942 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/Makefile.in41
-rw-r--r--lib/sg_lib.c34
-rw-r--r--lib/sg_lib_data.c4
-rw-r--r--lib/sg_lib_names.c132
5 files changed, 179 insertions, 33 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 16efe9e5..ec3932ed 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,6 +1,7 @@
libsgutils2_la_SOURCES = \
sg_lib.c \
sg_lib_data.c \
+ sg_lib_names.c \
sg_cmds_basic.c \
sg_cmds_basic2.c \
sg_cmds_extra.c \
diff --git a/lib/Makefile.in b/lib/Makefile.in
index e221b44e..3b07a603 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -145,10 +145,10 @@ am__uninstall_files_from_dir = { \
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__libsgutils2_la_SOURCES_DIST = sg_lib.c sg_lib_data.c \
- sg_cmds_basic.c sg_cmds_basic2.c sg_cmds_extra.c sg_cmds_mmc.c \
- sg_pt_common.c sg_pt_dummy.c sg_pt_linux.c sg_io_linux.c \
- sg_pt_linux_nvme.c sg_pt_win32.c sg_pt_freebsd.c \
- sg_pt_solaris.c sg_pt_osf1.c sg_pt_haiku.c
+ sg_lib_names.c sg_cmds_basic.c sg_cmds_basic2.c \
+ sg_cmds_extra.c sg_cmds_mmc.c sg_pt_common.c sg_pt_dummy.c \
+ sg_pt_linux.c sg_io_linux.c sg_pt_linux_nvme.c sg_pt_win32.c \
+ sg_pt_freebsd.c sg_pt_solaris.c sg_pt_osf1.c sg_pt_haiku.c
@OS_LINUX_TRUE@@PT_DUMMY_TRUE@am__objects_1 = sg_pt_dummy.lo
@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__objects_2 = sg_pt_linux.lo \
@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_io_linux.lo \
@@ -164,13 +164,13 @@ am__libsgutils2_la_SOURCES_DIST = sg_lib.c sg_lib_data.c \
@OS_NETBSD_TRUE@am__objects_11 = sg_pt_dummy.lo
@OS_OPENBSD_TRUE@am__objects_12 = sg_pt_dummy.lo
@OS_OTHER_TRUE@am__objects_13 = sg_pt_dummy.lo
-am_libsgutils2_la_OBJECTS = sg_lib.lo sg_lib_data.lo sg_cmds_basic.lo \
- sg_cmds_basic2.lo sg_cmds_extra.lo sg_cmds_mmc.lo \
- sg_pt_common.lo $(am__objects_1) $(am__objects_2) \
- $(am__objects_3) $(am__objects_4) $(am__objects_5) \
- $(am__objects_6) $(am__objects_7) $(am__objects_8) \
- $(am__objects_9) $(am__objects_10) $(am__objects_11) \
- $(am__objects_12) $(am__objects_13)
+am_libsgutils2_la_OBJECTS = sg_lib.lo sg_lib_data.lo sg_lib_names.lo \
+ sg_cmds_basic.lo sg_cmds_basic2.lo sg_cmds_extra.lo \
+ sg_cmds_mmc.lo sg_pt_common.lo $(am__objects_1) \
+ $(am__objects_2) $(am__objects_3) $(am__objects_4) \
+ $(am__objects_5) $(am__objects_6) $(am__objects_7) \
+ $(am__objects_8) $(am__objects_9) $(am__objects_10) \
+ $(am__objects_11) $(am__objects_12) $(am__objects_13)
libsgutils2_la_OBJECTS = $(am_libsgutils2_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -199,11 +199,11 @@ am__depfiles_remade = ./$(DEPDIR)/sg_cmds_basic.Plo \
./$(DEPDIR)/sg_cmds_basic2.Plo ./$(DEPDIR)/sg_cmds_extra.Plo \
./$(DEPDIR)/sg_cmds_mmc.Plo ./$(DEPDIR)/sg_io_linux.Plo \
./$(DEPDIR)/sg_lib.Plo ./$(DEPDIR)/sg_lib_data.Plo \
- ./$(DEPDIR)/sg_pt_common.Plo ./$(DEPDIR)/sg_pt_dummy.Plo \
- ./$(DEPDIR)/sg_pt_freebsd.Plo ./$(DEPDIR)/sg_pt_haiku.Plo \
- ./$(DEPDIR)/sg_pt_linux.Plo ./$(DEPDIR)/sg_pt_linux_nvme.Plo \
- ./$(DEPDIR)/sg_pt_osf1.Plo ./$(DEPDIR)/sg_pt_solaris.Plo \
- ./$(DEPDIR)/sg_pt_win32.Plo
+ ./$(DEPDIR)/sg_lib_names.Plo ./$(DEPDIR)/sg_pt_common.Plo \
+ ./$(DEPDIR)/sg_pt_dummy.Plo ./$(DEPDIR)/sg_pt_freebsd.Plo \
+ ./$(DEPDIR)/sg_pt_haiku.Plo ./$(DEPDIR)/sg_pt_linux.Plo \
+ ./$(DEPDIR)/sg_pt_linux_nvme.Plo ./$(DEPDIR)/sg_pt_osf1.Plo \
+ ./$(DEPDIR)/sg_pt_solaris.Plo ./$(DEPDIR)/sg_pt_win32.Plo
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -374,9 +374,9 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-libsgutils2_la_SOURCES = sg_lib.c sg_lib_data.c sg_cmds_basic.c \
- sg_cmds_basic2.c sg_cmds_extra.c sg_cmds_mmc.c sg_pt_common.c \
- $(am__append_1) $(am__append_2) $(am__append_3) \
+libsgutils2_la_SOURCES = sg_lib.c sg_lib_data.c sg_lib_names.c \
+ sg_cmds_basic.c sg_cmds_basic2.c sg_cmds_extra.c sg_cmds_mmc.c \
+ sg_pt_common.c $(am__append_1) $(am__append_2) $(am__append_3) \
$(am__append_4) $(am__append_5) $(am__append_6) \
$(am__append_7) $(am__append_8) $(am__append_9) \
$(am__append_10) $(am__append_11) $(am__append_12) \
@@ -491,6 +491,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_io_linux.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_lib.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_lib_data.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_lib_names.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_common.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_dummy.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_freebsd.Plo@am__quote@ # am--include-marker
@@ -668,6 +669,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/sg_io_linux.Plo
-rm -f ./$(DEPDIR)/sg_lib.Plo
-rm -f ./$(DEPDIR)/sg_lib_data.Plo
+ -rm -f ./$(DEPDIR)/sg_lib_names.Plo
-rm -f ./$(DEPDIR)/sg_pt_common.Plo
-rm -f ./$(DEPDIR)/sg_pt_dummy.Plo
-rm -f ./$(DEPDIR)/sg_pt_freebsd.Plo
@@ -729,6 +731,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/sg_io_linux.Plo
-rm -f ./$(DEPDIR)/sg_lib.Plo
-rm -f ./$(DEPDIR)/sg_lib_data.Plo
+ -rm -f ./$(DEPDIR)/sg_lib_names.Plo
-rm -f ./$(DEPDIR)/sg_pt_common.Plo
-rm -f ./$(DEPDIR)/sg_pt_dummy.Plo
-rm -f ./$(DEPDIR)/sg_pt_freebsd.Plo
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index e504e6b8..c4fe1d7d 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -1063,7 +1063,7 @@ sg_get_designation_descriptor_str(const char * lip, const uint8_t * ddp,
}
ccc_id = sg_get_unaligned_be64(ip + ci_off);
n += sg_scnpr(b + n, blen - n, "%s IEEE identifier: 0x%"
- PRIx64 "x\n", lip, ccc_id);
+ PRIx64 "x\n", lip, ccc_id);
if (12 == dlen) {
d_id = sg_get_unaligned_be32(ip + 8);
n += sg_scnpr(b + n, blen - n, "%s Directory ID: 0x%x\n",
@@ -1093,7 +1093,7 @@ sg_get_designation_descriptor_str(const char * lip, const uint8_t * ddp,
n += sg_scnpr(b + n, blen - n, "%s NAA 2, vendor "
"specific identifier A: 0x%x\n", lip, d_id);
n += sg_scnpr(b + n, blen - n, "%s AOI: 0x%x\n", lip,
- c_id);
+ c_id);
n += sg_scnpr(b + n, blen - n, "%s vendor specific "
"identifier B: 0x%x\n", lip, vsi);
n += sg_scnpr(b + n, blen - n, "%s [0x", lip);
@@ -1137,7 +1137,7 @@ sg_get_designation_descriptor_str(const char * lip, const uint8_t * ddp,
}
if (do_long) {
n += sg_scnpr(b + n, blen - n, "%s NAA 5, AOI: 0x%x\n",
- lip, c_id);
+ lip, c_id);
n += sg_scnpr(b + n, blen - n, "%s Vendor Specific "
"Identifier: 0x%" PRIx64 "\n", lip, vsei);
n += sg_scnpr(b + n, blen - n, "%s [0x", lip);
@@ -1167,7 +1167,7 @@ sg_get_designation_descriptor_str(const char * lip, const uint8_t * ddp,
}
if (do_long) {
n += sg_scnpr(b + n, blen - n, "%s NAA 6, AOI: 0x%x\n",
- lip, c_id);
+ lip, c_id);
n += sg_scnpr(b + n, blen - n, "%s Vendor Specific "
"Identifier: 0x%" PRIx64 "\n", lip, vsei);
vsei = sg_get_unaligned_be64(ip + 8);
@@ -2943,24 +2943,27 @@ dStrHexErr(const char* str, int len, int no_ascii)
(sg_warnings_strm ? sg_warnings_strm : stderr));
}
-#define DSHS_LINE_BLEN 160
-#define DSHS_BPL 16
+#define DSHS_LINE_BLEN 160 /* maximum characters per line */
+#define DSHS_BPL 16 /* bytes per line */
/* Read 'len' bytes from 'str' and output as ASCII-Hex bytes (space
* separated) to 'b' not to exceed 'b_len' characters. Each line
* starts with 'leadin' (NULL for no leadin) and there are 16 bytes
* per line with an extra space between the 8th and 9th bytes. 'format'
- * is 0 for repeat in printable ASCII ('.' for non printable) to
- * right of each line; 1 don't (so just output ASCII hex). Returns
- * number of bytes written to 'b' excluding the trailing '\0'. */
+ * is 0 for repeat in printable ASCII ('.' for non printable chars) to
+ * right of each line; 1 don't (so just output ASCII hex). Note that
+ * an address is not printed on each line preceding the hex data. Returns
+ * number of bytes written to 'b' excluding the trailing '\0'.
+ * The only difference between dStrHexStr() and hex2str() is the type of
+ * the first argument. */
int
dStrHexStr(const char * str, int len, const char * leadin, int format,
int b_len, char * b)
{
int bpstart, bpos, k, n, prior_ascii_len;
bool want_ascii;
- char buff[DSHS_LINE_BLEN + 2];
- char a[DSHS_BPL + 1];
+ char buff[DSHS_LINE_BLEN + 2]; /* allow for trailing null */
+ char a[DSHS_BPL + 1]; /* printable ASCII bytes or '.' */
const char * p = str;
if (len <= 0) {
@@ -3531,6 +3534,8 @@ sg_get_llnum_nomult(const char * buf)
return (1 == res) ? num : -1;
}
+#define MAX_NUM_ASCII_LINES 1048576
+
/* 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
@@ -3622,7 +3627,7 @@ sg_f2hex_arr(const char * fname, bool as_binary, bool no_space,
}
carry_over[0] = 0;
- for (j = 0; j < 512; ++j) {
+ for (j = 0; j < MAX_NUM_ASCII_LINES; ++j) {
if (NULL == fgets(line, sizeof(line), fp))
break;
in_len = strlen(line);
@@ -3740,6 +3745,11 @@ sg_f2hex_arr(const char * fname, bool as_binary, bool no_space,
}
off += (k + 1);
}
+ } /* end of per line loop */
+ if (j >= MAX_NUM_ASCII_LINES) {
+ pr2ws("%s: wow, more than %d lines of ASCII, give up\n", __func__,
+ SG_LIB_LBA_OUT_OF_RANGE);
+ return SG_LIB_LBA_OUT_OF_RANGE;
}
*mp_arr_len = off;
if (stdin != fp)
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index a7970f2a..f6c9b3ac 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -19,7 +19,7 @@
#include "sg_lib_data.h"
-const char * sg_lib_version_str = "2.87 20220217";
+const char * sg_lib_version_str = "2.88 20220305";
/* spc6r06, sbc5r01, zbc2r12 */
@@ -257,7 +257,7 @@ struct sg_lib_value_name_t sg_lib_read_buff_arr[] = {
{0x3, PDT_ALL, "descriptor"},
{0xa, PDT_ALL, "read data from echo buffer"},
{0xb, PDT_ALL, "echo buffer descriptor"},
- {0xf, PDT_ALL, "read microcode status"}, /* added in spc5r20 */
+ {0xf, PDT_ALL, "read microcode status"}, /* added in spc5r20 */
{0x1a, PDT_ALL, "enable expander comms protocol and echo buffer"},
{0x1c, PDT_ALL, "error history"},
{0xffff, 0, NULL},
diff --git a/lib/sg_lib_names.c b/lib/sg_lib_names.c
new file mode 100644
index 00000000..2543f2ab
--- /dev/null
+++ b/lib/sg_lib_names.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2022 Douglas Gilbert.
+ * All rights reserved.
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the BSD_LICENSE file.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <stdlib.h>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#else
+#define SG_SCSI_STRINGS 1
+#endif
+
+#include "sg_lib.h"
+#include "sg_lib_data.h"
+#include "sg_lib_names.h"
+
+/* List of SPC, then SBC, the ZBC mode page names. Tape and other mode pages
+ * are squeezed into this list as long as they don't conflict.
+ * The value is: (mode_page << 8) | mode_subpage
+ * Maintain the list in numerical order to allow binary search. */
+struct sg_lib_simple_value_name_t sg_lib_names_mode_arr[] = {
+ {0x0000, "Unit Attention condition"}, /* common vendor specific page */
+ {0x0100, "Read-Write error recovery"}, /* SBC */
+ {0x0200, "Disconnect-Reconnect"}, /* SPC */
+ {0x0300, "Format (obsolete)"}, /* SBC */
+ {0x0400, "Rigid disk geometry (obsolete)"}, /* SBC */
+ {0x0500, "Flexible disk (obsolete)"}, /* SBC */
+ {0x0700, "Verify error recovery"}, /* SBC */
+ {0x0800, "Caching"}, /* SBC */
+ {0x0900, "Peripheral device (obsolete)"}, /* SPC */
+ {0x0a00, "Control"}, /* SPC */
+ {0x0a01, "Control extension"}, /* SPC */
+ {0x0a02, "Application tage"}, /* SBC */
+ {0x0a03, "Command duration limit A"}, /* SPC */
+ {0x0a04, "Command duration limit B"}, /* SPC */
+ {0x0a05, "IO Advice Hints Grouping"}, /* SBC */
+ {0x0a06, "Background operation control"}, /* SBC */
+ {0x0af0, "Control data protection"}, /* SSC */
+ {0x0af1, "PATA control"}, /* SAT */
+ {0x0b00, "Medium Types Supported (obsolete)"}, /* SSC */
+ {0x0c00, "Notch and partition (obsolete)"}, /* SBC */
+ {0x0d00, "Power condition (obsolete), CD device parameters"},
+ {0x0e00, "CD audio control"}, /* MMC */
+ {0x0e01, "Target device"}, /* ADC */
+ {0x0e02, "DT device primary port"}, /* ADC */
+ {0x0e03, "Logical unit"}, /* ADC */
+ {0x0e04, "Target device serial number"}, /* ADC */
+ {0x0f00, "Data compression"}, /* SSC */
+ {0x1000, "XOR control (obsolete, Device configuration"}, /* SBC,SSC */
+ {0x1001, "Device configuration extension"}, /* SSC */
+ {0x1100, "Medium partition (1)"}, /* SSC */
+ {0x1400, "Enclosure services management"}, /* SES */
+ {0x1800, "Protocol specific logical unit"}, /* transport */
+ {0x1900, "Protocol specific port"}, /* transport */
+ {0x1901, "Phy control and discovery"}, /* SPL */
+ {0x1902, "Shared port control"}, /* SPL */
+ {0x1903, "Enhanced phy control"}, /* SPL */
+ {0x1904, "Out of band management control"}, /* SPL */
+ {0x1A00, "Power condition"}, /* SPC */
+ {0x1A01, "Power consumption"}, /* SPC */
+ {0x1Af1, "ATA Power condition"}, /* SPC */
+ {0x1b00, "LUN mapping"}, /* ADC */
+ {0x1c00, "Information exceptions control"}, /* SPC */
+ {0x1c01, "Background control"}, /* SBC */
+ {0x1c02, "Logical block provisioning"}, /* SBC */
+ {0x1c02, "Logical block provisioning"}, /* SBC */
+ {0x1d00, "Medium configuration, CD/DVD timeout, "
+ "element address assignments"}, /* SSC,MMC,SMC */
+ {0x1e00, "Transport geometry assignments"}, /* SMC */
+ {0x1f00, "Device capabilities"}, /* SMC */
+
+ {-1, NULL}, /* sentinel */
+};
+
+/* Don't count sentinel when doing binary searches, etc */
+const size_t sg_lib_names_mode_len =
+ SG_ARRAY_SIZE(sg_lib_names_mode_arr) - 1;
+
+/* List of SPC, then SBC, the ZBC VPD page names. Tape and other VPD pages
+ * are squeezed into this list as long as they don't conflict.
+ * For VPDs > 0 the value is: (vpd << 8) | vpd_number
+ * Maintain the list in numerical order to allow binary search. */
+struct sg_lib_simple_value_name_t sg_lib_names_vpd_arr[] = {
+ {0x00, "Supported VPD pages"}, /* SPC */
+ {0x80, "Unit serial number"}, /* SPC */
+ {0x81, "Implemented operating definition (obsolete)"}, /* SPC */
+ {0x82, "ASCII implemented operating definition (obsolete)"}, /* SPC */
+ {0x83, "Device identification"}, /* SPC */
+ {0x84, "Software interface identification"}, /* SPC */
+ {0x85, "Management network addresses"}, /* SPC */
+ {0x86, "Extended INQUIRY data"}, /* SPC */
+ {0x87, "Mode page policy"}, /* SPC */
+ {0x88, "SCSI ports"}, /* SPC */
+ {0x89, "ATA information"}, /* SAT */
+ {0x8a, "Power condition"}, /* SPC */
+ {0x8b, "Device constituents"}, /* SSC */
+ {0x8c, "CFA profile information"}, /* SPC */
+ {0x8d, "Power consumption"}, /* SPC */
+ {0x8f, "Third party copy"}, /* SPC */
+ {0x90, "Protocol specific logical unit information"}, /* transport */
+ {0x91, "Protocol specific port information"}, /* transport */
+ {0x92, "SCSI feature sets"}, /* SPC,SBC */
+ {0xb0, "Block limits"}, /* SBC */
+ {0xb1, "Block device characteristics"}, /* SBC */
+ {0xb2, "Logical block provisioning"}, /* SBC */
+ {0xb3, "Referrals"}, /* SBC */
+ {0xb4, "Supported Block Lengths and Protection Types"}, /* SBC */
+ {0xb5, "Block device characteristics extension"}, /* SBC */
+ {0xb6, "Zoned block device characteristics"}, /* ZBC */
+ {0xb7, "Block limits extension"}, /* SBC */
+ {0xb8, "Format presets"}, /* SBC */
+ {0xb9, "Concurrent positioning ranges"}, /* SBC */
+ {0x01b0, "Sequential access Device Capabilities"}, /* SSC */
+ {0x01b1, "Manufacturer-assigned serial number"}, /* SSC */
+ {0x01b2, "TapeAlert supported flags"}, /* SSC */
+ {0x01b3, "Automation device serial number"}, /* SSC */
+ {0x01b4, "Data transfer device element address"}, /* SSC */
+ {0x01b5, "Data transfer device element address"}, /* SSC */
+ {0x11b0, "OSD information"}, /* OSD */
+ {0x11b1, "Security token"}, /* OSD */
+
+ {-1, NULL}, /* sentinel */
+};
+
+/* Don't count sentinel when doing binary searches, etc */
+const size_t sg_lib_names_vpd_len =
+ SG_ARRAY_SIZE(sg_lib_names_vpd_arr) - 1;