aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2013-09-07 11:53:57 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2013-09-07 11:53:57 +0000
commit0c1a4a1ac548179c7ccaf288cecfd9a57d34db0f (patch)
tree042c524aa3a0a32f738577ac3eb3d970d8716d86 /examples
parent61e33879b3446324b66f92868a4b26dfad56b58e (diff)
downloadsg3_utils-0c1a4a1ac548179c7ccaf288cecfd9a57d34db0f.tar.gz
sg_ses: AES page EIIOE field addition; sg_tst_excl* tweaks
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@512 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'examples')
-rw-r--r--examples/README7
-rw-r--r--examples/sg_tst_excl.cpp45
-rw-r--r--examples/sg_tst_excl2.cpp45
3 files changed, 64 insertions, 33 deletions
diff --git a/examples/README b/examples/README
index 22c15272..ea0bf85a 100644
--- a/examples/README
+++ b/examples/README
@@ -10,5 +10,10 @@ There is an brief explanation of each example in the README file in
the main (i.e. this directory's parent) directory. There are also
some notes at the top of each source file.
+
+Those files with the extension "cpp" are C++ examples that use facilities
+in C++11. They can be built by calling 'make -f Makefile.cplus'. A
+gcc/g++ compiler of 4.7.3 vintage or later will be required.
+
Douglas Gilbert
-17th February 2008
+30th August 2013
diff --git a/examples/sg_tst_excl.cpp b/examples/sg_tst_excl.cpp
index 384a3566..fbd38550 100644
--- a/examples/sg_tst_excl.cpp
+++ b/examples/sg_tst_excl.cpp
@@ -46,7 +46,7 @@
#include "sg_lib.h"
#include "sg_io_linux.h"
-static const char * version_str = "1.04 20130806";
+static const char * version_str = "1.04 20130829";
static const char * util_name = "sg_tst_excl";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -104,11 +104,16 @@ static unsigned int bounce_count;
static void
usage(void)
{
- printf("Usage: %s [-b] [-l <lba>] [-n <n_per_thr>] [-t <num_thrs>]\n"
+ printf("Usage: %s [-b] [-f] [-h] [-l <lba>] [-n <n_per_thr>] "
+ "[-t <num_thrs>]\n"
" [-V] [-w <wait_ms>] [-x] "
"<disk_device>\n", util_name);
printf(" where\n");
printf(" -b block on open (def: O_NONBLOCK)\n");
+ printf(" -f force: any SCSI disk (def: only "
+ "scsi_debug)\n");
+ printf(" WARNING: <lba> written to\n");
+ printf(" -h print this usage message then exit\n");
printf(" -l <lba> logical block to increment (def: %u)\n",
DEF_LBA);
printf(" -n <n_per_thr> number of loops per thread "
@@ -407,6 +412,7 @@ main(int argc, char * argv[])
{
int k, res;
int block = 0;
+ int force = 0;
unsigned int lba = DEF_LBA;
int num_per_thread = DEF_NUM_PER_THREAD;
int num_threads = DEF_NUM_THREADS;
@@ -418,7 +424,12 @@ main(int argc, char * argv[])
for (k = 1; k < argc; ++k) {
if (0 == memcmp("-b", argv[k], 2))
++block;
- else if (0 == memcmp("-l", argv[k], 2)) {
+ else if (0 == memcmp("-f", argv[k], 2))
+ ++force;
+ else if (0 == memcmp("-h", argv[k], 2)) {
+ usage();
+ return 0;
+ } else if (0 == memcmp("-l", argv[k], 2)) {
++k;
if ((k < argc) && isdigit(*argv[k]))
lba = (unsigned int)atoi(argv[k]);
@@ -469,19 +480,21 @@ main(int argc, char * argv[])
}
try {
- res = do_inquiry_prod_id(dev_name, block, ! exclude_o_excl, wait_ms,
- bounce_count, b, sizeof(b));
- if (res) {
- fprintf(stderr, "INQUIRY failed on %s\n", dev_name);
- return 1;
- }
- // Comment out next block to use with non scsi_debug devices
- // If so, be careful, as it writes to a LBA <lba>
- if (0 != memcmp("scsi_debug", b, 10)) {
- fprintf(stderr, "Since this utility writes to LBA %d, only "
- "devices with scsi_debug\nproduct ID accepted.\n",
- lba);
- return 2;
+ if (! force) {
+ res = do_inquiry_prod_id(dev_name, block, ! exclude_o_excl,
+ wait_ms, bounce_count, b, sizeof(b));
+ if (res) {
+ fprintf(stderr, "INQUIRY failed on %s\n", dev_name);
+ return 1;
+ }
+ // For safety, since <lba> written to, only permit scsi_debug
+ // devices. Bypass this with '-f' option.
+ if (0 != memcmp("scsi_debug", b, 10)) {
+ fprintf(stderr, "Since this utility writes to LBA %d, only "
+ "devices with scsi_debug\nproduct ID accepted.\n",
+ lba);
+ return 2;
+ }
}
vector<thread *> vt;
diff --git a/examples/sg_tst_excl2.cpp b/examples/sg_tst_excl2.cpp
index 8f88a25f..fd480e7b 100644
--- a/examples/sg_tst_excl2.cpp
+++ b/examples/sg_tst_excl2.cpp
@@ -46,7 +46,7 @@
#include "sg_lib.h"
#include "sg_pt.h"
-static const char * version_str = "1.04 20130806";
+static const char * version_str = "1.04 20130829";
static const char * util_name = "sg_tst_excl2";
/* This is a test program for checking O_EXCL on open() works. It uses
@@ -105,11 +105,16 @@ static unsigned int bounce_count;
static void
usage(void)
{
- printf("Usage: %s [-b] [-l <lba>] [-n <n_per_thr>] [-t <num_thrs>]\n"
+ printf("Usage: %s [-b] [-f] [-h] [-l <lba>] [-n <n_per_thr>] "
+ "[-t <num_thrs>]\n"
" [-V] [-w <wait_ms>] [-x] "
"<disk_device>\n", util_name);
printf(" where\n");
printf(" -b block on open (def: O_NONBLOCK)\n");
+ printf(" -f force: any SCSI disk (def: only "
+ "scsi_debug)\n");
+ printf(" WARNING: <lba> written to\n");
+ printf(" -h print this usage message then exit\n");
printf(" -l <lba> logical block to increment (def: %u)\n",
DEF_LBA);
printf(" -n <n_per_thr> number of loops per thread "
@@ -405,6 +410,7 @@ main(int argc, char * argv[])
{
int k, res;
int block = 0;
+ int force = 0;
unsigned int lba = DEF_LBA;
int num_per_thread = DEF_NUM_PER_THREAD;
int num_threads = DEF_NUM_THREADS;
@@ -416,7 +422,12 @@ main(int argc, char * argv[])
for (k = 1; k < argc; ++k) {
if (0 == memcmp("-b", argv[k], 2))
++block;
- else if (0 == memcmp("-l", argv[k], 2)) {
+ else if (0 == memcmp("-f", argv[k], 2))
+ ++force;
+ else if (0 == memcmp("-h", argv[k], 2)) {
+ usage();
+ return 0;
+ } else if (0 == memcmp("-l", argv[k], 2)) {
++k;
if ((k < argc) && isdigit(*argv[k]))
lba = (unsigned int)atoi(argv[k]);
@@ -467,19 +478,21 @@ main(int argc, char * argv[])
}
try {
- res = do_inquiry_prod_id(dev_name, block, ! exclude_o_excl, wait_ms,
- bounce_count, b, sizeof(b));
- if (res) {
- fprintf(stderr, "INQUIRY failed on %s\n", dev_name);
- return 1;
- }
- // Comment out next block to use with non scsi_debug devices
- // If so, be careful, as it writes to a LBA <lba>
- if (0 != memcmp("scsi_debug", b, 10)) {
- fprintf(stderr, "Since this utility writes to LBA %d, only "
- "devices with scsi_debug\nproduct ID accepted.\n",
- lba);
- return 2;
+ if (! force) {
+ res = do_inquiry_prod_id(dev_name, block, ! exclude_o_excl,
+ wait_ms, bounce_count, b, sizeof(b));
+ if (res) {
+ fprintf(stderr, "INQUIRY failed on %s\n", dev_name);
+ return 1;
+ }
+ // For safety, since <lba> written to, only permit scsi_debug
+ // devices. Bypass this with '-f' option.
+ if (0 != memcmp("scsi_debug", b, 10)) {
+ fprintf(stderr, "Since this utility writes to LBA %d, only "
+ "devices with scsi_debug\nproduct ID accepted.\n",
+ lba);
+ return 2;
+ }
}
vector<thread *> vt;