smartmontools SVN Rev 5640
Utility to control and monitor storage systems with "S.M.A.R.T."
Macros | Functions | Variables
scsiprint.cpp File Reference
#include "config.h"
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include "scsicmds.h"
#include "atacmds.h"
#include "dev_interface.h"
#include "scsiprint.h"
#include "smartctl.h"
#include "utility.h"
#include "sg_unaligned.h"
#include "farmcmds.h"
#include "farmprint.h"
Include dependency graph for scsiprint.cpp:

Go to the source code of this file.

Macros

#define __STDC_FORMAT_MACROS   1
 
#define GBUF_SIZE   65532
 
#define ARRAY_SIZE(arr)   (sizeof(arr) / sizeof((arr)[0]))
 
#define LOG_RESP_LEN   252
 
#define LOG_RESP_LONG_LEN   ((62 * 256) + 252)
 
#define LOG_RESP_TAPE_ALERT_LEN   0x144
 
#define SCSI_SUPP_LOG_PAGES_MAX_COUNT   (252 + (62 * 128) + 126)
 
#define SCSI_VERSION_SPC_4   0x6
 
#define SCSI_VERSION_SPC_5   0x7
 
#define SCSI_VERSION_SPC_6   0xd /* T10/BSR INCITS 566, proposed in 23-015r0 */
 
#define SCSI_VERSION_HIGHEST   SCSI_VERSION_SPC_6
 
#define T10_VENDOR_SEAGATE   "SEAGATE"
 
#define T10_VENDOR_HITACHI_1   "HITACHI"
 
#define T10_VENDOR_HITACHI_2   "HL-DT-ST"
 
#define T10_VENDOR_HITACHI_3   "HGST"
 

Functions

static bool seagate_or_hitachi (void)
 
static bool all_ffs (const uint8_t *bp, int b_len)
 
static std::string rtrim (const std::string &s, const char *t=" \t\n\r\f\v")
 
static void scsiGetSupportedLogPages (scsi_device *device)
 
static int scsiGetSmartData (scsi_device *device, bool attribs)
 
static int scsiPrintActiveTapeAlerts (scsi_device *device, int peripheral_type, bool from_health)
 
static void scsiGetStartStopData (scsi_device *device)
 
static void scsiPrintPendingDefectsLPage (scsi_device *device)
 
static void scsiPrintGrownDefectListLen (scsi_device *device, bool prefer12)
 
static uint64_t variableLengthIntegerParam (const unsigned char *ucp)
 
static void scsiPrintSeagateCacheLPage (scsi_device *device)
 
static void scsiPrintSeagateFactoryLPage (scsi_device *device)
 
static void scsiPrintErrorCounterLog (scsi_device *device)
 
static int scsiPrintSelfTest (scsi_device *device)
 
static int scsiPrintBackgroundResults (scsi_device *device, bool only_pow_time)
 
static int64_t scsiGetTimeUnitInNano (const uint8_t *ucp, int num, uint16_t ti_pc)
 
static void scsiPrintTimeUnitInNano (int leadin_spaces, uint64_t intervals, int64_t timeUnitInNS)
 
static int scsiPrintGStatsPerf (scsi_device *device)
 
static int scsiPrintSSMedia (scsi_device *device)
 
static int scsiPrintZBDeviceStats (scsi_device *device)
 
static int scsiPrintTapeDeviceStats (scsi_device *device)
 
static int scsiPrintFormatStatus (scsi_device *device)
 
static void show_sas_phy_event_info (const json::ref &jref, int peis, unsigned int val, unsigned thresh_val)
 
static void show_sas_port_param (int port_num, unsigned char *ucp, int param_len)
 
static int show_protocol_specific_port_page (unsigned char *resp, int len)
 
static int scsiPrintSasPhy (scsi_device *device, int reset)
 
static int scsiGetDriveInfo (scsi_device *device, uint8_t *peripheral_type, bool &have_zbc, bool all)
 
static int scsiSmartEnable (scsi_device *device)
 
static int scsiSmartDisable (scsi_device *device)
 
static void scsiPrintTemp (scsi_device *device)
 
static void scsiPrintEnviroReporting (scsi_device *device)
 
int scsiPrintMain (scsi_device *device, const scsi_print_options &options)
 

Variables

const char * scsiprint_c_cvsid
 
uint8_t gBuf [GBUF_SIZE]
 
static bool gSmartLPage = false
 
static bool gTempLPage = false
 
static bool gSelfTestLPage = false
 
static bool gStartStopLPage = false
 
static bool gReadECounterLPage = false
 
static bool gWriteECounterLPage = false
 
static bool gVerifyECounterLPage = false
 
static bool gNonMediumELPage = false
 
static bool gLastNErrorEvLPage = false
 
static bool gBackgroundResultsLPage = false
 
static bool gProtocolSpecificLPage = false
 
static bool gTapeAlertsLPage = false
 
static bool gSSMediaLPage = false
 
static bool gFormatStatusLPage = false
 
static bool gEnviroReportingLPage = false
 
static bool gEnviroLimitsLPage = false
 
static bool gUtilizationLPage = false
 
static bool gPendDefectsLPage = false
 
static bool gBackgroundOpLPage = false
 
static bool gLPSMisalignLPage = false
 
static bool gTapeDeviceStatsLPage = false
 
static bool gZBDeviceStatsLPage = false
 
static bool gGenStatsAndPerfLPage = false
 
static bool gSeagateCacheLPage = false
 
static bool gSeagateFactoryLPage = false
 
static bool gSeagateFarmLPage = false
 
static bool gIecMPage = true
 
static int modese_len = 0
 
static int scsi_version
 
static char scsi_vendor [8+1]
 
static const char * logSenStr = "Log Sense"
 
static const char * logSenRspStr = "Log Sense response"
 
static const char * gsap_s = "General statistics and performance"
 
static const char * ssm_s = "Solid state media"
 
static const char * zbds_s = "Zoned block device statistics"
 
static const char * lp_s = "log page"
 
static const char *const severities = "CWI"
 
static const char * self_test_code []
 
static const char * self_test_result []
 
static const char * bms_status []
 
static const char * reassign_status []
 
static const char * peripheral_dt_arr [32]
 
static const char * transport_proto_arr []
 

Macro Definition Documentation

◆ __STDC_FORMAT_MACROS

#define __STDC_FORMAT_MACROS   1

Definition at line 15 of file scsiprint.cpp.

◆ ARRAY_SIZE

#define ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof((arr)[0]))

Definition at line 39 of file scsiprint.cpp.

◆ GBUF_SIZE

#define GBUF_SIZE   65532

Definition at line 34 of file scsiprint.cpp.

◆ LOG_RESP_LEN

#define LOG_RESP_LEN   252

Definition at line 42 of file scsiprint.cpp.

◆ LOG_RESP_LONG_LEN

#define LOG_RESP_LONG_LEN   ((62 * 256) + 252)

Definition at line 43 of file scsiprint.cpp.

◆ LOG_RESP_TAPE_ALERT_LEN

#define LOG_RESP_TAPE_ALERT_LEN   0x144

Definition at line 44 of file scsiprint.cpp.

◆ SCSI_SUPP_LOG_PAGES_MAX_COUNT

#define SCSI_SUPP_LOG_PAGES_MAX_COUNT   (252 + (62 * 128) + 126)

Definition at line 47 of file scsiprint.cpp.

◆ SCSI_VERSION_HIGHEST

#define SCSI_VERSION_HIGHEST   SCSI_VERSION_SPC_6

Definition at line 90 of file scsiprint.cpp.

◆ SCSI_VERSION_SPC_4

#define SCSI_VERSION_SPC_4   0x6

Definition at line 87 of file scsiprint.cpp.

◆ SCSI_VERSION_SPC_5

#define SCSI_VERSION_SPC_5   0x7

Definition at line 88 of file scsiprint.cpp.

◆ SCSI_VERSION_SPC_6

#define SCSI_VERSION_SPC_6   0xd /* T10/BSR INCITS 566, proposed in 23-015r0 */

Definition at line 89 of file scsiprint.cpp.

◆ T10_VENDOR_HITACHI_1

#define T10_VENDOR_HITACHI_1   "HITACHI"

Definition at line 96 of file scsiprint.cpp.

◆ T10_VENDOR_HITACHI_2

#define T10_VENDOR_HITACHI_2   "HL-DT-ST"

Definition at line 97 of file scsiprint.cpp.

◆ T10_VENDOR_HITACHI_3

#define T10_VENDOR_HITACHI_3   "HGST"

Definition at line 98 of file scsiprint.cpp.

◆ T10_VENDOR_SEAGATE

#define T10_VENDOR_SEAGATE   "SEAGATE"

Definition at line 95 of file scsiprint.cpp.

Function Documentation

◆ all_ffs()

static bool all_ffs ( const uint8_t *  bp,
int  b_len 
)
static

Definition at line 122 of file scsiprint.cpp.

◆ rtrim()

static std::string rtrim ( const std::string &  s,
const char *  t = " \t\n\r\f\v" 
)
static

Definition at line 134 of file scsiprint.cpp.

◆ scsiGetDriveInfo()

static int scsiGetDriveInfo ( scsi_device device,
uint8_t *  peripheral_type,
bool &  have_zbc,
bool  all 
)
static

Definition at line 2826 of file scsiprint.cpp.

◆ scsiGetSmartData()

static int scsiGetSmartData ( scsi_device device,
bool  attribs 
)
static

Definition at line 372 of file scsiprint.cpp.

◆ scsiGetStartStopData()

static void scsiGetStartStopData ( scsi_device device)
static

Definition at line 491 of file scsiprint.cpp.

◆ scsiGetSupportedLogPages()

static void scsiGetSupportedLogPages ( scsi_device device)
static

Definition at line 143 of file scsiprint.cpp.

◆ scsiGetTimeUnitInNano()

static int64_t scsiGetTimeUnitInNano ( const uint8_t *  ucp,
int  num,
uint16_t  ti_pc 
)
static

Definition at line 1457 of file scsiprint.cpp.

◆ scsiPrintActiveTapeAlerts()

static int scsiPrintActiveTapeAlerts ( scsi_device device,
int  peripheral_type,
bool  from_health 
)
static

Definition at line 430 of file scsiprint.cpp.

◆ scsiPrintBackgroundResults()

static int scsiPrintBackgroundResults ( scsi_device device,
bool  only_pow_time 
)
static

Definition at line 1302 of file scsiprint.cpp.

◆ scsiPrintEnviroReporting()

static void scsiPrintEnviroReporting ( scsi_device device)
static

Definition at line 3324 of file scsiprint.cpp.

◆ scsiPrintErrorCounterLog()

static void scsiPrintErrorCounterLog ( scsi_device device)
static

Definition at line 933 of file scsiprint.cpp.

◆ scsiPrintFormatStatus()

static int scsiPrintFormatStatus ( scsi_device device)
static

Definition at line 2185 of file scsiprint.cpp.

◆ scsiPrintGrownDefectListLen()

static void scsiPrintGrownDefectListLen ( scsi_device device,
bool  prefer12 
)
static

Definition at line 654 of file scsiprint.cpp.

◆ scsiPrintGStatsPerf()

static int scsiPrintGStatsPerf ( scsi_device device)
static

Definition at line 1522 of file scsiprint.cpp.

◆ scsiPrintMain()

int scsiPrintMain ( scsi_device device,
const scsi_print_options options 
)

Definition at line 3494 of file scsiprint.cpp.

◆ scsiPrintPendingDefectsLPage()

static void scsiPrintPendingDefectsLPage ( scsi_device device)
static

Definition at line 575 of file scsiprint.cpp.

◆ scsiPrintSasPhy()

static int scsiPrintSasPhy ( scsi_device device,
int  reset 
)
static

Definition at line 2728 of file scsiprint.cpp.

◆ scsiPrintSeagateCacheLPage()

static void scsiPrintSeagateCacheLPage ( scsi_device device)
static

Definition at line 773 of file scsiprint.cpp.

◆ scsiPrintSeagateFactoryLPage()

static void scsiPrintSeagateFactoryLPage ( scsi_device device)
static

Definition at line 842 of file scsiprint.cpp.

◆ scsiPrintSelfTest()

static int scsiPrintSelfTest ( scsi_device device)
static

Definition at line 1090 of file scsiprint.cpp.

◆ scsiPrintSSMedia()

static int scsiPrintSSMedia ( scsi_device device)
static

Definition at line 1723 of file scsiprint.cpp.

◆ scsiPrintTapeDeviceStats()

static int scsiPrintTapeDeviceStats ( scsi_device device)
static

Definition at line 1910 of file scsiprint.cpp.

◆ scsiPrintTemp()

static void scsiPrintTemp ( scsi_device device)
static

Definition at line 3300 of file scsiprint.cpp.

◆ scsiPrintTimeUnitInNano()

static void scsiPrintTimeUnitInNano ( int  leadin_spaces,
uint64_t  intervals,
int64_t  timeUnitInNS 
)
static

Definition at line 1503 of file scsiprint.cpp.

◆ scsiPrintZBDeviceStats()

static int scsiPrintZBDeviceStats ( scsi_device device)
static

Definition at line 1782 of file scsiprint.cpp.

◆ scsiSmartDisable()

static int scsiSmartDisable ( scsi_device device)
static

Definition at line 3263 of file scsiprint.cpp.

◆ scsiSmartEnable()

static int scsiSmartEnable ( scsi_device device)
static

Definition at line 3226 of file scsiprint.cpp.

◆ seagate_or_hitachi()

static bool seagate_or_hitachi ( void  )
static

Definition at line 109 of file scsiprint.cpp.

◆ show_protocol_specific_port_page()

static int show_protocol_specific_port_page ( unsigned char *  resp,
int  len 
)
static

Definition at line 2704 of file scsiprint.cpp.

◆ show_sas_phy_event_info()

static void show_sas_phy_event_info ( const json::ref jref,
int  peis,
unsigned int  val,
unsigned  thresh_val 
)
static

Definition at line 2320 of file scsiprint.cpp.

◆ show_sas_port_param()

static void show_sas_port_param ( int  port_num,
unsigned char *  ucp,
int  param_len 
)
static

Definition at line 2523 of file scsiprint.cpp.

◆ variableLengthIntegerParam()

static uint64_t variableLengthIntegerParam ( const unsigned char *  ucp)
static

Definition at line 759 of file scsiprint.cpp.

Variable Documentation

◆ bms_status

const char* bms_status[]
static
Initial value:
= {
"no scans active",
"scan is active",
"pre-scan is active",
"halted due to fatal error",
"halted due to a vendor specific pattern of error",
"halted due to medium formatted without P-List",
"halted - vendor specific cause",
"halted due to temperature out of range",
"waiting until BMS interval timer expires",
}

Definition at line 1271 of file scsiprint.cpp.

◆ gBackgroundOpLPage

bool gBackgroundOpLPage = false
static

Definition at line 68 of file scsiprint.cpp.

◆ gBackgroundResultsLPage

bool gBackgroundResultsLPage = false
static

Definition at line 59 of file scsiprint.cpp.

◆ gBuf

uint8_t gBuf[GBUF_SIZE]

Definition at line 41 of file scsiprint.cpp.

◆ gEnviroLimitsLPage

bool gEnviroLimitsLPage = false
static

Definition at line 65 of file scsiprint.cpp.

◆ gEnviroReportingLPage

bool gEnviroReportingLPage = false
static

Definition at line 64 of file scsiprint.cpp.

◆ gFormatStatusLPage

bool gFormatStatusLPage = false
static

Definition at line 63 of file scsiprint.cpp.

◆ gGenStatsAndPerfLPage

bool gGenStatsAndPerfLPage = false
static

Definition at line 72 of file scsiprint.cpp.

◆ gIecMPage

bool gIecMPage = true
static

Definition at line 80 of file scsiprint.cpp.

◆ gLastNErrorEvLPage

bool gLastNErrorEvLPage = false
static

Definition at line 58 of file scsiprint.cpp.

◆ gLPSMisalignLPage

bool gLPSMisalignLPage = false
static

Definition at line 69 of file scsiprint.cpp.

◆ gNonMediumELPage

bool gNonMediumELPage = false
static

Definition at line 57 of file scsiprint.cpp.

◆ gPendDefectsLPage

bool gPendDefectsLPage = false
static

Definition at line 67 of file scsiprint.cpp.

◆ gProtocolSpecificLPage

bool gProtocolSpecificLPage = false
static

Definition at line 60 of file scsiprint.cpp.

◆ gReadECounterLPage

bool gReadECounterLPage = false
static

Definition at line 54 of file scsiprint.cpp.

◆ gsap_s

const char* gsap_s = "General statistics and performance"
static

Definition at line 102 of file scsiprint.cpp.

◆ gSeagateCacheLPage

bool gSeagateCacheLPage = false
static

Definition at line 75 of file scsiprint.cpp.

◆ gSeagateFactoryLPage

bool gSeagateFactoryLPage = false
static

Definition at line 76 of file scsiprint.cpp.

◆ gSeagateFarmLPage

bool gSeagateFarmLPage = false
static

Definition at line 77 of file scsiprint.cpp.

◆ gSelfTestLPage

bool gSelfTestLPage = false
static

Definition at line 52 of file scsiprint.cpp.

◆ gSmartLPage

bool gSmartLPage = false
static

Definition at line 50 of file scsiprint.cpp.

◆ gSSMediaLPage

bool gSSMediaLPage = false
static

Definition at line 62 of file scsiprint.cpp.

◆ gStartStopLPage

bool gStartStopLPage = false
static

Definition at line 53 of file scsiprint.cpp.

◆ gTapeAlertsLPage

bool gTapeAlertsLPage = false
static

Definition at line 61 of file scsiprint.cpp.

◆ gTapeDeviceStatsLPage

bool gTapeDeviceStatsLPage = false
static

Definition at line 70 of file scsiprint.cpp.

◆ gTempLPage

bool gTempLPage = false
static

Definition at line 51 of file scsiprint.cpp.

◆ gUtilizationLPage

bool gUtilizationLPage = false
static

Definition at line 66 of file scsiprint.cpp.

◆ gVerifyECounterLPage

bool gVerifyECounterLPage = false
static

Definition at line 56 of file scsiprint.cpp.

◆ gWriteECounterLPage

bool gWriteECounterLPage = false
static

Definition at line 55 of file scsiprint.cpp.

◆ gZBDeviceStatsLPage

bool gZBDeviceStatsLPage = false
static

Definition at line 71 of file scsiprint.cpp.

◆ logSenRspStr

const char* logSenRspStr = "Log Sense response"
static

Definition at line 101 of file scsiprint.cpp.

◆ logSenStr

const char* logSenStr = "Log Sense"
static

Definition at line 100 of file scsiprint.cpp.

◆ lp_s

const char* lp_s = "log page"
static

Definition at line 105 of file scsiprint.cpp.

◆ modese_len

int modese_len = 0
static

Definition at line 83 of file scsiprint.cpp.

◆ peripheral_dt_arr

const char* peripheral_dt_arr[32]
static

Definition at line 2769 of file scsiprint.cpp.

◆ reassign_status

const char* reassign_status[]
static
Initial value:
= {
"Reserved [0x0]",
"Require Write or Reassign Blocks command",
"Successfully reassigned",
"Reserved [0x3]",
"Reassignment by disk failed",
"Recovered via rewrite in-place",
"Reassigned by app, has valid data",
"Reassigned by app, has no valid data",
"Unsuccessfully reassigned by app",
}

Definition at line 1283 of file scsiprint.cpp.

◆ scsi_vendor

char scsi_vendor[8+1]
static

Definition at line 94 of file scsiprint.cpp.

◆ scsi_version

int scsi_version
static

Definition at line 86 of file scsiprint.cpp.

◆ scsiprint_c_cvsid

const char* scsiprint_c_cvsid
Initial value:
= "$Id: scsiprint.cpp 5556 2023-10-17 04:26:48Z dpgilbert $"
#define SCSIPRINT_H_CVSID
Definition: scsiprint.h:19

Definition at line 36 of file scsiprint.cpp.

◆ self_test_code

const char* self_test_code[]
static
Initial value:
= {
"Default ",
"Background short",
"Background long ",
"Reserved(3) ",
"Abort background",
"Foreground short",
"Foreground long ",
"Reserved(7) "
}

Definition at line 1055 of file scsiprint.cpp.

◆ self_test_result

const char* self_test_result[]
static
Initial value:
= {
"Completed ",
"Aborted (by user command)",
"Aborted (device reset ?) ",
"Unknown error, incomplete",
"Completed, segment failed",
"Failed in first segment ",
"Failed in second segment ",
"Failed in segment",
"Reserved(8) ",
"Reserved(9) ",
"Reserved(10) ",
"Reserved(11) ",
"Reserved(12) ",
"Reserved(13) ",
"Reserved(14) ",
"Self test in progress ..."
}

Definition at line 1066 of file scsiprint.cpp.

◆ severities

const char* const severities = "CWI"
static

Definition at line 427 of file scsiprint.cpp.

◆ ssm_s

const char* ssm_s = "Solid state media"
static

Definition at line 103 of file scsiprint.cpp.

◆ transport_proto_arr

const char* transport_proto_arr[]
static
Initial value:
= {
"Fibre channel (FCP-4)",
"Parallel SCSI (SPI-4)",
"SSA",
"IEEE 1394 (SBP-3)",
"RDMA (SRP)",
"iSCSI",
"SAS (SPL-4)",
"ADT",
"ATA (ACS-2)",
"UAS",
"SOP",
"PCIe",
"0xc",
"0xd",
"0xe",
"None given [0xf]"
}

Definition at line 2805 of file scsiprint.cpp.

◆ zbds_s

const char* zbds_s = "Zoned block device statistics"
static

Definition at line 104 of file scsiprint.cpp.