aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2021-06-11 03:57:05 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2021-06-11 03:57:05 +0000
commitbee57c535c29a01cadfaa660d8c0182288960c33 (patch)
tree2a9355f53953526dc12f101d6bf6b26962f5dbbe
parent30363466e3580cae5f428c9bf35caa934cef469b (diff)
downloadsg3_utils-bee57c535c29a01cadfaa660d8c0182288960c33.tar.gz
sg_read_buffer: fix --length= problem; pt: new configure option --enable-pt_dummy builds the library with sg_pt_dummy.c instead of OS specific code
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@904 6180dd3e-e324-4e3e-922d-17de1ae2f315
-rw-r--r--ChangeLog8
-rw-r--r--config.h.in6
-rwxr-xr-xconfigure67
-rw-r--r--configure.ac17
-rw-r--r--lib/Makefile.am16
-rw-r--r--lib/Makefile.in66
-rw-r--r--lib/sg_pt_dummy.c362
-rw-r--r--lib/sg_pt_osf1.c26
-rw-r--r--lib/sg_pt_solaris.c19
-rw-r--r--lib/sg_pt_win32.c4
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in32
-rw-r--r--src/sg_decode_sense.c7
-rw-r--r--src/sg_inq.c4
-rw-r--r--src/sg_logs.c10
-rw-r--r--src/sg_luns.c6
-rw-r--r--src/sg_modes.c6
-rw-r--r--src/sg_opcodes.c4
-rw-r--r--src/sg_persist.c8
-rw-r--r--src/sg_read_attr.c8
-rw-r--r--src/sg_read_buffer.c11
-rw-r--r--src/sg_requests.c14
-rw-r--r--src/sg_senddiag.c6
-rw-r--r--src/sg_ses.c16
-rw-r--r--src/sg_ses_microcode.c6
-rw-r--r--src/sg_stpg.c12
-rw-r--r--src/sg_vpd.c14
-rw-r--r--src/sg_wr_mode.c6
-rw-r--r--src/sg_write_buffer.c6
-rw-r--r--src/sg_write_x.c10
-rw-r--r--testing/sgh_dd.cpp70
31 files changed, 716 insertions, 133 deletions
diff --git a/ChangeLog b/ChangeLog
index 6bf0479e..465479c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,21 +2,25 @@ 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 pre-release sg3_utils-1.47 [20210607] [svn: r903]
+Changelog for pre-release sg3_utils-1.47 [20210610] [svn: r904]
- sg_rep_zones: add support for REPORT ZONE DOMAINS and
REPORT REALMS in this utility
- sg_raw: fix prints of NVMe NVM command names
- sg_ses: fix Windows problem "No command (cdb) given"
- sg_logs: additions to Volume statistics lpage [ssc5r05c]
- sg_vpd: fix do_hex type on some recent pages
- - sg_lib: add sg_scsi_status_is_good(),
+ - sg_read_buffer: fix --length= problem
- sg_dd, sgm_dd, sgp_dd: don't close negative file descriptors
+ - sg_lib: add sg_scsi_status_is_good(),
sg_scsi_status_is_bad() and sg_get_zone_type_str()
- pt_linux: fix verify(BytChk=0) which Linux SNTL translated
to write, other SNTL cleanups
- pt_linux_nvme: fix fua setting
- pt: check_pt_file_handle() add return value of 5 for
FreeBSD for nvme(cam)
+ - pt: new configure option --enable-pt_dummy builds the
+ library with sg_pt_dummy.c instead of OS specific code.
+ To experiment with --inhex= decoding on netbsd
- move some hex files from examples to inhex directory
- major rework of lib/sg_pt_freebsd.c; make SNTL as similar
as feasible to the Linux implementation
diff --git a/config.h.in b/config.h.in
index 02d3725c..ed7d18a8 100644
--- a/config.h.in
+++ b/config.h.in
@@ -135,6 +135,12 @@
/* also MinGW environment */
#undef SG_LIB_MINGW
+/* sg3_utils on NetBSD */
+#undef SG_LIB_NETBSD
+
+/* sg3_utils on OpenBSD */
+#undef SG_LIB_OPENBSD
+
/* sg3_utils on Tru64 UNIX */
#undef SG_LIB_OSF1
diff --git a/configure b/configure
index c3abf65f..fd88c2b0 100755
--- a/configure
+++ b/configure
@@ -661,8 +661,14 @@ ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
+PT_DUMMY_FALSE
+PT_DUMMY_TRUE
DEBUG_FALSE
DEBUG_TRUE
+OS_OPENBSD_FALSE
+OS_OPENBSD_TRUE
+OS_NETBSD_FALSE
+OS_NETBSD_TRUE
OS_ANDROID_FALSE
OS_ANDROID_TRUE
OS_WIN32_CYGWIN_FALSE
@@ -812,6 +818,7 @@ with_gnu_ld
with_sysroot
enable_libtool_lock
enable_debug
+enable_pt_dummy
enable_linuxbsg
enable_win32_spt_direct
enable_scsistrings
@@ -1470,7 +1477,8 @@ Optional Features:
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
- --enable-debug Turn on debugging
+ --enable-debug Turn on debugging
+ --enable-pt_dummy pass-through codes compiles, does nothing
--disable-linuxbsg option ignored, this is placeholder
--enable-win32-spt-direct
enable Win32 SPT Direct
@@ -13248,6 +13256,14 @@ printf "%s\n" "#define HAVE_NVME 1" >>confdefs.h
printf "%s\n" "#define SG_LIB_SOLARIS 1" >>confdefs.h
;;
+ *-*-netbsd*)
+
+printf "%s\n" "#define SG_LIB_NETBSD 1" >>confdefs.h
+;;
+ *-*-openbsd*)
+
+printf "%s\n" "#define SG_LIB_OPENBSD 1" >>confdefs.h
+;;
*-*-osf*)
printf "%s\n" "#define SG_LIB_OSF1 1" >>confdefs.h
@@ -13341,6 +13357,22 @@ else
OS_ANDROID_FALSE=
fi
+ if echo $host_os | grep 'netbsd' > /dev/null; then
+ OS_NETBSD_TRUE=
+ OS_NETBSD_FALSE='#'
+else
+ OS_NETBSD_TRUE='#'
+ OS_NETBSD_FALSE=
+fi
+
+ if echo $host_os | grep 'openbsd' > /dev/null; then
+ OS_OPENBSD_TRUE=
+ OS_OPENBSD_FALSE='#'
+else
+ OS_OPENBSD_TRUE='#'
+ OS_OPENBSD_FALSE=
+fi
+
# Check whether --enable-debug was given.
if test ${enable_debug+y}
@@ -13363,6 +13395,27 @@ else
fi
+# Check whether --enable-pt_dummy was given.
+if test ${enable_pt_dummy+y}
+then :
+ enableval=$enable_pt_dummy; case "${enableval}" in
+ yes) pt_dummy=true ;;
+ no) pt_dummy=false ;;
+ *) as_fn_error $? "bad value ${enableval} for --enable-dummy_pt" "$LINENO" 5 ;;
+ esac
+else $as_nop
+ pt_dummy=false
+fi
+
+ if test x$pt_dummy = xtrue; then
+ PT_DUMMY_TRUE=
+ PT_DUMMY_FALSE='#'
+else
+ PT_DUMMY_TRUE='#'
+ PT_DUMMY_FALSE=
+fi
+
+
# Check whether --enable-linuxbsg was given.
if test ${enable_linuxbsg+y}
then :
@@ -13587,10 +13640,22 @@ if test -z "${OS_ANDROID_TRUE}" && test -z "${OS_ANDROID_FALSE}"; then
as_fn_error $? "conditional \"OS_ANDROID\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
+if test -z "${OS_NETBSD_TRUE}" && test -z "${OS_NETBSD_FALSE}"; then
+ as_fn_error $? "conditional \"OS_NETBSD\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${OS_OPENBSD_TRUE}" && test -z "${OS_OPENBSD_FALSE}"; then
+ as_fn_error $? "conditional \"OS_OPENBSD\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
if test -z "${DEBUG_TRUE}" && test -z "${DEBUG_FALSE}"; then
as_fn_error $? "conditional \"DEBUG\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
+if test -z "${PT_DUMMY_TRUE}" && test -z "${PT_DUMMY_FALSE}"; then
+ as_fn_error $? "conditional \"PT_DUMMY\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
diff --git a/configure.ac b/configure.ac
index f9589dcf..bb1e1477 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,10 @@ case "${host}" in
LIBS="$LIBS -lcam";;
*-*-solaris*)
AC_DEFINE_UNQUOTED(SG_LIB_SOLARIS, 1, [sg3_utils on Solaris]);;
+ *-*-netbsd*)
+ AC_DEFINE_UNQUOTED(SG_LIB_NETBSD, 1, [sg3_utils on NetBSD]);;
+ *-*-openbsd*)
+ AC_DEFINE_UNQUOTED(SG_LIB_OPENBSD, 1, [sg3_utils on OpenBSD]);;
*-*-osf*)
AC_DEFINE_UNQUOTED(SG_LIB_OSF1, 1, [sg3_utils on Tru64 UNIX]);;
*-*-cygwin*)
@@ -117,9 +121,11 @@ AM_CONDITIONAL(OS_SOLARIS, [echo $host_os | grep '^solaris' > /dev/null])
AM_CONDITIONAL(OS_WIN32_MINGW, [echo $host_os | grep '^mingw' > /dev/null])
AM_CONDITIONAL(OS_WIN32_CYGWIN, [echo $host_os | grep '^cygwin' > /dev/null])
AM_CONDITIONAL(OS_ANDROID, [echo $host_os | grep 'android' > /dev/null])
+AM_CONDITIONAL(OS_NETBSD, [echo $host_os | grep 'netbsd' > /dev/null])
+AM_CONDITIONAL(OS_OPENBSD, [echo $host_os | grep 'openbsd' > /dev/null])
AC_ARG_ENABLE([debug],
- [ --enable-debug Turn on debugging],
+ [ --enable-debug Turn on debugging],
[case "${enableval}" in
yes) debug=true ;;
no) debug=false ;;
@@ -127,6 +133,15 @@ AC_ARG_ENABLE([debug],
esac],[debug=false])
AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
+AC_ARG_ENABLE([pt_dummy],
+ [ --enable-pt_dummy pass-through codes compiles, does nothing],
+ [case "${enableval}" in
+ yes) pt_dummy=true ;;
+ no) pt_dummy=false ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-dummy_pt]) ;;
+ esac],[pt_dummy=false])
+AM_CONDITIONAL([PT_DUMMY], [test x$pt_dummy = xtrue])
+
AC_ARG_ENABLE([linuxbsg],
AC_HELP_STRING([--disable-linuxbsg], [option ignored, this is placeholder]),
[AC_DEFINE_UNQUOTED(IGNORE_LINUX_BSG, 1, [option ignored], )], [])
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9f39d4a5..f04c7778 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,11 +8,15 @@ libsgutils2_la_SOURCES = \
sg_pt_common.c
if OS_LINUX
+if PT_DUMMY
+libsgutils2_la_SOURCES += sg_pt_dummy.c
+else
libsgutils2_la_SOURCES += \
sg_pt_linux.c \
sg_io_linux.c \
sg_pt_linux_nvme.c
endif
+endif
if OS_WIN32_MINGW
libsgutils2_la_SOURCES += sg_pt_win32.c
@@ -23,8 +27,12 @@ libsgutils2_la_SOURCES += sg_pt_win32.c
endif
if OS_FREEBSD
+if PT_DUMMY
+libsgutils2_la_SOURCES += sg_pt_dummy.c
+else
libsgutils2_la_SOURCES += sg_pt_freebsd.c
endif
+endif
if OS_SOLARIS
libsgutils2_la_SOURCES += sg_pt_solaris.c
@@ -34,6 +42,14 @@ if OS_OSF
libsgutils2_la_SOURCES += sg_pt_osf1.c
endif
+if OS_NETBSD
+libsgutils2_la_SOURCES += sg_pt_dummy.c
+endif
+
+if OS_OPENBSD
+libsgutils2_la_SOURCES += sg_pt_dummy.c
+endif
+
if DEBUG
# This is active if --enable-debug given to ./configure
# removed -Wduplicated-branches because needs gcc-8
diff --git a/lib/Makefile.in b/lib/Makefile.in
index c20d06f4..4e12ff91 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -88,16 +88,20 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
-@OS_LINUX_TRUE@am__append_1 = \
-@OS_LINUX_TRUE@ sg_pt_linux.c \
-@OS_LINUX_TRUE@ sg_io_linux.c \
-@OS_LINUX_TRUE@ sg_pt_linux_nvme.c
-
-@OS_WIN32_MINGW_TRUE@am__append_2 = sg_pt_win32.c
-@OS_WIN32_CYGWIN_TRUE@am__append_3 = sg_pt_win32.c
-@OS_FREEBSD_TRUE@am__append_4 = sg_pt_freebsd.c
-@OS_SOLARIS_TRUE@am__append_5 = sg_pt_solaris.c
-@OS_OSF_TRUE@am__append_6 = sg_pt_osf1.c
+@OS_LINUX_TRUE@@PT_DUMMY_TRUE@am__append_1 = sg_pt_dummy.c
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__append_2 = \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_pt_linux.c \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_io_linux.c \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_pt_linux_nvme.c
+
+@OS_WIN32_MINGW_TRUE@am__append_3 = sg_pt_win32.c
+@OS_WIN32_CYGWIN_TRUE@am__append_4 = sg_pt_win32.c
+@OS_FREEBSD_TRUE@@PT_DUMMY_TRUE@am__append_5 = sg_pt_dummy.c
+@OS_FREEBSD_TRUE@@PT_DUMMY_FALSE@am__append_6 = sg_pt_freebsd.c
+@OS_SOLARIS_TRUE@am__append_7 = sg_pt_solaris.c
+@OS_OSF_TRUE@am__append_8 = sg_pt_osf1.c
+@OS_NETBSD_TRUE@am__append_9 = sg_pt_dummy.c
+@OS_OPENBSD_TRUE@am__append_10 = sg_pt_dummy.c
subdir = lib
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -139,20 +143,27 @@ am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__libsgutils2_la_SOURCES_DIST = sg_lib.c sg_lib_data.c \
sg_cmds_basic.c sg_cmds_basic2.c sg_cmds_extra.c sg_cmds_mmc.c \
- sg_pt_common.c sg_pt_linux.c sg_io_linux.c sg_pt_linux_nvme.c \
- sg_pt_win32.c sg_pt_freebsd.c sg_pt_solaris.c sg_pt_osf1.c
-@OS_LINUX_TRUE@am__objects_1 = sg_pt_linux.lo sg_io_linux.lo \
-@OS_LINUX_TRUE@ sg_pt_linux_nvme.lo
-@OS_WIN32_MINGW_TRUE@am__objects_2 = sg_pt_win32.lo
-@OS_WIN32_CYGWIN_TRUE@am__objects_3 = sg_pt_win32.lo
-@OS_FREEBSD_TRUE@am__objects_4 = sg_pt_freebsd.lo
-@OS_SOLARIS_TRUE@am__objects_5 = sg_pt_solaris.lo
-@OS_OSF_TRUE@am__objects_6 = sg_pt_osf1.lo
+ sg_pt_common.c sg_pt_dummy.c sg_pt_linux.c sg_io_linux.c \
+ sg_pt_linux_nvme.c sg_pt_win32.c sg_pt_freebsd.c \
+ sg_pt_solaris.c sg_pt_osf1.c
+@OS_LINUX_TRUE@@PT_DUMMY_TRUE@am__objects_1 = sg_pt_dummy.lo
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__objects_2 = sg_pt_linux.lo \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_io_linux.lo \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_pt_linux_nvme.lo
+@OS_WIN32_MINGW_TRUE@am__objects_3 = sg_pt_win32.lo
+@OS_WIN32_CYGWIN_TRUE@am__objects_4 = sg_pt_win32.lo
+@OS_FREEBSD_TRUE@@PT_DUMMY_TRUE@am__objects_5 = sg_pt_dummy.lo
+@OS_FREEBSD_TRUE@@PT_DUMMY_FALSE@am__objects_6 = sg_pt_freebsd.lo
+@OS_SOLARIS_TRUE@am__objects_7 = sg_pt_solaris.lo
+@OS_OSF_TRUE@am__objects_8 = sg_pt_osf1.lo
+@OS_NETBSD_TRUE@am__objects_9 = sg_pt_dummy.lo
+@OS_OPENBSD_TRUE@am__objects_10 = sg_pt_dummy.lo
am_libsgutils2_la_OBJECTS = sg_lib.lo sg_lib_data.lo sg_cmds_basic.lo \
sg_cmds_basic2.lo sg_cmds_extra.lo sg_cmds_mmc.lo \
sg_pt_common.lo $(am__objects_1) $(am__objects_2) \
$(am__objects_3) $(am__objects_4) $(am__objects_5) \
- $(am__objects_6)
+ $(am__objects_6) $(am__objects_7) $(am__objects_8) \
+ $(am__objects_9) $(am__objects_10)
libsgutils2_la_OBJECTS = $(am_libsgutils2_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@@ -181,10 +192,10 @@ am__depfiles_remade = ./$(DEPDIR)/sg_cmds_basic.Plo \
./$(DEPDIR)/sg_cmds_basic2.Plo ./$(DEPDIR)/sg_cmds_extra.Plo \
./$(DEPDIR)/sg_cmds_mmc.Plo ./$(DEPDIR)/sg_io_linux.Plo \
./$(DEPDIR)/sg_lib.Plo ./$(DEPDIR)/sg_lib_data.Plo \
- ./$(DEPDIR)/sg_pt_common.Plo ./$(DEPDIR)/sg_pt_freebsd.Plo \
- ./$(DEPDIR)/sg_pt_linux.Plo ./$(DEPDIR)/sg_pt_linux_nvme.Plo \
- ./$(DEPDIR)/sg_pt_osf1.Plo ./$(DEPDIR)/sg_pt_solaris.Plo \
- ./$(DEPDIR)/sg_pt_win32.Plo
+ ./$(DEPDIR)/sg_pt_common.Plo ./$(DEPDIR)/sg_pt_dummy.Plo \
+ ./$(DEPDIR)/sg_pt_freebsd.Plo ./$(DEPDIR)/sg_pt_linux.Plo \
+ ./$(DEPDIR)/sg_pt_linux_nvme.Plo ./$(DEPDIR)/sg_pt_osf1.Plo \
+ ./$(DEPDIR)/sg_pt_solaris.Plo ./$(DEPDIR)/sg_pt_win32.Plo
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -355,7 +366,9 @@ top_srcdir = @top_srcdir@
libsgutils2_la_SOURCES = sg_lib.c sg_lib_data.c sg_cmds_basic.c \
sg_cmds_basic2.c sg_cmds_extra.c sg_cmds_mmc.c sg_pt_common.c \
$(am__append_1) $(am__append_2) $(am__append_3) \
- $(am__append_4) $(am__append_5) $(am__append_6)
+ $(am__append_4) $(am__append_5) $(am__append_6) \
+ $(am__append_7) $(am__append_8) $(am__append_9) \
+ $(am__append_10)
@DEBUG_FALSE@DBG_CFLAGS =
# This is active if --enable-debug given to ./configure
@@ -466,6 +479,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_lib.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_lib_data.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_common.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_dummy.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_freebsd.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_linux.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sg_pt_linux_nvme.Plo@am__quote@ # am--include-marker
@@ -642,6 +656,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/sg_lib.Plo
-rm -f ./$(DEPDIR)/sg_lib_data.Plo
-rm -f ./$(DEPDIR)/sg_pt_common.Plo
+ -rm -f ./$(DEPDIR)/sg_pt_dummy.Plo
-rm -f ./$(DEPDIR)/sg_pt_freebsd.Plo
-rm -f ./$(DEPDIR)/sg_pt_linux.Plo
-rm -f ./$(DEPDIR)/sg_pt_linux_nvme.Plo
@@ -701,6 +716,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/sg_lib.Plo
-rm -f ./$(DEPDIR)/sg_lib_data.Plo
-rm -f ./$(DEPDIR)/sg_pt_common.Plo
+ -rm -f ./$(DEPDIR)/sg_pt_dummy.Plo
-rm -f ./$(DEPDIR)/sg_pt_freebsd.Plo
-rm -f ./$(DEPDIR)/sg_pt_linux.Plo
-rm -f ./$(DEPDIR)/sg_pt_linux_nvme.Plo
diff --git a/lib/sg_pt_dummy.c b/lib/sg_pt_dummy.c
new file mode 100644
index 00000000..be84b503
--- /dev/null
+++ b/lib/sg_pt_dummy.c
@@ -0,0 +1,362 @@
+/*
+ * Copyright (c) 2021 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.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+
+#include "sg_pt.h"
+#include "sg_lib.h"
+#include "sg_pr2serr.h"
+
+/* Version 1.01 20210609 */
+
+/* Simply defines all the functions needed by the pt interface (see sg_pt.h).
+ * They do nothing. This allows decoding of hex files (e.g. with the --in=
+ * or --inhex= option) with utilities like sg_vpd and sg_logs. */
+
+struct sg_pt_dummy {
+ int dummy;
+};
+
+struct sg_pt_base {
+ struct sg_pt_dummy impl;
+};
+
+
+/* Returns >= 0 if successful. If error in Unix returns negated errno. */
+int
+scsi_pt_open_device(const char * device_name, bool read_only, int verbose)
+{
+ int oflags = 0 /* O_NONBLOCK*/ ;
+
+ oflags |= (read_only ? O_RDONLY : O_RDWR);
+ return scsi_pt_open_flags(device_name, oflags, verbose);
+}
+
+/* Similar to scsi_pt_open_device() but takes Unix style open flags OR-ed
+ * together. The 'flags' argument is ignored in OSF-1.
+ * Returns >= 0 if successful, otherwise returns negated errno. */
+int
+scsi_pt_open_flags(const char * device_name, int flags, int verbose)
+{
+ if (device_name) {}
+ if (flags) {}
+ if (verbose) {}
+ errno = EINVAL;
+ return -1;
+}
+
+/* Returns 0 if successful. If error in Unix returns negated errno. */
+int
+scsi_pt_close_device(int device_fd)
+{
+ if (device_fd) {}
+ return 0;
+}
+
+struct sg_pt_base *
+construct_scsi_pt_obj_with_fd(int device_fd, int verbose)
+{
+ struct sg_pt_dummy * ptp;
+
+ if (device_fd) {}
+ ptp = (struct sg_pt_dummy *)malloc(sizeof(struct sg_pt_dummy));
+ if (ptp) {
+ memset(ptp, 0, sizeof(struct sg_pt_dummy));
+ } else if (verbose)
+ pr2ws("%s: malloc() out of memory\n", __func__);
+ return (struct sg_pt_base *)ptp;
+}
+
+struct sg_pt_base *
+construct_scsi_pt_obj(void)
+{
+ return construct_scsi_pt_obj_with_fd(-1, 0);
+}
+
+void
+destruct_scsi_pt_obj(struct sg_pt_base * vp)
+{
+ struct sg_pt_dummy * ptp = &vp->impl;
+
+ if (ptp)
+ free(ptp);
+}
+
+void
+clear_scsi_pt_obj(struct sg_pt_base * vp)
+{
+ struct sg_pt_dummy * ptp = &vp->impl;
+
+ if (ptp) {
+ ptp->dummy = 0;
+ }
+}
+
+void
+partial_clear_scsi_pt_obj(struct sg_pt_base * vp)
+{
+ struct sg_pt_dummy * ptp = &vp->impl;
+
+ if (NULL == ptp)
+ return;
+ ptp->dummy = 0;
+}
+
+void
+set_scsi_pt_cdb(struct sg_pt_base * vp, const uint8_t * cdb,
+ int cdb_len)
+{
+ if (vp) {}
+ if (cdb) {}
+ if (cdb_len) {}
+}
+
+int
+get_scsi_pt_cdb_len(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 6;
+}
+
+uint8_t *
+get_scsi_pt_cdb_buf(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return NULL;
+}
+
+void
+set_scsi_pt_sense(struct sg_pt_base * vp, uint8_t * sense,
+ int max_sense_len)
+{
+ if (vp) {}
+ if (sense) {}
+ if (max_sense_len) {}
+}
+
+/* from device */
+void
+set_scsi_pt_data_in(struct sg_pt_base * vp, uint8_t * dxferp,
+ int dxfer_len)
+{
+ if (vp) {}
+ if (dxferp) {}
+ if (dxfer_len) {}
+}
+
+/* to device */
+void
+set_scsi_pt_data_out(struct sg_pt_base * vp, const uint8_t * dxferp,
+ int dxfer_len)
+{
+ if (vp) {}
+ if (dxferp) {}
+ if (dxfer_len) {}
+}
+
+void
+set_scsi_pt_packet_id(struct sg_pt_base * vp, int pack_id)
+{
+ if (vp) {}
+ if (pack_id) {}
+}
+
+void
+set_scsi_pt_tag(struct sg_pt_base * vp, uint64_t tag)
+{
+ if (vp) {}
+ if (tag) {}
+}
+
+void
+set_scsi_pt_task_management(struct sg_pt_base * vp, int tmf_code)
+{
+ if (vp) {}
+ if (tmf_code) {}
+}
+
+void
+set_scsi_pt_task_attr(struct sg_pt_base * vp, int attrib, int priority)
+{
+ if (vp) {}
+ if (attrib) {}
+ if (priority) {}
+}
+
+void
+set_scsi_pt_flags(struct sg_pt_base * vp, int flags)
+{
+ if (vp) {}
+ if (flags) {}
+}
+
+int
+do_scsi_pt(struct sg_pt_base * vp, int device_fd, int time_secs, int verbose)
+{
+ if (vp) {}
+ if (device_fd) {}
+ if (time_secs) {}
+ if (verbose) {}
+ return 0;
+}
+
+int
+get_scsi_pt_result_category(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+int
+get_scsi_pt_resid(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+void
+get_pt_req_lengths(const struct sg_pt_base * vp, int * req_dinp,
+ int * req_doutp)
+{
+ if (vp) {}
+ if (req_dinp) {}
+ if (req_doutp) {}
+}
+
+void
+get_pt_actual_lengths(const struct sg_pt_base * vp, int * act_dinp,
+ int * act_doutp)
+{
+ if (vp) {}
+ if (act_dinp) {}
+ if (act_doutp) {}
+}
+
+
+int
+get_scsi_pt_status_response(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+int
+get_scsi_pt_sense_len(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+uint8_t *
+get_scsi_pt_sense_buf(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return NULL;
+}
+
+int
+get_scsi_pt_duration_ms(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+/* If not available return 0 otherwise return number of nanoseconds that the
+ * lower layers (and hardware) took to execute the command just completed. */
+uint64_t
+get_pt_duration_ns(const struct sg_pt_base * vp __attribute__ ((unused)))
+{
+ return 0;
+}
+
+int
+get_scsi_pt_transport_err(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+int
+get_scsi_pt_os_err(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return 0;
+}
+
+bool
+pt_device_is_nvme(const struct sg_pt_base * vp)
+{
+ if (vp) {}
+ return false;
+}
+
+char *
+get_scsi_pt_transport_err_str(const struct sg_pt_base * vp, int max_b_len,
+ char * b)
+{
+ if (vp) {}
+ if (max_b_len) {}
+ if (b) {}
+ return NULL;
+}
+
+char *
+get_scsi_pt_os_err_str(const struct sg_pt_base * vp, int max_b_len, char * b)
+{
+ if (vp) {}
+ if (max_b_len) {}
+ if (b) {}
+ return NULL;
+}
+
+int
+do_nvm_pt(struct sg_pt_base * vp, int submq, int timeout_secs, int verbose)
+{
+ if (vp) { }
+ if (submq) { }
+ if (timeout_secs) { }
+ if (verbose) { }
+ return SCSI_PT_DO_NOT_SUPPORTED;
+}
+
+int
+check_pt_file_handle(int device_fd, const char * device_name, int vb)
+{
+ if (device_fd) {}
+ if (device_name) {}
+ if (vb) {}
+ return 0;
+}
+
+/* If a NVMe block device (which includes the NSID) handle is associated
+ * with 'vp', then its NSID is returned (values range from 0x1 to
+ * 0xffffffe). Otherwise 0 is returned. */
+uint32_t
+get_pt_nvme_nsid(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}
+
+uint32_t
+get_pt_result(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}
diff --git a/lib/sg_pt_osf1.c b/lib/sg_pt_osf1.c
index 99900fd3..3296e18b 100644
--- a/lib/sg_pt_osf1.c
+++ b/lib/sg_pt_osf1.c
@@ -650,3 +650,29 @@ do_nvm_pt(struct sg_pt_base * vp, int submq, int timeout_secs, int verbose)
if (verbose) { }
return SCSI_PT_DO_NOT_SUPPORTED;
}
+
+int
+check_pt_file_handle(int device_fd, const char * device_name, int vb)
+{
+ if (device_fd) {}
+ if (device_name) {}
+ if (vb) {}
+ return 0;
+}
+
+/* If a NVMe block device (which includes the NSID) handle is associated
+ * with 'vp', then its NSID is returned (values range from 0x1 to
+ * 0xffffffe). Otherwise 0 is returned. */
+uint32_t
+get_pt_nvme_nsid(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}
+
+uint32_t
+get_pt_result(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}
diff --git a/lib/sg_pt_solaris.c b/lib/sg_pt_solaris.c
index ec346ab4..2e5b430d 100644
--- a/lib/sg_pt_solaris.c
+++ b/lib/sg_pt_solaris.c
@@ -529,3 +529,22 @@ do_nvm_pt(struct sg_pt_base * vp, int submq, int timeout_secs, int verbose)
if (verbose) { }
return SCSI_PT_DO_NOT_SUPPORTED;
}
+
+int
+check_pt_file_handle(int device_fd, const char * device_name, int vb)
+{
+ if (device_fd) {}
+ if (device_name) {}
+ if (vb) {}
+ return 0;
+}
+
+/* If a NVMe block device (which includes the NSID) handle is associated
+ * with 'vp', then its NSID is returned (values range from 0x1 to
+ * 0xffffffe). Otherwise 0 is returned. */
+uint32_t
+get_pt_nvme_nsid(const struct sg_pt_base * vp)
+{
+ if (vp) { }
+ return 0;
+}
diff --git a/lib/sg_pt_win32.c b/lib/sg_pt_win32.c
index 62a69309..dab66cb0 100644
--- a/lib/sg_pt_win32.c
+++ b/lib/sg_pt_win32.c
@@ -1445,8 +1445,8 @@ pt_device_is_nvme(const struct sg_pt_base * vp)
}
/* If a NVMe block device (which includes the NSID) handle is associated
- * * with 'vp', then its NSID is returned (values range from 0x1 to
- * * 0xffffffe). Otherwise 0 is returned. */
+ * with 'vp', then its NSID is returned (values range from 0x1 to
+ * 0xffffffe). Otherwise 0 is returned. */
uint32_t
get_pt_nvme_nsid(const struct sg_pt_base * vp)
{
diff --git a/src/Makefile.am b/src/Makefile.am
index 47293fe5..1b0a44a2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,11 +15,13 @@ sg_scan_SOURCES =
if OS_LINUX
+if !PT_DUMMY
bin_PROGRAMS += \
sg_copy_results sg_dd sg_emc_trespass sg_map sg_map26 sg_rbuf \
sg_read sg_reset sg_scan sg_test_rwbuf sg_xcopy sginfo sgm_dd sgp_dd
sg_scan_SOURCES += sg_scan_linux.c
endif
+endif
if OS_WIN32_MINGW
diff --git a/src/Makefile.in b/src/Makefile.in
index cd146ae6..f0fffb05 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -111,11 +111,11 @@ bin_PROGRAMS = sg_bg_ctl$(EXEEXT) sg_compare_and_write$(EXEEXT) \
sg_write_long$(EXEEXT) sg_write_same$(EXEEXT) \
sg_write_verify$(EXEEXT) sg_write_x$(EXEEXT) sg_zone$(EXEEXT) \
$(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3)
-@OS_LINUX_TRUE@am__append_1 = \
-@OS_LINUX_TRUE@ sg_copy_results sg_dd sg_emc_trespass sg_map sg_map26 sg_rbuf \
-@OS_LINUX_TRUE@ sg_read sg_reset sg_scan sg_test_rwbuf sg_xcopy sginfo sgm_dd sgp_dd
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__append_1 = \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_copy_results sg_dd sg_emc_trespass sg_map sg_map26 sg_rbuf \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_read sg_reset sg_scan sg_test_rwbuf sg_xcopy sginfo sgm_dd sgp_dd
-@OS_LINUX_TRUE@am__append_2 = sg_scan_linux.c
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__append_2 = sg_scan_linux.c
@OS_WIN32_MINGW_TRUE@am__append_3 = sg_scan
@OS_WIN32_MINGW_TRUE@am__append_4 = sg_scan_win32.c
@OS_WIN32_CYGWIN_TRUE@am__append_5 = sg_scan
@@ -130,13 +130,20 @@ mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
-@OS_LINUX_TRUE@am__EXEEXT_1 = sg_copy_results$(EXEEXT) sg_dd$(EXEEXT) \
-@OS_LINUX_TRUE@ sg_emc_trespass$(EXEEXT) sg_map$(EXEEXT) \
-@OS_LINUX_TRUE@ sg_map26$(EXEEXT) sg_rbuf$(EXEEXT) \
-@OS_LINUX_TRUE@ sg_read$(EXEEXT) sg_reset$(EXEEXT) \
-@OS_LINUX_TRUE@ sg_scan$(EXEEXT) sg_test_rwbuf$(EXEEXT) \
-@OS_LINUX_TRUE@ sg_xcopy$(EXEEXT) sginfo$(EXEEXT) \
-@OS_LINUX_TRUE@ sgm_dd$(EXEEXT) sgp_dd$(EXEEXT)
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__EXEEXT_1 = \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_copy_results$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_dd$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_emc_trespass$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_map$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_map26$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_rbuf$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_read$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_reset$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_scan$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_test_rwbuf$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_xcopy$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sginfo$(EXEEXT) sgm_dd$(EXEEXT) \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sgp_dd$(EXEEXT)
@OS_WIN32_MINGW_TRUE@am__EXEEXT_2 = sg_scan$(EXEEXT)
@OS_WIN32_CYGWIN_TRUE@am__EXEEXT_3 = sg_scan$(EXEEXT)
am__installdirs = "$(DESTDIR)$(bindir)"
@@ -278,7 +285,8 @@ sg_sat_set_features_SOURCES = sg_sat_set_features.c
sg_sat_set_features_OBJECTS = sg_sat_set_features.$(OBJEXT)
sg_sat_set_features_DEPENDENCIES = ../lib/libsgutils2.la
am__sg_scan_SOURCES_DIST = sg_scan_linux.c sg_scan_win32.c
-@OS_LINUX_TRUE@am__objects_1 = sg_scan_linux.$(OBJEXT)
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@am__objects_1 = \
+@OS_LINUX_TRUE@@PT_DUMMY_FALSE@ sg_scan_linux.$(OBJEXT)
@OS_WIN32_MINGW_TRUE@am__objects_2 = sg_scan_win32.$(OBJEXT)
@OS_WIN32_CYGWIN_TRUE@am__objects_3 = sg_scan_win32.$(OBJEXT)
am_sg_scan_OBJECTS = $(am__objects_1) $(am__objects_2) \
diff --git a/src/sg_decode_sense.c b/src/sg_decode_sense.c
index a71de325..18b4ef6e 100644
--- a/src/sg_decode_sense.c
+++ b/src/sg_decode_sense.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2019 Douglas Gilbert.
+ * Copyright (c) 2010-2021 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.
@@ -30,7 +30,7 @@
#include "sg_unaligned.h"
-static const char * version_str = "1.21 20190602";
+static const char * version_str = "1.22 20210610";
#define MAX_SENSE_LEN 1024 /* max descriptor format actually: 255+8 */
@@ -347,7 +347,8 @@ main(int argc, char *argv[])
if (op->verbose > 2)
pr2serr("no_space str: %s\n", op->no_space_str);
cp = op->no_space_str;
- for (k = 0; isxdigit(cp[k]) && isxdigit(cp[k + 1]); k += 2) {
+ for (k = 0; isxdigit((uint8_t)cp[k]) &&
+ isxdigit((uint8_t)cp[k + 1]); k += 2) {
if (1 != sscanf(cp + k, "%2x", &ui)) {
pr2serr("bad no_space hex string: %s\n", cp);
return SG_LIB_SYNTAX_ERROR;
diff --git a/src/sg_inq.c b/src/sg_inq.c
index 6bbeb991..17c0730c 100644
--- a/src/sg_inq.c
+++ b/src/sg_inq.c
@@ -51,7 +51,7 @@
#include "sg_pt_nvme.h"
#endif
-static const char * version_str = "2.11 20210430"; /* spc6r05 */
+static const char * version_str = "2.12 20210610"; /* spc6r05 */
/* INQUIRY notes:
* It is recommended that the initial allocation length given to a
@@ -4130,7 +4130,7 @@ main(int argc, char * argv[])
"implies a page\n");
return SG_LIB_CONTRADICT;
}
- if (isalpha(op->page_arg[0])) {
+ if (isalpha((uint8_t)op->page_arg[0])) {
vnp = sdp_find_vpd_by_acron(op->page_arg);
if (NULL == vnp) {
#ifdef SG_SCSI_STRINGS
diff --git a/src/sg_logs.c b/src/sg_logs.c
index 409d0614..91a46181 100644
--- a/src/sg_logs.c
+++ b/src/sg_logs.c
@@ -36,7 +36,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.82 20210503"; /* spc6r01 + sbc4r17 */
+static const char * version_str = "1.83 20210610"; /* spc6r05 + sbc5r01 */
#define MX_ALLOC_LEN (0xfffc)
#define SHORT_RESP_LEN 128
@@ -800,7 +800,7 @@ find_vpn_by_acron(const char * vp_ap)
for (vpp = vp_arr; vpp->acron; ++vpp) {
len = strlen(vpp->acron);
for (k = 0; k < len; ++k) {
- if (tolower(vp_ap[k]) != vpp->acron[k])
+ if (tolower((uint8_t)vp_ap[k]) != (uint8_t)vpp->acron[k])
break;
}
if (k < len)
@@ -1216,7 +1216,7 @@ old_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
const struct log_elem * lep;
char b[80];
- if (isalpha(ccp[0])) {
+ if (isalpha((uint8_t)ccp[0])) {
if (strlen(ccp) >= (sizeof(b) - 1)) {
pr2serr("argument to '-p=' is too long\n");
return SG_LIB_SYNTAX_ERROR;
@@ -6773,7 +6773,7 @@ decode_pg_arg(struct opts_t * op)
char * cp;
char b[80];
- if (isalpha(op->pg_arg[0])) {
+ if (isalpha((uint8_t)op->pg_arg[0])) {
if (strlen(op->pg_arg) >= (sizeof(b) - 1)) {
pr2serr("argument to '--page=' is too long\n");
return SG_LIB_SYNTAX_ERROR;
@@ -6876,7 +6876,7 @@ main(int argc, char * argv[])
}
vb = op->verbose;
if (op->vend_prod) {
- if (isdigit(op->vend_prod[0]))
+ if (isdigit((uint8_t)op->vend_prod[0]))
k = sg_get_num_nomult(op->vend_prod);
else
k = find_vpn_by_acron(op->vend_prod);
diff --git a/src/sg_luns.c b/src/sg_luns.c
index 62a2e6ca..c538956c 100644
--- a/src/sg_luns.c
+++ b/src/sg_luns.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2020 Douglas Gilbert.
+ * Copyright (c) 2004-2021 Douglas Gilbert.
* All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the BSD_LICENSE file.
@@ -34,7 +34,7 @@
* and decodes the response.
*/
-static const char * version_str = "1.45 20200708"; /* spc6r02 */
+static const char * version_str = "1.46 20210610"; /* spc6r05 */
#define MAX_RLUNS_BUFF_LEN (1024 * 1024)
#define DEF_RLUNS_BUFF_LEN (1024 * 8)
@@ -503,7 +503,7 @@ main(int argc, char * argv[])
if ('L' == toupper(cp[0])) {
uint64_t ull;
- if (('0' == cp[1]) && ('X' == toupper(cp[2])))
+ if (('0' == cp[1]) && ('X' == toupper((uint8_t)cp[2])))
k = sscanf(cp + 3, " %" SCNx64, &ull);
else
k = sscanf(cp + 1, " %" SCNu64, &ull);
diff --git a/src/sg_modes.c b/src/sg_modes.c
index 3e6c9b85..16ea142c 100644
--- a/src/sg_modes.c
+++ b/src/sg_modes.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2020 D. Gilbert
+ * Copyright (C) 2000-2021 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)
@@ -32,7 +32,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.72 20200930";
+static const char * version_str = "1.73 20210610";
#define DEF_ALLOC_LEN (1024 * 4)
#define DEF_6_ALLOC_LEN 252
@@ -507,7 +507,7 @@ new_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
op->opt_new = false;
return 0;
case 'p':
- if (isalpha(optarg[0])) {
+ if (isalpha((uint8_t)optarg[0])) {
const struct page_code_desc * pcdp;
op->page_acron = optarg;
diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c
index 57b92968..4abe9f17 100644
--- a/src/sg_opcodes.c
+++ b/src/sg_opcodes.c
@@ -33,7 +33,7 @@
#include "sg_pt.h"
-static const char * version_str = "0.69 20210319"; /* spc6r05 */
+static const char * version_str = "0.70 20210610"; /* spc6r05 */
#define SENSE_BUFF_LEN 64 /* Arbitrary, could be larger */
@@ -382,7 +382,7 @@ new_parse_cmd_line(struct opts_t * op, int argc, char * argv[])
return 0;
case 'p':
n = -2;
- if (isdigit(optarg[0]))
+ if (isdigit((uint8_t)optarg[0]))
n = sg_get_num(optarg);
else if ((2 == strlen(optarg)) && (0 == strcmp("-1", optarg)))
n = -1;
diff --git a/src/sg_persist.c b/src/sg_persist.c
index 59067f2a..e779fe41 100644
--- a/src/sg_persist.c
+++ b/src/sg_persist.c
@@ -1,5 +1,5 @@
/* A utility program originally written for the Linux OS SCSI subsystem.
- * Copyright (C) 2004-2019 D. Gilbert
+ * Copyright (C) 2004-2021 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)
@@ -35,7 +35,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "0.67 20190913";
+static const char * version_str = "0.68 20210610";
#define PRIN_RKEY_SA 0x0
@@ -779,7 +779,7 @@ decode_file_tids(const char * fnp, struct opts_t * op)
continue;
}
if (carry_over[0]) {
- if (isxdigit(line[0])) {
+ if (isxdigit((uint8_t)line[0])) {
carry_over[1] = line[0];
carry_over[2] = '\0';
if (1 == sscanf(carry_over, "%x", &h))
@@ -826,7 +826,7 @@ decode_file_tids(const char * fnp, struct opts_t * op)
pr2serr("%s: array length exceeded\n", __func__);
goto bad;
}
- op->transportid_arr[off + k] = h; /* keep code checker happy */
+ op->transportid_arr[off + k] = h;/* keep code checker happy */
lcp = strpbrk(lcp, " ,\t");
if (NULL == lcp)
break;
diff --git a/src/sg_read_attr.c b/src/sg_read_attr.c
index bf27da1e..3f5d6528 100644
--- a/src/sg_read_attr.c
+++ b/src/sg_read_attr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2019 Douglas Gilbert.
+ * Copyright (c) 2016-2021 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.
@@ -39,7 +39,7 @@
* and decodes the response. Based on spc5r08.pdf
*/
-static const char * version_str = "1.13 20191220";
+static const char * version_str = "1.14 20210610";
#define MAX_RATTR_BUFF_LEN (1024 * 1024)
#define DEF_RATTR_BUFF_LEN (1024 * 8)
@@ -323,7 +323,7 @@ find_sa_acron(const char * cp)
for (mp = cp, k = 0; *mp; ++mp, ++k) {
if (0 == anvp->acron[k])
return anvp->val;
- if (tolower(*mp) != anvp->acron[k])
+ if (tolower((uint8_t)*mp) != (uint8_t)anvp->acron[k])
break;
}
if ((0 == *mp) && (0 == anvp->acron[k]))
@@ -827,7 +827,7 @@ main(int argc, char * argv[])
op->o_readonly = true;
break;
case 's':
- if (isdigit(*optarg)) {
+ if (isdigit((uint8_t)*optarg)) {
op->sa = sg_get_num(optarg);
if ((op->sa < 0) || (op->sa > 63)) {
pr2serr("bad argument to '--sa=SA', expect 0 to 63\n");
diff --git a/src/sg_read_buffer.c b/src/sg_read_buffer.c
index 4eb5da4a..33aa1673 100644
--- a/src/sg_read_buffer.c
+++ b/src/sg_read_buffer.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2019 Luben Tuikov and Douglas Gilbert.
+ * Copyright (c) 2006-2021 Luben Tuikov and 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.
@@ -39,7 +39,7 @@
* device.
*/
-static const char * version_str = "1.30 20191220"; /* spc5r22 */
+static const char * version_str = "1.31 20210608"; /* spc6r05 */
#ifndef SG_READ_BUFFER_10_CMD
@@ -410,7 +410,8 @@ main(int argc, char * argv[])
bool do_raw = false;
bool verbose_given = false;
bool version_given = false;
- int res, c, len, k, inhex_len;
+ int res, c, len, k;
+ int inhex_len = 0;
int sg_fd = -1;
int do_help = 0;
int do_hex = 0;
@@ -476,7 +477,7 @@ main(int argc, char * argv[])
do_long = true;
break;
case 'm':
- if (isdigit(*optarg)) {
+ if (isdigit((uint8_t)*optarg)) {
rb_mode = sg_get_num(optarg);
if ((rb_mode < 0) || (rb_mode > 31)) {
pr2serr("argument to '--mode' should be in the range 0 "
@@ -574,8 +575,6 @@ main(int argc, char * argv[])
return 0;
}
- rb_len = 0;
- inhex_len = 0;
if (device_name && fname) {
pr2serr("Confused: both DEVICE (%s) and --inhex= option given. One "
"only please\n", device_name);
diff --git a/src/sg_requests.c b/src/sg_requests.c
index fbb56cab..f27c60d6 100644
--- a/src/sg_requests.c
+++ b/src/sg_requests.c
@@ -34,7 +34,7 @@
* This program issues the SCSI command REQUEST SENSE to the given SCSI device.
*/
-static const char * version_str = "1.36 20210329";
+static const char * version_str = "1.36 20210610";
#define MAX_REQS_RESP_LEN 255
#define DEF_REQS_RESP_LEN 252
@@ -320,11 +320,11 @@ main(int argc, char * argv[])
n = 0;
} else {
if (verbose && (0 == k)) {
- char b[128];
+ char bb[128];
pr2serr(" cdb: %s\n",
sg_get_command_str(rs_cdb, REQUEST_SENSE_CMDLEN,
- true, sizeof(b), b));
+ true, sizeof(bb), bb));
}
rs = do_scsi_pt(ptvp, -1, DEF_PT_TIMEOUT, verbose);
n = sg_cmds_process_resp(ptvp, "Request sense", rs, (0 == k),
@@ -413,11 +413,11 @@ main(int argc, char * argv[])
n = 0;
} else {
if (verbose && (0 == k)) {
- char b[128];
+ char bb[128];
pr2serr(" cdb: %s\n",
sg_get_command_str(rs_cdb, REQUEST_SENSE_CMDLEN,
- true, sizeof(b), b));
+ true, sizeof(bb), bb));
}
rs = do_scsi_pt(ptvp, -1, DEF_PT_TIMEOUT, verbose);
n = sg_cmds_process_resp(ptvp, "Request sense", rs, (0 == k),
@@ -468,10 +468,10 @@ main(int argc, char * argv[])
most_recent_skey = ssh.sense_key;
}
if (not_raw_hex && ((1 == num_rs) || verbose)) {
- char b[144];
+ char bb[144];
sg_get_sense_str(NULL, rsBuff, act_din_len,
- false, sizeof(b), b);
+ false, sizeof(bb), bb);
pr2serr("data-in decoded as sense:\n%s\n", b);
}
}
diff --git a/src/sg_senddiag.c b/src/sg_senddiag.c
index 38d4e40d..6539d79d 100644
--- a/src/sg_senddiag.c
+++ b/src/sg_senddiag.c
@@ -1,6 +1,6 @@
/*
* A utility program originally written for the Linux OS SCSI subsystem
- * Copyright (C) 2003-2018 D. Gilbert
+ * Copyright (C) 2003-2021 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)
@@ -34,7 +34,7 @@
#include "sg_pr2serr.h"
-static const char * version_str = "0.63 20180628";
+static const char * version_str = "0.64 20210610";
#define ME "sg_senddiag: "
@@ -511,7 +511,7 @@ build_diag_page(const char * inp, uint8_t * mp_arr, int * mp_arr_len,
continue;
}
if (carry_over[0]) {
- if (isxdigit(line[0])) {
+ if (isxdigit((uint8_t)line[0])) {
carry_over[1] = line[0];
carry_over[2] = '\0';
if (1 == sscanf(carry_over, "%x", &h))
diff --git a/src/sg_ses.c b/src/sg_ses.c
index 7280130d..b9ac2e43 100644
--- a/src/sg_ses.c
+++ b/src/sg_ses.c
@@ -38,7 +38,7 @@
* commands tailored for SES (enclosure) devices.
*/
-static const char * version_str = "2.49 20210503"; /* ses4r04 */
+static const char * version_str = "2.50 20210610"; /* ses4r04 */
#define MX_ALLOC_LEN ((64 * 1024) - 4) /* max allowable for big enclosures */
#define MX_ELEM_HDR 1024
@@ -1046,7 +1046,7 @@ parse_index(struct opts_t *op)
}
op->ind_th = 0;
op->ind_indiv = -1;
- } else if (isdigit(b[0])) {
+ } else if (isdigit((uint8_t)b[0])) {
n = sg_get_num_nomult(b);
if ((n < 0) || (n > 255)) {
pr2serr("bad numeric argument to '--index', expect number from 0 "
@@ -1157,7 +1157,7 @@ parse_cmd_line(struct opts_t *op, int argc, char *argv[])
break;
case 'A': /* SAS address, assumed to be hex */
cp = optarg;
- if ((strlen(optarg) > 2) && ('X' == toupper(optarg[1])))
+ if ((strlen(optarg) > 2) && ('X' == toupper((uint8_t)optarg[1])))
cp = optarg + 2;
if (1 != sscanf(cp, "%" SCNx64 "", &saddr)) {
pr2serr("bad argument to '--sas-addr=SA'\n");
@@ -1289,7 +1289,7 @@ parse_cmd_line(struct opts_t *op, int argc, char *argv[])
op->mask_ign = true;
break;
case 'p':
- if (isdigit(optarg[0])) {
+ if (isdigit((uint8_t)optarg[0])) {
op->page_code = sg_get_num_nomult(optarg);
if ((op->page_code < 0) || (op->page_code > 255)) {
pr2serr("bad argument to '--page=PG' (0 to 255 "
@@ -1587,18 +1587,18 @@ parse_cgs_str(char * buff, struct tuple_acronym_val * tavp)
}
}
}
- if (isalpha(buff[0]))
+ if (isalpha((uint8_t)buff[0]))
tavp->acron = buff;
else {
colp = strchr(buff, ':');
if ((NULL == colp) || (buff == colp))
return -1;
*colp = '\0';
- if (('0' == buff[0]) && ('X' == toupper(buff[1]))) {
+ if (('0' == buff[0]) && ('X' == toupper((uint8_t)buff[1]))) {
if (1 != sscanf(buff + 2, "%x", &ui))
return -1;
tavp->start_byte = ui;
- } else if ('H' == toupper(*(colp - 1))) {
+ } else if ('H' == toupper((uint8_t)*(colp - 1))) {
if (1 != sscanf(buff, "%x", &ui))
return -1;
tavp->start_byte = ui;
@@ -4011,7 +4011,7 @@ read_hex(const char * inp, uint8_t * arr, int mx_arr_len, int * arr_len,
continue;
}
if (carry_over[0]) {
- if (isxdigit(line[0])) {
+ if (isxdigit((uint8_t)line[0])) {
carry_over[1] = line[0];
carry_over[2] = '\0';
if (1 == sscanf(carry_over, "%x", &h))
diff --git a/src/sg_ses_microcode.c b/src/sg_ses_microcode.c
index 36f3659e..a00b6d51 100644
--- a/src/sg_ses_microcode.c
+++ b/src/sg_ses_microcode.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Douglas Gilbert.
+ * Copyright (c) 2014-2021 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.
@@ -45,7 +45,7 @@
* RESULTS commands in order to send microcode to the given SES device.
*/
-static const char * version_str = "1.18 20190513"; /* ses4r02 */
+static const char * version_str = "1.19 20210610"; /* ses4r02 */
#define ME "sg_ses_microcode: "
#define MAX_XFER_LEN (128 * 1024 * 1024)
@@ -557,7 +557,7 @@ main(int argc, char * argv[])
op->mc_len_given = true;
break;
case 'm':
- if (isdigit(*optarg)) {
+ if (isdigit((uint8_t)*optarg)) {
op->mc_mode = sg_get_num_nomult(optarg);
if ((op->mc_mode < 0) || (op->mc_mode > 255)) {
pr2serr("argument to '--mode' should be in the range 0 "
diff --git a/src/sg_stpg.c b/src/sg_stpg.c
index 6cb78932..e57b13c5 100644
--- a/src/sg_stpg.c
+++ b/src/sg_stpg.c
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2004-2018 Hannes Reinecke, Christophe Varoqui, Douglas Gilbert
+ * Copyright (c) 2004-2021 Hannes Reinecke, Christophe Varoqui, Douglas Gilbert
* All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the BSD_LICENSE file.
@@ -34,7 +34,7 @@
* to the given SCSI device.
*/
-static const char * version_str = "1.19 20180628";
+static const char * version_str = "1.20 20210610";
#define TGT_GRP_BUFF_LEN 1024
#define MX_ALLOC_LEN (0xc000 + 0x80)
@@ -357,13 +357,13 @@ build_state_arr(const char * inp, int * state_arr, int * state_arr_len,
}
for (k = 0; k < max_arr_len; ++k) {
try_num = true;
- if (isalpha(*lcp)) {
+ if (isalpha((uint8_t)*lcp)) {
try_num = false;
- switch (toupper(*lcp)) {
+ switch (toupper((uint8_t)*lcp)) {
case 'A':
- if ('N' == toupper(*(lcp + 1)))
+ if ('N' == toupper((uint8_t)*(lcp + 1)))
state_arr[k] = 1;
- else if ('O' == toupper(*(lcp + 1)))
+ else if ('O' == toupper((uint8_t)*(lcp + 1)))
state_arr[k] = 0;
else
try_num = true;
diff --git a/src/sg_vpd.c b/src/sg_vpd.c
index 4e538d6f..d5b3c3eb 100644
--- a/src/sg_vpd.c
+++ b/src/sg_vpd.c
@@ -40,7 +40,7 @@
*/
-static const char * version_str = "1.64 20210601"; /* spc6r05 + sbc4r22 */
+static const char * version_str = "1.64 20210610"; /* spc6r05 + sbc5r01 */
/* standard VPD pages, in ascending page number order */
#define VPD_SUPPORTED_VPDS 0x0
@@ -3898,7 +3898,7 @@ main(int argc, char * argv[])
pr2serr("Device name %s ignored when --enumerate given\n",
op->device_name);
if (op->vend_prod) {
- if (isdigit(op->vend_prod[0])) {
+ if (isdigit((uint8_t)op->vend_prod[0])) {
op->vend_prod_num = sg_get_num_nomult(op->vend_prod);
if ((op->vend_prod_num < 0) || (op->vend_prod_num > 10)) {
pr2serr("Bad vendor/product number after '--vendor=' "
@@ -3920,7 +3920,7 @@ main(int argc, char * argv[])
if ((0 == strcmp("-1", op->page_str)) ||
(0 == strcmp("-2", op->page_str)))
op->vpd_pn = VPD_NOPE_WANT_STD_INQ;
- else if (isdigit(op->page_str[0])) {
+ else if (isdigit((uint8_t)op->page_str[0])) {
op->vpd_pn = sg_get_num_nomult(op->page_str);
if ((op->vpd_pn < 0) || (op->vpd_pn > 255)) {
pr2serr("Bad page code value after '-p' option\n");
@@ -3948,7 +3948,7 @@ main(int argc, char * argv[])
if ((0 == strcmp("-1", op->page_str)) ||
(0 == strcmp("-2", op->page_str)))
op->vpd_pn = VPD_NOPE_WANT_STD_INQ;
- else if (isalpha(op->page_str[0])) {
+ else if (isalpha((uint8_t)op->page_str[0])) {
vnp = sdp_find_vpd_by_acron(op->page_str);
if (NULL == vnp) {
vnp = svpd_find_vendor_by_acron(op->page_str);
@@ -3977,7 +3977,7 @@ main(int argc, char * argv[])
return SG_LIB_SYNTAX_ERROR;
}
if (cp) {
- if (isdigit(*(cp + 1)))
+ if (isdigit((uint8_t)*(cp + 1)))
op->vend_prod_num = sg_get_num_nomult(cp + 1);
else
op->vend_prod_num = svpd_find_vp_num_by_acron(cp + 1);
@@ -3990,7 +3990,7 @@ main(int argc, char * argv[])
}
subvalue = op->vend_prod_num;
} else if (op->vend_prod) {
- if (isdigit(op->vend_prod[0]))
+ if (isdigit((uint8_t)op->vend_prod[0]))
op->vend_prod_num = sg_get_num_nomult(op->vend_prod);
else
op->vend_prod_num =
@@ -4005,7 +4005,7 @@ main(int argc, char * argv[])
}
}
} else if (op->vend_prod) {
- if (isdigit(op->vend_prod[0]))
+ if (isdigit((uint8_t)op->vend_prod[0]))
op->vend_prod_num = sg_get_num_nomult(op->vend_prod);
else
op->vend_prod_num = svpd_find_vp_num_by_acron(op->vend_prod);
diff --git a/src/sg_wr_mode.c b/src/sg_wr_mode.c
index 9db253b3..2a10fb7c 100644
--- a/src/sg_wr_mode.c
+++ b/src/sg_wr_mode.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2018 Douglas Gilbert.
+ * Copyright (c) 2004-2021 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.
@@ -32,7 +32,7 @@
* mode page on the given device.
*/
-static const char * version_str = "1.26 20180628";
+static const char * version_str = "1.27 20210610";
#define ME "sg_wr_mode: "
@@ -151,7 +151,7 @@ build_mode_page(const char * inp, uint8_t * mp_arr, int * mp_arr_len,
continue;
}
if (carry_over[0]) {
- if (isxdigit(line[0])) {
+ if (isxdigit((uint8_t)line[0])) {
carry_over[1] = line[0];
carry_over[2] = '\0';
if (1 == sscanf(carry_over, "%x", &h))
diff --git a/src/sg_write_buffer.c b/src/sg_write_buffer.c
index 37dcc295..2b84323a 100644
--- a/src/sg_write_buffer.c
+++ b/src/sg_write_buffer.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018 Luben Tuikov and Douglas Gilbert.
+ * Copyright (c) 2006-2021 Luben Tuikov and 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.
@@ -40,7 +40,7 @@
* This utility issues the SCSI WRITE BUFFER command to the given device.
*/
-static const char * version_str = "1.29 20181112"; /* spc5r19 */
+static const char * version_str = "1.30 20210610"; /* spc6r05 */
#define ME "sg_write_buffer: "
#define DEF_XFER_LEN (8 * 1024 * 1024)
@@ -268,7 +268,7 @@ main(int argc, char * argv[])
wb_len_given = true;
break;
case 'm':
- if (isdigit(*optarg)) {
+ if (isdigit((uint8_t)*optarg)) {
wb_mode = sg_get_num(optarg);
if ((wb_mode < 0) || (wb_mode > 31)) {
pr2serr("argument to '--mode' should be in the range 0 "
diff --git a/src/sg_write_x.c b/src/sg_write_x.c
index 40edc352..2eed844b 100644
--- a/src/sg_write_x.c
+++ b/src/sg_write_x.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2020 Douglas Gilbert.
+ * Copyright (c) 2017-2021 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.
@@ -38,7 +38,7 @@
#include "sg_unaligned.h"
#include "sg_pr2serr.h"
-static const char * version_str = "1.24 20200429";
+static const char * version_str = "1.25 20210610";
/* Protection Information refers to 8 bytes of extra information usually
* associated with each logical block and is often abbreviated to PI while
@@ -521,7 +521,7 @@ all_ascii_f_s(const char * cp, int num_of_f_chars)
if (('0' == cp[0]) && (('x' == cp[1]) || ('X' == cp[1])))
cp += 2;
for ( ; num_of_f_chars >= 0 ; --num_of_f_chars, ++cp) {
- if ('F' != toupper(*cp))
+ if ('F' != toupper((uint8_t)*cp))
return false;
}
return true;
@@ -1375,8 +1375,8 @@ do_write_x(int sg_fd, const void * dataoutp, int dout_len,
ret = sense_cat;
break;
case SG_LIB_CAT_ILLEGAL_REQ:
- if (vb)
- sg_print_command_len(x_cdb, cdb_len);
+ if (vb)
+ sg_print_command_len(x_cdb, cdb_len);
ret = sense_cat;
break;
default:
diff --git a/testing/sgh_dd.cpp b/testing/sgh_dd.cpp
index 57158892..14b42824 100644
--- a/testing/sgh_dd.cpp
+++ b/testing/sgh_dd.cpp
@@ -36,7 +36,7 @@
* renamed [20181221]
*/
-static const char * version_str = "2.09 20210605";
+static const char * version_str = "2.09 20210609";
#define _XOPEN_SOURCE 600
#ifndef _GNU_SOURCE
@@ -160,9 +160,10 @@ using namespace std;
#define FT_DEV_NULL 8 /* either "/dev/null" or "." as filename */
#define FT_ST 16 /* filetype is st char device (tape) */
#define FT_BLOCK 32 /* filetype is a block device */
-#define FT_RANDOM_0_FF 64 /* iflag=00, iflag=ff and iflag=random
+#define FT_FIFO 64 /* fifo (named or unnamed pipe (stdout)) */
+#define FT_RANDOM_0_FF 128 /* iflag=00, iflag=ff and iflag=random
override if=IFILE */
-#define FT_ERROR 128 /* couldn't "stat" file */
+#define FT_ERROR 256 /* couldn't "stat" file */
#define DEV_NULL_MINOR_NUM 3
@@ -221,6 +222,7 @@ struct global_collection
atomic<int64_t> in_rem_count; /* | count of remaining in blocks */
atomic<int> in_partial; /* | */
atomic<bool> in_stop; /* | */
+ off_t in_st_size; /* Only for FT_OTHER (regular) file */
pthread_mutex_t in_mutex; /* -/ */
int nmrqs; /* Number of multi-reqs for sg v4 */
int outfd;
@@ -237,6 +239,7 @@ struct global_collection
atomic<int64_t> out_rem_count; /* | count of remaining out blocks */
atomic<int> out_partial; /* | */
atomic<bool> out_stop; /* | */
+ off_t out_st_size; /* Only for FT_OTHER (regular) file */
pthread_mutex_t out_mutex; /* | */
pthread_cond_t out_sync_cv; /* | hold writes until "in order" */
pthread_mutex_t out2_mutex;
@@ -879,6 +882,35 @@ tsafe_strerror(int code, char * ebp)
static int
+dd_filetype(const char * filename, off_t & st_size)
+{
+ struct stat st;
+ size_t len = strlen(filename);
+
+ if ((1 == len) && ('.' == filename[0]))
+ return FT_DEV_NULL;
+ if (stat(filename, &st) < 0)
+ return FT_ERROR;
+ if (S_ISCHR(st.st_mode)) {
+ if ((MEM_MAJOR == major(st.st_rdev)) &&
+ (DEV_NULL_MINOR_NUM == minor(st.st_rdev)))
+ return FT_DEV_NULL;
+ if (RAW_MAJOR == major(st.st_rdev))
+ return FT_RAW;
+ if (SCSI_GENERIC_MAJOR == major(st.st_rdev))
+ return FT_SG;
+ if (SCSI_TAPE_MAJOR == major(st.st_rdev))
+ return FT_ST;
+ } else if (S_ISBLK(st.st_mode))
+ return FT_BLOCK;
+ else if (S_ISFIFO(st.st_mode))
+ return FT_FIFO;
+ st_size = st.st_size;
+ return FT_OTHER;
+}
+
+#if 0
+static int
dd_filetype(const char * filename)
{
struct stat st;
@@ -902,6 +934,7 @@ dd_filetype(const char * filename)
return FT_BLOCK;
return FT_OTHER;
}
+#endif
static void
usage(int pg_num)
@@ -2418,7 +2451,6 @@ process_mrq_response(Rq_elem * rep, const struct sg_io_v4 * ctl_v4p,
}
}
if (slen > 0) {
-pr2serr(">>>>>>>>>>>> %s: slen=%d\n", __func__, slen);
struct sg_scsi_sense_hdr ssh;
const uint8_t *sbp = (const uint8_t *)
(sb_in_co ? ctl_v4p->response : a_v4p->response);
@@ -3517,7 +3549,6 @@ do_v4:
h4p->info = 0;
h4p->din_resid = 0;
}
-pr2serr(">>>>> %s: h4p->response: %sNULL, max_slen=%d\n", __func__, h4p->response ? "non-" : "", h4p->max_response_len);
while (((res = ioctl(fd, SG_IORECEIVE, h4p)) < 0) &&
((EINTR == errno) || (EAGAIN == errno) || (EBUSY == errno))) {
if (EAGAIN == errno) {
@@ -3539,11 +3570,8 @@ pr2serr(">>>>> %s: h4p->response: %sNULL, max_slen=%d\n", __func__, h4p->respons
perror("finishing io [SG_IORECEIVE] on sg device, error");
return -1;
}
-pr2serr(">>>>> %s: h4p->response_len=%d\n", __func__, h4p->response_len);
- if (mout_if && (0 == h4p->info) && (0 == h4p->din_resid)) {
-pr2serr("%s: META_OUT_IF set plus info and resid are zero, skip\n", __func__);
+ if (mout_if && (0 == h4p->info) && (0 == h4p->din_resid))
goto all_good;
- }
if (rep != (Rq_elem *)h4p->usr_ptr)
err_exit(0, "sg_finish_io: bad usr_ptr, request-response mismatch\n");
res = sg_err_category_new(h4p->device_status, h4p->transport_status,
@@ -4470,7 +4498,7 @@ main(int argc, char * argv[])
clp->infp = ccp;
clp->infd = -1;
} else if (inf[0] && ('-' != inf[0])) {
- clp->in_type = dd_filetype(inf);
+ clp->in_type = dd_filetype(inf, clp->in_st_size);
if (FT_ERROR == clp->in_type) {
pr2serr("%sunable to access %s\n", my_name, inf);
@@ -4524,7 +4552,7 @@ main(int argc, char * argv[])
if (outf[0])
clp->ofile_given = true;
if (outf[0] && ('-' != outf[0])) {
- clp->out_type = dd_filetype(outf);
+ clp->out_type = dd_filetype(outf, clp->out_st_size);
if ((FT_SG != clp->out_type) && clp->verify) {
pr2serr("%s --verify only supported by sg OFILEs\n", my_name);
@@ -4598,8 +4626,9 @@ main(int argc, char * argv[])
if (out2f[0])
clp->ofile2_given = true;
if (out2f[0] && ('-' != out2f[0])) {
- clp->out2_type = dd_filetype(out2f);
+ off_t out2_st_size;
+ clp->out2_type = dd_filetype(out2f, out2_st_size);
if (FT_ST == clp->out2_type) {
pr2serr("%sunable to use scsi tape device %s\n", my_name, out2f);
return SG_LIB_FILE_ERROR;
@@ -4704,7 +4733,8 @@ main(int argc, char * argv[])
clp->unbalanced_mrq = true;
}
if (outregf[0]) {
- int ftyp = dd_filetype(outregf);
+ off_t outrf_st_size;
+ int ftyp = dd_filetype(outregf, outrf_st_size);
clp->outreg_type = ftyp;
if (! ((FT_OTHER == ftyp) || (FT_ERROR == ftyp) ||
@@ -4767,6 +4797,13 @@ main(int argc, char * argv[])
"device=%d\n", inf, clp->bs, in_sect_sz);
in_num_sect = -1;
}
+ } else if (FT_OTHER == clp->in_type) {
+ in_num_sect = clp->in_st_size / clp->bs;
+ if (clp->in_st_size % clp->bs) {
+ ++in_num_sect;
+ pr2serr("Warning: the file size of %s is not a multiple of BS "
+ "[%d]\n", inf, clp->bs);
+ }
}
if (in_num_sect > clp->skip)
in_num_sect -= clp->skip;
@@ -4805,6 +4842,13 @@ main(int argc, char * argv[])
"device=%d\n", outf, clp->bs, out_sect_sz);
out_num_sect = -1;
}
+ } else if (FT_OTHER == clp->out_type) {
+ out_num_sect = clp->out_st_size / clp->bs;
+ if (clp->out_st_size % clp->bs) {
+ ++out_num_sect;
+ pr2serr("Warning: the file size of %s is not a multiple of BS "
+ "[%d]\n", outf, clp->bs);
+ }
}
if (out_num_sect > clp->seek)
out_num_sect -= clp->seek;