SG_DECODE_SENSE(8) | SG3_UTILS | SG_DECODE_SENSE(8) |
sg_decode_sense - decode SCSI sense and related data
sg_decode_sense [--binary=BFN] [--cdb] [--err=ES] [--file=HFN] [--help] [--hex] [--inhex=HFN] [--ignore-first] [--json[=JO]] [--js-file=JFN] [--nodecode] [--nospace] [--status=SS] [--verbose] [--version] [--write=WFN] [H1 H2 H3 ...]
This utility takes SCSI sense data in binary or as a sequence of ASCII hexadecimal bytes and decodes it. The primary reference for the decoding is SPC-5 ANSI INCITS 502-2020 and the most recent draft SPC-6 revision 6 which can be found at https://www.t10.org and other locations on the internet.
SCSI sense data is often found in kernel log files as a result of something going wrong or may be an informative warning. It is often shown as a sequence of hexadecimal bytes, starting with 70, 71, 72, 73, f0 or f1. Sense data could be up to 252 bytes long but typically is much shorter than that, 18 bytes long is often seen and is usually associated with the older "fixed" format sense data.
The sense data can be provided on the command line or in a file. If given on the command line the sense data should be a sequence of hexadecimal bytes separated by space. Alternatively a file can be given with the contents in binary or ASCII hexadecimal bytes. The latter form can contain several lines each with none, one or more ASCII hexadecimal bytes separated by space (comma or tab). The hash symbol may appear and it and the rest of the line is ignored making it useful for comments.
If the --cdb option is given then rather than viewing the given hex arguments as sense data, it is viewed as a SCSI command descriptor block (CDB). In this case the command name is printed out. That name is based on the first hex byte given (know as the opcode) and optionally on another field called the "service action".
Another alternate action is when the --err=ES is given. ES is assumed to be an "exit status" value between 0 and 255 from one of the utilities in this package. A descriptive string is printed. Other options are ignored apart from --verbose.
When the --nodecode option is given, this utility may be used to convert a binary file to hexadecimal or vice versa. The data converted does not need to be related to SCSI sense data nor CDBs.
Arguments to long options are mandatory for short options as well.
Unlike most utilities in this package, this utility does not access a SCSI device (logical unit). This utility accesses a library associated with this package. Amongst other things the library decodes SCSI sense data.
The sg_raw utility takes a ASCII hexadecimal sequence representing a SCSI CDB. When sg_raw is given the '-vvv' option, it will attempt to decode the CDB name.
Using the option combination: "--inhex=HFN --nodecode --write=WFN" may be used to convert hexadecimal (as produced by this and other utilities in this package) to binary where the output file is WFN.
Unlike many other utilities there is no --raw option. However binary data can be input using the --binary=BFN option while binary data can be output using the --write=WFN option (in the absence of the --hex option).
Sense data is often printed out in kernel logs and sometimes on the command line when verbose or debug flags are given. It will be at least 8 bytes long, often 18 bytes long but may be longer. A sense data string might look like this:
f0 00 03 00 00 12 34 0a 00 00 00 00 11 00 00 00
00 00
Cut and paste it after the sg_decode_sense command:
sg_decode_sense f0 00 03 00 00 12 34 0a 00 00 00 00 11 00 00 00 00 00
and for this sense data the output should look like this:
Fixed format, current; Sense key: Medium Error
Additional sense: Unrecovered read error
Info fld=0x1234 [4660]
For a medium error the Info field is the logical block address (LBA) of the lowest numbered block that the associated SCSI command was not able to read (verify or write).
To convert arbitrary binary data to hex, suitable to be parsed by other sg3_utils utilities. The --nodecode option is used in this case:
sg_decode_sense -N -i vpd_zbdc.hex -w vpd_zbdc.bin
The '-HHH' will output hex to the console (stdout) in a form suitable for other utilities in this package to parse as input. And sg_decode_sense can also be used to convert from arbitrary hex to binary with:
sg_decode_sense -N -b vpd_zbdc.raw -HHH
Note that tools like hexdump and od place a counter (i.e. an index starting at 0) at the beginning of each line which is a pain when parsing hex. The '/-HHH' option(s) does not output that leading counter on each line.
The exit status of sg_decode_sense is 0 when it is successful. Otherwise see the sg3_utils(8) man page.
Written by Douglas Gilbert.
Report bugs to <dgilbert at interlog dot com>.
Copyright © 2010-2022 Douglas Gilbert
This software is distributed under a BSD-2-Clause license. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
sg_requests,sg_raw(sg3_utils)
May 2023 | sg3_utils-1.48 |