"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/sg_write_x.c" between
sg3_utils-1.47r908.tgz and sg3_utils-1.47r915.tar.xz

About: sg3_utils contains utilities that send SCSI commands to devices. Beta version.

sg_write_x.c  (sg3_utils-1.47r908.tgz):sg_write_x.c  (sg3_utils-1.47r915.tar.xz)
skipping to change at line 41 skipping to change at line 41
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#include "sg_lib.h" #include "sg_lib.h"
#include "sg_pt.h" #include "sg_pt.h"
#include "sg_cmds_basic.h" #include "sg_cmds_basic.h"
#include "sg_cmds_extra.h" #include "sg_cmds_extra.h"
#include "sg_unaligned.h" #include "sg_unaligned.h"
#include "sg_pr2serr.h" #include "sg_pr2serr.h"
static const char * version_str = "1.26 20210630"; static const char * version_str = "1.28 20210923";
/* Protection Information refers to 8 bytes of extra information usually /* Protection Information refers to 8 bytes of extra information usually
* associated with each logical block and is often abbreviated to PI while * associated with each logical block and is often abbreviated to PI while
* its fields: reference-tag (4 bytes), application-tag (2 bytes) and * its fields: reference-tag (4 bytes), application-tag (2 bytes) and
* tag-mask (2 bytes) are often abbreviated to RT, AT and TM respectively. * tag-mask (2 bytes) are often abbreviated to RT, AT and TM respectively.
* And the LBA Range Descriptor associated with the WRITE SCATTERED command * And the LBA Range Descriptor associated with the WRITE SCATTERED command
* is abbreviated to RD. A degenerate RD is one where length components, * is abbreviated to RD. A degenerate RD is one where length components,
( and perhaps the LBA, are zero; it is not illegal according to T10 but are ( and perhaps the LBA, are zero; it is not illegal according to T10 but are
* a little tricky to handle when scanning and little extra information * a little tricky to handle when scanning and little extra information
* is provided. */ * is provided. */
skipping to change at line 805 skipping to change at line 805
* else error number. If ok also yields the number of LBA range descriptors * else error number. If ok also yields the number of LBA range descriptors
* written in num_scat_elems and the sum of NUM elements found. Note that * written in num_scat_elems and the sum of NUM elements found. Note that
* sum_num is not initialized to 0. If parse_one is true then exits * sum_num is not initialized to 0. If parse_one is true then exits
* after one LBA range descriptor is decoded. */ * after one LBA range descriptor is decoded. */
static int static int
build_t10_scat(const char * scat_fname, bool do_16, bool parse_one, build_t10_scat(const char * scat_fname, bool do_16, bool parse_one,
uint8_t * t10_scat_list_out, uint16_t * num_scat_elems, uint8_t * t10_scat_list_out, uint16_t * num_scat_elems,
uint32_t * sum_num, uint32_t max_list_blen) uint32_t * sum_num, uint32_t max_list_blen)
{ {
bool have_stdin = false; bool have_stdin = false;
bool del_fp = false;
bool bit0, ok; bool bit0, ok;
int off = 0; int off = 0;
int in_len, k, j, m, n, res, err; int in_len, k, j, m, n, res, err;
int64_t ll; int64_t ll;
char * lcp; char * lcp;
uint8_t * up = t10_scat_list_out; uint8_t * up = t10_scat_list_out;
FILE * fp = NULL; FILE * fp = NULL;
char line[1024]; char line[1024];
if (up) { if (up) {
skipping to change at line 835 skipping to change at line 836
fp = stdin; fp = stdin;
scat_fname = "<stdin>"; scat_fname = "<stdin>";
} else { } else {
fp = fopen(scat_fname, "r"); fp = fopen(scat_fname, "r");
if (NULL == fp) { if (NULL == fp) {
err = errno; err = errno;
pr2serr("%s: unable to open %s: %s\n", __func__, scat_fname, pr2serr("%s: unable to open %s: %s\n", __func__, scat_fname,
safe_strerror(err)); safe_strerror(err));
return sg_convert_errno(err); return sg_convert_errno(err);
} }
del_fp = true;
} }
for (j = 0; j < 1024; ++j) {/* loop over lines in file */ for (j = 0; j < 1024; ++j) {/* loop over lines in file */
if ((max_list_blen > 0) && ((n + lbard_sz) > max_list_blen)) if ((max_list_blen > 0) && ((n + lbard_sz) > max_list_blen))
goto fini; goto fini;
if (NULL == fgets(line, sizeof(line), fp)) if (NULL == fgets(line, sizeof(line), fp))
break; break;
// could improve with carry_over logic if sizeof(line) too small // could improve with carry_over logic if sizeof(line) too small
in_len = strlen(line); in_len = strlen(line);
if (in_len > 0) { if (in_len > 0) {
if ('\n' == line[in_len - 1]) { if ('\n' == line[in_len - 1]) {
skipping to change at line 929 skipping to change at line 931
} /* inner for loop(k) over line elements */ } /* inner for loop(k) over line elements */
off += (k + 1); off += (k + 1);
} /* outer for loop(j) over lines */ } /* outer for loop(j) over lines */
if (do_16 && (0x1 & off)) { if (do_16 && (0x1 & off)) {
pr2serr("%s: expect LBA,NUM pairs but decoded odd number\n from " pr2serr("%s: expect LBA,NUM pairs but decoded odd number\n from "
"%s\n", __func__, scat_fname); "%s\n", __func__, scat_fname);
goto bad_exit; goto bad_exit;
} }
fini: fini:
*num_scat_elems = (n / lbard_sz) - 1; *num_scat_elems = (n / lbard_sz) - 1;
if (fp && (stdin != fp)) if (del_fp)
fclose(fp); fclose(fp);
return 0; return 0;
bad_exit: bad_exit:
if (fp && (stdin != fp)) if (del_fp)
fclose(fp); fclose(fp);
return SG_LIB_SYNTAX_ERROR; return SG_LIB_SYNTAX_ERROR;
bad_mem_exit: bad_mem_exit:
if (fp && (stdin != fp)) if (del_fp)
fclose(fp); fclose(fp);
return SG_LIB_CAT_NOT_READY; /* flag output buffer too small */ return SG_LIB_CAT_NOT_READY; /* flag output buffer too small */
} }
static bool static bool
is_pi_default(const struct opts_t * op) is_pi_default(const struct opts_t * op)
{ {
return ((DEF_AT == op->app_tag) && (DEF_RT == op->ref_tag) && return ((DEF_AT == op->app_tag) && (DEF_RT == op->ref_tag) &&
(DEF_TM == op->tag_mask)); (DEF_TM == op->tag_mask));
} }
skipping to change at line 1335 skipping to change at line 1337
set_scsi_pt_cdb(ptvp, x_cdb, cdb_len); set_scsi_pt_cdb(ptvp, x_cdb, cdb_len);
set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
if (dout_len > 0) if (dout_len > 0)
set_scsi_pt_data_out(ptvp, (uint8_t *)dataoutp, dout_len); set_scsi_pt_data_out(ptvp, (uint8_t *)dataoutp, dout_len);
else if (vb && (! op->ndob)) else if (vb && (! op->ndob))
pr2serr("%s: dout_len==0, so empty dout buffer\n", pr2serr("%s: dout_len==0, so empty dout buffer\n",
op->cdb_name); op->cdb_name);
res = do_scsi_pt(ptvp, sg_fd, op->timeout, vb); res = do_scsi_pt(ptvp, sg_fd, op->timeout, vb);
ret = sg_cmds_process_resp(ptvp, op->cdb_name, res, true /*noisy */, vb, ret = sg_cmds_process_resp(ptvp, op->cdb_name, res, true /*noisy */, vb,
&sense_cat); &sense_cat);
if (-1 == ret) if (-1 == ret) {
ret = sg_convert_errno(get_scsi_pt_os_err(ptvp)); if (get_scsi_pt_transport_err(ptvp))
else if (-2 == ret) { ret = SG_LIB_TRANSPORT_ERROR;
else
ret = sg_convert_errno(get_scsi_pt_os_err(ptvp));
} else if (-2 == ret) {
switch (sense_cat) { switch (sense_cat) {
case SG_LIB_CAT_RECOVERED: case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE: case SG_LIB_CAT_NO_SENSE:
ret = 0; ret = 0;
break; break;
case SG_LIB_CAT_MEDIUM_HARD: case SG_LIB_CAT_MEDIUM_HARD:
{ {
bool valid; bool valid;
int slen; int slen;
uint64_t ull = 0; uint64_t ull = 0;
 End of changes. 7 change blocks. 
7 lines changed or deleted 12 lines changed or added

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