sg_pt_win32.c (sdparm-1.11.tgz) | : | sg_pt_win32.c (sdparm-1.12.tgz) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright (c) 2006-2019 Douglas Gilbert. | * Copyright (c) 2006-2021 Douglas Gilbert. | |||
* All rights reserved. | * All rights reserved. | |||
* Use of this source code is governed by a BSD-style | * Use of this source code is governed by a BSD-style | |||
* license that can be found in the BSD_LICENSE file. | * license that can be found in the BSD_LICENSE file. | |||
* | * | |||
* SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | |||
*/ | */ | |||
/* sg_pt_win32 version 1.30 20190210 */ | /* sg_pt_win32 version 1.33 20210103 */ | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <stddef.h> | #include <stddef.h> | |||
#include <stdarg.h> | #include <stdarg.h> | |||
#include <string.h> | #include <string.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <ctype.h> | #include <ctype.h> | |||
#include <fcntl.h> | #include <fcntl.h> | |||
#define __STDC_FORMAT_MACROS 1 | #define __STDC_FORMAT_MACROS 1 | |||
skipping to change at line 438 | skipping to change at line 438 | |||
got_scsi_name = true; | got_scsi_name = true; | |||
} | } | |||
} | } | |||
} | } | |||
shp->bus = bus; | shp->bus = bus; | |||
shp->target = target; | shp->target = target; | |||
shp->lun = lun; | shp->lun = lun; | |||
shp->scsi_pdt = -1; | shp->scsi_pdt = -1; | |||
shp->verbose = vb; | shp->verbose = vb; | |||
memset(shp->adapter, 0, sizeof(shp->adapter)); | memset(shp->adapter, 0, sizeof(shp->adapter)); | |||
strncpy(shp->adapter, "\\\\.\\", 4); | memcpy(shp->adapter, "\\\\.\\", 4); | |||
if (shp->got_physical_drive) | if (shp->got_physical_drive) | |||
snprintf(shp->adapter + 4, sizeof(shp->adapter) - 5, | snprintf(shp->adapter + 4, sizeof(shp->adapter) - 5, | |||
"PhysicalDrive%d", pd_num); | "PhysicalDrive%d", pd_num); | |||
else if (got_scsi_name) | else if (got_scsi_name) | |||
snprintf(shp->adapter + 4, sizeof(shp->adapter) - 5, "SCSI%d:", | snprintf(shp->adapter + 4, sizeof(shp->adapter) - 5, "SCSI%d:", | |||
adapter_num); | adapter_num); | |||
else | else | |||
snprintf(shp->adapter + 4, sizeof(shp->adapter) - 5, "%s", | snprintf(shp->adapter + 4, sizeof(shp->adapter) - 5, "%s", | |||
device_name + off); | device_name + off); | |||
if (vb > 4) | if (vb > 4) | |||
skipping to change at line 863 | skipping to change at line 863 | |||
psp->swb_i.spt.TimeOutValue = DEF_TIMEOUT; | psp->swb_i.spt.TimeOutValue = DEF_TIMEOUT; | |||
} | } | |||
psp->dev_fd = dev_fd; | psp->dev_fd = dev_fd; | |||
psp->is_nvme = is_nvme; | psp->is_nvme = is_nvme; | |||
psp->nvme_nsid = nvme_nsid; | psp->nvme_nsid = nvme_nsid; | |||
psp->dev_statp = dsp; | psp->dev_statp = dsp; | |||
} | } | |||
} | } | |||
void | void | |||
partial_clear_scsi_pt_obj(struct sg_pt_base * vp) | ||||
{ | ||||
struct sg_pt_win32_scsi * psp = vp->implp; | ||||
if (NULL == psp) | ||||
return; | ||||
psp->in_err = 0; | ||||
psp->os_err = 0; | ||||
psp->transport_err = 0; | ||||
psp->scsi_status = 0; | ||||
if (spt_direct) { | ||||
psp->swb_d.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; | ||||
psp->swb_d.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; | ||||
psp->swb_d.spt.SenseInfoOffset = | ||||
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, ucSenseBuf); | ||||
psp->swb_d.spt.TimeOutValue = DEF_TIMEOUT; | ||||
} else { | ||||
psp->swb_i.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED; | ||||
psp->swb_i.spt.SenseInfoLength = SCSI_MAX_SENSE_LEN; | ||||
psp->swb_i.spt.SenseInfoOffset = | ||||
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, ucSenseBuf); | ||||
psp->swb_i.spt.TimeOutValue = DEF_TIMEOUT; | ||||
} | ||||
} | ||||
void | ||||
set_scsi_pt_cdb(struct sg_pt_base * vp, const uint8_t * cdb, | set_scsi_pt_cdb(struct sg_pt_base * vp, const uint8_t * cdb, | |||
int cdb_len) | int cdb_len) | |||
{ | { | |||
bool scsi_cdb = sg_is_scsi_cdb(cdb, cdb_len); | bool scsi_cdb = sg_is_scsi_cdb(cdb, cdb_len); | |||
struct sg_pt_win32_scsi * psp = vp->implp; | struct sg_pt_win32_scsi * psp = vp->implp; | |||
if (! scsi_cdb) { | if (! scsi_cdb) { | |||
if (psp->have_nvme_cmd) | psp->have_nvme_cmd = true; | |||
++psp->in_err; | ||||
else | ||||
psp->have_nvme_cmd = true; | ||||
memcpy(psp->nvme_cmd, cdb, cdb_len); | memcpy(psp->nvme_cmd, cdb, cdb_len); | |||
} else if (spt_direct) { | } else if (spt_direct) { | |||
if (psp->swb_d.spt.CdbLength > 0) | ||||
++psp->in_err; | ||||
if (cdb_len > (int)sizeof(psp->swb_d.spt.Cdb)) { | if (cdb_len > (int)sizeof(psp->swb_d.spt.Cdb)) { | |||
++psp->in_err; | ++psp->in_err; | |||
return; | return; | |||
} | } | |||
memcpy(psp->swb_d.spt.Cdb, cdb, cdb_len); | memcpy(psp->swb_d.spt.Cdb, cdb, cdb_len); | |||
psp->swb_d.spt.CdbLength = cdb_len; | psp->swb_d.spt.CdbLength = cdb_len; | |||
} else { | } else { | |||
if (psp->swb_i.spt.CdbLength > 0) | ||||
++psp->in_err; | ||||
if (cdb_len > (int)sizeof(psp->swb_i.spt.Cdb)) { | if (cdb_len > (int)sizeof(psp->swb_i.spt.Cdb)) { | |||
++psp->in_err; | ++psp->in_err; | |||
return; | return; | |||
} | } | |||
memcpy(psp->swb_i.spt.Cdb, cdb, cdb_len); | memcpy(psp->swb_i.spt.Cdb, cdb, cdb_len); | |||
psp->swb_i.spt.CdbLength = cdb_len; | psp->swb_i.spt.CdbLength = cdb_len; | |||
} | } | |||
} | } | |||
int | ||||
get_scsi_pt_cdb_len(const struct sg_pt_base * vp) | ||||
{ | ||||
const struct sg_pt_win32_scsi * psp = vp->implp; | ||||
return spt_direct ? psp->swb_d.spt.CdbLength : psp->swb_i.spt.CdbLength; | ||||
} | ||||
uint8_t * | ||||
get_scsi_pt_cdb_buf(const struct sg_pt_base * vp) | ||||
{ | ||||
const struct sg_pt_win32_scsi * psp = vp->implp; | ||||
return (uint8_t *)(spt_direct ? psp->swb_d.spt.Cdb : psp->swb_i.spt.Cdb); | ||||
} | ||||
void | void | |||
set_scsi_pt_sense(struct sg_pt_base * vp, uint8_t * sense, | set_scsi_pt_sense(struct sg_pt_base * vp, uint8_t * sense, int sense_len) | |||
int sense_len) | ||||
{ | { | |||
struct sg_pt_win32_scsi * psp = vp->implp; | struct sg_pt_win32_scsi * psp = vp->implp; | |||
if (psp->sensep) | if (sense && (sense_len > 0)) | |||
++psp->in_err; | memset(sense, 0, sense_len); | |||
memset(sense, 0, sense_len); | ||||
psp->sensep = sense; | psp->sensep = sense; | |||
psp->sense_len = sense_len; | psp->sense_len = sense_len; | |||
} | } | |||
/* from device */ | /* from device */ | |||
void | void | |||
set_scsi_pt_data_in(struct sg_pt_base * vp, uint8_t * dxferp, | set_scsi_pt_data_in(struct sg_pt_base * vp, uint8_t * dxferp, | |||
int dxfer_len) | int dxfer_len) | |||
{ | { | |||
struct sg_pt_win32_scsi * psp = vp->implp; | struct sg_pt_win32_scsi * psp = vp->implp; | |||
skipping to change at line 2106 | skipping to change at line 2139 | |||
n = (uint32_t)GetLastError(); | n = (uint32_t)GetLastError(); | |||
psp->transport_err = n; | psp->transport_err = n; | |||
psp->os_err = EIO; /* simulate Unix error, */ | psp->os_err = EIO; /* simulate Unix error, */ | |||
if (vb > 2) { | if (vb > 2) { | |||
char b[128]; | char b[128]; | |||
pr2ws("%s: IOCTL_SCSI_MINIPORT failed: %s [%u]\n", __func__, | pr2ws("%s: IOCTL_SCSI_MINIPORT failed: %s [%u]\n", __func__, | |||
get_err_str(n, sizeof(b), b), n); | get_err_str(n, sizeof(b), b), n); | |||
} | } | |||
} | } | |||
/* nvme_status is SCT|SC, therefor it excludes DNR+More */ | /* nvme_status is SCT|SC, therefore it excludes DNR+More */ | |||
psp->nvme_status = 0x3ff & (pthru->CplEntry[3] >> 17); | psp->nvme_status = 0x3ff & (pthru->CplEntry[3] >> 17); | |||
if (psp->nvme_status && (vb > 1)) { | if (psp->nvme_status && (vb > 1)) { | |||
uint16_t s = psp->nvme_status; | uint16_t s = psp->nvme_status; | |||
char b[80]; | char b[80]; | |||
pr2ws("%s: opcode=0x%x failed: NVMe status: %s [0x%x]\n", __func__, | pr2ws("%s: opcode=0x%x failed: NVMe status: %s [0x%x]\n", __func__, | |||
cmdp[0], sg_get_nvme_cmd_status_str(s, sizeof(b), b), s); | cmdp[0], sg_get_nvme_cmd_status_str(s, sizeof(b), b), s); | |||
} | } | |||
psp->nvme_result = sg_get_unaligned_le32(pthru->CplEntry + 0); | psp->nvme_result = sg_get_unaligned_le32(pthru->CplEntry + 0); | |||
skipping to change at line 3094 | skipping to change at line 3127 | |||
int time_secs, int vb) | int time_secs, int vb) | |||
{ | { | |||
if (vb) | if (vb) | |||
pr2ws("%s: not supported [time_secs=%d]\n", __func__, time_secs); | pr2ws("%s: not supported [time_secs=%d]\n", __func__, time_secs); | |||
if (psp) { ; } /* suppress warning */ | if (psp) { ; } /* suppress warning */ | |||
if (shp) { ; } /* suppress warning */ | if (shp) { ; } /* suppress warning */ | |||
return -ENOTTY; /* inappropriate ioctl error */ | return -ENOTTY; /* inappropriate ioctl error */ | |||
} | } | |||
#endif /* (HAVE_NVME && (! IGNORE_NVME)) */ | #endif /* (HAVE_NVME && (! IGNORE_NVME)) */ | |||
int | ||||
do_nvm_pt(struct sg_pt_base * vp, int submq, int timeout_secs, int verbose) | ||||
{ | ||||
if (vp) { } | ||||
if (submq) { } | ||||
if (timeout_secs) { } | ||||
if (verbose) { } | ||||
return SCSI_PT_DO_NOT_SUPPORTED; | ||||
} | ||||
End of changes. 12 change blocks. | ||||
17 lines changed or deleted | 50 lines changed or added |