smartmontools SVN Rev 5388
Utility to control and monitor storage systems with "S.M.A.R.T."
Classes | Macros | Functions | Variables
scsicmds.cpp File Reference
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "config.h"
#include "scsicmds.h"
#include "dev_interface.h"
#include "utility.h"
#include "sg_unaligned.h"
Include dependency graph for scsicmds.cpp:

Go to the source code of this file.

Classes

struct  scsi_opcode_name
 

Macros

#define DEXCPT_ENABLE   0x08
 
#define EWASC_ENABLE   0x10
 
#define DEXCPT_DISABLE   0xf7
 
#define EWASC_DISABLE   0xef
 
#define TEST_DISABLE   0xfb
 
#define SCSI_IEC_MP_BYTE2_ENABLED   0x10
 
#define SCSI_IEC_MP_BYTE2_TEST_MASK   0x4
 
#define SCSI_IEC_MP_MRIE   6
 
#define SCSI_IEC_MP_INTERVAL_T   0
 
#define SCSI_IEC_MP_REPORT_COUNT   1
 

Functions

void dStrHex (const uint8_t *up, int len, int no_ascii)
 
bool is_scsi_cdb (const uint8_t *cdbp, int clen)
 
const char * scsi_get_opcode_name (uint8_t opcode)
 
void scsi_do_sense_disect (const struct scsi_cmnd_io *io_buf, struct scsi_sense_disect *out)
 
int scsiSimpleSenseFilter (const struct scsi_sense_disect *sinfo)
 
const char * scsiErrString (int scsiErr)
 
char * scsi_get_sense_key_str (int sense_key, int buff_len, char *buff)
 
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)
 
int scsi_decode_lu_dev_id (const unsigned char *b, int blen, char *s, int slen, int *transport)
 
int scsiLogSense (scsi_device *device, int pagenum, int subpagenum, uint8_t *pBuf, int bufLen, int known_resp_len)
 
int scsiLogSelect (scsi_device *device, int pcr, int sp, int pc, int pagenum, int subpagenum, uint8_t *pBuf, int bufLen)
 
int scsiModeSense (scsi_device *device, int pagenum, int subpagenum, int pc, uint8_t *pBuf, int bufLen)
 
int scsiModeSelect (scsi_device *device, int sp, uint8_t *pBuf, int bufLen)
 
int scsiModeSense10 (scsi_device *device, int pagenum, int subpagenum, int pc, uint8_t *pBuf, int bufLen)
 
int scsiModeSelect10 (scsi_device *device, int sp, uint8_t *pBuf, int bufLen)
 
int scsiStdInquiry (scsi_device *device, uint8_t *pBuf, int bufLen)
 
int scsiInquiryVpd (scsi_device *device, int vpd_page, uint8_t *pBuf, int bufLen)
 
int scsiRequestSense (scsi_device *device, struct scsi_sense_disect *sense_info)
 
int scsiSetPowerCondition (scsi_device *device, int power_cond, int pcond_modifier)
 
int scsiSendDiagnostic (scsi_device *device, int functioncode, uint8_t *pBuf, int bufLen)
 
static int _testunitready (scsi_device *device, struct scsi_sense_disect *sinfop)
 
int scsiTestUnitReady (scsi_device *device)
 
int scsiReadDefect10 (scsi_device *device, int req_plist, int req_glist, int dl_format, uint8_t *pBuf, int bufLen)
 
int scsiReadDefect12 (scsi_device *device, int req_plist, int req_glist, int dl_format, int addrDescIndex, uint8_t *pBuf, int bufLen)
 
bool scsi_pass_through_yield_sense (scsi_device *device, scsi_cmnd_io *iop, scsi_sense_disect &sinfo)
 
int scsiReadCapacity10 (scsi_device *device, unsigned int *last_lbap, unsigned int *lb_sizep)
 
int scsiReadCapacity16 (scsi_device *device, uint8_t *pBuf, int bufLen)
 
uint64_t scsiGetSize (scsi_device *device, bool avoid_rcap16, struct scsi_readcap_resp *srrp)
 
int scsiModePageOffset (const uint8_t *resp, int len, int modese_len)
 
int scsiFetchIECmpage (scsi_device *device, struct scsi_iec_mode_page *iecp, int modese_len)
 
int scsi_IsExceptionControlEnabled (const struct scsi_iec_mode_page *iecp)
 
int scsi_IsWarningEnabled (const struct scsi_iec_mode_page *iecp)
 
int scsiSetExceptionControlAndWarning (scsi_device *device, int enabled, const struct scsi_iec_mode_page *iecp)
 
int scsiGetTemp (scsi_device *device, uint8_t *currenttemp, uint8_t *triptemp)
 
int scsiCheckIE (scsi_device *device, int hasIELogPage, int hasTempLogPage, uint8_t *asc, uint8_t *ascq, uint8_t *currenttemp, uint8_t *triptemp)
 
const char * scsiTapeAlertsTapeDevice (unsigned short code)
 
const char * scsiTapeAlertsChangerDevice (unsigned short code)
 
const char * scsiGetIEString (uint8_t asc, uint8_t ascq)
 
int scsiSmartDefaultSelfTest (scsi_device *device)
 
int scsiSmartShortSelfTest (scsi_device *device)
 
int scsiSmartExtendSelfTest (scsi_device *device)
 
int scsiSmartShortCapSelfTest (scsi_device *device)
 
int scsiSmartExtendCapSelfTest (scsi_device *device)
 
int scsiSmartSelfTestAbort (scsi_device *device)
 
int scsiFetchExtendedSelfTestTime (scsi_device *device, int *durationSec, int modese_len)
 
void scsiDecodeErrCounterPage (unsigned char *resp, struct scsiErrorCounter *ecp)
 
void scsiDecodeNonMediumErrPage (unsigned char *resp, struct scsiNonMediumError *nmep)
 
int scsiCountFailedSelfTests (scsi_device *fd, int noisy)
 
int scsiSelfTestInProgress (scsi_device *fd, int *inProgress)
 
int scsiFetchControlGLTSD (scsi_device *device, int modese_len, int current)
 
int scsiGetRPM (scsi_device *device, int modese_len, int *form_factorp, int *haw_zbcp)
 
int scsiGetSetCache (scsi_device *device, int modese_len, short int *wcep, short int *rcdp)
 
int scsiSetControlGLTSD (scsi_device *device, int enabled, int modese_len)
 
int scsiFetchTransportProtocol (scsi_device *device, int modese_len)
 
const unsigned char * sg_scsi_sense_desc_find (const unsigned char *sensep, int sense_len, int desc_type)
 
void scsi_format_id_string (char *out, const uint8_t *in, int n)
 

Variables

const char * scsicmds_c_cvsid
 
static const char * logSenStr = "Log Sense"
 
unsigned char scsi_debugmode = 0
 
supported_vpd_pagessupported_vpd_pages_p = NULL
 
static struct scsi_opcode_name opcode_name_arr []
 
static const char * vendor_specific = "<vendor specific>"
 
static const char * sense_key_desc []
 
static const char * TapeAlertsMessageTable []
 
static const char * ChangerTapeAlertsMessageTable []
 
static const char * strs_for_asc_5d []
 
static const char * strs_for_asc_b []
 
static char spare_buff [128]
 

Macro Definition Documentation

◆ DEXCPT_DISABLE

#define DEXCPT_DISABLE   0xf7

Definition at line 1428 of file scsicmds.cpp.

◆ DEXCPT_ENABLE

#define DEXCPT_ENABLE   0x08

Definition at line 1426 of file scsicmds.cpp.

◆ EWASC_DISABLE

#define EWASC_DISABLE   0xef

Definition at line 1429 of file scsicmds.cpp.

◆ EWASC_ENABLE

#define EWASC_ENABLE   0x10

Definition at line 1427 of file scsicmds.cpp.

◆ SCSI_IEC_MP_BYTE2_ENABLED

#define SCSI_IEC_MP_BYTE2_ENABLED   0x10

Definition at line 1513 of file scsicmds.cpp.

◆ SCSI_IEC_MP_BYTE2_TEST_MASK

#define SCSI_IEC_MP_BYTE2_TEST_MASK   0x4

Definition at line 1514 of file scsicmds.cpp.

◆ SCSI_IEC_MP_INTERVAL_T

#define SCSI_IEC_MP_INTERVAL_T   0

Definition at line 1517 of file scsicmds.cpp.

◆ SCSI_IEC_MP_MRIE

#define SCSI_IEC_MP_MRIE   6

Definition at line 1516 of file scsicmds.cpp.

◆ SCSI_IEC_MP_REPORT_COUNT

#define SCSI_IEC_MP_REPORT_COUNT   1

Definition at line 1518 of file scsicmds.cpp.

◆ TEST_DISABLE

#define TEST_DISABLE   0xfb

Definition at line 1430 of file scsicmds.cpp.

Function Documentation

◆ _testunitready()

static int _testunitready ( scsi_device device,
struct scsi_sense_disect sinfop 
)
static

Definition at line 1094 of file scsicmds.cpp.

◆ dStrHex()

void dStrHex ( const uint8_t *  up,
int  len,
int  no_ascii 
)

Definition at line 78 of file scsicmds.cpp.

◆ is_scsi_cdb()

bool is_scsi_cdb ( const uint8_t *  cdbp,
int  clen 
)

Definition at line 151 of file scsicmds.cpp.

◆ scsi_decode_lu_dev_id()

int scsi_decode_lu_dev_id ( const unsigned char *  b,
int  blen,
char *  s,
int  slen,
int *  transport 
)

Definition at line 433 of file scsicmds.cpp.

◆ scsi_do_sense_disect()

void scsi_do_sense_disect ( const struct scsi_cmnd_io io_buf,
struct scsi_sense_disect out 
)

Definition at line 251 of file scsicmds.cpp.

◆ scsi_format_id_string()

void scsi_format_id_string ( char *  out,
const uint8_t *  in,
int  n 
)

Definition at line 2852 of file scsicmds.cpp.

◆ scsi_get_opcode_name()

const char * scsi_get_opcode_name ( uint8_t  opcode)

Definition at line 233 of file scsicmds.cpp.

◆ scsi_get_sense_key_str()

char * scsi_get_sense_key_str ( int  sense_key,
int  buff_len,
char *  buff 
)

Definition at line 381 of file scsicmds.cpp.

◆ scsi_IsExceptionControlEnabled()

int scsi_IsExceptionControlEnabled ( const struct scsi_iec_mode_page iecp)

Definition at line 1485 of file scsicmds.cpp.

◆ scsi_IsWarningEnabled()

int scsi_IsWarningEnabled ( const struct scsi_iec_mode_page iecp)

Definition at line 1499 of file scsicmds.cpp.

◆ scsi_pass_through_yield_sense()

bool scsi_pass_through_yield_sense ( scsi_device device,
scsi_cmnd_io iop,
scsi_sense_disect sinfo 
)

Definition at line 1212 of file scsicmds.cpp.

◆ scsi_vpd_dev_id_iter()

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 at line 404 of file scsicmds.cpp.

◆ scsiCheckIE()

int scsiCheckIE ( scsi_device device,
int  hasIELogPage,
int  hasTempLogPage,
uint8_t *  asc,
uint8_t *  ascq,
uint8_t *  currenttemp,
uint8_t *  triptemp 
)

Definition at line 1621 of file scsicmds.cpp.

◆ scsiCountFailedSelfTests()

int scsiCountFailedSelfTests ( scsi_device fd,
int  noisy 
)

Definition at line 2457 of file scsicmds.cpp.

◆ scsiDecodeErrCounterPage()

void scsiDecodeErrCounterPage ( unsigned char *  resp,
struct scsiErrorCounter ecp 
)

Definition at line 2358 of file scsicmds.cpp.

◆ scsiDecodeNonMediumErrPage()

void scsiDecodeNonMediumErrPage ( unsigned char *  resp,
struct scsiNonMediumError nmep 
)

Definition at line 2396 of file scsicmds.cpp.

◆ scsiErrString()

const char * scsiErrString ( int  scsiErr)

Definition at line 316 of file scsicmds.cpp.

◆ scsiFetchControlGLTSD()

int scsiFetchControlGLTSD ( scsi_device device,
int  modese_len,
int  current 
)

Definition at line 2536 of file scsicmds.cpp.

◆ scsiFetchExtendedSelfTestTime()

int scsiFetchExtendedSelfTestTime ( scsi_device device,
int *  durationSec,
int  modese_len 
)

Definition at line 2306 of file scsicmds.cpp.

◆ scsiFetchIECmpage()

int scsiFetchIECmpage ( scsi_device device,
struct scsi_iec_mode_page iecp,
int  modese_len 
)

Definition at line 1438 of file scsicmds.cpp.

◆ scsiFetchTransportProtocol()

int scsiFetchTransportProtocol ( scsi_device device,
int  modese_len 
)

Definition at line 2792 of file scsicmds.cpp.

◆ scsiGetIEString()

const char * scsiGetIEString ( uint8_t  asc,
uint8_t  ascq 
)

Definition at line 2206 of file scsicmds.cpp.

◆ scsiGetRPM()

int scsiGetRPM ( scsi_device device,
int  modese_len,
int *  form_factorp,
int *  haw_zbcp 
)

Definition at line 2573 of file scsicmds.cpp.

◆ scsiGetSetCache()

int scsiGetSetCache ( scsi_device device,
int  modese_len,
short int *  wcep,
short int *  rcdp 
)

Definition at line 2618 of file scsicmds.cpp.

◆ scsiGetSize()

uint64_t scsiGetSize ( scsi_device device,
bool  avoid_rcap16,
struct scsi_readcap_resp srrp 
)

Definition at line 1317 of file scsicmds.cpp.

◆ scsiGetTemp()

int scsiGetTemp ( scsi_device device,
uint8_t *  currenttemp,
uint8_t *  triptemp 
)

Definition at line 1598 of file scsicmds.cpp.

◆ scsiInquiryVpd()

int scsiInquiryVpd ( scsi_device device,
int  vpd_page,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 879 of file scsicmds.cpp.

◆ scsiLogSelect()

int scsiLogSelect ( scsi_device device,
int  pcr,
int  sp,
int  pc,
int  pagenum,
int  subpagenum,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 648 of file scsicmds.cpp.

◆ scsiLogSense()

int scsiLogSense ( scsi_device device,
int  pagenum,
int  subpagenum,
uint8_t *  pBuf,
int  bufLen,
int  known_resp_len 
)

Definition at line 559 of file scsicmds.cpp.

◆ scsiModePageOffset()

int scsiModePageOffset ( const uint8_t *  resp,
int  len,
int  modese_len 
)

Definition at line 1395 of file scsicmds.cpp.

◆ scsiModeSelect()

int scsiModeSelect ( scsi_device device,
int  sp,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 726 of file scsicmds.cpp.

◆ scsiModeSelect10()

int scsiModeSelect10 ( scsi_device device,
int  sp,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 809 of file scsicmds.cpp.

◆ scsiModeSense()

int scsiModeSense ( scsi_device device,
int  pagenum,
int  subpagenum,
int  pc,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 680 of file scsicmds.cpp.

◆ scsiModeSense10()

int scsiModeSense10 ( scsi_device device,
int  pagenum,
int  subpagenum,
int  pc,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 765 of file scsicmds.cpp.

◆ scsiReadCapacity10()

int scsiReadCapacity10 ( scsi_device device,
unsigned int *  last_lbap,
unsigned int *  lb_sizep 
)

Definition at line 1251 of file scsicmds.cpp.

◆ scsiReadCapacity16()

int scsiReadCapacity16 ( scsi_device device,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 1287 of file scsicmds.cpp.

◆ scsiReadDefect10()

int scsiReadDefect10 ( scsi_device device,
int  req_plist,
int  req_glist,
int  dl_format,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 1141 of file scsicmds.cpp.

◆ scsiReadDefect12()

int scsiReadDefect12 ( scsi_device device,
int  req_plist,
int  req_glist,
int  dl_format,
int  addrDescIndex,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 1175 of file scsicmds.cpp.

◆ scsiRequestSense()

int scsiRequestSense ( scsi_device device,
struct scsi_sense_disect sense_info 
)

Definition at line 937 of file scsicmds.cpp.

◆ scsiSelfTestInProgress()

int scsiSelfTestInProgress ( scsi_device fd,
int *  inProgress 
)

Definition at line 2508 of file scsicmds.cpp.

◆ scsiSendDiagnostic()

int scsiSendDiagnostic ( scsi_device device,
int  functioncode,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 1061 of file scsicmds.cpp.

◆ scsiSetControlGLTSD()

int scsiSetControlGLTSD ( scsi_device device,
int  enabled,
int  modese_len 
)

Definition at line 2722 of file scsicmds.cpp.

◆ scsiSetExceptionControlAndWarning()

int scsiSetExceptionControlAndWarning ( scsi_device device,
int  enabled,
const struct scsi_iec_mode_page iecp 
)

Definition at line 1528 of file scsicmds.cpp.

◆ scsiSetPowerCondition()

int scsiSetPowerCondition ( scsi_device device,
int  power_cond,
int  pcond_modifier 
)

Definition at line 1030 of file scsicmds.cpp.

◆ scsiSimpleSenseFilter()

int scsiSimpleSenseFilter ( const struct scsi_sense_disect sinfo)

Definition at line 273 of file scsicmds.cpp.

◆ scsiSmartDefaultSelfTest()

int scsiSmartDefaultSelfTest ( scsi_device device)

Definition at line 2236 of file scsicmds.cpp.

◆ scsiSmartExtendCapSelfTest()

int scsiSmartExtendCapSelfTest ( scsi_device device)

Definition at line 2281 of file scsicmds.cpp.

◆ scsiSmartExtendSelfTest()

int scsiSmartExtendSelfTest ( scsi_device device)

Definition at line 2258 of file scsicmds.cpp.

◆ scsiSmartSelfTestAbort()

int scsiSmartSelfTestAbort ( scsi_device device)

Definition at line 2293 of file scsicmds.cpp.

◆ scsiSmartShortCapSelfTest()

int scsiSmartShortCapSelfTest ( scsi_device device)

Definition at line 2270 of file scsicmds.cpp.

◆ scsiSmartShortSelfTest()

int scsiSmartShortSelfTest ( scsi_device device)

Definition at line 2247 of file scsicmds.cpp.

◆ scsiStdInquiry()

int scsiStdInquiry ( scsi_device device,
uint8_t *  pBuf,
int  bufLen 
)

Definition at line 849 of file scsicmds.cpp.

◆ scsiTapeAlertsChangerDevice()

const char * scsiTapeAlertsChangerDevice ( unsigned short  code)

Definition at line 2070 of file scsicmds.cpp.

◆ scsiTapeAlertsTapeDevice()

const char * scsiTapeAlertsTapeDevice ( unsigned short  code)

Definition at line 1922 of file scsicmds.cpp.

◆ scsiTestUnitReady()

int scsiTestUnitReady ( scsi_device device)

Definition at line 1125 of file scsicmds.cpp.

◆ sg_scsi_sense_desc_find()

const unsigned char * sg_scsi_sense_desc_find ( const unsigned char *  sensep,
int  sense_len,
int  desc_type 
)

Definition at line 2825 of file scsicmds.cpp.

Variable Documentation

◆ ChangerTapeAlertsMessageTable

const char* ChangerTapeAlertsMessageTable[]
static

Definition at line 1931 of file scsicmds.cpp.

◆ logSenStr

const char* logSenStr = "Log Sense"
static

Definition at line 42 of file scsicmds.cpp.

◆ opcode_name_arr

struct scsi_opcode_name opcode_name_arr[]
static
Initial value:
= {
{TEST_UNIT_READY, "test unit ready"},
{REQUEST_SENSE, "request sense"},
{INQUIRY, "inquiry"},
{MODE_SELECT, "mode select(6)"},
{MODE_SENSE, "mode sense(6)"},
{START_STOP_UNIT, "start stop unit"},
{RECEIVE_DIAGNOSTIC, "receive diagnostic"},
{SEND_DIAGNOSTIC, "send diagnostic"},
{READ_CAPACITY_10, "read capacity(10)"},
{READ_DEFECT_10, "read defect list(10)"},
{LOG_SELECT, "log select"},
{LOG_SENSE, "log sense"},
{MODE_SELECT_10, "mode select(10)"},
{MODE_SENSE_10, "mode sense(10)"},
{SAT_ATA_PASSTHROUGH_16, "ata pass-through(16)"},
{READ_CAPACITY_16, "read capacity(16)"},
{REPORT_LUNS, "report luns"},
{SAT_ATA_PASSTHROUGH_12, "ata pass-through(12)"},
{READ_DEFECT_12, "read defect list(12)"},
}
#define REPORT_LUNS
Definition: scsicmds.h:76
#define START_STOP_UNIT
Definition: scsicmds.h:73
#define READ_CAPACITY_10
Definition: scsicmds.h:79
#define MODE_SENSE
Definition: scsicmds.h:43
#define SAT_ATA_PASSTHROUGH_12
Definition: scsicmds.h:89
#define SEND_DIAGNOSTIC
Definition: scsicmds.h:64
#define READ_DEFECT_12
Definition: scsicmds.h:70
#define READ_DEFECT_10
Definition: scsicmds.h:67
#define RECEIVE_DIAGNOSTIC
Definition: scsicmds.h:61
#define MODE_SELECT_10
Definition: scsicmds.h:52
#define LOG_SENSE
Definition: scsicmds.h:40
#define SAT_ATA_PASSTHROUGH_16
Definition: scsicmds.h:92
#define READ_CAPACITY_16
Definition: scsicmds.h:82
#define MODE_SENSE_10
Definition: scsicmds.h:46
#define LOG_SELECT
Definition: scsicmds.h:37
#define TEST_UNIT_READY
Definition: scsicmds.h:34
#define MODE_SELECT
Definition: scsicmds.h:49
#define INQUIRY
Definition: scsicmds.h:55
#define REQUEST_SENSE
Definition: scsicmds.h:58

Definition at line 205 of file scsicmds.cpp.

◆ scsi_debugmode

unsigned char scsi_debugmode = 0

Definition at line 45 of file scsicmds.cpp.

◆ scsicmds_c_cvsid

const char* scsicmds_c_cvsid
Initial value:
="$Id: scsicmds.cpp 5337 2022-02-27 07:53:55Z dpgilbert $"
#define SCSICMDS_H_CVSID
Definition: scsicmds.h:22

Definition at line 39 of file scsicmds.cpp.

◆ sense_key_desc

const char* sense_key_desc[]
static
Initial value:
= {
"No Sense",
"Recovered Error",
"Not Ready",
"Medium Error",
"Hardware Error",
"Illegal Request",
"Unit Attention",
"Data Protect",
"Blank Check",
"Vendor specific(9)",
"Copy Aborted",
"Aborted Command",
"Equal",
"Volume Overflow",
"Miscompare",
"Completed"
}

Definition at line 354 of file scsicmds.cpp.

◆ spare_buff

char spare_buff[128]
static

Definition at line 2203 of file scsicmds.cpp.

◆ strs_for_asc_5d

const char* strs_for_asc_5d[]
static

Definition at line 2083 of file scsicmds.cpp.

◆ strs_for_asc_b

const char* strs_for_asc_b[]
static
Initial value:
= {
"WARNING",
"WARNING - SPECIFIED TEMPERATURE EXCEEDED",
"WARNING - ENCLOSURE DEGRADED"}

Definition at line 2198 of file scsicmds.cpp.

◆ supported_vpd_pages_p

supported_vpd_pages* supported_vpd_pages_p = NULL

Definition at line 47 of file scsicmds.cpp.

◆ TapeAlertsMessageTable

const char* TapeAlertsMessageTable[]
static

Definition at line 1678 of file scsicmds.cpp.

◆ vendor_specific

const char* vendor_specific = "<vendor specific>"
static

Definition at line 228 of file scsicmds.cpp.