diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2017-10-09 23:49:50 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2017-10-09 23:49:50 +0000 |
commit | b2e59f46a39f19ffc18be02fad71df68974a8d0b (patch) | |
tree | 83b037b8108830c5f04d93fa50d19bbda5fb6ea1 /lib | |
parent | dc469cf010ce1c840d6a1790cc4179ea0f5912dd (diff) | |
download | sg3_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')
-rw-r--r-- | lib/Makefile.am | 6 | ||||
-rw-r--r-- | lib/Makefile.in | 9 | ||||
-rw-r--r-- | lib/sg_cmds_basic.c | 102 | ||||
-rw-r--r-- | lib/sg_cmds_basic2.c | 78 | ||||
-rw-r--r-- | lib/sg_cmds_extra.c | 239 | ||||
-rw-r--r-- | lib/sg_cmds_mmc.c | 10 | ||||
-rw-r--r-- | lib/sg_io_linux.c | 8 | ||||
-rw-r--r-- | lib/sg_lib.c | 104 | ||||
-rw-r--r-- | lib/sg_lib_data.c | 2 | ||||
-rw-r--r-- | lib/sg_pt_common.c | 4 | ||||
-rw-r--r-- | lib/sg_pt_freebsd.c | 7 | ||||
-rw-r--r-- | lib/sg_pt_linux.c | 9 | ||||
-rw-r--r-- | lib/sg_pt_osf1.c | 5 | ||||
-rw-r--r-- | lib/sg_pt_solaris.c | 8 | ||||
-rw-r--r-- | lib/sg_pt_win32.c | 6 |
15 files changed, 397 insertions, 200 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 84202dc5..1dd6b5ef 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -37,15 +37,15 @@ endif ## CC = gcc ## CC = g++ ## CC = clang -## CC = clang++ +CC = clang++ # -std=<s> can be c99, c11, gnu11, etc. Default is gnu89 (gnu90 is the same) # -Wall is no longer all warnings. Add -W (since renamed to -Wextra) for more AM_CPPFLAGS = -iquote ${top_srcdir}/include -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -AM_CFLAGS = -Wall -W +##AM_CFLAGS = -Wall -W # AM_CFLAGS = -Wall -W -pedantic -std=c11 # AM_CFLAGS = -Wall -W -pedantic -std=c11 --analyze -# AM_CFLAGS = -Wall -W -pedantic -std=c++14 +AM_CFLAGS = -Wall -W -pedantic -std=c++14 lib_LTLIBRARIES = libsgutils2.la diff --git a/lib/Makefile.in b/lib/Makefile.in index fa695ceb..f045695e 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -230,7 +230,9 @@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ -CC = @CC@ + +# For C++/clang testing +CC = clang++ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPP = @CPP@ @@ -347,15 +349,12 @@ libsgutils2_la_SOURCES = sg_lib.c sg_lib_data.c sg_cmds_basic.c \ $(am__append_1) $(am__append_2) $(am__append_3) \ $(am__append_4) $(am__append_5) $(am__append_6) -# For C++/clang testing - # -std=<s> can be c99, c11, gnu11, etc. Default is gnu89 (gnu90 is the same) # -Wall is no longer all warnings. Add -W (since renamed to -Wextra) for more AM_CPPFLAGS = -iquote ${top_srcdir}/include -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -AM_CFLAGS = -Wall -W # AM_CFLAGS = -Wall -W -pedantic -std=c11 # AM_CFLAGS = -Wall -W -pedantic -std=c11 --analyze -# AM_CFLAGS = -Wall -W -pedantic -std=c++14 +AM_CFLAGS = -Wall -W -pedantic -std=c++14 lib_LTLIBRARIES = libsgutils2.la libsgutils2_la_LDFLAGS = -version-info 2:0:0 -no-undefined libsgutils2_la_LIBADD = @GETOPT_O_FILES@ @os_libs@ diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c index 4cec465e..44c3fa45 100644 --- a/lib/sg_cmds_basic.c +++ b/lib/sg_cmds_basic.c @@ -35,7 +35,7 @@ #endif -static const char * const version_str = "1.75 20170917"; +static const char * const version_str = "1.76 20171007"; #define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */ @@ -86,7 +86,7 @@ pr2ws(const char * fmt, ...) /* Returns file descriptor >= 0 if successful. If error in Unix returns negated errno. */ int -sg_cmds_open_device(const char * device_name, int read_only, int verbose) +sg_cmds_open_device(const char * device_name, bool read_only, int verbose) { /* The following 2 lines are temporary. It is to avoid a NULL pointer * crash when an old utility is used with a newer library built after @@ -327,9 +327,10 @@ create_pt_obj(const char * cname) static const char * const inquiry_s = "inquiry"; /* Invokes a SCSI INQUIRY command and yields the response. Returns 0 when - * successful, various SG_LIB_CAT_* positive values or -1 -> other errors */ + * successful, various SG_LIB_CAT_* positive values or -1 -> other errors. + * The CMDDT field is obsolete in the INQUIRY cdb. */ int -sg_ll_inquiry(int sg_fd, int cmddt, int evpd, int pg_op, void * resp, +sg_ll_inquiry(int sg_fd, bool cmddt, bool evpd, int pg_op, void * resp, int mx_resp_len, bool noisy, int verbose) { int res, ret, k, sense_cat, resid; @@ -469,6 +470,93 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data, return ret; } +/* Invokes a SCSI INQUIRY command and yields the response. Returns 0 when + * successful, various SG_LIB_CAT_* positive values or -1 -> other errors. + * The CMDDT field is obsolete in the INQUIRY cdb (since spc3r16 in 2003) so + * an argument to set it has been removed (use the REPORT SUPPORTED OPERATION + * CODES command instead). Adds the ability to set the command abort timeout + * and the ability to report the residual count. If timeout_secs is zero + * or less the the default command abort timeout (60 seconds) is used. + * If residp is non-NULL then the residual value is written where residp + * points. A residual value of 0 implies mx_resp_len bytes have be written + * where resp points. If the residual value equals mx_resp_len then no + * bytes have been written. */ +int +sg_ll_inquiry_v2(int sg_fd, bool evpd, int pg_op, void * resp, + int mx_resp_len, int timeout_secs, int * residp, + bool noisy, int verbose) +{ + int res, ret, k, sense_cat, resid; + unsigned char inq_cdb[INQUIRY_CMDLEN] = {INQUIRY_CMD, 0, 0, 0, 0, 0}; + unsigned char sense_b[SENSE_BUFF_LEN]; + unsigned char * up; + struct sg_pt_base * ptvp; + + if (evpd) + inq_cdb[1] |= 1; + inq_cdb[2] = (unsigned char)pg_op; + /* 16 bit allocation length (was 8) is a recent SPC-3 addition */ + sg_put_unaligned_be16((uint16_t)mx_resp_len, inq_cdb + 3); + if (verbose) { + pr2ws(" inquiry cdb: "); + for (k = 0; k < INQUIRY_CMDLEN; ++k) + pr2ws("%02x ", inq_cdb[k]); + pr2ws("\n"); + } + if (resp && (mx_resp_len > 0)) { + up = (unsigned char *)resp; + up[0] = 0x7f; /* defensive prefill */ + if (mx_resp_len > 4) + up[4] = 0; + } + 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, inq_cdb, sizeof(inq_cdb)); + set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); + set_scsi_pt_data_in(ptvp, (unsigned char *)resp, mx_resp_len); + res = do_scsi_pt(ptvp, sg_fd, timeout_secs, verbose); + ret = sg_cmds_process_resp(ptvp, "inquiry", res, mx_resp_len, sense_b, + noisy, verbose, &sense_cat); + resid = get_scsi_pt_resid(ptvp); + if (residp) + *residp = resid; + destruct_scsi_pt_obj(ptvp); + 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 if (ret < 4) { + if (verbose) + pr2ws("%s: got too few bytes (%d)\n", __func__, ret); + ret = SG_LIB_CAT_MALFORMED; + } else + ret = 0; + + if (resid > 0) { + if (resid > mx_resp_len) { + pr2ws("INQUIRY resid (%d) should never exceed requested " + "len=%d\n", resid, mx_resp_len); + return ret ? ret : SG_LIB_CAT_MALFORMED; + } + /* zero unfilled section of response buffer */ + memset((unsigned char *)resp + (mx_resp_len - resid), 0, resid); + } + return ret; +} + /* Invokes a SCSI TEST UNIT READY command. * 'pack_id' is just for diagnostics, safe to set to 0. * Looks for progress indicator if 'progress' non-NULL; @@ -498,8 +586,8 @@ sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress, set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); set_scsi_pt_packet_id(ptvp, pack_id); res = do_scsi_pt(ptvp, sg_fd, DEF_PT_TIMEOUT, verbose); - ret = sg_cmds_process_resp(ptvp, tur_s, res, 0, sense_b, noisy, verbose, - &sense_cat); + ret = sg_cmds_process_resp(ptvp, tur_s, res, SG_NO_DATA_IN, sense_b, + noisy, verbose, &sense_cat); if (-1 == ret) ; else if (-2 == ret) { @@ -539,7 +627,7 @@ sg_ll_test_unit_ready(int sg_fd, int pack_id, bool noisy, int verbose) /* Invokes a SCSI REQUEST SENSE command. Returns 0 when successful, various * SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_request_sense(int sg_fd, int desc, void * resp, int mx_resp_len, +sg_ll_request_sense(int sg_fd, bool desc, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const rq_s = "request sense"; diff --git a/lib/sg_cmds_basic2.c b/lib/sg_cmds_basic2.c index f74a0644..08b1e2c2 100644 --- a/lib/sg_cmds_basic2.c +++ b/lib/sg_cmds_basic2.c @@ -100,7 +100,7 @@ create_pt_obj(const char * cname) /* Invokes a SCSI SYNCHRONIZE CACHE (10) command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_sync_cache_10(int sg_fd, int sync_nv, int immed, int group, +sg_ll_sync_cache_10(int sg_fd, bool sync_nv, bool immed, int group, unsigned int lba, unsigned int count, bool noisy, int verbose) { @@ -134,8 +134,8 @@ sg_ll_sync_cache_10(int sg_fd, int sync_nv, int immed, int group, set_scsi_pt_cdb(ptvp, sc_cdb, sizeof(sc_cdb)); set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); 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) { @@ -158,7 +158,7 @@ sg_ll_sync_cache_10(int sg_fd, int sync_nv, int immed, int group, /* Invokes a SCSI READ CAPACITY (16) command. Returns 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_readcap_16(int sg_fd, int pmi, uint64_t llba, void * resp, +sg_ll_readcap_16(int sg_fd, bool pmi, uint64_t llba, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const cdb_name_s = "read capacity(16)"; @@ -211,7 +211,7 @@ sg_ll_readcap_16(int sg_fd, int pmi, uint64_t llba, void * resp, /* Invokes a SCSI READ CAPACITY (10) command. Returns 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_readcap_10(int sg_fd, int pmi, unsigned int lba, void * resp, +sg_ll_readcap_10(int sg_fd, bool pmi, unsigned int lba, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const cdb_name_s = "read capacity(10)"; @@ -261,7 +261,7 @@ sg_ll_readcap_10(int sg_fd, int pmi, unsigned int lba, void * resp, /* Invokes a SCSI MODE SENSE (6) command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_mode_sense6(int sg_fd, int dbd, int pc, int pg_code, int sub_pg_code, +sg_ll_mode_sense6(int sg_fd, bool dbd, int pc, int pg_code, int sub_pg_code, void * resp, int mx_resp_len, bool noisy, int verbose) { static const char * const cdb_name_s = "mode sense(6)"; @@ -336,7 +336,7 @@ sg_ll_mode_sense6(int sg_fd, int dbd, int pc, int pg_code, int sub_pg_code, /* Invokes a SCSI MODE SENSE (10) command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_mode_sense10(int sg_fd, int llbaa, int dbd, int pc, int pg_code, +sg_ll_mode_sense10(int sg_fd, bool llbaa, bool dbd, int pc, int pg_code, int sub_pg_code, void * resp, int mx_resp_len, bool noisy, int verbose) { @@ -412,7 +412,7 @@ sg_ll_mode_sense10(int sg_fd, int llbaa, int dbd, int pc, int pg_code, /* Invokes a SCSI MODE SELECT (6) command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_mode_select6(int sg_fd, int pf, int sp, void * paramp, int param_len, +sg_ll_mode_select6(int sg_fd, bool pf, bool sp, void * paramp, int param_len, bool noisy, int verbose) { static const char * const cdb_name_s = "mode select(6)"; @@ -422,7 +422,7 @@ sg_ll_mode_select6(int sg_fd, int pf, int sp, void * paramp, int param_len, unsigned char sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; - modes_cdb[1] = (unsigned char)(((pf << 4) & 0x10) | (sp & 0x1)); + modes_cdb[1] = (unsigned char)((pf ? 0x10 : 0x0) | (sp ? 0x1 : 0x0)); modes_cdb[4] = (unsigned char)(param_len & 0xff); if (param_len > 0xff) { pr2ws("%s: param_len too big\n", cdb_name_s); @@ -445,8 +445,8 @@ sg_ll_mode_select6(int sg_fd, int pf, int sp, 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) { @@ -469,7 +469,7 @@ sg_ll_mode_select6(int sg_fd, int pf, int sp, void * paramp, int param_len, /* Invokes a SCSI MODE SELECT (10) command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_mode_select10(int sg_fd, int pf, int sp, void * paramp, int param_len, +sg_ll_mode_select10(int sg_fd, bool pf, bool sp, void * paramp, int param_len, bool noisy, int verbose) { static const char * const cdb_name_s = "mode select(10)"; @@ -479,7 +479,7 @@ sg_ll_mode_select10(int sg_fd, int pf, int sp, void * paramp, int param_len, unsigned char sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; - modes_cdb[1] = (unsigned char)(((pf << 4) & 0x10) | (sp & 0x1)); + modes_cdb[1] = (unsigned char)((pf ? 0x10 : 0x0) | (sp ? 0x1 : 0x0)); sg_put_unaligned_be16((int16_t)param_len, modes_cdb + 7); if (param_len > 0xffff) { pr2ws("%s: param_len too big\n", cdb_name_s); @@ -502,8 +502,8 @@ sg_ll_mode_select10(int sg_fd, int pf, int sp, 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) { @@ -526,12 +526,12 @@ sg_ll_mode_select10(int sg_fd, int pf, int sp, void * paramp, int param_len, /* MODE SENSE commands yield a response that has block descriptors followed * by mode pages. In most cases users are interested in the first mode page. * This function returns the (byte) offset of the start of the first mode - * page. Set mode_sense_6 to 1 for MODE SENSE (6) and 0 for MODE SENSE (10). - * Returns >= 0 is successful or -1 if failure. If there is a failure + * page. Set mode_sense_6 to true for MODE SENSE (6) and false for MODE SENSE + * 10). Returns >= 0 is successful or -1 if failure. If there is a failure * a message is written to err_buff if err_buff_len > 0. */ int sg_mode_page_offset(const unsigned char * resp, int resp_len, - int mode_sense_6, char * err_buff, int err_buff_len) + bool mode_sense_6, char * err_buff, int err_buff_len) { int bd_len, calc_len, offset; @@ -570,7 +570,7 @@ sg_mode_page_offset(const unsigned char * resp, int resp_len, /* Fetches current, changeable, default and/or saveable modes pages as * indicated by pcontrol_arr for given pg_code and sub_pg_code. If - * mode6==0 then use MODE SENSE (10) else use MODE SENSE (6). If + * mode6==false then use MODE SENSE (10) else use MODE SENSE (6). If * flexible set and mode data length seems wrong then try and * fix (compensating hack for bad device or driver). pcontrol_arr * should have 4 elements for output of current, changeable, default @@ -584,8 +584,8 @@ sg_mode_page_offset(const unsigned char * resp, int resp_len, * then stops and returns that error; otherwise continues if an error is * detected but returns the first error encountered. */ int -sg_get_mode_page_controls(int sg_fd, int mode6, int pg_code, int sub_pg_code, - int dbd, int flexible, int mx_mpage_len, +sg_get_mode_page_controls(int sg_fd, bool mode6, int pg_code, int sub_pg_code, + bool dbd, bool flexible, int mx_mpage_len, int * success_mask, void * pcontrol_arr[], int * reported_len, int verbose) { @@ -608,7 +608,7 @@ sg_get_mode_page_controls(int sg_fd, int mode6, int pg_code, int sub_pg_code, sub_pg_code, buff, MODE10_RESP_HDR_LEN, true, verbose); else - res = sg_ll_mode_sense10(sg_fd, 0 /* llbaa */, dbd, + res = sg_ll_mode_sense10(sg_fd, false /* llbaa */, dbd, 0 /* pc */, pg_code, sub_pg_code, buff, MODE10_RESP_HDR_LEN, true, verbose); if (0 != res) @@ -662,7 +662,7 @@ sg_get_mode_page_controls(int sg_fd, int mode6, int pg_code, int sub_pg_code, pg_code, sub_pg_code, buff, calc_len, true, verbose); else - res = sg_ll_mode_sense10(sg_fd, 0 /* llbaa */, dbd, + res = sg_ll_mode_sense10(sg_fd, false /* llbaa */, dbd, k /* pc */, pg_code, sub_pg_code, buff, calc_len, true, verbose); if (0 != res) { @@ -684,7 +684,7 @@ sg_get_mode_page_controls(int sg_fd, int mode6, int pg_code, int sub_pg_code, /* Invokes a SCSI LOG SENSE command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_log_sense(int sg_fd, int ppc, int sp, int pc, int pg_code, +sg_ll_log_sense(int sg_fd, bool ppc, bool sp, int pc, int pg_code, int subpg_code, int paramp, unsigned char * resp, int mx_resp_len, bool noisy, int verbose) { @@ -757,7 +757,7 @@ sg_ll_log_sense(int sg_fd, int ppc, int sp, int pc, int pg_code, /* Invokes a SCSI LOG SELECT command. Return of 0 -> success, * various SG_LIB_CAT_* positive values or -1 -> other errors */ int -sg_ll_log_select(int sg_fd, int pcr, int sp, int pc, int pg_code, +sg_ll_log_select(int sg_fd, bool pcr, bool sp, int pc, int pg_code, int subpg_code, unsigned char * paramp, int param_len, bool noisy, int verbose) { @@ -793,8 +793,8 @@ sg_ll_log_select(int sg_fd, int pcr, int sp, int pc, int pg_code, set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); set_scsi_pt_data_out(ptvp, 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) { @@ -823,8 +823,8 @@ sg_ll_log_select(int sg_fd, int pcr, int sp, int pc, int pg_code, * pc_mod__fl_num and noflush__fl arguments to this function. * */ int -sg_ll_start_stop_unit(int sg_fd, int immed, int pc_mod__fl_num, - int power_cond, int noflush__fl, int loej, int start, +sg_ll_start_stop_unit(int sg_fd, bool immed, int pc_mod__fl_num, + int power_cond, bool noflush__fl, bool loej, bool start, bool noisy, int verbose) { static const char * const cdb_name_s = "start stop unit"; @@ -833,10 +833,16 @@ sg_ll_start_stop_unit(int sg_fd, int immed, int pc_mod__fl_num, unsigned char ssuBlk[START_STOP_CMDLEN] = {START_STOP_CMD, 0, 0, 0, 0, 0}; unsigned char sense_b[SENSE_BUFF_LEN]; - ssuBlk[1] = immed & 1; + if (immed) + ssuBlk[1] = 0x1; ssuBlk[3] = pc_mod__fl_num & 0xf; /* bits 2 and 3 are reserved in MMC */ - ssuBlk[4] = ((power_cond & 0xf) << 4) | (noflush__fl ? 0x4 : 0) | - (loej ? 0x2 : 0) | (start ? 0x1 : 0); + ssuBlk[4] = ((power_cond & 0xf) << 4); + if (noflush__fl) + ssuBlk[4] |= 0x4; + if (loej) + ssuBlk[4] |= 0x2; + if (start) + ssuBlk[4] |= 0x1; if (verbose) { pr2ws(" %s command:", cdb_name_s); for (k = 0; k < (int)sizeof(ssuBlk); ++k) @@ -849,8 +855,8 @@ sg_ll_start_stop_unit(int sg_fd, int immed, int pc_mod__fl_num, set_scsi_pt_cdb(ptvp, ssuBlk, sizeof(ssuBlk)); set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); res = do_scsi_pt(ptvp, sg_fd, START_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) { @@ -901,8 +907,8 @@ sg_ll_prevent_allow(int sg_fd, int prevent, bool noisy, int verbose) set_scsi_pt_cdb(ptvp, p_cdb, sizeof(p_cdb)); set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); 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) { 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) { diff --git a/lib/sg_cmds_mmc.c b/lib/sg_cmds_mmc.c index c418023f..026662f4 100644 --- a/lib/sg_cmds_mmc.c +++ b/lib/sg_cmds_mmc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2016 Douglas Gilbert. + * Copyright (c) 2008-2017 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. @@ -97,8 +97,8 @@ sg_ll_set_cd_speed(int sg_fd, int rot_control, int drv_read_speed, set_scsi_pt_cdb(ptvp, scsCmdBlk, sizeof(scsCmdBlk)); set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); 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) { @@ -340,8 +340,8 @@ sg_ll_set_streaming(int sg_fd, int type, 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) { diff --git a/lib/sg_io_linux.c b/lib/sg_io_linux.c index 4ce41900..636b7fe4 100644 --- a/lib/sg_io_linux.c +++ b/lib/sg_io_linux.c @@ -118,7 +118,7 @@ sg_print_driver_status(int driver_status) static int sg_linux_sense_print(const char * leadin, int scsi_status, int host_status, int driver_status, const unsigned char * sense_buffer, - int sb_len, int raw_sinfo) + int sb_len, bool raw_sinfo) { bool done_leadin = false; bool done_sense = false; @@ -169,7 +169,7 @@ sg_linux_sense_print(const char * leadin, int scsi_status, int host_status, #ifdef SG_IO -int +bool sg_normalize_sense(const struct sg_io_hdr * hp, struct sg_scsi_sense_hdr * sshp) { @@ -185,7 +185,7 @@ sg_normalize_sense(const struct sg_io_hdr * hp, returns 0. */ int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp, - int raw_sinfo) + bool raw_sinfo) { return sg_linux_sense_print(leadin, hp->status, hp->host_status, hp->driver_status, hp->sbp, hp->sb_len_wr, @@ -198,7 +198,7 @@ sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp, int sg_chk_n_print(const char * leadin, int masked_status, int host_status, int driver_status, const unsigned char * sense_buffer, - int sb_len, int raw_sinfo) + int sb_len, bool raw_sinfo) { int scsi_status = (masked_status << 1) & 0x7e; diff --git a/lib/sg_lib.c b/lib/sg_lib.c index bf8be4d3..7014a0eb 100644 --- a/lib/sg_lib.c +++ b/lib/sg_lib.c @@ -318,10 +318,10 @@ sg_scsi_sense_desc_find(const unsigned char * sbp, int sb_len, return NULL; } -/* Returns 1 if valid bit set, 0 if valid bit clear. Irrespective the +/* Returns true if valid bit set, false if valid bit clear. Irrespective the * information field is written out via 'info_outp' (except when it is * NULL). Handles both fixed and descriptor sense formats. */ -int +bool sg_get_sense_info_fld(const unsigned char * sbp, int sb_len, uint64_t * info_outp) { @@ -331,13 +331,13 @@ sg_get_sense_info_fld(const unsigned char * sbp, int sb_len, if (info_outp) *info_outp = 0; if (sb_len < 7) - return 0; + return false; switch (sbp[0] & 0x7f) { case 0x70: case 0x71: if (info_outp) *info_outp = sg_get_unaligned_be32(sbp + 3); - return (sbp[0] & 0x80) ? 1 : 0; + return !!(sbp[0] & 0x80); case 0x72: case 0x73: bp = sg_scsi_sense_desc_find(sbp, sb_len, 0 /* info desc */); @@ -347,24 +347,24 @@ sg_get_sense_info_fld(const unsigned char * sbp, int sb_len, *info_outp = ull; return !!(bp[2] & 0x80); /* since spc3r23 should be set */ } else - return 0; + return false; default: - return 0; + return false; } } -/* Returns 1 if any of the 3 bits (i.e. FILEMARK, EOM or ILI) are set. +/* Returns true if any of the 3 bits (i.e. FILEMARK, EOM or ILI) are set. * In descriptor format if the stream commands descriptor not found - * then returns 0. Writes 1 or 0 corresponding to these bits to the - * last three arguments if they are non-NULL. */ -int + * then returns false. Writes true or false corresponding to these bits to + * the last three arguments if they are non-NULL. */ +bool sg_get_sense_filemark_eom_ili(const unsigned char * sbp, int sb_len, - int * filemark_p, int * eom_p, int * ili_p) + bool * filemark_p, bool * eom_p, bool * ili_p) { const unsigned char * bp; if (sb_len < 7) - return 0; + return false; switch (sbp[0] & 0x7f) { case 0x70: case 0x71: @@ -375,9 +375,9 @@ sg_get_sense_filemark_eom_ili(const unsigned char * sbp, int sb_len, *eom_p = !!(sbp[2] & 0x40); if (ili_p) *ili_p = !!(sbp[2] & 0x20); - return 1; + return true; } else - return 0; + return false; case 0x72: case 0x73: /* Look for stream commands sense data descriptor */ @@ -390,23 +390,23 @@ sg_get_sense_filemark_eom_ili(const unsigned char * sbp, int sb_len, *eom_p = !!(bp[3] & 0x40); if (ili_p) *ili_p = !!(bp[3] & 0x20); - return 1; + return true; } } - return 0; + return false; default: - return 0; + return false; } } -/* Returns 1 if SKSV is set and sense key is NO_SENSE or NOT_READY. Also - * returns 1 if progress indication sense data descriptor found. Places +/* Returns true if SKSV is set and sense key is NO_SENSE or NOT_READY. Also + * returns true if progress indication sense data descriptor found. Places * progress field from sense data where progress_outp points. If progress - * field is not available returns 0 and *progress_outp is unaltered. Handles - * both fixed and descriptor sense formats. - * Hint: if 1 is returned *progress_outp may be multiplied by 100 then + * field is not available returns false and *progress_outp is unaltered. + * Handles both fixed and descriptor sense formats. + * Hint: if true is returned *progress_outp may be multiplied by 100 then * divided by 65536 to get the percentage completion. */ -int +bool sg_get_sense_progress_fld(const unsigned char * sbp, int sb_len, int * progress_outp) { @@ -414,20 +414,20 @@ sg_get_sense_progress_fld(const unsigned char * sbp, int sb_len, int sk, sk_pr; if (sb_len < 7) - return 0; + return false; switch (sbp[0] & 0x7f) { case 0x70: case 0x71: sk = (sbp[2] & 0xf); if ((sb_len < 18) || ((SPC_SK_NO_SENSE != sk) && (SPC_SK_NOT_READY != sk))) - return 0; + return false; if (sbp[15] & 0x80) { /* SKSV bit set */ if (progress_outp) *progress_outp = sg_get_unaligned_be16(sbp + 16); - return 1; + return true; } else - return 0; + return false; case 0x72: case 0x73: /* sense key specific progress (0x2) or progress descriptor (0xa) */ @@ -437,16 +437,16 @@ sg_get_sense_progress_fld(const unsigned char * sbp, int sb_len, (0x6 == bp[1]) && (0x80 & bp[4])) { if (progress_outp) *progress_outp = sg_get_unaligned_be16(bp + 5); - return 1; + return true; } else if (((bp = sg_scsi_sense_desc_find(sbp, sb_len, 0xa))) && ((0x6 == bp[1]))) { if (progress_outp) *progress_outp = sg_get_unaligned_be16(bp + 6); - return 1; + return true; } else - return 0; + return false; default: - return 0; + return false; } } @@ -714,7 +714,7 @@ sg_get_desig_type_str(int val) int sg_get_designation_descriptor_str(const char * lip, const unsigned char * ddp, - int dd_len, int print_assoc, int do_long, + int dd_len, bool print_assoc, bool do_long, int blen, char * b) { int m, p_id, piv, c_set, assoc, desig_type, ci_off, c_id, d_id, naa; @@ -1459,7 +1459,7 @@ sg_get_sense_descriptors_str(const char * lip, const unsigned char * sbp, if (add_d_len > 2) { /* recursing; hope not to get carried away */ n += scnpr(b + n, blen - n, "%s vvvvvvvvvvvvvvvv\n", lip); - sg_get_sense_str(lip, descp + 4, add_d_len - 2, 0, + sg_get_sense_str(lip, descp + 4, add_d_len - 2, false, sizeof(c), c); n += scnpr(b + n, blen - n, "%s", c); n += scnpr(b + n, blen - n, "%s ^^^^^^^^^^^^^^^^\n", lip); @@ -1507,7 +1507,8 @@ sg_get_sense_descriptors_str(const char * lip, const unsigned char * sbp, n += scnpr(b + n, blen - n, "%s Usage reason: " "reserved[%d]\n", lip, descp[3]); n += sg_get_designation_descriptor_str(z, descp + 4, descp[1] - 2, - 1, 0, blen - n, b + n); + true, false, blen - n, + b + n); break; case 0xf: /* Added in SPC-5 rev 10 (for Write buffer) */ n += scnpr(b + n, blen - n, "Microcode activation "); @@ -1585,7 +1586,7 @@ sg_get_sense_sat_pt_fixed_str(const char * lip, const unsigned char * sp, /* Fetch sense information */ int sg_get_sense_str(const char * lip, const unsigned char * sbp, int sb_len, - int raw_sinfo, int buff_len, char * buff) + bool raw_sinfo, int buff_len, char * buff) { int len, progress, n, r, pr, rem, blen; unsigned int info; @@ -1796,7 +1797,7 @@ sg_get_sense_str(const char * lip, const unsigned char * sbp, int sb_len, /* Print sense information */ void sg_print_sense(const char * leadin, const unsigned char * sbp, int sb_len, - int raw_sinfo) + bool raw_sinfo) { char b[2048]; @@ -1805,14 +1806,14 @@ sg_print_sense(const char * leadin, const unsigned char * sbp, int sb_len, } /* See description in sg_lib.h header file */ -int +bool sg_scsi_normalize_sense(const unsigned char * sbp, int sb_len, struct sg_scsi_sense_hdr * sshp) { if (sshp) memset(sshp, 0, sizeof(struct sg_scsi_sense_hdr)); if ((NULL == sbp) || (0 == sb_len) || (0x70 != (0x70 & sbp[0]))) - return 0; + return false; if (sshp) { sshp->response_code = (0x7f & sbp[0]); if (sshp->response_code >= 0x72) { /* descriptor format */ @@ -1836,7 +1837,7 @@ sg_scsi_normalize_sense(const unsigned char * sbp, int sb_len, } } } - return 1; + return true; } /* Returns a SG_LIB_CAT_* value. If cannot decode sense buffer (sbp) or a @@ -2247,18 +2248,21 @@ sg_get_category_sense_str(int sense_cat, int buff_len, char * buff, return buff; } -static const char * sg_sfs_spc_reserved = "SPC reserved"; -static const char * sg_sfs_sbc_reserved = "SBC reserved"; -static const char * sg_sfs_ssc_reserved = "SSC reserved"; -static const char * sg_sfs_zbc_reserved = "ZBC reserved"; +static const char * sg_sfs_spc_reserved = "SPC Reserved"; +static const char * sg_sfs_sbc_reserved = "SBC Reserved"; +static const char * sg_sfs_ssc_reserved = "SSC Reserved"; +static const char * sg_sfs_zbc_reserved = "ZBC Reserved"; static const char * sg_sfs_reserved = "Reserved"; /* Yield SCSI Feature Set (sfs) string. When 'peri_type' is < -1 (or > 31) * returns pointer to string (same as 'buff') associated with 'sfs_code'. * When 'peri_type' is between -1 (for SPC) and 31 (inclusive) then a match - * on both 'sfs_code' and 'peri_type' is required. If a match is found and - * 'foundp' is not NULL then the bool it points to is set to true; else if - * 'foundp' is not NULL then the bool it points to is set to false. + * on both 'sfs_code' and 'peri_type' is required. If 'foundp' is not NULL + * then where it points is set to true if a match is found else it is set to + * false. If 'buff' is not NULL then in the case of a match a descriptive + * string is written to 'buff' while if there is not a not then a string + * ending in "Reserved" is written (and may be prefixed with SPC, SBC, SSC + * or ZBC). Returns 'buff' (i.e. a pointer value) even if it is NULL. * Example: * char b[64]; * ... @@ -2711,7 +2715,7 @@ sg_get_num(const char * buf) if (n == len) return -1; buf += n; - len -=n; + len -= n; } /* following hack to keep C++ happy */ cp = strpbrk((char *)buf, " \t,#-"); @@ -2850,7 +2854,7 @@ sg_get_llnum(const char * buf) len -= n; } /* following hack to keep C++ happy */ - cp = strpbrk((char *)buf, " \t-,#"); + cp = strpbrk((char *)buf, " \t,#-"); if (cp) { len = cp - buf; n = (int)sizeof(lb) - 1; @@ -2861,10 +2865,10 @@ sg_get_llnum(const char * buf) } else b = buf; if (('0' == b[0]) && (('x' == b[1]) || ('X' == b[1]))) { - res = sscanf(b + 2, "%" SCNx64 "", &unum); + res = sscanf(b + 2, "%" SCNx64 , &unum); num = unum; } else if ('H' == toupper((int)b[len - 1])) { - res = sscanf(b, "%" SCNx64 "", &unum); + res = sscanf(b, "%" SCNx64 , &unum); num = unum; } else res = sscanf(b, "%" SCNd64 "%c%c%c", &num, &c, &c2, &c3); diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c index ded09df5..d7840bb2 100644 --- a/lib/sg_lib_data.c +++ b/lib/sg_lib_data.c @@ -17,7 +17,7 @@ #endif -const char * sg_lib_version_str = "2.29 20170920";/* spc5r17, sbc4r14 */ +const char * sg_lib_version_str = "2.30 20171003";/* spc5r17, sbc4r14 */ /* indexed by pdt; those that map to own index do not decay */ diff --git a/lib/sg_pt_common.c b/lib/sg_pt_common.c index 357816a4..c3177791 100644 --- a/lib/sg_pt_common.c +++ b/lib/sg_pt_common.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2014 Douglas Gilbert. + * Copyright (c) 2009-2017 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. @@ -14,7 +14,7 @@ #endif -static const char * scsi_pt_version_str = "2.12 20140606"; +static const char * scsi_pt_version_str = "2.13 20171005"; const char * scsi_pt_version() diff --git a/lib/sg_pt_freebsd.c b/lib/sg_pt_freebsd.c index 8adf3160..cfb362a7 100644 --- a/lib/sg_pt_freebsd.c +++ b/lib/sg_pt_freebsd.c @@ -1,15 +1,16 @@ /* - * Copyright (c) 2005-2016 Douglas Gilbert. + * Copyright (c) 2005-2017 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. */ -/* sg_pt_freebsd version 1.14 20160405 */ +/* sg_pt_freebsd version 1.15 20171005 */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> +#include <stdbool.h> #include <string.h> #include <sys/types.h> #include <dirent.h> @@ -95,7 +96,7 @@ pr2ws(const char * fmt, ...) /* Returns >= 0 if successful. If error in Unix returns negated errno. */ int -scsi_pt_open_device(const char * device_name, int read_only, int verbose) +scsi_pt_open_device(const char * device_name, bool read_only, int verbose) { int oflags = 0 /* O_NONBLOCK*/ ; diff --git a/lib/sg_pt_linux.c b/lib/sg_pt_linux.c index 19c84cd1..a88e179b 100644 --- a/lib/sg_pt_linux.c +++ b/lib/sg_pt_linux.c @@ -1,16 +1,17 @@ /* - * Copyright (c) 2005-2016 Douglas Gilbert. + * Copyright (c) 2005-2017 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. */ -/* sg_pt_linux version 1.26 20160405 */ +/* sg_pt_linux version 1.27 20171005 */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> +#include <stdbool.h> #include <string.h> #include <ctype.h> #include <unistd.h> @@ -130,7 +131,7 @@ struct sg_pt_base { /* Returns >= 0 if successful. If error in Unix returns negated errno. */ int -scsi_pt_open_device(const char * device_name, int read_only, int verbose) +scsi_pt_open_device(const char * device_name, bool read_only, int verbose) { int oflags = O_NONBLOCK; @@ -586,7 +587,7 @@ find_bsg_major(int verbose) /* Returns >= 0 if successful. If error in Unix returns negated errno. */ int -scsi_pt_open_device(const char * device_name, int read_only, int verbose) +scsi_pt_open_device(const char * device_name, bool read_only, int verbose) { int oflags = O_NONBLOCK; diff --git a/lib/sg_pt_osf1.c b/lib/sg_pt_osf1.c index 06e48b1a..d2d35b7b 100644 --- a/lib/sg_pt_osf1.c +++ b/lib/sg_pt_osf1.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2016 Douglas Gilbert. + * Copyright (c) 2005-2017 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. @@ -20,6 +20,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> +#include <stdbool.h> #include <string.h> #include <errno.h> @@ -85,7 +86,7 @@ pr2ws(const char * fmt, ...) /* Returns >= 0 if successful. If error in Unix returns negated errno. */ int -scsi_pt_open_device(const char * device_name, int read_only, int verbose) +scsi_pt_open_device(const char * device_name, bool read_only, int verbose) { int oflags = 0 /* O_NONBLOCK*/ ; diff --git a/lib/sg_pt_solaris.c b/lib/sg_pt_solaris.c index 497acf91..b05aafe8 100644 --- a/lib/sg_pt_solaris.c +++ b/lib/sg_pt_solaris.c @@ -1,14 +1,16 @@ /* - * Copyright (c) 2007-2015 Douglas Gilbert. + * Copyright (c) 2007-2017 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. */ -/* sg_pt_solaris version 1.04 20151220 */ +/* sg_pt_solaris version 1.05 20171005 */ #include <stdio.h> #include <stdlib.h> +#include <stdarg.h> +#include <stdbool.h> #include <string.h> #include <ctype.h> #include <unistd.h> @@ -46,7 +48,7 @@ struct sg_pt_base { /* Returns >= 0 if successful. If error in Unix returns negated errno. */ int -scsi_pt_open_device(const char * device_name, int read_only, int verbose) +scsi_pt_open_device(const char * device_name, bool read_only, int verbose) { int oflags = 0 /* O_NONBLOCK*/ ; diff --git a/lib/sg_pt_win32.c b/lib/sg_pt_win32.c index d157fbe6..a36de817 100644 --- a/lib/sg_pt_win32.c +++ b/lib/sg_pt_win32.c @@ -1,11 +1,11 @@ /* - * Copyright (c) 2006-2016 Douglas Gilbert. + * Copyright (c) 2006-2017 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. */ -/* sg_pt_win32 version 1.16 20150511 */ +/* sg_pt_win32 version 1.17 20171005 */ #include <stdio.h> #include <stdlib.h> @@ -139,7 +139,7 @@ scsi_pt_win32_spt_state(void) /* Returns >= 0 if successful. If error in Unix returns negated errno. */ int -scsi_pt_open_device(const char * device_name, int read_only, int verbose) +scsi_pt_open_device(const char * device_name, bool read_only, int verbose) { int oflags = 0 /* O_NONBLOCK*/ ; |