diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2018-02-19 05:55:24 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2018-02-19 05:55:24 +0000 |
commit | 39ea1b548f21c006c311ace897b221b100bfa88d (patch) | |
tree | 764ecee434b161b62c41182a6bc09ce950b85258 /lib/sg_pt_linux.c | |
parent | 5bdce507b09d32f452a390c22cb98ae7f840c151 (diff) | |
download | sg3_utils-39ea1b548f21c006c311ace897b221b100bfa88d.tar.gz |
sg_raw: add --raw option (for CF in binary); sg_lib: add sg_get_nvme_opcode_name() and sg_is_aligned(); sg_vpd: fully implement Device Constituents vpage
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@753 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib/sg_pt_linux.c')
-rw-r--r-- | lib/sg_pt_linux.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/sg_pt_linux.c b/lib/sg_pt_linux.c index 22ea0683..acbf9d6d 100644 --- a/lib/sg_pt_linux.c +++ b/lib/sg_pt_linux.c @@ -5,7 +5,7 @@ * license that can be found in the BSD_LICENSE file. */ -/* sg_pt_linux version 1.37 20180126 */ +/* sg_pt_linux version 1.38 20180215 */ #include <stdio.h> @@ -64,27 +64,20 @@ static const char * linux_host_bytes[] = { "DID_MEDIUM_ERROR", }; -#define LINUX_HOST_BYTES_SZ \ - (int)(sizeof(linux_host_bytes) / sizeof(linux_host_bytes[0])) - static const char * linux_driver_bytes[] = { "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE" }; -#define LINUX_DRIVER_BYTES_SZ \ - (int)(sizeof(linux_driver_bytes) / sizeof(linux_driver_bytes[0])) - #if 0 + static const char * linux_driver_suggests[] = { "SUGGEST_OK", "SUGGEST_RETRY", "SUGGEST_ABORT", "SUGGEST_REMAP", "SUGGEST_DIE", "UNKNOWN","UNKNOWN","UNKNOWN", "SUGGEST_SENSE" }; -#define LINUX_DRIVER_SUGGESTS_SZ \ - (int)(sizeof(linux_driver_suggests) / sizeof(linux_driver_suggests[0])) #endif /* @@ -431,15 +424,20 @@ construct_scsi_pt_obj() void destruct_scsi_pt_obj(struct sg_pt_base * vp) { - struct sg_pt_linux_scsi * ptp = &vp->impl; - if (ptp->free_nvme_id_ctlp) { - free(ptp->free_nvme_id_ctlp); - ptp->free_nvme_id_ctlp = NULL; - ptp->nvme_id_ctlp = NULL; + if (NULL == vp) + pr2ws(">>>>>>> Warning: %s called with NULL pointer\n", __func__); + else { + struct sg_pt_linux_scsi * ptp = &vp->impl; + + if (ptp->free_nvme_id_ctlp) { + free(ptp->free_nvme_id_ctlp); + ptp->free_nvme_id_ctlp = NULL; + ptp->nvme_id_ctlp = NULL; + } + if (ptp) + free(ptp); } - if (ptp) - free(ptp); } /* Remembers previous device file descriptor */ @@ -457,6 +455,8 @@ clear_scsi_pt_obj(struct sg_pt_base * vp) is_bsg = ptp->is_bsg; is_nvme = ptp->is_nvme; nvme_nsid = ptp->nvme_nsid; + if (ptp->free_nvme_id_ctlp) + free(ptp->free_nvme_id_ctlp); memset(ptp, 0, sizeof(struct sg_pt_linux_scsi)); ptp->io_hdr.guard = 'Q'; #ifdef BSG_PROTOCOL_SCSI @@ -735,7 +735,7 @@ get_scsi_pt_transport_err_str(const struct sg_pt_base * vp, int max_b_len, m = max_b_len; n = 0; if (hs) { - if ((hs < 0) || (hs >= LINUX_HOST_BYTES_SZ)) + if ((hs < 0) || (hs >= (int)SG_ARRAY_SIZE(linux_host_bytes))) n = snprintf(cp, m, "Host_status=0x%02x is invalid\n", hs); else n = snprintf(cp, m, "Host_status=0x%02x [%s]\n", hs, @@ -748,11 +748,11 @@ get_scsi_pt_transport_err_str(const struct sg_pt_base * vp, int max_b_len, } cp += n; driv = ds & SG_LIB_DRIVER_MASK; - if (driv < LINUX_DRIVER_BYTES_SZ) + if (driv < (int)SG_ARRAY_SIZE(linux_driver_bytes)) driv_cp = linux_driver_bytes[driv]; #if 0 sugg = (ds & SG_LIB_SUGGEST_MASK) >> 4; - if (sugg < LINUX_DRIVER_SUGGESTS_SZ) + if (sugg < SG_ARRAY_SIZE(linux_driver_suggests) sugg_cp = linux_driver_suggests[sugg]; #endif n = snprintf(cp, m, "Driver_status=0x%02x [%s]\n", ds, driv_cp); |