smartmontools  SVN Rev 5304
Utility to control and monitor storage systems with "S.M.A.R.T."
scsicmds.h
Go to the documentation of this file.
1 /*
2  * scsicmds.h
3  *
4  * Home page of code is: https://www.smartmontools.org
5  *
6  * Copyright (C) 2002-8 Bruce Allen
7  * Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
8  * Copyright (C) 2003-18 Douglas Gilbert <dgilbert@interlog.com>
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  *
12  *
13  * N.B. What was formerly known as "SMART" are now called "informational
14  * exceptions" in recent t10.org drafts (i.e. recent SCSI).
15  *
16  */
17 
18 
19 #ifndef SCSICMDS_H_
20 #define SCSICMDS_H_
21 
22 #define SCSICMDS_H_CVSID "$Id: scsicmds.h 5302 2022-01-14 20:11:03Z dpgilbert $\n"
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdint.h>
27 #include <string.h>
28 
29 /* #define SCSI_DEBUG 1 */ /* Comment out to disable command debugging */
30 
31 /* Following conditional defines just in case OS already has them defined.
32  * If they are defined we hope they are defined correctly (for SCSI). */
33 #ifndef TEST_UNIT_READY
34 #define TEST_UNIT_READY 0x0
35 #endif
36 #ifndef LOG_SELECT
37 #define LOG_SELECT 0x4c
38 #endif
39 #ifndef LOG_SENSE
40 #define LOG_SENSE 0x4d
41 #endif
42 #ifndef MODE_SENSE
43 #define MODE_SENSE 0x1a
44 #endif
45 #ifndef MODE_SENSE_10
46 #define MODE_SENSE_10 0x5a
47 #endif
48 #ifndef MODE_SELECT
49 #define MODE_SELECT 0x15
50 #endif
51 #ifndef MODE_SELECT_10
52 #define MODE_SELECT_10 0x55
53 #endif
54 #ifndef INQUIRY
55 #define INQUIRY 0x12
56 #endif
57 #ifndef REQUEST_SENSE
58 #define REQUEST_SENSE 0x03
59 #endif
60 #ifndef RECEIVE_DIAGNOSTIC
61 #define RECEIVE_DIAGNOSTIC 0x1c
62 #endif
63 #ifndef SEND_DIAGNOSTIC
64 #define SEND_DIAGNOSTIC 0x1d
65 #endif
66 #ifndef READ_DEFECT_10
67 #define READ_DEFECT_10 0x37
68 #endif
69 #ifndef READ_DEFECT_12
70 #define READ_DEFECT_12 0xb7
71 #endif
72 #ifndef START_STOP_UNIT /* SSU */
73 #define START_STOP_UNIT 0x1b
74 #endif
75 #ifndef REPORT_LUNS
76 #define REPORT_LUNS 0xa0
77 #endif
78 #ifndef READ_CAPACITY_10
79 #define READ_CAPACITY_10 0x25
80 #endif
81 #ifndef READ_CAPACITY_16
82 #define READ_CAPACITY_16 0x9e
83 #endif
84 #ifndef SAI_READ_CAPACITY_16 /* service action for READ_CAPACITY_16 */
85 #define SAI_READ_CAPACITY_16 0x10
86 #endif
87 
88 #ifndef SAT_ATA_PASSTHROUGH_12
89 #define SAT_ATA_PASSTHROUGH_12 0xa1
90 #endif
91 #ifndef SAT_ATA_PASSTHROUGH_16
92 #define SAT_ATA_PASSTHROUGH_16 0x85
93 #endif
94 
95 
96 #define DXFER_NONE 0
97 #define DXFER_FROM_DEVICE 1
98 #define DXFER_TO_DEVICE 2
99 
101 {
102  uint8_t * cmnd; /* [in]: ptr to SCSI command block (cdb) */
103  size_t cmnd_len; /* [in]: number of bytes in SCSI command */
104  int dxfer_dir; /* [in]: DXFER_NONE, DXFER_FROM_DEVICE, or
105  DXFER_TO_DEVICE */
106  uint8_t * dxferp; /* [in]: ptr to outgoing or incoming data buffer */
107  size_t dxfer_len; /* [in]: bytes to be transferred to/from dxferp */
108  uint8_t * sensep; /* [in]: ptr to sense buffer, filled when
109  CHECK CONDITION status occurs */
110  size_t max_sense_len; /* [in]: max number of bytes to write to sensep */
111  unsigned timeout; /* [in]: seconds, 0-> default timeout (60 seconds?) */
112  size_t resp_sense_len; /* [out]: sense buffer length written */
113  uint8_t scsi_status; /* [out]: 0->ok, 2->CHECK CONDITION, etc ... */
114  int resid; /* [out]: Number of bytes requested to be transferred
115  less actual number transferred (0 if not
116  supported) */
117 };
118 
120  uint8_t resp_code;
121  uint8_t sense_key;
122  uint8_t asc;
123  uint8_t ascq;
124  int progress; /* -1 -> N/A, 0-65535 -> available */
125 };
126 
127 /* Useful data from Informational Exception Control mode page (0x1c) */
128 #define SCSI_IECMP_RAW_LEN 64
131  uint8_t gotCurrent;
133  uint8_t gotChangeable;
134  uint8_t modese_len; /* 0 (don't know), 6 or 10 */
137 };
138 
139 /* Carrier for Error counter log pages (e.g. read, write, verify ...) */
141  uint8_t gotPC[7];
142  uint8_t gotExtraPC;
143  uint64_t counter[8];
144 };
145 
146 /* Carrier for Non-medium error log page */
148  uint8_t gotPC0;
149  uint8_t gotExtraPC;
150  uint64_t counterPC0;
151  uint8_t gotTFE_H;
152  uint64_t counterTFE_H; /* Track following errors [Hitachi] */
153  uint8_t gotPE_H;
154  uint64_t counterPE_H; /* Positioning errors [Hitachi] */
155 };
156 
158  uint64_t num_lblocks; /* Number of Logical Blocks on device */
159  uint32_t lb_size; /* should be available in all non-error cases */
160  /* following fields from READ CAPACITY(16) or set to 0 */
161  uint8_t prot_type; /* 0, 1, 2 or 3 protection type, deduced from
162  * READ CAPACITY(16) P_TYPE and PROT_EN fields */
163  uint8_t p_i_exp; /* Protection information Intervals Exponent */
164  uint8_t lb_p_pb_exp;/* Logical Blocks per Physical Block Exponent */
165  bool lbpme; /* Logical Block Provisioning Management Enabled */
166  bool lbprz; /* Logical Block Provisioning Read Zeros */
167  uint16_t l_a_lba; /* Lowest Aligned Logical Block Address */
168 };
169 
171  uint8_t page_code;
172  uint8_t subpage_code;
173 };
174 
175 /* SCSI Peripheral types (of interest) */
176 #define SCSI_PT_DIRECT_ACCESS 0x0
177 #define SCSI_PT_SEQUENTIAL_ACCESS 0x1
178 #define SCSI_PT_CDROM 0x5
179 #define SCSI_PT_MEDIUM_CHANGER 0x8
180 #define SCSI_PT_ENCLOSURE 0xd
181 #define SCSI_PT_HOST_MANAGED 0x14 /* Zoned disk */
182 
183 /* Transport protocol identifiers or just Protocol identifiers */
184 #define SCSI_TPROTO_FCP 0
185 #define SCSI_TPROTO_SPI 1
186 #define SCSI_TPROTO_SSA 2
187 #define SCSI_TPROTO_1394 3
188 #define SCSI_TPROTO_SRP 4 /* SCSI over RDMA */
189 #define SCSI_TPROTO_ISCSI 5
190 #define SCSI_TPROTO_SAS 6
191 #define SCSI_TPROTO_ADT 7
192 #define SCSI_TPROTO_ATA 8
193 #define SCSI_TPROTO_UAS 9 /* USB attached SCSI */
194 #define SCSI_TPROTO_SOP 0xa /* SCSI over PCIe */
195 #define SCSI_TPROTO_PCIE 0xb /* includes NVMe */
196 #define SCSI_TPROTO_NONE 0xf
197 
198 
199 /* SCSI Log Pages retrieved by LOG SENSE. 0x0 to 0x3f, 0x30 to 0x3e vendor */
200 #define SUPPORTED_LPAGES 0x00
201 #define BUFFER_OVERRUN_LPAGE 0x01
202 #define WRITE_ERROR_COUNTER_LPAGE 0x02
203 #define READ_ERROR_COUNTER_LPAGE 0x03
204 #define READ_REVERSE_ERROR_COUNTER_LPAGE 0x04
205 #define VERIFY_ERROR_COUNTER_LPAGE 0x05
206 #define NON_MEDIUM_ERROR_LPAGE 0x06
207 #define LAST_N_ERROR_EVENTS_LPAGE 0x07
208 #define FORMAT_STATUS_LPAGE 0x08
209 #define LAST_N_DEFERRED_LPAGE 0x0b /* or async events */
210 #define LB_PROV_LPAGE 0x0c /* SBC-3 */
211 #define TEMPERATURE_LPAGE 0x0d
212 #define STARTSTOP_CYCLE_COUNTER_LPAGE 0x0e
213 #define APPLICATION_CLIENT_LPAGE 0x0f
214 #define SELFTEST_RESULTS_LPAGE 0x10
215 #define SS_MEDIA_LPAGE 0x11 /* SBC-3 */
216 #define DEVICE_STATS_LPAGE 0x14 /* SSC-5 */
217 #define BACKGROUND_RESULTS_LPAGE 0x15 /* SBC-3 */
218 #define ATA_PT_RESULTS_LPAGE 0x16 /* SAT */
219 #define NONVOL_CACHE_LPAGE 0x17 /* SBC-3 */
220 #define PROTOCOL_SPECIFIC_LPAGE 0x18
221 #define GEN_STATS_PERF_LPAGE 0x19
222 #define POWER_COND_TRANS_LPAGE 0x1a
223 #define IE_LPAGE 0x2f
224 
225 /* SCSI Log subpages (8 bits), added spc4r05 2006, standardized SPC-4 2015 */
226 #define NO_SUBPAGE_L_SPAGE 0x0 /* 0x0-0x3f,0x0 */
227 #define LAST_N_INQ_DAT_L_SPAGE 0x1 /* 0xb,0x1 */
228 #define LAST_N_MODE_PG_L_SPAGE 0x2 /* 0xb,0x2 */
229 #define ENVIRO_REP_L_SPAGE 0x1 /* 0xd,0x1 */
230 #define ENVIRO_LIMITS_L_SPAGE 0x2 /* 0xd,0x2 */
231 #define UTILIZATION_L_SPAGE 0x1 /* 0xe,0x1 */
232 #define ZB_DEV_STATS_L_SPAGE 0x1 /* 0x14,0x1 */
233 #define PEND_DEFECTS_L_SPAGE 0x1 /* 0x15,0x1 */
234 #define BACKGROUND_OP_L_SPAGE 0x2 /* 0x15,0x2 */
235 #define LPS_MISALIGN_L_SPAGE 0x3 /* 0x15,0x3 */
236 #define SUPP_SPAGE_L_SPAGE 0xff /* 0x0,0xff pages+subpages */
237 
238 /* Seagate vendor specific log pages. */
239 #define SEAGATE_CACHE_LPAGE 0x37
240 #define SEAGATE_FACTORY_LPAGE 0x3e
241 
242 /* Log page response lengths */
243 #define LOG_RESP_SELF_TEST_LEN 0x194
244 
245 /* See the SSC-2 document at www.t10.org . Earlier note: From IBM
246 Documentation, see http://www.storage.ibm.com/techsup/hddtech/prodspecs.htm */
247 #define TAPE_ALERTS_LPAGE 0x2e
248 
249 /* ANSI SCSI-3 Mode Pages */
250 #define VENDOR_UNIQUE_PAGE 0x00
251 #define READ_WRITE_ERROR_RECOVERY_PAGE 0x01
252 #define DISCONNECT_RECONNECT_PAGE 0x02
253 #define FORMAT_DEVICE_PAGE 0x03
254 #define RIGID_DISK_DRIVE_GEOMETRY_PAGE 0x04
255 #define FLEXIBLE_DISK_PAGE 0x05
256 #define VERIFY_ERROR_RECOVERY_PAGE 0x07
257 #define CACHING_PAGE 0x08
258 #define PERIPHERAL_DEVICE_PAGE 0x09
259 #define XOR_CONTROL_MODE_PAGE 0x10
260 #define CONTROL_MODE_PAGE 0x0a
261 #define MEDIUM_TYPES_SUPPORTED_PAGE 0x0b
262 #define NOTCH_PAGE 0x0c
263 #define CD_DEVICE_PAGE 0x0d
264 #define CD_AUDIO_CONTROL_PAGE 0x0e
265 #define DATA_COMPRESSION_PAGE 0x0f
266 #define ENCLOSURE_SERVICES_MANAGEMENT_PAGE 0x14
267 #define PROTOCOL_SPECIFIC_LUN_PAGE 0x18
268 #define PROTOCOL_SPECIFIC_PORT_PAGE 0x19
269 #define POWER_CONDITION_PAGE 0x1a
270 #define INFORMATIONAL_EXCEPTIONS_CONTROL_PAGE 0x1c
271 #define FAULT_FAILURE_REPORTING_PAGE 0x1c
272 
273 /* Background control mode subpage is [0x1c,0x1] */
274 #define BACKGROUND_CONTROL_M_SUBPAGE 0x1 /* SBC-2 */
275 
276 #define ALL_MODE_PAGES 0x3f
277 
278 /* Mode page control field */
279 #define MPAGE_CONTROL_CURRENT 0
280 #define MPAGE_CONTROL_CHANGEABLE 1
281 #define MPAGE_CONTROL_DEFAULT 2
282 #define MPAGE_CONTROL_SAVED 3
283 
284 /* SCSI Vital Product Data (VPD) pages */
285 #define SCSI_VPD_SUPPORTED_VPD_PAGES 0x0
286 #define SCSI_VPD_UNIT_SERIAL_NUMBER 0x80
287 #define SCSI_VPD_DEVICE_IDENTIFICATION 0x83
288 #define SCSI_VPD_EXTENDED_INQUIRY_DATA 0x86
289 #define SCSI_VPD_ATA_INFORMATION 0x89
290 #define SCSI_VPD_POWER_CONDITION 0x8a
291 #define SCSI_VPD_POWER_CONSUMPTION 0x8d
292 #define SCSI_VPD_BLOCK_LIMITS 0xb0
293 #define SCSI_VPD_BLOCK_DEVICE_CHARACTERISTICS 0xb1
294 #define SCSI_VPD_LOGICAL_BLOCK_PROVISIONING 0xb2
295 #define SCSI_VPD_ZONED_BLOCK_DEV_CHAR 0xb6
296 
297 /* defines for useful SCSI Status codes */
298 #define SCSI_STATUS_CHECK_CONDITION 0x2
299 
300 /* defines for useful Sense Key codes */
301 #define SCSI_SK_NO_SENSE 0x0
302 #define SCSI_SK_RECOVERED_ERR 0x1
303 #define SCSI_SK_NOT_READY 0x2
304 #define SCSI_SK_MEDIUM_ERROR 0x3
305 #define SCSI_SK_HARDWARE_ERROR 0x4
306 #define SCSI_SK_ILLEGAL_REQUEST 0x5
307 #define SCSI_SK_UNIT_ATTENTION 0x6
308 #define SCSI_SK_ABORTED_COMMAND 0xb
309 
310 /* defines for useful Additional Sense Codes (ASCs) */
311 #define SCSI_ASC_NOT_READY 0x4 /* more info in ASCQ code */
312 #define SCSI_ASC_NO_MEDIUM 0x3a /* more info in ASCQ code */
313 #define SCSI_ASC_UNKNOWN_OPCODE 0x20
314 #define SCSI_ASC_INVALID_FIELD 0x24
315 #define SCSI_ASC_UNKNOWN_PARAM 0x26
316 #define SCSI_ASC_WARNING 0xb
317 #define SCSI_ASC_IMPENDING_FAILURE 0x5d
318 
319 #define SCSI_ASCQ_ATA_PASS_THROUGH 0x1d
320 
321 /* Simplified error code (negative values as per errno) */
322 #define SIMPLE_NO_ERROR 0
323 #define SIMPLE_ERR_NOT_READY 1
324 #define SIMPLE_ERR_BAD_OPCODE 2
325 #define SIMPLE_ERR_BAD_FIELD 3 /* in cbd */
326 #define SIMPLE_ERR_BAD_PARAM 4 /* in data */
327 #define SIMPLE_ERR_BAD_RESP 5 /* response fails sanity */
328 #define SIMPLE_ERR_NO_MEDIUM 6 /* no medium present */
329 #define SIMPLE_ERR_BECOMING_READY 7 /* device will be ready soon */
330 #define SIMPLE_ERR_TRY_AGAIN 8 /* some warning, try again */
331 #define SIMPLE_ERR_MEDIUM_HARDWARE 9 /* medium or hardware error */
332 #define SIMPLE_ERR_UNKNOWN 10 /* unknown sense value */
333 #define SIMPLE_ERR_ABORTED_COMMAND 11 /* probably transport error */
334 
335 
336 /* defines for functioncode parameter in SENDDIAGNOSTIC function */
337 #define SCSI_DIAG_NO_SELF_TEST 0x00
338 #define SCSI_DIAG_DEF_SELF_TEST 0xff
339 #define SCSI_DIAG_BG_SHORT_SELF_TEST 0x01
340 #define SCSI_DIAG_BG_EXTENDED_SELF_TEST 0x02
341 #define SCSI_DIAG_FG_SHORT_SELF_TEST 0x05
342 #define SCSI_DIAG_FG_EXTENDED_SELF_TEST 0x06
343 #define SCSI_DIAG_ABORT_SELF_TEST 0x04
344 
345 /* Defines for power_cond in scsiSetPowerCondition() (SSU command) */
346 #define SCSI_POW_COND_ACTIVE 0x1
347 #define SCSI_POW_COND_IDLE 0x2
348 #define SCSI_POW_COND_STANDBY 0x3
349 
350 
351 /* SCSI command timeout values (units are seconds) */
352 #define SCSI_TIMEOUT_DEFAULT 60 // should be longer than the spin up time
353  // of a disk in JBOD.
354 
355 #define SCSI_TIMEOUT_SELF_TEST (5 * 60 * 60) /* allow max 5 hours for */
356  /* extended foreground self test */
357 
358 
359 
360 #define LOGPAGEHDRSIZE 4
361 
362 class scsi_device;
363 
364 // Set of supported SCSI VPD pages. Constructor fetches Supported VPD pages
365 // VPD page and remembers the response for later queries.
367 {
368 public:
369  explicit supported_vpd_pages(scsi_device * device);
370 
371  bool is_supported(int vpd_page_num) const;
372 
373 private:
374  int num_valid; /* 0 or less for invalid */
375  unsigned char pages[256];
376 };
377 
379 
380 /* This is a heuristic that takes into account the command bytes and length
381  * to decide whether the presented unstructured sequence of bytes could be
382  * a SCSI command. If so it returns true otherwise false. Vendor specific
383  * SCSI commands (i.e. opcodes from 0xc0 to 0xff), if presented, are assumed
384  * to follow SCSI conventions (i.e. length of 6, 10, 12 or 16 bytes). The
385  * only SCSI commands considered above 16 bytes of length are the Variable
386  * Length Commands (opcode 0x7f) and the XCDB wrapped commands (opcode 0x7e).
387  * Both have an inbuilt length field which can be cross checked with clen.
388  * No NVMe commands (64 bytes long plus some extra added by some OSes) have
389  * opcodes 0x7e or 0x7f yet. ATA is register based but SATA has FIS
390  * structures that are sent across the wire. The FIS register structure is
391  * used to move a command from a SATA host to device, but the ATA 'command'
392  * is not the first byte. So it is harder to say what will happen if a
393  * FIS structure is presented as a SCSI command, hopefully there is a low
394  * probability this function will yield true in that case. */
395 bool is_scsi_cdb(const uint8_t * cdbp, int clen);
396 
397 // Print SCSI debug messages?
398 extern unsigned char scsi_debugmode;
399 
400 void scsi_do_sense_disect(const struct scsi_cmnd_io * in,
401  struct scsi_sense_disect * out);
402 
403 int scsiSimpleSenseFilter(const struct scsi_sense_disect * sinfo);
404 
405 const char * scsiErrString(int scsiErr);
406 
407 /* Yield string associated with sense_key value. Returns 'buff'. */
408 char * scsi_get_sense_key_str(int sense_key, int buff_len, char * buff);
409 
410 int scsi_vpd_dev_id_iter(const unsigned char * initial_desig_desc,
411  int page_len, int * off, int m_assoc,
412  int m_desig_type, int m_code_set);
413 
414 int scsi_decode_lu_dev_id(const unsigned char * b, int blen, char * s,
415  int slen, int * transport);
416 
417 
418 /* STANDARD SCSI Commands */
419 int scsiTestUnitReady(scsi_device * device);
420 
421 int scsiStdInquiry(scsi_device * device, uint8_t *pBuf, int bufLen);
422 
423 int scsiInquiryVpd(scsi_device * device, int vpd_page, uint8_t *pBuf,
424  int bufLen);
425 
426 int scsiLogSense(scsi_device * device, int pagenum, int subpagenum,
427  uint8_t *pBuf, int bufLen, int known_resp_len);
428 
429 int scsiLogSelect(scsi_device * device, int pcr, int sp, int pc, int pagenum,
430  int subpagenum, uint8_t *pBuf, int bufLen);
431 
432 int scsiModeSense(scsi_device * device, int pagenum, int subpagenum, int pc,
433  uint8_t *pBuf, int bufLen);
434 
435 int scsiModeSelect(scsi_device * device, int sp, uint8_t *pBuf, int bufLen);
436 
437 int scsiModeSense10(scsi_device * device, int pagenum, int subpagenum, int pc,
438  uint8_t *pBuf, int bufLen);
439 
440 int scsiModeSelect10(scsi_device * device, int sp, uint8_t *pBuf, int bufLen);
441 
442 int scsiModePageOffset(const uint8_t * resp, int len, int modese_len);
443 
444 int scsiRequestSense(scsi_device * device,
445  struct scsi_sense_disect * sense_info);
446 
447 int scsiSetPowerCondition(scsi_device * device, int power_cond,
448  int pcond_modifier = 0);
449 
450 int scsiSendDiagnostic(scsi_device * device, int functioncode, uint8_t *pBuf,
451  int bufLen);
452 
454 
455 int scsiReadDefect10(scsi_device * device, int req_plist, int req_glist,
456  int dl_format, uint8_t *pBuf, int bufLen);
457 
458 int scsiReadDefect12(scsi_device * device, int req_plist, int req_glist,
459  int dl_format, int addrDescIndex, uint8_t *pBuf,
460  int bufLen);
461 
462 int scsiReadCapacity10(scsi_device * device, unsigned int * last_lbp,
463  unsigned int * lb_sizep);
464 
465 int scsiReadCapacity16(scsi_device * device, uint8_t *pBuf, int bufLen);
466 
467 /* SMART specific commands */
468 int scsiCheckIE(scsi_device * device, int hasIELogPage, int hasTempLogPage,
469  uint8_t *asc, uint8_t *ascq, uint8_t *currenttemp,
470  uint8_t *triptemp);
471 
472 int scsiFetchIECmpage(scsi_device * device, struct scsi_iec_mode_page *iecp,
473  int modese_len);
474 int scsi_IsExceptionControlEnabled(const struct scsi_iec_mode_page *iecp);
475 int scsi_IsWarningEnabled(const struct scsi_iec_mode_page *iecp);
476 int scsiSetExceptionControlAndWarning(scsi_device * device, int enabled,
477  const struct scsi_iec_mode_page *iecp);
478 void scsiDecodeErrCounterPage(unsigned char * resp,
479  struct scsiErrorCounter *ecp);
480 void scsiDecodeNonMediumErrPage(unsigned char * resp,
481  struct scsiNonMediumError *nmep);
482 int scsiFetchExtendedSelfTestTime(scsi_device * device, int * durationSec,
483  int modese_len);
484 int scsiCountFailedSelfTests(scsi_device * device, int noisy);
485 int scsiSelfTestInProgress(scsi_device * device, int * inProgress);
486 int scsiFetchControlGLTSD(scsi_device * device, int modese_len, int current);
487 int scsiSetControlGLTSD(scsi_device * device, int enabled, int modese_len);
489 int scsiGetRPM(scsi_device * device, int modese_len, int * form_factorp,
490  int * haw_zbcp);
491 int scsiGetSetCache(scsi_device * device, int modese_len, short int * wce,
492  short int * rcd);
493 uint64_t scsiGetSize(scsi_device * device, bool avoid_rcap16,
494  struct scsi_readcap_resp * srrp);
495 
496 /* T10 Standard IE Additional Sense Code strings taken from t10.org */
497 const char* scsiGetIEString(uint8_t asc, uint8_t ascq);
498 int scsiGetTemp(scsi_device * device, uint8_t *currenttemp, uint8_t *triptemp);
499 
500 
502 int scsiSmartShortSelfTest(scsi_device * device);
506 int scsiSmartSelfTestAbort(scsi_device * device);
507 
508 const char * scsiTapeAlertsTapeDevice(unsigned short code);
509 const char * scsiTapeAlertsChangerDevice(unsigned short code);
510 
511 const char * scsi_get_opcode_name(uint8_t opcode);
512 void scsi_format_id_string(char * out, const uint8_t * in, int n);
513 
514 void dStrHex(const uint8_t * up, int len, int no_ascii);
515 
516 /* Attempt to find the first SCSI sense data descriptor that matches the
517  given 'desc_type'. If found return pointer to start of sense data
518  descriptor; otherwise (including fixed format sense data) returns NULL. */
519 const unsigned char * sg_scsi_sense_desc_find(const unsigned char * sensep,
520  int sense_len, int desc_type);
521 
522 
523 /* SCSI command transmission interface function declaration. Its
524  * definition is target OS specific (see os_<OS>.c file).
525  * Returns 0 if SCSI command successfully launched and response
526  * received. Even when 0 is returned the caller should check
527  * scsi_cmnd_io::scsi_status for SCSI defined errors and warnings
528  * (e.g. CHECK CONDITION). If the SCSI command could not be issued
529  * (e.g. device not present or not a SCSI device) or some other problem
530  * arises (e.g. timeout) then returns a negative errno value. */
531 // Moved to C++ interface
532 //int do_scsi_cmnd_io(int dev_fd, struct scsi_cmnd_io * iop, int report);
533 
534 
535 
536 #endif
SCSI device access.
bool is_supported(int vpd_page_num) const
Definition: scsicmds.cpp:65
unsigned char pages[256]
Definition: scsicmds.h:375
supported_vpd_pages(scsi_device *device)
Definition: scsicmds.cpp:50
u8 sense_len
Definition: megaraid.h:2
uint8_t opcode
Definition: megaraid.h:0
u8 b[12]
Definition: megaraid.h:17
u16 s[6]
Definition: megaraid.h:18
int scsiReadDefect12(scsi_device *device, int req_plist, int req_glist, int dl_format, int addrDescIndex, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:1208
int scsiFetchExtendedSelfTestTime(scsi_device *device, int *durationSec, int modese_len)
Definition: scsicmds.cpp:2332
int scsiModeSelect(scsi_device *device, int sp, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:732
int scsiSimpleSenseFilter(const struct scsi_sense_disect *sinfo)
Definition: scsicmds.cpp:272
int scsiSetExceptionControlAndWarning(scsi_device *device, int enabled, const struct scsi_iec_mode_page *iecp)
Definition: scsicmds.cpp:1552
int scsiSmartExtendCapSelfTest(scsi_device *device)
Definition: scsicmds.cpp:2307
void scsiDecodeErrCounterPage(unsigned char *resp, struct scsiErrorCounter *ecp)
Definition: scsicmds.cpp:2370
char * scsi_get_sense_key_str(int sense_key, int buff_len, char *buff)
Definition: scsicmds.cpp:371
int scsiFetchIECmpage(scsi_device *device, struct scsi_iec_mode_page *iecp, int modese_len)
Definition: scsicmds.cpp:1462
int scsiGetTemp(scsi_device *device, uint8_t *currenttemp, uint8_t *triptemp)
Definition: scsicmds.cpp:1622
int scsiSmartShortCapSelfTest(scsi_device *device)
Definition: scsicmds.cpp:2296
int scsiSmartSelfTestAbort(scsi_device *device)
Definition: scsicmds.cpp:2319
int scsiGetSetCache(scsi_device *device, int modese_len, short int *wce, short int *rcd)
Definition: scsicmds.cpp:2632
int scsiReadCapacity10(scsi_device *device, unsigned int *last_lbp, unsigned int *lb_sizep)
Definition: scsicmds.cpp:1268
int scsiFetchTransportProtocol(scsi_device *device, int modese_len)
Definition: scsicmds.cpp:2807
int scsi_decode_lu_dev_id(const unsigned char *b, int blen, char *s, int slen, int *transport)
Definition: scsicmds.cpp:423
bool is_scsi_cdb(const uint8_t *cdbp, int clen)
Definition: scsicmds.cpp:151
void scsi_do_sense_disect(const struct scsi_cmnd_io *in, struct scsi_sense_disect *out)
Definition: scsicmds.cpp:250
const char * scsiErrString(int scsiErr)
Definition: scsicmds.cpp:310
int scsiTestUnitReady(scsi_device *device)
Definition: scsicmds.cpp:1147
int scsiCountFailedSelfTests(scsi_device *device, int noisy)
Definition: scsicmds.cpp:2469
int scsiModeSense10(scsi_device *device, int pagenum, int subpagenum, int pc, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:774
int scsiModePageOffset(const uint8_t *resp, int len, int modese_len)
Definition: scsicmds.cpp:1419
int scsiInquiryVpd(scsi_device *device, int vpd_page, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:903
int scsiSelfTestInProgress(scsi_device *device, int *inProgress)
Definition: scsicmds.cpp:2520
int scsiSetPowerCondition(scsi_device *device, int power_cond, int pcond_modifier=0)
Definition: scsicmds.cpp:1052
int scsiSmartExtendSelfTest(scsi_device *device)
Definition: scsicmds.cpp:2284
#define SCSI_IECMP_RAW_LEN
Definition: scsicmds.h:128
int scsiRequestSense(scsi_device *device, struct scsi_sense_disect *sense_info)
Definition: scsicmds.cpp:964
int scsiCheckIE(scsi_device *device, int hasIELogPage, int hasTempLogPage, uint8_t *asc, uint8_t *ascq, uint8_t *currenttemp, uint8_t *triptemp)
Definition: scsicmds.cpp:1646
uint64_t scsiGetSize(scsi_device *device, bool avoid_rcap16, struct scsi_readcap_resp *srrp)
Definition: scsicmds.cpp:1341
const unsigned char * sg_scsi_sense_desc_find(const unsigned char *sensep, int sense_len, int desc_type)
Definition: scsicmds.cpp:2841
supported_vpd_pages * supported_vpd_pages_p
Definition: scsicmds.cpp:47
int scsiGetRPM(scsi_device *device, int modese_len, int *form_factorp, int *haw_zbcp)
Definition: scsicmds.cpp:2586
void scsi_format_id_string(char *out, const uint8_t *in, int n)
Definition: scsicmds.cpp:2868
int scsiReadCapacity16(scsi_device *device, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:1308
int scsiStdInquiry(scsi_device *device, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:870
const char * scsiTapeAlertsTapeDevice(unsigned short code)
Definition: scsicmds.cpp:1948
int scsiModeSelect10(scsi_device *device, int sp, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:827
const char * scsi_get_opcode_name(uint8_t opcode)
Definition: scsicmds.cpp:233
void scsiDecodeNonMediumErrPage(unsigned char *resp, struct scsiNonMediumError *nmep)
Definition: scsicmds.cpp:2408
int scsiSmartDefaultSelfTest(scsi_device *device)
Definition: scsicmds.cpp:2262
const char * scsiGetIEString(uint8_t asc, uint8_t ascq)
Definition: scsicmds.cpp:2232
void dStrHex(const uint8_t *up, int len, int no_ascii)
Definition: scsicmds.cpp:78
int scsiSendDiagnostic(scsi_device *device, int functioncode, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:1084
int scsiFetchControlGLTSD(scsi_device *device, int modese_len, int current)
Definition: scsicmds.cpp:2548
bool scsi_pass_through_with_retry(scsi_device *device, scsi_cmnd_io *iop)
Definition: scsicmds.cpp:1244
int scsiModeSense(scsi_device *device, int pagenum, int subpagenum, int pc, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:677
int scsi_IsWarningEnabled(const struct scsi_iec_mode_page *iecp)
Definition: scsicmds.cpp:1523
int scsiSetControlGLTSD(scsi_device *device, int enabled, int modese_len)
Definition: scsicmds.cpp:2736
int scsi_IsExceptionControlEnabled(const struct scsi_iec_mode_page *iecp)
Definition: scsicmds.cpp:1509
int scsiSmartShortSelfTest(scsi_device *device)
Definition: scsicmds.cpp:2273
int scsiLogSense(scsi_device *device, int pagenum, int subpagenum, uint8_t *pBuf, int bufLen, int known_resp_len)
Definition: scsicmds.cpp:549
unsigned char scsi_debugmode
Definition: scsicmds.cpp:45
const char * scsiTapeAlertsChangerDevice(unsigned short code)
Definition: scsicmds.cpp:2096
int scsiLogSelect(scsi_device *device, int pcr, int sp, int pc, int pagenum, int subpagenum, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:642
int scsiReadDefect10(scsi_device *device, int req_plist, int req_glist, int dl_format, uint8_t *pBuf, int bufLen)
Definition: scsicmds.cpp:1171
int scsi_vpd_dev_id_iter(const unsigned char *initial_desig_desc, int page_len, int *off, int m_assoc, int m_desig_type, int m_code_set)
Definition: scsicmds.cpp:394
static int modese_len
Definition: scsiprint.cpp:78
uint8_t gotPC[7]
Definition: scsicmds.h:141
uint64_t counter[8]
Definition: scsicmds.h:143
uint8_t gotExtraPC
Definition: scsicmds.h:142
uint64_t counterTFE_H
Definition: scsicmds.h:152
uint64_t counterPE_H
Definition: scsicmds.h:154
uint8_t gotTFE_H
Definition: scsicmds.h:151
uint8_t gotExtraPC
Definition: scsicmds.h:149
uint64_t counterPC0
Definition: scsicmds.h:150
uint8_t * sensep
Definition: scsicmds.h:108
uint8_t * dxferp
Definition: scsicmds.h:106
int dxfer_dir
Definition: scsicmds.h:104
size_t cmnd_len
Definition: scsicmds.h:103
size_t resp_sense_len
Definition: scsicmds.h:112
size_t dxfer_len
Definition: scsicmds.h:107
size_t max_sense_len
Definition: scsicmds.h:110
uint8_t scsi_status
Definition: scsicmds.h:113
uint8_t * cmnd
Definition: scsicmds.h:102
unsigned timeout
Definition: scsicmds.h:111
uint8_t gotChangeable
Definition: scsicmds.h:133
uint8_t gotCurrent
Definition: scsicmds.h:131
uint8_t modese_len
Definition: scsicmds.h:134
uint8_t raw_curr[SCSI_IECMP_RAW_LEN]
Definition: scsicmds.h:135
uint8_t raw_chg[SCSI_IECMP_RAW_LEN]
Definition: scsicmds.h:136
uint8_t requestedChangeable
Definition: scsicmds.h:132
uint8_t requestedCurrent
Definition: scsicmds.h:130
uint16_t l_a_lba
Definition: scsicmds.h:167
uint8_t lb_p_pb_exp
Definition: scsicmds.h:164
uint8_t prot_type
Definition: scsicmds.h:161
uint8_t p_i_exp
Definition: scsicmds.h:163
uint32_t lb_size
Definition: scsicmds.h:159
uint64_t num_lblocks
Definition: scsicmds.h:158
uint8_t resp_code
Definition: scsicmds.h:120
uint8_t sense_key
Definition: scsicmds.h:121
uint8_t subpage_code
Definition: scsicmds.h:172