aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2022-01-28 20:51:37 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2022-01-28 20:51:37 +0000
commitd5890d56b6bcb6d1aa277f0bab78abb1ef66a88e (patch)
tree7040a74064a5c63a64b95e577e402fb65aacb15e
parentbff5298804af11eab5072217d362f55707849a5a (diff)
downloadsg3_utils-d5890d56b6bcb6d1aa277f0bab78abb1ef66a88e.tar.gz
cleanup masks for PDT [0x1f] and group_number [0x3f]
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@934 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog3
-rw-r--r--doc/sg_rep_zones.822
-rw-r--r--doc/sg_write_verify.84
-rw-r--r--include/sg_lib.h4
-rw-r--r--lib/sg_cmds_basic.c8
-rw-r--r--lib/sg_cmds_basic2.c4
-rw-r--r--lib/sg_cmds_extra.c10
-rw-r--r--lib/sg_lib.c52
-rw-r--r--lib/sg_lib_data.c8
-rw-r--r--lib/sg_pt_common.c6
-rw-r--r--lib/sg_pt_freebsd.c6
-rw-r--r--lib/sg_pt_win32.c10
-rw-r--r--src/sg_compare_and_write.c6
-rw-r--r--src/sg_format.c8
-rw-r--r--src/sg_inq.c26
-rw-r--r--src/sg_logs.c168
-rw-r--r--src/sg_opcodes.c8
-rw-r--r--src/sg_rep_zones.c56
-rw-r--r--src/sg_sanitize.c6
-rw-r--r--src/sg_scan_linux.c2
-rw-r--r--src/sg_scan_win32.c6
-rw-r--r--src/sg_ses.c6
-rw-r--r--src/sg_sync.c2
-rw-r--r--src/sg_vpd.c66
-rw-r--r--src/sg_wr_mode.c2
-rw-r--r--src/sg_write_same.c10
-rw-r--r--src/sg_write_verify.c8
-rw-r--r--src/sg_write_x.c10
28 files changed, 271 insertions, 256 deletions
diff --git a/ChangeLog b/ChangeLog
index cfbf4179..6f04a2e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ 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 pre-release sg3_utils-1.48 [20220126] [svn: r933]
+Changelog for pre-release sg3_utils-1.48 [20220128] [svn: r934]
- sg_z_act_query: new utility for sending either a
Zone activate or Zone query command
- sg_rep_density: new utility for decoding the response of
@@ -19,6 +19,7 @@ Changelog for pre-release sg3_utils-1.48 [20220126] [svn: r933]
- sg_opcodes: cleanup error reporting
- sg_lib: add sg_pdt_s_eq() to cope with ZBC disks which may
be either PDT_ZBC (if host managed) or PDT_DISK
+ - cleanup masks for PDT [0x1f] and group_number [0x3f]
- initialize all sense buffers to 0
- rework main README file
- rev 921+922 are bugfix revs on release 1.47 [r919,920]
diff --git a/doc/sg_rep_zones.8 b/doc/sg_rep_zones.8
index d438971e..839d368b 100644
--- a/doc/sg_rep_zones.8
+++ b/doc/sg_rep_zones.8
@@ -1,13 +1,14 @@
-.TH SG_REP_ZONES "8" "November 2021" "sg3_utils\-1.48" SG3_UTILS
+.TH SG_REP_ZONES "8" "January 2022" "sg3_utils\-1.48" SG3_UTILS
.SH NAME
sg_rep_zones \- send SCSI REPORT ZONES, REALMS or ZONE DOMAINS command
.SH SYNOPSIS
.B sg_rep_zones
-[\fI\-\-domain\fR] [\fI\-\-force\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR]
-[\fI\-\-inhex=FN\fR] [\fI\-\-locator=LBA\fR] [\fI\-\-maxlen=LEN\fR]
-[\fI\-\-num=NUM\fR] [\fI\-\-partial\fR] [\fI\-\-raw\fR] [\fI\-\-readonly\fR]
-[\fI\-\-realm\fR] [\fI\-\-report=OPT\fR] [\fI\-\-start=LBA\fR]
-[\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-wp\fR] \fIDEVICE\fR
+[\fI\-\-brief\fR] [\fI\-\-domain\fR] [\fI\-\-force\fR] [\fI\-\-help\fR]
+[\fI\-\-hex\fR] [\fI\-\-inhex=FN\fR] [\fI\-\-locator=LBA\fR]
+[\fI\-\-maxlen=LEN\fR] [\fI\-\-num=NUM\fR] [\fI\-\-partial\fR] [\fI\-\-raw\fR]
+[\fI\-\-readonly\fR] [\fI\-\-realm\fR] [\fI\-\-report=OPT\fR]
+[\fI\-\-start=LBA\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-wp\fR]
+\fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
@@ -30,6 +31,13 @@ option is given then the corresponding command response is assumed.
.SH OPTIONS
Arguments to long options are mandatory for short options as well.
.TP
+\fB\-b\fR, \fB\-\-brief\fR
+even though a ZBC disk will typically limit the size of the response
+to the REPORT ZONES command (e.g. to 127 zones say), this is still
+potentially a lot of output. This option will only decode and output
+fields found in the header plus some of the fields from the last
+descriptor in the current response.
+.TP
\fB\-d\fR, \fB\-\-domain\fR
send or decode the SCSI REPORT ZONE DOMAINS command.
.TP
@@ -141,7 +149,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2014\-2021 Douglas Gilbert
+Copyright \(co 2014\-2022 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_write_verify.8 b/doc/sg_write_verify.8
index 1ae27cb0..f1837f95 100644
--- a/doc/sg_write_verify.8
+++ b/doc/sg_write_verify.8
@@ -1,4 +1,4 @@
-.TH "WRITE AND VERIFY" "8" "June 2018" "sg3_utils\-1.43" SG3_UTILS
+.TH "WRITE AND VERIFY" "8" "January 2022" "sg3_utils\-1.48" SG3_UTILS
.SH NAME
sg_write_and_verify \- send the SCSI WRITE AND VERIFY command
.SH SYNOPSIS
@@ -57,7 +57,7 @@ it clear.
.TP
\fB\-g\fR, \fB\-\-group\fR=\fIGN\fR
where \fIGN\fR is the value to place in the command's GROUP NUMBER field.
-Values between 0 and 31 (inclusive) are accepted. The default is value is 0.
+Values between 0 and 63 (inclusive) are accepted. The default is value is 0.
.TP
\fB\-h\fR, \fB\-\-help\fR
output the usage message then exit.
diff --git a/include/sg_lib.h b/include/sg_lib.h
index 5cfbba76..38aa0011 100644
--- a/include/sg_lib.h
+++ b/include/sg_lib.h
@@ -62,6 +62,10 @@ extern "C" {
#define PDT_ZBC 0x14 /* Zoned Block Commands (ZBC) */
#define PDT_WLUN 0x1e /* Well known logical unit (WLUN) */
#define PDT_UNKNOWN 0x1f /* Unknown or no device type */
+#define PDT_MASK 0x1f /* For byte 0 of INQUIRY response */
+#define PDT_MAX 0x1f
+
+#define GRPNUM_MASK 0x3f
/* ZBC disks use either PDT_ZBC (if 'host managed') or PDT_DISK .
* So squeeze two PDTs into one integer. Use sg_pdt_s_eq() to compare.
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c
index 92dd102d..d9970c89 100644
--- a/lib/sg_cmds_basic.c
+++ b/lib/sg_cmds_basic.c
@@ -542,7 +542,7 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
if (inq_data) {
memset(inq_data, 0, sizeof(* inq_data));
inq_data->peripheral_qualifier = 0x3;
- inq_data->peripheral_type = 0x1f;
+ inq_data->peripheral_type = PDT_UNKNOWN;
}
inq_resp = sg_memalign(SAFE_STD_INQ_RESP_LEN, 0, &free_irp, false);
if (NULL == inq_resp) {
@@ -554,7 +554,7 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
if (inq_data && (0 == ret)) {
inq_data->peripheral_qualifier = (inq_resp[0] >> 5) & 0x7;
- inq_data->peripheral_type = inq_resp[0] & 0x1f;
+ inq_data->peripheral_type = inq_resp[0] & PDT_MASK;
inq_data->byte_1 = inq_resp[1];
inq_data->version = inq_resp[2];
inq_data->byte_3 = inq_resp[3];
@@ -584,7 +584,7 @@ sg_simple_inquiry_pt(struct sg_pt_base * ptvp,
if (inq_data) {
memset(inq_data, 0, sizeof(* inq_data));
inq_data->peripheral_qualifier = 0x3;
- inq_data->peripheral_type = 0x1f;
+ inq_data->peripheral_type = PDT_MASK;
}
inq_resp = sg_memalign(SAFE_STD_INQ_RESP_LEN, 0, &free_irp, false);
if (NULL == inq_resp) {
@@ -596,7 +596,7 @@ sg_simple_inquiry_pt(struct sg_pt_base * ptvp,
if (inq_data && (0 == ret)) {
inq_data->peripheral_qualifier = (inq_resp[0] >> 5) & 0x7;
- inq_data->peripheral_type = inq_resp[0] & 0x1f;
+ inq_data->peripheral_type = inq_resp[0] & PDT_MASK;
inq_data->byte_1 = inq_resp[1];
inq_data->version = inq_resp[2];
inq_data->byte_3 = inq_resp[3];
diff --git a/lib/sg_cmds_basic2.c b/lib/sg_cmds_basic2.c
index 7772aa45..1239bfe5 100644
--- a/lib/sg_cmds_basic2.c
+++ b/lib/sg_cmds_basic2.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999-2021 Douglas Gilbert.
+ * Copyright (c) 1999-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.
@@ -101,7 +101,7 @@ sg_ll_sync_cache_10(int sg_fd, bool sync_nv, bool immed, int group,
if (immed)
sc_cdb[1] |= 2;
sg_put_unaligned_be32((uint32_t)lba, sc_cdb + 2);
- sc_cdb[6] = group & 0x1f;
+ sc_cdb[6] = group & GRPNUM_MASK;
if (count > 0xffff) {
pr2ws("count too big\n");
return -1;
diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c
index bacb0338..cb42b32c 100644
--- a/lib/sg_cmds_extra.c
+++ b/lib/sg_cmds_extra.c
@@ -1718,7 +1718,7 @@ sg_ll_verify16(int sg_fd, int vrprotect, bool dpo, int bytchk, uint64_t llba,
v_cdb[1] |= 0x10;
sg_put_unaligned_be64(llba, v_cdb + 2);
sg_put_unaligned_be32((uint32_t)veri_len, v_cdb + 10);
- v_cdb[14] = group_num & 0x1f;
+ v_cdb[14] = group_num & GRPNUM_MASK;
if (vb > 1) {
char b[128];
@@ -2191,7 +2191,7 @@ sg_ll_unmap_v2(int sg_fd, bool anchor, int group_num, int timeout_secs,
if (anchor)
u_cdb[1] |= 0x1;
tmout = (timeout_secs > 0) ? timeout_secs : DEF_PT_TIMEOUT;
- u_cdb[6] = group_num & 0x1f;
+ u_cdb[6] = group_num & GRPNUM_MASK;
sg_put_unaligned_be16((uint16_t)param_len, u_cdb + 7);
if (vb) {
char b[128];
@@ -2443,7 +2443,7 @@ sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num,
case 0x11: /* WRITE USING TOKEN (SBC-3) */
sg_put_unaligned_be32((uint32_t)list_id, xcopy_cdb + 6);
sg_put_unaligned_be32((uint32_t)param_len, xcopy_cdb + 10);
- xcopy_cdb[14] = (uint8_t)(group_num & 0x1f);
+ xcopy_cdb[14] = (uint8_t)(group_num & GRPNUM_MASK);
break;
case 0x1c: /* COPY OPERATION ABORT */
sg_put_unaligned_be32((uint32_t)list_id, xcopy_cdb + 2);
@@ -2545,7 +2545,7 @@ sg_ll_pre_fetch_x(int sg_fd, bool do_seek10, bool cdb16, bool immed,
preFetchCdb[1] = 0x2;
sg_put_unaligned_be64(lba, preFetchCdb + 2);
sg_put_unaligned_be32(num_blocks, preFetchCdb + 10);
- preFetchCdb[14] = 0x3f & group_num;
+ preFetchCdb[14] = GRPNUM_MASK & group_num;
} else {
preFetchCdb[0] = PRE_FETCH10_CMD;
cdb_len = PRE_FETCH10_CMDLEN;
@@ -2553,7 +2553,7 @@ sg_ll_pre_fetch_x(int sg_fd, bool do_seek10, bool cdb16, bool immed,
if (immed)
preFetchCdb[1] = 0x2;
sg_put_unaligned_be32((uint32_t)lba, preFetchCdb + 2);
- preFetchCdb[6] = 0x3f & group_num;
+ preFetchCdb[6] = GRPNUM_MASK & group_num;
sg_put_unaligned_be16((uint16_t)num_blocks, preFetchCdb + 7);
}
}
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index c8a0ffaf..f7029cad 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -586,7 +586,7 @@ sg_get_sense_progress_fld(const uint8_t * sbp, int sb_len,
char *
sg_get_pdt_str(int pdt, int buff_len, char * buff)
{
- if ((pdt < 0) || (pdt > 31))
+ if ((pdt < 0) || (pdt > PDT_MAX))
sg_scnpr(buff, buff_len, "bad pdt");
else
sg_scnpr(buff, buff_len, "%s", sg_lib_pdt_strs[pdt]);
@@ -623,7 +623,7 @@ sg_pdt_s_eq(int l_pdt_s, int r_pdt_s)
int
sg_lib_pdt_decay(int pdt)
{
- if ((pdt < 0) || (pdt > 31))
+ if ((pdt < 0) || (pdt > PDT_MAX))
return 0;
return sg_lib_pdt_decay_arr[pdt];
}
@@ -2329,33 +2329,34 @@ sg_get_command_name(const uint8_t * cdbp, int peri_type, int buff_len,
struct op_code2sa_t {
int op_code;
- int pdt_match; /* -1->all; 0->disk,ZBC,RCB, 1->tape+adc+smc */
+ int pdt_s;
struct sg_lib_value_name_t * arr;
const char * prefix;
};
static struct op_code2sa_t op_code2sa_arr[] = {
- {SG_VARIABLE_LENGTH_CMD, -1, sg_lib_variable_length_arr, NULL},
- {SG_MAINTENANCE_IN, -1, sg_lib_maint_in_arr, NULL},
- {SG_MAINTENANCE_OUT, -1, sg_lib_maint_out_arr, NULL},
- {SG_SERVICE_ACTION_IN_12, -1, sg_lib_serv_in12_arr, NULL},
- {SG_SERVICE_ACTION_OUT_12, -1, sg_lib_serv_out12_arr, NULL},
- {SG_SERVICE_ACTION_IN_16, -1, sg_lib_serv_in16_arr, NULL},
- {SG_SERVICE_ACTION_OUT_16, -1, sg_lib_serv_out16_arr, NULL},
- {SG_SERVICE_ACTION_BIDI, -1, sg_lib_serv_bidi_arr, NULL},
- {SG_PERSISTENT_RESERVE_IN, -1, sg_lib_pr_in_arr, "Persistent reserve in"},
- {SG_PERSISTENT_RESERVE_OUT, -1, sg_lib_pr_out_arr,
+ {SG_VARIABLE_LENGTH_CMD, PDT_ALL, sg_lib_variable_length_arr, NULL},
+ {SG_MAINTENANCE_IN, PDT_ALL, sg_lib_maint_in_arr, NULL},
+ {SG_MAINTENANCE_OUT, PDT_ALL, sg_lib_maint_out_arr, NULL},
+ {SG_SERVICE_ACTION_IN_12, PDT_ALL, sg_lib_serv_in12_arr, NULL},
+ {SG_SERVICE_ACTION_OUT_12, PDT_ALL, sg_lib_serv_out12_arr, NULL},
+ {SG_SERVICE_ACTION_IN_16, PDT_ALL, sg_lib_serv_in16_arr, NULL},
+ {SG_SERVICE_ACTION_OUT_16, PDT_ALL, sg_lib_serv_out16_arr, NULL},
+ {SG_SERVICE_ACTION_BIDI, PDT_ALL, sg_lib_serv_bidi_arr, NULL},
+ {SG_PERSISTENT_RESERVE_IN, PDT_ALL, sg_lib_pr_in_arr,
+ "Persistent reserve in"},
+ {SG_PERSISTENT_RESERVE_OUT, PDT_ALL, sg_lib_pr_out_arr,
"Persistent reserve out"},
- {SG_3PARTY_COPY_OUT, -1, sg_lib_xcopy_sa_arr, NULL},
- {SG_3PARTY_COPY_IN, -1, sg_lib_rec_copy_sa_arr, NULL},
- {SG_READ_BUFFER, -1, sg_lib_read_buff_arr, "Read buffer(10)"},
- {SG_READ_BUFFER_16, -1, sg_lib_read_buff_arr, "Read buffer(16)"},
- {SG_READ_ATTRIBUTE, -1, sg_lib_read_attr_arr, "Read attribute"},
- {SG_READ_POSITION, 1, sg_lib_read_pos_arr, "Read position"},
- {SG_SANITIZE, 0, sg_lib_sanitize_sa_arr, "Sanitize"},
- {SG_WRITE_BUFFER, -1, sg_lib_write_buff_arr, "Write buffer"},
- {SG_ZONING_IN, 0, sg_lib_zoning_in_arr, NULL},
- {SG_ZONING_OUT, 0, sg_lib_zoning_out_arr, NULL},
+ {SG_3PARTY_COPY_OUT, PDT_ALL, sg_lib_xcopy_sa_arr, NULL},
+ {SG_3PARTY_COPY_IN, PDT_ALL, sg_lib_rec_copy_sa_arr, NULL},
+ {SG_READ_BUFFER, PDT_ALL, sg_lib_read_buff_arr, "Read buffer(10)"},
+ {SG_READ_BUFFER_16, PDT_ALL, sg_lib_read_buff_arr, "Read buffer(16)"},
+ {SG_READ_ATTRIBUTE, PDT_ALL, sg_lib_read_attr_arr, "Read attribute"},
+ {SG_READ_POSITION, PDT_TAPE, sg_lib_read_pos_arr, "Read position"},
+ {SG_SANITIZE, PDT_DISK_ZBC, sg_lib_sanitize_sa_arr, "Sanitize"},
+ {SG_WRITE_BUFFER, PDT_ALL, sg_lib_write_buff_arr, "Write buffer"},
+ {SG_ZONING_IN, PDT_DISK_ZBC, sg_lib_zoning_in_arr, NULL},
+ {SG_ZONING_OUT, PDT_DISK_ZBC, sg_lib_zoning_out_arr, NULL},
{0xffff, -1, NULL, NULL},
};
@@ -2380,7 +2381,7 @@ sg_get_opcode_sa_name(uint8_t cmd_byte0, int service_action,
d_pdt = sg_lib_pdt_decay(peri_type);
for (osp = op_code2sa_arr; osp->arr; ++osp) {
if ((int)cmd_byte0 == osp->op_code) {
- if ((osp->pdt_match < 0) || (d_pdt == osp->pdt_match)) {
+ if (sg_pdt_s_eq(osp->pdt_s, d_pdt)) {
vnp = get_value_name(osp->arr, service_action, peri_type);
if (vnp) {
if (osp->prefix)
@@ -2562,7 +2563,7 @@ sg_get_sfs_str(uint16_t sfs_code, int peri_type, int buff_len, char * buff,
*foundp = false;
return NULL;
}
- my_pdt = ((peri_type < -1) || (peri_type > 0x1f)) ? -2 : peri_type;
+ my_pdt = ((peri_type < -1) || (peri_type > PDT_MAX)) ? -2 : peri_type;
vnp = get_value_name(sg_lib_scsi_feature_sets, sfs_code, my_pdt);
if (vnp && (-2 != my_pdt)) {
if (! sg_pdt_s_eq(my_pdt, vnp->peri_dev_type))
@@ -2866,7 +2867,6 @@ dStrHexFp(const char* str, int len, int no_ascii, FILE * fp)
int bpos = bpstart;
int i, k, blen;
-fprintf(stderr, "%s: no_ascii=%d\n", __func__, no_ascii);
if (len <= 0)
return;
blen = (int)sizeof(buff);
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index 847b5791..15798fe3 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.85 20220126";
+const char * sg_lib_version_str = "2.85 20220127";
/* spc6r06, sbc5r01, zbc2r12 */
@@ -116,10 +116,10 @@ struct sg_lib_value_name_t sg_lib_normal_opcodes[] = {
{0x34, PDT_TAPE, "Read position"},
{0x35, PDT_ALL, "Synchronize cache(10)"},
/* SBC-3 r31 recommends Synchronize cache(16) */
- {0x36, 0, "Lock unlock cache(10)"},
- {0x37, 0, "Read defect data(10)"},
- /* SBC-3 r31 recommends Read defect data(12) */
+ {0x36, PDT_ALL, "Lock unlock cache(10)"},
{0x37, PDT_MCHANGER, "Initialize element status with range"},
+ {0x37, PDT_ALL, "Read defect data(10)"},
+ /* SBC-3 r31 recommends Read defect data(12) */
{0x38, PDT_DISK_ZBC, "Format with preset scan"},
{0x38, PDT_OCRW, "Medium scan"},
{0x39, PDT_ALL, "Compare"}, /* obsolete in SPC-4 r11 */
diff --git a/lib/sg_pt_common.c b/lib/sg_pt_common.c
index 345aec39..9af5020a 100644
--- a/lib/sg_pt_common.c
+++ b/lib/sg_pt_common.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009-2021 Douglas Gilbert.
+ * Copyright (c) 2009-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.
@@ -31,7 +31,7 @@
#include "sg_pt_nvme.h"
#endif
-static const char * scsi_pt_version_str = "3.18 20210617";
+static const char * scsi_pt_version_str = "3.19 20220127";
/* List of external functions that need to be defined for each OS are
* listed at the top of sg_pt_dummy.c */
@@ -413,7 +413,7 @@ sntl_resp_mode_sense10(const struct sg_sntl_dev_state_t * dsp,
pcode = cdbp[2] & 0x3f;
subpcode = cdbp[3];
llbaa = !!(cdbp[1] & 0x10);
- is_disk = ((dsp->pdt == PDT_DISK) || (dsp->pdt == PDT_ZBC));
+ is_disk = sg_pdt_s_eq(sg_lib_pdt_decay(dsp->pdt), PDT_DISK_ZBC);
if (is_disk && !dbd)
bd_len = llbaa ? 16 : 8;
else
diff --git a/lib/sg_pt_freebsd.c b/lib/sg_pt_freebsd.c
index 645d9bef..c18fe6a7 100644
--- a/lib/sg_pt_freebsd.c
+++ b/lib/sg_pt_freebsd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005-2021 Douglas Gilbert.
+ * Copyright (c) 2005-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.
@@ -7,7 +7,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-/* sg_pt_freebsd version 1.46 20210912 */
+/* sg_pt_freebsd version 1.47 20220127 */
#include <stdio.h>
#include <stdlib.h>
@@ -1852,7 +1852,7 @@ sntl_inq(struct sg_pt_freebsd_scsi * ptp, const uint8_t * cdbp, int time_secs,
}
} else { /* Standard INQUIRY response */
/* pdt=0 --> disk; pdt=0xd --> SES; pdt=3 --> processor (safte) */
- inq_dout[0] = (0x1f & fdc_p->dev_stat.pdt); /* (PQ=0)<<5 */
+ inq_dout[0] = (PDT_MASK & fdc_p->dev_stat.pdt); /* (PQ=0)<<5 */
/* inq_dout[1] = (RMD=0)<<7 | (LU_CONG=0)<<6; rest reserved */
inq_dout[2] = 6; /* version: SPC-4 */
inq_dout[3] = 2; /* NORMACA=0, HISUP=0, response data format: 2 */
diff --git a/lib/sg_pt_win32.c b/lib/sg_pt_win32.c
index dab66cb0..170e33c3 100644
--- a/lib/sg_pt_win32.c
+++ b/lib/sg_pt_win32.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2021 Douglas Gilbert.
+ * Copyright (c) 2006-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.
@@ -133,7 +133,7 @@ struct sg_pt_handle {
int bus; /* a.k.a. PathId in MS docs */
int target;
int lun;
- int scsi_pdt; /* Peripheral Device Type, -1 if not known */
+ int scsi_pdt; /* Peripheral Device Type, PDT_ALL if not known */
// uint32_t nvme_nsid; /* how do we find this given file handle ?? */
int verbose; /* tunnel verbose through to scsi_pt_close_device */
char dname[20];
@@ -436,7 +436,7 @@ scsi_pt_open_flags(const char * device_name, int flags, int vb)
shp->bus = bus;
shp->target = target;
shp->lun = lun;
- shp->scsi_pdt = -1;
+ shp->scsi_pdt = PDT_ALL;
shp->verbose = vb;
memset(shp->adapter, 0, sizeof(shp->adapter));
memcpy(shp->adapter, "\\\\.\\", 4);
@@ -548,7 +548,7 @@ get_scsi_pdt(struct sg_pt_handle *shp, int vb)
if ((shp->bus == pid->PathId) &&
(shp->target == pid->TargetId) &&
(shp->lun == pid->Lun)) { /* got match */
- shp->scsi_pdt = pid->InquiryData[0] & 0x3f;
+ shp->scsi_pdt = pid->InquiryData[0] & PDT_MASK;
shp->not_claimed = ! pid->DeviceClaimed;
shp->checked_handle = true;
shp->bus_type_failed = false;
@@ -2443,7 +2443,7 @@ sntl_inq(struct sg_pt_win32_scsi * psp, struct sg_pt_handle * shp,
}
} else { /* Standard INQUIRY response */
/* pdt=0 --> disk; pdt=0xd --> SES; pdt=3 --> processor (safte) */
- inq_dout[0] = (0x1f & shp->dev_stat.pdt); /* (PQ=0)<<5 */
+ inq_dout[0] = (PDT_MASK & shp->dev_stat.pdt); /* (PQ=0)<<5 */
/* inq_dout[1] = (RMD=0)<<7 | (LU_CONG=0)<<6; rest reserved */
inq_dout[2] = 6; /* version: SPC-4 */
inq_dout[3] = 2; /* NORMACA=0, HISUP=0, response data format: 2 */
diff --git a/src/sg_compare_and_write.c b/src/sg_compare_and_write.c
index 0a307003..89bb18b8 100644
--- a/src/sg_compare_and_write.c
+++ b/src/sg_compare_and_write.c
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2012-2021, Kaminario Technologies LTD
+* Copyright (c) 2012-2022, Kaminario Technologies LTD
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -56,7 +56,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.31 20211114";
+static const char * version_str = "1.32 20220127";
#define DEF_BLOCK_SIZE 512
#define DEF_NUM_BLOCKS (1)
@@ -339,7 +339,7 @@ sg_build_scsi_cdb(uint8_t * cdbp, unsigned int blocks,
sg_put_unaligned_be64((uint64_t)start_block, cdbp + 2);
/* cdbp[10-12] are reserved */
cdbp[13] = (uint8_t)(blocks & 0xff);
- cdbp[14] = (uint8_t)(flags.group & 0x1f);
+ cdbp[14] = (uint8_t)(flags.group & GRPNUM_MASK);
return 0;
}
diff --git a/src/sg_format.c b/src/sg_format.c
index b6620ab2..19d1203a 100644
--- a/src/sg_format.c
+++ b/src/sg_format.c
@@ -6,7 +6,7 @@
*
* Copyright (C) 2003 Grant Grundler grundler at parisc-linux dot org
* Copyright (C) 2003 James Bottomley jejb at parisc-linux dot org
- * Copyright (C) 2005-2021 Douglas Gilbert dgilbert at interlog dot com
+ * Copyright (C) 2005-2022 Douglas Gilbert dgilbert at interlog dot com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
#include "sg_pr2serr.h"
#include "sg_pt.h"
-static const char * version_str = "1.64 20211114";
+static const char * version_str = "1.65 20220127";
#define RW_ERROR_RECOVERY_PAGE 1 /* can give alternate with --mode=MP */
@@ -909,7 +909,7 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen,
n = SAFE_STD_INQ_RESP_LEN;
memcpy(sinq_resp, b, (n < max_rlen) ? n : max_rlen);
if (n == SAFE_STD_INQ_RESP_LEN) {
- pdt = b[0] & 0x1f;
+ pdt = b[0] & PDT_MASK;
printf(" %.8s %.16s %.4s peripheral_type: %s [0x%x]\n",
(const char *)(b + 8), (const char *)(b + 16),
(const char *)(b + 32),
@@ -1586,7 +1586,7 @@ main(int argc, char **argv)
} else
goto out;
} else
- pdt = 0x1f & inq_resp[0];
+ pdt = PDT_MASK & inq_resp[0];
if (op->format) {
if ((PDT_DISK != pdt) && (PDT_OPTICAL != pdt) &&
(PDT_RBC != pdt)) {
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 7540797e..38b033b6 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -1067,7 +1067,7 @@ decode_supported_vpd(uint8_t * buff, int len, int do_hex)
pr2serr("Supported VPD pages VPD page length too short=%d\n", len);
return;
}
- pdt = 0x1f & buff[0];
+ pdt = PDT_MASK & buff[0];
rlen = buff[3] + 4;
if (rlen > len)
pr2serr("Supported VPD pages VPD page truncated, indicates %d, got "
@@ -2187,7 +2187,7 @@ decode_b0_vpd(uint8_t * buff, int len, int do_hex)
hex2stdout(buff, len, (1 == do_hex) ? 0 : -1);
return;
}
- pdt = 0x1f & buff[0];
+ pdt = PDT_MASK & buff[0];
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL:
if (len < 16) {
@@ -2333,7 +2333,7 @@ decode_b1_vpd(uint8_t * buff, int len, int do_hex)
hex2stdout(buff, len, (1 == do_hex) ? 0 : -1);
return;
}
- pdt = 0x1f & buff[0];
+ pdt = PDT_MASK & buff[0];
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL:
if (len < 64) {
@@ -2408,7 +2408,7 @@ decode_b3_vpd(uint8_t * buff, int len, int do_hex)
hex2stdout(buff, len, (1 == do_hex) ? 0 : -1);
return;
}
- pdt = 0x1f & buff[0];
+ pdt = PDT_MASK & buff[0];
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL:
if (len < 0x10) {
@@ -2811,7 +2811,7 @@ std_inq_decode(const struct opts_t * op, int act_len)
* [spc-r11a (1997)] bits 6,7: ISO/IEC version; bits 3-5: ECMA
* version; bits 0-2: SCSI version */
ansi_version = rp[2] & 0x7; /* Only take SCSI version */
- peri_type = rp[0] & 0x1f;
+ peri_type = rp[0] & PDT_MASK;
if (op->do_export) {
printf("SCSI_TPGS=%d\n", (rp[5] & 0x30) >> 4);
cp = sg_get_pdt_str(peri_type, sizeof(buff), buff);
@@ -3194,7 +3194,7 @@ cmddt_process(int sg_fd, const struct opts_t * op)
res = sg_ll_inquiry(sg_fd, true /* cmddt */, false, k, rsp_buff,
DEF_ALLOC_LEN, true, op->verbose);
if (0 == res) {
- peri_type = rsp_buff[0] & 0x1f;
+ peri_type = rsp_buff[0] & PDT_MASK;
support_num = rsp_buff[1] & 7;
reserved_cmddt = rsp_buff[4];
if ((3 == support_num) || (5 == support_num)) {
@@ -3227,7 +3227,7 @@ cmddt_process(int sg_fd, const struct opts_t * op)
res = sg_ll_inquiry(sg_fd, true /* cmddt */, false, op->page_num,
rsp_buff, DEF_ALLOC_LEN, true, op->verbose);
if (0 == res) {
- peri_type = rsp_buff[0] & 0x1f;
+ peri_type = rsp_buff[0] & PDT_MASK;
if (! op->do_raw) {
printf("CmdDt INQUIRY, opcode=0x%.2x: [", op->page_num);
sg_get_opcode_name((uint8_t)op->page_num, peri_type,
@@ -3335,7 +3335,7 @@ vpd_mainly_hex(int sg_fd, const struct opts_t * op, int inhex_len)
decode_supported_vpd(rp, len, op->do_hex);
else {
if (op->verbose) {
- cp = sg_get_pdt_str(rp[0] & 0x1f, sizeof(b), b);
+ cp = sg_get_pdt_str(rp[0] & PDT_MASK, sizeof(b), b);
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5, cp);
}
@@ -3395,7 +3395,7 @@ vpd_decode(int sg_fd, const struct opts_t * op, int inhex_len)
else if (op->do_hex)
hex2stdout(rp, len, (1 == op->do_hex) ? 0 : -1);
else
- decode_supported_vpd(rp, len, 0x1f & rp[0]);
+ decode_supported_vpd(rp, len, PDT_MASK & rp[0]);
break;
case VPD_UNIT_SERIAL_NUM:
if (! op->do_raw && ! op->do_export && (op->do_hex < 2))
@@ -3538,7 +3538,7 @@ vpd_decode(int sg_fd, const struct opts_t * op, int inhex_len)
case 0xb0: /* VPD pages in B0h to BFh range depend on pdt */
res = vpd_fetch_page_from_dev(sg_fd, rp, pn, mxlen, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (! op->do_raw && (op->do_hex < 2)) {
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL:
@@ -3566,7 +3566,7 @@ vpd_decode(int sg_fd, const struct opts_t * op, int inhex_len)
case 0xb1: /* VPD pages in B0h to BFh range depend on pdt */
res = vpd_fetch_page_from_dev(sg_fd, rp, pn, mxlen, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (! op->do_raw && (op->do_hex < 2)) {
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL:
@@ -3604,7 +3604,7 @@ vpd_decode(int sg_fd, const struct opts_t * op, int inhex_len)
case 0xb3: /* VPD pages in B0h to BFh range depend on pdt */
res = vpd_fetch_page_from_dev(sg_fd, rp, pn, mxlen, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (! op->do_raw && (op->do_hex < 2)) {
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL:
@@ -4230,7 +4230,7 @@ main(int argc, char * argv[])
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];
+ op->page_pdt = PDT_MASK & rsp_buff[0];
if ((0x2 == (0xf & rsp_buff[3])) && (rsp_buff[2] > 2)) {
if (op->verbose)
pr2serr("Guessing from --inhex= this is a standard "
diff --git a/src/sg_logs.c b/src/sg_logs.c
index de5d339e..26e1b477 100644
--- a/src/sg_logs.c
+++ b/src/sg_logs.c
@@ -36,7 +36,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.92 20220114"; /* spc6r06 + sbc5r01 */
+static const char * version_str = "1.93 20220127"; /* spc6r06 + sbc5r01 */
#define MX_ALLOC_LEN (0xfffc)
#define SHORT_RESP_LEN 128
@@ -5046,6 +5046,7 @@ static bool
show_zoned_block_dev_stats(const uint8_t * resp, int len,
const struct opts_t * op)
{
+ bool trunc, bad_pl;
int num, pl, pc;
const uint8_t * bp;
char str[PCB_STR_LEN];
@@ -5055,8 +5056,12 @@ show_zoned_block_dev_stats(const uint8_t * resp, int len,
num = len - 4;
bp = &resp[0] + 4;
while (num > 3) {
+ trunc = false;
+ bad_pl = false;
pc = sg_get_unaligned_be16(bp + 0);
pl = bp[3] + 4;
+ if (4 == pl) /* DC HC560 has empty descriptors */
+ goto skip;
if (op->filter_given) {
if (pc != op->filter)
goto skip;
@@ -5070,166 +5075,135 @@ show_zoned_block_dev_stats(const uint8_t * resp, int len,
}
switch (pc) {
case 0x0:
- printf(" Maximum open zones:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Maximum open zones: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x1:
- printf(" Maximum explicitly open zones:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Maximum explicitly open zones: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x2:
- printf(" Maximum implicitly open zones:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Maximum implicitly open zones: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x3:
- printf(" Minimum empty zones:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Minimum empty zones: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x4:
- printf(" Maximum non-sequential zones:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Maximum non-sequential zones: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x5:
- printf(" Zones emptied:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Zones emptied: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x6:
- printf(" Suboptimal write commands:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Suboptimal write commands: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x7:
- printf(" Commands exceeding optimal limit:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Commands exceeding optimal limit: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x8:
- printf(" Failed explicit opens:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Failed explicit opens: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0x9:
- printf(" Read rule violations:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Read rule violations: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0xa:
- printf(" Write rule violations:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Write rule violations: %" PRIu32 "\n",
+ sg_get_unaligned_be32(bp + 8));
break;
case 0xb: /* added zbc2r04 */
- printf(" Maximum implicitly open or before required zones:");
if ((pl < 8) || (num < 8)) {
if (num < 8)
- pr2serr("\n truncated by response length, expected "
- "at least 8 bytes\n");
+ trunc = true;
else
- pr2serr("\n parameter length >= 8 expected, got %d\n",
- pl);
- break;
- }
- printf(" %" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
+ bad_pl = true;
+ } else
+ printf(" Maximum implicitly open or before required zones: "
+ "%" PRIu32 "\n", sg_get_unaligned_be32(bp + 8));
break;
default:
printf(" Reserved [parameter_code=0x%x]:\n", pc);
hex2stdout(bp, ((pl < num) ? pl : num), 0);
break;
}
+ if (trunc)
+ pr2serr(" truncated by response length, expected at least "
+ "8 bytes\n");
+ if (bad_pl)
+ pr2serr(" parameter length >= 8 expected, got %d\n", pl);
if (op->do_pcb)
printf(" <%s>\n", get_pcb_str(bp[2], str, sizeof(str)));
if (op->filter_given)
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index 54b90723..944a3e76 100644
--- a/src/sg_opcodes.c
+++ b/src/sg_opcodes.c
@@ -1,5 +1,5 @@
/* A utility program originally written for the Linux OS SCSI subsystem.
- * Copyright (C) 2004-2021 D. Gilbert
+ * Copyright (C) 2004-2022 D. Gilbert
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
@@ -33,7 +33,7 @@
#include "sg_pt.h"
-static const char * version_str = "0.72 20211221"; /* spc6r05 */
+static const char * version_str = "0.73 20220127"; /* spc6r06 */
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
@@ -393,7 +393,7 @@ new_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
n = sg_get_num(optarg);
else if ((2 == strlen(optarg)) && (0 == strcmp("-1", optarg)))
n = -1;
- if ((n < -1) || (n > 0x1f)) {
+ if ((n < -1) || (n > PDT_MAX)) {
pr2serr("bad argument to '--pdt=DT', expect -1 to 31\n");
return SG_LIB_SYNTAX_ERROR;
}
@@ -539,7 +539,7 @@ old_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
op->opcode = n;
} else if (0 == strncmp("p=", cp, 2)) {
num = sscanf(cp + 2, "%d", &n);
- if ((1 != num) || (n > 0x1f) || (n < -1)) {
+ if ((1 != num) || (n > PDT_MAX) || (n < -1)) {
pr2serr("Bad number after 'p=' option, expect -1 to "
"31\n");
return SG_LIB_SYNTAX_ERROR;
diff --git a/src/sg_rep_zones.c b/src/sg_rep_zones.c
index 2e719e75..02c8953c 100644
--- a/src/sg_rep_zones.c
+++ b/src/sg_rep_zones.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2021 Douglas Gilbert.
+ * Copyright (c) 2014-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.
@@ -39,8 +39,9 @@
* Based on zbc2r10.pdf
*/
-static const char * version_str = "1.29 20211117";
+static const char * version_str = "1.30 20220128";
+#define WILD_RZONES_BUFF_LEN (1 << 28)
#define MAX_RZONES_BUFF_LEN (1024 * 1024)
#define DEF_RZONES_BUFF_LEN (1024 * 8)
@@ -54,6 +55,7 @@ static const char * version_str = "1.29 20211117";
#define DEF_PT_TIMEOUT 60 /* 60 seconds */
struct opts_t {
+ bool do_brief;
bool do_force;
bool do_partial;
bool do_raw;
@@ -76,6 +78,7 @@ struct opts_t {
static struct option long_options[] = {
+ {"brief", no_argument, 0, 'b'}, /* only header and last descriptor */
{"domain", no_argument, 0, 'd'},
{"domains", no_argument, 0, 'd'},
{"force", no_argument, 0, 'f'},
@@ -108,10 +111,11 @@ usage(int h)
"sg_rep_zones [--domain] [--force] [--help] [--hex] "
"[--inhex=FN]\n"
" [--locator=LBA] [--maxlen=LEN] "
- "[--partial] [--raw]\n"
- " [--readonly] [--realm] [--report=OPT] "
- "[--start=LBA]\n"
- " [--verbose] [--version] DEVICE\n");
+ "[--partial] [--only]\n"
+ " [--raw] [--readonly] [--realm] "
+ "[--report=OPT]\n"
+ " [--start=LBA] [--verbose] [--version] "
+ "DEVICE\n");
pr2serr(" where:\n"
" --domain|-d sends a REPORT ZONE DOMAINS command\n"
" --force|-f bypass some sanity checks when decoding "
@@ -128,6 +132,8 @@ usage(int h)
" (def: 0 -> 8192 bytes)\n"
" --num=NUM|-n NUM number of zones to output (def: 0 -> "
"all)\n"
+ " --only|-o output header and starting LBA of "
+ "next\n"
" --partial|-p sets PARTIAL bit in cdb (def: 0 -> "
"zone list\n"
" length not altered by allocation length "
@@ -317,7 +323,7 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
{
uint8_t zt;
int k, same, zc, num_zd;
- uint64_t wp;
+ uint64_t wp, ul, ul2, mx_lba;
const uint8_t * bp;
char b[80];
@@ -334,10 +340,10 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
} else
num_zd = (decod_len - 64) / 64;
same = rzBuff[4] & 0xf;
+ mx_lba = sg_get_unaligned_be64(rzBuff + 8);
if (! op->wp_only) {
printf(" Same=%d: %s\n", same, same_desc_arr[same]);
- printf(" Maximum LBA: 0x%" PRIx64 "\n\n",
- sg_get_unaligned_be64(rzBuff + 8));
+ printf(" Maximum LBA: 0x%" PRIx64 "\n\n", mx_lba);
printf(" Reported zone starting LBA granularity: 0x%" PRIx64 "\n\n",
sg_get_unaligned_be64(rzBuff + 16)); /* zbc2r12 */
}
@@ -348,6 +354,20 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
"value less than %d\n", num_zd);
return SG_LIB_CAT_MALFORMED;
}
+ if (op->do_brief && (num_zd > 0)) {
+ bp = rzBuff + 64 + ((num_zd - 1) * 64);
+ printf("From last descriptor in this response:\n");
+ ul = sg_get_unaligned_be64(bp + 16);
+ printf(" Zone start LBA: 0x%" PRIx64 "\n", ul);
+ ul2 = sg_get_unaligned_be64(bp + 8);
+ printf(" Zone Length: 0x%" PRIx64 "\n", ul2);
+ ul = ul + ul2;
+ if (ul > mx_lba)
+ printf(" This zone seems to be the last one\n");
+ else
+ printf(" Probable next Zone start LBA: 0x%" PRIx64 "\n", ul);
+ return 0;
+ }
for (k = 0, bp = rzBuff + 64; k < num_zd; ++k, bp += 64) {
if (! op->wp_only)
printf(" Zone descriptor: %d\n", k);
@@ -356,7 +376,11 @@ decode_rep_zones(const uint8_t * rzBuff, int act_len, uint32_t decod_len,
continue;
}
if (op->wp_only) {
- printf("0x%" PRIx64 "\n", sg_get_unaligned_be64(bp + 24));
+ wp = sg_get_unaligned_be64(bp + 24);
+ if (sg_all_ffs((const uint8_t *)&wp, sizeof(wp)))
+ printf("-1\n");
+ else
+ printf("0x%" PRIx64 "\n", wp);
continue;
}
zt = bp[0] & 0xf;
@@ -531,12 +555,15 @@ main(int argc, char * argv[])
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "defhHi:l:m:n:o:prRs:vVw", long_options,
+ c = getopt_long(argc, argv, "bdefhHi:l:m:n:o:prRs:vVw", long_options,
&option_index);
if (c == -1)
break;
switch (c) {
+ case 'b':
+ op->do_brief = true;
+ break;
case 'd':
op->do_zdomains = true;
serv_act = REPORT_ZONE_DOMAINS_SA;
@@ -744,7 +771,7 @@ start_response:
goto the_end;
}
decod_len = sg_get_unaligned_be32(rzBuff + 0) + 64;
- if (decod_len > MAX_RZONES_BUFF_LEN) {
+ if (decod_len > WILD_RZONES_BUFF_LEN) {
if (! op->do_force) {
pr2serr("decode length [%u bytes] seems wild, use --force "
"override\n", decod_len);
@@ -753,8 +780,9 @@ start_response:
}
if (decod_len > (uint32_t)rlen) {
if ((REPORT_ZONES_SA == serv_act) && (! op->do_partial)) {
- printf("%u zones available but only %d zones returned\n",
- (decod_len - 64) / 64, (rlen - 64) / 64);
+ printf("%u zones starting from LBA 0x%" PRIx64 " available "
+ "but only %d zones returned\n",
+ (decod_len - 64) / 64, op->st_lba, (rlen - 64) / 64);
decod_len = rlen;
act_len = rlen;
} else {
diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c
index ade9be71..147898fe 100644
--- a/src/sg_sanitize.c
+++ b/src/sg_sanitize.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2021 Douglas Gilbert.
+ * Copyright (c) 2011-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.
@@ -33,7 +33,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.17 20211114";
+static const char * version_str = "1.18 20220127";
/* Not all environments support the Unix sleep() */
#if defined(MSC_VER) || defined(__MINGW32__)
@@ -368,7 +368,7 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, int verbose)
n = SAFE_STD_INQ_RESP_LEN;
memcpy(sinq_resp, b, (n < max_rlen) ? n : max_rlen);
if (n == SAFE_STD_INQ_RESP_LEN) {
- pdt = b[0] & 0x1f;
+ pdt = b[0] & PDT_MASK;
printf(" %.8s %.16s %.4s peripheral_type: %s [0x%x]\n",
(const char *)(b + 8), (const char *)(b + 16),
(const char *)(b + 32),
diff --git a/src/sg_scan_linux.c b/src/sg_scan_linux.c
index c04206a1..9fa3374a 100644
--- a/src/sg_scan_linux.c
+++ b/src/sg_scan_linux.c
@@ -452,7 +452,7 @@ int sg3_inq(int sg_fd, uint8_t * inqBuff, bool do_extra)
printf(" %.8s %.16s %.4s ", p + 8, p + 16, p + 32);
printf("[rmb=%d cmdq=%d pqual=%d pdev=0x%x] ",
!!(p[1] & 0x80), !!(p[7] & 2), (p[0] & 0xe0) >> 5,
- (p[0] & 0x1f));
+ (p[0] & PDT_MASK));
if (do_extra && sg_io)
printf("dur=%ums\n", io_hdr.duration);
else
diff --git a/src/sg_scan_win32.c b/src/sg_scan_win32.c
index 4ba59836..06851497 100644
--- a/src/sg_scan_win32.c
+++ b/src/sg_scan_win32.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018 Douglas Gilbert.
+ * Copyright (c) 2006-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.
@@ -43,7 +43,7 @@
#include "sg_pt_win32.h"
-static const char * version_str = "1.22 (win32) 20181110";
+static const char * version_str = "1.23 (win32) 20220127";
#define MAX_SCSI_ELEMS 4096
#define MAX_ADAPTER_NUM 256
@@ -366,7 +366,7 @@ enum_scsi_adapters(void)
printf("%-15s", b);
snprintf(b, sizeof(b) - 1, "claimed=%d pdt=%xh %s ",
pid->DeviceClaimed,
- pid->InquiryData[0] % 0x3f,
+ pid->InquiryData[0] % PDT_MASK,
((0 == pid->InquiryData[4]) ? "dubious" :
""));
printf("%-26s", b);
diff --git a/src/sg_ses.c b/src/sg_ses.c
index 9b16134b..aa545a87 100644
--- a/src/sg_ses.c
+++ b/src/sg_ses.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2021 Douglas Gilbert.
+ * Copyright (c) 2004-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.
@@ -38,7 +38,7 @@
* commands tailored for SES (enclosure) devices.
*/
-static const char * version_str = "2.54 20211028"; /* ses4r04 */
+static const char * version_str = "2.55 20220127"; /* ses4r04 */
#define MX_ALLOC_LEN ((64 * 1024) - 4) /* max allowable for big enclosures */
#define MX_ELEM_HDR 1024
@@ -5750,7 +5750,7 @@ main(int argc, char * argv[])
pr2serr("Short INQUIRY response, not looking good\n");
printf(" %.8s %.16s %.4s\n", inq_rsp + 8, inq_rsp + 16,
inq_rsp + 32);
- pd_type = 0x1f & inq_rsp[0];
+ pd_type = PDT_MASK & inq_rsp[0];
cp = sg_get_pdt_str(pd_type, sizeof(buff), buff);
if (0xd == pd_type) {
if (vb)
diff --git a/src/sg_sync.c b/src/sg_sync.c
index 1a8eebfb..a5d6ce8d 100644
--- a/src/sg_sync.c
+++ b/src/sg_sync.c
@@ -109,7 +109,7 @@ sg_ll_sync_cache_16(int sg_fd, bool sync_nv, bool immed, int group,
if (immed)
sc_cdb[1] |= 2;
sg_put_unaligned_be64(lba, sc_cdb + 2);
- sc_cdb[14] = group & 0x1f;
+ sc_cdb[14] = group & GRPNUM_MASK;
sg_put_unaligned_be32((uint32_t)num_lb, sc_cdb + 10);
if (verbose) {
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
index 1a74af52..46b7e603 100644
--- a/src/sg_vpd.c
+++ b/src/sg_vpd.c
@@ -504,7 +504,7 @@ std_inq_decode(uint8_t * b, int len, int verbose)
else
printf(" [reserved or vendor specific qualifier [%d]]\n", pqual);
printf(" PQual=%d PDT=%d RMB=%d LU_CONG=%d hot_pluggable=%d "
- "version=0x%02x ", pqual, b[0] & 0x1f, !!(b[1] & 0x80),
+ "version=0x%02x ", pqual, b[0] & PDT_MASK, !!(b[1] & 0x80),
!!(b[1] & 0x40), (b[1] >> 4) & 0x3, (unsigned int)b[2]);
printf(" [%s]\n", sg_ansi_version_arr[b[2] & 0xf]);
printf(" [AERC=%d] [TrmTsk=%d] NormACA=%d HiSUP=%d "
@@ -1308,8 +1308,8 @@ decode_dev_constit_vpd(const uint8_t * buff, int len, struct opts_t * op)
else if (bp[2] >= 0x20)
printf("Reserved [0x%x]\n", bp[2]);
else
- printf("%s [0x%x]\n", sg_get_pdt_str(0x1f & bp[2], sizeof(b), b),
- bp[2]);
+ printf("%s [0x%x]\n",
+ sg_get_pdt_str(PDT_MASK & bp[2], sizeof(b), b), bp[2]);
printf(" Vendor_identification: %.8s\n", bp + 4);
printf(" Product_identification: %.16s\n", bp + 12);
printf(" Product_revision_level: %.4s\n", bp + 28);
@@ -2562,11 +2562,11 @@ decode_zbdch_vpd(uint8_t * b, int len, int do_hex)
return;
}
printf(" Peripheral device type: %s\n",
- sg_get_pdt_str(0x1f & b[0], sizeof(d), d));
+ sg_get_pdt_str(PDT_MASK & b[0], sizeof(d), d));
printf(" Zoned block device extension: ");
switch ((b[4] >> 4) & 0xf) {
case 0:
- if (PDT_ZBC == (0x1f & b[0]))
+ if (PDT_ZBC == (PDT_MASK & b[0]))
printf("host managed zoned block device [0, pdt=0x14]\n");
else
printf("not reported [0]\n");
@@ -2920,7 +2920,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
else if (op->do_hex)
hex2stdout(rp, len, (1 == op->do_hex) ? 0 : -1);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -2967,7 +2967,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
else if (op->do_hex)
hex2stdout(rp, len, (1 == op->do_hex) ? 0 : -1);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -2995,7 +2995,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
else if (op->do_hex)
hex2stdout(rp, len, (1 == op->do_hex) ? 0 : -1);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3016,7 +3016,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3064,7 +3064,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
} else
protect = !!(sir.byte_5 & 0x1); /* SPC-3 and later */
}
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3085,7 +3085,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3106,7 +3106,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3136,7 +3136,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
else if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3157,7 +3157,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3193,7 +3193,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3216,7 +3216,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
else if (1 == op->do_hex)
hex2stdout(rp, len, 0);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3237,7 +3237,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rsp_buff[0] & 0x1f;
+ pdt = rsp_buff[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3258,7 +3258,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3279,7 +3279,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3292,7 +3292,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb0: /* depends on pdt */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Block limits VPD page (SBC):";
@@ -3314,7 +3314,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3329,7 +3329,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb1: /* depends on pdt */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Block device characteristics VPD page (SBC):";
@@ -3368,7 +3368,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb2: /* VPD page depends on pdt */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Logical block provisioning VPD page (SBC):";
@@ -3401,7 +3401,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb3: /* VPD page depends on pdt */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Referrals VPD page (SBC):";
@@ -3434,7 +3434,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb4: /* VPD page depends on pdt */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Supported block lengths and protection types VPD page "
@@ -3468,7 +3468,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb5: /* VPD page depends on pdt */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Block device characteristics extension VPD page (SBC):";
@@ -3501,7 +3501,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case VPD_ZBC_DEV_CHARS: /* 0xb6 for both pdt=0 and pdt=0x14 */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Zoned block device characteristics VPD page (SBC, "
@@ -3532,7 +3532,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb7:
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Block limits extension VPD page (SBC):";
@@ -3548,7 +3548,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3563,7 +3563,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb8: /* VPD_FORMAT_PRESETS */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Format presets VPD page (SBC):";
@@ -3579,7 +3579,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
@@ -3594,7 +3594,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
case 0xb9: /* VPD_CON_POS_RANGE */
res = vpd_fetch_page(sg_fd, rp, pn, op->maxlen, qt, vb, &len);
if (0 == res) {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
switch (pdt) {
case PDT_DISK: case PDT_WO: case PDT_OPTICAL: case PDT_ZBC:
np = "Concurrent positioning ranges VPD page (SBC):";
@@ -3610,7 +3610,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off,
if (op->do_raw)
dStrRaw(rp, len);
else {
- pdt = rp[0] & 0x1f;
+ pdt = rp[0] & PDT_MASK;
if (vb || long_notquiet)
printf(" [PQual=%d Peripheral device type: %s]\n",
(rp[0] & 0xe0) >> 5,
diff --git a/src/sg_wr_mode.c b/src/sg_wr_mode.c
index 2a10fb7c..b2dff407 100644
--- a/src/sg_wr_mode.c
+++ b/src/sg_wr_mode.c
@@ -502,7 +502,7 @@ main(int argc, char * argv[])
if (0 == sg_simple_inquiry(sg_fd, &inq_data, false, verbose))
pdt = inq_data.peripheral_type;
else
- pdt = 0x1f;
+ pdt = PDT_UNKNOWN;
/* do MODE SENSE to fetch current values */
memset(ref_md, 0, MX_ALLOC_LEN);
diff --git a/src/sg_write_same.c b/src/sg_write_same.c
index e2213fba..011deb99 100644
--- a/src/sg_write_same.c
+++ b/src/sg_write_same.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009-2021 Douglas Gilbert.
+ * Copyright (c) 2009-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.
@@ -33,7 +33,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.33 20211114";
+static const char * version_str = "1.34 20220127";
#define ME "sg_write_same: "
@@ -209,7 +209,7 @@ do_write_same(int sg_fd, const struct opts_t * op, const void * dataoutp,
if (op->lbdata)
ws_cdb[1] |= 0x2;
sg_put_unaligned_be32((uint32_t)op->lba, ws_cdb + 2);
- ws_cdb[6] = (op->grpnum & 0x1f);
+ ws_cdb[6] = (op->grpnum & GRPNUM_MASK);
sg_put_unaligned_be16((uint16_t)op->numblocks, ws_cdb + 7);
break;
case WRITE_SAME16_LEN:
@@ -227,11 +227,11 @@ do_write_same(int sg_fd, const struct opts_t * op, const void * dataoutp,
ws_cdb[1] |= 0x1;
sg_put_unaligned_be64(op->lba, ws_cdb + 2);
sg_put_unaligned_be32((uint32_t)op->numblocks, ws_cdb + 10);
- ws_cdb[14] = (op->grpnum & 0x1f);
+ ws_cdb[14] = (op->grpnum & GRPNUM_MASK);
break;
case WRITE_SAME32_LEN:
ws_cdb[0] = VARIABLE_LEN_OP;
- ws_cdb[6] = (op->grpnum & 0x1f);
+ ws_cdb[6] = (op->grpnum & GRPNUM_MASK);
ws_cdb[7] = WRITE_SAME32_ADD;
sg_put_unaligned_be16((uint16_t)WRITE_SAME32_SA, ws_cdb + 8);
ws_cdb[10] = ((op->wrprotect & 0x7) << 5);
diff --git a/src/sg_write_verify.c b/src/sg_write_verify.c
index 384899b2..e2af4019 100644
--- a/src/sg_write_verify.c
+++ b/src/sg_write_verify.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2021 Douglas Gilbert
+ * Copyright (c) 2014-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.
@@ -40,7 +40,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.20 20211114";
+static const char * version_str = "1.21 20220127";
#define ME "sg_write_verify: "
@@ -215,7 +215,7 @@ sg_ll_write_verify10(int sg_fd, int wrprotect, bool dpo, int bytchk,
wv_cdb[1] |= ((bytchk & 0x3) << 1);
sg_put_unaligned_be32((uint32_t)lba, wv_cdb + 2);
- wv_cdb[6] = group & 0x1f;
+ wv_cdb[6] = group & GRPNUM_MASK;
sg_put_unaligned_be16((uint16_t)num_lb, wv_cdb + 7);
ret = run_scsi_transaction(sg_fd, wv_cdb, sizeof(wv_cdb), dop, do_len,
timeout, noisy, verbose);
@@ -243,7 +243,7 @@ sg_ll_write_verify16(int sg_fd, int wrprotect, bool dpo, int bytchk,
sg_put_unaligned_be64(llba, wv_cdb + 2);
sg_put_unaligned_be32((uint32_t)num_lb, wv_cdb + 10);
- wv_cdb[14] = group & 0x1f;
+ wv_cdb[14] = group & GRPNUM_MASK;
ret = run_scsi_transaction(sg_fd, wv_cdb, sizeof(wv_cdb), dop, do_len,
timeout, noisy, verbose);
return ret;
diff --git a/src/sg_write_x.c b/src/sg_write_x.c
index 18d1e7ec..81ee1a67 100644
--- a/src/sg_write_x.c
+++ b/src/sg_write_x.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 Douglas Gilbert.
+ * Copyright (c) 2017-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.
@@ -38,7 +38,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.29 20211114";
+static const char * version_str = "1.30 20220127";
/* Protection Information refers to 8 bytes of extra information usually
* associated with each logical block and is often abbreviated to PI while
@@ -160,7 +160,7 @@ struct opts_t {
* DLD0, bit 1 --> DLD1, bit 2 --> DLD2
* only WRITE(16) and WRITE SCATTERED(16) */
int dry_run; /* temporary write when used more than once */
- int grpnum; /* "Group Number", 0 to 0x3f */
+ int grpnum; /* "Group Number", 0 to 0x3f (GRPNUM_MASK) */
int help;
int pi_type; /* -1: unknown: 0: type 0 (none): 1: type 1 */
int strict; /* > 0, report then exit on questionable meta data */
@@ -1062,10 +1062,10 @@ do_write_x(int sg_fd, const void * dataoutp, int dout_len,
if (16 == cdb_len) {
if (! op->do_scattered)
sg_put_unaligned_be64(op->lba, x_cdb + 2);
- x_cdb[14] = (op->grpnum & 0x1f);
+ x_cdb[14] = (op->grpnum & GRPNUM_MASK);
} else {
x_cdb[0] = VARIABLE_LEN_OP;
- x_cdb[6] = (op->grpnum & 0x1f);
+ x_cdb[6] = (op->grpnum & GRPNUM_MASK);
x_cdb[7] = WRITE_X_32_ADD;
if (! op->do_scattered)
sg_put_unaligned_be64(op->lba, x_cdb + 12);