diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2007-06-27 03:26:00 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2007-06-27 03:26:00 +0000 |
commit | 543a9ec553506a206d3191503ed6a24ac7721101 (patch) | |
tree | 3b2b9a102e67f38a89a5a54c21e5d125cb1c8d3a /examples | |
parent | 71e6e2d40657e63b9c20dc68f5e307639ef19c21 (diff) | |
download | sg3_utils-543a9ec553506a206d3191503ed6a24ac7721101.tar.gz |
Load sg3_utils-1.22 into trunk/.
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@71 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile | 8 | ||||
-rw-r--r-- | examples/Makefile.freebsd | 3 | ||||
-rw-r--r-- | examples/reassign_addr.txt | 4 | ||||
-rw-r--r-- | examples/sdiag_sas_p0_cjtpat.txt | 7 | ||||
-rw-r--r-- | examples/sdiag_sas_p1_cjtpat.txt | 8 | ||||
-rw-r--r-- | examples/sdiag_sas_p1_stop.txt | 11 | ||||
-rw-r--r-- | examples/sg__sat_identify.c (renamed from examples/sg_sat_identify.c) | 14 | ||||
-rwxr-xr-x | examples/sg_persist_tst.sh | 20 | ||||
-rw-r--r-- | examples/sg_sat_chk_power.c | 6 | ||||
-rw-r--r-- | examples/sg_sat_set_features.c | 215 | ||||
-rw-r--r-- | examples/sg_sat_smart_rd_data.c | 6 |
11 files changed, 274 insertions, 28 deletions
diff --git a/examples/Makefile b/examples/Makefile index 4a71efb0..f44381d8 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -9,7 +9,8 @@ LD = gcc EXECS = sg_simple1 sg_simple2 sg_simple3 sg_simple4 sg_simple16 \ sg_iovec_tst scsi_inquiry sg_excl sg_sense_test sg_simple5 \ - sg_sat_identify sg_sat_chk_power sg_sat_smart_rd_data + sg__sat_identify sg_sat_chk_power sg_sat_smart_rd_data \ + sg_sat_set_features # EXECS = sg_simple1 sg_simple2 sg_simple3 sg_simple4 sg_simple16 \ # sg_simple_aio sg_iovec_tst scsi_inquiry sg_excl @@ -67,7 +68,7 @@ sg_sense_test: sg_sense_test.o ../sg_lib.o ../sg_io_linux.o sg_simple5: sg_simple5.o ../sg_lib.o ../sg_pt_linux.o $(LD) -o $@ $(LDFLAGS) $^ -sg_sat_identify: sg_sat_identify.o ../sg_lib.o ../sg_io_linux.o +sg__sat_identify: sg__sat_identify.o ../sg_lib.o ../sg_io_linux.o $(LD) -o $@ $(LDFLAGS) $^ sg_sat_chk_power: sg_sat_chk_power.o ../sg_lib.o ../sg_io_linux.o @@ -76,6 +77,9 @@ sg_sat_chk_power: sg_sat_chk_power.o ../sg_lib.o ../sg_io_linux.o sg_sat_smart_rd_data: sg_sat_smart_rd_data.o ../sg_lib.o ../sg_io_linux.o $(LD) -o $@ $(LDFLAGS) $^ +sg_sat_set_features: sg_sat_set_features.o ../sg_lib.o ../sg_io_linux.o + $(LD) -o $@ $(LDFLAGS) $^ + install: $(EXECS) install -d $(INSTDIR) for name in $^; \ diff --git a/examples/Makefile.freebsd b/examples/Makefile.freebsd index 36d10ff7..966af32c 100644 --- a/examples/Makefile.freebsd +++ b/examples/Makefile.freebsd @@ -21,6 +21,7 @@ CFLAGS = -g -O2 -Wall -W $(EXTRA_FLAGS) CFLAGS_PTHREADS = -D_REENTRANT +D_FILES = ../sg_lib.o ../sg_pt_freebsd.o O_FILES = sg_lib.o sg_pt_freebsd.o LDFLAGS = -lcam @@ -36,7 +37,7 @@ clean: /bin/rm -f *.o $(EXECS) core* .depend *.a *.la *.lo /bin/rm -rf .libs -sg_simple5: sg_simple5.o $(O_FILES) +sg_simple5: sg_simple5.o $(D_FILES) $(LD) -o $@ $(LDFLAGS) $@.o $(O_FILES) install: $(EXECS) diff --git a/examples/reassign_addr.txt b/examples/reassign_addr.txt index 9daf91a7..47915852 100644 --- a/examples/reassign_addr.txt +++ b/examples/reassign_addr.txt @@ -3,9 +3,9 @@ # either the '--address=-" or "-a -" option is given on the command line. # To see logical block addresses placed in the command parameter block -# without executing the command try something like: +# without executing them command try something like: # 'sg_reassign --address=- -d -vv /dev/sda < reassign_addr.txt 1,34,0x33,0X444 0x89abcde 0xdeadbeef # 6 lba's -# dpg 20050109 +# dpg 20060824 diff --git a/examples/sdiag_sas_p0_cjtpat.txt b/examples/sdiag_sas_p0_cjtpat.txt index 87c3ae1a..b663ca11 100644 --- a/examples/sdiag_sas_p0_cjtpat.txt +++ b/examples/sdiag_sas_p0_cjtpat.txt @@ -1,3 +1,10 @@ +# This is the hex for a SAS protocol specific diagnostic +# page. It will attempt to put phy identifier 0 of the +# given device into CJTPAT (jitter pattern) generation mode. +# N.B. This will turn the receiver off on phy id 0. +# +# Usage example: 'sg_senddiag -pf -raw=- /dev/sg2 < {this_file}' +# 3f,6,0,1c,0,1,2,9, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, diff --git a/examples/sdiag_sas_p1_cjtpat.txt b/examples/sdiag_sas_p1_cjtpat.txt index 8259f72f..f8b09daf 100644 --- a/examples/sdiag_sas_p1_cjtpat.txt +++ b/examples/sdiag_sas_p1_cjtpat.txt @@ -1,3 +1,11 @@ +# This is the hex for a SAS protocol specific diagnostic +# page. It will attempt to put phy identifier 1 of the +# given device into CJTPAT (jitter pattern) generation mode. +# See sdiag_sas_p1_stop.txt to turn off this test pattern. +# N.B. This will turn the receiver off on phy id 1. +# +# Usage example: 'sg_senddiag -pf -raw=- /dev/sg2 < {this_file}' +# 3f,6,0,1c,1,1,2,9, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, diff --git a/examples/sdiag_sas_p1_stop.txt b/examples/sdiag_sas_p1_stop.txt new file mode 100644 index 00000000..c4046adb --- /dev/null +++ b/examples/sdiag_sas_p1_stop.txt @@ -0,0 +1,11 @@ +# This is the hex for a SAS protocol specific diagnostic +# page. It will attempt to stop phy identifier 1 of the +# given device producing a test pattern. +# N.B. This should make phy id 1 usable for SAS protocols again. +# +# Usage example: 'sg_senddiag -pf -raw=- /dev/sg2 < {this_file}' +# +3f,6,0,1c,1,0,2,9, +0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0 diff --git a/examples/sg_sat_identify.c b/examples/sg__sat_identify.c index c3fa5528..bdf4d826 100644 --- a/examples/sg_sat_identify.c +++ b/examples/sg__sat_identify.c @@ -39,13 +39,13 @@ #include "sg_lib.h" #include "sg_io_linux.h" -/* This program uses a ATA PASS THROUGH (16) SCSI command to package +/* This program uses a ATA PASS-THROUGH (16) SCSI command to package an ATA IDENTIFY DEVICE (A1h) command. If the '-p' option is given, it will package an ATA IDENTIFY PACKET DEVICE (Ech) instead (for ATAPI device like cd/dvd drives) See http://www.t10.org SAT draft at time of writing: sat-r08a.pdf - Invocation: sg_sat_identify [-p] [-v] [-V] <device> + Invocation: sg__sat_identify [-p] [-v] [-V] <device> With SAT, the user can find out whether a device is an ATA disk or an ATAPI device. The ATA Information VPD page contains a "command @@ -64,12 +64,12 @@ #define EBUFF_SZ 256 -static char * version_str = "1.01 20060629"; +static char * version_str = "1.01 20061014"; static void usage() { fprintf(stderr, "Usage: " - "sg_sat_identify [-p] [-v] [-V] <device>\n" + "sg__sat_identify [-p] [-v] [-V] <device>\n" " where: -p do IDENTIFY PACKET DEVICE (def: IDENTIFY " "DEVICE) command\n" " -v increase verbosity\n" @@ -132,12 +132,12 @@ int main(int argc, char * argv[]) if ((sg_fd = open(file_name, O_RDWR)) < 0) { snprintf(ebuff, EBUFF_SZ, - "sg_sat_identify: error opening file: %s", file_name); + "sg__sat_identify: error opening file: %s", file_name); perror(ebuff); return 1; } - /* Prepare ATA PASS THROUGH COMMAND (16) command */ + /* Prepare ATA PASS-THROUGH COMMAND (16) command */ aptCmdBlk[6] = 1; /* sector count */ aptCmdBlk[14] = (do_packet ? ATA_IDENTIFY_PACKET_DEVICE : ATA_IDENTIFY_DEVICE); @@ -167,7 +167,7 @@ int main(int argc, char * argv[]) /* io_hdr.usr_ptr = NULL; */ if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) { - perror("sg_sat_identify: SG_IO ioctl error"); + perror("sg__sat_identify: SG_IO ioctl error"); close(sg_fd); return 1; } diff --git a/examples/sg_persist_tst.sh b/examples/sg_persist_tst.sh index 0680eaed..95a09a82 100755 --- a/examples/sg_persist_tst.sh +++ b/examples/sg_persist_tst.sh @@ -1,7 +1,7 @@ #!/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. +# author's Fujitsu MAM3184 and a Seagate ST373455 disk. # N.B. make sure the device name is correct for your environment. @@ -13,46 +13,46 @@ if [ ! -n "$1" ];then exit 1 fi -echo "check if any keys are registered:" +echo ">>> check if any keys are registered:" sg_persist -k $1 sleep 1 echo -echo "register a key:" +echo ">>> register a key:" sg_persist -n --out --register --param-sark=123abc $1 sleep 1 echo -echo "now key 123abc should be registered:" +echo ">>> now key 123abc should be registered:" sg_persist -n -k $1 sleep 1 echo -echo "reserve the device (based on key 123abc):" +echo ">>> reserve the device (based on key 123abc):" 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):" +echo ">>> check if the device is reserved (it should be now):" sg_persist -n --read-reservation $1 sleep 1 echo -echo "now release reservation:" +echo ">>> now release reservation:" 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):" +echo ">>> check if the device is reserved (it should _not_ be now):" sg_persist -n --read-reservation $1 sleep 1 echo -echo "unregister key 123abc:" +echo ">>> unregister key 123abc:" sg_persist -n --out --register --param-rk=123abc $1 sleep 1 echo -echo "now key 123abc should not be registered:" +echo ">>> now key 123abc should not be registered:" sg_persist -n -k $1 sleep 1 diff --git a/examples/sg_sat_chk_power.c b/examples/sg_sat_chk_power.c index aefbdab9..355150c9 100644 --- a/examples/sg_sat_chk_power.c +++ b/examples/sg_sat_chk_power.c @@ -39,7 +39,7 @@ #include "sg_lib.h" #include "sg_io_linux.h" -/* This program performs a ATA PASS THROUGH (16) SCSI command in order +/* 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 @@ -55,7 +55,7 @@ #define EBUFF_SZ 256 -static char * version_str = "1.02 20060629"; +static char * version_str = "1.02 20061014"; int main(int argc, char * argv[]) { @@ -109,7 +109,7 @@ int main(int argc, char * argv[]) return 1; } - /* Prepare ATA PASS THROUGH COMMAND (16) command */ + /* Prepare ATA PASS-THROUGH COMMAND (16) command */ aptCmdBlk[14] = ATA_CHECK_POWER_MODE; aptCmdBlk[1] = (protocol << 1) | extend; aptCmdBlk[2] = (chk_cond << 5) | (t_dir << 3) | diff --git a/examples/sg_sat_set_features.c b/examples/sg_sat_set_features.c new file mode 100644 index 00000000..d0b82adb --- /dev/null +++ b/examples/sg_sat_set_features.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2006 Douglas Gilbert. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "sg_lib.h" +#include "sg_io_linux.h" + +/* This program performs a ATA PASS-THROUGH (16) SCSI command in order + to perform an ATA SET FEATURES command. See http://www.t10.org + SAT draft at time of writing: sat-r08a.pdf + + Invocation: + sg_sat_set_features [-c <n>] [-f <n>] [-l <n>] [-v] [-V] <device> + +*/ + +#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 ATA_SET_FEATURES 0xef + +#define EBUFF_SZ 256 + +static char * version_str = "1.01 20061014"; + +int main(int argc, char * argv[]) +{ + int sg_fd, k; + unsigned char aptCmdBlk[SAT_ATA_PASS_THROUGH16_LEN] = + {SAT_ATA_PASS_THROUGH16, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; + sg_io_hdr_t io_hdr; + char * file_name = 0; + char ebuff[EBUFF_SZ]; + unsigned char sense_buffer[64]; + int count = 0; + int feature = 0; + int lba = 0; + int verbose = 0; + int extend = 0; + int chk_cond = 0; /* set to 1 to read register(s) back */ + int protocol = 3; /* non-dat data-in */ + int t_dir = 1; /* 0 -> to device, 1 -> from device */ + int byte_block = 1; /* 0 -> bytes, 1 -> 512 byte blocks */ + int t_length = 0; /* 0 -> no data transferred, 2 -> sector count */ + const unsigned char * ucp = NULL; + + for (k = 1; k < argc; ++k) { + if (0 == strncmp(argv[k], "-c", 2)) { + count = sg_get_num(argv[++k]); + if ((count < 0) || (count > 255)) { + fprintf(stderr, "bad argument for '-c'\n"); + file_name = 0; + break; + } + } else if (0 == strncmp(argv[k], "-f", 2)) { + feature = sg_get_num(argv[++k]); + if ((feature < 0) || (feature > 255)) { + fprintf(stderr, "bad argument for '-f'\n"); + file_name = 0; + break; + } + } else if (0 == strncmp(argv[k], "-l", 2)) { + lba = sg_get_num(argv[++k]); + if (lba < 0) { + fprintf(stderr, "bad argument for '-l'\n"); + file_name = 0; + break; + } + } else if (0 == strcmp(argv[k], "-v")) + ++verbose; + else if (0 == strcmp(argv[k], "-vv")) + verbose += 2; + else if (0 == strcmp(argv[k], "-V")) { + fprintf(stderr, "version: %s\n", version_str); + exit(0); + } 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 { + fprintf(stderr, "too many arguments\n"); + file_name = 0; + break; + } + } + if (0 == file_name) { + fprintf(stderr, "Usage: 'sg_sat_set_features [-c <n>] [-f <n>] " + "[-l <n>] [-v] [-V] <device>'\n"); + return 1; + } + + if ((sg_fd = open(file_name, O_RDWR)) < 0) { + snprintf(ebuff, EBUFF_SZ, + "sg_sat_set_features: error opening file: %s", file_name); + perror(ebuff); + return 1; + } + + /* Prepare ATA PASS-THROUGH COMMAND (16) command */ + aptCmdBlk[14] = ATA_SET_FEATURES; + aptCmdBlk[1] = (protocol << 1) | extend; + aptCmdBlk[2] = (chk_cond << 5) | (t_dir << 3) | + (byte_block << 2) | t_length; + aptCmdBlk[4] = feature; + aptCmdBlk[6] = count; + aptCmdBlk[8] = lba & 0xff; + aptCmdBlk[10] = (lba >> 8) & 0xff; + aptCmdBlk[12] = (lba >> 16) & 0xff; + if (verbose) { + fprintf(stderr, " ata pass through(16) cdb: "); + for (k = 0; k < SAT_ATA_PASS_THROUGH16_LEN; ++k) + fprintf(stderr, "%02x ", aptCmdBlk[k]); + fprintf(stderr, "\n"); + } + + memset(&io_hdr, 0, sizeof(sg_io_hdr_t)); + io_hdr.interface_id = 'S'; + io_hdr.cmd_len = sizeof(aptCmdBlk); + /* io_hdr.iovec_count = 0; */ /* memset takes care of this */ + io_hdr.mx_sb_len = sizeof(sense_buffer); + io_hdr.dxfer_direction = SG_DXFER_NONE; + io_hdr.dxfer_len = 0; + io_hdr.dxferp = NULL; + io_hdr.cmdp = aptCmdBlk; + io_hdr.sbp = sense_buffer; + io_hdr.timeout = 20000; /* 20000 millisecs == 20 seconds */ + /* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */ + /* io_hdr.pack_id = 0; */ + /* io_hdr.usr_ptr = NULL; */ + + if (ioctl(sg_fd, SG_IO, &io_hdr) < 0) { + perror("sg_sat_set_features: SG_IO ioctl error"); + close(sg_fd); + return 1; + } + + /* error processing: N.B. expect check condition, no sense ... !! */ + 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 */ + ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer), + SAT_STATUS_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", &io_hdr, 1); + if (ucp && ucp[3]) { + if (ucp[3] & 0x4) + printf("error in returned FIS: aborted command\n"); + else + printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]); + } + break; + default: + fprintf(stderr, "unexpected SCSI sense category\n"); + ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer), + SAT_STATUS_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", + &io_hdr, 1); + if (ucp && ucp[3]) { + if (ucp[3] & 0x4) + printf("error in returned FIS: aborted command\n"); + else + printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]); + } + break; + } + + close(sg_fd); + return 0; +} diff --git a/examples/sg_sat_smart_rd_data.c b/examples/sg_sat_smart_rd_data.c index 5ebf1212..a5122baf 100644 --- a/examples/sg_sat_smart_rd_data.c +++ b/examples/sg_sat_smart_rd_data.c @@ -39,7 +39,7 @@ #include "sg_lib.h" #include "sg_io_linux.h" -/* This program performs a ATA PASS THROUGH (16) SCSI command in order +/* This program performs a ATA PASS-THROUGH (16) SCSI command in order to perform an ATA SMART/READ DATA command. See http://www.t10.org SAT draft at time of writing: sat-r08.pdf @@ -57,7 +57,7 @@ #define EBUFF_SZ 256 -static char * version_str = "1.01 20060629"; +static char * version_str = "1.01 20061014"; int main(int argc, char * argv[]) { @@ -112,7 +112,7 @@ int main(int argc, char * argv[]) return 1; } - /* Prepare ATA PASS THROUGH COMMAND (16) command */ + /* Prepare ATA PASS-THROUGH COMMAND (16) command */ aptCmdBlk[4] = ATA_SMART_READ_DATA; /* feature (7:0) */ aptCmdBlk[6] = 1; /* number of block (sector count) */ aptCmdBlk[10] = 0x4f; /* lba_mid (7:0) */ |