diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | doc/sg_sat_identify.8 | 12 | ||||
-rw-r--r-- | src/sg_sat_identify.c | 50 |
3 files changed, 47 insertions, 16 deletions
@@ -3,6 +3,7 @@ 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 sg3_utils-1.32 [20110510] [svn: r395] + - sg_sat_identify: add '--ident' to output WWN - sg_raw: exit status corrections - sg_decode_sense: add --nospace and --hex options - sg_logs: fix bug with large --maxlen diff --git a/doc/sg_sat_identify.8 b/doc/sg_sat_identify.8 index adbd7bf8..db1eff21 100644 --- a/doc/sg_sat_identify.8 +++ b/doc/sg_sat_identify.8 @@ -1,12 +1,12 @@ -.TH SG_SAT_IDENTIFY "8" "March 2011" "sg3_utils\-1.32" SG3_UTILS +.TH SG_SAT_IDENTIFY "8" "May 2011" "sg3_utils\-1.32" SG3_UTILS .SH NAME sg_sat_identify \- sends a ATA IDENTIFY (PACKET) DEVICE command via a SCSI to ATA Translation (SAT) layer .SH SYNOPSIS .B sg_sat_identify [\fI\-\-ck_cond\fR] [\fI\-\-extend\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR] -[\fI\-\-len=\fR16|12] [\fI\-\-packet\fR] [\fI\-\-raw\fR] [\fI\-\-verbose\fR] -[\fI\-\-version\fR] \fIDEVICE\fR +[\fI\-\-indent\fR] [\fI\-\-len=\fR16|12] [\fI\-\-packet\fR] [\fI\-\-raw\fR] +[\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR .SH DESCRIPTION .\" Add any additional description here .PP @@ -54,6 +54,12 @@ a header. When given thrice (i.e. '\-HHH') the output is in hex, grouped in 16 bit words, in a format that is acceptable for 'hdparm \-\-Istdin' to process. .TP +\fB\-i\fR, \fB\-\-indent\fR +outputs the World Wide Name (WWN) of the device. This should be a NAA-5 +64 bit number. It is output in hex prefixed with "0x". If not available +then "0x0000000000000000" is output. The equivalent for a SCSI disk (i.e. its +logical unit name) can be found with "sg_vpd -ii". +.TP \fB\-l\fR, \fB\-\-len\fR=16 | 12 this is the length of the SCSI cdb used for the ATA PASS\-THROUGH commands. The argument can either be 16 or 12. The default is 16. The larger cdb diff --git a/src/sg_sat_identify.c b/src/sg_sat_identify.c index b1483aee..31d6d9d0 100644 --- a/src/sg_sat_identify.c +++ b/src/sg_sat_identify.c @@ -11,6 +11,8 @@ #include <stdlib.h> #include <string.h> #include <getopt.h> +#define __STDC_FORMAT_MACROS 1 +#include <inttypes.h> #ifdef HAVE_CONFIG_H #include "config.h" @@ -43,7 +45,7 @@ #define EBUFF_SZ 256 -static char * version_str = "1.07 20110401"; +static char * version_str = "1.08 20110513"; static struct option long_options[] = { {"ck_cond", no_argument, 0, 'c'}, @@ -51,6 +53,7 @@ static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"hex", no_argument, 0, 'H'}, {"len", required_argument, 0, 'l'}, + {"ident", no_argument, 0, 'i'}, {"packet", no_argument, 0, 'p'}, {"raw", no_argument, 0, 'r'}, {"verbose", no_argument, 0, 'v'}, @@ -62,14 +65,18 @@ static void usage() { fprintf(stderr, "Usage: " "sg_sat_identify [--ck_cond] [--extend] [--help] [--hex] " - "[--len=16|12]\n" - " [--packet] [--raw] [--verbose] [--version] " - "DEVICE\n" + "[--ident]\n" + " [--len=16|12] [--packet] [--raw] " + "[--verbose]\n" + " [--version] DEVICE\n" " where:\n" " --ck_cond|-c sets ck_cond bit in cdb (def: 0)\n" " --extend|-e sets extend bit in cdb (def: 0)\n" " --help|-h print out usage message then exit\n" " --hex|-H output response in hex\n" + " --ident|-i output WWN prefixed by 0x, if not available " + "output\n" + " 0x0000000000000000\n" " --len=16|12 | -l 16|12 cdb length: 16 or 12 bytes " "(default: 16)\n" " --packet|-p do IDENTIFY PACKET DEVICE (def: IDENTIFY " @@ -90,10 +97,10 @@ static void dStrRaw(const char* str, int len) } static int do_identify_dev(int sg_fd, int do_packet, int cdb_len, - int ck_cond, int extend, int do_hex, int do_raw, - int verbose) + int ck_cond, int extend, int do_indent, + int do_hex, int do_raw, int verbose) { - int ok, res, ret; + int ok, j, res, ret; int protocol = 4; /* PIO data-in */ int t_dir = 1; /* 0 -> to device, 1 -> from device */ int byte_block = 1; /* 0 -> bytes, 1 -> 512 byte blocks */ @@ -111,6 +118,8 @@ static int do_identify_dev(int sg_fd, int do_packet, int cdb_len, unsigned char apt12CmdBlk[SAT_ATA_PASS_THROUGH12_LEN] = {SAT_ATA_PASS_THROUGH12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const unsigned short * usp; + uint64_t ull; sb_sz = sizeof(sense_buffer); memset(sense_buffer, 0, sb_sz); @@ -246,10 +255,21 @@ static int do_identify_dev(int sg_fd, int do_packet, int cdb_len, if (do_raw) dStrRaw((const char *)inBuff, 512); else if (0 == do_hex) { - printf("Response for IDENTIFY %sDEVICE ATA command:\n", - (do_packet ? "PACKET " : "")); - dWordHex((const unsigned short *)inBuff, 256, 0, - sg_is_big_endian()); + if (do_indent) { + usp = (const unsigned short *)inBuff; + ull = 0; + for (j = 0; j < 4; ++j) { + if (j > 0) + ull <<= 16; + ull |= usp[108 + j]; + } + printf("0x%016" PRIx64 "\n", ull); + } else { + printf("Response for IDENTIFY %sDEVICE ATA command:\n", + (do_packet ? "PACKET " : "")); + dWordHex((const unsigned short *)inBuff, 256, 0, + sg_is_big_endian()); + } } else if (1 == do_hex) dStrHex((const char *)inBuff, 512, 0); else if (2 == do_hex) @@ -269,6 +289,7 @@ int main(int argc, char * argv[]) int cdb_len = SAT_ATA_PASS_THROUGH16_LEN; int do_packet = 0; int do_hex = 0; + int do_indent = 0; int do_raw = 0; int verbose = 0; int ck_cond = 0; /* set to 1 to read register(s) back */ @@ -278,7 +299,7 @@ int main(int argc, char * argv[]) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "cehHl:prvV", long_options, + c = getopt_long(argc, argv, "cehHil:prvV", long_options, &option_index); if (c == -1) break; @@ -297,6 +318,9 @@ int main(int argc, char * argv[]) case 'H': ++do_hex; break; + case 'i': + ++do_indent; + break; case 'l': cdb_len = sg_get_num(optarg); if (! ((cdb_len == 12) || (cdb_len == 16))) { @@ -356,7 +380,7 @@ int main(int argc, char * argv[]) } ret = do_identify_dev(sg_fd, do_packet, cdb_len, ck_cond, extend, - do_hex, do_raw, verbose); + do_indent, do_hex, do_raw, verbose); res = sg_cmds_close_device(sg_fd); if (res < 0) { |