aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:51:21 +0000
committerDouglas Gilbert <dgilbert@interlog.com>2007-06-27 03:51:21 +0000
commit7502647d46389b2e0e659f658b51f56abd1f9511 (patch)
treedc0c45bcd01d5f6ddeac34258c765efe417c70ac /examples
parent130627841138672bf26e9b4b5a1f70a240e910a6 (diff)
downloadsg3_utils-7502647d46389b2e0e659f658b51f56abd1f9511.tar.gz
Load sg3_utils-1.23 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@74 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.freebsd4
-rw-r--r--examples/reassign_addr.txt4
-rw-r--r--examples/scsi_inquiry.c21
-rw-r--r--examples/sg__sat_identify.c10
l---------examples/sg_io_linux.h1
-rw-r--r--examples/sg_io_linux.hh1
-rw-r--r--examples/sg_iovec_tst.c6
l---------examples/sg_lib.h1
-rw-r--r--examples/sg_lib.hh1
l---------examples/sg_linux_inc.h1
-rw-r--r--examples/sg_linux_inc.hh1
l---------examples/sg_pt.h1
-rw-r--r--examples/sg_pt.hh1
-rw-r--r--examples/sg_sat_chk_power.c33
-rw-r--r--examples/sg_sat_set_features.c28
-rw-r--r--examples/sg_sat_smart_rd_data.c20
-rw-r--r--examples/sg_simple4.c6
17 files changed, 79 insertions, 61 deletions
diff --git a/examples/Makefile.freebsd b/examples/Makefile.freebsd
index 966af32c..a7b2797a 100644
--- a/examples/Makefile.freebsd
+++ b/examples/Makefile.freebsd
@@ -21,6 +21,8 @@ CFLAGS = -g -O2 -Wall -W $(EXTRA_FLAGS)
CFLAGS_PTHREADS = -D_REENTRANT
+# there is no rule to make the following in the parent directory,
+# it is assumed they are already built.
D_FILES = ../sg_lib.o ../sg_pt_freebsd.o
O_FILES = sg_lib.o sg_pt_freebsd.o
@@ -38,7 +40,7 @@ clean:
/bin/rm -rf .libs
sg_simple5: sg_simple5.o $(D_FILES)
- $(LD) -o $@ $(LDFLAGS) $@.o $(O_FILES)
+ $(LD) -o $@ $(LDFLAGS) $@.o $(D_FILES)
install: $(EXECS)
install -d $(INSTDIR)
diff --git a/examples/reassign_addr.txt b/examples/reassign_addr.txt
index 47915852..9d48d005 100644
--- a/examples/reassign_addr.txt
+++ b/examples/reassign_addr.txt
@@ -4,8 +4,8 @@
# To see logical block addresses placed in the command parameter block
# without executing them command try something like:
-# 'sg_reassign --address=- -d -vv /dev/sda < reassign_addr.txt
+# 'sg_reassign --address=- --dummy -vv /dev/sda < reassign_addr.txt
1,34,0x33,0X444 0x89abcde 0xdeadbeef # 6 lba's
-# dpg 20060824
+# dpg 20070130
diff --git a/examples/scsi_inquiry.c b/examples/scsi_inquiry.c
index 6b6e79d0..aae8e374 100644
--- a/examples/scsi_inquiry.c
+++ b/examples/scsi_inquiry.c
@@ -53,7 +53,8 @@ int main(int argc, char * argv[])
int s_fd, res, k, to;
unsigned char inqCmdBlk [INQUIRY_CMDLEN] = {INQUIRY_CMD, 0, 0, 0,
INQUIRY_REPLY_LEN, 0};
- unsigned char * inqBuff = malloc(OFF + sizeof(inqCmdBlk) + 512);
+ unsigned char * inqBuff = (unsigned char *)
+ malloc(OFF + sizeof(inqCmdBlk) + 512);
unsigned char * buffp = inqBuff + OFF;
My_Scsi_Ioctl_Command * ishp = (My_Scsi_Ioctl_Command *)inqBuff;
char * file_name = 0;
@@ -61,15 +62,15 @@ int main(int argc, char * argv[])
int oflags = 0;
for (k = 1; k < argc; ++k) {
- if (0 == strcmp(argv[k], "-n"))
- do_nonblock = 1;
- else if (*argv[k] != '-')
+ if (0 == strcmp(argv[k], "-n"))
+ do_nonblock = 1;
+ else if (*argv[k] != '-')
file_name = argv[k];
- else {
- printf("Unrecognized argument '%s'\n", argv[k]);
- file_name = 0;
- break;
- }
+ else {
+ printf("Unrecognized argument '%s'\n", argv[k]);
+ file_name = 0;
+ break;
+ }
}
if (0 == file_name) {
printf("Usage: 'scsi_inquiry [-n] <scsi_device>'\n");
@@ -81,7 +82,7 @@ int main(int argc, char * argv[])
}
if (do_nonblock)
- oflags = O_NONBLOCK;
+ oflags = O_NONBLOCK;
s_fd = open(file_name, oflags | O_RDWR);
if (s_fd < 0) {
if ((EROFS == errno) || (EACCES == errno)) {
diff --git a/examples/sg__sat_identify.c b/examples/sg__sat_identify.c
index bdf4d826..06ecfe6f 100644
--- a/examples/sg__sat_identify.c
+++ b/examples/sg__sat_identify.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006 Douglas Gilbert.
+ * Copyright (c) 2006-2007 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@
#define SAT_ATA_PASS_THROUGH16 0x85
#define SAT_ATA_PASS_THROUGH16_LEN 16
-#define SAT_STATUS_RETURN_DESC 9 /* ATA status return (sense) descriptor */
+#define SAT_ATA_RETURN_DESC 9 /* ATA Return (sense) Descriptor */
#define ATA_IDENTIFY_DEVICE 0xec
#define ATA_IDENTIFY_PACKET_DEVICE 0xa1
@@ -64,7 +64,7 @@
#define EBUFF_SZ 256
-static char * version_str = "1.01 20061014";
+static char * version_str = "1.02 20070130";
static void usage()
{
@@ -179,11 +179,11 @@ int main(int argc, char * argv[])
ok = 1;
break;
case SG_LIB_CAT_RECOVERED:
- /* check for ATA status return descriptor */
if (verbose)
sg_chk_n_print3(">>> ATA_16 command", &io_hdr, 1);
+ /* check for ATA Return Descriptor */
cucp = sg_scsi_sense_desc_find(io_hdr.sbp, io_hdr.sb_len_wr,
- SAT_STATUS_RETURN_DESC);
+ SAT_ATA_RETURN_DESC);
if (cucp && (cucp[3])) {
if (cucp[3] & 0x4) {
printf("error in returned FIS: aborted command\n");
diff --git a/examples/sg_io_linux.h b/examples/sg_io_linux.h
deleted file mode 120000
index 6c9c2ba9..00000000
--- a/examples/sg_io_linux.h
+++ /dev/null
@@ -1 +0,0 @@
-../sg_io_linux.h \ No newline at end of file
diff --git a/examples/sg_io_linux.hh b/examples/sg_io_linux.hh
new file mode 100644
index 00000000..459a7cd9
--- /dev/null
+++ b/examples/sg_io_linux.hh
@@ -0,0 +1 @@
+#include "../sg_io_linux.h"
diff --git a/examples/sg_iovec_tst.c b/examples/sg_iovec_tst.c
index 8732f1bc..83ccf593 100644
--- a/examples/sg_iovec_tst.c
+++ b/examples/sg_iovec_tst.c
@@ -13,7 +13,7 @@
/* Test code for D. Gilbert's extensions to the Linux OS SCSI generic ("sg")
device driver.
-* Copyright (C) 2003 D. Gilbert
+* Copyright (C) 2003-2007 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)
@@ -24,7 +24,7 @@
normal file. The purpose is to test the sg_iovec mechanism within the
sg_io_hdr structure.
- Version 0.11 (20060622)
+ Version 0.12 (20070121)
*/
@@ -171,7 +171,7 @@ int main(int argc, char * argv[])
return 1;
}
dxfer_len = count * blk_size;
- buffp = malloc(dxfer_len);
+ buffp = (unsigned char *)malloc(dxfer_len);
if (buffp) {
if (0 == sg_read(sg_fd, buffp, count, 0, blk_size)) {
if (write(fd, buffp, dxfer_len) < 0)
diff --git a/examples/sg_lib.h b/examples/sg_lib.h
deleted file mode 120000
index f6ce0761..00000000
--- a/examples/sg_lib.h
+++ /dev/null
@@ -1 +0,0 @@
-../sg_lib.h \ No newline at end of file
diff --git a/examples/sg_lib.hh b/examples/sg_lib.hh
new file mode 100644
index 00000000..e2f826a1
--- /dev/null
+++ b/examples/sg_lib.hh
@@ -0,0 +1 @@
+#include "../sg_lib.h"
diff --git a/examples/sg_linux_inc.h b/examples/sg_linux_inc.h
deleted file mode 120000
index 55808134..00000000
--- a/examples/sg_linux_inc.h
+++ /dev/null
@@ -1 +0,0 @@
-../sg_linux_inc.h \ No newline at end of file
diff --git a/examples/sg_linux_inc.hh b/examples/sg_linux_inc.hh
new file mode 100644
index 00000000..a5bf738d
--- /dev/null
+++ b/examples/sg_linux_inc.hh
@@ -0,0 +1 @@
+#include "../sg_linux_inc.h"
diff --git a/examples/sg_pt.h b/examples/sg_pt.h
deleted file mode 120000
index 508f66d3..00000000
--- a/examples/sg_pt.h
+++ /dev/null
@@ -1 +0,0 @@
-../sg_pt.h \ No newline at end of file
diff --git a/examples/sg_pt.hh b/examples/sg_pt.hh
new file mode 100644
index 00000000..2be7b43b
--- /dev/null
+++ b/examples/sg_pt.hh
@@ -0,0 +1 @@
+#include "../sg_pt.h"
diff --git a/examples/sg_sat_chk_power.c b/examples/sg_sat_chk_power.c
index 355150c9..d6d09286 100644
--- a/examples/sg_sat_chk_power.c
+++ b/examples/sg_sat_chk_power.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006 Douglas Gilbert.
+ * Copyright (c) 2006-2007 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@
/* This program performs a ATA PASS-THROUGH (16) SCSI command in order
to perform an ATA CHECK POWER MODE command. See http://www.t10.org
- SAT draft at time of writing: sat-r08.pdf
+ SAT draft at time of writing: sat-r09.pdf
Invocation: sg_sat_chk_power [-v] [-V] <device>
@@ -49,13 +49,13 @@
#define SAT_ATA_PASS_THROUGH16 0x85
#define SAT_ATA_PASS_THROUGH16_LEN 16
-#define SAT_STATUS_RETURN_DESC 9 /* ATA status return (sense) descriptor */
+#define SAT_ATA_RETURN_DESC 9 /* ATA Return (sense) Descriptor */
#define ATA_CHECK_POWER_MODE 0xe5
#define EBUFF_SZ 256
-static char * version_str = "1.02 20061014";
+static char * version_str = "1.03 20070129";
int main(int argc, char * argv[])
{
@@ -81,6 +81,8 @@ int main(int argc, char * argv[])
++verbose;
else if (0 == strcmp(argv[k], "-vv"))
verbose += 2;
+ else if (0 == strcmp(argv[k], "-vvv"))
+ verbose += 3;
else if (0 == strcmp(argv[k], "-V")) {
fprintf(stderr, "version: %s\n", version_str);
exit(0);
@@ -146,15 +148,18 @@ int main(int argc, char * argv[])
switch (sg_err_category3(&io_hdr)) {
case SG_LIB_CAT_CLEAN:
break;
- case SG_LIB_CAT_RECOVERED:
- case SG_LIB_CAT_NO_SENSE:
+ case SG_LIB_CAT_RECOVERED: /* sat-r09 (latest) uses this sk */
+ case SG_LIB_CAT_NO_SENSE: /* earlier SAT drafts used this */
/* XXX: Until the spec decides which one to go with. 20060607 */
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
- SAT_STATUS_RETURN_DESC);
- if (NULL == ucp)
+ SAT_ATA_RETURN_DESC);
+ if (NULL == ucp) {
+ if (verbose > 1)
+ printf("ATA Return Descriptor expected in sense but not "
+ "found\n");
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
- else if (verbose)
- sg_chk_n_print3("status return descriptor, as expected",
+ } else if (verbose)
+ sg_chk_n_print3("ATA Return Descriptor, as expected",
&io_hdr, 1);
if (ucp && ucp[3]) {
if (ucp[3] & 0x4)
@@ -166,11 +171,11 @@ int main(int argc, char * argv[])
default:
fprintf(stderr, "unexpected SCSI sense category\n");
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
- SAT_STATUS_RETURN_DESC);
+ SAT_ATA_RETURN_DESC);
if (NULL == ucp)
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
else if (verbose)
- sg_chk_n_print3("status return descriptor, as expected",
+ sg_chk_n_print3("ATA Return Descriptor, as expected",
&io_hdr, 1);
if (ucp && ucp[3]) {
if (ucp[3] & 0x4)
@@ -203,8 +208,8 @@ int main(int argc, char * argv[])
break;
}
} else
- fprintf(stderr, "Expecting a special error return and didn't "
- "receive it\n");
+ fprintf(stderr, "Expecting a ATA Return Descriptor in sense and "
+ "didn't receive it\n");
close(sg_fd);
return 0;
diff --git a/examples/sg_sat_set_features.c b/examples/sg_sat_set_features.c
index d0b82adb..0ae6738d 100644
--- a/examples/sg_sat_set_features.c
+++ b/examples/sg_sat_set_features.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006 Douglas Gilbert.
+ * Copyright (c) 2006-2007 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -50,13 +50,13 @@
#define SAT_ATA_PASS_THROUGH16 0x85
#define SAT_ATA_PASS_THROUGH16_LEN 16
-#define SAT_STATUS_RETURN_DESC 9 /* ATA status return (sense) descriptor */
+#define SAT_ATA_RETURN_DESC 9 /* ATA Return (sense) Descriptor */
#define ATA_SET_FEATURES 0xef
#define EBUFF_SZ 256
-static char * version_str = "1.01 20061014";
+static char * version_str = "1.02 20070130";
int main(int argc, char * argv[])
{
@@ -106,6 +106,8 @@ int main(int argc, char * argv[])
++verbose;
else if (0 == strcmp(argv[k], "-vv"))
verbose += 2;
+ else if (0 == strcmp(argv[k], "-vvv"))
+ verbose += 3;
else if (0 == strcmp(argv[k], "-V")) {
fprintf(stderr, "version: %s\n", version_str);
exit(0);
@@ -176,15 +178,17 @@ int main(int argc, char * argv[])
switch (sg_err_category3(&io_hdr)) {
case SG_LIB_CAT_CLEAN:
break;
- case SG_LIB_CAT_RECOVERED:
- case SG_LIB_CAT_NO_SENSE:
- /* XXX: Until the spec decides which one to go with. 20060607 */
+ case SG_LIB_CAT_RECOVERED: /* sat-r09 uses this sk */
+ case SG_LIB_CAT_NO_SENSE: /* earlier SAT drafts used this */
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
- SAT_STATUS_RETURN_DESC);
- if (NULL == ucp)
+ SAT_ATA_RETURN_DESC);
+ if (NULL == ucp) {
+ if (verbose > 1)
+ printf("ATA Return Descriptor expected in sense but not "
+ "found\n");
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
- else if (verbose)
- sg_chk_n_print3("status return descriptor", &io_hdr, 1);
+ } else if (verbose)
+ sg_chk_n_print3("ATA Return Descriptor", &io_hdr, 1);
if (ucp && ucp[3]) {
if (ucp[3] & 0x4)
printf("error in returned FIS: aborted command\n");
@@ -195,11 +199,11 @@ int main(int argc, char * argv[])
default:
fprintf(stderr, "unexpected SCSI sense category\n");
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
- SAT_STATUS_RETURN_DESC);
+ SAT_ATA_RETURN_DESC);
if (NULL == ucp)
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
else if (verbose)
- sg_chk_n_print3("status return descriptor, as expected",
+ sg_chk_n_print3("ATA Return Descriptor, as expected",
&io_hdr, 1);
if (ucp && ucp[3]) {
if (ucp[3] & 0x4)
diff --git a/examples/sg_sat_smart_rd_data.c b/examples/sg_sat_smart_rd_data.c
index a5122baf..dcf4b41e 100644
--- a/examples/sg_sat_smart_rd_data.c
+++ b/examples/sg_sat_smart_rd_data.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006 Douglas Gilbert.
+ * Copyright (c) 2006-2007 Douglas Gilbert.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -49,7 +49,7 @@
#define SAT_ATA_PASS_THROUGH16 0x85
#define SAT_ATA_PASS_THROUGH16_LEN 16
-#define SAT_STATUS_RETURN_DESC 9 /* ATA status return (sense) descriptor */
+#define SAT_ATA_RETURN_DESC 9 /* ATA Return (sense) Descriptor */
#define ATA_SMART 0xb0
#define ATA_SMART_READ_DATA 0xd0
@@ -57,7 +57,7 @@
#define EBUFF_SZ 256
-static char * version_str = "1.01 20061014";
+static char * version_str = "1.02 20070130";
int main(int argc, char * argv[])
{
@@ -84,6 +84,8 @@ int main(int argc, char * argv[])
++verbose;
else if (0 == strcmp(argv[k], "-vv"))
verbose += 2;
+ else if (0 == strcmp(argv[k], "-vvv"))
+ verbose += 3;
else if (0 == strcmp(argv[k], "-V")) {
fprintf(stderr, "version: %s\n", version_str);
exit(0);
@@ -157,12 +159,14 @@ int main(int argc, char * argv[])
break;
case SG_LIB_CAT_RECOVERED:
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
- SAT_STATUS_RETURN_DESC);
- if (NULL == ucp)
+ SAT_ATA_RETURN_DESC);
+ if (NULL == ucp) {
+ if (verbose > 1)
+ printf("ATA Return Descriptor expected in sense but not "
+ "found\n");
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
- else if (verbose)
- sg_chk_n_print3("ATA status return descriptor",
- &io_hdr, 1);
+ } else if (verbose)
+ sg_chk_n_print3("ATA Return Descriptor", &io_hdr, 1);
if (ucp && ucp[3])
printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]);
else
diff --git a/examples/sg_simple4.c b/examples/sg_simple4.c
index 20d8d7f5..df36f3f0 100644
--- a/examples/sg_simple4.c
+++ b/examples/sg_simple4.c
@@ -97,7 +97,8 @@ int main(int argc, char * argv[])
/* since I know this program will only read from inqBuff then I use
PROT_READ rather than PROT_READ | PROT_WRITE */
- inqBuff = mmap(NULL, 8000, PROT_READ | PROT_WRITE, MAP_SHARED, sg_fd, 0);
+ inqBuff = (unsigned char *)mmap(NULL, 8000, PROT_READ | PROT_WRITE,
+ MAP_SHARED, sg_fd, 0);
if (MAP_FAILED == inqBuff) {
snprintf(ebuff, EBUFF_SZ, "sg_simple4: error using mmap() on "
"file: %s", file_name);
@@ -205,7 +206,8 @@ int main(int argc, char * argv[])
/* could call munmap(inqBuff, INQ_REPLY_LEN) here but following close()
causes this too happen anyway */
#if 1
- inqBuff2 = mmap(NULL, 8000, PROT_READ | PROT_WRITE, MAP_SHARED, sg_fd, 0);
+ inqBuff2 = (unsigned char *)mmap(NULL, 8000, PROT_READ | PROT_WRITE,
+ MAP_SHARED, sg_fd, 0);
if (MAP_FAILED == inqBuff2) {
snprintf(ebuff, EBUFF_SZ, "sg_simple4: error using mmap() 2 on "
"file: %s", file_name);