"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/sg_pt_linux.c" between
sdparm-1.11.tgz and sdparm-1.12.tgz

About: sdparm let you access SCSI modes pages, read VPD pages, send simple SCSI commands (similar functionality for SCSI disks like "hdparm" for ATA disks).

sg_pt_linux.c  (sdparm-1.11.tgz):sg_pt_linux.c  (sdparm-1.12.tgz)
/* /*
* Copyright (c) 2005-2019 Douglas Gilbert. * Copyright (c) 2005-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_linux version 1.47 20190612 */ /* sg_pt_linux version 1.51 20210102 */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
skipping to change at line 467 skipping to change at line 467
#ifdef BSG_PROTOCOL_SCSI #ifdef BSG_PROTOCOL_SCSI
ptp->io_hdr.protocol = BSG_PROTOCOL_SCSI; ptp->io_hdr.protocol = BSG_PROTOCOL_SCSI;
#endif #endif
#ifdef BSG_SUB_PROTOCOL_SCSI_CMD #ifdef BSG_SUB_PROTOCOL_SCSI_CMD
ptp->io_hdr.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD; ptp->io_hdr.subprotocol = BSG_SUB_PROTOCOL_SCSI_CMD;
#endif #endif
ptp->dev_fd = fd; ptp->dev_fd = fd;
ptp->is_sg = is_sg; ptp->is_sg = is_sg;
ptp->is_bsg = is_bsg; ptp->is_bsg = is_bsg;
ptp->is_nvme = is_nvme; ptp->is_nvme = is_nvme;
ptp->nvme_direct = false; ptp->nvme_our_sntl = false;
ptp->nvme_nsid = nvme_nsid; ptp->nvme_nsid = nvme_nsid;
ptp->dev_stat = dev_stat; ptp->dev_stat = dev_stat;
} }
} }
void
partial_clear_scsi_pt_obj(struct sg_pt_base * vp)
{
struct sg_pt_linux_scsi * ptp = &vp->impl;
if (NULL == ptp)
return;
ptp->in_err = 0;
ptp->os_err = 0;
ptp->io_hdr.device_status = 0;
ptp->io_hdr.transport_status = 0;
ptp->io_hdr.driver_status = 0;
ptp->io_hdr.din_xferp = 0;
ptp->io_hdr.din_xfer_len = 0;
ptp->io_hdr.dout_xferp = 0;
ptp->io_hdr.dout_xfer_len = 0;
ptp->nvme_result = 0;
}
#ifndef SG_SET_GET_EXTENDED #ifndef SG_SET_GET_EXTENDED
/* If both sei_wr_mask and sei_rd_mask are 0, this ioctl does nothing */ /* If both sei_wr_mask and sei_rd_mask are 0, this ioctl does nothing */
struct sg_extended_info { struct sg_extended_info {
uint32_t sei_wr_mask; /* OR-ed SG_SEIM_* user->driver values */ uint32_t sei_wr_mask; /* OR-ed SG_SEIM_* user->driver values */
uint32_t sei_rd_mask; /* OR-ed SG_SEIM_* driver->user values */ uint32_t sei_rd_mask; /* OR-ed SG_SEIM_* driver->user values */
uint32_t ctl_flags_wr_mask; /* OR-ed SG_CTL_FLAGM_* values */ uint32_t ctl_flags_wr_mask; /* OR-ed SG_CTL_FLAGM_* values */
uint32_t ctl_flags_rd_mask; /* OR-ed SG_CTL_FLAGM_* values */ uint32_t ctl_flags_rd_mask; /* OR-ed SG_CTL_FLAGM_* values */
uint32_t ctl_flags; /* bit values OR-ed, see SG_CTL_FLAGM_* */ uint32_t ctl_flags; /* bit values OR-ed, see SG_CTL_FLAGM_* */
uint32_t read_value; /* write SG_SEIRV_*, read back related */ uint32_t read_value; /* write SG_SEIRV_*, read back related */
skipping to change at line 584 skipping to change at line 603
} else if (ptp->is_sg && (ptp->sg_version >= SG_LINUX_SG_VER_V4_BASE) } else if (ptp->is_sg && (ptp->sg_version >= SG_LINUX_SG_VER_V4_BASE)
&& getenv("SG3_UTILS_LINUX_NANO")) { && getenv("SG3_UTILS_LINUX_NANO")) {
if (verbose > 2) if (verbose > 2)
pr2ws("%s: dev_fd=%d, ignored SG3_UTILS_LINUX_NANO\nbecause " pr2ws("%s: dev_fd=%d, ignored SG3_UTILS_LINUX_NANO\nbecause "
"base version sg version 4 driver\n", __func__, dev_fd); "base version sg version 4 driver\n", __func__, dev_fd);
} }
} else { } else {
ptp->is_sg = false; ptp->is_sg = false;
ptp->is_bsg = false; ptp->is_bsg = false;
ptp->is_nvme = false; ptp->is_nvme = false;
ptp->nvme_direct = false; ptp->nvme_our_sntl = false;
ptp->nvme_nsid = 0; ptp->nvme_nsid = 0;
ptp->os_err = 0; ptp->os_err = 0;
} }
return ptp->os_err; return ptp->os_err;
} }
int int
sg_linux_get_sg_version(const struct sg_pt_base * vp) sg_linux_get_sg_version(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
skipping to change at line 615 skipping to change at line 634
return ptp->dev_fd; return ptp->dev_fd;
} }
void 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)
{ {
struct sg_pt_linux_scsi * ptp = &vp->impl; struct sg_pt_linux_scsi * ptp = &vp->impl;
if (ptp->io_hdr.request)
++ptp->in_err;
ptp->io_hdr.request = (__u64)(sg_uintptr_t)cdb; ptp->io_hdr.request = (__u64)(sg_uintptr_t)cdb;
ptp->io_hdr.request_len = cdb_len; ptp->io_hdr.request_len = cdb_len;
} }
int
get_scsi_pt_cdb_len(const struct sg_pt_base * vp)
{
const struct sg_pt_linux_scsi * ptp = &vp->impl;
return ptp->io_hdr.request_len;
}
uint8_t *
get_scsi_pt_cdb_buf(const struct sg_pt_base * vp)
{
const struct sg_pt_linux_scsi * ptp = &vp->impl;
return (uint8_t *)(sg_uintptr_t)ptp->io_hdr.request;
}
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 max_sense_len) int max_sense_len)
{ {
struct sg_pt_linux_scsi * ptp = &vp->impl; struct sg_pt_linux_scsi * ptp = &vp->impl;
if (ptp->io_hdr.response) if (sense) {
++ptp->in_err; if (max_sense_len > 0)
memset(sense, 0, max_sense_len); memset(sense, 0, max_sense_len);
}
ptp->io_hdr.response = (__u64)(sg_uintptr_t)sense; ptp->io_hdr.response = (__u64)(sg_uintptr_t)sense;
ptp->io_hdr.max_response_len = max_sense_len; ptp->io_hdr.max_response_len = max_sense_len;
} }
/* Setup for data transfer from device */ /* Setup for data transfer 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_ilen) int dxfer_ilen)
{ {
struct sg_pt_linux_scsi * ptp = &vp->impl; struct sg_pt_linux_scsi * ptp = &vp->impl;
skipping to change at line 682 skipping to change at line 716
ptp->mdxfer_len = dxfer_len; ptp->mdxfer_len = dxfer_len;
ptp->mdxfer_out = out_true; ptp->mdxfer_out = out_true;
} }
} }
void void
set_scsi_pt_packet_id(struct sg_pt_base * vp, int pack_id) set_scsi_pt_packet_id(struct sg_pt_base * vp, int pack_id)
{ {
struct sg_pt_linux_scsi * ptp = &vp->impl; struct sg_pt_linux_scsi * ptp = &vp->impl;
ptp->io_hdr.request_extra = pack_id; /* was place in spare_in */ ptp->io_hdr.request_extra = pack_id; /* was placed in spare_in */
} }
void void
set_scsi_pt_tag(struct sg_pt_base * vp, uint64_t tag) set_scsi_pt_tag(struct sg_pt_base * vp, uint64_t tag)
{ {
struct sg_pt_linux_scsi * ptp = &vp->impl; struct sg_pt_linux_scsi * ptp = &vp->impl;
ptp->io_hdr.request_tag = tag; ptp->io_hdr.request_tag = tag;
} }
skipping to change at line 756 skipping to change at line 790
* number actually transferred. This it typically important for data-in * number actually transferred. This it typically important for data-in
* transfers. For data-out (only) transfers, the 'dout_req_len - * transfers. For data-out (only) transfers, the 'dout_req_len -
* dout_act_len' is returned. For bidi transfer the "din" residual is * dout_act_len' is returned. For bidi transfer the "din" residual is
* returned. */ * returned. */
/* N.B. Returns din_resid and ignores dout_resid */ /* N.B. Returns din_resid and ignores dout_resid */
int int
get_scsi_pt_resid(const struct sg_pt_base * vp) get_scsi_pt_resid(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
if ((NULL == ptp) || (ptp->nvme_direct)) if ((NULL == ptp) || (ptp->is_nvme && ! ptp->nvme_our_sntl))
return 0; return 0;
else if ((ptp->io_hdr.din_xfer_len > 0) && else if ((ptp->io_hdr.din_xfer_len > 0) &&
(ptp->io_hdr.dout_xfer_len > 0)) (ptp->io_hdr.dout_xfer_len > 0))
return ptp->io_hdr.din_resid; return ptp->io_hdr.din_resid;
else if (ptp->io_hdr.dout_xfer_len > 0) else if (ptp->io_hdr.dout_xfer_len > 0)
return ptp->io_hdr.dout_resid; return ptp->io_hdr.dout_resid;
return ptp->io_hdr.din_resid; return ptp->io_hdr.din_resid;
} }
void void
skipping to change at line 815 skipping to change at line 849
} }
} }
int int
get_scsi_pt_status_response(const struct sg_pt_base * vp) get_scsi_pt_status_response(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
if (NULL == ptp) if (NULL == ptp)
return 0; return 0;
return (int)(ptp->nvme_direct ? ptp->nvme_status : return (int)((ptp->is_nvme && ! ptp->nvme_our_sntl) ?
ptp->io_hdr.device_status); ptp->nvme_status : ptp->io_hdr.device_status);
} }
uint32_t uint32_t
get_pt_result(const struct sg_pt_base * vp) get_pt_result(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
if (NULL == ptp) if (NULL == ptp)
return 0; return 0;
return ptp->nvme_direct ? ptp->nvme_result : return (ptp->is_nvme && ! ptp->nvme_our_sntl) ?
ptp->io_hdr.device_status; ptp->nvme_result : ptp->io_hdr.device_status;
} }
int int
get_scsi_pt_sense_len(const struct sg_pt_base * vp) get_scsi_pt_sense_len(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
return ptp->io_hdr.response_len; return ptp->io_hdr.response_len;
} }
uint8_t * uint8_t *
get_scsi_pt_sense_buf(const struct sg_pt_base * vp) get_scsi_pt_sense_buf(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
return (uint8_t *)ptp->io_hdr.response; return (uint8_t *)(sg_uintptr_t)ptp->io_hdr.response;
} }
int int
get_scsi_pt_duration_ms(const struct sg_pt_base * vp) get_scsi_pt_duration_ms(const struct sg_pt_base * vp)
{ {
const struct sg_pt_linux_scsi * ptp = &vp->impl; const struct sg_pt_linux_scsi * ptp = &vp->impl;
return sg_duration_set_nano ? (ptp->io_hdr.duration / 1000) : return sg_duration_set_nano ? (ptp->io_hdr.duration / 1000) :
ptp->io_hdr.duration; ptp->io_hdr.duration;
} }
skipping to change at line 1115 skipping to change at line 1149
return SCSI_PT_DO_BAD_PARAMS; return SCSI_PT_DO_BAD_PARAMS;
} else } else
fd = ptp->dev_fd; fd = ptp->dev_fd;
if (! have_checked_for_type) { if (! have_checked_for_type) {
err = set_pt_file_handle(vp, ptp->dev_fd, verbose); err = set_pt_file_handle(vp, ptp->dev_fd, verbose);
if (err) if (err)
return -ptp->os_err; return -ptp->os_err;
} }
if (ptp->os_err) if (ptp->os_err)
return -ptp->os_err; return -ptp->os_err;
if (verbose > 5)
pr2ws("%s: is_nvme=%d, is_sg=%d, is_bsg=%d\n", __func__,
(int)ptp->is_nvme, (int)ptp->is_sg, (int)ptp->is_bsg);
if (ptp->is_nvme) if (ptp->is_nvme)
return sg_do_nvme_pt(vp, -1, time_secs, verbose); return sg_do_nvme_pt(vp, -1, time_secs, verbose);
else if (ptp->is_sg) { else if (ptp->is_sg) {
#ifdef IGNORE_LINUX_SGV4 #ifdef IGNORE_LINUX_SGV4
return do_scsi_pt_v3(ptp, fd, time_secs, verbose); return do_scsi_pt_v3(ptp, fd, time_secs, verbose);
#else #else
if (ptp->sg_version >= SG_LINUX_SG_VER_V4_BASE) if (ptp->sg_version >= SG_LINUX_SG_VER_V4_BASE)
return do_scsi_pt_v4(ptp, fd, time_secs, verbose); return do_scsi_pt_v4(ptp, fd, time_secs, verbose);
else else
return do_scsi_pt_v3(ptp, fd, time_secs, verbose); return do_scsi_pt_v3(ptp, fd, time_secs, verbose);
 End of changes. 14 change blocks. 
16 lines changed or deleted 53 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)