aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2016-02-28 04:46:32 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2016-02-28 04:46:32 +0000
commit1c1b89e65392808cab0275b914bf6f76f1dff1c2 (patch)
treef9974559bb26b6c41b53752f6e69981bbd20e9bd
parent83415041e1e9a9b93e743069ca7600af31ddb839 (diff)
downloadsg3_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
-rw-r--r--ChangeLog7
-rw-r--r--doc/sg_format.848
-rw-r--r--doc/sg_requests.818
-rw-r--r--doc/sg_sanitize.814
-rw-r--r--doc/sg_sync.810
-rw-r--r--doc/sg_turs.819
-rw-r--r--lib/sg_cmds_extra.c30
-rw-r--r--src/sg_copy_results.c7
-rw-r--r--src/sg_format.c124
-rw-r--r--src/sg_inq.c6
-rw-r--r--src/sg_reassign.c10
-rw-r--r--src/sg_requests.c12
-rw-r--r--src/sg_sanitize.c43
-rw-r--r--src/sg_senddiag.c2
-rw-r--r--src/sg_sync.c8
-rw-r--r--src/sg_turs.c33
-rw-r--r--src/sg_write_same.c12
-rw-r--r--src/sg_xcopy.c38
18 files changed, 268 insertions, 173 deletions
diff --git a/ChangeLog b/ChangeLog
index 079a95e1..3910042c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,8 +2,13 @@ Each utility has its own version number, date of last change and
some description at the top of its ".c" file. All utilities in the main
directory have their own "man" pages. There is also a sg3_utils man page.
-Changelog for sg3_utils-1.43 [20160224] [svn: r679]
+Changelog for sg3_utils-1.43 [20160226] [svn: r680]
- sg_senddiag: add --timeout=SEC option
+ - sg_sanitize: add --timeout=SEC option
+ - sg_format: add --timeout=SEC option
+ - sg_reassign+sg_write_same: fix ULONG_MAX problem
+ - sg_turs+sg_requests: make both accept '--num=NUM'
+ and '--number=NUM' for mutual compatibility
- shellcheck cleanup on scripts
Changelog for sg3_utils-1.42 [20160217] [svn: r663]
diff --git a/doc/sg_format.8 b/doc/sg_format.8
index 2e8cda2d..679e007f 100644
--- a/doc/sg_format.8
+++ b/doc/sg_format.8
@@ -1,4 +1,4 @@
-.TH SG_FORMAT "8" "February 2016" "sg3_utils\-1.42" SG3_UTILS
+.TH SG_FORMAT "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_format \- format, resize a SCSI disk or format a tape
.SH SYNOPSIS
@@ -9,7 +9,8 @@ sg_format \- format, resize a SCSI disk or format a tape
[\fI\-\-mode=MP\fR] [\fI\-\-pfu=PFU\fR] [\fI\-\-pie=PIE\fR] [\fI\-\-pinfo\fR]
[\fI\-\-poll=PT\fR] [\fI\-\-resize\fR] [\fI\-\-rto_req\fR]
[\fI\-\-security\fR] [\fI\-\-six\fR] [\fI\-\-size=SIZE\fR] [\fI\-\-tape=FM\fR]
-[\fI\-\-verbose\fR] [\fI\-\-verify\fR] [\fI\-\-version\fR] [\fI\-\-wait\fR]
+[\fI\-\-timeout=SEC\fR] [\fI\-\-verbose\fR] [\fI\-\-verify\fR]
+[\fI\-\-version\fR] [\fI\-\-wait\fR]
\fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
@@ -266,6 +267,18 @@ set to \fIFM\fR. This option is used to prepare a tape (i.e. the "medium")
in a tape drive for use. Values for \fIFM\fR include 0 to do the "default"
format; 1 to partition a volume and 2 to do a default format then partition.
.TP
+\fB\-m\fR, \fB\-\-timeout\fR=\fISEC\fR
+where \fISEC\fR is the FORMAT UNIT or FORMAT MEDIUM command timeout in
+seconds. \fISEC\fR will only be used if it exceeds the internal timeout
+which is 20 seconds if the IMMED bit is set and 72000 seconds (20 hours)
+if the IMMED bit is not set. If the timeout is exceeded then the
+operating system will typically abort the command. Aborting a command
+may escalate to a LUN reset (or worse). A timeout may also leave
+the disk or tape format operation incomplete. And that may result in the
+disk or tape being in a "format corrupt" state requiring another format
+to remedy the situation. So for various reasons timeouts are best
+avoided.
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
increase the level of verbosity, (i.e. debug output). "\-vvv" gives
a lot more debug output.
@@ -280,12 +293,10 @@ print the version string and then exit.
\fB\-w\fR, \fB\-\-wait\fR
the default format action is to set the "IMMED" bit in the FORMAT UNIT
command's (short) parameter header. If this option (i.e. \fI\-\-wait\fR) is
-given then the "IMMED" bit is not set. If \fI\-\-wait\fR is given the
-FORMAT UNIT command waits until the format operation completes before
-returning its response. This can be many hours on large disks. This
-utility sets a 15 hour timeout on such a FORMAT UNIT command! Some recent
-SSDs go to the other extreme of completing a format operation in 1.5
-seconds hence waiting is not an issue.
+given then the "IMMED" bit is not set. If \fI\-\-wait\fR is given then the
+FORMAT UNIT or FORMAT MEDIUM command waits until the format operation
+completes before returning its response. This can be many hours on large
+disks. See the \fI\-\-timeout=SEC\fR option.
.SH LISTS
The SBC\-3 draft (revision 36) defines PLIST, CLIST, DLIST and GLIST in
section 4.13 on "Medium defects". Briefly, the PLIST is the "primary"
@@ -381,15 +392,18 @@ can be terminated (e.g. with control\-C) without affecting the format
operation which continues. However a target or device reset (or a power
cycle) will probably cause the device to become "format corrupt".
.PP
-When the \fI\-\-format\fR and \fI\-\-wait\fR options are both given then
-this utility may take a long time to return. In this case care should be
-taken not to send any other SCSI commands to the disk as it may not respond
-leaving those commands queued behind the active format command. This may
-cause a timeout in the OS driver (in a lot shorter period than 15 hours
-applicable to some format operations). This may result in the OS resetting
-the disk leaving the format operation incomplete. This may leave the
-disk in a "format corrupt" state requiring another format to remedy
-the situation.
+When the \fI\-\-format\fR (or \fI\-\-tape\fR) and \fI\-\-wait\fR options are
+both given then this utility may take a long time to return. In this case
+care should be taken not to send any other SCSI commands to the disk as it
+may not respond leaving those commands queued behind the active format
+command. This may cause a timeout in the OS driver (in a lot shorter period
+than 20 hours applicable to some format operations). This may result in the
+OS resetting the disk leaving the format operation incomplete. This may leave
+the disk in a "format corrupt" state requiring another format to remedy
+the situation. Modern SCSI devices should yield a "not ready" sense key
+with an additional sense indicating a format is in progress. With older
+devices the user should take precautions that nothing attempts to access
+a device while it is being formatted.
.PP
When the block size (i.e. the number of bytes in each block) is changed
on a disk two SCSI commands must be sent: a MODE SELECT to change the block
diff --git a/doc/sg_requests.8 b/doc/sg_requests.8
index ef177056..5372deb3 100644
--- a/doc/sg_requests.8
+++ b/doc/sg_requests.8
@@ -1,11 +1,12 @@
-.TH SG_REQUESTS "8" "May 2014" "sg3_utils\-1.39" SG3_UTILS
+.TH SG_REQUESTS "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_requests \- send one or more SCSI REQUEST SENSE commands
.SH SYNOPSIS
.B sg_requests
[\fI\-\-desc\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR] [\fI\-\-maxlen=LEN\fR]
-[\fI\-\-num=NUM\fR] [\fI\-\-progress\fR] [\fI\-\-raw\fR] [\fI\-\-status\fR]
-[\fI\-\-time\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
+[\fI\-\-num=NUM\fR] [\fI\-\-number=NUM\fR] [\fI\-\-progress\fR]
+[\fI\-\-raw\fR] [\fI\-\-status\fR] [\fI\-\-time\fR] [\fI\-\-verbose\fR]
+[\fI\-\-version\fR] \fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
@@ -42,6 +43,9 @@ cdb's "allocation length" field. If not given (or \fILEN\fR is zero) then
perform \fINUM\fR SCSI REQUEST SENSE commands, stopping when either \fINUM\fR
is reached or an error occurs. The default value for \fINUM\fR is 1 .
.TP
+\fB\-\-number\fR=\fINUM\fR
+same action as \fI\-\-num=NUM\fR. Added for compatibility with sg_turs.
+.TP
\fB\-p\fR, \fB\-\-progress\fR
show progress indication (a percentage) if available. If \fI\-\-number=NUM\fR
is given, \fINUM\fR is greater than 1 and an initial progress indication
@@ -103,8 +107,8 @@ SBC\-3). Several long duration SCSI commands associated with tape drives also
use the progress indication (see SSC\-3).
.PP
Early standards suggested that the SCSI TEST UNIT READY command be used for
-polling the progress indication. More recent standards seem to suggest
-the SCSI REQUEST SENSE command should be used instead.
+polling the progress indication (see the sg_turs utility). Since SPC\-3 the
+standards suggest that the SCSI REQUEST SENSE command should be used instead.
.PP
The \fIDEVICE\fR is opened with a read\-only flag (e.g. in Unix with the
O_RDONLY flag).
@@ -116,9 +120,9 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2004\-2014 Douglas Gilbert
+Copyright \(co 2004\-2016 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH "SEE ALSO"
-.B sg3_utils
+.B sg_turs (sg3_utils)
diff --git a/doc/sg_sanitize.8 b/doc/sg_sanitize.8
index bed48c7e..4886cd2b 100644
--- a/doc/sg_sanitize.8
+++ b/doc/sg_sanitize.8
@@ -1,4 +1,4 @@
-.TH SG_SANITIZE "8" "November 2015" "sg3_utils\-1.42" SG3_UTILS
+.TH SG_SANITIZE "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_sanitize \- remove all user data from disk with SCSI SANITIZE command
.SH SYNOPSIS
@@ -7,8 +7,8 @@ sg_sanitize \- remove all user data from disk with SCSI SANITIZE command
[\fI\-\-desc\fR] [\fI\-\-early\fR] [\fI\-\-fail\fR] [\fI\-\-help\fR]
[\fI\-\-invert\fR] [\fI\-\-ipl=LEN\fR] [\fI\-\-overwrite\fR]
[\fI\-\-pattern=PF\fR] [\fI\-\-quick\fR] [\fI\-\-test=TE\fR]
-[\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-wait\fR] [\fI\-\-zero\fR]
-[\fI\-\-znr\fR] \fIDEVICE\fR
+[\fI\-\-timeout=SEC\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
+[\fI\-\-wait\fR] [\fI\-\-zero\fR] [\fI\-\-znr\fR] \fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
@@ -36,7 +36,7 @@ in case the wrong \fIDEVICE\fR has been given.
If the \fI\-\-early\fR option is given then this utility will exit soon
after starting the SANITIZE command with the IMMED bit set. The user can
monitor the progress of the sanitize operation with
-the "sg_request \-\-num=9999 \-\-progress" which sends a REQUEST SENSE
+the "sg_requests \-\-num=9999 \-\-progress" which sends a REQUEST SENSE
command every 30 seconds. Otherwise if the \fI\-\-wait\fR option is given
then this utility will wait until the SANITIZE command completes (or fails)
and that can be many hours.
@@ -124,6 +124,10 @@ set the TEST field in the overwrite service action parameter list. This
only affects the "overwrite" sanitize operation. The default is to place
0 in that field.
.TP
+\fB\-t\fR, \fB\-\-timeout\fR=\fISEC\fR
+where \fISEC\fR is the number of seconds used for the timeout on the
+SANITIZE command.
+.TP
\fB\-v\fR, \fB\-\-verbose\fR
increase the level of verbosity, (i.e. debug output).
.TP
@@ -230,7 +234,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2011\-2015 Douglas Gilbert
+Copyright \(co 2011\-2016 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_sync.8 b/doc/sg_sync.8
index 68035ab7..1dd63eeb 100644
--- a/doc/sg_sync.8
+++ b/doc/sg_sync.8
@@ -1,11 +1,11 @@
-.TH SG_SYNC "8" "July 2013" "sg3_utils\-1.37" SG3_UTILS
+.TH SG_SYNC "8" "February 2016" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_sync \- send SCSI SYNCHRONIZE CACHE command
.SH SYNOPSIS
.B sg_sync
[\fI\-\-16\fR] [\fI\-\-count=COUNT\fR] [\fI\-\-group=GN\fR]
[\fI\-\-help\fR] [\fI\-\-immed\fR] [\fI\-\-lba=LBA\fR] [\fI\-\-sync\-nv\fR]
-[\fI\-\-timeout=SECS\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
+[\fI\-\-timeout=SEC\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
@@ -58,8 +58,8 @@ option (or if there is no non\-volatile cache in the device) the
synchronization is with the medium. The SYNC_NV bit was made obsolete in
SBC\-3 revision 35d.
.TP
-\fB\-t\fR, \fB\-\-timeout\fR=\fISECS\fR
-where \fISECS\fR is the number of seconds the OS allows the SYNCHRONIZE
+\fB\-t\fR, \fB\-\-timeout\fR=\fISEC\fR
+where \fISEC\fR is the number of seconds the OS allows the SYNCHRONIZE
CACHE(16) to complete before it tries to cancel the command. Cancelling
commands (typically with the task management function "abort task") is
best avoided. Note this option is only active together with the \fI\-\-16\fR
@@ -89,7 +89,7 @@ Written by Douglas Gilbert.
.SH "REPORTING BUGS"
Report bugs to <dgilbert at interlog dot com>.
.SH COPYRIGHT
-Copyright \(co 2004\-2013 Douglas Gilbert
+Copyright \(co 2004\-2016 Douglas Gilbert
.br
This software is distributed under a FreeBSD license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
diff --git a/doc/sg_turs.8 b/doc/sg_turs.8
index fc50c3b0..6c23303b 100644
--- a/doc/sg_turs.8
+++ b/doc/sg_turs.8
@@ -1,10 +1,11 @@
-.TH SG_TURS "8" "May 2014" "sg3_utils\-1.39" SG3_UTILS
+.TH SG_TURS "8" "Fenruary 2016" "sg3_utils\-1.43" SG3_UTILS
.SH NAME
sg_turs \- send one or more SCSI TEST UNIT READY commands
.SH SYNOPSIS
.B sg_turs
-[\fI\-\-help\fR] [\fI\-\-number=NUM\fR] [\fI\-\-progress\fR] [\fI\-\-time\fR]
-[\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
+[\fI\-\-help\fR] [\fI\-\-number=NUM\fR] [\fI\-\-num=NUM\fR]
+[\fI\-\-progress\fR] [\fI\-\-time\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
+\fIDEVICE\fR
.PP
.B sg_turs
[\fI\-n=NUM\fR] [\fI\-p\fR] [\fI\-t\fR] [\fI\-v\fR] [\fI\-V\fR]
@@ -34,6 +35,10 @@ g G GiB *1,073,741,824; and GB *1,000,000,000 . Also a suffix of the
form "x<n>" multiplies the leading number by <n>. Alternatively a hex
number may be given, prefixed by either '0x' or has a trailing 'h'.
.TP
+\fB\-\-num\fR=\fINUM\fR
+same as \fI\-\-number=NUM\fR. Added for compatibility with sg_requests
+which has taken over the role of polling the progress indication.
+.TP
\fB\-O\fR, \fB\-\-old\fR
switch to older style options.
.TP
@@ -57,7 +62,9 @@ print version string then exit.
The progress indication is optionally part of the sense data. When a prior
command that takes a long time to complete (and typically precludes other
media access commands) is still underway, the progress indication can be used
-to determine how long before the device returns to its normal state.
+to determine how long before the device returns to its normal state. Around
+SPC\-3 T10 changed the preferred command for polling the progress indication
+from TEST UNIT READY to REQUEST SENSE (see the sg_requests utilty).
.PP
The SCSI FORMAT command for disks used with the IMMED bit set is an example
of an operation that takes a significant amount of time and precludes other
@@ -108,9 +115,9 @@ print out version string then exit.
.SH AUTHORS
Written by D. Gilbert
.SH COPYRIGHT
-Copyright \(co 2000\-2014 Douglas Gilbert
+Copyright \(co 2000\-2016 Douglas Gilbert
.br
This software is distributed under the GPL version 2. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
.SH "SEE ALSO"
-.B sg_inq, sg_request (sg3_utils)
+.B sg_inq, sg_requests (sg3_utils)
diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c
index 5ccf3707..ce3948eb 100644
--- a/lib/sg_cmds_extra.c
+++ b/lib/sg_cmds_extra.c
@@ -354,7 +354,7 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
}
/* Invokes a SCSI SEND DIAGNOSTIC command. Foreground, extended self tests can
- * take a long time, if so set long_duration flag in which case the timout
+ * take a long time, if so set long_duration flag in which case the timeout
* is set to 7200 seconds; if the value of long_duration is > 7200 then that
* value is taken as the timeout value in seconds. Return of 0 -> success,
* various SG_LIB_CAT_* positive values or -1 -> other errors */
@@ -372,21 +372,24 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
senddiagCmdBlk[1] = (unsigned char)((sf_code << 5) | (pf_bit << 4) |
(sf_bit << 2) | (devofl_bit << 1) | unitofl_bit);
sg_put_unaligned_be16((uint16_t)param_len, senddiagCmdBlk + 3);
+ if (long_duration > LONG_PT_TIMEOUT)
+ tmout = long_duration;
+ else
+ tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT;
if (verbose) {
pr2ws(" Send diagnostic cmd: ");
for (k = 0; k < SEND_DIAGNOSTIC_CMDLEN; ++k)
pr2ws("%02x ", senddiagCmdBlk[k]);
pr2ws("\n");
- if ((verbose > 1) && paramp && param_len) {
- pr2ws(" Send diagnostic parameter list:\n");
- dStrHexErr((const char *)paramp, param_len, -1);
+ if (verbose > 1) {
+ if (paramp && param_len) {
+ pr2ws(" Send diagnostic parameter list:\n");
+ dStrHexErr((const char *)paramp, param_len, -1);
+ }
+ pr2ws(" Send diagnostic timeout: %d seconds\n", tmout);
}
}
- if (long_duration > LONG_PT_TIMEOUT)
- tmout = long_duration;
- else
- tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT;
ptvp = construct_scsi_pt_obj();
if (NULL == ptvp) {
@@ -756,10 +759,13 @@ sg_ll_format_unit2(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
for (k = 0; k < 6; ++k)
pr2ws("%02x ", fuCmdBlk[k]);
pr2ws("\n");
- }
- if ((verbose > 1) && (param_len > 0)) {
- pr2ws(" format parameter list:\n");
- dStrHexErr((const char *)paramp, param_len, -1);
+ if (verbose > 1) {
+ if (param_len > 0) {
+ pr2ws(" format unit parameter list:\n");
+ dStrHexErr((const char *)paramp, param_len, -1);
+ }
+ pr2ws(" format unit timeout: %d seconds\n", tmout);
+ }
}
ptvp = construct_scsi_pt_obj();
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;
}