aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:20:52 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:20:52 +0000
commit68f4f8dd3682a586c2b082b115c1e4166a3146dd (patch)
treece060fd9dfffd4d9ef72db58c73632a6ed659fcf /examples
parent3e7335214bdf0173b615311b1f0c5f8297ff2f46 (diff)
downloadsg3_utils-68f4f8dd3682a586c2b082b115c1e4166a3146dd.tar.gz
Load sg3_utils-1.19 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@65 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile21
-rw-r--r--examples/Makefile.freebsd61
-rw-r--r--examples/sg_excl.c2
-rw-r--r--examples/sg_include.h56
l---------examples/sg_io_linux.h1
-rw-r--r--examples/sg_iovec_tst.c2
l---------examples/sg_linux_inc.h1
-rwxr-xr-xexamples/sg_persist_tst.sh28
l---------examples/sg_pt.h1
-rw-r--r--examples/sg_sense_test.c19
-rw-r--r--examples/sg_simple1.c2
-rw-r--r--examples/sg_simple16.c2
-rw-r--r--examples/sg_simple2.c2
-rw-r--r--examples/sg_simple3.c2
-rw-r--r--examples/sg_simple4.c2
-rw-r--r--examples/sg_simple5.c236
-rw-r--r--examples/sg_simple_aio.c2
17 files changed, 351 insertions, 89 deletions
diff --git a/examples/Makefile b/examples/Makefile
index e3ff3fb7..bf1434f4 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -8,7 +8,7 @@ CC = gcc
LD = gcc
EXECS = sg_simple1 sg_simple2 sg_simple3 sg_simple4 sg_simple16 \
- sg_iovec_tst scsi_inquiry sg_excl sg_sense_test
+ sg_iovec_tst scsi_inquiry sg_excl sg_sense_test sg_simple5
# EXECS = sg_simple1 sg_simple2 sg_simple3 sg_simple4 sg_simple16 \
# sg_simple_aio sg_iovec_tst scsi_inquiry sg_excl
@@ -33,34 +33,37 @@ depend dep:
clean:
/bin/rm -f *.o $(EXECS) core .depend
-sg_simple1: sg_simple1.o ../sg_lib.o
+sg_simple1: sg_simple1.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^
sg_simple2: sg_simple2.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_simple3: sg_simple3.o ../sg_lib.o
+sg_simple3: sg_simple3.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_simple4: sg_simple4.o ../sg_lib.o
+sg_simple4: sg_simple4.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_simple16: sg_simple16.o ../sg_lib.o
+sg_simple16: sg_simple16.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_simple_aio: sg_simple_aio.o ../sg_lib.o
+sg_simple_aio: sg_simple_aio.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^ -l aio
-sg_iovec_tst: sg_iovec_tst.o ../sg_lib.o
+sg_iovec_tst: sg_iovec_tst.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^
scsi_inquiry: scsi_inquiry.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_excl: sg_excl.o ../sg_lib.o
+sg_excl: sg_excl.o ../sg_lib.o ../sg_io_linux.o
$(LD) -o $@ $(LDFLAGS) $^
-sg_sense_test: sg_sense_test.o ../sg_lib.o
+sg_sense_test: sg_sense_test.o ../sg_lib.o ../sg_io_linux.o
+ $(LD) -o $@ $(LDFLAGS) $^
+
+sg_simple5: sg_simple5.o ../sg_lib.o ../sg_pt_linux.o
$(LD) -o $@ $(LDFLAGS) $^
install: $(EXECS)
diff --git a/examples/Makefile.freebsd b/examples/Makefile.freebsd
new file mode 100644
index 00000000..36d10ff7
--- /dev/null
+++ b/examples/Makefile.freebsd
@@ -0,0 +1,61 @@
+SHELL = /bin/sh
+
+PREFIX=/usr/local
+INSTDIR=$(DESTDIR)/$(PREFIX)/bin
+MANDIR=$(DESTDIR)/$(PREFIX)/man
+
+CC = gcc
+LD = gcc
+
+EXECS = sg_simple5
+
+MAN_PGS =
+MAN_PREF = man8
+
+OS_FLAGS = -DSG3_UTILS_FREEBSD
+EXTRA_FLAGS = $(OS_FLAGS)
+
+# CFLAGS = -O2 -Wall -W $(EXTRA_FLAGS)
+CFLAGS = -g -O2 -Wall -W $(EXTRA_FLAGS)
+# CFLAGS = -g -O2 -Wall -W -pedantic -std=c99 $(EXTRA_FLAGS)
+
+CFLAGS_PTHREADS = -D_REENTRANT
+
+O_FILES = sg_lib.o sg_pt_freebsd.o
+
+LDFLAGS = -lcam
+# LDFLAGS = -v -lm
+
+all: $(EXECS)
+
+depend dep:
+ for i in *.c; do $(CC) $(INCLUDES) $(CFLAGS) -M $$i; \
+ done > .depend
+
+clean:
+ /bin/rm -f *.o $(EXECS) core* .depend *.a *.la *.lo
+ /bin/rm -rf .libs
+
+sg_simple5: sg_simple5.o $(O_FILES)
+ $(LD) -o $@ $(LDFLAGS) $@.o $(O_FILES)
+
+install: $(EXECS)
+ install -d $(INSTDIR)
+ for name in $(EXECS); \
+ do install -s -m 755 $$name $(INSTDIR); \
+ done
+ install -d $(MANDIR)/$(MAN_PREF)
+ for mp in $(MAN_PGS); \
+ do install -m 644 $$mp $(MANDIR)/$(MAN_PREF); \
+ gzip -9f $(MANDIR)/$(MAN_PREF)/$$mp; \
+ done
+
+uninstall:
+ dists="$(EXECS)"; \
+ for name in $$dists; do \
+ rm -f $(INSTDIR)/$$name; \
+ done
+ for mp in $(MAN_PGS); do \
+ rm -f $(MANDIR)/$(MAN_PREF)/$$mp.gz; \
+ done
+
diff --git a/examples/sg_excl.c b/examples/sg_excl.c
index f9c3e175..6e651a88 100644
--- a/examples/sg_excl.c
+++ b/examples/sg_excl.c
@@ -7,8 +7,8 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_io_linux.h"
/* This is a simple program that tests the O_EXCL flag in sg while
executing a SCSI INQUIRY command and a
diff --git a/examples/sg_include.h b/examples/sg_include.h
deleted file mode 100644
index b7310ec0..00000000
--- a/examples/sg_include.h
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef SG_INCLUDES_H
-#define SG_INCLUDES_H
-
-#ifdef SG_KERNEL_INCLUDES
- #define __user
- typedef unsigned char u8;
- #include "/usr/src/linux/include/scsi/sg.h"
- #include "/usr/src/linux/include/scsi/scsi.h"
-#else
- #ifdef SG_TRICK_GNU_INCLUDES
- #include <linux/../scsi/sg.h>
- #include <linux/../scsi/scsi.h>
- #else
- #include <scsi/sg.h>
- #include <scsi/scsi.h>
- #endif
-#endif
-
-#ifdef BLKGETSIZE64
- #ifndef u64
- #include <stdint.h> /* C99 header for exact integer types */
- typedef uint64_t u64; /* problems with BLKGETSIZE64 ioctl in lk 2.4 */
- #endif
-#endif
-
-/*
- Getting the correct include files for the sg interface can be an ordeal.
- In a perfect world, one would just write:
- #include <scsi/sg.h>
- #include <scsi/scsi.h>
- This would include the files found in the /usr/include/scsi directory.
- Those files are maintained with the GNU library which may or may not
- agree with the kernel and version of sg driver that is running. Any
- many cases this will not matter. However in some it might, for example
- glibc 2.1's include files match the sg driver found in the lk 2.2
- series. Hence if glibc 2.1 is used with lk 2.4 then the additional
- sg v3 interface will not be visible.
- If this is a problem then defining SG_KERNEL_INCLUDES will access the
- kernel supplied header files (assuming they are in the normal place).
- The GNU library maintainers and various kernel people don't like
- this approach (but it does work).
- The technique selected by defining SG_TRICK_GNU_INCLUDES worked (and
- was used) prior to glibc 2.2 . Prior to that version /usr/include/linux
- was a symbolic link to /usr/src/linux/include/linux .
-
- There are other approaches if this include "mixup" causes pain. These
- would involve include files being copied or symbolic links being
- introduced.
-
- Sorry about the inconvenience. Typically neither SG_KERNEL_INCLUDES
- nor SG_TRICK_GNU_INCLUDES is defined.
-
- dpg 20010415, 20030522
-*/
-
-#endif
diff --git a/examples/sg_io_linux.h b/examples/sg_io_linux.h
new file mode 120000
index 00000000..6c9c2ba9
--- /dev/null
+++ b/examples/sg_io_linux.h
@@ -0,0 +1 @@
+../sg_io_linux.h \ No newline at end of file
diff --git a/examples/sg_iovec_tst.c b/examples/sg_iovec_tst.c
index dd4c52f7..f4f62382 100644
--- a/examples/sg_iovec_tst.c
+++ b/examples/sg_iovec_tst.c
@@ -8,8 +8,8 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_io_linux.h"
/* Test code for D. Gilbert's extensions to the Linux OS SCSI generic ("sg")
device driver.
diff --git a/examples/sg_linux_inc.h b/examples/sg_linux_inc.h
new file mode 120000
index 00000000..55808134
--- /dev/null
+++ b/examples/sg_linux_inc.h
@@ -0,0 +1 @@
+../sg_linux_inc.h \ No newline at end of file
diff --git a/examples/sg_persist_tst.sh b/examples/sg_persist_tst.sh
index 3ed2e4e3..0680eaed 100755
--- a/examples/sg_persist_tst.sh
+++ b/examples/sg_persist_tst.sh
@@ -1,50 +1,58 @@
-#/bin/sh
+#!/bin/sh
# This script is meant as an example of using the sg_persist utility
# in the sg3_utils package. This script works as expected on the
# author's Fujitsu MAM3184 disk.
# N.B. make sure the device name is correct for your environment.
+if [ ! -n "$1" ];then
+ echo "Usage: `basename $0` <device_name>"
+ echo
+ echo "Tests various SCSI Persistent Reserve (in + out) commands."
+ echo "Should be harmless (unless key 0x123abc is already in use)."
+ exit 1
+fi
+
echo "check if any keys are registered:"
-sg_persist -k /dev/sdb
+sg_persist -k $1
sleep 1
echo
echo "register a key:"
-sg_persist -n --out --register --param-sark=123abc /dev/sdb
+sg_persist -n --out --register --param-sark=123abc $1
sleep 1
echo
echo "now key 123abc should be registered:"
-sg_persist -n -k /dev/sdb
+sg_persist -n -k $1
sleep 1
echo
echo "reserve the device (based on key 123abc):"
-sg_persist -n --out --reserve --param-rk=123abc --prout-type=1 /dev/sdb
+sg_persist -n --out --reserve --param-rk=123abc --prout-type=1 $1
sleep 1
echo
echo "check if the device is reserved (it should be now):"
-sg_persist -n --read-reservation /dev/sdb
+sg_persist -n --read-reservation $1
sleep 1
echo
echo "now release reservation:"
-sg_persist -n --out --release --param-rk=123abc --prout-type=1 /dev/sdb
+sg_persist -n --out --release --param-rk=123abc --prout-type=1 $1
sleep 1
echo
echo "check if the device is reserved (it should _not_ be now):"
-sg_persist -n --read-reservation /dev/sdb
+sg_persist -n --read-reservation $1
sleep 1
echo
echo "unregister key 123abc:"
-sg_persist -n --out --register --param-rk=123abc /dev/sdb
+sg_persist -n --out --register --param-rk=123abc $1
sleep 1
echo
echo "now key 123abc should not be registered:"
-sg_persist -n -k /dev/sdb
+sg_persist -n -k $1
sleep 1
diff --git a/examples/sg_pt.h b/examples/sg_pt.h
new file mode 120000
index 00000000..508f66d3
--- /dev/null
+++ b/examples/sg_pt.h
@@ -0,0 +1 @@
+../sg_pt.h \ No newline at end of file
diff --git a/examples/sg_sense_test.c b/examples/sg_sense_test.c
index 2ecdc447..5cef47b6 100644
--- a/examples/sg_sense_test.c
+++ b/examples/sg_sense_test.c
@@ -7,13 +7,12 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
#include "sg_lib.h"
/* This is a simple program that tests the sense data descriptor format
printout function in sg_lib.c
-* Copyright (C) 2004 D. Gilbert
+* Copyright (C) 2004-2005 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)
@@ -33,27 +32,35 @@ int main(int argc, char * argv[])
0xaa, 0xbb, 0xcc, 0xdd,
1, 0xa, 0, 0, 1, 2, 3, 4,
0xaa, 0xbb, 0xcc, 0xdd};
- unsigned char err2[] = {0x72, MEDIUM_ERROR, 0x4, 0x1, 0, 0, 0, 32,
+ unsigned char err2[] = {0x72, SPC_SK_MEDIUM_ERROR, 0x4, 0x1, 0, 0, 0, 32,
0x2, 0x6, 0, 0, 0xc8, 0x0, 0x3, 0,
0, 0xa, 0x80, 0, 1, 2, 3, 4,
0xaa, 0xbb, 0xcc, 0xdd,
1, 0xa, 0, 0, 1, 2, 3, 4,
0xaa, 0xbb, 0xcc, 0xdd};
- unsigned char err3[] = {0x72, NO_SENSE, 0x4, 0x1, 0, 0, 0, 8,
+ unsigned char err3[] = {0x72, SPC_SK_NO_SENSE, 0x4, 0x1, 0, 0, 0, 8,
0x2, 0x6, 0, 0, 0xc8, 0x0, 0x3, 0};
- unsigned char err4[] = {0x73, COPY_ABORTED, 0x4, 0x1, 0, 0, 0, 22,
+ unsigned char err4[] = {0x73, SPC_SK_COPY_ABORTED, 0x4, 0x1, 0, 0, 0, 22,
0x2, 0x6, 0, 0, 0xc8, 0x0, 0x3, 0,
0x3, 0x2, 0, 0x55,
0x5, 0x2, 0, 0x20,
0x85, 0x4, 0, 0x20, 0x33, 0x44};
- unsigned char err5[] = {0xf1, 0, (0xf0 | ILLEGAL_REQUEST), 0x11, 0x22,
+ unsigned char err5[] = {0xf1, 0, (0xf0 | SPC_SK_ILLEGAL_REQUEST), 0x11, 0x22,
0x33, 0x44, 0xa,
0x0, 0x0, 0, 0, 0x4, 0x1, 0, 0xcf, 0, 5,};
+ unsigned char err6[] = {0x72, SPC_SK_NO_SENSE, 0x4, 0x1, 0, 0, 0, 14,
+ 0x9, 0xc, 1, 0, 0x11, 0x22, 0x33, 0x44,
+ 0x55, 0x66, 0x77, 0x88, 0x1, 0x2};
+ unsigned char err7[] = {0xf1, 0, 0xe5, 0x11, 0x22, 0x33, 0x44, 0xa,
+ 0x0, 0x0, 0x0, 0x0, 0x24, 0x1, 0xbb,
+ 0xc9, 0x0, 0x2};
sg_print_sense("err1 test", err1, sizeof(err1), 1);
sg_print_sense("\nerr2 test", err2, sizeof(err2), 1);
sg_print_sense("\nerr3 test", err3, sizeof(err3), 1);
sg_print_sense("\nerr4 test", err4, sizeof(err4), 1);
sg_print_sense("\nerr5 test", err5, sizeof(err5), 1);
+ sg_print_sense("\nerr6 test", err6, sizeof(err6), 1);
+ sg_print_sense("\nerr7 test", err7, sizeof(err7), 1);
return 0;
}
diff --git a/examples/sg_simple1.c b/examples/sg_simple1.c
index 623f944f..a59979a4 100644
--- a/examples/sg_simple1.c
+++ b/examples/sg_simple1.c
@@ -7,8 +7,8 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_io_linux.h"
/* This is a simple program executing a SCSI INQUIRY command and a
TEST UNIT READY command using the SCSI generic (sg) driver
diff --git a/examples/sg_simple16.c b/examples/sg_simple16.c
index 12e40609..33625859 100644
--- a/examples/sg_simple16.c
+++ b/examples/sg_simple16.c
@@ -7,8 +7,8 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_io_linux.h"
/* This program performs a READ_16 command as scsi mid-level support
16 byte commands from lk 2.4.15
diff --git a/examples/sg_simple2.c b/examples/sg_simple2.c
index eb398d06..acc01328 100644
--- a/examples/sg_simple2.c
+++ b/examples/sg_simple2.c
@@ -7,7 +7,7 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
+#include "sg_linux_inc.h"
/* This is a simple program executing a SCSI INQUIRY command and a
TEST UNIT READY command using the SCSI generic (sg) driver.
diff --git a/examples/sg_simple3.c b/examples/sg_simple3.c
index ead162de..0ee26843 100644
--- a/examples/sg_simple3.c
+++ b/examples/sg_simple3.c
@@ -7,8 +7,8 @@
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_io_linux.h"
/* This is a simple program executing a SCSI INQUIRY command and a
TEST UNIT READY command using the SCSI generic (sg) driver.
diff --git a/examples/sg_simple4.c b/examples/sg_simple4.c
index 64c8f31f..20d8d7f5 100644
--- a/examples/sg_simple4.c
+++ b/examples/sg_simple4.c
@@ -8,8 +8,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_io_linux.h"
/* This is a simple program executing a SCSI INQUIRY command and a
TEST UNIT READY command using the SCSI generic (sg) driver
diff --git a/examples/sg_simple5.c b/examples/sg_simple5.c
new file mode 100644
index 00000000..2179570b
--- /dev/null
+++ b/examples/sg_simple5.c
@@ -0,0 +1,236 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "sg_lib.h"
+#include "sg_pt.h"
+
+/* This is a simple program executing a SCSI INQUIRY command and a
+ TEST UNIT READY command using the SCSI generic pass through
+ interface. This allows this example program to be ported to
+ OSes other than linux.
+
+* Copyright (C) 2006 D. Gilbert
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2, or (at your option)
+* any later version.
+
+ Invocation: sg_simple5 [-x] <sg_device>
+
+ Version 1.00 (20060105)
+
+*/
+
+#define INQ_REPLY_LEN 96
+#define INQ_CMD_LEN 6
+#define TUR_CMD_LEN 6
+
+#define CMD_TIMEOUT_SECS 60
+
+
+int main(int argc, char * argv[])
+{
+ int sg_fd, k, ok, dsize, res, duration, resid, cat, got, slen;
+ unsigned char inqCmdBlk [INQ_CMD_LEN] =
+ {0x12, 0, 0, 0, INQ_REPLY_LEN, 0};
+ unsigned char turCmdBlk [TUR_CMD_LEN] =
+ {0x00, 0, 0, 0, 0, 0};
+ unsigned char inqBuff[INQ_REPLY_LEN];
+ char * file_name = 0;
+ char b[512];
+ unsigned char sense_b[32];
+ int verbose = 0;
+ void * ptvp;
+
+ for (k = 1; k < argc; ++k) {
+ if (0 == strcmp("-v", argv[k]))
+ verbose = 1;
+ else if (0 == strcmp("-vv", argv[k]))
+ verbose = 2;
+ else if (0 == strcmp("-vvv", argv[k]))
+ verbose = 3;
+ else if (*argv[k] == '-') {
+ printf("Unrecognized switch: %s\n", argv[k]);
+ file_name = 0;
+ break;
+ }
+ else if (0 == file_name)
+ file_name = argv[k];
+ else {
+ printf("too many arguments\n");
+ file_name = 0;
+ break;
+ }
+ }
+ if (0 == file_name) {
+ printf("Usage: 'sg_simple5 [-v|-vv|-vvv] <device>'\n");
+ return 1;
+ }
+
+ sg_fd = scsi_pt_open_device(file_name, 1 /* ro */, 0);
+ /* N.B. An access mode of O_RDWR is required for some SCSI commands */
+ if (sg_fd < 0) {
+ fprintf(stderr, "error opening file: %s: %s\n",
+ file_name, safe_strerror(-sg_fd));
+ return 1;
+ }
+
+ dsize = sizeof(inqBuff);
+ ok = 0;
+
+ ptvp = construct_scsi_pt_obj(); /* one object per command */
+ if (NULL == ptvp) {
+ fprintf(stderr, "sg_simple5: out of memory\n");
+ return -1;
+ }
+ set_scsi_pt_cdb(ptvp, inqCmdBlk, sizeof(inqCmdBlk));
+ set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
+ set_scsi_pt_data_in(ptvp, inqBuff, dsize);
+ res = do_scsi_pt(ptvp, sg_fd, CMD_TIMEOUT_SECS, verbose);
+ if (res < 0) {
+ fprintf(stderr, " pass through os error: %s\n",
+ safe_strerror(-res));
+ goto finish_inq;
+ } else if (SCSI_PT_DO_BAD_PARAMS == res) {
+ fprintf(stderr, " bad pass through setup\n");
+ goto finish_inq;
+ } else if (SCSI_PT_DO_TIMEOUT == res) {
+ fprintf(stderr, " pass through timeout\n");
+ goto finish_inq;
+ }
+ if ((verbose > 1) && ((duration = get_scsi_pt_duration_ms(ptvp)) >= 0))
+ fprintf(stderr, " duration=%d ms\n", duration);
+ resid = get_scsi_pt_resid(ptvp);
+ switch ((cat = get_scsi_pt_result_category(ptvp))) {
+ case SCSI_PT_RESULT_GOOD:
+ got = dsize - resid;
+ if (verbose && (resid > 0))
+ fprintf(stderr, " requested %d bytes but "
+ "got %d bytes)\n", dsize, got);
+ break;
+ case SCSI_PT_RESULT_STATUS: /* other than GOOD and CHECK CONDITION */
+ if (verbose) {
+ sg_get_scsi_status_str(get_scsi_pt_status_response(ptvp),
+ sizeof(b), b);
+ fprintf(stderr, " scsi status: %s\n", b);
+ }
+ goto finish_inq;
+ case SCSI_PT_RESULT_SENSE:
+ slen = get_scsi_pt_sense_len(ptvp);
+ if (verbose) {
+ sg_get_sense_str("", sense_b, slen, (verbose > 1),
+ sizeof(b), b);
+ fprintf(stderr, "%s", b);
+ }
+ if (verbose && (resid > 0)) {
+ got = dsize - resid;
+ if ((verbose) || (got > 0))
+ fprintf(stderr, " requested %d bytes but "
+ "got %d bytes\n", dsize, got);
+ }
+ goto finish_inq;
+ case SCSI_PT_RESULT_TRANSPORT_ERR:
+ if (verbose) {
+ get_scsi_pt_transport_err_str(ptvp, sizeof(b), b);
+ fprintf(stderr, " transport: %s", b);
+ }
+ goto finish_inq;
+ case SCSI_PT_RESULT_OS_ERR:
+ if (verbose) {
+ get_scsi_pt_os_err_str(ptvp, sizeof(b), b);
+ fprintf(stderr, " os: %s", b);
+ }
+ goto finish_inq;
+ default:
+ fprintf(stderr, " unknown pass through result "
+ "category (%d)\n", cat);
+ goto finish_inq;
+ }
+
+ ok = 1;
+finish_inq:
+ destruct_scsi_pt_obj(ptvp);
+
+ if (ok) { /* output result if it is available */
+ char * p = (char *)inqBuff;
+
+ printf("Some of the INQUIRY command's results:\n");
+ printf(" %.8s %.16s %.4s\n", p + 8, p + 16, p + 32);
+ }
+ ok = 0;
+
+
+ /* Now prepare TEST UNIT READY command */
+ ptvp = construct_scsi_pt_obj(); /* one object per command */
+ if (NULL == ptvp) {
+ fprintf(stderr, "sg_simple5: out of memory\n");
+ return -1;
+ }
+ set_scsi_pt_cdb(ptvp, turCmdBlk, sizeof(turCmdBlk));
+ set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
+ /* no data in or out */
+ res = do_scsi_pt(ptvp, sg_fd, CMD_TIMEOUT_SECS, verbose);
+ if (res < 0) {
+ fprintf(stderr, " pass through os error: %s\n",
+ safe_strerror(-res));
+ goto finish_inq;
+ } else if (SCSI_PT_DO_BAD_PARAMS == res) {
+ fprintf(stderr, " bad pass through setup\n");
+ goto finish_inq;
+ } else if (SCSI_PT_DO_TIMEOUT == res) {
+ fprintf(stderr, " pass through timeout\n");
+ goto finish_inq;
+ }
+ if ((verbose > 1) && ((duration = get_scsi_pt_duration_ms(ptvp)) >= 0))
+ fprintf(stderr, " duration=%d ms\n", duration);
+ resid = get_scsi_pt_resid(ptvp);
+ switch ((cat = get_scsi_pt_result_category(ptvp))) {
+ case SCSI_PT_RESULT_GOOD:
+ break;
+ case SCSI_PT_RESULT_STATUS: /* other than GOOD and CHECK CONDITION */
+ if (verbose) {
+ sg_get_scsi_status_str(get_scsi_pt_status_response(ptvp),
+ sizeof(b), b);
+ fprintf(stderr, " scsi status: %s\n", b);
+ }
+ goto finish_tur;
+ case SCSI_PT_RESULT_SENSE:
+ slen = get_scsi_pt_sense_len(ptvp);
+ if (verbose) {
+ sg_get_sense_str("", sense_b, slen, (verbose > 1),
+ sizeof(b), b);
+ fprintf(stderr, "%s", b);
+ }
+ goto finish_tur;
+ case SCSI_PT_RESULT_TRANSPORT_ERR:
+ if (verbose) {
+ get_scsi_pt_transport_err_str(ptvp, sizeof(b), b);
+ fprintf(stderr, " transport: %s", b);
+ }
+ goto finish_tur;
+ case SCSI_PT_RESULT_OS_ERR:
+ if (verbose) {
+ get_scsi_pt_os_err_str(ptvp, sizeof(b), b);
+ fprintf(stderr, " os: %s", b);
+ }
+ goto finish_tur;
+ default:
+ fprintf(stderr, " unknown pass through result "
+ "category (%d)\n", cat);
+ goto finish_tur;
+ }
+
+ ok = 1;
+finish_tur:
+ destruct_scsi_pt_obj(ptvp);
+
+ if (ok)
+ printf("Test Unit Ready successful so unit is ready!\n");
+ else
+ printf("Test Unit Ready failed so unit may _not_ be ready!\n");
+
+ scsi_pt_close_device(sg_fd);
+ return 0;
+}
diff --git a/examples/sg_simple_aio.c b/examples/sg_simple_aio.c
index bc5cccfd..009c3fda 100644
--- a/examples/sg_simple_aio.c
+++ b/examples/sg_simple_aio.c
@@ -8,8 +8,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <libaio.h>
-#include "sg_include.h"
#include "sg_lib.h"
+#include "sg_linux_inc.h"
/* This is a simple program executing a SCSI INQUIRY command and a
TEST UNIT READY command using the SCSI generic (sg) driver