aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2013-02-21 01:02:08 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2013-02-21 01:02:08 +0000
commit074a673a2d0b1b74337c1a3fc66ab7408a27c6f0 (patch)
treed9637e4f821a372cc61e2d89a56112fdc12239fa
parent853b6b47bca5457847c4c6efe959ed5c9df5de2b (diff)
downloadsg3_utils-074a673a2d0b1b74337c1a3fc66ab7408a27c6f0.tar.gz
sg_reset: add --no-esc option plus command line and manpage clean-up
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@481 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog4
-rw-r--r--README2
-rw-r--r--debian/changelog2
-rw-r--r--doc/sg_reset.8163
-rw-r--r--sg3_utils.spec2
-rw-r--r--src/sg_reset.c253
-rw-r--r--src/sg_write_same.c90
7 files changed, 339 insertions, 177 deletions
diff --git a/ChangeLog b/ChangeLog
index e54820b1..a6c661fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,13 +2,15 @@ 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.36 [20130207] [svn: r480]
+Changelog for sg3_utils-1.36 [20130220] [svn: r481]
- sg_lib: improve snprintf handling
- sg_vpd: Protocol-specific port information VPD page for
SAS SSP, persistent connection (spl3r2)
- sg_xcopy: handle more descriptor types; handle zero
maximum segment length; allow list IDs to be disabled;
improve skip/seek handling
+ - sg_reset: and '--no-esc' option to stop reset escalation
+ - clean up including adding long option names
Changelog for sg3_utils-1.35 [20130117] [svn: r476]
- sg_compare_and_write: new utility
diff --git a/README b/README
index ff5cd5a8..1549c4fb 100644
--- a/README
+++ b/README
@@ -374,4 +374,4 @@ See http://sg.danny.cz/sg/tools.html
Douglas Gilbert
-17th January 2013
+20th February 2013
diff --git a/debian/changelog b/debian/changelog
index 21383f6f..1cc18f70 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,7 +2,7 @@ sg3-utils (1.36-0.1) unstable; urgency=low
* New upstream version
- -- Douglas Gilbert <dgilbert@interlog.com> Fri, 18 Jan 2013 12:00:00 -0500
+ -- Douglas Gilbert <dgilbert@interlog.com> Wed, 20 Feb 2013 19:00:00 -0500
sg3-utils (1.35-0.1) unstable; urgency=low
diff --git a/doc/sg_reset.8 b/doc/sg_reset.8
index d6245762..3cfc326b 100644
--- a/doc/sg_reset.8
+++ b/doc/sg_reset.8
@@ -1,91 +1,126 @@
-.TH SG_RESET "8" "July 2009" "sg3_utils\-1.28" SG3_UTILS
+.TH SG_RESET "8" "February 2013" "sg3_utils\-1.36" SG3_UTILS
.SH NAME
-sg_reset \- sends SCSI device, target, bus or host reset; or checks reset state
+sg_reset \- sends SCSI device, target, bus or host reset; or checks reset
+state
.SH SYNOPSIS
.B sg_reset
-[\fI\-b\fR] [\fI\-d\fR] [\fI\-h\fR] [\fI\-t\fR] [\fI\-V\fR]
+[\fI\-\-bus\fR] [\fI\-\-device\fR] [\fI\-\-help\fR] [\fI\-\-host\fR]
+[\fI\-\-no-esc\fR] [\fI\-\-target\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR]
\fIDEVICE\fR
.SH DESCRIPTION
.\" Add any additional description here
.PP
-The sg_reset utility with no options (just a \fIDEVICE\fR) reports on
-the reset state (e.g. if a reset is underway) of \fIDEVICE\fR. When given
-a \fI\-d\fR, \fI\-t\fR, \fI\-b\fR or \fI\-h\fR option it requests a device,
-target, bus or host reset respectively.
+The sg_reset utility with no options (just a \fIDEVICE\fR) reports on the
+reset state (e.g. if a reset is underway) of the \fIDEVICE\fR. When given
+a \fI\-\-device\fR, \fI\-\-target\fR, \fI\-\-bus\fR or \fI\-\-host\fR
+option it requests a device, target, bus or host reset respectively.
.PP
-The ability to reset a SCSI target (often called a "hard reset" at the
-transport level) was added in linux kernel 2.6.27 . Low level drivers that
-support target reset hopefully reset a logical unit only when given the
-device reset (i.e. \fI\-d\fR) option. This should removed the ambiguity of
-whether "device" meant LU or target that we have had in the past.
+A device reset is applied to the Logical Unit (LU) corresponding to
+\fIDEVICE\fR. It is most likely implemented by a Low level Driver (LLD)
+in Linux as a LOGICAL UNIT RESET task management function.
.PP
-In the linux kernel 2.6 series this utility can be called on sd,
-sr (cd/dvd), st or sg device nodes; if the user has appropriate
-permissions.
+The ability to reset a SCSI target was added in linux kernel 2.6.27 . A LLD
+may send Low level Drivers (LLDs) the I_T NEXUS RESET task management
+function. Alternatively it may use a transport mechanism to do the same
+thing (e.g. a hard reset on the link containing a SAS target).
.PP
-In the linux kernel 2.4 series support for this utility first
-appeared in lk 2.4.19 and could only be called on sg device
-nodes. Various vendors made this capability available in their
-kernels prior to lk 2.4.19.
+In the linux kernel 2.6 series this utility can be called on sd, sr (cd/dvd),
+st or sg device nodes; if the user has appropriate permissions.
.SH OPTIONS
.TP
-\fB\-b\fR
-attempt a SCSI bus reset. This would normally be tried if the
-device reset (i.e. option \fI\-d\fR) was not successful.
+\fB\-b\fR, \fB\-\-bus\fR
+attempt a SCSI bus reset. A bus reset is a SCSI Parallel Interface (SPI)
+concept not found in modern transports. A recent LLD may implement it as
+a series of resets on targets that might be considered as siblings to the
+target on the \fIDEVICE\fR path.
.TP
-\fB\-d\fR
-attempt a SCSI device reset. If the device seems stuck, this is
-the first reset that should be tried. This assumes the linux
-scsi mid level error handler is not already in the process
-of resetting \fIDEVICE\fR.
+\fB\-d\fR, \fB\-\-device\fR
+attempt a SCSI device reset. This would typically involve sending a LOGICAL
+UNIT RESET task management function to \fIDEVICE\fR.
.TP
-\fB\-h\fR
-attempt a host adapter reset. This would normally be tried if both
-device reset (i.e. option \fI\-d\fR) and bus reset (i.e. option \fI\-b\fR)
-were not successful.
+\fB\-h\fR, \fB\-\-help\fR
+print the usage message then exit.
.TP
-\fB\-t\fR
-attempt a SCSI target reset. This assumes the linux scsi mid level
-error handler is not already in the process of resetting the target that
-contains the given \fIDEVICE\fR.
+\fB\-H\fR, \fB\-\-host\fR
+attempt a host reset. The "host" in this context is often called
+a Host Bus Adapter (HBA) and contains one or more SCSI initiators.
.TP
-\fB\-V\fR
+\fB\-N\fR, \fB\-\-no\-esc\fR
+without this option, if a device reset (\fI\-\-device\fR) fails then it
+will escalate to a target reset. And if a target reset (\fI\-\-target\fR)
+fails then it will escalate to a bus reset. And if a bus
+reset (\fI\-\-bus\fR) fails then it will escalate to a host reset. With this
+option only the requested reset is attempted. An alternate option name of
+\fI\-\-no-escalate\fR is also accepted.
+.TP
+\fB\-t\fR, \fB\-\-target\fR
+attempt a SCSI target reset. A SCSI target contains one or more LUs. This
+would typically involve sending a I_T NEXUS RESET task management function
+to \fIDEVICE\fR There may be a transport action that is equivalent (e.g.
+in SAS a hard reset on the link that contains the target).
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+increase the degree of verbosity (debug messages).
+.TP
+\fB\-V\fR, \fB\-\-version\fR
prints the version string then exits.
.SH NOTES
-The error recovery code within the linux kernel when faced with a SCSI command
-timing out and no response from the device (LU), first tries a device reset
-and if that is not successful tries a target reset. If that is not successful
-it tries a bus reset. If that is not successful it tries a host reset. Users
-of this utility should check whether such a recovery is already underway
-before trying to reset with this utility. The "device,target,bus,host"
-order is also recommended (i.e. first start with the smallest
-hammer). The above is a generalization and exact details will vary depending
-on the transport and the low level driver concerned.
+The error recovery code within the Linux kernel (SCSI mid\-level) when faced
+with a SCSI command timing out and no response from the device (LU) does the
+following. First it tries a device reset and if that is not successful tries
+a target reset. If that is not successful it tries a bus reset. If that is
+not successful it tries a host reset. Users of this utility can check whether
+such a recovery is already underway before trying to reset with this utility.
+Calling this utility with no options, just the \fIDEVICE\fR, will do such
+a check. The "device,target,bus,host" order is the reset escalation that the
+\fI\-\-no-esc\fR option attempts to stop. In large storage configurations
+th escalation may be (very) undesirable.
+.PP
+This utility calls the SG_SCSI_RESET ioctl and as of lk 3.8.0 the
+\fI\-\-no-esc\fR option is not supported but may be soon after.
+.PP
+SAM\-4 and 5 define a hard reset, a LOGICAL UNIT RESET and a I_T NEXUS
+RESET. A hard reset is defined to be a power on condition, a microcode
+change or a transport reset event. LOGICAL UNIT RESET and I_T NEXUS
+RESET can be requested via task management functions (and support for
+LOGICAL UNIT RESET is mandatory). In Linux the SCSI subsystem leaves it up
+to the LLDs as to exactly what type (if any) of reset is performed.
+The "bus reset" is SCSI Parallel Interface (SPI) concept that may not map
+well to recent SCSI transports so it may be a dummy operation. A "host reset"
+attempts to re\-initialize the HBA that the request passes through en route
+to the \fIDEVICE\fR. Note that a "host reset" and a "bus reset" may cause
+collateral damage.
.PP
-SAM\-4 defines a hard reset, a logical unit reset and a I_T nexus reset. A
-hard reset is defined to be a power on condition, a microcode change or a
-transport reset event. A LU reset and an I_T nexus reset can be requested
-via task management function (and support for LU reset is mandatory). In
-Linux the SCSI subsystem leaves it up to the low level drivers as to whether
-a "device reset" is only for the addressed LU or all the LUs in the device
-that contains the addressed LU (i.e. a target reset). The additional of the
-target reset (i.e. option \fI\-t\fR) should give more control in this area.
-The "bus reset" is a transport reset and may be a dummy operation, depending
-on the transport. A "host reset" attempts to re\-initialize the HBA that the
-request passes through en route to the \fIDEVICE\fR. Note that a "host reset"
-and a "bus reset" may cause collateral damage.
+This utility does not allow individual SCSI commands to be aborted. SAM\-4
+defines ABORT TASK and ABORT TASK SET task management functions for that.
.PP
-This utility does not allow individual SCSI commands (or tasks as they are
-called in SAM\-4) to be aborted. SAM\-4 defines ABORT TASK and ABORT TASK
-SET task management functions for that.
+Prior to SAM\-3 there was a TARGET RESET task management function. And in
+SAM\-4 I_T NEXUS RESET appeared which seems closely related: the "I_T"
+stands for Initiator\-Target.
.PP
-Prior to SAM\-3 there was a TARGET RESET task management function. Several
-transports still support that function and many associated linux low level
-drivers map the \fI\-t\fR option to it.
+Transports may have their own types of resets not supported by this utility.
+For example SAS has a link reset in which both ends of a physical link (e.g.
+between a SAS expander and a SAS tape drive) renogiatate their connection.
+.PP
+Prior to version 0.57 of this utility the command line had short options
+only (e.g. \fI\-d\fR but not \fI\-\-device\fR). Also \fI\-h\fR invoked a host
+reset while in the current version \fI\-h\fR is equivalent to \fI\-\-help\fR
+and both \fI\-H\fR and \fI\-\-host\fR invoke a host reset. For backward
+compatibility define the environment variable SG3_UTILS_OLD_OPTS or
+SG_RESET_OLD_OPTS . In this case \fI\-h\fR will invoke a host reset and the
+output will be verbose as it was previously (equivalent to using the
+\fI\-\-verbose\fR option now).
+For example:
+.PP
+ SG_RESET_OLD_OPTS=1 sg_reset -h /dev/sg1
+.br
+sg_reset: starting host reset
+.br
+sg_reset: completed host reset
.SH AUTHORS
Written by Douglas Gilbert.
.SH COPYRIGHT
-Copyright \(co 1999\-2009 Douglas Gilbert
+Copyright \(co 1999\-2013 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.
diff --git a/sg3_utils.spec b/sg3_utils.spec
index 24c483ef..d5c3b220 100644
--- a/sg3_utils.spec
+++ b/sg3_utils.spec
@@ -79,7 +79,7 @@ fi
%{_libdir}/*.la
%changelog
-* Fri Jan 18 2013 - dgilbert at interlog dot com
+* Wed Feb 20 2013 - dgilbert at interlog dot com
- track t10 changes
* sg3_utils-1.36
diff --git a/src/sg_reset.c b/src/sg_reset.c
index 3417d966..a235693e 100644
--- a/src/sg_reset.c
+++ b/src/sg_reset.c
@@ -1,3 +1,14 @@
+/* A utility program originally written for the Linux OS SCSI subsystem.
+ * Copyright (C) 1999-2013 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)
+ * any later version.
+ *
+ * This program send either device, bus or host resets to device,
+ * or bus or host associated with the given sg device.
+ */
+
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
@@ -7,26 +18,17 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <getopt.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "sg_io_linux.h"
-/* A utility program originally written for the Linux OS SCSI subsystem.
- * Copyright (C) 1999-2009 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)
- * any later version.
- *
- * This program send either device, bus or host resets to device,
- * or bus or host associated with the given sg device.
- */
#define ME "sg_reset: "
-static char * version_str = "0.56 20090615";
+static char * version_str = "0.58 20130220";
#ifndef SG_SCSI_RESET
#define SG_SCSI_RESET 0x2284
@@ -43,101 +45,224 @@ static char * version_str = "0.56 20090615";
#define SG_SCSI_RESET_TARGET 4
#endif
+#ifndef SG_SCSI_RESET_NO_ESCALATE
+#define SG_SCSI_RESET_NO_ESCALATE 0x100
+#endif
+
+static struct option long_options[] = {
+ {"bus", no_argument, 0, 'b'},
+ {"device", no_argument, 0, 'd'},
+ {"help", no_argument, 0, 'z'},
+ {"host", no_argument, 0, 'H'},
+ {"no-esc", no_argument, 0, 'N'},
+ {"no-escalate", no_argument, 0, 'N'},
+ {"target", no_argument, 0, 't'},
+ {"verbose", no_argument, 0, 'v'},
+ {"version", no_argument, 0, 'V'},
+ {0, 0, 0, 0},
+};
+
+
+static void
+usage(int compat_mode)
+{
+ fprintf(stderr, "Usage: "
+ "sg_reset [--bus] [--device] [--help] [--host] [--no-esc] "
+ "[--target]\n"
+ " [--verbose] [--version] DEVICE\n"
+ " where:\n"
+ " --bus|-b SCSI bus reset (SPI concept), might be all "
+ "targets\n"
+ " --device|-d device (logical unit) reset\n");
+ if (compat_mode) {
+ fprintf(stderr,
+ " --help|-z print usage information then exit\n"
+ " --host|-h|-H host (bus adapter: HBA) reset\n");
+ } else {
+ fprintf(stderr,
+ " --help|-h print usage information then exit\n"
+ " --host|-H host (bus adapter: HBA) reset\n");
+ }
+ fprintf(stderr,
+ " --no-esc|-N overrides default action and only does "
+ "reset requested\n"
+ " --target|-t target reset. The target holds the DEVICE "
+ "and perhaps\n"
+ " other LUs\n"
+ " --verbose|-v increase the level of verbosity\n"
+ " --version|-V print version number then exit\n\n"
+ "Use SG_SCSI_RESET ioctl to send a reset to the "
+ "host/bus/target/device\nalong the DEVICE path. The DEVICE "
+ "itself is known as a logical unit (LU)\nin SCSI terminology.\n"
+ "Be warned: if the '-N' option is not given then if '-d' "
+ "fails then a\ntarget reset ('-t') is instigated. And it "
+ "'-t' fails then a bus reset\n('-b') is instigated. And if "
+ "'-b' fails then a host reset ('h') is\ninstigated. It is "
+ "recommended to use '-N' to stop the reset escalation.\n"
+ );
+}
+
int main(int argc, char * argv[])
{
- int sg_fd, res, k;
+ int c, sg_fd, res, k;
int do_device_reset = 0;
int do_bus_reset = 0;
int do_host_reset = 0;
+ int no_escalate = 0;
int do_target_reset = 0;
- char * file_name = 0;
-
- for (k = 1; k < argc; ++k) {
- if (0 == strcmp("-d", argv[k]))
- do_device_reset = 1;
- else if (0 == strcmp("-b", argv[k]))
- do_bus_reset = 1;
- else if (0 == strcmp("-h", argv[k]))
- do_host_reset = 1;
- else if (0 == strcmp("-t", argv[k]))
- do_target_reset = 1;
- else if (0 == strcmp("-V", argv[k])) {
- fprintf(stderr, "Version string: %s\n", version_str);
- exit(0);
- } else if (*argv[k] == '-') {
- printf("Unrecognized switch: %s\n", argv[k]);
- file_name = 0;
+ int verbose = 0;
+ char * device_name = NULL;
+ char * cp = NULL;
+
+ cp = getenv("SG3_UTILS_OLD_OPTS");
+ if (NULL == cp)
+ cp = getenv("SG_RESET_OLD_OPTS");
+
+ while (1) {
+ int option_index = 0;
+
+ c = getopt_long(argc, argv, "bdhHNtvVz", long_options,
+ &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'b':
+ ++do_bus_reset;
+ break;
+ case 'd':
+ ++do_device_reset;
+ break;
+ case 'h':
+ if (cp) {
+ ++do_host_reset;
+ break;
+ } else {
+ usage(!!cp);
+ return 0;
+ }
+ case 'H':
+ ++do_host_reset;
+ break;
+ case 'N':
+ ++no_escalate;
break;
- } else
- file_name = argv[k];
+ case 't':
+ ++do_target_reset;
+ break;
+
+ case 'v':
+ ++verbose;
+ break;
+ case 'V':
+ fprintf(stderr, ME "version: %s\n", version_str);
+ return 0;
+ case 'z':
+ usage(!!cp);
+ return 0;
+ default:
+ fprintf(stderr, "unrecognised option code 0x%x ??\n", c);
+ usage(!!cp);
+ return SG_LIB_SYNTAX_ERROR;
+ }
+ }
+
+ if (optind < argc) {
+ if (NULL == device_name) {
+ device_name = argv[optind];
+ ++optind;
+ }
+ if (optind < argc) {
+ for (; optind < argc; ++optind)
+ fprintf(stderr, "Unexpected extra argument: %s\n",
+ argv[optind]);
+ usage(!!cp);
+ return SG_LIB_SYNTAX_ERROR;
+ }
+ }
+ if (NULL == device_name) {
+ fprintf(stderr, "Missing DEVICE name. Use '--help' to see usage.\n");
+ return SG_LIB_SYNTAX_ERROR;
}
- if (0 == file_name) {
- printf(
- "Usage: sg_reset [-b] [-d] [-h] [-t] [-V] DEVICE\n");
- printf(" where: -b attempt a SCSI bus reset\n");
- printf(" -d attempt a SCSI device reset\n");
- printf(" -h attempt a host adapter reset\n");
- printf(" -t attempt a SCSI target reset\n");
- printf(" -V print version string then exit\n\n");
- printf(" {if no switch given then check if reset underway}\n");
- printf("To reset use '-d' first, if that is unsuccessful, "
- "then use '-b', then '-h'\n");
+
+ if (cp && (0 == verbose))
+ ++verbose; // older behaviour was more verbose
+
+ if ((!!do_device_reset + !!do_target_reset + !!do_bus_reset +
+ !!do_host_reset) > 1) {
+ fprintf(stderr, "Can only request one type of reset per "
+ "invocation\n");
return 1;
}
- sg_fd = open(file_name, O_RDWR | O_NONBLOCK);
+ sg_fd = open(device_name, O_RDWR | O_NONBLOCK);
if (sg_fd < 0) {
- fprintf(stderr, ME "open error: %s: ", file_name);
+ fprintf(stderr, ME "open error: %s: ", device_name);
perror("");
return 1;
}
k = SG_SCSI_RESET_NOTHING;
if (do_device_reset) {
- printf(ME "starting device reset\n");
+ if (verbose)
+ printf(ME "starting device reset\n");
k = SG_SCSI_RESET_DEVICE;
}
else if (do_target_reset) {
- printf(ME "starting target reset\n");
+ if (verbose)
+ printf(ME "starting target reset\n");
k = SG_SCSI_RESET_TARGET;
}
else if (do_bus_reset) {
- printf(ME "starting bus reset\n");
+ if (verbose)
+ printf(ME "starting bus reset\n");
k = SG_SCSI_RESET_BUS;
}
else if (do_host_reset) {
- printf(ME "starting host reset\n");
+ if (verbose)
+ printf(ME "starting host reset\n");
k = SG_SCSI_RESET_HOST;
}
+ if (no_escalate)
+ k += SG_SCSI_RESET_NO_ESCALATE;
res = ioctl(sg_fd, SG_SCSI_RESET, &k);
if (res < 0) {
if (EBUSY == errno)
- printf(ME "BUSY, may be resetting now\n");
+ fprintf(stderr, ME "BUSY, may be resetting now\n");
else if (EIO == errno)
- printf(ME "requested type of reset may not be available\n");
+ fprintf(stderr, ME "reset (for value=0x%x) may not be "
+ "available\n", k);
else if (EACCES == errno)
- printf(ME "reset requires CAP_SYS_ADMIN (root) "
+ fprintf(stderr, ME "reset requires CAP_SYS_ADMIN (root) "
"permission\n");
else if (EINVAL == errno)
- printf(ME "SG_SCSI_RESET not supported\n");
- else if (EIO == errno)
- printf(ME "scsi_reset_provider() call failed\n");
+ fprintf(stderr, ME "SG_SCSI_RESET not supported (for "
+ "value=0x%x)\n", k);
else
perror(ME "SG_SCSI_RESET failed");
+ close(sg_fd);
return 1;
}
- if (SG_SCSI_RESET_NOTHING == k)
- printf(ME "did nothing, device is normal mode\n");
- else if (SG_SCSI_RESET_DEVICE == k)
- printf(ME "completed device reset\n");
- else if (SG_SCSI_RESET_TARGET == k)
- printf(ME "completed target reset\n");
- else if (SG_SCSI_RESET_BUS == k)
- printf(ME "completed bus reset\n");
- else if (SG_SCSI_RESET_HOST == k)
- printf(ME "completed host reset\n");
+
+ if (no_escalate)
+ k -= SG_SCSI_RESET_NO_ESCALATE;
+ if (verbose) {
+ if (SG_SCSI_RESET_NOTHING == k)
+ printf(ME "did nothing, device is normal mode\n");
+ else if (SG_SCSI_RESET_DEVICE == k)
+ printf(ME "completed device %sreset\n", (no_escalate ?
+ "" : "(or target or bus or host) "));
+ else if (SG_SCSI_RESET_TARGET == k)
+ printf(ME "completed target %sreset\n", (no_escalate ?
+ "" : "(or bus or host) "));
+ else if (SG_SCSI_RESET_BUS == k)
+ printf(ME "completed bus %sreset\n", (no_escalate ?
+ "" : "(or host) "));
+ else if (SG_SCSI_RESET_HOST == k)
+ printf(ME "completed host reset\n");
+ }
if (close(sg_fd) < 0) {
perror(ME "close error");
diff --git a/src/sg_write_same.c b/src/sg_write_same.c
index 4d728888..7347283d 100644
--- a/src/sg_write_same.c
+++ b/src/sg_write_same.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009-2012 Douglas Gilbert.
+ * Copyright (c) 2009-2013 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 @@
#include "sg_cmds_basic.h"
#include "sg_cmds_extra.h"
-static char * version_str = "1.00 20121112";
+static char * version_str = "1.01 20130220";
#define ME "sg_write_same: "
@@ -91,47 +91,47 @@ struct opts_t {
static void
usage()
{
- fprintf(stderr, "Usage: "
- "sg_write_same [--10] [--16] [--32] [--anchor] [--grpnum=GN] "
- "[--help]\n"
- " [--in=IF] [--lba=LBA] [--lbdata] "
- "[--num=NUM] [--pbdata]\n"
- " [--timeout=TO] [--unmap] [--verbose] "
- "[--version]\n"
- " [--wrprotect=WRP] [xferlen=LEN] DEVICE\n"
- " where:\n"
- " --10|-R do WRITE SAME(10) (even if '--unmap' "
- "is given)\n"
- " --16|-S do WRITE SAME(16) (def: 10 unless "
- "'--unmap' given\n"
- " or LBA+NUM needs more than 32 bits)\n"
- " --32|-T do WRITE SAME(32) (def: 10 or 16)\n"
- " --anchor|-a set anchor field in cdb\n"
- " --grpnum=GN|-g GN GN is group number field (def: 0)\n"
- " --help|-h print out usage message\n"
- " --in=IF|-i IF IF is file to fetch one block of data "
- "from (use LEN\n"
- " bytes or whole file). Block written to "
- "DEVICE\n"
- " --lba=LBA|-l LBA LBA is the logical block address to "
- "start (def: 0)\n"
- " --lbdata|-L set LBDATA bit\n"
- " --num=NUM|-n NUM NUM is number of logical blocks to write "
- "(def: 1)\n"
- " [Beware NUM==0 means rest of device]\n"
- " --pbdata|-P set PBDATA bit\n"
- " --timeout=TO|-t TO command timeout (unit: seconds) (def: "
- "60)\n"
- " --unmap|-U set UNMAP bit\n"
- " --verbose|-v increase verbosity\n"
- " --version|-V print version string then exit\n"
- " --wrprotect=WPR|-w WPR WPR is the WRPROTECT field value "
- "(def: 0)\n"
- " --xferlen=LEN|-x LEN LEN is number of bytes from IF to "
- "send to\n"
- " DEVICE (def: IF file length)\n\n"
- "Performs a SCSI WRITE SAME (10, 16 or 32) command\n"
- );
+ fprintf(stderr, "Usage: "
+ "sg_write_same [--10] [--16] [--32] [--anchor] [--grpnum=GN] "
+ "[--help]\n"
+ " [--in=IF] [--lba=LBA] [--lbdata] "
+ "[--num=NUM] [--pbdata]\n"
+ " [--timeout=TO] [--unmap] [--verbose] "
+ "[--version]\n"
+ " [--wrprotect=WRP] [xferlen=LEN] DEVICE\n"
+ " where:\n"
+ " --10|-R do WRITE SAME(10) (even if '--unmap' "
+ "is given)\n"
+ " --16|-S do WRITE SAME(16) (def: 10 unless "
+ "'--unmap' given\n"
+ " or LBA+NUM needs more than 32 bits)\n"
+ " --32|-T do WRITE SAME(32) (def: 10 or 16)\n"
+ " --anchor|-a set anchor field in cdb\n"
+ " --grpnum=GN|-g GN GN is group number field (def: 0)\n"
+ " --help|-h print out usage message\n"
+ " --in=IF|-i IF IF is file to fetch one block of data "
+ "from (use LEN\n"
+ " bytes or whole file). Block written to "
+ "DEVICE\n"
+ " --lba=LBA|-l LBA LBA is the logical block address to "
+ "start (def: 0)\n"
+ " --lbdata|-L set LBDATA bit\n"
+ " --num=NUM|-n NUM NUM is number of logical blocks to "
+ "write (def: 1)\n"
+ " [Beware NUM==0 means rest of device]\n"
+ " --pbdata|-P set PBDATA bit\n"
+ " --timeout=TO|-t TO command timeout (unit: seconds) (def: "
+ "60)\n"
+ " --unmap|-U set UNMAP bit\n"
+ " --verbose|-v increase verbosity\n"
+ " --version|-V print version string then exit\n"
+ " --wrprotect=WPR|-w WPR WPR is the WRPROTECT field value "
+ "(def: 0)\n"
+ " --xferlen=LEN|-x LEN LEN is number of bytes from IF to "
+ "send to\n"
+ " DEVICE (def: IF file length)\n\n"
+ "Performs a SCSI WRITE SAME (10, 16 or 32) command\n"
+ );
}
static int
@@ -206,8 +206,8 @@ do_write_same(int sg_fd, const struct opts_t * optsp, const void * dataoutp,
wsCmdBlk[14] = (optsp->grpnum & 0x1f);
break;
case WRITE_SAME32_LEN:
- /* Note: In Linux at this time the sg driver does not support
- * cdb_s > 16 bytes long, but the bsg driver does. */
+ /* Note: In Linux at this time the sg driver does not support
+ * cdb_s > 16 bytes long, but the bsg driver does. */
wsCmdBlk[0] = VARIABLE_LEN_OP;
wsCmdBlk[6] = (optsp->grpnum & 0x1f);
wsCmdBlk[7] = WRITE_SAME32_ADD;