chiark / gitweb /
[PATCH] more extras/multipath updates
[elogind.git] / extras / multipath / sg_err.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "sg_include.h"
5 #include "sg_err.h"
6
7
8 /* This file is a huge cut, paste and hack from linux/drivers/scsi/constant.c
9 *  which I guess was written by:
10 *         Copyright (C) 1993, 1994, 1995 Eric Youngdale
11
12 * The rest of this is:
13 *  Copyright (C) 1999 - 2003 D. Gilbert
14 *
15 *  This program is free software; you can redistribute it and/or modify
16 *  it under the terms of the GNU General Public License as published by
17 *  the Free Software Foundation; either version 2, or (at your option)
18 *  any later version.
19 *
20 *  ASCII values for a number of symbolic constants, printing functions, etc.
21 *
22 *  Some of the tables have been updated for SCSI 2.
23 *  Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 12 18 March 2003)
24 *
25 *  Version 0.91 (20030529)
26 *      sense key specific field (bytes 15-17) decoding [Trent Piepho]
27 */
28
29 #define OUTP stderr
30
31 static const unsigned char scsi_command_size[8] = { 6, 10, 10, 12,
32                                                    16, 12, 10, 10 };
33
34 #define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
35
36 static const char unknown[] = "UNKNOWN";
37
38 static const char * group_0_commands[] = {
39 /* 00-03 */ "Test Unit Ready", "Rezero Unit", unknown, "Request Sense",
40 /* 04-07 */ "Format Unit", "Read Block Limits", unknown, "Reasssign Blocks",
41 /* 08-0d */ "Read (6)", unknown, "Write (6)", "Seek (6)", unknown, unknown,
42 /* 0e-12 */ unknown, "Read Reverse", "Write Filemarks", "Space", "Inquiry",
43 /* 13-16 */ "Verify", "Recover Buffered Data", "Mode Select", "Reserve",
44 /* 17-1b */ "Release", "Copy", "Erase", "Mode Sense", "Start/Stop Unit",
45 /* 1c-1d */ "Receive Diagnostic", "Send Diagnostic",
46 /* 1e-1f */ "Prevent/Allow Medium Removal", unknown,
47 };
48
49
50 static const char *group_1_commands[] = {
51 /* 20-23 */  unknown, unknown, unknown, "Read Format capacities",
52 /* 24-28 */ "Set window", "Read Capacity",
53             unknown, unknown, "Read (10)",
54 /* 29-2d */ "Read Generation", "Write (10)", "Seek (10)", "Erase",
55             "Read updated block",
56 /* 2e-31 */ "Write Verify","Verify", "Search High", "Search Equal",
57 /* 32-34 */ "Search Low", "Set Limits", "Prefetch or Read Position",
58 /* 35-37 */ "Synchronize Cache","Lock/Unlock Cache", "Read Defect Data",
59 /* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer",
60             "Read Buffer",
61 /* 3d-3f */ "Update Block", "Read Long",  "Write Long",
62 };
63
64 static const char *group_2_commands[] = {
65 /* 40-41 */ "Change Definition", "Write Same",
66 /* 42-48 */ "Read sub-channel", "Read TOC", "Read header",
67             "Play audio (10)", "Get configuration", "Play audio msf",
68             "Play audio track/index",
69 /* 49-4f */ "Play track relative (10)", "Get event status notification",
70             "Pause/resume", "Log Select", "Log Sense", "Stop play/scan",
71             unknown,
72 /* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info",
73             "Reserve track", "Send OPC onfo", "Mode Select (10)",
74 /* 56-5b */ "Reserve (10)", "Release (10)", "Repair track", "Read master cue",
75             "Mode Sense (10)", "Close track/session",
76 /* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in",
77             "Persistent reserve out",
78 };
79
80 /* The following are 16 byte commands in group 4 */
81 static const char *group_4_commands[] = {
82 /* 80-84 */ "Xdwrite (16)", "Rebuild (16)", "Regenerate (16)", "Extended copy",
83             "Receive copy results",
84 /* 85-89 */ "Memory Export In (16)", "Access control in", "Access control out",
85             "Read (16)", "Memory Export Out (16)",
86 /* 8a-8f */ "Write (16)", unknown, "Read attributes", "Write attributes",
87             "Write and verify (16)", "Verify (16)",
88 /* 90-94 */ "Pre-fetch (16)", "Synchronize cache (16)",
89             "Lock/unlock cache (16)", "Write same (16)", unknown,
90 /* 95-99 */ unknown, unknown, unknown, unknown, unknown,
91 /* 9a-9f */ unknown, unknown, unknown, unknown, "Service action in",
92             "Service action out",
93 };
94
95 /* The following are 12 byte commands in group 5 */
96 static const char *group_5_commands[] = {
97 /* a0-a5 */ "Report luns", "Blank", "Send event", "Maintenance (in)",
98             "Maintenance (out)", "Move medium/play audio(12)",
99 /* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)",
100             "Play track relative(12)",
101 /* aa-ae */ "Write(12)", unknown, "Erase(12), Get Performance",
102             "Read DVD structure", "Write and verify(12)",
103 /* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)",
104 /* b2-b4 */ "Search data low(12)", "Set limits(12)",
105             "Read element status attached",
106 /* b5-b6 */ "Request volume element address", "Send volume tag, set streaming",
107 /* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf",
108 /* ba-bc */ "Redundancy group (in), Scan",
109             "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd",
110 /* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd",
111             "Volume set (out), Send DVD structure",
112 };
113
114
115 #define group(opcode) (((opcode) >> 5) & 7)
116
117 #define RESERVED_GROUP  0
118 #define VENDOR_GROUP    1
119
120 static const char **commands[] = {
121     group_0_commands, group_1_commands, group_2_commands,
122     (const char **) RESERVED_GROUP, group_4_commands,
123     group_5_commands, (const char **) VENDOR_GROUP,
124     (const char **) VENDOR_GROUP
125 };
126
127 static const char reserved[] = "RESERVED";
128 static const char vendor[] = "VENDOR SPECIFIC";
129
130 static void print_opcode(int opcode) {
131     const char **table = commands[ group(opcode) ];
132
133     switch ((unsigned long) table) {
134     case RESERVED_GROUP:
135         fprintf(OUTP, "%s(0x%02x)", reserved, opcode);
136         break;
137     case VENDOR_GROUP:
138         fprintf(OUTP, "%s(0x%02x)", vendor, opcode);
139         break;
140     default:
141         fprintf(OUTP, "%s",table[opcode & 0x1f]);
142         break;
143     }
144 }
145
146 void sg_print_command (const unsigned char * command) {
147     int k, s;
148     print_opcode(command[0]);
149     fprintf(OUTP, " [");
150     for (k = 0, s = COMMAND_SIZE(command[0]); k < s; ++k)
151         fprintf(OUTP, "%02x ", command[k]);
152     fprintf(OUTP, "]\n");
153 }
154
155 void sg_print_status(int masked_status) 
156 {
157     int scsi_status = (masked_status << 1) & 0x7e;
158
159     sg_print_scsi_status(scsi_status);
160 }
161
162 void sg_print_scsi_status(int scsi_status) 
163 {
164     const char * ccp;
165
166     scsi_status &= 0x7e; /* sanitize as much as possible */
167     switch (scsi_status) {
168         case 0: ccp = "Good"; break;
169         case 0x2: ccp = "Check Condition"; break;
170         case 0x4: ccp = "Condition Met"; break;
171         case 0x8: ccp = "Busy"; break;
172         case 0x10: ccp = "Intermediate"; break;
173         case 0x14: ccp = "Intermediate-Condition Met"; break;
174         case 0x18: ccp = "Reservation Conflict"; break;
175         case 0x22: ccp = "Command Terminated (obsolete)"; break;
176         case 0x28: ccp = "Task set Full"; break;
177         case 0x30: ccp = "ACA Active"; break;
178         case 0x40: ccp = "Task Aborted"; break;
179         default: ccp = "Unknown status"; break;
180     }
181     fprintf(OUTP, "%s ", ccp);
182 }
183
184 /* In brackets is the related SCSI document (see www.t10.org) with the */
185 /* peripheral device type after the colon */
186 /* No programmatic use is made of these flags currently */
187 #define D 0x0001  /* DIRECT ACCESS DEVICE (disk) [SBC-2: 0] */
188 #define T 0x0002  /* SEQUENTIAL ACCESS DEVICE (tape) [SSC: 1] */
189 #define L 0x0004  /* PRINTER DEVICE [SSC: 2] */
190 #define P 0x0008  /* PROCESSOR DEVICE [SPC-2: 3] */
191 #define W 0x0010  /* WRITE ONCE READ MULTIPLE DEVICE [SBC-2: 4] */
192 #define R 0x0020  /* CD/DVD DEVICE [MMC-2: 5] */
193 #define S 0x0040  /* SCANNER DEVICE [SCSI-2 (obsolete): 6] */
194 #define O 0x0080  /* OPTICAL MEMORY DEVICE [SBC-2: 7] */
195 #define M 0x0100  /* MEDIA CHANGER DEVICE [SMC-2: 8] */
196 #define C 0x0200  /* COMMUNICATION DEVICE [SCSI-2 (obsolete): 9] */
197 #define A 0x0400  /* ARRAY STORAGE [SCC-2: 12] */
198 #define E 0x0800  /* ENCLOSURE SERVICES DEVICE [SES: 13] */
199 #define B 0x1000  /* SIMPLIFIED DIRECT ACCESS DEVICE [RBC: 14] */
200 #define K 0x2000  /* OPTICAL CARD READER/WRITER DEVICE [OCRW: 15] */
201
202 #define SC_ALL_DEVS ( D|T|L|P|W|R|S|O|M|C|A|E|B|K )
203
204 /* oft used strings are encoded using ASCII codes 0x1 to 0x1f . */
205 /* This is to save space. This encoding should be UTF-8 and */
206 /* UTF-16 friendly. */
207 #define SC_AUDIO_PLAY_OPERATION "\x1"
208 #define SC_LOGICAL_UNIT "\x2"
209 #define SC_NOT_READY "\x3"
210 #define SC_OPERATION "\x4"
211 #define SC_IN_PROGRESS "\x5"
212 #define SC_HARDWARE_IF "\x6"
213 #define SC_CONTROLLER_IF "\x7"
214 #define SC_DATA_CHANNEL_IF "\x8"
215 #define SC_SERVO_IF "\x9"
216 #define SC_SPINDLE_IF "\xa"
217 #define SC_FIRMWARE_IF "\xb"
218 #define SC_RECOVERED_DATA "\xc"
219 #define SC_ERROR_RATE_TOO_HIGH "\xd"
220 #define SC_TIMES_TOO_HIGH "\xe"
221
222
223 struct error_info{
224     unsigned char code1, code2;
225     unsigned short int devices;
226     const char * text;
227 };
228
229 struct error_info2{
230     unsigned char code1, code2_min, code2_max;
231     unsigned short int devices;
232     const char * text;
233 };
234
235 static struct error_info2 additional2[] =
236 {
237   {0x40,0x00,0x7f,D,"Ram failure (%x)"},
238   {0x40,0x80,0xff,D|T|L|P|W|R|S|O|M|C,"Diagnostic failure on component (%x)"},
239   {0x41,0x00,0xff,D,"Data path failure (%x)"},
240   {0x42,0x00,0xff,D,"Power-on or self-test failure (%x)"},
241   {0, 0, 0, 0, NULL}
242 };
243
244 static struct error_info additional[] =
245 {
246   {0x00,0x00,SC_ALL_DEVS,"No additional sense information"},
247   {0x00,0x01,T,"Filemark detected"},
248   {0x00,0x02,T|S,"End-of-partition/medium detected"},
249   {0x00,0x03,T,"Setmark detected"},
250   {0x00,0x04,T|S,"Beginning-of-partition/medium detected"},
251   {0x00,0x05,T|L|S,"End-of-data detected"},
252   {0x00,0x06,SC_ALL_DEVS,"I/O process terminated"},
253   {0x00,0x11,R,SC_AUDIO_PLAY_OPERATION SC_IN_PROGRESS},
254   {0x00,0x12,R,SC_AUDIO_PLAY_OPERATION "paused"},
255   {0x00,0x13,R,SC_AUDIO_PLAY_OPERATION "successfully completed"},
256   {0x00,0x14,R,SC_AUDIO_PLAY_OPERATION "stopped due to error"},
257   {0x00,0x15,R,"No current audio status to return"},
258   {0x00,0x16,SC_ALL_DEVS,SC_OPERATION SC_IN_PROGRESS},
259   {0x00,0x17,D|T|L|W|R|S|O|M|A|E|B|K,"Cleaning requested"},
260   {0x00,0x18,T,"Erase" SC_OPERATION SC_IN_PROGRESS},
261   {0x00,0x19,T,"Locate" SC_OPERATION SC_IN_PROGRESS},
262   {0x00,0x1a,T,"Rewind" SC_OPERATION SC_IN_PROGRESS},
263   {0x00,0x1b,T,"Set capacity" SC_OPERATION SC_IN_PROGRESS},
264   {0x00,0x1c,T,"Verify" SC_OPERATION SC_IN_PROGRESS},
265   {0x01,0x00,D|W|O|B|K,"No index/sector signal"},
266   {0x02,0x00,D|W|R|O|M|B|K,"No seek complete"},
267   {0x03,0x00,D|T|L|W|S|O|B|K,"Peripheral device write fault"},
268   {0x03,0x01,T,"No write current"},
269   {0x03,0x02,T,"Excessive write errors"},
270   {0x04,0x00,SC_ALL_DEVS,SC_LOGICAL_UNIT SC_NOT_READY "cause not reportable"},
271   {0x04,0x01,SC_ALL_DEVS,SC_LOGICAL_UNIT "is" SC_IN_PROGRESS 
272                 "of becoming ready"},
273   {0x04,0x02,SC_ALL_DEVS,SC_LOGICAL_UNIT SC_NOT_READY 
274                 "initializing cmd. required"},
275   {0x04,0x03,SC_ALL_DEVS,SC_LOGICAL_UNIT SC_NOT_READY 
276                 "manual intervention required"},
277   {0x04,0x04,D|T|L|R|O|B,SC_LOGICAL_UNIT SC_NOT_READY "format" SC_IN_PROGRESS},
278   {0x04,0x05,D|T|W|O|M|C|A|B|K,SC_LOGICAL_UNIT SC_NOT_READY 
279                 "rebuild" SC_IN_PROGRESS},
280   {0x04,0x06,D|T|W|O|M|C|A|B|K,SC_LOGICAL_UNIT SC_NOT_READY 
281                 "recalculation" SC_IN_PROGRESS},
282   {0x04,0x07,SC_ALL_DEVS,SC_LOGICAL_UNIT SC_NOT_READY 
283                 SC_OPERATION SC_IN_PROGRESS},
284   {0x04,0x08,R,SC_LOGICAL_UNIT SC_NOT_READY "long write" SC_IN_PROGRESS},
285   {0x04,0x09,SC_ALL_DEVS,SC_LOGICAL_UNIT SC_NOT_READY "self-test" 
286                 SC_IN_PROGRESS},
287   {0x04,0x0a,SC_ALL_DEVS,SC_LOGICAL_UNIT 
288                 "not accessible, asymmetric access state transition"},
289   {0x04,0x0b,SC_ALL_DEVS,SC_LOGICAL_UNIT 
290                 "not accessible, target port in standby state"},
291   {0x04,0x0c,SC_ALL_DEVS,SC_LOGICAL_UNIT 
292                 "not accessible, target port in unavailable state"},
293   {0x04,0x10,SC_ALL_DEVS,SC_LOGICAL_UNIT SC_NOT_READY
294                 "auxiliary memory not accessible"},
295   {0x05,0x00,D|T|L|W|R|S|O|M|C|A|E|B|K,SC_LOGICAL_UNIT 
296                 "does not respond to selection"},
297   {0x06,0x00,D|W|R|O|M|B|K,"No reference position found"},
298   {0x07,0x00,D|T|L|W|R|S|O|M|B|K,"Multiple peripheral devices selected"},
299   {0x08,0x00,D|T|L|W|R|S|O|M|C|A|E|B|K,SC_LOGICAL_UNIT "communication failure"},
300   {0x08,0x01,D|T|L|W|R|S|O|M|C|A|E|B|K,SC_LOGICAL_UNIT 
301                 "communication time-out"},
302   {0x08,0x02,D|T|L|W|R|S|O|M|C|A|E|B|K,SC_LOGICAL_UNIT 
303                 "communication parity error"},
304   {0x08,0x03,D|T|R|O|M|B|K,SC_LOGICAL_UNIT 
305                 "communication CRC error (Ultra-DMA/32)"},
306   {0x08,0x04,D|T|L|P|W|R|S|O|C|K,"Unreachable copy target"},
307   {0x09,0x00,D|T|W|R|O|B,"Track following error"},
308   {0x09,0x01,W|R|O|K,"Tracking servo failure"},
309   {0x09,0x02,W|R|O|K,"Focus servo failure"},
310   {0x09,0x03,W|R|O,"Spindle servo failure"},
311   {0x09,0x04,D|T|W|R|O|B,"Head select fault"},
312   {0x0A,0x00,SC_ALL_DEVS,"Error log overflow"},
313   {0x0B,0x00,SC_ALL_DEVS,"Warning"},
314   {0x0B,0x01,SC_ALL_DEVS,"Warning - specified temperature exceeded"},
315   {0x0B,0x02,SC_ALL_DEVS,"Warning - enclosure degraded"},
316   {0x0C,0x00,T|R|S,"Write error"},
317   {0x0C,0x01,K,"Write error - recovered with auto reallocation"},
318   {0x0C,0x02,D|W|O|B|K,"Write error - auto reallocation failed"},
319   {0x0C,0x03,D|W|O|B|K,"Write error - recommend reassignment"},
320   {0x0C,0x04,D|T|W|O|B,"Compression check miscompare error"},
321   {0x0C,0x05,D|T|W|O|B,"Data expansion occurred during compression"},
322   {0x0C,0x06,D|T|W|O|B,"Block not compressible"},
323   {0x0C,0x07,R,"Write error - recovery needed"},
324   {0x0C,0x08,R,"Write error - recovery failed"},
325   {0x0C,0x09,R,"Write error - loss of streaming"},
326   {0x0C,0x0A,R,"Write error - padding blocks added"},
327   {0x0C,0x0B,D|T|W|R|O|M|B,"Auxiliary memory write error"},
328   {0x0C,0x0C,SC_ALL_DEVS,"Write error - unexpected unsolicited data"},
329   {0x0C,0x0D,SC_ALL_DEVS,"Write error - not enough unsolicited data"},
330   {0x0D,0x00,D|T|L|P|W|R|S|O|C|A|K,
331                 "Error detected by third party temporary initiator"},
332   {0x0D,0x01,D|T|L|P|W|R|S|O|C|A|K, "Third party device failure"},
333   {0x0D,0x02,D|T|L|P|W|R|S|O|C|A|K, "Copy target device not reachable"},
334   {0x0D,0x03,D|T|L|P|W|R|S|O|C|A|K, "Incorrect copy target device"},
335   {0x0D,0x04,D|T|L|P|W|R|S|O|C|A|K, "Copy target device underrun"},
336   {0x0D,0x05,D|T|L|P|W|R|S|O|C|A|K, "Copy target device overrun"},
337   {0x10,0x00,D|W|O|B|K,"Id CRC or ECC error"},
338   {0x11,0x00,D|T|W|R|S|O|B|K,"Unrecovered read error"},
339   {0x11,0x01,D|T|W|R|S|O|B|K,"Read retries exhausted"},
340   {0x11,0x02,D|T|W|R|S|O|B|K,"Error too long to correct"},
341   {0x11,0x03,D|T|W|S|O|B|K,"Multiple read errors"},
342   {0x11,0x04,D|W|O|B|K,"Unrecovered read error - auto reallocate failed"},
343   {0x11,0x05,W|R|O|B,"L-EC uncorrectable error"},
344   {0x11,0x06,W|R|O|B,"CIRC unrecovered error"},
345   {0x11,0x07,W|O|B,"Data re-synchronization error"},
346   {0x11,0x08,T,"Incomplete block read"},
347   {0x11,0x09,T,"No gap found"},
348   {0x11,0x0A,D|T|O|B|K,"Miscorrected error"},
349   {0x11,0x0B,D|W|O|B|K,"Unrecovered read error - recommend reassignment"},
350   {0x11,0x0C,D|W|O|B|K,"Unrecovered read error - recommend rewrite the data"},
351   {0x11,0x0D,D|T|W|R|O|B,"De-compression CRC error"},
352   {0x11,0x0E,D|T|W|R|O|B,"Cannot decompress using declared algorithm"},
353   {0x11,0x0F,R,"Error reading UPC/EAN number"},
354   {0x11,0x10,R,"Error reading ISRC number"},
355   {0x11,0x11,R,"Read error - loss of streaming"},
356   {0x11,0x12,D|T|W|R|O|M|B,"Auxiliary memory read error"},
357   {0x11,0x13,SC_ALL_DEVS,"Read error - failed retransmission request"},
358   {0x12,0x00,D|W|O|B|K,"Address mark not found for id field"},
359   {0x13,0x00,D|W|O|B|K,"Address mark not found for data field"},
360   {0x14,0x00,D|T|L|W|R|S|O|B|K,"Recorded entity not found"},
361   {0x14,0x01,D|T|W|R|O|B|K,"Record not found"},
362   {0x14,0x02,T,"Filemark or setmark not found"},
363   {0x14,0x03,T,"End-of-data not found"},
364   {0x14,0x04,T,"Block sequence error"},
365   {0x14,0x05,D|T|W|O|B|K,"Record not found - recommend reassignment"},
366   {0x14,0x06,D|T|W|O|B|K,"Record not found - data auto-reallocated"},
367   {0x14,0x07,T,"Locate" SC_OPERATION " failure"},
368   {0x15,0x00,D|T|L|W|R|S|O|M|B|K,"Random positioning error"},
369   {0x15,0x01,D|T|L|W|R|S|O|M|B|K,"Mechanical positioning error"},
370   {0x15,0x02,D|T|W|R|O|B|K,"Positioning error detected by read of medium"},
371   {0x16,0x00,D|W|O|B|K,"Data synchronization mark error"},
372   {0x16,0x01,D|W|O|B|K,"Data sync error - data rewritten"},
373   {0x16,0x02,D|W|O|B|K,"Data sync error - recommend rewrite"},
374   {0x16,0x03,D|W|O|B|K,"Data sync error - data auto-reallocated"},
375   {0x16,0x04,D|W|O|B|K,"Data sync error - recommend reassignment"},
376   {0x17,0x00,D|T|W|R|S|O|B|K,SC_RECOVERED_DATA 
377                 "with no error correction applied"},
378   {0x17,0x01,D|T|W|R|S|O|B|K,SC_RECOVERED_DATA "with retries"},
379   {0x17,0x02,D|T|W|R|O|B|K,SC_RECOVERED_DATA "with positive head offset"},
380   {0x17,0x03,D|T|W|R|O|B|K,SC_RECOVERED_DATA "with negative head offset"},
381   {0x17,0x04,W|R|O|B,SC_RECOVERED_DATA "with retries and/or circ applied"},
382   {0x17,0x05,D|W|R|O|B|K,SC_RECOVERED_DATA "using previous sector id"},
383   {0x17,0x06,D|W|O|B|K,SC_RECOVERED_DATA "without ecc - data auto-reallocated"},
384   {0x17,0x07,D|W|R|O|B|K,SC_RECOVERED_DATA 
385                 "without ecc - recommend reassignment"},
386   {0x17,0x08,D|W|R|O|B|K,SC_RECOVERED_DATA "without ecc - recommend rewrite"},
387   {0x17,0x09,D|W|R|O|B|K,SC_RECOVERED_DATA "without ecc - data rewritten"},
388   {0x18,0x00,D|T|W|R|O|B|K,SC_RECOVERED_DATA "with error correction applied"},
389   {0x18,0x01,D|W|R|O|B|K,SC_RECOVERED_DATA 
390                 "with error corr. & retries applied"},
391   {0x18,0x02,D|W|R|O|B|K,SC_RECOVERED_DATA "- data auto-reallocated"},
392   {0x18,0x03,R,SC_RECOVERED_DATA "with CIRC"},
393   {0x18,0x04,R,SC_RECOVERED_DATA "with L-EC"},
394   {0x18,0x05,D|W|R|O|B|K,SC_RECOVERED_DATA "- recommend reassignment"},
395   {0x18,0x06,D|W|R|O|B|K,SC_RECOVERED_DATA "- recommend rewrite"},
396   {0x18,0x07,D|W|O|B|K,SC_RECOVERED_DATA "with ecc - data rewritten"},
397   {0x18,0x08,R,SC_RECOVERED_DATA "with linking"},
398   {0x19,0x00,D|O|K,"Defect list error"},
399   {0x19,0x01,D|O|K,"Defect list not available"},
400   {0x19,0x02,D|O|K,"Defect list error in primary list"},
401   {0x19,0x03,D|O|K,"Defect list error in grown list"},
402   {0x1A,0x00,SC_ALL_DEVS,"Parameter list length error"},
403   {0x1B,0x00,SC_ALL_DEVS,"Synchronous data transfer error"},
404   {0x1C,0x00,D|O|B|K,"Defect list not found"},
405   {0x1C,0x01,D|O|B|K,"Primary defect list not found"},
406   {0x1C,0x02,D|O|B|K,"Grown defect list not found"},
407   {0x1D,0x00,D|T|W|R|O|B|K,"Miscompare during verify" SC_OPERATION},
408   {0x1E,0x00,D|W|O|B|K,"Recovered id with ecc correction"},
409   {0x1F,0x00,D|O|K,"Partial defect list transfer"},
410   {0x20,0x00,SC_ALL_DEVS,"Invalid command" SC_OPERATION " code"},
411   {0x20,0x01,D|T|P|W|R|O|M|A|E|B|K,
412         "Access denied - initiator pending-enrolled"},
413   {0x20,0x02,D|T|P|W|R|O|M|A|E|B|K,"Access denied - no access rights"},
414   {0x20,0x03,D|T|P|W|R|O|M|A|E|B|K,"Access denied - no mgmt id key"},
415   {0x20,0x04,T,"Illegal command while in write capable state"},
416   {0x20,0x05,T,"Obsolete"},
417   {0x20,0x06,T,"Illegal command while in explicit address mode"},
418   {0x20,0x07,T,"Illegal command while in implicit address mode"},
419   {0x20,0x08,D|T|P|W|R|O|M|A|E|B|K,"Access denied - enrollment conflict"},
420   {0x20,0x09,D|T|P|W|R|O|M|A|E|B|K,"Access denied - invalid LU identifier"},
421   {0x20,0x0A,D|T|P|W|R|O|M|A|E|B|K,"Access denied - invalid proxy token"},
422   {0x20,0x0B,D|T|P|W|R|O|M|A|E|B|K,"Access denied - ACL LUN conflict"},
423   {0x21,0x00,D|T|W|R|O|M|B|K,"Logical block address out of range"},
424   {0x21,0x01,D|T|W|R|O|M|B|K,"Invalid element address"},
425   {0x21,0x02,R,"Invalid address for write"},
426   {0x22,0x00,D,"Illegal function (use 20 00,24 00,or 26 00)"},
427   {0x24,0x00,SC_ALL_DEVS,"Invalid field in cdb"},
428   {0x24,0x01,SC_ALL_DEVS,"CDB decryption error"},
429   {0x25,0x00,SC_ALL_DEVS,SC_LOGICAL_UNIT "not supported"},
430   {0x26,0x00,SC_ALL_DEVS,"Invalid field in parameter list"},
431   {0x26,0x01,SC_ALL_DEVS,"Parameter not supported"},
432   {0x26,0x02,SC_ALL_DEVS,"Parameter value invalid"},
433   {0x26,0x03,D|T|L|P|W|R|S|O|M|C|A|E|K,"Threshold parameters not supported"},
434   {0x26,0x04,SC_ALL_DEVS,"Invalid release of persistent reservation"},
435   {0x26,0x05,D|T|L|P|W|R|S|O|M|C|A|B|K,"Data decryption error"},
436   {0x26,0x06,D|T|L|P|W|R|S|O|C|K,"Too many target descriptors"},
437   {0x26,0x07,D|T|L|P|W|R|S|O|C|K,"Unsupported target descriptor type code"},
438   {0x26,0x08,D|T|L|P|W|R|S|O|C|K,"Too many segment descriptors"},
439   {0x26,0x09,D|T|L|P|W|R|S|O|C|K,"Unsupported segment descriptor type code"},
440   {0x26,0x0A,D|T|L|P|W|R|S|O|C|K,"Unexpected inexact segment"},
441   {0x26,0x0B,D|T|L|P|W|R|S|O|C|K,"Inline data length exceeded"},
442   {0x26,0x0C,D|T|L|P|W|R|S|O|C|K,
443                 "Invalid" SC_OPERATION " for copy source or destination"},
444   {0x26,0x0D,D|T|L|P|W|R|S|O|C|K,"Copy segment granularity violation"},
445   {0x27,0x00,D|T|W|R|O|B|K,"Write protected"},
446   {0x27,0x01,D|T|W|R|O|B|K,"Hardware write protected"},
447   {0x27,0x02,D|T|W|R|O|B|K,SC_LOGICAL_UNIT "software write protected"},
448   {0x27,0x03,T|R,"Associated write protect"},
449   {0x27,0x04,T|R,"Persistent write protect"},
450   {0x27,0x05,T|R,"Permanent write protect"},
451   {0x27,0x06,R,"Conditional write protect"},
452   {0x28,0x00,SC_ALL_DEVS,"Not ready to ready change, medium may have changed"},
453   {0x28,0x01,D|T|W|R|O|M|B,"Import or export element accessed"},
454   {0x29,0x00,SC_ALL_DEVS,"Power on, reset, or bus device reset occurred"},
455   {0x29,0x01,SC_ALL_DEVS,"Power on occurred"},
456   {0x29,0x02,SC_ALL_DEVS,"Scsi bus reset occurred"},
457   {0x29,0x03,SC_ALL_DEVS,"Bus device reset function occurred"},
458   {0x29,0x04,SC_ALL_DEVS,"Device internal reset"},
459   {0x29,0x05,SC_ALL_DEVS,"Transceiver mode changed to single-ended"},
460   {0x29,0x06,SC_ALL_DEVS,"Transceiver mode changed to lvd"},
461   {0x29,0x07,SC_ALL_DEVS,"I_T nexus loss occurred"},
462   {0x2A,0x00,D|T|L|W|R|S|O|M|C|A|E|B|K,"Parameters changed"},
463   {0x2A,0x01,D|T|L|W|R|S|O|M|C|A|E|B|K,"Mode parameters changed"},
464   {0x2A,0x02,D|T|L|W|R|S|O|M|C|A|E|K,"Log parameters changed"},
465   {0x2A,0x03,D|T|L|P|W|R|S|O|M|C|A|E|K,"Reservations preempted"},
466   {0x2A,0x04,D|T|L|P|W|R|S|O|M|C|A|E,"Reservations released"},
467   {0x2A,0x05,D|T|L|P|W|R|S|O|M|C|A|E,"Registrations preempted"},
468   {0x2A,0x06,SC_ALL_DEVS,"Asymmetric access state changed"},
469   {0x2A,0x07,SC_ALL_DEVS,"Implicit asymmetric access state transition failed"},
470   {0x2B,0x00,D|T|L|P|W|R|S|O|C|K,
471                 "Copy cannot execute since host cannot disconnect"},
472   {0x2C,0x00,SC_ALL_DEVS,"Command sequence error"},
473   {0x2C,0x01,S,"Too many windows specified"},
474   {0x2C,0x02,S,"Invalid combination of windows specified"},
475   {0x2C,0x03,R,"Current program area is not empty"},
476   {0x2C,0x04,R,"Current program area is empty"},
477   {0x2C,0x05,B,"Illegal power condition request"},
478   {0x2C,0x06,R,"Persistent prevent conflict"},
479   {0x2C,0x07,SC_ALL_DEVS,"Previous busy status"},
480   {0x2C,0x08,SC_ALL_DEVS,"Previous task set full status"},
481   {0x2C,0x09,D|T|L|P|W|R|S|O|M|E|B|K,"Previous reservation conflict status"},
482   {0x2D,0x00,T,"Overwrite error on update in place"},
483   {0x2F,0x00,SC_ALL_DEVS,"Commands cleared by another initiator"},
484   {0x30,0x00,D|T|W|R|O|M|B|K,"Incompatible medium installed"},
485   {0x30,0x01,D|T|W|R|O|B|K,"Cannot read medium - unknown format"},
486   {0x30,0x02,D|T|W|R|O|B|K,"Cannot read medium - incompatible format"},
487   {0x30,0x03,D|T|R|K,"Cleaning cartridge installed"},
488   {0x30,0x04,D|T|W|R|O|B|K,"Cannot write medium - unknown format"},
489   {0x30,0x05,D|T|W|R|O|B|K,"Cannot write medium - incompatible format"},
490   {0x30,0x06,D|T|W|R|O|B,"Cannot format medium - incompatible medium"},
491   {0x30,0x07,D|T|L|W|R|S|O|M|A|E|B|K,"Cleaning failure"},
492   {0x30,0x08,R,"Cannot write - application code mismatch"},
493   {0x30,0x09,R,"Current session not fixated for append"},
494   {0x30,0x10,R,"Medium not formatted"}, /* should ascq be 0xa ?? */
495   {0x31,0x00,D|T|W|R|O|B|K,"Medium format corrupted"},
496   {0x31,0x01,D|L|R|O|B,"Format command failed"},
497   {0x31,0x02,R,"Zoned formatting failed due to spare linking"},
498   {0x32,0x00,D|W|O|B|K,"No defect spare location available"},
499   {0x32,0x01,D|W|O|B|K,"Defect list update failure"},
500   {0x33,0x00,T,"Tape length error"},
501   {0x34,0x00,SC_ALL_DEVS,"Enclosure failure"},
502   {0x35,0x00,SC_ALL_DEVS,"Enclosure services failure"},
503   {0x35,0x01,SC_ALL_DEVS,"Unsupported enclosure function"},
504   {0x35,0x02,SC_ALL_DEVS,"Enclosure services unavailable"},
505   {0x35,0x03,SC_ALL_DEVS,"Enclosure services transfer failure"},
506   {0x35,0x04,SC_ALL_DEVS,"Enclosure services transfer refused"},
507   {0x36,0x00,L,"Ribbon,ink,or toner failure"},
508   {0x37,0x00,D|T|L|W|R|S|O|M|C|A|E|B|K,"Rounded parameter"},
509   {0x38,0x00,B,"Event status notification"},
510   {0x38,0x02,B,"Esn - power management class event"},
511   {0x38,0x04,B,"Esn - media class event"},
512   {0x38,0x06,B,"Esn - device busy class event"},
513   {0x39,0x00,D|T|L|W|R|S|O|M|C|A|E|K,"Saving parameters not supported"},
514   {0x3A,0x00,D|T|L|W|R|S|O|M|B|K,"Medium not present"},
515   {0x3A,0x01,D|T|W|R|O|M|B|K,"Medium not present - tray closed"},
516   {0x3A,0x02,D|T|W|R|O|M|B|K,"Medium not present - tray open"},
517   {0x3A,0x03,D|T|W|R|O|M|B,"Medium not present - loadable"},
518   {0x3A,0x04,D|T|W|R|O|M|B,
519                 "Medium not present - medium auxiliary memory accessible"},
520   {0x3B,0x00,T|L,"Sequential positioning error"},
521   {0x3B,0x01,T,"Tape position error at beginning-of-medium"},
522   {0x3B,0x02,T,"Tape position error at end-of-medium"},
523   {0x3B,0x03,L,"Tape or electronic vertical forms unit " SC_NOT_READY},
524   {0x3B,0x04,L,"Slew failure"},
525   {0x3B,0x05,L,"Paper jam"},
526   {0x3B,0x06,L,"Failed to sense top-of-form"},
527   {0x3B,0x07,L,"Failed to sense bottom-of-form"},
528   {0x3B,0x08,T,"Reposition error"},
529   {0x3B,0x09,S,"Read past end of medium"},
530   {0x3B,0x0A,S,"Read past beginning of medium"},
531   {0x3B,0x0B,S,"Position past end of medium"},
532   {0x3B,0x0C,T|S,"Position past beginning of medium"},
533   {0x3B,0x0D,D|T|W|R|O|M|B|K,"Medium destination element full"},
534   {0x3B,0x0E,D|T|W|R|O|M|B|K,"Medium source element empty"},
535   {0x3B,0x0F,R,"End of medium reached"},
536   {0x3B,0x11,D|T|W|R|O|M|B|K,"Medium magazine not accessible"},
537   {0x3B,0x12,D|T|W|R|O|M|B|K,"Medium magazine removed"},
538   {0x3B,0x13,D|T|W|R|O|M|B|K,"Medium magazine inserted"},
539   {0x3B,0x14,D|T|W|R|O|M|B|K,"Medium magazine locked"},
540   {0x3B,0x15,D|T|W|R|O|M|B|K,"Medium magazine unlocked"},
541   {0x3B,0x16,R,"Mechanical positioning or changer error"},
542   {0x3D,0x00,D|T|L|P|W|R|S|O|M|C|A|E|K,"Invalid bits in identify message"},
543   {0x3E,0x00,SC_ALL_DEVS,SC_LOGICAL_UNIT "has not self-configured yet"},
544   {0x3E,0x01,SC_ALL_DEVS,SC_LOGICAL_UNIT "failure"},
545   {0x3E,0x02,SC_ALL_DEVS,"Timeout on logical unit"},
546   {0x3E,0x03,SC_ALL_DEVS,SC_LOGICAL_UNIT "failed self-test"},
547   {0x3E,0x04,SC_ALL_DEVS,SC_LOGICAL_UNIT "unable to update self-test log"},
548   {0x3F,0x00,SC_ALL_DEVS,"Target operating conditions have changed"},
549   {0x3F,0x01,SC_ALL_DEVS,"Microcode has been changed"},
550   {0x3F,0x02,D|T|L|P|W|R|S|O|M|C|B|K,"Changed operating definition"},
551   {0x3F,0x03,SC_ALL_DEVS,"Inquiry data has changed"},
552   {0x3F,0x04,D|T|W|R|O|M|C|A|E|B|K,"Component device attached"},
553   {0x3F,0x05,D|T|W|R|O|M|C|A|E|B|K,"Device identifier changed"},
554   {0x3F,0x06,D|T|W|R|O|M|C|A|E|B,"Redundancy group created or modified"},
555   {0x3F,0x07,D|T|W|R|O|M|C|A|E|B,"Redundancy group deleted"},
556   {0x3F,0x08,D|T|W|R|O|M|C|A|E|B,"Spare created or modified"},
557   {0x3F,0x09,D|T|W|R|O|M|C|A|E|B,"Spare deleted"},
558   {0x3F,0x0A,D|T|W|R|O|M|C|A|E|B|K,"Volume set created or modified"},
559   {0x3F,0x0B,D|T|W|R|O|M|C|A|E|B|K,"Volume set deleted"},
560   {0x3F,0x0C,D|T|W|R|O|M|C|A|E|B|K,"Volume set deassigned"},
561   {0x3F,0x0D,D|T|W|R|O|M|C|A|E|B|K,"Volume set reassigned"},
562   {0x3F,0x0E,D|T|L|P|W|R|S|O|M|C|A|E,"Reported luns data has changed"},
563   {0x3F,0x10,D|T|W|R|O|M|B,"Medium loadable"},
564   {0x3F,0x11,D|T|W|R|O|M|B,"Medium auxiliary memory accessible"},
565   {0x40,0x00,D,"Ram failure (should use 40 nn)"},
566   /*
567    * FIXME(eric) - need a way to represent wildcards here.
568    */
569   {0x40,0x00,SC_ALL_DEVS,"Diagnostic failure on component nn (80h-ffh)"},
570   {0x41,0x00,D,"Data path failure (should use 40 nn)"},
571   {0x42,0x00,D,"Power-on or self-test failure (should use 40 nn)"},
572   {0x43,0x00,SC_ALL_DEVS,"Message error"},
573   {0x44,0x00,SC_ALL_DEVS,"Internal target failure"},
574   {0x45,0x00,SC_ALL_DEVS,"Select or reselect failure"},
575   {0x46,0x00,D|T|L|P|W|R|S|O|M|C|B|K,"Unsuccessful soft reset"},
576   {0x47,0x00,SC_ALL_DEVS,"Scsi parity error"},
577   {0x47,0x01,SC_ALL_DEVS,"Data phase CRC error detected"},
578   {0x47,0x02,SC_ALL_DEVS,"Scsi parity error detected during st data phase"},
579   {0x47,0x03,SC_ALL_DEVS,"Information unit CRC error detected"},
580   {0x47,0x04,SC_ALL_DEVS,"Asynchronous information protection error detected"},
581   {0x47,0x05,SC_ALL_DEVS,"Protocol service CRC error"},
582   {0x48,0x00,SC_ALL_DEVS,"Initiator detected error message received"},
583   {0x49,0x00,SC_ALL_DEVS,"Invalid message error"},
584   {0x4A,0x00,SC_ALL_DEVS,"Command phase error"},
585   {0x4B,0x00,SC_ALL_DEVS,"Data phase error"},
586   {0x4C,0x00,SC_ALL_DEVS,SC_LOGICAL_UNIT "failed self-configuration"},
587   /*
588    * FIXME(eric) - need a way to represent wildcards here.
589    */
590   {0x4D,0x00,SC_ALL_DEVS,"Tagged overlapped commands (nn = queue tag)"},
591   {0x4E,0x00,SC_ALL_DEVS,"Overlapped commands attempted"},
592   {0x50,0x00,T,"Write append error"},
593   {0x50,0x01,T,"Write append position error"},
594   {0x50,0x02,T,"Position error related to timing"},
595   {0x51,0x00,T|R|O,"Erase failure"},
596   {0x52,0x00,T,"Cartridge fault"},
597   {0x53,0x00,D|T|L|W|R|S|O|M|B|K,"Media load or eject failed"},
598   {0x53,0x01,T,"Unload tape failure"},
599   {0x53,0x02,D|T|W|R|O|M|B|K,"Medium removal prevented"},
600   {0x54,0x00,P,"Scsi to host system interface failure"},
601   {0x55,0x00,P,"System resource failure"},
602   {0x55,0x01,D|O|B|K,"System buffer full"},
603   {0x55,0x02,D|T|L|P|W|R|S|O|M|A|E|K,"Insufficient reservation resources"},
604   {0x55,0x03,D|T|L|P|W|R|S|O|M|C|A|E,"Insufficient resources"},
605   {0x55,0x04,D|T|L|P|W|R|S|O|M|A|E,"Insufficient registration resources"},
606   {0x55,0x05,D|T|P|W|R|O|M|A|E|B|K,"Insufficient access control resources"},
607   {0x55,0x06,D|T|W|R|O|M|B,"Auxiliary memory out of space"},
608   {0x57,0x00,R,"Unable to recover table-of-contents"},
609   {0x58,0x00,O,"Generation does not exist"},
610   {0x59,0x00,O,"Updated block read"},
611   {0x5A,0x00,D|T|L|P|W|R|S|O|M|B|K,"Operator request or state change input"},
612   {0x5A,0x01,D|T|W|R|O|M|B|K,"Operator medium removal request"},
613   {0x5A,0x02,D|T|W|R|O|A|B|K,"Operator selected write protect"},
614   {0x5A,0x03,D|T|W|R|O|A|B|K,"Operator selected write permit"},
615   {0x5B,0x00,D|T|L|P|W|R|S|O|M|K,"Log exception"},
616   {0x5B,0x01,D|T|L|P|W|R|S|O|M|K,"Threshold condition met"},
617   {0x5B,0x02,D|T|L|P|W|R|S|O|M|K,"Log counter at maximum"},
618   {0x5B,0x03,D|T|L|P|W|R|S|O|M|K,"Log list codes exhausted"},
619   {0x5C,0x00,D|O,"Rpl status change"},
620   {0x5C,0x01,D|O,"Spindles synchronized"},
621   {0x5C,0x02,D|O,"Spindles not synchronized"},
622   {0x5D,0x00,SC_ALL_DEVS,"Failure prediction threshold exceeded"},
623   {0x5D,0x01,R|B,"Media failure prediction threshold exceeded"},
624   {0x5D,0x02,R,SC_LOGICAL_UNIT "failure prediction threshold exceeded"},
625   {0x5D,0x03,R,"spare area exhaustion prediction threshold exceeded"},
626         /* large series of "impending failure" messages */
627   {0x5D,0x10,D|B,SC_HARDWARE_IF "general hard drive failure"},
628   {0x5D,0x11,D|B,SC_HARDWARE_IF "drive" SC_ERROR_RATE_TOO_HIGH },
629   {0x5D,0x12,D|B,SC_HARDWARE_IF "data" SC_ERROR_RATE_TOO_HIGH },
630   {0x5D,0x13,D|B,SC_HARDWARE_IF "seek" SC_ERROR_RATE_TOO_HIGH },
631   {0x5D,0x14,D|B,SC_HARDWARE_IF "too many block reassigns"},
632   {0x5D,0x15,D|B,SC_HARDWARE_IF "access" SC_TIMES_TOO_HIGH },
633   {0x5D,0x16,D|B,SC_HARDWARE_IF "start unit" SC_TIMES_TOO_HIGH },
634   {0x5D,0x17,D|B,SC_HARDWARE_IF "channel parametrics"},
635   {0x5D,0x18,D|B,SC_HARDWARE_IF "controller detected"},
636   {0x5D,0x19,D|B,SC_HARDWARE_IF "throughput performance"},
637   {0x5D,0x1A,D|B,SC_HARDWARE_IF "seek time performance"},
638   {0x5D,0x1B,D|B,SC_HARDWARE_IF "spin-up retry count"},
639   {0x5D,0x1C,D|B,SC_HARDWARE_IF "drive calibration retry count"},
640   {0x5D,0x20,D|B,SC_CONTROLLER_IF "general hard drive failure"},
641   {0x5D,0x21,D|B,SC_CONTROLLER_IF "drive" SC_ERROR_RATE_TOO_HIGH },
642   {0x5D,0x22,D|B,SC_CONTROLLER_IF "data" SC_ERROR_RATE_TOO_HIGH },
643   {0x5D,0x23,D|B,SC_CONTROLLER_IF "seek" SC_ERROR_RATE_TOO_HIGH },
644   {0x5D,0x24,D|B,SC_CONTROLLER_IF "too many block reassigns"},
645   {0x5D,0x25,D|B,SC_CONTROLLER_IF "access" SC_TIMES_TOO_HIGH },
646   {0x5D,0x26,D|B,SC_CONTROLLER_IF "start unit" SC_TIMES_TOO_HIGH },
647   {0x5D,0x27,D|B,SC_CONTROLLER_IF "channel parametrics"},
648   {0x5D,0x28,D|B,SC_CONTROLLER_IF "controller detected"},
649   {0x5D,0x29,D|B,SC_CONTROLLER_IF "throughput performance"},
650   {0x5D,0x2A,D|B,SC_CONTROLLER_IF "seek time performance"},
651   {0x5D,0x2B,D|B,SC_CONTROLLER_IF "spin-up retry count"},
652   {0x5D,0x2C,D|B,SC_CONTROLLER_IF "drive calibration retry count"},
653   {0x5D,0x30,D|B,SC_DATA_CHANNEL_IF "general hard drive failure"},
654   {0x5D,0x31,D|B,SC_DATA_CHANNEL_IF "drive" SC_ERROR_RATE_TOO_HIGH },
655   {0x5D,0x32,D|B,SC_DATA_CHANNEL_IF "data" SC_ERROR_RATE_TOO_HIGH },
656   {0x5D,0x33,D|B,SC_DATA_CHANNEL_IF "seek" SC_ERROR_RATE_TOO_HIGH },
657   {0x5D,0x34,D|B,SC_DATA_CHANNEL_IF "too many block reassigns"},
658   {0x5D,0x35,D|B,SC_DATA_CHANNEL_IF "access" SC_TIMES_TOO_HIGH },
659   {0x5D,0x36,D|B,SC_DATA_CHANNEL_IF "start unit" SC_TIMES_TOO_HIGH },
660   {0x5D,0x37,D|B,SC_DATA_CHANNEL_IF "channel parametrics"},
661   {0x5D,0x38,D|B,SC_DATA_CHANNEL_IF "controller detected"},
662   {0x5D,0x39,D|B,SC_DATA_CHANNEL_IF "throughput performance"},
663   {0x5D,0x3A,D|B,SC_DATA_CHANNEL_IF "seek time performance"},
664   {0x5D,0x3B,D|B,SC_DATA_CHANNEL_IF "spin-up retry count"},
665   {0x5D,0x3C,D|B,SC_DATA_CHANNEL_IF "drive calibration retry count"},
666   {0x5D,0x40,D|B,SC_SERVO_IF "general hard drive failure"},
667   {0x5D,0x41,D|B,SC_SERVO_IF "drive" SC_ERROR_RATE_TOO_HIGH },
668   {0x5D,0x42,D|B,SC_SERVO_IF "data" SC_ERROR_RATE_TOO_HIGH },
669   {0x5D,0x43,D|B,SC_SERVO_IF "seek" SC_ERROR_RATE_TOO_HIGH },
670   {0x5D,0x44,D|B,SC_SERVO_IF "too many block reassigns"},
671   {0x5D,0x45,D|B,SC_SERVO_IF "access" SC_TIMES_TOO_HIGH },
672   {0x5D,0x46,D|B,SC_SERVO_IF "start unit" SC_TIMES_TOO_HIGH },
673   {0x5D,0x47,D|B,SC_SERVO_IF "channel parametrics"},
674   {0x5D,0x48,D|B,SC_SERVO_IF "controller detected"},
675   {0x5D,0x49,D|B,SC_SERVO_IF "throughput performance"},
676   {0x5D,0x4A,D|B,SC_SERVO_IF "seek time performance"},
677   {0x5D,0x4B,D|B,SC_SERVO_IF "spin-up retry count"},
678   {0x5D,0x4C,D|B,SC_SERVO_IF "drive calibration retry count"},
679   {0x5D,0x50,D|B,SC_SPINDLE_IF "general hard drive failure"},
680   {0x5D,0x51,D|B,SC_SPINDLE_IF "drive" SC_ERROR_RATE_TOO_HIGH },
681   {0x5D,0x52,D|B,SC_SPINDLE_IF "data" SC_ERROR_RATE_TOO_HIGH },
682   {0x5D,0x53,D|B,SC_SPINDLE_IF "seek" SC_ERROR_RATE_TOO_HIGH },
683   {0x5D,0x54,D|B,SC_SPINDLE_IF "too many block reassigns"},
684   {0x5D,0x55,D|B,SC_SPINDLE_IF "access" SC_TIMES_TOO_HIGH },
685   {0x5D,0x56,D|B,SC_SPINDLE_IF "start unit" SC_TIMES_TOO_HIGH },
686   {0x5D,0x57,D|B,SC_SPINDLE_IF "channel parametrics"},
687   {0x5D,0x58,D|B,SC_SPINDLE_IF "controller detected"},
688   {0x5D,0x59,D|B,SC_SPINDLE_IF "throughput performance"},
689   {0x5D,0x5A,D|B,SC_SPINDLE_IF "seek time performance"},
690   {0x5D,0x5B,D|B,SC_SPINDLE_IF "spin-up retry count"},
691   {0x5D,0x5C,D|B,SC_SPINDLE_IF "drive calibration retry count"},
692   {0x5D,0x60,D|B,SC_FIRMWARE_IF "general hard drive failure"},
693   {0x5D,0x61,D|B,SC_FIRMWARE_IF "drive" SC_ERROR_RATE_TOO_HIGH },
694   {0x5D,0x62,D|B,SC_FIRMWARE_IF "data" SC_ERROR_RATE_TOO_HIGH },
695   {0x5D,0x63,D|B,SC_FIRMWARE_IF "seek" SC_ERROR_RATE_TOO_HIGH },
696   {0x5D,0x64,D|B,SC_FIRMWARE_IF "too many block reassigns"},
697   {0x5D,0x65,D|B,SC_FIRMWARE_IF "access" SC_TIMES_TOO_HIGH },
698   {0x5D,0x66,D|B,SC_FIRMWARE_IF "start unit" SC_TIMES_TOO_HIGH },
699   {0x5D,0x67,D|B,SC_FIRMWARE_IF "channel parametrics"},
700   {0x5D,0x68,D|B,SC_FIRMWARE_IF "controller detected"},
701   {0x5D,0x69,D|B,SC_FIRMWARE_IF "throughput performance"},
702   {0x5D,0x6A,D|B,SC_FIRMWARE_IF "seek time performance"},
703   {0x5D,0x6B,D|B,SC_FIRMWARE_IF "spin-up retry count"},
704   {0x5D,0x6C,D|B,SC_FIRMWARE_IF "drive calibration retry count"},
705   {0x5D,0xFF,SC_ALL_DEVS,"Failure prediction threshold exceeded (false)"},
706   {0x5E,0x00,D|T|L|P|W|R|S|O|C|A|K,"Low power condition on"},
707   {0x5E,0x01,D|T|L|P|W|R|S|O|C|A|K,"Idle condition activated by timer"},
708   {0x5E,0x02,D|T|L|P|W|R|S|O|C|A|K,"Standby condition activated by timer"},
709   {0x5E,0x03,D|T|L|P|W|R|S|O|C|A|K,"Idle condition activated by command"},
710   {0x5E,0x04,D|T|L|P|W|R|S|O|C|A|K,"Standby condition activated by command"},
711   {0x5E,0x41,B,"Power state change to active"},
712   {0x5E,0x42,B,"Power state change to idle"},
713   {0x5E,0x43,B,"Power state change to standby"},
714   {0x5E,0x45,B,"Power state change to sleep"},
715   {0x5E,0x47,B|K,"Power state change to device control"},
716   {0x60,0x00,S,"Lamp failure"},
717   {0x61,0x00,S,"Video acquisition error"},
718   {0x61,0x01,S,"Unable to acquire video"},
719   {0x61,0x02,S,"Out of focus"},
720   {0x62,0x00,S,"Scan head positioning error"},
721   {0x63,0x00,R,"End of user area encountered on this track"},
722   {0x63,0x01,R,"Packet does not fit in available space"},
723   {0x64,0x00,R,"Illegal mode for this track"},
724   {0x64,0x01,R,"Invalid packet size"},
725   {0x65,0x00,SC_ALL_DEVS,"Voltage fault"},
726   {0x66,0x00,S,"Automatic document feeder cover up"},
727   {0x66,0x01,S,"Automatic document feeder lift up"},
728   {0x66,0x02,S,"Document jam in automatic document feeder"},
729   {0x66,0x03,S,"Document miss feed automatic in document feeder"},
730   {0x67,0x00,A,"Configuration failure"},
731   {0x67,0x01,A,"Configuration of incapable logical units failed"},
732   {0x67,0x02,A,"Add logical unit failed"},
733   {0x67,0x03,A,"Modification of logical unit failed"},
734   {0x67,0x04,A,"Exchange of logical unit failed"},
735   {0x67,0x05,A,"Remove of logical unit failed"},
736   {0x67,0x06,A,"Attachment of logical unit failed"},
737   {0x67,0x07,A,"Creation of logical unit failed"},
738   {0x67,0x08,A,"Assign failure occurred"},
739   {0x67,0x09,A,"Multiply assigned logical unit"},
740   {0x67,0x0A,SC_ALL_DEVS,"Set target port groups command failed"},
741   {0x68,0x00,A,SC_LOGICAL_UNIT "not configured"},
742   {0x69,0x00,A,"Data loss on logical unit"},
743   {0x69,0x01,A,"Multiple logical unit failures"},
744   {0x69,0x02,A,"Parity/data mismatch"},
745   {0x6A,0x00,A,"Informational,refer to log"},
746   {0x6B,0x00,A,"State change has occurred"},
747   {0x6B,0x01,A,"Redundancy level got better"},
748   {0x6B,0x02,A,"Redundancy level got worse"},
749   {0x6C,0x00,A,"Rebuild failure occurred"},
750   {0x6D,0x00,A,"Recalculate failure occurred"},
751   {0x6E,0x00,A,"Command to logical unit failed"},
752   {0x6F,0x00,R,"Copy protection key exchange failure - authentication failure"},
753   {0x6F,0x01,R,"Copy protection key exchange failure - key not present"},
754   {0x6F,0x02,R,"Copy protection key exchange failure - key not established"},
755   {0x6F,0x03,R,"Read of scrambled sector without authentication"},
756   {0x6F,0x04,R,"Media region code is mismatched to logical unit region"},
757   {0x6F,0x05,R,"Drive region must be permanent/region reset count error"},
758   /*
759    * FIXME(eric) - need a way to represent wildcards here.
760    */
761   {0x70,0x00,T,"Decompression exception short algorithm id of nn"},
762   {0x71,0x00,T,"Decompression exception long algorithm id"},
763   {0x72,0x00,R,"Session fixation error"},
764   {0x72,0x01,R,"Session fixation error writing lead-in"},
765   {0x72,0x02,R,"Session fixation error writing lead-out"},
766   {0x72,0x03,R,"Session fixation error - incomplete track in session"},
767   {0x72,0x04,R,"Empty or partially written reserved track"},
768   {0x72,0x05,R,"No more track reservations allowed"},
769   {0x73,0x00,R,"Cd control error"},
770   {0x73,0x01,R,"Power calibration area almost full"},
771   {0x73,0x02,R,"Power calibration area is full"},
772   {0x73,0x03,R,"Power calibration area error"},
773   {0x73,0x04,R,"Program memory area update failure"},
774   {0x73,0x05,R,"Program memory area is full"},
775   {0x73,0x06,R,"RMA/PMA is full"},
776   {0, 0, 0, NULL}
777 };
778
779 static const char * sc_oft_used[0x1f] = {
780         "umulig",                       /* index 0x0 should be impossible */
781         "Audio play operation ",
782         "Logical unit ",
783         "not ready, ",
784         " operation",
785         " in progress ",
786         "Hardware impending failure ",
787         "Controller impending failure ",
788         "Data channel impending failure ",      /* index 0x8 */
789         "Servo impending failure ",
790         "Spindle impending failure ",
791         "Firmware impending failure ",
792         "Recovered data ",
793         " error rate too high",
794         " times too high",
795 };
796
797 static const char *snstext[] = {
798     "No Sense",                 /* There is no sense information */
799     "Recovered Error",          /* The last command completed successfully
800                                    but used error correction */
801     "Not Ready",                /* The addressed target is not ready */
802     "Medium Error",             /* Data error detected on the medium */
803     "Hardware Error",           /* Controller or device failure */
804     "Illegal Request",
805     "Unit Attention",           /* Removable medium was changed, or
806                                    the target has been reset */
807     "Data Protect",             /* Access to the data is blocked */
808     "Blank Check",              /* Reached unexpected written or unwritten
809                                    region of the medium */
810     "Key=9",                    /* Vendor specific */
811     "Copy Aborted",             /* COPY or COMPARE was aborted */
812     "Aborted Command",          /* The target aborted the command */
813     "Equal",                    /* SEARCH DATA found data equal (obsolete) */
814     "Volume Overflow",          /* Medium full with still data to be written */
815     "Miscompare",               /* Source data and data on the medium
816                                    do not agree */
817     "Key=15"                    /* Reserved */
818 };
819
820 static
821 void sg_print_asc_ascq(unsigned char asc, unsigned char ascq)
822 {
823     int k, j;
824     char obuff[256];
825     const char * ccp;
826     const char * oup;
827     char c;
828     int found = 0;
829
830     for (k=0; additional[k].text; k++) {
831         if (additional[k].code1 == asc &&
832             additional[k].code2 == ascq) {
833             found = 1;
834             ccp = additional[k].text;
835             for (j = 0; *ccp && (j < sizeof(obuff)); ++ccp) {
836                 c = *ccp;
837                 if ((c < 0x20) && (c > 0)) {
838                     oup = sc_oft_used[(int)c];
839                     if (oup) {
840                         strcpy(obuff + j, oup);
841                         j += strlen(oup);
842                     }
843                     else {
844                         strcpy(obuff + j, "???");
845                         j += 3;
846                     }
847                 }
848                 else
849                     obuff[j++] = c;
850             }
851             if (j < sizeof(obuff))
852                 obuff[j] = '\0';
853             else
854                 obuff[sizeof(obuff) - 1] = '\0';
855             fprintf(OUTP, "Additional sense: %s\n", obuff);
856         }
857     }
858     if (found)
859         return;
860
861     for(k=0; additional2[k].text; k++) {
862         if ((additional2[k].code1 == asc) &&
863             (ascq >= additional2[k].code2_min)  &&
864             (ascq <= additional2[k].code2_max)) {
865             found = 1;
866             fprintf(OUTP, "Additional sense: ");
867             fprintf(OUTP, additional2[k].text, ascq);
868             fprintf(OUTP, "\n");
869         }
870     }
871     if (! found)
872         fprintf(OUTP, "ASC=%2x ASCQ=%2x\n", asc, ascq);
873 }
874
875 /* Print sense information */
876 void sg_print_sense(const char * leadin, const unsigned char * sense_buffer,
877                     int sb_len)
878 {
879     int k, s;
880     int sense_key, sense_class, valid, code;
881     int descriptor_format = 0;
882     const char * error = NULL;
883
884     if (sb_len < 1) {
885             fprintf(OUTP, "sense buffer empty\n");
886             return;
887     }
888     sense_class = (sense_buffer[0] >> 4) & 0x07;
889     code = sense_buffer[0] & 0xf;
890     valid = sense_buffer[0] & 0x80;
891     if (leadin)
892         fprintf(OUTP, "%s: ", leadin);
893
894     if (sense_class == 7) {     /* extended sense data */
895         s = sense_buffer[7] + 8;
896         if(s > sb_len)  /* device has more available which we ignore */
897             s = sb_len;
898
899         switch (code) {
900         case 0x0:
901             error = "Current";  /* error concerns current command */
902             break;
903         case 0x1:
904             error = "Deferred"; /* error concerns some earlier command */
905                 /* e.g., an earlier write to disk cache succeeded, but
906                    now the disk discovers that it cannot write the data */
907             break;
908         case 0x2:
909             descriptor_format = 1;
910             error = "Descriptor current";
911             /* new descriptor sense format */
912             break;
913         case 0x3:
914             descriptor_format = 1;
915             error = "Descriptor deferred";
916             /* new descriptor sense format (deferred report) */
917             break;
918         default:
919             error = "Invalid";
920         }
921         sense_key = sense_buffer[ descriptor_format ? 1 : 2 ] & 0xf;
922         fprintf(OUTP, "%s, Sense key: %s\n", error, snstext[sense_key]);
923
924         if (descriptor_format)
925             sg_print_asc_ascq(sense_buffer[2], sense_buffer[3]);
926         else {
927             if (!valid)
928                 fprintf(OUTP, "[valid=0] ");
929             fprintf(OUTP, "Info fld=0x%x, ", (int)((sense_buffer[3] << 24) |
930                     (sense_buffer[4] << 16) | (sense_buffer[5] << 8) |
931                     sense_buffer[6]));
932
933             if (sense_buffer[2] & 0x80)
934                fprintf(OUTP, "FMK "); /* current command has read a filemark */
935             if (sense_buffer[2] & 0x40)
936                fprintf(OUTP, "EOM "); /* end-of-medium condition exists */
937             if (sense_buffer[2] & 0x20)
938                fprintf(OUTP, "ILI "); /* incorrect block length requested */
939
940             if (s > 13) {
941                 if (sense_buffer[12] || sense_buffer[13])
942                     sg_print_asc_ascq(sense_buffer[12], sense_buffer[13]);
943             }
944             if (sense_key == 5 && s >= 18 && (sense_buffer[15]&0x80)) {
945                 fprintf(OUTP, "Sense Key Specific: Error in %s byte %d",
946                         (sense_buffer[15]&0x40)?"Command":"Data",
947                         (sense_buffer[16]<<8)|sense_buffer[17]);
948                 if(sense_buffer[15]&0x08) {
949                     fprintf(OUTP, " bit %d\n", sense_buffer[15]&0x07);
950                 } else {
951                     fprintf(OUTP, "\n");
952                 }
953             }
954         }
955
956     } else {    /* non-extended sense data */
957
958          /*
959           * Standard says:
960           *    sense_buffer[0] & 0200 : address valid
961           *    sense_buffer[0] & 0177 : vendor-specific error code
962           *    sense_buffer[1] & 0340 : vendor-specific
963           *    sense_buffer[1..3] : 21-bit logical block address
964           */
965
966         if (sb_len < 4) {
967             fprintf(OUTP, "sense buffer too short (4 byte minimum)\n");
968             return;
969         }
970         if (leadin)
971             fprintf(OUTP, "%s: ", leadin);
972         if (sense_buffer[0] < 15)
973             fprintf(OUTP, 
974                     "old sense: key %s\n", snstext[sense_buffer[0] & 0x0f]);
975         else
976             fprintf(OUTP, "sns = %2x %2x\n", sense_buffer[0], sense_buffer[2]);
977
978         fprintf(OUTP, "Non-extended sense class %d code 0x%0x ", 
979                 sense_class, code);
980         s = 4;
981     }
982
983     fprintf(OUTP, "Raw sense data (in hex):\n  ");
984     for (k = 0; k < s; ++k) {
985         if ((k > 0) && (0 == (k % 24)))
986             fprintf(OUTP, "\n  ");
987         fprintf(OUTP, "%02x ", sense_buffer[k]);
988     }
989     fprintf(OUTP, "\n");
990 }
991
992 static const char * hostbyte_table[]={
993 "DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET",
994 "DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR",
995 "DID_PASSTHROUGH", "DID_SOFT_ERROR", NULL};
996
997 void sg_print_host_status(int host_status)
998 {   static int maxcode=0;
999     int i;
1000
1001     if(! maxcode) {
1002         for(i = 0; hostbyte_table[i]; i++) ;
1003         maxcode = i-1;
1004     }
1005     fprintf(OUTP, "Host_status=0x%02x", host_status);
1006     if(host_status > maxcode) {
1007         fprintf(OUTP, "is invalid ");
1008         return;
1009     }
1010     fprintf(OUTP, "(%s) ",hostbyte_table[host_status]);
1011 }
1012
1013 static const char * driverbyte_table[]={
1014 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
1015 "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE", NULL};
1016
1017 static const char * driversuggest_table[]={"SUGGEST_OK",
1018 "SUGGEST_RETRY", "SUGGEST_ABORT", "SUGGEST_REMAP", "SUGGEST_DIE",
1019 unknown,unknown,unknown, "SUGGEST_SENSE",NULL};
1020
1021
1022 void sg_print_driver_status(int driver_status)
1023 {
1024     static int driver_max =0 , suggest_max=0;
1025     int i;
1026     int dr = driver_status & SG_ERR_DRIVER_MASK;
1027     int su = (driver_status & SG_ERR_SUGGEST_MASK) >> 4;
1028
1029     if(! driver_max) {
1030         for(i = 0; driverbyte_table[i]; i++) ;
1031         driver_max = i;
1032         for(i = 0; driversuggest_table[i]; i++) ;
1033         suggest_max = i;
1034     }
1035     fprintf(OUTP, "Driver_status=0x%02x",driver_status);
1036     fprintf(OUTP, " (%s,%s) ",
1037             dr < driver_max  ? driverbyte_table[dr]:"invalid",
1038             su < suggest_max ? driversuggest_table[su]:"invalid");
1039 }
1040
1041 static int sg_sense_print(const char * leadin, int scsi_status,
1042                           int host_status, int driver_status,
1043                           const unsigned char * sense_buffer, int sb_len)
1044 {
1045     int done_leadin = 0;
1046     int done_sense = 0;
1047
1048     scsi_status &= 0x7e; /*sanity */
1049     if ((0 == scsi_status) && (0 == host_status) &&
1050         (0 == driver_status))
1051         return 1;       /* No problems */
1052     if (0 != scsi_status) {
1053         if (leadin)
1054             fprintf(OUTP, "%s: ", leadin);
1055         done_leadin = 1;
1056         fprintf(OUTP, "scsi status: ");
1057         sg_print_scsi_status(scsi_status);
1058         fprintf(OUTP, "\n");
1059         if (sense_buffer && ((scsi_status == SCSI_CHECK_CONDITION) ||
1060                              (scsi_status == SCSI_COMMAND_TERMINATED))) {
1061             sg_print_sense(0, sense_buffer, sb_len);
1062             done_sense = 1;
1063         }
1064     }
1065     if (0 != host_status) {
1066         if (leadin && (! done_leadin))
1067             fprintf(OUTP, "%s: ", leadin);
1068         if (done_leadin)
1069             fprintf(OUTP, "plus...: ");
1070         else
1071             done_leadin = 1;
1072         sg_print_host_status(host_status);
1073         fprintf(OUTP, "\n");
1074     }
1075     if (0 != driver_status) {
1076         if (leadin && (! done_leadin))
1077             fprintf(OUTP, "%s: ", leadin);
1078         if (done_leadin)
1079             fprintf(OUTP, "plus...: ");
1080         else
1081             done_leadin = 1;
1082         sg_print_driver_status(driver_status);
1083         fprintf(OUTP, "\n");
1084         if (sense_buffer && (! done_sense) &&
1085             (SG_ERR_DRIVER_SENSE == (0xf & driver_status)))
1086             sg_print_sense(0, sense_buffer, sb_len);
1087     }
1088     return 0;
1089 }
1090
1091 #ifdef SG_IO
1092 int sg_chk_n_print3(const char * leadin, struct sg_io_hdr * hp)
1093 {
1094     return sg_sense_print(leadin, hp->status, hp->host_status,
1095                           hp->driver_status, hp->sbp, hp->sb_len_wr);
1096 }
1097 #endif
1098
1099 int sg_chk_n_print(const char * leadin, int masked_status,
1100                    int host_status, int driver_status,
1101                    const unsigned char * sense_buffer, int sb_len)
1102 {
1103     int scsi_status = (masked_status << 1) & 0x7e;
1104
1105     return sg_sense_print(leadin, scsi_status, host_status, driver_status,
1106                           sense_buffer, sb_len);
1107 }
1108
1109 #ifdef SG_IO
1110 int sg_err_category3(struct sg_io_hdr * hp)
1111 {
1112     return sg_err_category_new(hp->status, hp->host_status,
1113                                hp->driver_status, hp->sbp, hp->sb_len_wr);
1114 }
1115 #endif
1116
1117 int sg_err_category(int masked_status, int host_status,
1118                     int driver_status, const unsigned char * sense_buffer,
1119                     int sb_len)
1120 {
1121     int scsi_status = (masked_status << 1) & 0x7e;
1122
1123     return sg_err_category_new(scsi_status, host_status, driver_status,
1124                                sense_buffer, sb_len);
1125 }
1126
1127 int sg_err_category_new(int scsi_status, int host_status, int driver_status, 
1128                         const unsigned char * sense_buffer, int sb_len)
1129 {
1130     scsi_status &= 0x7e;
1131     if ((0 == scsi_status) && (0 == host_status) &&
1132         (0 == driver_status))
1133         return SG_ERR_CAT_CLEAN;
1134     if ((SCSI_CHECK_CONDITION == scsi_status) ||
1135         (SCSI_COMMAND_TERMINATED == scsi_status) ||
1136         (SG_ERR_DRIVER_SENSE == (0xf & driver_status))) {
1137         if (sense_buffer && (sb_len > 2)) {
1138             int sense_key;
1139             unsigned char asc;
1140
1141             if (sense_buffer[0] & 0x2) {
1142                 sense_key = sense_buffer[1] & 0xf;
1143                 asc = sense_buffer[2];
1144             }
1145             else {
1146                 sense_key = sense_buffer[2] & 0xf;
1147                 asc = (sb_len > 12) ? sense_buffer[12] : 0;
1148             }
1149
1150             if(RECOVERED_ERROR == sense_key)
1151                 return SG_ERR_CAT_RECOVERED;
1152             else if (UNIT_ATTENTION == sense_key) {
1153                 if (0x28 == asc)
1154                     return SG_ERR_CAT_MEDIA_CHANGED;
1155                 if (0x29 == asc)
1156                     return SG_ERR_CAT_RESET;
1157             }
1158         }
1159         return SG_ERR_CAT_SENSE;
1160     }
1161     if (0 != host_status) {
1162         if ((SG_ERR_DID_NO_CONNECT == host_status) ||
1163             (SG_ERR_DID_BUS_BUSY == host_status) ||
1164             (SG_ERR_DID_TIME_OUT == host_status))
1165             return SG_ERR_CAT_TIMEOUT;
1166     }
1167     if (0 != driver_status) {
1168         if (SG_ERR_DRIVER_TIMEOUT == driver_status)
1169             return SG_ERR_CAT_TIMEOUT;
1170     }
1171     return SG_ERR_CAT_OTHER;
1172 }
1173
1174 int sg_get_command_size(unsigned char opcode)
1175 {
1176     return COMMAND_SIZE(opcode);
1177 }
1178
1179 void sg_get_command_name(unsigned char opcode, int buff_len, char * buff)
1180 {
1181     const char **table = commands[ group(opcode) ];
1182
1183     if ((NULL == buff) || (buff_len < 1))
1184         return;
1185
1186     switch ((unsigned long) table) {
1187     case RESERVED_GROUP:
1188         strncpy(buff, reserved, buff_len);
1189         break;
1190     case VENDOR_GROUP:
1191         strncpy(buff, vendor, buff_len);
1192         break;
1193     default:
1194         strncpy(buff, table[opcode & 0x1f], buff_len);
1195         break;
1196     }
1197 }