diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2016-02-28 04:46:32 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2016-02-28 04:46:32 +0000 |
commit | 1c1b89e65392808cab0275b914bf6f76f1dff1c2 (patch) | |
tree | f9974559bb26b6c41b53752f6e69981bbd20e9bd /src | |
parent | 83415041e1e9a9b93e743069ca7600af31ddb839 (diff) | |
download | sg3_utils-1c1b89e65392808cab0275b914bf6f76f1dff1c2.tar.gz |
sg_sanitize+sg_format: add --timeout=SEC option; sg_reassign+sg_write_same: fix ULONG_MAX problem
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@680 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r-- | src/sg_copy_results.c | 7 | ||||
-rw-r--r-- | src/sg_format.c | 124 | ||||
-rw-r--r-- | src/sg_inq.c | 6 | ||||
-rw-r--r-- | src/sg_reassign.c | 10 | ||||
-rw-r--r-- | src/sg_requests.c | 12 | ||||
-rw-r--r-- | src/sg_sanitize.c | 43 | ||||
-rw-r--r-- | src/sg_senddiag.c | 2 | ||||
-rw-r--r-- | src/sg_sync.c | 8 | ||||
-rw-r--r-- | src/sg_turs.c | 33 | ||||
-rw-r--r-- | src/sg_write_same.c | 12 | ||||
-rw-r--r-- | src/sg_xcopy.c | 38 |
11 files changed, 175 insertions, 120 deletions
diff --git a/src/sg_copy_results.c b/src/sg_copy_results.c index 38d7f9ab..1f490d07 100644 --- a/src/sg_copy_results.c +++ b/src/sg_copy_results.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Hannes Reinecke, SUSE Labs + * Copyright (c) 2011-2016 Hannes Reinecke, SUSE Labs * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. @@ -36,7 +36,7 @@ and the optional list identifier passed as the list_id argument. */ -static const char * version_str = "1.12 20150227"; +static const char * version_str = "1.13 20160227"; #define MAX_XFER_LEN 10000 @@ -408,7 +408,8 @@ main(int argc, char * argv[]) if (sg_fd < 0) { pr2serr(ME "open error: %s: %s\n", device_name, safe_strerror(-sg_fd)); - return SG_LIB_FILE_ERROR; + ret = SG_LIB_FILE_ERROR; + goto finish; } if ((sa < 0) || (sa >= (int)(sizeof(rec_copy_name_arr) / sizeof(char *)))) diff --git a/src/sg_format.c b/src/sg_format.c index 9535a867..a96b69cf 100644 --- a/src/sg_format.c +++ b/src/sg_format.c @@ -36,7 +36,7 @@ #include "sg_pr2serr.h" #include "sg_pt.h" -static const char * version_str = "1.34 20160209"; +static const char * version_str = "1.35 20160227"; #define RW_ERROR_RECOVERY_PAGE 1 /* can give alternate with --mode=MP */ @@ -86,8 +86,9 @@ struct opts_t { bool do_rcap16; /* -l */ bool resize; /* -r */ bool rto_req; /* -R, deprecated, prefer fmtpinfo */ - int tape; /* -T <format>, def: -1 */ int sec_init; /* -S */ + int tape; /* -T <format>, def: -1 */ + int timeout; /* -m SEC, def: depends on IMMED bit */ int verbose; /* -v */ int verify; /* -y */ const char * device_name; @@ -119,6 +120,7 @@ static struct option long_options[] = { {"six", no_argument, 0, '6'}, {"size", required_argument, 0, 's'}, {"tape", required_argument, 0, 'T'}, + {"timeout", required_argument, 0, 'm'}, {"verbose", no_argument, 0, 'v'}, {"verify", no_argument, 0, 'y'}, {"version", no_argument, 0, 'V'}, @@ -138,9 +140,9 @@ usage() "[--pie=PIE] [--pinfo]\n" " [--poll=PT] [--resize] [--rto_req] " "[--security] [--six]\n" - " [--size=SIZE] [--tape=FM] [--verbose] " - "[--verify]\n" - " [--version] [--wait] DEVICE\n" + " [--size=SIZE] [--tape=FM] [--timeout=SEC] " + "[--verbose]\n" + " [--verify] [--version] [--wait] DEVICE\n" " where:\n" " --cmplst=0|1\n" " -C 0|1 sets CMPLST bit in format cdb " @@ -195,6 +197,8 @@ usage() " --tape=FM|-T FM request FORMAT MEDIUM with FORMAT " "field set\n" " to FM (def: 0 --> default format)\n" + " --timeout=SEC|-m SEC FORMAT UNIT/MEDIUM command " + "timeout in seconds\n" " --verbose|-v increase verbosity\n" " --verify|-y sets VERIFY bit in FORMAT MEDIUM (tape)\n" " --version|-V print version details and exit\n" @@ -273,7 +277,7 @@ static int scsi_format_unit(int fd, const struct opts_t * op) { int res, need_hdr, progress, pr, rem, verb, fmt_pl_sz, longlist, off; - int resp_len, ip_desc; + int resp_len, ip_desc, timeout; int immed = ! op->fwait; const int SH_FORMAT_HEADER_SZ = 4; const int LO_FORMAT_HEADER_SZ = 8; @@ -283,6 +287,9 @@ scsi_format_unit(int fd, const struct opts_t * op) char b[80]; memset(fmt_pl, 0, sizeof(fmt_pl)); + timeout = (immed ? SHORT_TIMEOUT : FORMAT_TIMEOUT); + if (op->timeout > timeout) + timeout = op->timeout; longlist = (op->pie > 0); ip_desc = (op->ip_def || op->sec_init); off = longlist ? LO_FORMAT_HEADER_SZ : SH_FORMAT_HEADER_SZ; @@ -308,8 +315,7 @@ scsi_format_unit(int fd, const struct opts_t * op) res = sg_ll_format_unit2(fd, op->fmtpinfo, longlist, need_hdr/* FMTDATA*/, op->cmplst, 0 /* DEFECT_LIST_FORMAT */, op->ffmt, - (immed ? SHORT_TIMEOUT : FORMAT_TIMEOUT), - fmt_pl, fmt_pl_sz, 1, op->verbose); + timeout, fmt_pl, fmt_pl_sz, 1, op->verbose); if (res) { sg_get_category_sense_str(res, sizeof(b), b, op->verbose); pr2serr("Format unit command: %s\n", b); @@ -374,37 +380,40 @@ scsi_format_unit(int fd, const struct opts_t * op) } #if 0 for (k = 0; k < num_rs; ++k) { - if (k > 0) - sleep_for(30); - memset(requestSenseBuff, 0x0, sizeof(requestSenseBuff)); - res = sg_ll_request_sense(sg_fd, desc, requestSenseBuff, maxlen, - 1, op->verbose); - if (res) { - ret = res; - sg_get_category_sense_str(res, sizeof(b), b, op->verbose); - pr2serr("Request Sense command: %s\n", b); - break; - } - /* "Additional sense length" same in descriptor and fixed */ - resp_len = requestSenseBuff[7] + 8; - if (op->verbose > 1) { - pr2serr("Parameter data in hex\n"); - dStrHexErr((const char *)requestSenseBuff, resp_len, 1); - } - progress = -1; - sg_get_sense_progress_fld(requestSenseBuff, resp_len, - &progress); - if (progress < 0) { - ret = res; - if (op->verbose > 1) - pr2serr("No progress indication found, iteration %d\n", - k + 1); - /* N.B. exits first time there isn't a progress indication */ - break; - } else - printf("Progress indication: %d.%02d%% done\n", - (progress * 100) / 65536, - ((progress * 100) % 65536) / 656); + if (k > 0) + sleep_for(30); + memset(requestSenseBuff, 0x0, sizeof(requestSenseBuff)); + res = sg_ll_request_sense(sg_fd, desc, requestSenseBuff, + maxlen, 1, op->verbose); + if (res) { + ret = res; + sg_get_category_sense_str(res, sizeof(b), b, + op->verbose); + pr2serr("Request Sense command: %s\n", b); + break; + } + /* "Additional sense length" same in descriptor and fixed */ + resp_len = requestSenseBuff[7] + 8; + if (op->verbose > 1) { + pr2serr("Parameter data in hex\n"); + dStrHexErr((const char *)requestSenseBuff, resp_len, + 1); + } + progress = -1; + sg_get_sense_progress_fld(requestSenseBuff, resp_len, + &progress); + if (progress < 0) { + ret = res; + if (op->verbose > 1) + pr2serr("No progress indication found, " + "iteration %d\n", k + 1); + /* N.B. exits first time there isn't a + * progress indication */ + break; + } else + printf("Progress indication: %d.%02d%% done\n", + (progress * 100) / 65536, + ((progress * 100) % 65536) / 656); } #endif printf("FORMAT UNIT Complete\n"); @@ -415,14 +424,16 @@ scsi_format_unit(int fd, const struct opts_t * op) static int scsi_format_medium(int fd, const struct opts_t * op) { - int res, progress, pr, rem, verb, resp_len; + int res, progress, pr, rem, verb, resp_len, timeout; int immed = ! op->fwait; unsigned char reqSense[MAX_BUFF_SZ]; char b[80]; + timeout = (immed ? SHORT_TIMEOUT : FORMAT_TIMEOUT); + if (op->timeout > timeout) + timeout = op->timeout; res = sg_ll_format_medium(fd, op->verify, immed, 0xf & op->tape, NULL, - 0, (immed ? SHORT_TIMEOUT : FORMAT_TIMEOUT), - 1, op->verbose); + 0, timeout, 1, op->verbose); if (res) { sg_get_category_sense_str(res, sizeof(b), b, op->verbose); pr2serr("Format medium command: %s\n", b); @@ -707,11 +718,11 @@ print_read_cap(int fd, const struct opts_t * op) last_blk_addr = sg_get_unaligned_be32(resp_buff + 0); block_size = sg_get_unaligned_be32(resp_buff + 4); if (0xffffffff == last_blk_addr) { - if (op->verbose) - printf("Read Capacity (10) reponse " - "indicates that Read Capacity (16) " - "is required\n"); - return -2; + if (op->verbose) + printf("Read Capacity (10) reponse " + "indicates that Read Capacity " + "(16) is required\n"); + return -2; } printf("Read Capacity (10) results:\n"); printf(" Number of logical blocks=%u\n", @@ -750,7 +761,7 @@ main(int argc, char **argv) int c; c = getopt_long(argc, argv, - "c:C:Def:FhIlM:pP:q:rRs:St:T:vVwx:y6", + "c:C:Def:FhIlm:M:pP:q:rRs:St:T:vVwx:y6", long_options, &option_index); if (c == -1) break; @@ -802,6 +813,14 @@ main(int argc, char **argv) op->long_lba = true; op->do_rcap16 = true; break; + case 'm': + op->timeout = sg_get_num(optarg); + if (op->timeout < 0) { + pr2serr("bad argument to '--timeout=', " + "accepts 0 or more\n"); + return SG_LIB_SYNTAX_ERROR; + } + break; case 'M': op->mode_page = sg_get_num(optarg); if ((op->mode_page < 0) || ( op->mode_page > 62)) { @@ -1156,8 +1175,7 @@ again_with_long_lba: if (op->resize) { printf("Resize operation seems to have been successful\n"); goto out; - } - else if (! op->format) { + } else if (! op->format) { res = print_read_cap(fd, op); if (-2 == res) { op->do_rcap16 = 1; @@ -1174,10 +1192,10 @@ again_with_long_lba: } if ((PDT_TAPE == pdt) || (PDT_MCHANGER == pdt) || (PDT_ADC == pdt)) - printf("No changes made. To format use '--tape='.\n"); + printf("No changes made. To format use '--tape='.\n"); else - printf("No changes made. To format use '--format'. To " - "resize use '--resize'\n"); + printf("No changes made. To format use '--format'. " + "To resize use '--resize'\n"); goto out; } diff --git a/src/sg_inq.c b/src/sg_inq.c index e4bcfd3d..6c58a5dd 100644 --- a/src/sg_inq.c +++ b/src/sg_inq.c @@ -382,7 +382,7 @@ usage_for(const struct opts_t * op) static void usage_for(const struct opts_t * op) { - op = op; + if (op) { } /* suppress warning */ usage(); } @@ -3380,8 +3380,8 @@ cmddt_process(int sg_fd, const struct opts_t * op) static int cmddt_process(int sg_fd, const struct opts_t * op) { - sg_fd = sg_fd; - op = op; + if (sg_fd) { } /* suppress warning */ + if (op) { } /* suppress warning */ pr2serr("'--cmddt' not implemented, use sg_opcodes\n"); return 0; } diff --git a/src/sg_reassign.c b/src/sg_reassign.c index d6882dff..02ed33a9 100644 --- a/src/sg_reassign.c +++ b/src/sg_reassign.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2015 Douglas Gilbert. + * Copyright (c) 2005-2016 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. @@ -34,12 +34,16 @@ * vendor specific data is written. */ -static const char * version_str = "1.17 20151207"; +static const char * version_str = "1.18 20160226"; #define DEF_DEFECT_LIST_FORMAT 4 /* bytes from index */ #define MAX_NUM_ADDR 1024 +#ifndef UINT32_MAX +#define UINT32_MAX ((uint32_t)-1) +#endif + static struct option long_options[] = { {"address", 1, 0, 'a'}, @@ -350,7 +354,7 @@ main(int argc, char * argv[]) } if (got_addr) { for (k = 0; k < addr_arr_len; ++k) { - if (addr_arr[k] >= ULONG_MAX) { + if (addr_arr[k] >= UINT32_MAX) { if (eight < 0) { eight = 1; break; diff --git a/src/sg_requests.c b/src/sg_requests.c index 29c611c9..fc691ebe 100644 --- a/src/sg_requests.c +++ b/src/sg_requests.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2015 Douglas Gilbert. + * Copyright (c) 2004-2016 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. @@ -26,7 +26,7 @@ * This program issues the SCSI command REQUEST SENSE to the given SCSI device. */ -static const char * version_str = "1.26 20151219"; +static const char * version_str = "1.27 20160226"; #define MAX_REQS_RESP_LEN 255 #define DEF_REQS_RESP_LEN 252 @@ -51,6 +51,7 @@ static struct option long_options[] = { {"hex", no_argument, 0, 'H'}, {"maxlen", required_argument, 0, 'm'}, {"num", required_argument, 0, 'n'}, + {"number", required_argument, 0, 'n'}, {"progress", no_argument, 0, 'p'}, {"raw", no_argument, 0, 'r'}, {"status", no_argument, 0, 's'}, @@ -65,9 +66,9 @@ usage() { pr2serr("Usage: sg_requests [--desc] [--help] [--hex] [--maxlen=LEN] " "[--num=NUM]\n" - " [--progress] [--raw] [--status] [--time] " - "[--verbose]\n" - " [--version] DEVICE\n" + " [--number=NUM] [--progress] [--raw] " + "[--status]\n" + " [--time] [--verbose] [--version] DEVICE\n" " where:\n" " --desc|-d set flag for descriptor sense " "format\n" @@ -78,6 +79,7 @@ usage() " (def: 0 -> 252 bytes)\n" " --num=NUM|-n NUM number of REQUEST SENSE commands " "to send (def: 1)\n" + " --number=NUM same action as '--num=NUM'\n" " --progress|-p output a progress indication (percentage) " "if available\n" " --raw|-r output in binary (to stdout)\n" diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c index 2f301ca2..a898a8f5 100644 --- a/src/sg_sanitize.c +++ b/src/sg_sanitize.c @@ -28,7 +28,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.01 20160218"; +static const char * version_str = "1.02 20160227"; /* Not all environments support the Unix sleep() */ #if defined(MSC_VER) || defined(__MINGW32__) @@ -76,6 +76,7 @@ static struct option long_options[] = { {"pattern", required_argument, 0, 'p'}, {"quick", no_argument, 0, 'Q'}, {"test", required_argument, 0, 'T'}, + {"timeout", required_argument, 0, 't'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wait", no_argument, 0, 'w'}, @@ -94,8 +95,9 @@ struct opts_t { int invert; int ipl; /* initialization pattern length */ int overwrite; - int test; int quick; + int test; + int timeout; /* in seconds */ int verbose; int wait; int zero; @@ -112,8 +114,9 @@ usage() " [--fail] [--help] [--invert] [--ipl=LEN] " "[--overwrite]\n" " [--pattern=PF] [--quick] [--test=TE] " - "[--verbose]\n" - " [--version] [--wait] [--zero] [--znr] DEVICE\n" + "[--timeout=SEC]\n" + " [--verbose] [--version] [--wait] [--zero] " + "[--znr] DEVICE\n" " where:\n" " --ause|-A set AUSE bit in cdb\n" " --block|-B do BLOCK ERASE sanitize\n" @@ -143,6 +146,7 @@ usage() " --test=TE|-T TE TE is placed in TEST field of " "OVERWRITE\n" " parameter list (def: 0)\n" + " --timeout=SEC|-t SEC SANITIZE command timeout in seconds\n" " --verbose|-v increase verbosity\n" " --version|-V print version string then exit\n" " --wait|-w wait for command to finish (could " @@ -164,7 +168,7 @@ static int do_sanitize(int sg_fd, const struct opts_t * op, const void * param_lstp, int param_lst_len) { - int k, ret, res, sense_cat, immed; + int k, ret, res, sense_cat, immed, timeout; unsigned char sanCmdBlk[SANITIZE_OP_LEN]; unsigned char sense_b[SENSE_BUFF_LEN]; struct sg_pt_base * ptvp; @@ -173,6 +177,10 @@ do_sanitize(int sg_fd, const struct opts_t * op, const void * param_lstp, immed = op->early ? 1 : 0; else immed = 1; + timeout = (immed ? SHORT_TIMEOUT : LONG_TIMEOUT); + /* only use command line timeout if it exceeds previous defaults */ + if (op->timeout > timeout) + timeout = op->timeout; memset(sanCmdBlk, 0, sizeof(sanCmdBlk)); sanCmdBlk[0] = SANITIZE_OP; if (op->overwrite) @@ -198,10 +206,13 @@ do_sanitize(int sg_fd, const struct opts_t * op, const void * param_lstp, for (k = 0; k < SANITIZE_OP_LEN; ++k) pr2serr("%02x ", sanCmdBlk[k]); pr2serr("\n"); - } - if ((op->verbose > 2) && (param_lst_len > 0)) { - pr2serr(" Parameter list contents:\n"); - dStrHexErr((const char *)param_lstp, param_lst_len, 1); + if (op->verbose > 2) { + if (param_lst_len > 0) { + pr2serr(" Parameter list contents:\n"); + dStrHexErr((const char *)param_lstp, param_lst_len, 1); + } + pr2serr(" Sanitize command timeout: %d seconds\n", timeout); + } } ptvp = construct_scsi_pt_obj(); if (NULL == ptvp) { @@ -211,8 +222,7 @@ do_sanitize(int sg_fd, const struct opts_t * op, const void * param_lstp, set_scsi_pt_cdb(ptvp, sanCmdBlk, sizeof(sanCmdBlk)); set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b)); set_scsi_pt_data_out(ptvp, (unsigned char *)param_lstp, param_lst_len); - res = do_scsi_pt(ptvp, sg_fd, (immed ? SHORT_TIMEOUT : LONG_TIMEOUT), - op->verbose); + res = do_scsi_pt(ptvp, sg_fd, timeout, op->verbose); ret = sg_cmds_process_resp(ptvp, "Sanitize", res, 0, sense_b, 1 /*noisy */, op->verbose, &sense_cat); if (-1 == ret) @@ -436,7 +446,7 @@ main(int argc, char * argv[]) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "ABc:CdeFhi:IOp:QT:vVwzZ", long_options, + c = getopt_long(argc, argv, "ABc:CdeFhi:IOp:Qt:T:vVwzZ", long_options, &option_index); if (c == -1) break; @@ -490,6 +500,13 @@ main(int argc, char * argv[]) case 'Q': ++op->quick; break; + case 't': + op->timeout = sg_get_num(optarg); + if (op->timeout < 0) { + pr2serr("bad argument to '--timeout=SEC', want 0 or more\n"); + return SG_LIB_SYNTAX_ERROR; + } + break; case 'T': op->test = sg_get_num(optarg); if ((op->test < 0) || (op->test > 3)) { @@ -673,7 +690,7 @@ main(int argc, char * argv[]) sleep_for(POLL_DURATION_SECS); memset(rsBuff, 0x0, sizeof(rsBuff)); res = sg_ll_request_sense(sg_fd, op->desc, rsBuff, sizeof(rsBuff), - 1, vb); + 1, vb); if (res) { ret = res; if (SG_LIB_CAT_INVALID_OP == res) diff --git a/src/sg_senddiag.c b/src/sg_senddiag.c index 3cfd47fa..f42bbbb7 100644 --- a/src/sg_senddiag.c +++ b/src/sg_senddiag.c @@ -28,7 +28,7 @@ #include "sg_pr2serr.h" -static const char * version_str = "0.48 20160218"; +static const char * version_str = "0.49 20160228"; #define ME "sg_senddiag: " diff --git a/src/sg_sync.c b/src/sg_sync.c index 0a9600fa..c847f62f 100644 --- a/src/sg_sync.c +++ b/src/sg_sync.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2015 Douglas Gilbert. + * Copyright (c) 2004-2016 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. @@ -27,7 +27,7 @@ * (e.g. disks). */ -static const char * version_str = "1.14 20151219"; +static const char * version_str = "1.15 20160227"; #define SYNCHRONIZE_CACHE16_CMD 0x91 #define SYNCHRONIZE_CACHE16_CMDLEN 16 @@ -53,7 +53,7 @@ static void usage() { pr2serr("Usage: sg_sync [--16] [--count=COUNT] [--group=GN] [--help] " "[--immed]\n" - " [--lba=LBA] [--sync-nv] [--timeout=SECS] " + " [--lba=LBA] [--sync-nv] [--timeout=SEC] " "[--verbose]\n" " [--version] DEVICE\n" " where:\n" @@ -74,7 +74,7 @@ static void usage() " --sync-nv|-s synchronize to non-volatile storage " "(if distinct\n" " from medium). Obsolete in sbc3r35d.\n" - " --timeout=SECS|-t SECS command timeout in seconds, only " + " --timeout=SEC|-t SEC command timeout in seconds, only " "active\n" " if '--16' given (def: 60 seconds)\n" " --verbose|-v increase verbosity\n" diff --git a/src/sg_turs.c b/src/sg_turs.c index 1d6cc425..64c151dc 100644 --- a/src/sg_turs.c +++ b/src/sg_turs.c @@ -3,7 +3,7 @@ * data transfer (and no REQUEST SENSE command iff the unit is ready) * then this can be used for timing per SCSI command overheads. * - * Copyright (C) 2000-2015 D. Gilbert + * Copyright (C) 2000-2016 D. Gilbert * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) @@ -31,7 +31,7 @@ #include "sg_pr2serr.h" -static const char * version_str = "3.31 20151220"; +static const char * version_str = "3.32 20160226"; #if defined(MSC_VER) || defined(__MINGW32__) #define HAVE_MS_SLEEP @@ -45,14 +45,16 @@ static const char * version_str = "3.31 20151220"; #endif static struct option long_options[] = { - {"help", 0, 0, 'h'}, - {"new", 0, 0, 'N'}, - {"number", 1, 0, 'n'}, - {"old", 0, 0, 'O'}, - {"progress", 0, 0, 'p'}, - {"time", 0, 0, 't'}, - {"verbose", 0, 0, 'v'}, - {"version", 0, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {"new", no_argument, 0, 'N'}, + {"number", required_argument, 0, 'n'}, + {"num", required_argument, 0, 'n'}, /* added in v3.32 (sg3_utils + * v1.43) for sg_requests compatibility */ + {"old", no_argument, 0, 'O'}, + {"progress", no_argument, 0, 'p'}, + {"time", no_argument, 0, 't'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}, }; @@ -70,20 +72,21 @@ struct opts_t { static void usage() { - printf("Usage: sg_turs [--help] [--number=NUM] [--progress] [--time] " - "[--verbose]\n" - " [--version] DEVICE\n" + printf("Usage: sg_turs [--help] [--number=NUM] [--num=NUM] [--progress] " + "[--time]\n" + " [--verbose] [--version] DEVICE\n" " where:\n" " --help|-h print usage message then exit\n" " --number=NUM|-n NUM number of test_unit_ready commands " "(def: 1)\n" + " --num=NUM|-n NUM same action as '--number=NUM'\n" " --progress|-p outputs progress indication (percentage) " "if available\n" " --time|-t outputs total duration and commands per " "second\n" " --verbose|-v increase verbosity\n" " --version|-V print version string then exit\n\n" - "Performs a SCSI TEST UNIT READY command (or many of them)\n"); + "Performs a SCSI TEST UNIT READY command (or many of them).\n"); } static void usage_old() @@ -99,7 +102,7 @@ static void usage_old() "second\n" " -v increase verbosity\n" " -V print version string then exit\n\n" - "Performs a SCSI TEST UNIT READY command (or many of them)\n"); + "Performs a SCSI TEST UNIT READY command (or many of them).\n"); } static void usage_for(const struct opts_t * op) diff --git a/src/sg_write_same.c b/src/sg_write_same.c index 486e1ad4..640d1c64 100644 --- a/src/sg_write_same.c +++ b/src/sg_write_same.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2015 Douglas Gilbert. + * Copyright (c) 2009-2016 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. @@ -28,7 +28,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.11 20151220"; +static const char * version_str = "1.12 20160226"; #define ME "sg_write_same: " @@ -50,6 +50,10 @@ static const char * version_str = "1.11 20151220"; #define MAX_XFER_LEN (64 * 1024) #define EBUFF_SZ 256 +#ifndef UINT32_MAX +#define UINT32_MAX ((uint32_t)-1) +#endif + static struct option long_options[] = { {"10", no_argument, 0, 'R'}, {"16", no_argument, 0, 'S'}, @@ -155,7 +159,7 @@ do_write_same(int sg_fd, const struct opts_t * op, const void * dataoutp, cdb_len = op->pref_cdb_size; if (WRITE_SAME10_LEN == cdb_len) { llba = op->lba + op->numblocks; - if ((op->numblocks > 0xffff) || (llba > ULONG_MAX) || + if ((op->numblocks > 0xffff) || (llba > UINT32_MAX) || op->ndob || (op->unmap && (0 == op->want_ws10))) { cdb_len = WRITE_SAME16_LEN; if (op->verbose) { @@ -164,7 +168,7 @@ do_write_same(int sg_fd, const struct opts_t * op, const void * dataoutp, if (op->numblocks > 0xffff) pr2serr("%s since blocks exceed 65535\n", cp); - else if (llba > ULONG_MAX) + else if (llba > UINT32_MAX) pr2serr("%s since LBA may exceed 32 bits\n", cp); else pr2serr("%s due to ndob or unmap settings\n", cp); diff --git a/src/sg_xcopy.c b/src/sg_xcopy.c index a6a6ca17..ae0265ab 100644 --- a/src/sg_xcopy.c +++ b/src/sg_xcopy.c @@ -86,6 +86,10 @@ static const char * version_str = "0.53 20160201"; #define DEF_TIMEOUT 60000 /* 60,000 millisecs == 60 seconds */ +#ifndef UINT32_MAX +#define UINT32_MAX ((uint32_t)-1) +#endif + #ifndef RAW_MAJOR #define RAW_MAJOR 255 /*unlikey value */ #endif @@ -174,8 +178,8 @@ struct xcopy_fp_t { dev_t devno; int sg_type; int sg_fd; - unsigned long min_bytes; - unsigned long max_bytes; + uint32_t min_bytes; + uint32_t max_bytes; int64_t num_sect; int sect_sz; int append; @@ -718,7 +722,7 @@ scsi_operating_parameter(struct xcopy_fp_t *xfp, int is_target) max_segment_num = sg_get_unaligned_be16(rcBuff + 10); max_desc_len = sg_get_unaligned_be32(rcBuff + 12); max_segment_len = sg_get_unaligned_be32(rcBuff + 16); - xfp->max_bytes = max_segment_len ? max_segment_len : ULONG_MAX; + xfp->max_bytes = max_segment_len ? max_segment_len : UINT32_MAX; max_inline_data = sg_get_unaligned_be32(rcBuff + 20); if (verbose) { pr2serr(" >> %s response:\n", rec_copy_op_params_str); @@ -1763,36 +1767,38 @@ main(int argc, char * argv[]) return SG_LIB_CAT_OTHER; } - if ((unsigned long)dd_count < ixcf.min_bytes / ixcf.sect_sz) { - pr2serr("not enough data to read (min %ld bytes)\n", oxcf.min_bytes); + if (dd_count < (ixcf.min_bytes / (uint32_t)ixcf.sect_sz)) { + pr2serr("not enough data to read (min %" PRIu32 " bytes)\n", + oxcf.min_bytes); return SG_LIB_CAT_OTHER; } - if ((unsigned long)dd_count < oxcf.min_bytes / oxcf.sect_sz) { - pr2serr("not enough data to write (min %ld bytes)\n", oxcf.min_bytes); + if (dd_count < (oxcf.min_bytes / (uint32_t)oxcf.sect_sz)) { + pr2serr("not enough data to write (min %" PRIu32 " bytes)\n", + oxcf.min_bytes); return SG_LIB_CAT_OTHER; } if (bpt_given) { if (xcopy_flag_dc) { - if ((unsigned long)bpt * oxcf.sect_sz > oxcf.max_bytes) { - pr2serr("bpt too large (max %ld blocks)\n", - oxcf.max_bytes / oxcf.sect_sz); + if ((uint32_t)(bpt * oxcf.sect_sz) > oxcf.max_bytes) { + pr2serr("bpt too large (max %" PRIu32 " blocks)\n", + oxcf.max_bytes / (uint32_t)oxcf.sect_sz); return SG_LIB_SYNTAX_ERROR; } } else { - if ((unsigned long)bpt * ixcf.sect_sz > ixcf.max_bytes) { - pr2serr("bpt too large (max %ld blocks)\n", - ixcf.max_bytes / ixcf.sect_sz); + if ((uint32_t)(bpt * ixcf.sect_sz) > ixcf.max_bytes) { + pr2serr("bpt too large (max %" PRIu32 " blocks)\n", + ixcf.max_bytes / (uint32_t)ixcf.sect_sz); return SG_LIB_SYNTAX_ERROR; } } } else { - unsigned long r; + uint32_t r; if (xcopy_flag_dc) - r = oxcf.max_bytes / (unsigned long)oxcf.sect_sz; + r = oxcf.max_bytes / (uint32_t)oxcf.sect_sz; else - r = ixcf.max_bytes / (unsigned long)ixcf.sect_sz; + r = ixcf.max_bytes / (uint32_t)ixcf.sect_sz; bpt = (r > MAX_BLOCKS_PER_TRANSFER) ? MAX_BLOCKS_PER_TRANSFER : r; } |