Skip to content

Commit 2e5c149

Browse files
committed
sg_cmds_extra: expand sg_ll_ata_pt() with ATA_PT(32); sg_sat_identify: expand to take --len=32
git-svn-id: svn://localhost/trunk@705 6180dd3e-e324-4e3e-922d-17de1ae2f315
1 parent 962f226 commit 2e5c149

File tree

10 files changed

+180
-106
lines changed

10 files changed

+180
-106
lines changed

Diff for: ChangeLog

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and
22
some description at the top of its ".c" file. All utilities in the main
33
directory have their own "man" pages. There is also a sg3_utils man page.
44

5-
Changelog for sg3_utils-1.43 [20160513] [svn: r704]
5+
Changelog for sg3_utils-1.43 [20160517] [svn: r705]
66
- sg_senddiag: add --timeout=SEC option
77
- sg_sanitize: add --timeout=SEC option
88
- sg_format: add --timeout=SEC option
@@ -40,6 +40,9 @@ Changelog for sg3_utils-1.43 [20160513] [svn: r704]
4040
- implement 'format' argument in dStrHexStr()
4141
- add Microcode activation sense descriptor spc5r10
4242
- sg_lib_data: sync asc/ascq codes with T10 20160425
43+
- sg_cmds_extra: expand sg_ll_ata_pt() to send new
44+
Ata pass-through(32) command (sat4r05)
45+
- sg_sat_identify: expand to take --len=32
4346
- rescan-scsi-bus.sh: harden code
4447
- fixes from Suse; bump version to: 20160511
4548
- 55-scsi-sg3_id.rules: fixes from Suse

Diff for: README

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,4 @@ See http://sg.danny.cz/sg/tools.html
462462

463463

464464
Douglas Gilbert
465-
4th May 2016
465+
17th May 2016

Diff for: debian/changelog

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sg3-utils (1.43-0.1) unstable; urgency=low
22

33
* New upstream version
44

5-
-- Douglas Gilbert <[email protected]> Wed, 04 May 2016 19:00:00 -0400
5+
-- Douglas Gilbert <[email protected]> Tue, 17 May 2016 22:00:00 +0200
66

77
sg3-utils (1.42-0.1) unstable; urgency=low
88

Diff for: doc/sg3_utils.8

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH SG3_UTILS "8" "April 2016" "sg3_utils\-1.43" SG3_UTILS
1+
.TH SG3_UTILS "8" "May 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg3_utils \- a package of utilities for sending SCSI commands
44
.SH SYNOPSIS
@@ -30,23 +30,26 @@ SCSI draft standards can be found at http://www.t10.org . The standards
3030
themselves can be purchased from ANSI and other standards organizations.
3131
A good overview of various SCSI standards can be seen in
3232
http://www.t10.org/scsi\-3.htm with the SCSI command sets in the upper part
33-
of the diagram. SCSI commands in common with all device types can be found
34-
in SPC of which SPC\-4 is the latest major version. Block device specific
35-
commands (e.g. as used by disks) are in SBC, those for tape drives in SSC
36-
and those for CD/DVD/BD drives in MMC.
33+
of the diagram. The highest level (i.e. most abstract) document is the SCSI
34+
Architecture Model (SAM) with SAM\-5 being the most recent standard (ANSI
35+
INCITS 447-2008) although SAM\-5 should be released soon. SCSI commands in
36+
common with all device types can be found in SPC of which SPC\-5 is the
37+
latest major version. Block device specific commands (e.g. as used by disks)
38+
are in SBC, those for tape drives in SSC and those for CD/DVD/BD drives in
39+
MMC.
3740
.PP
3841
It is becoming more common to control ATA disks with the SCSI command set.
39-
This involves the translation of SCSI commands to their corresponding
40-
ATA equivalents (and that is an imperfect mapping in some cases). The
41-
relevant standard is called SCSI to ATA Translation (SAT and SAT\-2
42-
are now standards at INCITS(ANSI) and ISO while SAT\-3 is at the draft
43-
stage). The logic to perform the command translation is often called
44-
a SAT Layer or SATL and may be within an operating system, in host bus
45-
adapter firmware or in an external device (e.g. associated with a SAS
46-
expander). See http://www.t10.org for more information.
42+
This involves the translation of SCSI commands to their corresponding ATA
43+
equivalents (and that is an imperfect mapping in some cases). The relevant
44+
standard is called SCSI to ATA Translation (SAT, SAT\-2 and SAT\-3) are
45+
now standards at INCITS(ANSI) and ISO while SAT\-4 is at the draft stage.
46+
The logic to perform the command translation is often called a SAT Layer or
47+
SATL and may be within an operating system, in host bus adapter firmware or
48+
in an external device (e.g. associated with a SAS expander). See
49+
http://www.t10.org for more information.
4750
.PP
4851
There is some support for SCSI tape devices but not for their basic
49-
commands. The reader is referred to the "mt" utility.
52+
operation. The reader is referred to the "mt" utility.
5053
.PP
5154
There are two generations of command line option usage. The newer
5255
utilities (written since July 2004) use the getopt_long() function to parse
@@ -281,9 +284,9 @@ the \fIDEVICE\fR reports a SCSI status of "condition met". Currently only
281284
the PRE\-FETCH command (see SBC\-4) yields this status.
282285
.TP
283286
.B 26
284-
the \fIDEVICE\fR reports a SCSI status of "busy". SAM\-5 defines this
285-
status as the logical unit is temporarily unable to process a command.
286-
It is recommended to re-issue the command.
287+
the \fIDEVICE\fR reports a SCSI status of "busy". SAM\-6 defines this status
288+
as the logical unit is temporarily unable to process a command. It is
289+
recommended to re\-issue the command.
287290
.TP
288291
.B 27
289292
the \fIDEVICE\fR reports a SCSI status of "task set full".

Diff for: doc/sg_sat_identify.8

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
.TH SG_SAT_IDENTIFY "8" "November 2014" "sg3_utils\-1.40" SG3_UTILS
1+
.TH SG_SAT_IDENTIFY "8" "May 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_sat_identify \- send ATA IDENTIFY DEVICE command via SCSI to ATA
44
Translation (SAT) layer
55
.SH SYNOPSIS
66
.B sg_sat_identify
77
[\fI\-\-ck_cond\fR] [\fI\-\-extend\fR] [\fI\-\-help\fR] [\fI\-\-hex\fR]
8-
[\fI\-\-indent\fR] [\fI\-\-len=\fR{16|12}] [\fI\-\-packet\fR] [\fI\-\-raw\fR]
8+
[\fI\-\-indent\fR] [\fI\-\-len=CLEN\fR] [\fI\-\-packet\fR] [\fI\-\-raw\fR]
99
[\fI\-\-readonly\fR] [\fI\-\-verbose\fR] [\fI\-\-version\fR] \fIDEVICE\fR
1010
.SH DESCRIPTION
1111
.\" Add any additional description here
@@ -21,9 +21,10 @@ adapter firmware or in some external enclosure.
2121
The SAT standard (SAT ANSI INCITS 431\-2007, prior draft: sat\-r09.pdf at
2222
www.t10.org) defines two SCSI "ATA PASS\-THROUGH" commands: one using a 16
2323
byte "cdb" and the other with a 12 byte cdb. This utility defaults to using
24-
the 16 byte cdb variant. SAT\-2 is also a standard: SAT\-2 ANSI INCITS
25-
465\-2010 and the draft prior to that is sat2r09.pdf . The SAT/-3 project
26-
has started and the most recent draft is sat3r01.pdf .
24+
the 16 byte cdb variant. SAT\-4 revision 5 added a SCSI "ATA
25+
PASS\-THROUGH(32)" command. SAT\-2 and SAT\-3 are now also standards: SAT\-2
26+
ANSI INCITS 465\-2010 and SAT\3 ANSI INCITS 517-2015 . The SAT\-4 project
27+
is ongiong and the most recent draft is sat4r05c.pdf .
2728
.SH OPTIONS
2829
Arguments to long options are mandatory for short options as well.
2930
.TP
@@ -61,15 +62,16 @@ outputs the World Wide Name (WWN) of the device. This should be a NAA\-5
6162
then "0x0000000000000000" is output. The equivalent for a SCSI disk (i.e. its
6263
logical unit name) can be found with "sg_vpd \-ii".
6364
.TP
64-
\fB\-l\fR, \fB\-\-len\fR={16|12}
65-
this is the length of the SCSI cdb used for the ATA PASS\-THROUGH commands.
66-
The argument can either be 16 or 12. The default is 16. The larger cdb
67-
size is needed for 48 bit LBA addressing of ATA devices. On the other
68-
hand some SCSI transports cannot convey SCSI commands longer than 12 bytes.
65+
\fB\-l\fR, \fB\-\-len\fR=CLEN
66+
CLEN this is the length of the SCSI cdb used for the ATA PASS\-THROUGH
67+
command. CLEN can either be 12, 16 or 32. The default is 16. The larger
68+
cdb sizes are needed for 48 bit LBA addressing of ATA devices. The ATA
69+
Auxiliary and ICC registers are only conveyed with the 32 byte cdb variant.
6970
.TP
7071
\fB\-p\fR, \fB\-\-packet\fR
7172
send an ATA IDENTIFY PACKET DEVICE command (via the SATL). The default
72-
action is to send an ATA IDENTIFY DEVICE command.
73+
action is to send an ATA IDENTIFY DEVICE command. Note that the ATAPI
74+
specification by T13 (i.e. the PACKET interface) is now obsolete.
7375
.TP
7476
\fB\-r\fR, \fB\-\-raw\fR
7577
output the ATA IDENTIFY (PACKET) DEVICE response in binary. The output
@@ -108,7 +110,7 @@ Written by Douglas Gilbert
108110
.SH "REPORTING BUGS"
109111
Report bugs to <dgilbert at interlog dot com>.
110112
.SH COPYRIGHT
111-
Copyright \(co 2006\-2014 Douglas Gilbert
113+
Copyright \(co 2006\-2016 Douglas Gilbert
112114
.br
113115
This software is distributed under a FreeBSD license. There is NO
114116
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Diff for: include/sg_cmds_extra.h

+18-16
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@ extern "C" {
2323
* a lot longer than the default timeout. */
2424

2525

26-
/* Invokes a ATA PASS-THROUGH (12 or 16) SCSI command (SAT). If cdb_len is
27-
* 12 then a ATA PASS-THROUGH (12) command is called. If cdb_len is 16 then
28-
* a ATA PASS-THROUGH (16) command is called. If cdb_len is any other value
29-
* -1 is returned. After copying from cdbp to an internal buffer, the first
30-
* byte (i.e. offset 0) is set to 0xa1 if cdb_len is 12; or is set to 0x85
31-
* if cdb_len is 16. The last byte (offset 11 or offset 15) is set to 0x0 in
32-
* the internal buffer. For data in or out transfers set dinp or doutp, and
33-
* dlen to the number of bytes to transfer. If dlen is zero then no data
34-
* transfer is assumed. If sense buffer obtained then it is written to
35-
* sensep, else sensep[0] is set to 0x0. If ATA return descriptor is obtained
36-
* then written to ata_return_dp, else ata_return_dp[0] is set to 0x0. Either
37-
* sensep or ata_return_dp (or both) may be NULL pointers. Returns SCSI
38-
* status value (>= 0) or -1 if other error. Users are expected to check the
39-
* sense buffer themselves. If available the data in resid is written to
40-
* residp. Note in SAT-2 and later, fixed format sense data may be placed in
41-
* *sensep in which case sensep[0]==0x70 .
26+
/* Invokes a ATA PASS-THROUGH (12, 16 or 32) SCSI command (SAT). This is
27+
* selected by the cdb_len argument that can take values of 12, 16 or 32
28+
* only (else -1 is returned). The byte at offset 0 (and bytes 0 to 9
29+
* inclusive for ATA PT(32)) pointed to be cdbp are ignored and apart from
30+
* the control byte, the rest is copied into an internal cdb which is then
31+
* sent to the device. The control byte is byte 11 for ATA PT(12), byte 15
32+
* for ATA PT(16) and byte 1 for ATA PT(32). If timeout_secs <= 0 then the
33+
* timeout is set to 60 seconds. For data in or out transfers set dinp or
34+
* doutp, and dlen to the number of bytes to transfer. If dlen is zero then
35+
* no data transfer is assumed. If sense buffer obtained then it is written
36+
* to sensep, else sensep[0] is set to 0x0. If ATA return descriptor is
37+
* obtained then written to ata_return_dp, else ata_return_dp[0] is set to
38+
* 0x0. Either sensep or ata_return_dp (or both) may be NULL pointers.
39+
* Returns SCSI status value (>= 0) or -1 if other error. Users are
40+
* expected to check the sense buffer themselves. If available the data in
41+
* resid is written to residp. Note in SAT-2 and later, fixed format sense
42+
* data may be placed in *sensep in which case sensep[0]==0x70, prior to
43+
* SAT-2 descriptor sense format was required (i.e. sensep[0]==0x72).
4244
*/
4345
int sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
4446
int timeout_secs, void * dinp, void * doutp, int dlen,

Diff for: lib/sg_cmds_extra.c

+58-36
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#define ATA_PT_12_CMDLEN 12
4444
#define ATA_PT_16_CMD 0x85
4545
#define ATA_PT_16_CMDLEN 16
46+
#define ATA_PT_32_SA 0x1ff0
47+
#define ATA_PT_32_CMDLEN 32
4648
#define FORMAT_UNIT_CMD 0x4
4749
#define FORMAT_UNIT_CMDLEN 6
4850
#define PERSISTENT_RESERVE_IN_CMD 0x5e
@@ -1531,23 +1533,24 @@ sg_ll_verify16(int sg_fd, int vrprotect, int dpo, int bytchk, uint64_t llba,
15311533
return ret;
15321534
}
15331535

1534-
/* Invokes a ATA PASS-THROUGH (12 or 16) SCSI command (SAT). If cdb_len
1535-
* is 12 then a ATA PASS-THROUGH (12) command is called. If cdb_len is 16
1536-
* then a ATA PASS-THROUGH (16) command is called. If cdb_len is any other
1537-
* value -1 is returned. After copying from cdbp to an internal buffer,
1538-
* the first byte (i.e. offset 0) is set to 0xa1 if cdb_len is 12; or is
1539-
* set to 0x85 if cdb_len is 16. The last byte (offset 11 or offset 15) is
1540-
* set to 0x0 in the internal buffer. If timeout_secs <= 0 then the timeout
1541-
* is set to 60 seconds. For data in or out transfers set dinp or doutp,
1542-
* and dlen to the number of bytes to transfer. If dlen is zero then no data
1543-
* transfer is assumed. If sense buffer obtained then it is written to
1544-
* sensep, else sensep[0] is set to 0x0. If ATA return descriptor is obtained
1545-
* then written to ata_return_dp, else ata_return_dp[0] is set to 0x0. Either
1546-
* sensep or ata_return_dp (or both) may be NULL pointers. Returns SCSI
1547-
* status value (>= 0) or -1 if other error. Users are expected to check the
1548-
* sense buffer themselves. If available the data in resid is written to
1549-
* residp. Note in SAT-2 and later, fixed format sense data may be placed in
1550-
* *sensep in which case sensep[0]==0x70 .
1536+
/* Invokes a ATA PASS-THROUGH (12, 16 or 32) SCSI command (SAT). This is
1537+
* selected by the cdb_len argument that can take values of 12, 16 or 32
1538+
* only (else -1 is returned). The byte at offset 0 (and bytes 0 to 9
1539+
* inclusive for ATA PT(32)) pointed to be cdbp are ignored and apart from
1540+
* the control byte, the rest is copied into an internal cdb which is then
1541+
* sent to the device. The control byte is byte 11 for ATA PT(12), byte 15
1542+
* for ATA PT(16) and byte 1 for ATA PT(32). If timeout_secs <= 0 then the
1543+
* timeout is set to 60 seconds. For data in or out transfers set dinp or
1544+
* doutp, and dlen to the number of bytes to transfer. If dlen is zero then
1545+
* no data transfer is assumed. If sense buffer obtained then it is written
1546+
* to sensep, else sensep[0] is set to 0x0. If ATA return descriptor is
1547+
* obtained then written to ata_return_dp, else ata_return_dp[0] is set to
1548+
* 0x0. Either sensep or ata_return_dp (or both) may be NULL pointers.
1549+
* Returns SCSI status value (>= 0) or -1 if other error. Users are
1550+
* expected to check the sense buffer themselves. If available the data in
1551+
* resid is written to residp. Note in SAT-2 and later, fixed format sense
1552+
* data may be placed in *sensep in which case sensep[0]==0x70, prior to
1553+
* SAT-2 descriptor sense format was required (i.e. sensep[0]==0x72).
15511554
*/
15521555
int
15531556
sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
@@ -1557,8 +1560,7 @@ sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
15571560
int * residp, int verbose)
15581561
{
15591562
int k, res, slen, duration;
1560-
unsigned char aptCmdBlk[ATA_PT_16_CMDLEN] =
1561-
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1563+
unsigned char aptCmdBlk[ATA_PT_32_CMDLEN];
15621564
unsigned char sense_b[SENSE_BUFF_LEN];
15631565
unsigned char * sp;
15641566
const unsigned char * bp;
@@ -1567,35 +1569,55 @@ sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
15671569
char b[256];
15681570
int ret = -1;
15691571

1572+
memset(aptCmdBlk, 0, sizeof(aptCmdBlk));
15701573
b[0] = '\0';
1571-
cnamep = (12 == cdb_len) ?
1572-
"ATA pass through (12)" : "ATA pass through (16)";
1573-
if ((NULL == cdbp) || ((12 != cdb_len) && (16 != cdb_len))) {
1574-
if (verbose) {
1575-
if (NULL == cdbp)
1576-
pr2ws("%s NULL cdb pointer\n", cnamep);
1577-
else
1578-
pr2ws("cdb_len must be 12 or 16\n");
1579-
}
1574+
switch (cdb_len) {
1575+
case 12:
1576+
cnamep = "ATA pass-through(12)";
1577+
aptCmdBlk[0] = ATA_PT_12_CMD;
1578+
memcpy(aptCmdBlk + 1, cdbp + 1, 10);
1579+
/* control byte at cdb[11] left at zero */
1580+
break;
1581+
case 16:
1582+
cnamep = "ATA pass-through(16)";
1583+
aptCmdBlk[0] = ATA_PT_16_CMD;
1584+
memcpy(aptCmdBlk + 1, cdbp + 1, 14);
1585+
/* control byte at cdb[15] left at zero */
1586+
break;
1587+
case 32:
1588+
cnamep = "ATA pass-through(32)";
1589+
aptCmdBlk[0] = SG_VARIABLE_LENGTH_CMD;
1590+
/* control byte at cdb[1] left at zero */
1591+
aptCmdBlk[7] = 0x18; /* length starting at next byte */
1592+
sg_put_unaligned_be16(ATA_PT_32_SA, aptCmdBlk + 8);
1593+
memcpy(aptCmdBlk + 10, cdbp + 10, 32 - 10);
1594+
break;
1595+
default:
1596+
pr2ws("cdb_len must be 12, 16 or 32\n");
1597+
return -1;
1598+
}
1599+
if (NULL == cdbp) {
1600+
if (verbose)
1601+
pr2ws("%s NULL cdb pointer\n", cnamep);
15801602
return -1;
15811603
}
1582-
aptCmdBlk[0] = (12 == cdb_len) ? ATA_PT_12_CMD : ATA_PT_16_CMD;
15831604
if (sensep && (max_sense_len >= (int)sizeof(sense_b))) {
15841605
sp = sensep;
15851606
slen = max_sense_len;
15861607
} else {
15871608
sp = sense_b;
15881609
slen = sizeof(sense_b);
15891610
}
1590-
if (12 == cdb_len)
1591-
memcpy(aptCmdBlk + 1, cdbp + 1, ((cdb_len > 11) ? 10 : (cdb_len - 1)));
1592-
else
1593-
memcpy(aptCmdBlk + 1, cdbp + 1, ((cdb_len > 15) ? 14 : (cdb_len - 1)));
15941611
if (verbose) {
15951612
pr2ws(" %s cdb: ", cnamep);
1596-
for (k = 0; k < cdb_len; ++k)
1597-
pr2ws("%02x ", aptCmdBlk[k]);
1598-
pr2ws("\n");
1613+
if (cdb_len < 32) {
1614+
for (k = 0; k < cdb_len; ++k)
1615+
pr2ws("%02x ", aptCmdBlk[k]);
1616+
pr2ws("\n");
1617+
} else {
1618+
pr2ws("\n");
1619+
dStrHexErr((const char *)aptCmdBlk, cdb_len, -1);
1620+
}
15991621
}
16001622
ptvp = construct_scsi_pt_obj();
16011623
if (NULL == ptvp) {

Diff for: sg3_utils.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fi
7979
%{_libdir}/*.la
8080

8181
%changelog
82-
* Wed May 04 2016 - dgilbert at interlog dot com
82+
* Tue May 17 2016 - dgilbert at interlog dot com
8383
- track t10 changes
8484
* sg3_utils-1.43
8585

0 commit comments

Comments
 (0)