aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.in19
-rw-r--r--aclocal.m4134
-rwxr-xr-xcompile347
-rwxr-xr-xconfigure114
-rw-r--r--doc/Makefile.in2
-rw-r--r--doc/sg3_utils.828
-rw-r--r--include/Makefile.in2
-rw-r--r--include/sg_lib.h35
-rw-r--r--lib/Makefile.in6
-rw-r--r--lib/sg_cmds_basic.c93
-rw-r--r--lib/sg_cmds_basic2.c162
-rw-r--r--lib/sg_cmds_extra.c381
-rw-r--r--lib/sg_lib.c142
-rw-r--r--lib/sg_lib_data.c4
-rwxr-xr-xltmain.sh4
-rwxr-xr-xmissing4
-rw-r--r--scripts/Makefile.in2
-rw-r--r--src/Makefile.in6
-rw-r--r--src/sg_copy_results.c42
-rw-r--r--src/sg_get_lba_status.c13
-rw-r--r--src/sg_inq.c67
-rw-r--r--src/sg_logs.c30
-rw-r--r--src/sg_luns.c9
-rw-r--r--src/sg_modes.c19
-rw-r--r--src/sg_opcodes.c46
-rw-r--r--src/sg_persist.c172
-rw-r--r--src/sg_raw.c138
-rw-r--r--src/sg_read_buffer.c31
-rw-r--r--src/sg_readcap.c32
-rw-r--r--src/sg_referrals.c17
-rw-r--r--src/sg_requests.c18
-rw-r--r--src/sg_rtpg.c13
-rw-r--r--src/sg_sat_identify.c29
-rw-r--r--src/sg_scan.c.win326
-rw-r--r--src/sg_ses.c56
-rw-r--r--src/sg_turs.c129
-rw-r--r--src/sg_vpd.c20
-rw-r--r--src/sg_write_buffer.c40
39 files changed, 1305 insertions, 1113 deletions
diff --git a/ChangeLog b/ChangeLog
index deac9a30..537e9788 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,7 @@ 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.39 [20140513] [svn: r576]
+Changelog for sg3_utils-1.39 [20140515] [svn: r577]
- sg_ses: add --eiioe=auto|force option
- fix AES dpage element indexing problems
- add --readonly option
@@ -23,6 +23,10 @@ Changelog for sg3_utils-1.39 [20140513] [svn: r576]
- sginfo: strip trailing spaces from INQUIRY text
- sg_rbuf: add --echo option (to use echo buffer)
- sg_lib: add sanitize command service action names
+ - add 'sense' categories for reservation conflict,
+ data protect and protection information violations
+ - add sg_get_category_sense_str() to API
+ - add initial zbc service actions
- dStrHex(Err): fix output truncation error
- win32: sg_scan, sg_ses and sg_log fixes
- examples/sgq_dd: re-add old utility as example
diff --git a/Makefile.in b/Makefile.in
index 94ddde09..29b2ad1f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
@@ -81,8 +81,8 @@ subdir = .
DIST_COMMON = INSTALL NEWS README AUTHORS ChangeLog \
$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/configure $(am__configure_deps) \
- $(srcdir)/config.h.in COPYING TODO config.guess config.sub \
- depcomp install-sh missing ltmain.sh
+ $(srcdir)/config.h.in COPYING TODO compile config.guess \
+ config.sub depcomp install-sh missing ltmain.sh
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -356,8 +356,8 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
$(am__aclocal_m4_deps):
config.h: stamp-h1
- @if test ! -f $@; then rm -f stamp-h1; else :; fi
- @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
+ @test -f $@ || rm -f stamp-h1
+ @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1
stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
@rm -f stamp-h1
@@ -566,10 +566,16 @@ dist-xz: distdir
$(am__post_remove_distdir)
dist-tarZ: distdir
+ @echo WARNING: "Support for shar distribution archives is" \
+ "deprecated." >&2
+ @echo WARNING: "It will be removed altogether in Automake 2.0" >&2
tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z
$(am__post_remove_distdir)
dist-shar: distdir
+ @echo WARNING: "Support for distribution archives compressed with" \
+ "legacy program 'compress' is deprecated." >&2
+ @echo WARNING: "It will be removed altogether in Automake 2.0" >&2
shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__post_remove_distdir)
@@ -611,9 +617,10 @@ distcheck: dist
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
&& am__cwd=`pwd` \
&& $(am__cd) $(distdir)/_build \
- && ../configure --srcdir=.. --prefix="$$dc_install_base" \
+ && ../configure \
$(AM_DISTCHECK_CONFIGURE_FLAGS) \
$(DISTCHECK_CONFIGURE_FLAGS) \
+ --srcdir=.. --prefix="$$dc_install_base" \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
diff --git a/aclocal.m4 b/aclocal.m4
index a3152887..63d68788 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,4 +1,4 @@
-# generated automatically by aclocal 1.13.3 -*- Autoconf -*-
+# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
@@ -1326,7 +1326,7 @@ ia64-*-hpux*)
rm -rf conftest*
;;
-x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
# Find out which ABI we are using.
echo 'int i;' > conftest.$ac_ext
@@ -1347,7 +1347,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
;;
esac
;;
- ppc64-*linux*|powerpc64-*linux*)
+ powerpc64le-*)
+ LD="${LD-ld} -m elf32lppclinux"
+ ;;
+ powerpc64-*)
LD="${LD-ld} -m elf32ppclinux"
;;
s390x-*linux*)
@@ -1366,7 +1369,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
x86_64-*linux*)
LD="${LD-ld} -m elf_x86_64"
;;
- ppc*-*linux*|powerpc*-*linux*)
+ powerpcle-*)
+ LD="${LD-ld} -m elf64lppc"
+ ;;
+ powerpc-*)
LD="${LD-ld} -m elf64ppc"
;;
s390*-*linux*|s390*-*tpf*)
@@ -8628,10 +8634,10 @@ m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])])
# generated from the m4 files accompanying Automake X.Y.
# (This private macro should not be called outside this file.)
AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.13'
+[am__api_version='1.14'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.13.3], [],
+m4_if([$1], [1.14.1], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -8647,7 +8653,7 @@ m4_define([_AM_AUTOCONF_VERSION], [])
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.13.3])dnl
+[AM_AUTOMAKE_VERSION([1.14.1])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
@@ -9014,6 +9020,12 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
# This macro actually does too much. Some checks are only needed if
# your package does certain things. But this isn't really a big deal.
+dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O.
+m4_define([AC_PROG_CC],
+m4_defn([AC_PROG_CC])
+[_AM_PROG_CC_C_O
+])
+
# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
# AM_INIT_AUTOMAKE([OPTIONS])
# -----------------------------------------------
@@ -9122,7 +9134,48 @@ dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below.
AC_CONFIG_COMMANDS_PRE(dnl
[m4_provide_if([_AM_COMPILER_EXEEXT],
[AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl
-])
+
+# POSIX will say in a future version that running "rm -f" with no argument
+# is OK; and we want to be able to make that assumption in our Makefile
+# recipes. So use an aggressive probe to check that the usage we want is
+# actually supported "in the wild" to an acceptable degree.
+# See automake bug#10828.
+# To make any issue more visible, cause the running configure to be aborted
+# by default if the 'rm' program in use doesn't match our expectations; the
+# user can still override this though.
+if rm -f && rm -fr && rm -rf; then : OK; else
+ cat >&2 <<'END'
+Oops!
+
+Your 'rm' program seems unable to run without file operands specified
+on the command line, even when the '-f' option is present. This is contrary
+to the behaviour of most rm programs out there, and not conforming with
+the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
+
+Please tell bug-automake@gnu.org about your system, including the value
+of your $PATH and any error possibly output before this message. This
+can help us improve future automake versions.
+
+END
+ if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
+ echo 'Configuration will proceed anyway, since you have set the' >&2
+ echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
+ echo >&2
+ else
+ cat >&2 <<'END'
+Aborting the configuration process, to ensure you take notice of the issue.
+
+You can download and install GNU coreutils to get an 'rm' implementation
+that behaves properly: <http://www.gnu.org/software/coreutils/>.
+
+If you want to complete the configuration process using your problematic
+'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
+to "yes", and re-run configure.
+
+END
+ AC_MSG_ERROR([Your 'rm' program is bad, sorry.])
+ fi
+fi])
dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not
dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further
@@ -9130,7 +9183,6 @@ dnl mangled by Autoconf and run in a shell conditional statement.
m4_define([_AC_COMPILER_EXEEXT],
m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])])
-
# When config.status generates a header, we must update the stamp-h file.
# This file resides in the same directory as the config header
# that is generated. The stamp files are numbered to have different names.
@@ -9377,6 +9429,70 @@ AC_DEFUN([_AM_SET_OPTIONS],
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# _AM_PROG_CC_C_O
+# ---------------
+# Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC
+# to automatically call this.
+AC_DEFUN([_AM_PROG_CC_C_O],
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
+AC_REQUIRE_AUX_FILE([compile])dnl
+AC_LANG_PUSH([C])dnl
+AC_CACHE_CHECK(
+ [whether $CC understands -c and -o together],
+ [am_cv_prog_cc_c_o],
+ [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])])
+ # Make sure it works both with $CC and with simple cc.
+ # Following AC_PROG_CC_C_O, we do the test twice because some
+ # compilers refuse to overwrite an existing .o file with -o,
+ # though they will create one.
+ am_cv_prog_cc_c_o=yes
+ for am_i in 1 2; do
+ if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \
+ && test -f conftest2.$ac_objext; then
+ : OK
+ else
+ am_cv_prog_cc_c_o=no
+ break
+ fi
+ done
+ rm -f core conftest*
+ unset am_i])
+if test "$am_cv_prog_cc_c_o" != yes; then
+ # Losing compiler, so override with the script.
+ # FIXME: It is wrong to rewrite CC.
+ # But if we don't then we get into trouble of one sort or another.
+ # A longer-term fix would be to have automake use am__CC in this case,
+ # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+ CC="$am_aux_dir/compile $CC"
+fi
+AC_LANG_POP([C])])
+
+# For backward compatibility.
+AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])])
+
+# Copyright (C) 2001-2013 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# AM_RUN_LOG(COMMAND)
+# -------------------
+# Run COMMAND, save the exit status in ac_status, and log it.
+# (This has been adapted from Autoconf's _AC_RUN_LOG macro.)
+AC_DEFUN([AM_RUN_LOG],
+[{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD
+ ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
+ (exit $ac_status); }])
+
# Check to make sure that the build environment is sane. -*- Autoconf -*-
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
diff --git a/compile b/compile
new file mode 100755
index 00000000..531136b0
--- /dev/null
+++ b/compile
@@ -0,0 +1,347 @@
+#! /bin/sh
+# Wrapper for compilers which do not understand '-c -o'.
+
+scriptversion=2012-10-14.11; # UTC
+
+# Copyright (C) 1999-2013 Free Software Foundation, Inc.
+# Written by Tom Tromey <tromey@cygnus.com>.
+#
+# 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 is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+nl='
+'
+
+# We need space, tab and new line, in precisely that order. Quoting is
+# there to prevent tools from complaining about whitespace usage.
+IFS=" "" $nl"
+
+file_conv=
+
+# func_file_conv build_file lazy
+# Convert a $build file to $host form and store it in $file
+# Currently only supports Windows hosts. If the determined conversion
+# type is listed in (the comma separated) LAZY, no conversion will
+# take place.
+func_file_conv ()
+{
+ file=$1
+ case $file in
+ / | /[!/]*) # absolute file, and not a UNC file
+ if test -z "$file_conv"; then
+ # lazily determine how to convert abs files
+ case `uname -s` in
+ MINGW*)
+ file_conv=mingw
+ ;;
+ CYGWIN*)
+ file_conv=cygwin
+ ;;
+ *)
+ file_conv=wine
+ ;;
+ esac
+ fi
+ case $file_conv/,$2, in
+ *,$file_conv,*)
+ ;;
+ mingw/*)
+ file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
+ ;;
+ cygwin/*)
+ file=`cygpath -m "$file" || echo "$file"`
+ ;;
+ wine/*)
+ file=`winepath -w "$file" || echo "$file"`
+ ;;
+ esac
+ ;;
+ esac
+}
+
+# func_cl_dashL linkdir
+# Make cl look for libraries in LINKDIR
+func_cl_dashL ()
+{
+ func_file_conv "$1"
+ if test -z "$lib_path"; then
+ lib_path=$file
+ else
+ lib_path="$lib_path;$file"
+ fi
+ linker_opts="$linker_opts -LIBPATH:$file"
+}
+
+# func_cl_dashl library
+# Do a library search-path lookup for cl
+func_cl_dashl ()
+{
+ lib=$1
+ found=no
+ save_IFS=$IFS
+ IFS=';'
+ for dir in $lib_path $LIB
+ do
+ IFS=$save_IFS
+ if $shared && test -f "$dir/$lib.dll.lib"; then
+ found=yes
+ lib=$dir/$lib.dll.lib
+ break
+ fi
+ if test -f "$dir/$lib.lib"; then
+ found=yes
+ lib=$dir/$lib.lib
+ break
+ fi
+ if test -f "$dir/lib$lib.a"; then
+ found=yes
+ lib=$dir/lib$lib.a
+ break
+ fi
+ done
+ IFS=$save_IFS
+
+ if test "$found" != yes; then
+ lib=$lib.lib
+ fi
+}
+
+# func_cl_wrapper cl arg...
+# Adjust compile command to suit cl
+func_cl_wrapper ()
+{
+ # Assume a capable shell
+ lib_path=
+ shared=:
+ linker_opts=
+ for arg
+ do
+ if test -n "$eat"; then
+ eat=
+ else
+ case $1 in
+ -o)
+ # configure might choose to run compile as 'compile cc -o foo foo.c'.
+ eat=1
+ case $2 in
+ *.o | *.[oO][bB][jJ])
+ func_file_conv "$2"
+ set x "$@" -Fo"$file"
+ shift
+ ;;
+ *)
+ func_file_conv "$2"
+ set x "$@" -Fe"$file"
+ shift
+ ;;
+ esac
+ ;;
+ -I)
+ eat=1
+ func_file_conv "$2" mingw
+ set x "$@" -I"$file"
+ shift
+ ;;
+ -I*)
+ func_file_conv "${1#-I}" mingw
+ set x "$@" -I"$file"
+ shift
+ ;;
+ -l)
+ eat=1
+ func_cl_dashl "$2"
+ set x "$@" "$lib"
+ shift
+ ;;
+ -l*)
+ func_cl_dashl "${1#-l}"
+ set x "$@" "$lib"
+ shift
+ ;;
+ -L)
+ eat=1
+ func_cl_dashL "$2"
+ ;;
+ -L*)
+ func_cl_dashL "${1#-L}"
+ ;;
+ -static)
+ shared=false
+ ;;
+ -Wl,*)
+ arg=${1#-Wl,}
+ save_ifs="$IFS"; IFS=','
+ for flag in $arg; do
+ IFS="$save_ifs"
+ linker_opts="$linker_opts $flag"
+ done
+ IFS="$save_ifs"
+ ;;
+ -Xlinker)
+ eat=1
+ linker_opts="$linker_opts $2"
+ ;;
+ -*)
+ set x "$@" "$1"
+ shift
+ ;;
+ *.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
+ func_file_conv "$1"
+ set x "$@" -Tp"$file"
+ shift
+ ;;
+ *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
+ func_file_conv "$1" mingw
+ set x "$@" "$file"
+ shift
+ ;;
+ *)
+ set x "$@" "$1"
+ shift
+ ;;
+ esac
+ fi
+ shift
+ done
+ if test -n "$linker_opts"; then
+ linker_opts="-link$linker_opts"
+ fi
+ exec "$@" $linker_opts
+ exit 1
+}
+
+eat=
+
+case $1 in
+ '')
+ echo "$0: No command. Try '$0 --help' for more information." 1>&2
+ exit 1;
+ ;;
+ -h | --h*)
+ cat <<\EOF
+Usage: compile [--help] [--version] PROGRAM [ARGS]
+
+Wrapper for compilers which do not understand '-c -o'.
+Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
+arguments, and rename the output as expected.
+
+If you are trying to build a whole package this is not the
+right script to run: please start by reading the file 'INSTALL'.
+
+Report bugs to <bug-automake@gnu.org>.
+EOF
+ exit $?
+ ;;
+ -v | --v*)
+ echo "compile $scriptversion"
+ exit $?
+ ;;
+ cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
+ func_cl_wrapper "$@" # Doesn't return...
+ ;;
+esac
+
+ofile=
+cfile=
+
+for arg
+do
+ if test -n "$eat"; then
+ eat=
+ else
+ case $1 in
+ -o)
+ # configure might choose to run compile as 'compile cc -o foo foo.c'.
+ # So we strip '-o arg' only if arg is an object.
+ eat=1
+ case $2 in
+ *.o | *.obj)
+ ofile=$2
+ ;;
+ *)
+ set x "$@" -o "$2"
+ shift
+ ;;
+ esac
+ ;;
+ *.c)
+ cfile=$1
+ set x "$@" "$1"
+ shift
+ ;;
+ *)
+ set x "$@" "$1"
+ shift
+ ;;
+ esac
+ fi
+ shift
+done
+
+if test -z "$ofile" || test -z "$cfile"; then
+ # If no '-o' option was seen then we might have been invoked from a
+ # pattern rule where we don't need one. That is ok -- this is a
+ # normal compilation that the losing compiler can handle. If no
+ # '.c' file was seen then we are probably linking. That is also
+ # ok.
+ exec "$@"
+fi
+
+# Name of file we expect compiler to create.
+cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
+
+# Create the lock directory.
+# Note: use '[/\\:.-]' here to ensure that we don't use the same name
+# that we are using for the .o file. Also, base the name on the expected
+# object file name, since that is what matters with a parallel build.
+lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
+while true; do
+ if mkdir "$lockdir" >/dev/null 2>&1; then
+ break
+ fi
+ sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir '$lockdir'; exit 1" 1 2 15
+
+# Run the compile.
+"$@"
+ret=$?
+
+if test -f "$cofile"; then
+ test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+ test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
+fi
+
+rmdir "$lockdir"
+exit $ret
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/configure b/configure
index b20df8a6..665ee702 100755
--- a/configure
+++ b/configure
@@ -2139,7 +2139,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
-am__api_version='1.13'
+am__api_version='1.14'
ac_aux_dir=
for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
@@ -2705,6 +2705,47 @@ am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'
+# POSIX will say in a future version that running "rm -f" with no argument
+# is OK; and we want to be able to make that assumption in our Makefile
+# recipes. So use an aggressive probe to check that the usage we want is
+# actually supported "in the wild" to an acceptable degree.
+# See automake bug#10828.
+# To make any issue more visible, cause the running configure to be aborted
+# by default if the 'rm' program in use doesn't match our expectations; the
+# user can still override this though.
+if rm -f && rm -fr && rm -rf; then : OK; else
+ cat >&2 <<'END'
+Oops!
+
+Your 'rm' program seems unable to run without file operands specified
+on the command line, even when the '-f' option is present. This is contrary
+to the behaviour of most rm programs out there, and not conforming with
+the upcoming POSIX standard: <http://austingroupbugs.net/view.php?id=542>
+
+Please tell bug-automake@gnu.org about your system, including the value
+of your $PATH and any error possibly output before this message. This
+can help us improve future automake versions.
+
+END
+ if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then
+ echo 'Configuration will proceed anyway, since you have set the' >&2
+ echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2
+ echo >&2
+ else
+ cat >&2 <<'END'
+Aborting the configuration process, to ensure you take notice of the issue.
+
+You can download and install GNU coreutils to get an 'rm' implementation
+that behaves properly: <http://www.gnu.org/software/coreutils/>.
+
+If you want to complete the configuration process using your problematic
+'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM
+to "yes", and re-run configure.
+
+END
+ as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5
+ fi
+fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5
$as_echo_n "checking whether to enable maintainer-specific portions of Makefiles... " >&6; }
@@ -3519,6 +3560,65 @@ ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5
+$as_echo_n "checking whether $CC understands -c and -o together... " >&6; }
+if ${am_cv_prog_cc_c_o+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+ # Make sure it works both with $CC and with simple cc.
+ # Following AC_PROG_CC_C_O, we do the test twice because some
+ # compilers refuse to overwrite an existing .o file with -o,
+ # though they will create one.
+ am_cv_prog_cc_c_o=yes
+ for am_i in 1 2; do
+ if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5
+ ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } \
+ && test -f conftest2.$ac_objext; then
+ : OK
+ else
+ am_cv_prog_cc_c_o=no
+ break
+ fi
+ done
+ rm -f core conftest*
+ unset am_i
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5
+$as_echo "$am_cv_prog_cc_c_o" >&6; }
+if test "$am_cv_prog_cc_c_o" != yes; then
+ # Losing compiler, so override with the script.
+ # FIXME: It is wrong to rewrite CC.
+ # But if we don't then we get into trouble of one sort or another.
+ # A longer-term fix would be to have automake use am__CC in this case,
+ # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
+ CC="$am_aux_dir/compile $CC"
+fi
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
DEPDIR="${am__leading_dot}deps"
ac_config_commands="$ac_config_commands depfiles"
@@ -6122,7 +6222,7 @@ ia64-*-hpux*)
rm -rf conftest*
;;
-x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \
s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
# Find out which ABI we are using.
echo 'int i;' > conftest.$ac_ext
@@ -6147,7 +6247,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
;;
esac
;;
- ppc64-*linux*|powerpc64-*linux*)
+ powerpc64le-*)
+ LD="${LD-ld} -m elf32lppclinux"
+ ;;
+ powerpc64-*)
LD="${LD-ld} -m elf32ppclinux"
;;
s390x-*linux*)
@@ -6166,7 +6269,10 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
x86_64-*linux*)
LD="${LD-ld} -m elf_x86_64"
;;
- ppc*-*linux*|powerpc*-*linux*)
+ powerpcle-*)
+ LD="${LD-ld} -m elf64lppc"
+ ;;
+ powerpc-*)
LD="${LD-ld} -m elf64ppc"
;;
s390*-*linux*|s390*-*tpf*)
diff --git a/doc/Makefile.in b/doc/Makefile.in
index cb88a3e5..023729b3 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
diff --git a/doc/sg3_utils.8 b/doc/sg3_utils.8
index a613d3ce..50e573f8 100644
--- a/doc/sg3_utils.8
+++ b/doc/sg3_utils.8
@@ -1,4 +1,4 @@
-.TH SG3_UTILS "8" "April 2014" "sg3_utils\-1.39" SG3_UTILS
+.TH SG3_UTILS "8" "May 2014" "sg3_utils\-1.39" SG3_UTILS
.SH NAME
sg3_utils \- a package of utilities for sending SCSI commands
.SH SYNOPSIS
@@ -217,11 +217,20 @@ reset) potentially before the current SCSI command was sent. The requested
command has not been executed by the device. Note that unit attention
conditions are usually only reported once by a device.
.TP
+.B 7
+the \fIDEVICE\fR reports a "data protect" sense key. This implies some
+mechanism has blocked writes (or possibly all access to the media).
+.TP
.B 9
the \fIDEVICE\fR reports an illegal request with an additional sense code
of "invalid command operation code" which means that it doesn't support the
requested command.
.TP
+.B 10
+the \fIDEVICE\fR reports a "copy aborted". This implies another command or
+device problem has stopped and copy operation. The EXTENDED COPY family of
+commands (including WRITE USING TOKEN) may return this sense key.
+.TP
.B 11
the \fIDEVICE\fR reports an aborted command. In some cases aborted
commands can be retried immediately (e.g. if the transport aborted
@@ -239,7 +248,8 @@ permission problems. Adding the '\-v' option may give more information.
.B 20
the \fIDEVICE\fR reports it has a check condition but "no sense"
and non\-zero information in its additional sense codes. Some polling
-commands (e.g. REQUEST SENSE) can receive this response.
+commands (e.g. REQUEST SENSE) can receive this response. There may
+be useful information in the sense data such as a progress indication.
.TP
.B 21
the \fIDEVICE\fR reports a "recovered error". The requested command
@@ -247,9 +257,23 @@ was successful. Most likely a utility will report a recovered error
to stderr and continue, probably leaving the utility with an exit
status of 0 .
.TP
+.B 24
+the \fIDEVICE\fR reports a SCSI status of "reservation conflict". This
+means access to the \fIDEVICE\fR with the current command has been blocked
+because another machine (HBA or SCSI "initiator") holds a reservation on
+this \fIDEVICE\fR. On modern SCSI systems this is related to the use of
+the PERSISTENT RESERVATION family of commands.
+.TP
.B 33
the command sent to \fIDEVICE\fR has timed out.
.TP
+.B 40
+the command sent to \fIDEVICE\fR has received an "aborted command" sense
+key with an additional sense code of 0x10. This group is related to
+problems with protection information (PI or DIF). For example this error
+may occur when reading a block on a drive that has never been written (or
+is unmapped) if that drive was formatted with type 1, 2 or 3 protection.
+.TP
.B 97
a SCSI command response failed sanity checks.
.TP
diff --git a/include/Makefile.in b/include/Makefile.in
index 64f3daa2..bbe399c7 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
diff --git a/include/sg_lib.h b/include/sg_lib.h
index dd7db34a..f9e172cc 100644
--- a/include/sg_lib.h
+++ b/include/sg_lib.h
@@ -225,35 +225,45 @@ void sg_print_sense(const char * leadin, const unsigned char * sense_buffer,
int sb_len, int raw_info);
void sg_print_scsi_status(int scsi_status);
-/* Utilities can use these process status values for syntax errors and
+/* Utilities can use these exit status values for syntax errors and
* file (device node) problems (e.g. not found or permissions). */
-#define SG_LIB_SYNTAX_ERROR 1
-#define SG_LIB_FILE_ERROR 15
+#define SG_LIB_SYNTAX_ERROR 1 /* command line syntax problem */
+#define SG_LIB_FILE_ERROR 15 /* device or other file problem */
/* The sg_err_category_sense() function returns one of the following.
- * These may be used as process status values (on exit). Notice that
+ * These may be used as exit status values (from a process). Notice that
* some of the lower values correspond to SCSI sense key values. */
#define SG_LIB_CAT_CLEAN 0 /* No errors or other information */
/* Value 1 left unused for utilities to use SG_LIB_SYNTAX_ERROR */
-#define SG_LIB_CAT_NOT_READY 2 /* interpreted from sense buffer */
+#define SG_LIB_CAT_NOT_READY 2 /* sense key, unit stopped? */
/* [sk,asc,ascq: 0x2,*,*] */
#define SG_LIB_CAT_MEDIUM_HARD 3 /* medium or hardware error, blank check */
/* [sk,asc,ascq: 0x3/0x4/0x8,*,*] */
#define SG_LIB_CAT_ILLEGAL_REQ 5 /* Illegal request (other than invalid */
/* opcode): [sk,asc,ascq: 0x5,*,*] */
-#define SG_LIB_CAT_UNIT_ATTENTION 6 /* interpreted from sense buffer */
+#define SG_LIB_CAT_UNIT_ATTENTION 6 /* sense key, device state changed */
/* [sk,asc,ascq: 0x6,*,*] */
/* was SG_LIB_CAT_MEDIA_CHANGED earlier [sk,asc,ascq: 0x6,0x28,*] */
+#define SG_LIB_CAT_DATA_PROTECT 7 /* sense key, media write protected? */
+ /* [sk,asc,ascq: 0x7,*,*] */
#define SG_LIB_CAT_INVALID_OP 9 /* (Illegal request,) Invalid opcode: */
/* [sk,asc,ascq: 0x5,0x20,0x0] */
+#define SG_LIB_CAT_COPY_ABORTED 10 /* sense key, some data transferred */
+ /* [sk,asc,ascq: 0xa,*,*] */
#define SG_LIB_CAT_ABORTED_COMMAND 11 /* interpreted from sense buffer */
- /* [sk,asc,ascq: 0xb,*,*] */
-#define SG_LIB_CAT_MISCOMPARE 14 /* interpreted from sense buffer */
+ /* [sk,asc,ascq: 0xb,! 0x10,*] */
+#define SG_LIB_CAT_MISCOMPARE 14 /* sense key, probably verify */
/* [sk,asc,ascq: 0xe,*,*] */
#define SG_LIB_CAT_NO_SENSE 20 /* sense data with key of "no sense" */
/* [sk,asc,ascq: 0x0,*,*] */
#define SG_LIB_CAT_RECOVERED 21 /* Successful command after recovered err */
/* [sk,asc,ascq: 0x1,*,*] */
+#define SG_LIB_CAT_RES_CONFLICT SAM_STAT_RESERVATION_CONFLICT
+ /* 24: this is a SCSI status, not sense. */
+ /* It indicates reservation by another */
+ /* machine blocks this command */
+#define SG_LIB_CAT_PROTECTION 40 /* subset of aborted command (for PI, DIF) */
+ /* [sk,asc,ascq: 0xb,0x10,*] */
#define SG_LIB_CAT_MALFORMED 97 /* Response to SCSI command malformed */
#define SG_LIB_CAT_SENSE 98 /* Something else is in the sense buffer */
#define SG_LIB_CAT_OTHER 99 /* Some other error/warning has occurred */
@@ -271,8 +281,17 @@ int sg_err_category_sense(const unsigned char * sense_buffer, int sb_len);
#define SG_LIB_CAT_MEDIUM_HARD_WITH_INFO 18 /* medium or hardware error */
/* sense key plus 'info' field: */
/* [sk,asc,ascq: 0x3/0x4,*,*] */
+#define SG_LIB_CAT_PROTECTION_WITH_INFO 41 /* aborted command sense key, */
+ /* protection plus 'info' field: */
+ /* [sk,asc,ascq: 0xb,0x10,*] */
#define SG_LIB_CAT_TIMEOUT 33
+/* Yield string associated with sense category. Returns 'buff' (or pointer
+ * to "Bad sense category" if 'buff' is NULL). If sense_cat unknown then
+ * yield "Sense category: <sense_cat>" string. */
+const char * sg_get_category_sense_str(int sense_cat, int buff_len,
+ char * buff, int verbose);
+
/* Iterates to next designation descriptor in the device identification
* VPD page. The 'initial_desig_desc' should point to start of first
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 084f5a61..d9d9beaa 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
@@ -442,14 +442,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/lib/sg_cmds_basic.c b/lib/sg_cmds_basic.c
index 0542de82..43c127c7 100644
--- a/lib/sg_cmds_basic.c
+++ b/lib/sg_cmds_basic.c
@@ -27,7 +27,7 @@
#endif
-static const char * version_str = "1.66 20140222";
+static const char * version_str = "1.67 20140514";
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
@@ -94,7 +94,11 @@ sg_cmds_process_helper(const char * leadin, int mx_di_len, int resid,
case SG_LIB_CAT_INVALID_OP:
case SG_LIB_CAT_ILLEGAL_REQ:
case SG_LIB_CAT_ABORTED_COMMAND:
+ case SG_LIB_CAT_COPY_ABORTED:
+ case SG_LIB_CAT_DATA_PROTECT:
+ case SG_LIB_CAT_PROTECTION:
case SG_LIB_CAT_NO_SENSE:
+ case SG_LIB_CAT_MISCOMPARE:
n = 0;
break;
case SG_LIB_CAT_RECOVERED:
@@ -102,6 +106,7 @@ sg_cmds_process_helper(const char * leadin, int mx_di_len, int resid,
++check_data_in;
/* drop through */
case SG_LIB_CAT_UNIT_ATTENTION:
+ case SG_LIB_CAT_SENSE:
default:
n = noisy;
break;
@@ -126,8 +131,8 @@ sg_cmds_process_helper(const char * leadin, int mx_di_len, int resid,
* call to the pass-through. pt_res is returned from do_scsi_pt(). If valid
* sense data is found it is decoded and output to sg_warnings_strm (def:
* stderr); depending on the 'noisy' and 'verbose' settings. Returns -2 for
- * sense data (may not be fatal), -1 for failed, 0, or a positive number. If
- * 'mx_di_len > 0' then asks pass-through for resid and returns
+ * "sense" category (may not be fatal), -1 for failed, 0, or a positive
+ * number. If 'mx_di_len > 0' then asks pass-through for resid and returns
* (mx_di_len - resid); otherwise returns 0. So for data-in it should return
* the actual number of bytes received. For data-out (to device) or no data
* call with 'mx_di_len' set to 0 or less. If -2 returned then sense category
@@ -138,7 +143,7 @@ sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin,
int pt_res, int mx_di_len, const unsigned char * sbp,
int noisy, int verbose, int * o_sense_cat)
{
- int got, cat, duration, slen, resid, resp_code;
+ int got, cat, duration, slen, resid, resp_code, sstat;
char b[1024];
if (NULL == sg_warnings_strm)
@@ -186,9 +191,14 @@ sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin,
} else
return 0;
case SCSI_PT_RESULT_STATUS: /* other than GOOD and CHECK CONDITION */
+ sstat = get_scsi_pt_status_response(ptvp);
+ if ((SAM_STAT_RESERVATION_CONFLICT == sstat) && o_sense_cat) {
+ /* treat this SCSI status as "sense" category */
+ *o_sense_cat = SG_LIB_CAT_RES_CONFLICT;
+ return -2;
+ }
if (verbose || noisy) {
- sg_get_scsi_status_str(get_scsi_pt_status_response(ptvp),
- sizeof(b), b);
+ sg_get_scsi_status_str(sstat, sizeof(b), b);
fprintf(sg_warnings_strm, "%s: scsi status: %s\n", leadin, b);
}
return -1;
@@ -219,10 +229,8 @@ sg_cmds_process_resp(struct sg_pt_base * ptvp, const char * leadin,
}
}
-/* Invokes a SCSI INQUIRY command and yields the response
- * Returns 0 when successful, SG_LIB_CAT_INVALID_OP -> not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_MALFORMED -> bad response, -1 -> other errors */
+/* Invokes a SCSI INQUIRY command and yields the response. Returns 0 when
+ * successful, various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_inquiry(int sg_fd, int cmddt, int evpd, int pg_op, void * resp,
int mx_resp_len, int noisy, int verbose)
@@ -271,17 +279,12 @@ sg_ll_inquiry(int sg_fd, int cmddt, int evpd, int pg_op, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else if (ret < 4) {
@@ -296,9 +299,8 @@ sg_ll_inquiry(int sg_fd, int cmddt, int evpd, int pg_op, void * resp,
}
/* Yields most of first 36 bytes of a standard INQUIRY (evpd==0) response.
- * Returns 0 when successful, SG_LIB_CAT_INVALID_OP -> not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_MALFORMED -> bad response, -1 -> other errors */
+ * Returns 0 when successful, various SG_LIB_CAT_* positive values or
+ * -1 -> other errors */
int
sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
int noisy, int verbose)
@@ -340,17 +342,12 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else if (ret < 4) {
@@ -382,9 +379,8 @@ sg_simple_inquiry(int sg_fd, struct sg_simple_inquiry_resp * inq_data,
* 'pack_id' is just for diagnostics, safe to set to 0.
* Looks for progress indicator if 'progress' non-NULL;
* if found writes value [0..65535] else write -1.
- * Return of 0 -> success, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_NOT_READY ->
- * device not ready, -1 -> other failure */
+ * Returns 0 when successful, various SG_LIB_CAT_* positive values or
+ * -1 -> other errors */
int
sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
int noisy, int verbose)
@@ -424,19 +420,12 @@ sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
*progress = -1;
}
switch (sense_cat) {
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -448,9 +437,8 @@ sg_ll_test_unit_ready_progress(int sg_fd, int pack_id, int * progress,
/* Invokes a SCSI TEST UNIT READY command.
* 'pack_id' is just for diagnostics, safe to set to 0.
- * Return of 0 -> success, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_NOT_READY ->
- * device not ready, -1 -> other failure */
+ * Returns 0 when successful, various SG_LIB_CAT_* positive values or
+ * -1 -> other errors */
int
sg_ll_test_unit_ready(int sg_fd, int pack_id, int noisy, int verbose)
{
@@ -458,10 +446,8 @@ sg_ll_test_unit_ready(int sg_fd, int pack_id, int noisy, int verbose)
verbose);
}
-/* Invokes a SCSI REQUEST SENSE command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Request Sense not supported??,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ABORTED_COMMAND, -1 -> other failure */
+/* Invokes a SCSI REQUEST SENSE command. Returns 0 when successful, various
+ * SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_request_sense(int sg_fd, int desc, void * resp, int mx_resp_len,
int noisy, int verbose)
@@ -503,18 +489,12 @@ sg_ll_request_sense(int sg_fd, int desc, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
- case SG_LIB_CAT_NOT_READY: /* shouldn't happen ?? */
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -531,10 +511,7 @@ sg_ll_request_sense(int sg_fd, int desc, void * resp, int mx_resp_len,
}
/* Invokes a SCSI REPORT LUNS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Report Luns not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_NOT_READY (shouldn't happen), -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_report_luns(int sg_fd, int select_report, void * resp, int mx_resp_len,
int noisy, int verbose)
@@ -574,18 +551,12 @@ sg_ll_report_luns(int sg_fd, int select_report, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- case SG_LIB_CAT_NOT_READY: /* shouldn't happen ?? */
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
diff --git a/lib/sg_cmds_basic2.c b/lib/sg_cmds_basic2.c
index 77cf8367..a9378de8 100644
--- a/lib/sg_cmds_basic2.c
+++ b/lib/sg_cmds_basic2.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999-2013 Douglas Gilbert.
+ * Copyright (c) 1999-2014 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.
@@ -67,10 +67,7 @@
/* Invokes a SCSI SYNCHRONIZE CACHE (10) command. Return of 0 -> success,
- * SG_LIB_CAT_UNIT_ATTENTION -> repeat,
- * SG_LIB_CAT_INVALID_OP -> cdb not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_sync_cache_10(int sg_fd, int sync_nv, int immed, int group,
unsigned int lba, unsigned int count, int noisy,
@@ -120,19 +117,12 @@ sg_ll_sync_cache_10(int sg_fd, int sync_nv, int immed, int group,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -143,10 +133,7 @@ sg_ll_sync_cache_10(int sg_fd, int sync_nv, int immed, int group,
}
/* Invokes a SCSI READ CAPACITY (16) command. Returns 0 -> success,
- * SG_LIB_CAT_UNIT_ATTENTION -> media changed??, SG_LIB_CAT_INVALID_OP
- * -> cdb not supported, SG_LIB_CAT_IlLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_NOT_READY -> device not ready,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_readcap_16(int sg_fd, int pmi, uint64_t llba, void * resp,
int mx_resp_len, int noisy, int verbose)
@@ -197,19 +184,12 @@ sg_ll_readcap_16(int sg_fd, int pmi, uint64_t llba, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -220,10 +200,7 @@ sg_ll_readcap_16(int sg_fd, int pmi, uint64_t llba, void * resp,
}
/* Invokes a SCSI READ CAPACITY (10) command. Returns 0 -> success,
- * SG_LIB_CAT_UNIT_ATTENTION -> media changed??, SG_LIB_CAT_INVALID_OP
- * -> cdb not supported, SG_LIB_CAT_IlLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_NOT_READY -> device not ready,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_readcap_10(int sg_fd, int pmi, unsigned int lba, void * resp,
int mx_resp_len, int noisy, int verbose)
@@ -264,19 +241,12 @@ sg_ll_readcap_10(int sg_fd, int pmi, unsigned int lba, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -287,10 +257,7 @@ sg_ll_readcap_10(int sg_fd, int pmi, unsigned int lba, void * resp,
}
/* Invokes a SCSI MODE SENSE (6) command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
- * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_UNIT_ATTENTION,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_mode_sense6(int sg_fd, int dbd, int pc, int pg_code, int sub_pg_code,
void * resp, int mx_resp_len, int noisy, int verbose)
@@ -332,19 +299,12 @@ sg_ll_mode_sense6(int sg_fd, int dbd, int pc, int pg_code, int sub_pg_code,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -360,10 +320,7 @@ sg_ll_mode_sense6(int sg_fd, int dbd, int pc, int pg_code, int sub_pg_code,
}
/* Invokes a SCSI MODE SENSE (10) command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
- * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_UNIT_ATTENTION,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_mode_sense10(int sg_fd, int llbaa, int dbd, int pc, int pg_code,
int sub_pg_code, void * resp, int mx_resp_len,
@@ -407,19 +364,12 @@ sg_ll_mode_sense10(int sg_fd, int llbaa, int dbd, int pc, int pg_code,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -435,10 +385,7 @@ sg_ll_mode_sense10(int sg_fd, int llbaa, int dbd, int pc, int pg_code,
}
/* Invokes a SCSI MODE SELECT (6) command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
- * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_UNIT_ATTENTION,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_mode_select6(int sg_fd, int pf, int sp, void * paramp, int param_len,
int noisy, int verbose)
@@ -483,19 +430,12 @@ sg_ll_mode_select6(int sg_fd, int pf, int sp, void * paramp, int param_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -506,10 +446,7 @@ sg_ll_mode_select6(int sg_fd, int pf, int sp, void * paramp, int param_len,
}
/* Invokes a SCSI MODE SELECT (10) command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_ILLEGAL_REQ ->
- * bad field in cdb, * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_ABORTED_COMMAND, SG_LIB_CAT_UNIT_ATTENTION,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_mode_select10(int sg_fd, int pf, int sp, void * paramp, int param_len,
int noisy, int verbose)
@@ -555,19 +492,12 @@ sg_ll_mode_select10(int sg_fd, int pf, int sp, void * paramp, int param_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -632,10 +562,8 @@ sg_mode_page_offset(const unsigned char * resp, int resp_len,
* should have 4 elements for output of current, changeable, default
* and saved values respectively. Each element should be NULL or
* at least mx_mpage_len bytes long.
- * Return of 0 -> overall success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_MALFORMED -> bad response, -1 -> other failure.
+ * Return of 0 -> overall success, various SG_LIB_CAT_* positive values or
+ * -1 -> other errors.
* If success_mask pointer is not NULL then first zeros it. Then set bits
* 0, 1, 2 and/or 3 if the current, changeable, default and saved values
* respectively have been fetched. If error on current page
@@ -744,10 +672,7 @@ sg_get_mode_page_controls(int sg_fd, int mode6, int pg_code, int sub_pg_code,
}
/* Invokes a SCSI LOG SENSE command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Log Sense not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_log_sense(int sg_fd, int ppc, int sp, int pc, int pg_code,
int subpg_code, int paramp, unsigned char * resp,
@@ -794,19 +719,12 @@ sg_ll_log_sense(int sg_fd, int ppc, int sp, int pc, int pg_code,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -822,10 +740,7 @@ sg_ll_log_sense(int sg_fd, int ppc, int sp, int pc, int pg_code,
}
/* Invokes a SCSI LOG SELECT command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Log Select not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_log_select(int sg_fd, int pcr, int sp, int pc, int pg_code,
int subpg_code, unsigned char * paramp, int param_len,
@@ -874,19 +789,12 @@ sg_ll_log_select(int sg_fd, int pcr, int sp, int pc, int pg_code,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -898,10 +806,7 @@ sg_ll_log_select(int sg_fd, int pcr, int sp, int pc, int pg_code,
/* Invokes a SCSI START STOP UNIT command (SBC + MMC).
* Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Start stop unit not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure
+ * various SG_LIB_CAT_* positive values or -1 -> other errors.
* SBC-3 and MMC partially overlap on the power_condition_modifier(sbc) and
* format_layer_number(mmc) fields. They also overlap on the noflush(sbc)
* and fl(mmc) one bit field. This is the cause of the awkardly named
@@ -944,19 +849,12 @@ sg_ll_start_stop_unit(int sg_fd, int immed, int pc_mod__fl_num,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -969,10 +867,7 @@ sg_ll_start_stop_unit(int sg_fd, int immed, int pc_mod__fl_num,
* [was in SPC-3 but displaced from SPC-4 into SBC-3, MMC-5, SSC-3]
* prevent==0 allows removal, prevent==1 prevents removal ...
* Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> command not supported
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_prevent_allow(int sg_fd, int prevent, int noisy, int verbose)
{
@@ -1011,19 +906,12 @@ sg_ll_prevent_allow(int sg_fd, int prevent, int noisy, int verbose)
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
diff --git a/lib/sg_cmds_extra.c b/lib/sg_cmds_extra.c
index 3facaa68..51257833 100644
--- a/lib/sg_cmds_extra.c
+++ b/lib/sg_cmds_extra.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999-2013 Douglas Gilbert.
+ * Copyright (c) 1999-2014 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.
@@ -91,9 +91,7 @@
/* Invokes a SCSI GET LBA STATUS command (SBC). Returns 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> GET LBA STATUS not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_get_lba_status(int sg_fd, uint64_t start_llba, void * resp,
int alloc_len, int noisy, int verbose)
@@ -143,19 +141,12 @@ sg_ll_get_lba_status(int sg_fd, uint64_t start_llba, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -179,9 +170,7 @@ sg_ll_report_tgt_prt_grp(int sg_fd, void * resp, int mx_resp_len,
}
/* Invokes a SCSI REPORT TARGET PORT GROUPS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Report Target Port Groups not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len,
int extended, int noisy, int verbose)
@@ -226,18 +215,12 @@ sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -253,9 +236,7 @@ sg_ll_report_tgt_prt_grp2(int sg_fd, void * resp, int mx_resp_len,
}
/* Invokes a SCSI SET TARGET PORT GROUPS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Set Target Port Groups not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, int noisy,
int verbose)
@@ -301,18 +282,12 @@ sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, int noisy,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -322,9 +297,7 @@ sg_ll_set_tgt_prt_grp(int sg_fd, void * paramp, int param_len, int noisy,
}
/* Invokes a SCSI REPORT REFERRALS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Report Referrals not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
void * resp, int mx_resp_len, int noisy,
@@ -376,18 +349,12 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -406,10 +373,7 @@ sg_ll_report_referrals(int sg_fd, uint64_t start_llba, int one_seg,
* take a long time, if so set long_duration flag in which case the timout
* 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,
- * SG_LIB_CAT_INVALID_OP -> Send diagnostic not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
int unitofl_bit, int long_duration, void * paramp,
@@ -459,19 +423,12 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -482,10 +439,7 @@ sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
}
/* Invokes a SCSI RECEIVE DIAGNOSTIC RESULTS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Receive diagnostic results not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp,
int mx_resp_len, int noisy, int verbose)
@@ -527,19 +481,12 @@ sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -554,11 +501,8 @@ sg_ll_receive_diag(int sg_fd, int pcv, int pg_code, void * resp,
return ret;
}
-/* Invokes a SCSI READ DEFECT DATA (10) command (SBC). Return of 0 ->
- * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+/* Invokes a SCSI READ DEFECT DATA (10) command (SBC). Return of 0 -> success
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_read_defect10(int sg_fd, int req_plist, int req_glist, int dl_format,
void * resp, int mx_resp_len, int noisy, int verbose)
@@ -601,19 +545,12 @@ sg_ll_read_defect10(int sg_fd, int req_plist, int req_glist, int dl_format,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -629,10 +566,7 @@ sg_ll_read_defect10(int sg_fd, int req_plist, int req_glist, int dl_format,
}
/* Invokes a SCSI READ MEDIA SERIAL NUMBER command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Read media serial number not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_read_media_serial_num(int sg_fd, void * resp, int mx_resp_len,
int noisy, int verbose)
@@ -674,19 +608,12 @@ sg_ll_read_media_serial_num(int sg_fd, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -703,10 +630,7 @@ sg_ll_read_media_serial_num(int sg_fd, void * resp, int mx_resp_len,
/* Invokes a SCSI REPORT IDENTIFYING INFORMATION command. This command was
* called REPORT DEVICE IDENTIFIER prior to spc4r07. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Report identifying information not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_report_id_info(int sg_fd, int itype, void * resp, int max_resp_len,
int noisy, int verbose)
@@ -750,19 +674,12 @@ sg_ll_report_id_info(int sg_fd, int itype, void * resp, int max_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -779,10 +696,7 @@ sg_ll_report_id_info(int sg_fd, int itype, void * resp, int max_resp_len,
/* Invokes a SCSI SET IDENTIFYING INFORMATION command. This command was
* called SET DEVICE IDENTIFIER prior to spc4r07. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Set identifying information not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len,
int noisy, int verbose)
@@ -829,19 +743,12 @@ sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -852,10 +759,7 @@ sg_ll_set_id_info(int sg_fd, int itype, void * paramp, int param_len,
}
/* Invokes a FORMAT UNIT (SBC-3) command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Format unit not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_format_unit(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
int cmplst, int dlist_format, int timeout_secs,
@@ -906,19 +810,12 @@ sg_ll_format_unit(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -929,9 +826,7 @@ sg_ll_format_unit(int sg_fd, int fmtpinfo, int longlist, int fmtdata,
}
/* Invokes a SCSI REASSIGN BLOCKS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> invalid opcode, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, void * paramp,
int param_len, int noisy, int verbose)
@@ -972,19 +867,12 @@ sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, void * paramp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -995,9 +883,8 @@ sg_ll_reassign_blocks(int sg_fd, int longlba, int longlist, void * paramp,
}
/* Invokes a SCSI PERSISTENT RESERVE IN command (SPC). Returns 0
- * when successful, SG_LIB_CAT_INVALID_OP if command not supported,
- * SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported,
- * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */
+ * when successful, various SG_LIB_CAT_* positive values or
+ * -1 -> other errors */
int
sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, void * resp,
int mx_resp_len, int noisy, int verbose)
@@ -1039,18 +926,12 @@ sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -1066,9 +947,8 @@ sg_ll_persistent_reserve_in(int sg_fd, int rq_servact, void * resp,
}
/* Invokes a SCSI PERSISTENT RESERVE OUT command (SPC). Returns 0
- * when successful, SG_LIB_CAT_INVALID_OP if command not supported,
- * SG_LIB_CAT_ILLEGAL_REQ if field in cdb not supported,
- * SG_LIB_CAT_UNIT_ATTENTION, SG_LIB_CAT_ABORTED_COMMAND, else -1 */
+ * when successful, various SG_LIB_CAT_* positive values or
+ * -1 -> other errors */
int
sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope,
unsigned int rq_type, void * paramp,
@@ -1115,18 +995,12 @@ sg_ll_persistent_reserve_out(int sg_fd, int rq_servact, int rq_scope,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -1156,11 +1030,7 @@ has_blk_ili(unsigned char * sensep, int sb_len)
/* Invokes a SCSI READ LONG (10) command (SBC). Note that 'xfer_len'
* is in bytes. Returns 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> READ LONG(10) not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
- * field written to 'offsetp', SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
void * resp, int xfer_len, int * offsetp, int noisy,
@@ -1208,12 +1078,6 @@ sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
@@ -1239,7 +1103,7 @@ sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
}
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -1256,11 +1120,7 @@ sg_ll_read_long10(int sg_fd, int pblock, int correct, unsigned int lba,
/* Invokes a SCSI READ LONG (16) command (SBC). Note that 'xfer_len'
* is in bytes. Returns 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> READ LONG(16) not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
- * field written to 'offsetp', SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_NOT_READY -> device not ready, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
void * resp, int xfer_len, int * offsetp, int noisy,
@@ -1313,12 +1173,6 @@ sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
@@ -1344,7 +1198,7 @@ sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
}
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -1361,12 +1215,7 @@ sg_ll_read_long16(int sg_fd, int pblock, int correct, uint64_t llba,
/* Invokes a SCSI WRITE LONG (10) command (SBC). Note that 'xfer_len'
* is in bytes. Returns 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> WRITE LONG(10) not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
- * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_ABORTED_COMMAND, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
unsigned int lba, void * data_out, int xfer_len,
@@ -1416,12 +1265,6 @@ sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
@@ -1447,7 +1290,7 @@ sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
}
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -1459,12 +1302,7 @@ sg_ll_write_long10(int sg_fd, int cor_dis, int wr_uncor, int pblock,
/* Invokes a SCSI WRITE LONG (16) command (SBC). Note that 'xfer_len'
* is in bytes. Returns 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> WRITE LONG(16) not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO -> bad field in cdb, with info
- * field written to 'offsetp', SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready,
- * SG_LIB_CAT_ABORTED_COMMAND, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
uint64_t llba, void * data_out, int xfer_len,
@@ -1519,12 +1357,6 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
@@ -1550,7 +1382,7 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
}
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -1563,12 +1395,7 @@ sg_ll_write_long16(int sg_fd, int cor_dis, int wr_uncor, int pblock,
/* Invokes a SCSI VERIFY (10) command (SBC and MMC).
* Note that 'veri_len' is in blocks while 'data_out_len' is in bytes.
* Returns of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Verify(10) not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_MEDIUM_HARD -> medium or hardware error, no valid info,
- * SG_LIB_CAT_MEDIUM_HARD_WITH_INFO -> as previous, with valid info,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_MISCOMPARE, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
unsigned int lba, int veri_len, void * data_out,
@@ -1620,14 +1447,6 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- case SG_LIB_CAT_MISCOMPARE:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
@@ -1648,7 +1467,7 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
}
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -1661,12 +1480,7 @@ sg_ll_verify10(int sg_fd, int vrprotect, int dpo, int bytchk,
/* Invokes a SCSI VERIFY (16) command (SBC and MMC).
* Note that 'veri_len' is in blocks while 'data_out_len' is in bytes.
* Returns of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Verify(16) not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_MEDIUM_HARD -> medium or hardware error, no valid info,
- * SG_LIB_CAT_MEDIUM_HARD_WITH_INFO -> as previous, with valid info,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_MISCOMPARE, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
int veri_len, int group_num, void * data_out,
@@ -1724,14 +1538,6 @@ sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- case SG_LIB_CAT_MISCOMPARE:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
@@ -1752,7 +1558,7 @@ sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
}
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -1923,11 +1729,8 @@ out:
return ret;
}
-/* Invokes a SCSI READ BUFFER command (SPC). Return of 0 ->
- * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+/* Invokes a SCSI READ BUFFER command (SPC). Return of 0 -> success
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
void * resp, int mx_resp_len, int noisy, int verbose)
@@ -1970,19 +1773,12 @@ sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -1997,11 +1793,8 @@ sg_ll_read_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
return ret;
}
-/* Invokes a SCSI WRITE BUFFER command (SPC). Return of 0 ->
- * success, SG_LIB_CAT_INVALID_OP -> invalid opcode,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+/* Invokes a SCSI WRITE BUFFER command (SPC). Return of 0 -> success
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
void * paramp, int param_len, int noisy, int verbose)
@@ -2050,19 +1843,12 @@ sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -2073,9 +1859,7 @@ sg_ll_write_buffer(int sg_fd, int mode, int buffer_id, int buffer_offset,
}
/* Invokes a SCSI UNMAP command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> command not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_CAT_UNIT_ATTENTION, -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_unmap(int sg_fd, int group_num, int timeout_secs, void * paramp,
int param_len, int noisy, int verbose)
@@ -2130,18 +1914,12 @@ sg_ll_unmap_v2(int sg_fd, int anchor, int group_num, int timeout_secs,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -2151,10 +1929,7 @@ sg_ll_unmap_v2(int sg_fd, int anchor, int group_num, int timeout_secs,
}
/* Invokes a SCSI READ BLOCK LIMITS command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Read block limits not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_ABORTED_COMMAND,
- * SG_LIB_NOT_READY (shouldn't happen), -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_read_block_limits(int sg_fd, void * resp, int mx_resp_len,
int noisy, int verbose)
@@ -2189,18 +1964,12 @@ sg_ll_read_block_limits(int sg_fd, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- case SG_LIB_CAT_NOT_READY: /* shouldn't happen ?? */
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else {
@@ -2217,10 +1986,7 @@ sg_ll_read_block_limits(int sg_fd, void * resp, int mx_resp_len,
/* Invokes a SCSI RECEIVE COPY RESULTS command. Actually cover all current
* uses of opcode 0x84 (Third-party copy IN). Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Receive copy results not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_receive_copy_results(int sg_fd, int sa, int list_id, void * resp,
int mx_resp_len, int noisy, int verbose)
@@ -2271,19 +2037,12 @@ sg_ll_receive_copy_results(int sg_fd, int sa, int list_id, void * resp,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -2299,10 +2058,7 @@ sg_ll_receive_copy_results(int sg_fd, int sa, int list_id, void * resp,
* sg_ll_3party_copy_out() for the other service actions ( > 0 ). */
/* Invokes a SCSI EXTENDED COPY (LID1) command. Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> Receive copy results not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, int noisy,
int verbose)
@@ -2349,19 +2105,12 @@ sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, int noisy,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -2374,10 +2123,7 @@ sg_ll_extended_copy(int sg_fd, void * paramp, int param_len, int noisy,
* called THIRD PARTY COPY OUT. These include the EXTENDED COPY(LID1 and
* LID4), POPULATE TOKEN and WRITE USING TOKEN commands.
* Return of 0 -> success,
- * SG_LIB_CAT_INVALID_OP -> opcode 0x83 not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -1 -> other failure */
+ * various SG_LIB_CAT_* positive values or -1 -> other errors */
int
sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num,
int timeout_secs, void * paramp, int param_len,
@@ -2454,19 +2200,12 @@ sg_ll_3party_copy_out(int sg_fd, int sa, unsigned int list_id, int group_num,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
diff --git a/lib/sg_lib.c b/lib/sg_lib.c
index 96822095..a1020ecc 100644
--- a/lib/sg_lib.c
+++ b/lib/sg_lib.c
@@ -1115,12 +1115,17 @@ sg_err_category_sense(const unsigned char * sense_buffer, int sb_len)
return SG_LIB_CAT_ILLEGAL_REQ;
break;
case SPC_SK_ABORTED_COMMAND:
- return SG_LIB_CAT_ABORTED_COMMAND;
+ if (0x10 == ssh.asc)
+ return SG_LIB_CAT_PROTECTION;
+ else
+ return SG_LIB_CAT_ABORTED_COMMAND;
case SPC_SK_MISCOMPARE:
return SG_LIB_CAT_MISCOMPARE;
case SPC_SK_DATA_PROTECT:
- case SPC_SK_COMPLETED:
+ return SG_LIB_CAT_DATA_PROTECT;
case SPC_SK_COPY_ABORTED:
+ return SG_LIB_CAT_COPY_ABORTED;
+ case SPC_SK_COMPLETED:
case SPC_SK_VOLUME_OVERFLOW:
return SG_LIB_CAT_SENSE;
default:
@@ -1390,6 +1395,139 @@ sg_vpd_dev_id_iter(const unsigned char * initial_desig_desc, int page_len,
return (k == page_len) ? -1 : -2;
}
+static const char * bad_sense_cat = "Bad sense category";
+
+/* Yield string associated with sense++ category. Returns 'buff' (or pointer
+ * to "Bad sense category" if 'buff' is NULL). If sense_cat unknown then
+ * yield "Sense category: <sense_cat>" string. */
+const char *
+sg_get_category_sense_str(int sense_cat, int buff_len, char * buff,
+ int verbose)
+{
+ int n;
+
+ if (NULL == buff)
+ return bad_sense_cat;
+ if (buff_len <= 0)
+ return buff;
+ switch (sense_cat) {
+ case SG_LIB_CAT_CLEAN: /* 0 */
+ snprintf(buff, buff_len, "No errors");
+ break;
+ case SG_LIB_SYNTAX_ERROR: /* 1 */
+ snprintf(buff, buff_len, "Syntax error");
+ break;
+ case SG_LIB_CAT_NOT_READY: /* 2 */
+ n = snprintf(buff, buff_len, "Not ready");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key");
+ break;
+ case SG_LIB_CAT_MEDIUM_HARD: /* 3 */
+ n = snprintf(buff, buff_len, "Medium or hardware error");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key (plus blank check)");
+ break;
+ case SG_LIB_CAT_ILLEGAL_REQ: /* 5 */
+ n = snprintf(buff, buff_len, "Illegal request");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key, apart from Invalid "
+ "opcode");
+ break;
+ case SG_LIB_CAT_UNIT_ATTENTION: /* 6 */
+ n = snprintf(buff, buff_len, "Unit attention");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key");
+ break;
+ case SG_LIB_CAT_DATA_PROTECT: /* 7 */
+ n = snprintf(buff, buff_len, "Data protect");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key, write protected "
+ "media?");
+ break;
+ case SG_LIB_CAT_INVALID_OP: /* 9 */
+ n = snprintf(buff, buff_len, "Illegal request, invalid opcode");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key");
+ break;
+ case SG_LIB_CAT_COPY_ABORTED: /* 10 */
+ n = snprintf(buff, buff_len, "Copy aborted");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key");
+ break;
+ case SG_LIB_CAT_ABORTED_COMMAND: /* 11 */
+ n = snprintf(buff, buff_len, "Aborted command");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key, other than "
+ "protection related (asc=0x10)");
+ break;
+ case SG_LIB_CAT_MISCOMPARE: /* 14 */
+ n = snprintf(buff, buff_len, "Miscompare");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key");
+ break;
+ case SG_LIB_FILE_ERROR: /* 15 */
+ snprintf(buff, buff_len, "File error");
+ break;
+ case SG_LIB_CAT_ILLEGAL_REQ_WITH_INFO: /* 17 */
+ snprintf(buff, buff_len, "Illegal request with info");
+ break;
+ case SG_LIB_CAT_MEDIUM_HARD_WITH_INFO: /* 18 */
+ snprintf(buff, buff_len, "Medium or hardware error with info");
+ break;
+ case SG_LIB_CAT_NO_SENSE: /* 20 */
+ n = snprintf(buff, buff_len, "No sense key");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " probably additional sense "
+ "information");
+ break;
+ case SG_LIB_CAT_RECOVERED: /* 21 */
+ n = snprintf(buff, buff_len, "Recovered error");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " sense key");
+ break;
+ case SG_LIB_CAT_RES_CONFLICT: /* 24 */
+ n = snprintf(buff, buff_len, "Reservation conflict");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " SCSI status");
+ break;
+ case SG_LIB_CAT_TIMEOUT: /* 33 */
+ snprintf(buff, buff_len, "SCSI command timeout");
+ break;
+ case SG_LIB_CAT_PROTECTION: /* 40 */
+ n = snprintf(buff, buff_len, "Aborted command, protection");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " information (PI) problem");
+ break;
+ case SG_LIB_CAT_PROTECTION_WITH_INFO: /* 41 */
+ n = snprintf(buff, buff_len, "Aborted command with info, protection");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " information (PI) problem");
+ break;
+ case SG_LIB_CAT_MALFORMED: /* 97 */
+ n = snprintf(buff, buff_len, "Malformed response");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, " to SCSI command");
+ break;
+ case SG_LIB_CAT_SENSE: /* 98 */
+ n = snprintf(buff, buff_len, "Some other sense data problem");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, ", try '-v' option for more "
+ "information");
+ break;
+ case SG_LIB_CAT_OTHER: /* 99 */
+ n = snprintf(buff, buff_len, "Some other error/warning has occurred");
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, ", possible transport of driver "
+ "issue");
+ default:
+ n = snprintf(buff, buff_len, "Sense category: %d", sense_cat);
+ if (verbose && (n < (buff_len - 1)))
+ snprintf(buff + n, buff_len - n, ", try '-v' option for more "
+ "information");
+ break;
+ }
+ return buff;
+}
/* safe_strerror() contributed by Clayton Weaver <cgweav at email dot com>
* Allows for situation in which strerror() is given a wild value (or the
diff --git a/lib/sg_lib_data.c b/lib/sg_lib_data.c
index d0c7c8f6..a7968094 100644
--- a/lib/sg_lib_data.c
+++ b/lib/sg_lib_data.c
@@ -17,7 +17,7 @@
#endif
-const char * sg_lib_version_str = "1.98 20140427"; /* spc4r36s, sbc4r01 */
+const char * sg_lib_version_str = "1.99 20140514"; /* spc4r36s, sbc4r01 */
#ifdef SG_SCSI_STRINGS
struct sg_lib_value_name_t sg_lib_normal_opcodes[] = {
@@ -289,11 +289,13 @@ struct sg_lib_value_name_t sg_lib_serv_in16_arr[] = { /* opcode 0x9e */
{0x11, 0, "Read long(16)"},
{0x12, 0, "Get LBA status"},
{0x13, 0, "Report referrals"},
+ {0x14, PDT_ZBC, "Report zones"},
{0xffff, 0, NULL},
};
struct sg_lib_value_name_t sg_lib_serv_out16_arr[] = { /* opcode 0x9f */
{0x11, 0, "Write long(16)"},
+ {0x14, PDT_ZBC, "Reset write pointer"},
{0x1f, PDT_ADC, "Notify data transfer device(16)"},
{0xffff, 0, NULL},
};
diff --git a/ltmain.sh b/ltmain.sh
index 3825a2aa..a356acaf 100755
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -70,7 +70,7 @@
# compiler: $LTCC
# compiler flags: $LTCFLAGS
# linker: $LD (gnu? $with_gnu_ld)
-# $progname: (GNU libtool) 2.4.2 Debian-2.4.2-1.3ubuntu1
+# $progname: (GNU libtool) 2.4.2 Debian-2.4.2-1.7ubuntu1
# automake: $automake_version
# autoconf: $autoconf_version
#
@@ -80,7 +80,7 @@
PROGRAM=libtool
PACKAGE=libtool
-VERSION="2.4.2 Debian-2.4.2-1.3ubuntu1"
+VERSION="2.4.2 Debian-2.4.2-1.7ubuntu1"
TIMESTAMP=""
package_revision=1.3337
diff --git a/missing b/missing
index cdea5149..db98974f 100755
--- a/missing
+++ b/missing
@@ -1,7 +1,7 @@
#! /bin/sh
# Common wrapper for a few potentially missing GNU programs.
-scriptversion=2012-06-26.16; # UTC
+scriptversion=2013-10-28.13; # UTC
# Copyright (C) 1996-2013 Free Software Foundation, Inc.
# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
@@ -160,7 +160,7 @@ give_advice ()
;;
autom4te*)
echo "You might have modified some maintainer files that require"
- echo "the 'automa4te' program to be rebuilt."
+ echo "the 'autom4te' program to be rebuilt."
program_details 'autom4te'
;;
bison*|yacc*)
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
index 485f6141..e16f9473 100644
--- a/scripts/Makefile.in
+++ b/scripts/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
diff --git a/src/Makefile.in b/src/Makefile.in
index ac5043e5..b7f3e00a 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
+# Makefile.in generated by automake 1.14.1 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
@@ -1233,14 +1233,14 @@ distclean-compile:
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/src/sg_copy_results.c b/src/sg_copy_results.c
index 3e7c7f6c..127d10f6 100644
--- a/src/sg_copy_results.c
+++ b/src/sg_copy_results.c
@@ -35,7 +35,7 @@
and the optional list identifier passed as the list_id argument.
*/
-static const char * version_str = "1.9 20140512";
+static const char * version_str = "1.9 20140515";
#define MAX_XFER_LEN 10000
@@ -430,44 +430,24 @@ main(int argc, char * argv[])
return SG_LIB_FILE_ERROR;
}
- cp = rec_copy_name_arr[sa];
+ if ((sa < 0) || (sa >= (int)(sizeof(rec_copy_name_arr) / sizeof(char *))))
+ cp = "Out of range service action";
+ else
+ cp = rec_copy_name_arr[sa];
if (verbose)
pr2serr(ME "issue %s to device %s\n\t\txfer_len= %d (0x%x), list_id=%"
PRIu32 "\n", cp, device_name, xfer_len, xfer_len, list_id);
- /* In SPC-4 opcode 0x84, service actions have command names:
- * 0x0 RECEIVE COPY STATUS(LID1)
- * 0x1 RECEIVE COPY DATA(LID1)
- * 0x3 RECEIVE COPY OPERATING PARAMETERS
- * 0x4 RECEIVE COPY FAILURE DETAILS(LID1)
- */
res = sg_ll_receive_copy_results(sg_fd, sa, list_id, cpResultBuff,
xfer_len, 1, verbose);
ret = res;
- switch (res) {
- case 0:
- break;
- case SG_LIB_CAT_NOT_READY:
- pr2serr(" SCSI %s failed, device not ready\n", cp);
- break;
- case SG_LIB_CAT_UNIT_ATTENTION:
- pr2serr(" SCSI %s failed, unit attention\n", cp);
- break;
- case SG_LIB_CAT_ABORTED_COMMAND:
- pr2serr(" SCSI %s failed, aborted command\n", cp);
- break;
- case SG_LIB_CAT_INVALID_OP:
- pr2serr(" SCSI %s command not supported\n", cp);
- break;
- case SG_LIB_CAT_ILLEGAL_REQ:
- pr2serr(" SCSI %s failed, bad field in cdb\n", cp);
- break;
- default:
- pr2serr(" SCSI %s command error %d\n", cp, res);
- break;
- }
- if (res != 0)
+ if (res) {
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ pr2serr(" SCSI %s failed: %s\n", cp, b);
goto finish;
+ }
if (1 == do_hex) {
dStrHex((const char *)cpResultBuff, xfer_len, 1);
res = 0;
diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c
index 61e47d17..d667580c 100644
--- a/src/sg_get_lba_status.c
+++ b/src/sg_get_lba_status.c
@@ -28,7 +28,7 @@
* device.
*/
-static const char * version_str = "1.06 20140512"; /* sbc2r29 */
+static const char * version_str = "1.06 20140515"; /* sbc2r29 */
#define MAX_GLBAS_BUFF_LEN (1024 * 1024)
#define DEF_GLBAS_BUFF_LEN 24
@@ -342,14 +342,13 @@ main(int argc, char * argv[])
"found\n");
} else if (SG_LIB_CAT_INVALID_OP == res)
fprintf(stderr, "Get LBA Status command not supported\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- fprintf(stderr, "Get LBA Status, aborted command\n");
else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- fprintf(stderr, "Get LBA Status command has bad field in cdb\n");
+ fprintf(stderr, "Get LBA Status command: bad field in cdb\n");
else {
- fprintf(stderr, "Get LBA Status command failed\n");
- if (0 == verbose)
- fprintf(stderr, " try '-v' option for more information\n");
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Get LBA Status command: %s\n", b);
}
the_end:
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 329428be..7665384a 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -41,7 +41,7 @@
#include "sg_cmds_basic.h"
#include "sg_pt.h"
-static const char * version_str = "1.36 20140502"; /* SPC-4 rev 36t */
+static const char * version_str = "1.37 20140514"; /* SPC-4 rev 36t */
/* INQUIRY notes:
* It is recommended that the initial allocation length given to a
@@ -977,17 +977,12 @@ pt_inquiry(int sg_fd, int evpd, int pg_op, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else if (ret < 4) {
@@ -2979,25 +2974,15 @@ std_inq_process(int sg_fd, const struct opts_t * op, int inhex_len)
return res;
#endif
} else {
+ char b[80];
+
pr2serr(" inquiry: failed requesting %d byte response: ", rlen);
if (resid && verb)
snprintf(buff, sizeof(buff), " [resid=%d]", resid);
else
buff[0] = '\0';
- if (SG_LIB_CAT_INVALID_OP == res)
- pr2serr("not supported (?)%s\n", buff);
- else if (SG_LIB_CAT_NOT_READY == res)
- pr2serr("device not ready (?)%s\n", buff);
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- pr2serr("field in cdb illegal%s\n", buff);
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- pr2serr("unit attention (?)%s\n", buff);
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- pr2serr("aborted command%s\n", buff);
- else if (SG_LIB_CAT_MALFORMED == res)
- pr2serr("malformed response%s\n", buff);
- else
- pr2serr("res=%d%s\n", res, buff);
+ sg_get_category_sense_str(res, sizeof(b), b, verb);
+ pr2serr("%s%s\n", b, buff);
return res;
}
return 0;
@@ -3135,7 +3120,7 @@ static int
vpd_mainly_hex(int sg_fd, const struct opts_t * op, int inhex_len)
{
int res, len;
- char b[48];
+ char b[128];
const char * cp;
unsigned char * rp;
@@ -3169,21 +3154,13 @@ vpd_mainly_hex(int sg_fd, const struct opts_t * op, int inhex_len)
}
}
} else {
- if (SG_LIB_CAT_INVALID_OP == res)
- pr2serr(" inquiry: not supported (?)\n");
- else if (SG_LIB_CAT_NOT_READY == res)
- pr2serr(" inquiry: device not ready (?)\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
+ if (SG_LIB_CAT_ILLEGAL_REQ == res)
pr2serr(" inquiry: field in cdb illegal (page not "
"supported)\n");
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- pr2serr(" inquiry: unit attention (?)\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- pr2serr(" inquiry: aborted command\n");
- else if (SG_LIB_CAT_MALFORMED == res)
- pr2serr(" inquiry: malformed response\n");
- else
- pr2serr(" inquiry: failed, res=%d\n", res);
+ else {
+ sg_get_category_sense_str(res, sizeof(b), b, op->do_verbose);
+ pr2serr(" inquiry: %s\n", b);
+ }
}
return res;
}
@@ -3481,21 +3458,15 @@ vpd_decode(int sg_fd, const struct opts_t * op, int inhex_len)
}
}
if (res) {
- if (SG_LIB_CAT_INVALID_OP == res)
- pr2serr(" inquiry: not supported (?)\n");
- else if (SG_LIB_CAT_NOT_READY == res)
- pr2serr(" inquiry: device not ready (?)\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
+ char b[80];
+
+ if (SG_LIB_CAT_ILLEGAL_REQ == res)
pr2serr(" inquiry: field in cdb illegal (page not "
"supported)\n");
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- pr2serr(" inquiry: unit attention (?)\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- pr2serr(" inquiry: aborted command\n");
- else if (SG_LIB_CAT_MALFORMED == res)
- pr2serr(" inquiry: malformed response\n");
- else
- pr2serr(" inquiry: failed, res=%d\n", res);
+ else {
+ sg_get_category_sense_str(res, sizeof(b), b, vb);
+ pr2serr(" inquiry: %s\n", b);
+ }
}
return res;
}
diff --git a/src/sg_logs.c b/src/sg_logs.c
index e36c5b81..841c8a13 100644
--- a/src/sg_logs.c
+++ b/src/sg_logs.c
@@ -28,7 +28,7 @@
#include "sg_cmds_basic.h"
#include "sg_pt.h" /* needed for scsi_pt_win32_direct() */
-static const char * version_str = "1.22 20140513"; /* spc4r36t + sbc4r01 */
+static const char * version_str = "1.22 20140514"; /* spc4r36t + sbc4r01 */
#define MX_ALLOC_LEN (0xfffc)
#define SHORT_RESP_LEN 128
@@ -907,18 +907,8 @@ do_logs(int sg_fd, unsigned char * resp, int mx_resp_len,
op->page_control, op->pg_code,
op->subpg_code, op->paramp,
resp, LOG_SENSE_PROBE_ALLOC_LEN,
- 1 /* noisy */, vb))) {
- switch (res) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- return res;
- default:
- return -1;
- }
- }
+ 1 /* noisy */, vb)))
+ return res;
actual_len = (resp[2] << 8) + resp[3] + 4;
if ((0 == op->do_raw) && (vb > 1)) {
pr2serr(" Log sense (find length) response:\n");
@@ -945,18 +935,8 @@ do_logs(int sg_fd, unsigned char * resp, int mx_resp_len,
if ((res = sg_ll_log_sense(sg_fd, op->do_ppc, op->do_sp,
op->page_control, op->pg_code,
op->subpg_code, op->paramp,
- resp, actual_len, 1 /* noisy */, vb))) {
- switch (res) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- return res;
- default:
- return -1;
- }
- }
+ resp, actual_len, 1 /* noisy */, vb)))
+ return res;
if ((0 == op->do_raw) && (vb > 1)) {
pr2serr(" Log sense response:\n");
dStrHexErr((const char *)resp, actual_len, 1);
diff --git a/src/sg_luns.c b/src/sg_luns.c
index 5cbdd82f..e5097625 100644
--- a/src/sg_luns.c
+++ b/src/sg_luns.c
@@ -28,7 +28,7 @@
* and decodes the response.
*/
-static const char * version_str = "1.25 20140508";
+static const char * version_str = "1.25 20140514";
#define MAX_RLUNS_BUFF_LEN (1024 * 1024)
#define DEF_RLUNS_BUFF_LEN (1024 * 8)
@@ -621,9 +621,10 @@ main(int argc, char * argv[])
else if (SG_LIB_CAT_ILLEGAL_REQ == res)
fprintf(stderr, "Report Luns command has bad field in cdb\n");
else {
- fprintf(stderr, "Report Luns command failed\n");
- if (0 == verbose)
- fprintf(stderr, " try '-v' option for more information\n");
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Report Luns command: %s\n", b);
}
the_end:
diff --git a/src/sg_modes.c b/src/sg_modes.c
index d4e2aec8..70335fb0 100644
--- a/src/sg_modes.c
+++ b/src/sg_modes.c
@@ -25,7 +25,7 @@
#include "sg_lib.h"
#include "sg_cmds_basic.h"
-static const char * version_str = "1.43 20140508";
+static const char * version_str = "1.43 20140514";
#define DEF_ALLOC_LEN (1024 * 4)
#define DEF_6_ALLOC_LEN 252
@@ -907,6 +907,12 @@ examine_pages(int sg_fd, int inq_pdt, int inq_byte6,
printf(" [0x%x]\n", k);
if (op->do_hex)
dStrHex((const char *)rbuf, len, 1);
+ } else if (op->do_verbose) {
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, op->do_verbose - 1);
+ fprintf(stderr, "MODE SENSE (%s) failed: %s\n",
+ (op->do_six ? "6" : "10"), b);
}
}
return res;
@@ -937,6 +943,7 @@ main(int argc, char * argv[])
unsigned char uc;
struct sg_simple_inquiry_resp inq_out;
char pdt_name[64];
+ char b[80];
struct opts_t opts;
struct opts_t * op;
@@ -1099,12 +1106,10 @@ main(int argc, char * argv[])
else
fprintf(stderr, "invalid field in cdb (perhaps "
"page 0x%x not supported)\n", op->pg_code);
- } else if (SG_LIB_CAT_NOT_READY == res)
- fprintf(stderr, "device not ready\n");
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- fprintf(stderr, "unit attention\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- fprintf(stderr, "aborted command\n");
+ } else if (res) {
+ sg_get_category_sense_str(res, sizeof(b), b, op->do_verbose);
+ fprintf(stderr, "%s\n", b);
+ }
ret = res;
if (0 == res) {
int medium_type, specific, headerlen;
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index 01903b52..9aac9fff 100644
--- a/src/sg_opcodes.c
+++ b/src/sg_opcodes.c
@@ -26,7 +26,7 @@
#include "sg_pt.h"
-static const char * version_str = "0.38 20140423"; /* spc4r36s */
+static const char * version_str = "0.39 20140515"; /* spc4r36t */
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
@@ -677,6 +677,7 @@ main(int argc, char * argv[])
int rep_opts = 0;
const char * cp;
char buff[48];
+ char b[80];
struct sg_simple_inquiry_resp inq_resp;
const char * op_name;
struct opts_t opts;
@@ -775,28 +776,9 @@ main(int argc, char * argv[])
res = do_rsoc(sg_fd, op->do_rctd, rep_opts, op->do_opcode,
op->do_servact, rsoc_buff, sizeof(rsoc_buff), 1,
op->do_verbose);
- switch (res) {
- case 0:
- case SG_LIB_CAT_RECOVERED:
- break;
- case SG_LIB_CAT_ABORTED_COMMAND:
- fprintf(stderr, "%s: aborted command\n", op_name);
- goto err_out;
- case SG_LIB_CAT_NOT_READY:
- fprintf(stderr, "%s: device not ready\n", op_name);
- goto err_out;
- case SG_LIB_CAT_UNIT_ATTENTION:
- fprintf(stderr, "%s: unit attention\n", op_name);
- goto err_out;
- case SG_LIB_CAT_INVALID_OP:
- fprintf(stderr, "%s: operation not supported\n", op_name);
- goto err_out;
- case SG_LIB_CAT_ILLEGAL_REQ:
- fprintf(stderr, "bad field in cdb (including %s not supported)\n",
- op_name);
- goto err_out;
- default:
- fprintf(stderr, "%s failed\n", op_name);
+ if (res) {
+ sg_get_category_sense_str(res, sizeof(b), b, op->do_verbose);
+ fprintf(stderr, "%s: %s command\n", op_name, b);
goto err_out;
}
if (op->do_taskman) {
@@ -941,19 +923,12 @@ do_rsoc(int sg_fd, int rctd, int rep_opts, int rq_opcode, int rq_servact,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -1004,19 +979,12 @@ do_rstmf(int sg_fd, int repd, void * resp, int mx_resp_len, int noisy,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
diff --git a/src/sg_persist.c b/src/sg_persist.c
index 5c30e8de..4ce3c1c1 100644
--- a/src/sg_persist.c
+++ b/src/sg_persist.c
@@ -27,7 +27,7 @@
#include "sg_cmds_basic.h"
#include "sg_cmds_extra.h"
-static const char * version_str = "0.48 20140511";
+static const char * version_str = "0.48 20140515";
#define PRIN_RKEY_SA 0x0
@@ -346,7 +346,7 @@ decode_transport_id(const char * leadin, unsigned char * ucp, int len,
}
static int
-prin_work(int sg_fd, const struct opts_t * optsp)
+prin_work(int sg_fd, const struct opts_t * op)
{
int k, j, num, res, add_len, add_desc_len, rel_pt_addr;
unsigned int pr_gen;
@@ -355,35 +355,34 @@ prin_work(int sg_fd, const struct opts_t * optsp)
unsigned char pr_buff[MX_ALLOC_LEN];
memset(pr_buff, 0, sizeof(pr_buff));
- res = sg_ll_persistent_reserve_in(sg_fd, optsp->prin_sa, pr_buff,
- optsp->alloc_len, 1, optsp->verbose);
+ res = sg_ll_persistent_reserve_in(sg_fd, op->prin_sa, pr_buff,
+ op->alloc_len, 1, op->verbose);
if (res) {
char b[64];
+ char bb[80];
- if (optsp->prin_sa < num_prin_sa_strs)
- snprintf(b, sizeof(b), "%s", prin_sa_strs[optsp->prin_sa]);
+ if (op->prin_sa < num_prin_sa_strs)
+ snprintf(b, sizeof(b), "%s", prin_sa_strs[op->prin_sa]);
else
- snprintf(b, sizeof(b), "service action=0x%x", optsp->prin_sa);
+ snprintf(b, sizeof(b), "service action=0x%x", op->prin_sa);
- if (SG_LIB_CAT_INVALID_OP == res)
+ if (SG_LIB_CAT_INVALID_OP == res)
pr2serr("PR in (%s): command not supported\n", b);
else if (SG_LIB_CAT_ILLEGAL_REQ == res)
pr2serr("PR in (%s): bad field in cdb or parameter list (perhaps "
"unsupported service action)\n", b);
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- pr2serr("PR in (%s): unit attention\n", b);
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- pr2serr("PR in (%s): aborted command\n", b);
- else
- pr2serr("PR in (%s): command failed\n", b);
+ else {
+ sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose);
+ pr2serr("PR in (%s): %s\n", b, bb);
+ }
return res;
}
- if (PRIN_RCAP_SA == optsp->prin_sa) {
+ if (PRIN_RCAP_SA == op->prin_sa) {
if (8 != pr_buff[1]) {
pr2serr("Unexpected response for PRIN Report Capabilities\n");
return SG_LIB_CAT_MALFORMED;
}
- if (optsp->hex)
+ if (op->hex)
dStrHex((const char *)pr_buff, 8, 1);
else {
printf("Report capabilities response:\n");
@@ -420,7 +419,7 @@ prin_work(int sg_fd, const struct opts_t * optsp)
(pr_buff[2] << 8) | pr_buff[3]);
add_len = ((pr_buff[4] << 24) | (pr_buff[5] << 16) |
(pr_buff[6] << 8) | pr_buff[7]);
- if (optsp->hex) {
+ if (op->hex) {
printf(" PR generation=0x%x, ", pr_gen);
if (add_len <= 0)
printf("Additional length=%d\n", add_len);
@@ -432,7 +431,7 @@ prin_work(int sg_fd, const struct opts_t * optsp)
printf("Additional length=%d\n", add_len);
dStrHex((const char *)(pr_buff + 8), add_len, 1);
}
- } else if (PRIN_RKEY_SA == optsp->prin_sa) {
+ } else if (PRIN_RKEY_SA == op->prin_sa) {
printf(" PR generation=0x%x, ", pr_gen);
num = add_len / 8;
if (num > 0) {
@@ -452,7 +451,7 @@ prin_work(int sg_fd, const struct opts_t * optsp)
}
} else
printf("there are NO registered reservation keys\n");
- } else if (PRIN_RRES_SA == optsp->prin_sa) {
+ } else if (PRIN_RRES_SA == op->prin_sa) {
printf(" PR generation=0x%x, ", pr_gen);
num = add_len / 16;
if (num > 0) {
@@ -474,12 +473,12 @@ prin_work(int sg_fd, const struct opts_t * optsp)
printf(" type: %s\n", pr_type_strs[j]);
} else
printf("there is NO reservation held\n");
- } else if (PRIN_RFSTAT_SA == optsp->prin_sa) {
+ } else if (PRIN_RFSTAT_SA == op->prin_sa) {
printf(" PR generation=0x%x\n", pr_gen);
ucp = pr_buff + 8;
if (0 == add_len) {
printf(" No full status descriptors\n");
- if (optsp->verbose)
+ if (op->verbose)
printf(" So there are no registered IT nexuses\n");
}
for (k = 0; k < add_len; k += num, ucp += num) {
@@ -523,13 +522,13 @@ prin_work(int sg_fd, const struct opts_t * optsp)
/* Compact the 2 dimensional transportid_arr into a one dimensional
* array in place returning the length. */
static int
-compact_transportid_array(struct opts_t * optsp)
+compact_transportid_array(struct opts_t * op)
{
int k, off, protocol_id, len;
int compact_len = 0;
- unsigned char * ucp = optsp->transportid_arr;
+ unsigned char * ucp = op->transportid_arr;
- for (k = 0, off = 0; ((k < optsp->num_transportids) && (k < MX_TIDS));
+ for (k = 0, off = 0; ((k < op->num_transportids) && (k < MX_TIDS));
++k, off += MX_TID_LEN) {
protocol_id = ucp[off] & 0xf;
if (TPROTO_ISCSI == protocol_id) {
@@ -550,98 +549,95 @@ compact_transportid_array(struct opts_t * optsp)
}
static int
-prout_work(int sg_fd, struct opts_t * optsp)
+prout_work(int sg_fd, struct opts_t * op)
{
int j, len, res, t_arr_len;
unsigned char pr_buff[MX_ALLOC_LEN];
uint64_t param_rk;
uint64_t param_sark;
+ char b[64];
+ char bb[80];
- t_arr_len = compact_transportid_array(optsp);
- param_rk = optsp->param_rk;
+ t_arr_len = compact_transportid_array(op);
+ param_rk = op->param_rk;
memset(pr_buff, 0, sizeof(pr_buff));
for (j = 7; j >= 0; --j) {
pr_buff[j] = (param_rk & 0xff);
param_rk >>= 8;
}
- param_sark = optsp->param_sark;
+ param_sark = op->param_sark;
for (j = 7; j >= 0; --j) {
pr_buff[8 + j] = (param_sark & 0xff);
param_sark >>= 8;
}
- if (optsp->param_alltgpt)
+ if (op->param_alltgpt)
pr_buff[20] |= 0x4;
- if (optsp->param_aptpl)
+ if (op->param_aptpl)
pr_buff[20] |= 0x1;
len = 24;
if (t_arr_len > 0) {
pr_buff[20] |= 0x8; /* set SPEC_I_PT bit */
- memcpy(&pr_buff[28], optsp->transportid_arr, t_arr_len);
+ memcpy(&pr_buff[28], op->transportid_arr, t_arr_len);
len += (t_arr_len + 4);
pr_buff[24] = (unsigned char)((t_arr_len >> 24) & 0xff);
pr_buff[25] = (unsigned char)((t_arr_len >> 16) & 0xff);
pr_buff[26] = (unsigned char)((t_arr_len >> 8) & 0xff);
pr_buff[27] = (unsigned char)(t_arr_len & 0xff);
}
- res = sg_ll_persistent_reserve_out(sg_fd, optsp->prout_sa, 0,
- optsp->prout_type, pr_buff, len, 1,
- optsp->verbose);
- if (res) {
- if (SG_LIB_CAT_INVALID_OP == res)
- pr2serr("PR out:, command not supported\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- pr2serr("PR out: bad field in cdb or parameter list (perhaps "
- "unsupported service action)\n");
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- pr2serr("PR out: unit attention\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- pr2serr("PR out: aborted command\n");
- else
- pr2serr("PR out: command failed\n");
- return res;
- } else if (optsp->verbose) {
- char buff[64];
-
- if (optsp->prout_sa < num_prout_sa_strs)
- snprintf(buff, sizeof(buff), "%s",
- prout_sa_strs[optsp->prout_sa]);
+ res = sg_ll_persistent_reserve_out(sg_fd, op->prout_sa, 0,
+ op->prout_type, pr_buff, len, 1,
+ op->verbose);
+ if (res || op->verbose) {
+ if (op->prout_sa < num_prout_sa_strs)
+ snprintf(b, sizeof(b), "%s", prout_sa_strs[op->prout_sa]);
else
- snprintf(buff, sizeof(buff), "service action=0x%x",
- optsp->prout_sa);
- pr2serr("PR out: command (%s) successful\n", buff);
+ snprintf(b, sizeof(b), "service action=0x%x", op->prout_sa);
+ if (res) {
+ if (SG_LIB_CAT_INVALID_OP == res)
+ pr2serr("PR out (%s): command not supported\n", b);
+ else if (SG_LIB_CAT_ILLEGAL_REQ == res)
+ pr2serr("PR out (%s): bad field in cdb or parameter list "
+ "(perhaps unsupported service action)\n", b);
+ else {
+ sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose);
+ pr2serr("PR out (%s): %s\n", b, bb);
+ }
+ return res;
+ } else if (op->verbose)
+ pr2serr("PR out: command (%s) successful\n", b);
}
return 0;
}
static int
-prout_reg_move_work(int sg_fd, struct opts_t * optsp)
+prout_reg_move_work(int sg_fd, struct opts_t * op)
{
int j, len, res, t_arr_len;
unsigned char pr_buff[MX_ALLOC_LEN];
uint64_t param_rk;
uint64_t param_sark;
- t_arr_len = compact_transportid_array(optsp);
- param_rk = optsp->param_rk;
+ t_arr_len = compact_transportid_array(op);
+ param_rk = op->param_rk;
memset(pr_buff, 0, sizeof(pr_buff));
for (j = 7; j >= 0; --j) {
pr_buff[j] = (param_rk & 0xff);
param_rk >>= 8;
}
- param_sark = optsp->param_sark;
+ param_sark = op->param_sark;
for (j = 7; j >= 0; --j) {
pr_buff[8 + j] = (param_sark & 0xff);
param_sark >>= 8;
}
- if (optsp->param_unreg)
+ if (op->param_unreg)
pr_buff[17] |= 0x2;
- if (optsp->param_aptpl)
+ if (op->param_aptpl)
pr_buff[17] |= 0x1;
- pr_buff[18] = (unsigned char)((optsp->param_rtp >> 8) & 0xff);
- pr_buff[19] = (unsigned char)(optsp->param_rtp & 0xff);
+ pr_buff[18] = (unsigned char)((op->param_rtp >> 8) & 0xff);
+ pr_buff[19] = (unsigned char)(op->param_rtp & 0xff);
len = 24;
if (t_arr_len > 0) {
- memcpy(&pr_buff[24], optsp->transportid_arr, t_arr_len);
+ memcpy(&pr_buff[24], op->transportid_arr, t_arr_len);
len += t_arr_len;
pr_buff[20] = (unsigned char)((t_arr_len >> 24) & 0xff);
pr_buff[21] = (unsigned char)((t_arr_len >> 16) & 0xff);
@@ -649,22 +645,22 @@ prout_reg_move_work(int sg_fd, struct opts_t * optsp)
pr_buff[23] = (unsigned char)(t_arr_len & 0xff);
}
res = sg_ll_persistent_reserve_out(sg_fd, PROUT_REG_MOVE_SA, 0,
- optsp->prout_type, pr_buff, len, 1,
- optsp->verbose);
+ op->prout_type, pr_buff, len, 1,
+ op->verbose);
if (res) {
if (SG_LIB_CAT_INVALID_OP == res)
- pr2serr("PR out: command not supported\n");
+ pr2serr("PR out (register and move): command not supported\n");
else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- pr2serr("PR out: bad field in cdb or parameter list (perhaps "
- "unsupported service action)\n");
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- pr2serr("PR out: unit attention\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- pr2serr("PR out: aborted command\n");
- else
- pr2serr("PR out: command failed\n");
+ pr2serr("PR out (register and move): bad field in cdb or "
+ "parameter list (perhaps unsupported service action)\n");
+ else {
+ char bb[80];
+
+ sg_get_category_sense_str(res, sizeof(bb), bb, op->verbose);
+ pr2serr("PR out (register and move): %s\n", bb);
+ }
return res;
- } else if (optsp->verbose)
+ } else if (op->verbose)
pr2serr("PR out: 'register and move' command successful\n");
return 0;
}
@@ -826,7 +822,7 @@ decode_sym_transportid(const char * lcp, unsigned char * tidp)
/* Read one or more TransportIDs from the given file or from stdin.
* Returns 0 if successful, 1 otherwise. */
static int
-decode_file_tids(const char * fnp, struct opts_t * optsp)
+decode_file_tids(const char * fnp, struct opts_t * op)
{
FILE * fp = stdin;
int in_len, k, j, m, split_line;
@@ -836,7 +832,7 @@ decode_file_tids(const char * fnp, struct opts_t * optsp)
char carry_over[4];
int off = 0;
int num = 0;
- unsigned char * tid_arr = optsp->transportid_arr;
+ unsigned char * tid_arr = op->transportid_arr;
if (fnp) {
fp = fopen(fnp, "r");
@@ -907,7 +903,7 @@ decode_file_tids(const char * fnp, struct opts_t * optsp)
/* single trailing hex digit might be a split pair */
carry_over[0] = *lcp;
}
- if ((off + k) >= (int)sizeof(optsp->transportid_arr)) {
+ if ((off + k) >= (int)sizeof(op->transportid_arr)) {
pr2serr("decode_file_tids: array length exceeded\n");
goto bad;
}
@@ -936,7 +932,7 @@ my_cont_a:
}
++num;
}
- optsp->num_transportids = num;
+ op->num_transportids = num;
return 0;
bad:
@@ -954,20 +950,20 @@ bad:
* sg_persist(8). Returns 0 if successful, else 1 .
*/
static int
-build_transportid(const char * inp, struct opts_t * optsp)
+build_transportid(const char * inp, struct opts_t * op)
{
int in_len;
int k = 0;
unsigned int h;
const char * lcp;
- unsigned char * tid_arr = optsp->transportid_arr;
+ unsigned char * tid_arr = op->transportid_arr;
char * cp;
char * c2p;
lcp = inp;
in_len = strlen(inp);
if (0 == in_len) {
- optsp->num_transportids = 0;
+ op->num_transportids = 0;
}
if (('-' == inp[0]) ||
(0 == memcmp("file=", inp, 5)) ||
@@ -976,7 +972,7 @@ build_transportid(const char * inp, struct opts_t * optsp)
lcp = NULL; /* read from stdin */
else
lcp = inp + 5; /* read from given file */
- return decode_file_tids(lcp, optsp);
+ return decode_file_tids(lcp, op);
} else { /* TransportID given directly on command line */
if (decode_sym_transportid(lcp, tid_arr))
goto my_cont_b;
@@ -985,7 +981,7 @@ build_transportid(const char * inp, struct opts_t * optsp)
pr2serr("build_transportid: error at pos %d\n", k + 1);
return 1;
}
- for (k = 0; k < (int)sizeof(optsp->transportid_arr); ++k) {
+ for (k = 0; k < (int)sizeof(op->transportid_arr); ++k) {
if (1 == sscanf(lcp, "%x", &h)) {
if (h > 0xff) {
pr2serr("build_transportid: hex number larger than 0xff "
@@ -1009,8 +1005,8 @@ build_transportid(const char * inp, struct opts_t * optsp)
}
}
my_cont_b:
- optsp->num_transportids = 1;
- if (k >= (int)sizeof(optsp->transportid_arr)) {
+ op->num_transportids = 1;
+ if (k >= (int)sizeof(op->transportid_arr)) {
pr2serr("build_transportid: array length exceeded\n");
return 1;
}
diff --git a/src/sg_raw.c b/src/sg_raw.c
index 72dae6bb..9380d32c 100644
--- a/src/sg_raw.c
+++ b/src/sg_raw.c
@@ -1,7 +1,7 @@
/*
* A utility program originally written for the Linux OS SCSI subsystem.
*
- * Copyright (C) 2000-2013 Ingo van Lil <inguin@gmx.de>
+ * Copyright (C) 2000-2014 Ingo van Lil <inguin@gmx.de>
*
* 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
@@ -27,7 +27,7 @@
#include "sg_lib.h"
#include "sg_pt.h"
-#define SG_RAW_VERSION "0.4.8 (2013-12-19)"
+#define SG_RAW_VERSION "0.4.9 (2014-05-14)"
#ifdef SG_LIB_WIN32
#ifndef HAVE_SYSCONF
@@ -132,7 +132,7 @@ usage()
}
static int
-process_cl(struct opts_t *optsp, int argc, char *argv[])
+process_cl(struct opts_t * op, int argc, char *argv[])
{
while (1) {
int c, n;
@@ -143,18 +143,18 @@ process_cl(struct opts_t *optsp, int argc, char *argv[])
switch (c) {
case 'b':
- optsp->datain_binary = 1;
+ op->datain_binary = 1;
break;
case 'h':
case '?':
- optsp->do_help = 1;
+ op->do_help = 1;
return 0;
case 'i':
- if (optsp->dataout_file) {
+ if (op->dataout_file) {
fprintf(stderr, "Too many '--infile=' options\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->dataout_file = optarg;
+ op->dataout_file = optarg;
break;
case 'k':
n = sg_get_num(optarg);
@@ -162,38 +162,38 @@ process_cl(struct opts_t *optsp, int argc, char *argv[])
fprintf(stderr, "Invalid argument to '--skip'\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->dataout_offset = n;
+ op->dataout_offset = n;
break;
case 'n':
- optsp->no_sense = 1;
+ op->no_sense = 1;
break;
case 'o':
- if (optsp->datain_file) {
+ if (op->datain_file) {
fprintf(stderr, "Too many '--outfile=' options\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->datain_file = optarg;
+ op->datain_file = optarg;
break;
case 'r':
- optsp->do_datain = 1;
+ op->do_datain = 1;
n = sg_get_num(optarg);
if (n < 0 || n > MAX_SCSI_DXLEN) {
fprintf(stderr, "Invalid argument to '--request'\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->datain_len = n;
+ op->datain_len = n;
break;
case 'R':
- ++optsp->readonly;
+ ++op->readonly;
break;
case 's':
- optsp->do_dataout = 1;
+ op->do_dataout = 1;
n = sg_get_num(optarg);
if (n < 0 || n > MAX_SCSI_DXLEN) {
fprintf(stderr, "Invalid argument to '--send'\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->dataout_len = n;
+ op->dataout_len = n;
break;
case 't':
n = sg_get_num(optarg);
@@ -201,13 +201,13 @@ process_cl(struct opts_t *optsp, int argc, char *argv[])
fprintf(stderr, "Invalid argument to '--timeout'\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->timeout = n;
+ op->timeout = n;
break;
case 'v':
- ++optsp->do_verbose;
+ ++op->do_verbose;
break;
case 'V':
- optsp->do_version = 1;
+ op->do_version = 1;
return 0;
default:
return SG_LIB_SYNTAX_ERROR;
@@ -218,7 +218,7 @@ process_cl(struct opts_t *optsp, int argc, char *argv[])
fprintf(stderr, "No device specified\n");
return SG_LIB_SYNTAX_ERROR;
}
- optsp->device_name = argv[optind];
+ op->device_name = argv[optind];
++optind;
while (optind < argc) {
@@ -230,15 +230,15 @@ process_cl(struct opts_t *optsp, int argc, char *argv[])
return SG_LIB_SYNTAX_ERROR;
}
- if (optsp->cdb_length > MAX_SCSI_CDBSZ) {
+ if (op->cdb_length > MAX_SCSI_CDBSZ) {
fprintf(stderr, "CDB too long (max. %d bytes)\n", MAX_SCSI_CDBSZ);
return SG_LIB_SYNTAX_ERROR;
}
- optsp->cdb[optsp->cdb_length] = cmd;
- ++optsp->cdb_length;
+ op->cdb[op->cdb_length] = cmd;
+ ++op->cdb_length;
}
- if (optsp->cdb_length < MIN_SCSI_CDBSZ) {
+ if (op->cdb_length < MIN_SCSI_CDBSZ) {
fprintf(stderr, "CDB too short (min. %d bytes)\n", MIN_SCSI_CDBSZ);
return SG_LIB_SYNTAX_ERROR;
}
@@ -325,17 +325,17 @@ skip(int fd, off_t offset)
}
static unsigned char *
-fetch_dataout(struct opts_t *optsp)
+fetch_dataout(struct opts_t * op)
{
unsigned char *buf = NULL;
unsigned char *wrkBuf = NULL;
int fd, len;
int ok = 0;
- if (optsp->dataout_file) {
- fd = open(optsp->dataout_file, O_RDONLY);
+ if (op->dataout_file) {
+ fd = open(op->dataout_file, O_RDONLY);
if (fd < 0) {
- perror(optsp->dataout_file);
+ perror(op->dataout_file);
goto bail;
}
@@ -347,23 +347,23 @@ fetch_dataout(struct opts_t *optsp)
goto bail;
}
- if (optsp->dataout_offset > 0) {
- if (skip(fd, optsp->dataout_offset) != 0) {
+ if (op->dataout_offset > 0) {
+ if (skip(fd, op->dataout_offset) != 0) {
goto bail;
}
}
- buf = my_memalign(optsp->dataout_len, &wrkBuf);
+ buf = my_memalign(op->dataout_len, &wrkBuf);
if (buf == NULL) {
perror("malloc");
goto bail;
}
- len = read(fd, buf, optsp->dataout_len);
+ len = read(fd, buf, op->dataout_len);
if (len < 0) {
perror("Failed to read input data");
goto bail;
- } else if (len < optsp->dataout_len) {
+ } else if (len < op->dataout_len) {
fprintf(stderr, "EOF on input file/stream\n");
goto bail;
}
@@ -420,33 +420,35 @@ main(int argc, char *argv[])
{
int ret = 0;
int res_cat, status, slen, k, ret2;
- struct opts_t opts;
int sg_fd = -1;
struct sg_pt_base *ptvp = NULL;
unsigned char sense_buffer[32];
unsigned char * dxfer_buffer_in = NULL;
unsigned char * dxfer_buffer_out = NULL;
unsigned char *wrkBuf = NULL;
+ struct opts_t opts;
+ struct opts_t * op;
char b[128];
- memset(&opts, 0, sizeof(opts));
- opts.timeout = DEFAULT_TIMEOUT;
- ret = process_cl(&opts, argc, argv);
+ op = &opts;
+ memset(op, 0, sizeof(opts));
+ op->timeout = DEFAULT_TIMEOUT;
+ ret = process_cl(op, argc, argv);
if (ret != 0) {
usage();
goto done;
- } else if (opts.do_help) {
+ } else if (op->do_help) {
usage();
goto done;
- } else if (opts.do_version) {
+ } else if (op->do_version) {
version();
goto done;
}
- sg_fd = scsi_pt_open_device(opts.device_name, opts.readonly,
- opts.do_verbose);
+ sg_fd = scsi_pt_open_device(op->device_name, op->readonly,
+ op->do_verbose);
if (sg_fd < 0) {
- fprintf(stderr, "%s: %s\n", opts.device_name, safe_strerror(-sg_fd));
+ fprintf(stderr, "%s: %s\n", op->device_name, safe_strerror(-sg_fd));
ret = SG_LIB_FILE_ERROR;
goto done;
}
@@ -457,39 +459,39 @@ main(int argc, char *argv[])
ret = SG_LIB_CAT_OTHER;
goto done;
}
- if (opts.do_verbose) {
+ if (op->do_verbose) {
fprintf(stderr, " cdb to send: ");
- for (k = 0; k < opts.cdb_length; ++k)
- fprintf(stderr, "%02x ", opts.cdb[k]);
+ for (k = 0; k < op->cdb_length; ++k)
+ fprintf(stderr, "%02x ", op->cdb[k]);
fprintf(stderr, "\n");
- if (opts.do_verbose > 2) {
- sg_get_command_name(opts.cdb, 0, sizeof(b) - 1, b);
+ if (op->do_verbose > 2) {
+ sg_get_command_name(op->cdb, 0, sizeof(b) - 1, b);
b[sizeof(b) - 1] = '\0';
fprintf(stderr, " Command name: %s\n", b);
}
}
- set_scsi_pt_cdb(ptvp, opts.cdb, opts.cdb_length);
+ set_scsi_pt_cdb(ptvp, op->cdb, op->cdb_length);
set_scsi_pt_sense(ptvp, sense_buffer, sizeof(sense_buffer));
- if (opts.do_dataout) {
- dxfer_buffer_out = fetch_dataout(&opts);
+ if (op->do_dataout) {
+ dxfer_buffer_out = fetch_dataout(op);
if (dxfer_buffer_out == NULL) {
ret = SG_LIB_CAT_OTHER;
goto done;
}
- set_scsi_pt_data_out(ptvp, dxfer_buffer_out, opts.dataout_len);
+ set_scsi_pt_data_out(ptvp, dxfer_buffer_out, op->dataout_len);
}
- if (opts.do_datain) {
- dxfer_buffer_in = my_memalign(opts.datain_len, &wrkBuf);
+ if (op->do_datain) {
+ dxfer_buffer_in = my_memalign(op->datain_len, &wrkBuf);
if (dxfer_buffer_in == NULL) {
perror("malloc");
ret = SG_LIB_CAT_OTHER;
goto done;
}
- set_scsi_pt_data_in(ptvp, dxfer_buffer_in, opts.datain_len);
+ set_scsi_pt_data_in(ptvp, dxfer_buffer_in, op->datain_len);
}
- ret = do_scsi_pt(ptvp, sg_fd, opts.timeout, opts.do_verbose);
+ ret = do_scsi_pt(ptvp, sg_fd, op->timeout, op->do_verbose);
if (ret > 0) {
if (SCSI_PT_DO_BAD_PARAMS == ret) {
fprintf(stderr, "do_scsi_pt: bad pass through setup\n");
@@ -537,7 +539,7 @@ main(int argc, char *argv[])
fprintf(stderr, "SCSI Status: ");
sg_print_scsi_status(status);
fprintf(stderr, "\n\n");
- if ((SAM_STAT_CHECK_CONDITION == status) && (! opts.no_sense)) {
+ if ((SAM_STAT_CHECK_CONDITION == status) && (! op->no_sense)) {
if (SCSI_PT_RESULT_SENSE != res_cat)
slen = get_scsi_pt_sense_len(ptvp);
if (0 == slen)
@@ -545,29 +547,31 @@ main(int argc, char *argv[])
"Sense Information\n");
else {
fprintf(stderr, "Sense Information:\n");
- sg_print_sense(NULL, sense_buffer, slen, (opts.do_verbose > 0));
+ sg_print_sense(NULL, sense_buffer, slen, (op->do_verbose > 0));
fprintf(stderr, "\n");
}
}
+ if (SAM_STAT_RESERVATION_CONFLICT == status)
+ ret = SG_LIB_CAT_RES_CONFLICT;
- if (opts.do_datain) {
- int data_len = opts.datain_len - get_scsi_pt_resid(ptvp);
+ if (op->do_datain) {
+ int data_len = op->datain_len - get_scsi_pt_resid(ptvp);
if (data_len == 0) {
fprintf(stderr, "No data received\n");
} else {
- if (opts.datain_file == NULL && !opts.datain_binary) {
+ if (op->datain_file == NULL && !op->datain_binary) {
fprintf(stderr, "Received %d bytes of data:\n", data_len);
dStrHexErr((const char *)dxfer_buffer_in, data_len, 0);
} else {
const char * cp = "stdout";
- if (opts.datain_file &&
- ! ((1 == strlen(opts.datain_file)) &&
- ('-' == opts.datain_file[0])))
- cp = opts.datain_file;
+ if (op->datain_file &&
+ ! ((1 == strlen(op->datain_file)) &&
+ ('-' == op->datain_file[0])))
+ cp = op->datain_file;
fprintf(stderr, "Writing %d bytes of data to %s\n", data_len,
cp);
- ret2 = write_dataout(opts.datain_file, dxfer_buffer_in,
+ ret2 = write_dataout(op->datain_file, dxfer_buffer_in,
data_len);
if (0 != ret2) {
if (0 == ret)
@@ -579,6 +583,10 @@ main(int argc, char *argv[])
}
done:
+ if (op->do_verbose) {
+ sg_get_category_sense_str(ret, sizeof(b), b, op->do_verbose - 1);
+ fprintf(stderr, "%s\n", b);
+ }
if (wrkBuf)
free(wrkBuf);
if (ptvp)
diff --git a/src/sg_read_buffer.c b/src/sg_read_buffer.c
index 5d0f75b7..1caf71eb 100644
--- a/src/sg_read_buffer.c
+++ b/src/sg_read_buffer.c
@@ -25,7 +25,7 @@
* This utility issues the SCSI READ BUFFER command to the given device.
*/
-static const char * version_str = "1.10 20140507";
+static const char * version_str = "1.11 20140515";
static struct option long_options[] = {
@@ -281,32 +281,11 @@ main(int argc, char * argv[])
res = sg_ll_read_buffer(sg_fd, rb_mode, rb_id, rb_offset, resp,
rb_len, 1, verbose);
if (0 != res) {
+ char b[80];
+
ret = res;
- switch (res) {
- case SG_LIB_CAT_NOT_READY:
- fprintf(stderr, "Read buffer failed, device not ready\n");
- break;
- case SG_LIB_CAT_UNIT_ATTENTION:
- fprintf(stderr, "Read buffer not done, unit attention\n");
- break;
- case SG_LIB_CAT_ABORTED_COMMAND:
- fprintf(stderr, "Read buffer, aborted command\n");
- break;
- case SG_LIB_CAT_INVALID_OP:
- fprintf(stderr, "Read buffer command not supported\n");
- break;
- case SG_LIB_CAT_ILLEGAL_REQ:
- fprintf(stderr, "bad field in Read buffer cdb\n");
- break;
- default:
- if (-1 == res) {
- fprintf(stderr, "Read buffer command failed\n");
- } else
- fprintf(stderr, "Read buffer failed, res=%d\n", res);
- if (0 == verbose)
- fprintf(stderr, "... try again with -v or -vv\n");
- break;
- }
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Read buffer failed: %s\n", b);
} else if (rb_len > 0) {
if (do_raw)
dStrRaw((const char *)resp, rb_len);
diff --git a/src/sg_readcap.c b/src/sg_readcap.c
index 31fcb208..6b55cbb5 100644
--- a/src/sg_readcap.c
+++ b/src/sg_readcap.c
@@ -29,7 +29,7 @@
#include "sg_cmds_basic.h"
-static const char * version_str = "3.91 20140412";
+static const char * version_str = "3.92 20140515";
#define ME "sg_readcap: "
@@ -359,6 +359,7 @@ int main(int argc, char * argv[])
int ret = 0;
unsigned int last_blk_addr, block_size;
unsigned char resp_buff[RCAP16_REPLY_LEN];
+ char b[80];
struct opts_t opts;
struct opts_t * op;
@@ -472,15 +473,10 @@ int main(int argc, char * argv[])
if (op->do_verbose)
fprintf(stderr, "READ CAPACITY (10) not supported, trying "
"READ CAPACITY (16)\n");
- } else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- fprintf(stderr, "bad field in READ CAPACITY (10) cdb\n");
- else if (SG_LIB_CAT_NOT_READY == res)
- fprintf(stderr, "READ CAPACITY (10) failed, device not ready\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- fprintf(stderr, "READ CAPACITY (10) failed, aborted command\n");
- else if (! op->do_verbose)
- fprintf(stderr, "READ CAPACITY (10) failed [res=%d], try "
- "with '-v'\n", res);
+ } else if (res) {
+ sg_get_category_sense_str(res, sizeof(b), b, op->do_verbose);
+ fprintf(stderr, "READ CAPACITY (10) failed: %s\n", b);
+ }
}
if (op->do_long) {
res = sg_ll_readcap_16(sg_fd, op->do_pmi, op->llba, resp_buff,
@@ -553,19 +549,13 @@ int main(int argc, char * argv[])
#endif
}
goto good;
- }
- else if (SG_LIB_CAT_INVALID_OP == res)
- fprintf(stderr, "READ CAPACITY (16) not supported\n");
- else if (SG_LIB_CAT_NOT_READY == res)
- fprintf(stderr, "READ CAPACITY (16) failed, device not ready\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- fprintf(stderr, "READ CAPACITY (16) failed, aborted command\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
+ } else if (SG_LIB_CAT_ILLEGAL_REQ == res)
fprintf(stderr, "bad field in READ CAPACITY (16) cdb "
"including unsupported service action\n");
- else if (! op->do_verbose)
- fprintf(stderr, "READ CAPACITY (16) failed [res=%d], try "
- "with '-v'\n", res);
+ else if (res) {
+ sg_get_category_sense_str(res, sizeof(b), b, op->do_verbose);
+ fprintf(stderr, "READ CAPACITY (16) failed: %s\n", b);
+ }
}
if (op->do_brief)
printf("0x0 0x0\n");
diff --git a/src/sg_referrals.c b/src/sg_referrals.c
index af7ca14a..6f64c57b 100644
--- a/src/sg_referrals.c
+++ b/src/sg_referrals.c
@@ -29,7 +29,7 @@
* SCSI device.
*/
-static const char * version_str = "1.04 20150511"; /* sbc4r01 */
+static const char * version_str = "1.04 20150515"; /* sbc4r01 */
#define MAX_REFER_BUFF_LEN (1024 * 1024)
#define DEF_REFER_BUFF_LEN 256
@@ -333,16 +333,11 @@ main(int argc, char * argv[])
k += res;
desc++;
}
- } else if (SG_LIB_CAT_INVALID_OP == res)
- fprintf(stderr, "Report Referrals command not supported\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- fprintf(stderr, "Report Referrals, aborted command\n");
- else if (SG_LIB_CAT_ILLEGAL_REQ == res)
- fprintf(stderr, "Report Referrals command has bad field in cdb\n");
- else {
- fprintf(stderr, "Report Referrals command failed\n");
- if (0 == verbose)
- fprintf(stderr, " try '-v' option for more information\n");
+ } else {
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Report Referrals command failed: %s\n", b);
}
the_end:
diff --git a/src/sg_requests.c b/src/sg_requests.c
index c45dba36..c5b3307f 100644
--- a/src/sg_requests.c
+++ b/src/sg_requests.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2013 Douglas Gilbert.
+ * Copyright (c) 2004-2014 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.
@@ -25,7 +25,7 @@
* This program issues the SCSI command REQUEST SENSE to the given SCSI device.
*/
-static const char * version_str = "1.24 20130730";
+static const char * version_str = "1.25 20140514";
#define MAX_REQS_RESP_LEN 255
#define DEF_REQS_RESP_LEN 252
@@ -118,6 +118,7 @@ main(int argc, char * argv[])
int verbose = 0;
const char * device_name = NULL;
int ret = 0;
+ char b[80];
#ifndef SG_LIB_MINGW
struct timeval start_tm, end_tm;
#endif
@@ -230,11 +231,8 @@ main(int argc, char * argv[])
else if (SG_LIB_CAT_ABORTED_COMMAND == res)
fprintf(stderr, "Request Sense, aborted command\n");
else {
- fprintf(stderr, "Request Sense command unexpectedly "
- "failed\n");
- if (0 == verbose)
- fprintf(stderr, " try the '-v' option for "
- "more information\n");
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Request Sense command: %s\n", b);
}
break;
}
@@ -299,10 +297,8 @@ main(int argc, char * argv[])
else if (SG_LIB_CAT_ABORTED_COMMAND == res)
fprintf(stderr, "Request Sense, aborted command\n");
else {
- fprintf(stderr, "Request Sense command unexpectedly failed\n");
- if (0 == verbose)
- fprintf(stderr, " try the '-v' option for "
- "more information\n");
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Request Sense command: %s\n", b);
}
break;
}
diff --git a/src/sg_rtpg.c b/src/sg_rtpg.c
index 6a0f7e0b..0440c4ea 100644
--- a/src/sg_rtpg.c
+++ b/src/sg_rtpg.c
@@ -26,7 +26,7 @@
* to the given SCSI device.
*/
-static const char * version_str = "1.19 20140511";
+static const char * version_str = "1.19 20140515";
#define REPORT_TGT_GRP_BUFF_LEN 1024
@@ -305,14 +305,11 @@ int main(int argc, char * argv[])
else if (SG_LIB_CAT_ILLEGAL_REQ == res)
fprintf(stderr, "bad field in Report Target Port Groups cdb "
"including unsupported service action\n");
- else if (SG_LIB_CAT_UNIT_ATTENTION == res)
- fprintf(stderr, "Report Target Port Groups, unit attention\n");
- else if (SG_LIB_CAT_ABORTED_COMMAND == res)
- fprintf(stderr, "Report Target Port Groups, aborted command\n");
else {
- fprintf(stderr, "Report Target Port Groups command failed\n");
- if (0 == verbose)
- fprintf(stderr, " try '-v' for more information\n");
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ fprintf(stderr, "Report Target Port Groups: %s\n", b);
}
err_out:
diff --git a/src/sg_sat_identify.c b/src/sg_sat_identify.c
index f0213d03..e0daa535 100644
--- a/src/sg_sat_identify.c
+++ b/src/sg_sat_identify.c
@@ -45,7 +45,7 @@
#define EBUFF_SZ 256
-static const char * version_str = "1.10 20140512";
+static const char * version_str = "1.10 20140515";
static struct option long_options[] = {
{"ck_cond", no_argument, 0, 'c'},
@@ -69,7 +69,7 @@ static void usage()
"[--ident]\n"
" [--len=16|12] [--packet] [--raw] "
"[--readonly]\n"
- " [--verbose] [--version] DEVICE\n"
+ " [--verbose] [--version] DEVICE\n"
" where:\n"
" --ck_cond|-c sets ck_cond bit in cdb (def: 0)\n"
" --extend|-e sets extend bit in cdb (def: 0)\n"
@@ -223,9 +223,19 @@ static int do_identify_dev(int sg_fd, int do_packet, int cdb_len,
"hardware error\n", cdb_len);
return SG_LIB_CAT_MEDIUM_HARD;
case SPC_SK_ABORTED_COMMAND:
- fprintf(stderr, "Aborted command: try again with%s '-p' "
- "option\n", (do_packet ? "out" : ""));
- return SG_LIB_CAT_ABORTED_COMMAND;
+ if (0x10 == ssh.asc) {
+ fprintf(stderr, "Aborted command: protection "
+ "information\n");
+ return SG_LIB_CAT_PROTECTION;
+ } else {
+ fprintf(stderr, "Aborted command: try again with%s '-p' "
+ "option\n", (do_packet ? "out" : ""));
+ return SG_LIB_CAT_ABORTED_COMMAND;
+ }
+ case SPC_SK_DATA_PROTECT:
+ fprintf(stderr, "ATA PASS-THROUGH (%d): data protect, read "
+ "only media?\n", cdb_len);
+ return SG_LIB_CAT_DATA_PROTECT;
default:
if (verbose < 2)
fprintf(stderr, "ATA PASS-THROUGH (%d), some sense "
@@ -242,8 +252,13 @@ static int do_identify_dev(int sg_fd, int do_packet, int cdb_len,
return SG_LIB_CAT_MALFORMED;
}
} else if (res > 0) {
- fprintf(stderr, "Unexpected SCSI status=0x%x\n", res);
- return SG_LIB_CAT_MALFORMED;
+ if (SAM_STAT_RESERVATION_CONFLICT == res) {
+ fprintf(stderr, "SCSI status: RESERVATION CONFLICT\n");
+ return SG_LIB_CAT_RES_CONFLICT;
+ } else {
+ fprintf(stderr, "Unexpected SCSI status=0x%x\n", res);
+ return SG_LIB_CAT_MALFORMED;
+ }
} else {
fprintf(stderr, "ATA pass through (%d) failed\n", cdb_len);
if (verbose < 2)
diff --git a/src/sg_scan.c.win32 b/src/sg_scan.c.win32
index 954e7aa8..f9463f95 100644
--- a/src/sg_scan.c.win32
+++ b/src/sg_scan.c.win32
@@ -37,7 +37,7 @@
#include "sg_pt_win32.h"
-static const char * version_str = "1.11 (win32) 20130513";
+static const char * version_str = "1.12 (win32) 20130513";
#define MAX_SCSI_ELEMS 1024
#define MAX_ADAPTER_NUM 64
@@ -671,6 +671,10 @@ sg_do_wscan(char letter, int show_bt, int scsi_scan)
dStrHex(sp->qp_descriptor.raw, 144, 0);
} else
printf("\n");
+ if ((verbose > 3) && sp->qp_uid_valid) {
+ printf(" UID valid, in hex:\n");
+ dStrHex(sp->qp_uid.raw, sizeof(sp->qp_uid.raw), 1);
+ }
}
}
diff --git a/src/sg_ses.c b/src/sg_ses.c
index 2003ba26..2d6e3ceb 100644
--- a/src/sg_ses.c
+++ b/src/sg_ses.c
@@ -29,7 +29,7 @@
* commands tailored for SES (enclosure) devices.
*/
-static const char * version_str = "1.90 20140512"; /* ses3r06 */
+static const char * version_str = "1.91 20140515"; /* ses3r06 */
#define MX_ALLOC_LEN ((64 * 1024) - 1) /* max allowable for big enclosures */
#define MX_ELEM_HDR 1024
@@ -1171,10 +1171,8 @@ find_out_diag_page_desc(int page_num)
return NULL;
}
-/* Return of 0 -> success, SG_LIB_CAT_INVALID_OP -> Send diagnostic not
- * supported, SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb,
- * SG_LIB_CAT_NOT_READY, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_ABORTED_COMMAND, -1 -> other failures */
+/* Return of 0 -> success, SG_LIB_CAT_* positive values or -1 -> other
+ * failures */
static int
do_senddiag(int sg_fd, int pf_bit, void * outgoing_pg, int outgoing_len,
int noisy, int verbose)
@@ -1268,16 +1266,15 @@ active_et_aesp(int el_type)
return 0;
}
-/* Return of 0 -> success, SG_LIB_CAT_INVALID_OP -> command not supported,
- * SG_LIB_CAT_ILLEGAL_REQ -> bad field in cdb, SG_LIB_CAT_UNIT_ATTENTION,
- * SG_LIB_CAT_NOT_READY -> device not ready, SG_LIB_CAT_ABORTED_COMMAND,
- * -2 -> unexpected response, -1 -> other failure */
+/* Return of 0 -> success, SG_LIB_CAT_* positive values or -1 -> other
+ * failures */
static int
do_rec_diag(int sg_fd, int page_code, unsigned char * rsp_buff,
int rsp_buff_size, const struct opts_t * op, int * rsp_lenp)
{
int rsp_len, res;
const char * cp;
+ char b[80];
memset(rsp_buff, 0, rsp_buff_size);
if (rsp_lenp)
@@ -1324,24 +1321,8 @@ do_rec_diag(int sg_fd, int page_code, unsigned char * rsp_buff,
else
pr2serr("Attempt to fetch status diagnostic page [0x%x] failed\n",
page_code);
- switch (res) {
- case SG_LIB_CAT_NOT_READY:
- pr2serr(" device no ready\n");
- break;
- case SG_LIB_CAT_ABORTED_COMMAND:
- pr2serr(" aborted command\n");
- break;
- case SG_LIB_CAT_UNIT_ATTENTION:
- pr2serr(" unit attention\n");
- break;
- case SG_LIB_CAT_INVALID_OP:
- pr2serr(" Receive diagnostic results command not supported\n");
- break;
- case SG_LIB_CAT_ILLEGAL_REQ:
- pr2serr(" Receive diagnostic results command, bad field in "
- "cdb\n");
- break;
- }
+ sg_get_category_sense_str(res, sizeof(b), b, op->verbose);
+ pr2serr(" %s\n", b);
}
return res;
}
@@ -3940,6 +3921,7 @@ main(int argc, char * argv[])
{
int sg_fd, res;
char buff[128];
+ char b[80];
int pd_type = 0;
int have_cgs = 0;
int ret = 0;
@@ -4133,24 +4115,8 @@ main(int argc, char * argv[])
err_out:
if (0 == op->do_status) {
- switch (ret) {
- case SG_LIB_CAT_NOT_READY:
- pr2serr(" device no ready\n");
- break;
- case SG_LIB_CAT_ABORTED_COMMAND:
- pr2serr(" aborted command\n");
- break;
- case SG_LIB_CAT_UNIT_ATTENTION:
- pr2serr(" unit attention\n");
- break;
- case SG_LIB_CAT_INVALID_OP:
- pr2serr(" Send diagnostics command not supported\n");
- break;
- case SG_LIB_CAT_ILLEGAL_REQ:
- pr2serr(" Send diagnostics command, bad field in cdb or "
- "parameter list\n");
- break;
- }
+ sg_get_category_sense_str(ret, sizeof(b), b, op->verbose);
+ pr2serr(" %s\n", b);
}
if (ret && (0 == op->verbose))
pr2serr("Problem detected, try again with --verbose option for more "
diff --git a/src/sg_turs.c b/src/sg_turs.c
index 7bd41a3e..3c69c004 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-2013 D. Gilbert
+ * Copyright (C) 2000-2014 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)
@@ -30,7 +30,7 @@
#include "sg_cmds_basic.h"
-static const char * version_str = "3.29 20130530";
+static const char * version_str = "3.30 20140514";
#if defined(MSC_VER) || defined(__MINGW32__)
#define HAVE_MS_SLEEP
@@ -101,15 +101,15 @@ static void usage_old()
"Performs a SCSI TEST UNIT READY command (or many of them)\n");
}
-static void usage_for(const struct opts_t * optsp)
+static void usage_for(const struct opts_t * op)
{
- if (optsp->opt_new)
+ if (op->opt_new)
usage();
else
usage_old();
}
-static int process_cl_new(struct opts_t * optsp, int argc, char * argv[])
+static int process_cl_new(struct opts_t * op, int argc, char * argv[])
{
int c, n;
@@ -124,7 +124,7 @@ static int process_cl_new(struct opts_t * optsp, int argc, char * argv[])
switch (c) {
case 'h':
case '?':
- ++optsp->do_help;
+ ++op->do_help;
break;
case 'n':
n = sg_get_num(optarg);
@@ -133,36 +133,36 @@ static int process_cl_new(struct opts_t * optsp, int argc, char * argv[])
usage();
return SG_LIB_SYNTAX_ERROR;
}
- optsp->do_number = n;
+ op->do_number = n;
break;
case 'N':
break; /* ignore */
case 'O':
- optsp->opt_new = 0;
+ op->opt_new = 0;
return 0;
case 'p':
- ++optsp->do_progress;
+ ++op->do_progress;
break;
case 't':
- ++optsp->do_time;
+ ++op->do_time;
break;
case 'v':
- ++optsp->do_verbose;
+ ++op->do_verbose;
break;
case 'V':
- ++optsp->do_version;
+ ++op->do_version;
break;
default:
fprintf(stderr, "unrecognised option code %c [0x%x]\n", c, c);
- if (optsp->do_help)
+ if (op->do_help)
break;
usage();
return SG_LIB_SYNTAX_ERROR;
}
}
if (optind < argc) {
- if (NULL == optsp->device_name) {
- optsp->device_name = argv[optind];
+ if (NULL == op->device_name) {
+ op->device_name = argv[optind];
++optind;
}
if (optind < argc) {
@@ -176,7 +176,7 @@ static int process_cl_new(struct opts_t * optsp, int argc, char * argv[])
return 0;
}
-static int process_cl_old(struct opts_t * optsp, int argc, char * argv[])
+static int process_cl_old(struct opts_t * op, int argc, char * argv[])
{
int k, jmp_out, plen;
const char * cp;
@@ -190,21 +190,21 @@ static int process_cl_old(struct opts_t * optsp, int argc, char * argv[])
for (--plen, ++cp, jmp_out = 0; plen > 0; --plen, ++cp) {
switch (*cp) {
case 'N':
- optsp->opt_new = 1;
+ op->opt_new = 1;
return 0;
case 'O':
break;
case 'p':
- ++optsp->do_progress;
+ ++op->do_progress;
break;
case 't':
- ++optsp->do_time;
+ ++op->do_time;
break;
case 'v':
- ++optsp->do_verbose;
+ ++op->do_verbose;
break;
case 'V':
- ++optsp->do_verbose;
+ ++op->do_verbose;
break;
case '?':
usage_old();
@@ -219,8 +219,8 @@ static int process_cl_old(struct opts_t * optsp, int argc, char * argv[])
if (plen <= 0)
continue;
if (0 == strncmp("n=", cp, 2)) {
- optsp->do_number = sg_get_num(cp + 2);
- if (optsp->do_number <= 0) {
+ op->do_number = sg_get_num(cp + 2);
+ if (op->do_number <= 0) {
printf("Couldn't decode number after 'n=' option\n");
usage_old();
return SG_LIB_SYNTAX_ERROR;
@@ -232,11 +232,11 @@ static int process_cl_old(struct opts_t * optsp, int argc, char * argv[])
usage_old();
return SG_LIB_SYNTAX_ERROR;
}
- } else if (0 == optsp->device_name)
- optsp->device_name = cp;
+ } else if (0 == op->device_name)
+ op->device_name = cp;
else {
fprintf(stderr, "too many arguments, got: %s, not expecting: "
- "%s\n", optsp->device_name, cp);
+ "%s\n", op->device_name, cp);
usage_old();
return SG_LIB_SYNTAX_ERROR;
}
@@ -244,22 +244,22 @@ static int process_cl_old(struct opts_t * optsp, int argc, char * argv[])
return 0;
}
-static int process_cl(struct opts_t * optsp, int argc, char * argv[])
+static int process_cl(struct opts_t * op, int argc, char * argv[])
{
int res;
char * cp;
cp = getenv("SG3_UTILS_OLD_OPTS");
if (cp) {
- optsp->opt_new = 0;
- res = process_cl_old(optsp, argc, argv);
- if ((0 == res) && optsp->opt_new)
- res = process_cl_new(optsp, argc, argv);
+ op->opt_new = 0;
+ res = process_cl_old(op, argc, argv);
+ if ((0 == res) && op->opt_new)
+ res = process_cl_new(op, argc, argv);
} else {
- optsp->opt_new = 1;
- res = process_cl_new(optsp, argc, argv);
- if ((0 == res) && (0 == optsp->opt_new))
- res = process_cl_old(optsp, argc, argv);
+ op->opt_new = 1;
+ res = process_cl_new(op, argc, argv);
+ if ((0 == res) && (0 == op->opt_new))
+ res = process_cl_old(op, argc, argv);
}
return res;
}
@@ -274,40 +274,43 @@ int main(int argc, char * argv[])
struct timeval start_tm, end_tm;
#endif
struct opts_t opts;
+ struct opts_t * op;
+ char b[80];
- memset(&opts, 0, sizeof(opts));
- opts.do_number = 1;
- res = process_cl(&opts, argc, argv);
+ op = &opts;
+ memset(op, 0, sizeof(opts));
+ op->do_number = 1;
+ res = process_cl(op, argc, argv);
if (res)
return SG_LIB_SYNTAX_ERROR;
- if (opts.do_help) {
- usage_for(&opts);
+ if (op->do_help) {
+ usage_for(op);
return 0;
}
- if (opts.do_version) {
+ if (op->do_version) {
fprintf(stderr, "Version string: %s\n", version_str);
return 0;
}
- if (NULL == opts.device_name) {
+ if (NULL == op->device_name) {
fprintf(stderr, "No DEVICE argument given\n");
- usage_for(&opts);
+ usage_for(op);
return SG_LIB_SYNTAX_ERROR;
}
- if ((sg_fd = sg_cmds_open_device(opts.device_name, 1 /* ro */,
- opts.do_verbose)) < 0) {
+ if ((sg_fd = sg_cmds_open_device(op->device_name, 1 /* ro */,
+ op->do_verbose)) < 0) {
fprintf(stderr, "sg_turs: error opening file: %s: %s\n",
- opts.device_name, safe_strerror(-sg_fd));
+ op->device_name, safe_strerror(-sg_fd));
return SG_LIB_FILE_ERROR;
}
- if (opts.do_progress) {
- for (k = 0; k < opts.do_number; ++k) {
+ if (op->do_progress) {
+ for (k = 0; k < op->do_number; ++k) {
if (k > 0)
sleep_for(30);
progress = -1;
res = sg_ll_test_unit_ready_progress(sg_fd, k, &progress,
- ((1 == opts.do_number) ? 1 : 0), opts.do_verbose);
+ ((1 == op->do_number) ? 1 : 0), op->do_verbose);
if (progress < 0) {
ret = res;
break;
@@ -317,32 +320,38 @@ int main(int argc, char * argv[])
printf("Progress indication: %d.%02d%% done\n", pr, rem);
}
}
- if (opts.do_number > 1)
+ if (op->do_number > 1)
printf("Completed %d Test Unit Ready commands\n",
- ((k < opts.do_number) ? k + 1 : k));
+ ((k < op->do_number) ? k + 1 : k));
} else {
#ifndef SG_LIB_MINGW
- if (opts.do_time) {
+ if (op->do_time) {
start_tm.tv_sec = 0;
start_tm.tv_usec = 0;
gettimeofday(&start_tm, NULL);
}
#endif
- for (k = 0; k < opts.do_number; ++k) {
+ for (k = 0; k < op->do_number; ++k) {
/* Might get Unit Attention on first invocation */
- res = sg_ll_test_unit_ready(sg_fd, k, (0 == k), opts.do_verbose);
+ res = sg_ll_test_unit_ready(sg_fd, k, (0 == k), op->do_verbose);
if (res) {
++num_errs;
ret = res;
- if ((1 == opts.do_number) && (SG_LIB_CAT_NOT_READY == res)) {
- printf("device not ready\n");
+ if (1 == op->do_number) {
+ if (SG_LIB_CAT_NOT_READY == res)
+ printf("device not ready\n");
+ else {
+ sg_get_category_sense_str(res, sizeof(b), b,
+ op->do_verbose);
+ printf("%s\n", b);
+ }
reported = 1;
break;
}
}
}
#ifndef SG_LIB_MINGW
- if ((opts.do_time) && (start_tm.tv_sec || start_tm.tv_usec)) {
+ if ((op->do_time) && (start_tm.tv_sec || start_tm.tv_usec)) {
struct timeval res_tm;
double a, b;
@@ -355,7 +364,7 @@ int main(int argc, char * argv[])
}
a = res_tm.tv_sec;
a += (0.000001 * res_tm.tv_usec);
- b = (double)opts.do_number;
+ b = (double)op->do_number;
printf("time to perform commands was %d.%06d secs",
(int)res_tm.tv_sec, (int)res_tm.tv_usec);
if (a > 0.00001)
@@ -365,9 +374,9 @@ int main(int argc, char * argv[])
}
#endif
- if (((opts.do_number > 1) || (num_errs > 0)) && (! reported))
+ if (((op->do_number > 1) || (num_errs > 0)) && (! reported))
printf("Completed %d Test Unit Ready commands with %d errors\n",
- opts.do_number, num_errs);
+ op->do_number, num_errs);
}
sg_cmds_close_device(sg_fd);
return (ret >= 0) ? ret : SG_LIB_CAT_OTHER;
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
index d1e5e459..1f2aa1c1 100644
--- a/src/sg_vpd.c
+++ b/src/sg_vpd.c
@@ -33,7 +33,7 @@
*/
-static const char * version_str = "0.81 20140330"; /* spc4r36s + sbc4r01 */
+static const char * version_str = "0.82 20140514"; /* spc4r36s + sbc4r01 */
/* And with sbc3r35, vale Mark Evans */
void svpd_enumerate_vendor(void);
@@ -473,17 +473,12 @@ pt_inquiry(int sg_fd, int evpd, int pg_op, void * resp, int mx_resp_len,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else if (ret < 4) {
@@ -3099,7 +3094,7 @@ svpd_decode_t10(int sg_fd, int pn, int subvalue, int maxlen, int do_hex,
int
main(int argc, char * argv[])
{
- int sg_fd, c, res, matches, inhex_len;
+ int sg_fd, c, res, matches;
const char * device_name = NULL;
const struct svpd_values_name_t * vnp;
const char * page_str = NULL;
@@ -3108,6 +3103,7 @@ main(int argc, char * argv[])
int num_vpd = 0;
int do_enum = 0;
int do_hex = 0;
+ int inhex_len = 0;
int do_ident = 0;
int do_long = 0;
int maxlen = 0;
@@ -3362,8 +3358,12 @@ main(int argc, char * argv[])
}
if (SG_LIB_CAT_ABORTED_COMMAND == res)
pr2serr("fetching VPD page failed, aborted command\n");
- else if (res)
- pr2serr("fetching VPD page failed\n");
+ else if (res) {
+ char b[80];
+
+ sg_get_category_sense_str(res, sizeof(b), b, do_verbose);
+ pr2serr("fetching VPD page failed: %s\n", b);
+ }
ret = res;
res = sg_cmds_close_device(sg_fd);
if (res < 0) {
diff --git a/src/sg_write_buffer.c b/src/sg_write_buffer.c
index 3f1bf1a9..93908c08 100644
--- a/src/sg_write_buffer.c
+++ b/src/sg_write_buffer.c
@@ -26,7 +26,7 @@
* This utility issues the SCSI WRITE BUFFER command to the given device.
*/
-static const char * version_str = "1.13 20140507"; /* spc4r36s */
+static const char * version_str = "1.14 20140515"; /* spc4r36s */
#define ME "sg_write_buffer: "
#define DEF_XFER_LEN (8 * 1024 * 1024)
@@ -233,19 +233,12 @@ sg_ll_write_buffer_v2(int sg_fd, int mode, int m_specific, int buffer_id,
;
else if (-2 == ret) {
switch (sense_cat) {
- case SG_LIB_CAT_NOT_READY:
- case SG_LIB_CAT_INVALID_OP:
- case SG_LIB_CAT_ILLEGAL_REQ:
- case SG_LIB_CAT_UNIT_ATTENTION:
- case SG_LIB_CAT_ABORTED_COMMAND:
- ret = sense_cat;
- break;
case SG_LIB_CAT_RECOVERED:
case SG_LIB_CAT_NO_SENSE:
ret = 0;
break;
default:
- ret = -1;
+ ret = sense_cat;
break;
}
} else
@@ -526,32 +519,11 @@ main(int argc, char * argv[])
wb_offset, dop, wb_len, 1, verbose);
}
if (0 != res) {
+ char b[80];
+
ret = res;
- switch (res) {
- case SG_LIB_CAT_NOT_READY:
- pr2serr("Write buffer failed, device not ready\n");
- break;
- case SG_LIB_CAT_UNIT_ATTENTION:
- pr2serr("Write buffer not done, unit attention\n");
- break;
- case SG_LIB_CAT_ABORTED_COMMAND:
- pr2serr("Write buffer, aborted command\n");
- break;
- case SG_LIB_CAT_INVALID_OP:
- pr2serr("Write buffer command not supported\n");
- break;
- case SG_LIB_CAT_ILLEGAL_REQ:
- pr2serr("bad field in Write buffer cdb\n");
- break;
- default:
- if (-1 == res) {
- fprintf(stderr, "Write buffer command failed\n");
- } else
- fprintf(stderr, "Write buffer failed, res=%d\n", res);
- if (0 == verbose)
- fprintf(stderr, "... try again with -v or -vv\n");
- break;
- }
+ sg_get_category_sense_str(res, sizeof(b), b, verbose);
+ pr2serr("Write buffer failed: %s\n", b);
}
err_out: