Skip to content

Commit b8a9e82

Browse files
committed
sg_decode sense: add --cdb option; add stdint.h to some headers
git-svn-id: svn://localhost/trunk@692 6180dd3e-e324-4e3e-922d-17de1ae2f315
1 parent 96055f3 commit b8a9e82

33 files changed

+784
-744
lines changed

ChangeLog

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ 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 [20160407] [svn: r691]
5+
Changelog for sg3_utils-1.43 [20160423] [svn: r692]
66
- sg_senddiag: add --timeout=SEC option
77
- sg_sanitize: add --timeout=SEC option
88
- sg_format: add --timeout=SEC option
9+
- sg_decode sense: add --cdb option
910
- sg_ses: handle 2 bit EIIOE field in aes dpage
1011
- expand join handling of SAS connectors and others
1112
- expand join debug code

doc/sg_decode_sense.8

+22-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
.TH SG_DECODE_SENSE "8" "August 2014" "sg3_utils\-1.40" SG3_UTILS
1+
.TH SG_DECODE_SENSE "8" "April 2016" "sg3_utils\-1.43" SG3_UTILS
22
.SH NAME
33
sg_decode_sense \- decode SCSI sense data
44
.SH SYNOPSIS
55
.B sg_decode_sense
6-
[\fI\-\-binary=FN\fR] [\fI\-\-file=FN\fR] [\fI\-\-help\fR]
6+
[\fI\-\-binary=FN\fR] [\fI\-\-cdb\fR] [\fI\-\-file=FN\fR] [\fI\-\-help\fR]
77
[\fI\-\-hex\fR] [\fI\-\-nospace\fR] [\fI\-\-status=SS\fR]
88
[\fI\-\-verbose\fR] [\fI\-\-version\fR] [\fI\-\-write=WFN\fR]
99
[H1 H2 H3 ...]
1010
.SH DESCRIPTION
1111
.\" Add any additional description here
1212
This utility takes SCSI sense data in binary or as a sequence of
1313
ASCII hexadecimal bytes and decodes it. The primary reference for the
14-
decoding is SPC\-3 ANSI INCITS 408-2005 and the most recent draft
15-
SPC\-4 revision 37 which can be found at http://www.t10.org and other
14+
decoding is SPC\-4 ANSI INCITS 513-2015 and the most recent draft
15+
SPC\-5 revision 8 which can be found at http://www.t10.org and other
1616
locations on the internet.
1717
.PP
1818
SCSI sense data is often found in kernel log files as a result of
@@ -22,20 +22,29 @@ Sense data could be up to 252 bytes long but typically is much shorter
2222
than that, 18 bytes long is often seen and is usually associated with
2323
the older "fixed" format sense data.
2424
.PP
25-
The sense data can be provided on the command line or in a file. If
26-
given on the command line the sense data should be a sequence of
27-
hexadecimal bytes separated by space. Alternatively a file can be
28-
given with the contents in binary or ASCII hexadecimal bytes. The
29-
latter form can contain several lines each with none, one or more
30-
ASCII hexadecimal bytes separated by space (comma or tab). The
31-
hash symbol may appear and it and the rest of the line is ignored
32-
making it useful for comments.
25+
The sense data can be provided on the command line or in a file. If given
26+
on the command line the sense data should be a sequence of hexadecimal bytes
27+
separated by space. Alternatively a file can be given with the contents in
28+
binary or ASCII hexadecimal bytes. The latter form can contain several lines
29+
each with none, one or more ASCII hexadecimal bytes separated by
30+
space (comma or tab). The hash symbol may appear and it and the rest of the
31+
line is ignored making it useful for comments.
32+
.PP
33+
If the \fI\-\-cdb\fR option is given then rather than viewing the given hex
34+
arguments as sense data, it is viewed as a SCSI command descriptor
35+
block (CDB). In this case the command name is printed out. That name is
36+
based on the first hex byte given (know as the opcode) and optionally on
37+
another field called the "service action".
3338
.SH OPTIONS
3439
Arguments to long options are mandatory for short options as well.
3540
.TP
3641
\fB\-b\fR, \fB\-\-binary\fR=\fIFN\fR
3742
the sense data is read in binary from a file called \fIFN\fR.
3843
.TP
44+
\fB\-c\fR, \fB\-\-cdb\fR
45+
treat the given string of hex arguments as bytes in a SCSI CDB and
46+
decode the command name.
47+
.TP
3948
\fB\-h\fR, \fB\-\-help\fR
4049
output the usage message then exit.
4150
.TP
@@ -123,7 +132,7 @@ Written by Douglas Gilbert.
123132
.SH "REPORTING BUGS"
124133
Report bugs to <dgilbert at interlog dot com>.
125134
.SH COPYRIGHT
126-
Copyright \(co 2010\-2014 Douglas Gilbert
135+
Copyright \(co 2010\-2016 Douglas Gilbert
127136
.br
128137
This software is distributed under a FreeBSD license. There is NO
129138
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

examples/sg__sat_set_features.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2007 Douglas Gilbert.
2+
* Copyright (c) 2006-2016 Douglas Gilbert.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,7 @@
5858

5959
#define EBUFF_SZ 256
6060

61-
static char * version_str = "1.03 20070719";
61+
static char * version_str = "1.04 20160423";
6262

6363
static struct option long_options[] = {
6464
{"count", required_argument, 0, 'c'},
@@ -117,7 +117,7 @@ int main(int argc, char * argv[])
117117
int t_dir = 1; /* 0 -> to device, 1 -> from device */
118118
int byte_block = 1; /* 0 -> bytes, 1 -> 512 byte blocks */
119119
int t_length = 0; /* 0 -> no data transferred, 2 -> sector count */
120-
const unsigned char * ucp = NULL;
120+
const unsigned char * bp = NULL;
121121

122122
memset(device_name, 0, sizeof(device_name));
123123
while (1) {
@@ -241,36 +241,36 @@ int main(int argc, char * argv[])
241241
break;
242242
case SG_LIB_CAT_RECOVERED: /* sat-r09 uses this sk */
243243
case SG_LIB_CAT_NO_SENSE: /* earlier SAT drafts used this */
244-
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
245-
SAT_ATA_RETURN_DESC);
246-
if (NULL == ucp) {
244+
bp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
245+
SAT_ATA_RETURN_DESC);
246+
if (NULL == bp) {
247247
if (verbose > 1)
248248
printf("ATA Return Descriptor expected in sense but not "
249249
"found\n");
250250
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
251251
} else if (verbose)
252252
sg_chk_n_print3("ATA Return Descriptor", &io_hdr, 1);
253-
if (ucp && ucp[3]) {
254-
if (ucp[3] & 0x4)
253+
if (bp && bp[3]) {
254+
if (bp[3] & 0x4)
255255
printf("error in returned FIS: aborted command\n");
256256
else
257-
printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]);
257+
printf("error=0x%x, status=0x%x\n", bp[3], bp[13]);
258258
}
259259
break;
260260
default:
261261
fprintf(stderr, "unexpected SCSI sense category\n");
262-
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
263-
SAT_ATA_RETURN_DESC);
264-
if (NULL == ucp)
262+
bp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
263+
SAT_ATA_RETURN_DESC);
264+
if (NULL == bp)
265265
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
266266
else if (verbose)
267267
sg_chk_n_print3("ATA Return Descriptor, as expected",
268268
&io_hdr, 1);
269-
if (ucp && ucp[3]) {
270-
if (ucp[3] & 0x4)
269+
if (bp && bp[3]) {
270+
if (bp[3] & 0x4)
271271
printf("error in returned FIS: aborted command\n");
272272
else
273-
printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]);
273+
printf("error=0x%x, status=0x%x\n", bp[3], bp[13]);
274274
}
275275
break;
276276
}

examples/sg_sat_chk_power.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2012 Douglas Gilbert.
2+
* Copyright (c) 2006-2016 Douglas Gilbert.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@
5656

5757
#define EBUFF_SZ 256
5858

59-
static const char * version_str = "1.04 20120319";
59+
static const char * version_str = "1.05 20160423";
6060

6161

6262
#if 0
@@ -112,7 +112,7 @@ int main(int argc, char * argv[])
112112
int t_dir = 1; /* 0 -> to device, 1 -> from device */
113113
int byte_block = 1; /* 0 -> bytes, 1 -> 512 byte blocks */
114114
int t_length = 0; /* 0 -> no data transferred, 2 -> sector count */
115-
const unsigned char * ucp = NULL;
115+
const unsigned char * bp = NULL;
116116

117117
for (k = 1; k < argc; ++k) {
118118
if (0 == strcmp(argv[k], "-v"))
@@ -189,43 +189,43 @@ int main(int argc, char * argv[])
189189
case SG_LIB_CAT_RECOVERED: /* sat-r09 (latest) uses this sk */
190190
case SG_LIB_CAT_NO_SENSE: /* earlier SAT drafts used this */
191191
/* XXX: Until the spec decides which one to go with. 20060607 */
192-
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
193-
SAT_ATA_RETURN_DESC);
194-
if (NULL == ucp) {
192+
bp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
193+
SAT_ATA_RETURN_DESC);
194+
if (NULL == bp) {
195195
if (verbose > 1)
196196
printf("ATA Return Descriptor expected in sense but not "
197197
"found\n");
198198
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
199199
} else if (verbose)
200200
sg_chk_n_print3("ATA Return Descriptor, as expected",
201201
&io_hdr, 1);
202-
if (ucp && ucp[3]) {
203-
if (ucp[3] & 0x4)
202+
if (bp && bp[3]) {
203+
if (bp[3] & 0x4)
204204
printf("error in returned FIS: aborted command\n");
205205
else
206-
printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]);
206+
printf("error=0x%x, status=0x%x\n", bp[3], bp[13]);
207207
}
208208
break;
209209
default:
210210
fprintf(stderr, "unexpected SCSI sense category\n");
211-
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
212-
SAT_ATA_RETURN_DESC);
213-
if (NULL == ucp)
211+
bp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
212+
SAT_ATA_RETURN_DESC);
213+
if (NULL == bp)
214214
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
215215
else if (verbose)
216216
sg_chk_n_print3("ATA Return Descriptor, as expected",
217217
&io_hdr, 1);
218-
if (ucp && ucp[3]) {
219-
if (ucp[3] & 0x4)
218+
if (bp && bp[3]) {
219+
if (bp[3] & 0x4)
220220
printf("error in returned FIS: aborted command\n");
221221
else
222-
printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]);
222+
printf("error=0x%x, status=0x%x\n", bp[3], bp[13]);
223223
}
224224
break;
225225
}
226226

227-
if (ucp) {
228-
switch (ucp[5]) { /* sector_count (7:0) */
227+
if (bp) {
228+
switch (bp[5]) { /* sector_count (7:0) */
229229
case 0xff:
230230
printf("In active mode or idle mode\n");
231231
break;
@@ -242,7 +242,7 @@ int main(int argc, char * argv[])
242242
printf("In standby mode\n");
243243
break;
244244
default:
245-
printf("unknown power mode (sector count) value=0x%x\n", ucp[5]);
245+
printf("unknown power mode (sector count) value=0x%x\n", bp[5]);
246246
break;
247247
}
248248
} else

examples/sg_sat_smart_rd_data.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2007 Douglas Gilbert.
2+
* Copyright (c) 2006-2016 Douglas Gilbert.
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -57,7 +57,7 @@
5757

5858
#define EBUFF_SZ 256
5959

60-
static char * version_str = "1.02 20070130";
60+
static char * version_str = "1.03 20160423";
6161

6262
int main(int argc, char * argv[])
6363
{
@@ -77,7 +77,7 @@ int main(int argc, char * argv[])
7777
int t_dir = 1; /* 0 -> to device, 1 -> from device */
7878
int byte_block = 1; /* 0 -> bytes, 1 -> 512 byte blocks */
7979
int t_length = 2; /* 0 -> no data transferred, 2 -> sector count */
80-
const unsigned char * ucp = NULL;
80+
const unsigned char * bp = NULL;
8181

8282
for (k = 1; k < argc; ++k) {
8383
if (0 == strcmp(argv[k], "-v"))
@@ -158,17 +158,17 @@ int main(int argc, char * argv[])
158158
ok = 1;
159159
break;
160160
case SG_LIB_CAT_RECOVERED:
161-
ucp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
162-
SAT_ATA_RETURN_DESC);
163-
if (NULL == ucp) {
161+
bp = sg_scsi_sense_desc_find(sense_buffer, sizeof(sense_buffer),
162+
SAT_ATA_RETURN_DESC);
163+
if (NULL == bp) {
164164
if (verbose > 1)
165165
printf("ATA Return Descriptor expected in sense but not "
166166
"found\n");
167167
sg_chk_n_print3("ATA_16 command error", &io_hdr, 1);
168168
} else if (verbose)
169169
sg_chk_n_print3("ATA Return Descriptor", &io_hdr, 1);
170-
if (ucp && ucp[3])
171-
printf("error=0x%x, status=0x%x\n", ucp[3], ucp[13]);
170+
if (bp && bp[3])
171+
printf("error=0x%x, status=0x%x\n", bp[3], bp[13]);
172172
else
173173
ok = 1;
174174
break;

include/sg_cmds_basic.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define SG_CMDS_BASIC_H
33

44
/*
5-
* Copyright (c) 2004-2014 Douglas Gilbert.
5+
* Copyright (c) 2004-2016 Douglas Gilbert.
66
* All rights reserved.
77
* Use of this source code is governed by a BSD-style
88
* license that can be found in the BSD_LICENSE file.
@@ -21,6 +21,8 @@
2121
* sg_warnings_strm.
2222
*/
2323

24+
#include <stdint.h>
25+
2426
#ifdef __cplusplus
2527
extern "C" {
2628
#endif

include/sg_cmds_extra.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* license that can be found in the BSD_LICENSE file.
99
*/
1010

11+
#include <stdint.h>
12+
1113
#ifdef __cplusplus
1214
extern "C" {
1315
#endif

lib/sg_cmds_extra.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
15611561
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
15621562
unsigned char sense_b[SENSE_BUFF_LEN];
15631563
unsigned char * sp;
1564-
const unsigned char * ucp;
1564+
const unsigned char * bp;
15651565
struct sg_pt_base * ptvp;
15661566
const char * cnamep;
15671567
char b[256];
@@ -1654,11 +1654,11 @@ sg_ll_ata_pt(int sg_fd, const unsigned char * cdbp, int cdb_len,
16541654
}
16551655
if (ata_return_dp && (max_ata_return_len > 0)) {
16561656
/* search for ATA return descriptor */
1657-
ucp = sg_scsi_sense_desc_find(sp, slen, 0x9);
1658-
if (ucp) {
1659-
k = ucp[1] + 2;
1657+
bp = sg_scsi_sense_desc_find(sp, slen, 0x9);
1658+
if (bp) {
1659+
k = bp[1] + 2;
16601660
k = (k > max_ata_return_len) ? max_ata_return_len : k;
1661-
memcpy(ata_return_dp, ucp, k);
1661+
memcpy(ata_return_dp, bp, k);
16621662
} else
16631663
ata_return_dp[0] = 0x0;
16641664
}

lib/sg_cmds_mmc.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ sg_ll_get_config(int sg_fd, int rt, int starting, void * resp,
186186
}
187187
} else {
188188
if ((verbose > 2) && (ret > 3)) {
189-
unsigned char * ucp;
189+
unsigned char * bp;
190190
int len;
191191

192-
ucp = (unsigned char *)resp;
193-
len = sg_get_unaligned_be32(ucp + 0);
192+
bp = (unsigned char *)resp;
193+
len = sg_get_unaligned_be32(bp + 0);
194194
if (len < 0)
195195
len = 0;
196196
len = (ret < len) ? ret : len;
@@ -279,11 +279,11 @@ sg_ll_get_performance(int sg_fd, int data_type, unsigned int starting_lba,
279279
}
280280
} else {
281281
if ((verbose > 2) && (ret > 3)) {
282-
unsigned char * ucp;
282+
unsigned char * bp;
283283
int len;
284284

285-
ucp = (unsigned char *)resp;
286-
len = sg_get_unaligned_be32(ucp + 0);
285+
bp = (unsigned char *)resp;
286+
len = sg_get_unaligned_be32(bp + 0);
287287
if (len < 0)
288288
len = 0;
289289
len = (ret < len) ? ret : len;

0 commit comments

Comments
 (0)