aboutsummaryrefslogtreecommitdiff
path: root/lib/sg_cmds_extra.c
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2017-10-09 23:49:50 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2017-10-09 23:49:50 +0000
commitb2e59f46a39f19ffc18be02fad71df68974a8d0b (patch)
tree83b037b8108830c5f04d93fa50d19bbda5fb6ea1 /lib/sg_cmds_extra.c
parentdc469cf010ce1c840d6a1790cc4179ea0f5912dd (diff)
downloadsg3_utils-b2e59f46a39f19ffc18be02fad71df68974a8d0b.tar.gz
convert lots of two valued 'int's to bool; add sg_ll_inquiry_v2() sg_ll_write_buffer_v2() sg_get_sfs_name() and sg_decode_transportid_str()
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@719 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'lib/sg_cmds_extra.c')
-rw-r--r--lib/sg_cmds_extra.c239
1 files changed, 167 insertions, 72 deletions
diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c
index a090dd30..b606b495 100644
--- a/lib/sg_cmds_extra.c
+++ b/lib/sg_cmds_extra.c
@@ -266,7 +266,7 @@ int
sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len,
bool noisy, int verbose)
{
- return sg_ll_report_tgt_prt_grp2(sg_fd, resp, mx_resp_len, 0, noisy,
+ return sg_ll_report_tgt_prt_grp2(sg_fd, resp, mx_resp_len, false, noisy,
verbose);
}
@@ -274,7 +274,7 @@ sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len,
- int extended, bool noisy, int verbose)
+ bool extended, bool noisy, int verbose)
{
static const char * const cdb_name_s = "report target port groups";
int k, res, ret, sense_cat;
@@ -284,9 +284,8 @@ sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len,
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
- if (extended) {
+ if (extended)
rtpg_cdb[1] |= 0x20;
- }
sg_put_unaligned_be32((uint32_t)mx_resp_len, rtpg_cdb + 6);
if (verbose) {
pr2ws(" %s cdb: ", cdb_name_s);
@@ -364,8 +363,8 @@ sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, bool noisy,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -387,7 +386,7 @@ sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, bool noisy,
/* Invokes a SCSI REPORT REFERRALS command. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
+sg_ll_report_referrals(int sg_fd, uint64_t start_llba, bool one_seg,
void * resp, int mx_resp_len, bool noisy,
int verbose)
{
@@ -401,7 +400,8 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
sg_put_unaligned_be64(start_llba, repRef_cdb + 2);
sg_put_unaligned_be32((uint32_t)mx_resp_len, repRef_cdb + 10);
- repRef_cdb[14] = one_seg & 0x1;
+ if (one_seg)
+ repRef_cdb[14] = 0x1;
if (verbose) {
pr2ws(" %s cdb: ", cdb_name_s);
for (k = 0; k < SERVICE_ACTION_IN_16_CMDLEN; ++k)
@@ -452,9 +452,9 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
* value is taken as the timeout value in seconds. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
- int unitofl_bit, int long_duration, void * paramp,
- int param_len, bool noisy, int verbose)
+sg_ll_send_diag(int sg_fd, int sf_code, bool pf_bit, bool sf_bit,
+ bool devofl_bit, bool unitofl_bit, int long_duration,
+ void * paramp, int param_len, bool noisy, int verbose)
{
static const char * const cdb_name_s = "send diagnostic";
int k, res, ret, sense_cat, tmout;
@@ -463,8 +463,15 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
- senddiag_cdb[1] = (unsigned char)((sf_code << 5) | (pf_bit << 4) |
- (sf_bit << 2) | (devofl_bit << 1) | unitofl_bit);
+ senddiag_cdb[1] = (unsigned char)(sf_code << 5);
+ if (pf_bit)
+ senddiag_cdb[1] |= 0x10;
+ if (sf_bit)
+ senddiag_cdb[1] |= 0x4;
+ if (devofl_bit)
+ senddiag_cdb[1] |= 0x2;
+ if (unitofl_bit)
+ senddiag_cdb[1] |= 0x1;
sg_put_unaligned_be16((uint16_t)param_len, senddiag_cdb + 3);
if (long_duration > LONG_PT_TIMEOUT)
tmout = long_duration;
@@ -491,8 +498,8 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -515,7 +522,7 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
/* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp,
+sg_ll_receive_diag(int sg_fd, bool pcv, int pg_code, void * resp,
int mx_resp_len, bool noisy, int verbose)
{
static const char * const cdb_name_s = "receive diagnostic results";
@@ -525,7 +532,8 @@ sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp,
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
- rcvdiag_cdb[1] = (unsigned char)(pcv ? 0x1 : 0);
+ if (pcv)
+ rcvdiag_cdb[1] = 0x1;
rcvdiag_cdb[2] = (unsigned char)(pg_code);
sg_put_unaligned_be16((uint16_t)mx_resp_len, rcvdiag_cdb + 3);
@@ -576,7 +584,7 @@ sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp,
/* Invokes a SCSI READ DEFECT DATA (10) command (SBC). Return of 0 -> success
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_read_defect10(int sg_fd, int req_plist, int req_glist, int dl_format,
+sg_ll_read_defect10(int sg_fd, bool req_plist, bool req_glist, int dl_format,
void * resp, int mx_resp_len, bool noisy, int verbose)
{
static const char * const cdb_name_s = "read defect(10)";
@@ -586,8 +594,11 @@ sg_ll_read_defect10(int sg_fd, int req_plist, int req_glist, int dl_format,
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
- rdef_cdb[2] = (unsigned char)(((req_plist << 4) & 0x10) |
- ((req_glist << 3) & 0x8) | (dl_format & 0x7));
+ rdef_cdb[2] = (dl_format & 0x7);
+ if (req_plist)
+ rdef_cdb[2] |= 0x10;
+ if (req_glist)
+ rdef_cdb[2] |= 0x8;
sg_put_unaligned_be16((uint16_t)mx_resp_len, rdef_cdb + 7);
if (mx_resp_len > 0xffff) {
pr2ws("mx_resp_len too big\n");
@@ -792,8 +803,8 @@ sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -873,8 +884,8 @@ sg_ll_format_unit2(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -897,7 +908,7 @@ sg_ll_format_unit2(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
/* Invokes a SCSI REASSIGN BLOCKS command. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, void * paramp,
+sg_ll_reassign_blocks(int sg_fd, bool longlba, bool longlist, void * paramp,
int param_len, bool noisy, int verbose)
{
static const char * const cdb_name_s = "reassign blocks";
@@ -907,8 +918,10 @@ sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, void * paramp,
unsigned char sense_b[SENSE_BUFF_LEN];
struct sg_pt_base * ptvp;
- reass_cdb[1] = (unsigned char)(((longlba << 1) & 0x2) |
- (longlist & 0x1));
+ if (longlba)
+ reass_cdb[1] = 0x2;
+ if (longlist)
+ reass_cdb[1] |= 0x1;
if (verbose) {
pr2ws(" %s cdb: ", cdb_name_s);
for (k = 0; k < REASSIGN_BLKS_CMDLEN; ++k)
@@ -926,8 +939,8 @@ sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, void * paramp,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1046,8 +1059,8 @@ sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1067,29 +1080,29 @@ sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope,
return ret;
}
-static int
+static bool
has_blk_ili(unsigned char * sensep, int sb_len)
{
int resp_code;
const unsigned char * cup;
if (sb_len < 8)
- return 0;
+ return false;
resp_code = (0x7f & sensep[0]);
if (resp_code >= 0x72) { /* descriptor format */
/* find block command descriptor */
if ((cup = sg_scsi_sense_desc_find(sensep, sb_len, 0x5)))
- return ((cup[3] & 0x20) ? 1 : 0);
+ return (cup[3] & 0x20);
} else /* fixed */
- return ((sensep[2] & 0x20) ? 1 : 0);
- return 0;
+ return (sensep[2] & 0x20);
+ return false;
}
/* Invokes a SCSI READ LONG (10) command (SBC). Note that 'xfer_len'
* is in bytes. Returns 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
+sg_ll_read_long10(int sg_fd, bool pblock, bool correct, unsigned int lba,
void * resp, int xfer_len, int * offsetp, bool noisy,
int verbose)
{
@@ -1133,7 +1146,8 @@ sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
break;
case SG_LIB_CAT_ILLEGAL_REQ:
{
- int valid, slen, ili;
+ bool valid, ili;
+ int slen;
uint64_t ull = 0;
slen = get_scsi_pt_sense_len(ptvp);
@@ -1176,7 +1190,7 @@ sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
* is in bytes. Returns 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
+sg_ll_read_long16(int sg_fd, bool pblock, bool correct, uint64_t llba,
void * resp, int xfer_len, int * offsetp, bool noisy,
int verbose)
{
@@ -1221,7 +1235,8 @@ sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
break;
case SG_LIB_CAT_ILLEGAL_REQ:
{
- int valid, slen, ili;
+ bool valid, ili;
+ int slen;
uint64_t ull = 0;
slen = get_scsi_pt_sense_len(ptvp);
@@ -1234,7 +1249,7 @@ sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
} else {
if (verbose > 1)
pr2ws(" info field: 0x%" PRIx64 ", valid: %d, "
- "ili: %d\n", ull, valid, ili);
+ "ili: %d\n", ull, (int)valid, (int)ili);
ret = SG_LIB_CAT_ILLEGAL_REQ;
}
}
@@ -1264,7 +1279,7 @@ sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
* is in bytes. Returns 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
+sg_ll_write_long10(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock,
unsigned int lba, void * data_out, int xfer_len,
int * offsetp, bool noisy, int verbose)
{
@@ -1298,8 +1313,8 @@ sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)data_out, xfer_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1323,7 +1338,7 @@ sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
} else {
if (verbose > 1)
pr2ws(" info field: 0x%" PRIx64 ", valid: %d, "
- "ili: %d\n", ull, valid, ili);
+ "ili: %d\n", ull, (int)valid, (int)ili);
ret = SG_LIB_CAT_ILLEGAL_REQ;
}
}
@@ -1343,7 +1358,7 @@ sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
* is in bytes. Returns 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
+sg_ll_write_long16(int sg_fd, bool cor_dis, bool wr_uncor, bool pblock,
uint64_t llba, void * data_out, int xfer_len,
int * offsetp, bool noisy, int verbose)
{
@@ -1378,8 +1393,8 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)data_out, xfer_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1390,7 +1405,8 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
break;
case SG_LIB_CAT_ILLEGAL_REQ:
{
- int valid, slen, ili;
+ bool valid, ili;
+ int slen;
uint64_t ull = 0;
slen = get_scsi_pt_sense_len(ptvp);
@@ -1403,7 +1419,7 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
} else {
if (verbose > 1)
pr2ws(" info field: 0x%" PRIx64 ", valid: %d, "
- "ili: %d\n", ull, valid, ili);
+ "ili: %d\n", ull, (int)valid, (int)ili);
ret = SG_LIB_CAT_ILLEGAL_REQ;
}
}
@@ -1424,7 +1440,7 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
* Returns of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
+sg_ll_verify10(int sg_fd, int vrprotect, bool dpo, int bytchk,
unsigned int lba, int veri_len, void * data_out,
int data_out_len, unsigned int * infop, bool noisy,
int verbose)
@@ -1437,8 +1453,9 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
struct sg_pt_base * ptvp;
/* N.B. BYTCHK field expanded to 2 bits sbc3r34 */
- v_cdb[1] = ((vrprotect & 0x7) << 5) | ((dpo & 0x1) << 4) |
- ((bytchk & 0x3) << 1) ;
+ v_cdb[1] = (((vrprotect & 0x7) << 5) | ((bytchk & 0x3) << 1)) ;
+ if (dpo)
+ v_cdb[1] |= 0x10;
sg_put_unaligned_be32((uint32_t)lba, v_cdb + 2);
sg_put_unaligned_be16((uint16_t)veri_len, v_cdb + 7);
if (verbose > 1) {
@@ -1460,8 +1477,8 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
if (data_out_len > 0)
set_scsi_pt_data_out(ptvp, (unsigned char *)data_out, data_out_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1472,7 +1489,7 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
break;
case SG_LIB_CAT_MEDIUM_HARD:
{
- int valid;
+ bool valid;
uint64_t ull = 0;
slen = get_scsi_pt_sense_len(ptvp);
@@ -1501,7 +1518,7 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
* Returns of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
int
-sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
+sg_ll_verify16(int sg_fd, int vrprotect, bool dpo, int bytchk, uint64_t llba,
int veri_len, int group_num, void * data_out,
int data_out_len, uint64_t * infop, bool noisy, int verbose)
{
@@ -1513,8 +1530,9 @@ sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
struct sg_pt_base * ptvp;
/* N.B. BYTCHK field expanded to 2 bits sbc3r34 */
- v_cdb[1] = ((vrprotect & 0x7) << 5) | ((dpo & 0x1) << 4) |
- ((bytchk & 0x3) << 1) ;
+ v_cdb[1] = (((vrprotect & 0x7) << 5) | ((bytchk & 0x3) << 1)) ;
+ if (dpo)
+ 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;
@@ -1537,8 +1555,8 @@ sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
if (data_out_len > 0)
set_scsi_pt_data_out(ptvp, (unsigned char *)data_out, data_out_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1549,7 +1567,7 @@ sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
break;
case SG_LIB_CAT_MEDIUM_HARD:
{
- int valid;
+ bool valid;
uint64_t ull = 0;
slen = get_scsi_pt_sense_len(ptvp);
@@ -1600,6 +1618,7 @@ sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
int * residp, int verbose)
{
int k, res, slen, duration;
+ int ret = -1;
unsigned char apt_cdb[ATA_PT_32_CMDLEN];
unsigned char sense_b[SENSE_BUFF_LEN];
unsigned char * sp;
@@ -1607,7 +1626,6 @@ sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
struct sg_pt_base * ptvp;
const char * cnamep;
char b[256];
- int ret = -1;
memset(apt_cdb, 0, sizeof(apt_cdb));
b[0] = '\0';
@@ -1849,8 +1867,85 @@ sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
+ if (-1 == ret)
+ ;
+ else if (-2 == ret) {
+ switch (sense_cat) {
+ case SG_LIB_CAT_RECOVERED:
+ case SG_LIB_CAT_NO_SENSE:
+ ret = 0;
+ break;
+ default:
+ ret = sense_cat;
+ break;
+ }
+ } else
+ ret = 0;
+
+ destruct_scsi_pt_obj(ptvp);
+ return ret;
+}
+
+/* Invokes a SCSI WRITE BUFFER command (SPC). Return of 0 ->
+ * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
+ * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
+ * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
+ * -1 -> other failure. Adds mode specific field (spc4r32) and timeout
+ * to command abort to override default of 60 seconds. If timeout_secs is
+ * 0 or less then the default timeout is used instead. */
+int
+sg_ll_write_buffer_v2(int sg_fd, int mode, int m_specific, int buffer_id,
+ uint32_t buffer_offset, void * paramp,
+ uint32_t param_len, int timeout_secs, bool noisy,
+ int verbose)
+{
+ int k, res, ret, sense_cat;
+ uint8_t wbuf_cdb[WRITE_BUFFER_CMDLEN] =
+ {WRITE_BUFFER_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ uint8_t sense_b[SENSE_BUFF_LEN];
+ struct sg_pt_base * ptvp;
+
+ if (buffer_offset > 0xffffff) {
+ pr2ws("%s: buffer_offset value too large for 24 bits\n", __func__);
+ return -1;
+ }
+ if (param_len > 0xffffff) {
+ pr2ws("%s: param_len value too large for 24 bits\n", __func__);
+ return -1;
+ }
+ wbuf_cdb[1] = (uint8_t)(mode & 0x1f);
+ wbuf_cdb[1] |= (uint8_t)((m_specific & 0x7) << 5);
+ wbuf_cdb[2] = (uint8_t)(buffer_id & 0xff);
+ sg_put_unaligned_be24(buffer_offset, wbuf_cdb + 3);
+ sg_put_unaligned_be24(param_len, wbuf_cdb + 6);
+ if (verbose) {
+ pr2ws(" Write buffer cdb: ");
+ for (k = 0; k < WRITE_BUFFER_CMDLEN; ++k)
+ pr2ws("%02x ", wbuf_cdb[k]);
+ pr2ws("\n");
+ if ((verbose > 1) && paramp && param_len) {
+ pr2ws(" Write buffer parameter list%s:\n",
+ ((param_len > 256) ? " (first 256 bytes)" : ""));
+ dStrHexErr((const char *)paramp,
+ ((param_len > 256) ? 256 : param_len), -1);
+ }
+ }
+ if (timeout_secs <= 0)
+ timeout_secs = DEF_PT_TIMEOUT;
+
+ ptvp = construct_scsi_pt_obj();
+ if (NULL == ptvp) {
+ pr2ws("%s: out of memory\n", __func__);
+ return -1;
+ }
+ set_scsi_pt_cdb(ptvp, wbuf_cdb, sizeof(wbuf_cdb));
+ set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
+ set_scsi_pt_data_out(ptvp, (uint8_t *)paramp, param_len);
+ res = do_scsi_pt(ptvp, sg_fd, timeout_secs, verbose);
+ ret = sg_cmds_process_resp(ptvp, "Write buffer", res, SG_NO_DATA_IN,
+ sense_b, noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -1876,14 +1971,14 @@ int
sg_ll_unmap(int sg_fd, int group_num, int timeout_secs, void * paramp,
int param_len, bool noisy, int verbose)
{
- return sg_ll_unmap_v2(sg_fd, 0, group_num, timeout_secs, paramp,
+ return sg_ll_unmap_v2(sg_fd, false, group_num, timeout_secs, paramp,
param_len, noisy, verbose);
}
/* Invokes a SCSI UNMAP (SBC-3) command. Version 2 adds anchor field
* (sbc3r22). Otherwise same as sg_ll_unmap() . */
int
-sg_ll_unmap_v2(int sg_fd, int anchor, int group_num, int timeout_secs,
+sg_ll_unmap_v2(int sg_fd, bool anchor, int group_num, int timeout_secs,
void * paramp, int param_len, bool noisy, int verbose)
{
static const char * const cdb_name_s = "unmap";
@@ -1915,8 +2010,8 @@ sg_ll_unmap_v2(int sg_fd, int anchor, int group_num, int timeout_secs,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
- ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, 0, sense_b, noisy,
- verbose, &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cdb_name_s, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {
@@ -2086,7 +2181,7 @@ sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, bool noisy,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose);
- ret = sg_cmds_process_resp(ptvp, opcode_name, res, 0, sense_b,
+ ret = sg_cmds_process_resp(ptvp, opcode_name, res, SG_NO_DATA_IN, sense_b,
noisy, verbose, &sense_cat);
if (-1 == ret)
;
@@ -2163,8 +2258,8 @@ sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num,
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
- ret = sg_cmds_process_resp(ptvp, cname, res, 0, sense_b, noisy, verbose,
- &sense_cat);
+ ret = sg_cmds_process_resp(ptvp, cname, res, SG_NO_DATA_IN, sense_b,
+ noisy, verbose, &sense_cat);
if (-1 == ret)
;
else if (-2 == ret) {