diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2022-01-28 20:51:37 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2022-01-28 20:51:37 +0000 |
commit | d5890d56b6bcb6d1aa277f0bab78abb1ef66a88e (patch) | |
tree | 7040a74064a5c63a64b95e577e402fb65aacb15e /lib | |
parent | bff5298804af11eab5072217d362f55707849a5a (diff) | |
download | sg3_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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sg_cmds_basic.c | 8 | ||||
-rw-r--r-- | lib/sg_cmds_basic2.c | 4 | ||||
-rw-r--r-- | lib/sg_cmds_extra.c | 10 | ||||
-rw-r--r-- | lib/sg_lib.c | 52 | ||||
-rw-r--r-- | lib/sg_lib_data.c | 8 | ||||
-rw-r--r-- | lib/sg_pt_common.c | 6 | ||||
-rw-r--r-- | lib/sg_pt_freebsd.c | 6 | ||||
-rw-r--r-- | lib/sg_pt_win32.c | 10 |
8 files changed, 52 insertions, 52 deletions
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 */ |