📄 scsiprint.cpp
字号:
return 2; } if (! all) return 0; /* Do this here to try and detect badly conforming devices (some USB keys) that will lock up on a InquiryVpd or log sense or ... */ if ((iec_err = scsiFetchIECmpage(device, &iec, modese_len))) { if (SIMPLE_ERR_BAD_RESP == iec_err) { pout(">> Terminate command early due to bad response to IEC " "mode page\n"); PRINT_OFF(con); gIecMPage = 0; return 1; } } else modese_len = iec.modese_len; if (!con->dont_print_serial) { if (0 == (err = scsiInquiryVpd(device, 0x80, gBuf, 64))) { /* should use VPD page 0x83 and fall back to this page (0x80) * if 0x83 not supported. NAA requires a lot of decoding code */ len = gBuf[3]; gBuf[4 + len] = '\0'; pout("Serial number: %s\n", &gBuf[4]); } else if (con->reportscsiioctl > 0) { PRINT_ON(con); if (SIMPLE_ERR_BAD_RESP == err) pout("Vital Product Data (VPD) bit ignored in INQUIRY\n"); else pout("Vital Product Data (VPD) INQUIRY failed [%d]\n", err); PRINT_OFF(con); } } // print SCSI peripheral device type if (peri_dt < (int)(sizeof(peripheral_dt_arr) / sizeof(peripheral_dt_arr[0]))) pout("Device type: %s\n", peripheral_dt_arr[peri_dt]); else pout("Device type: <%d>\n", peri_dt); // See if transport protocol is known val = scsiFetchTransportProtocol(device, modese_len); if ((val >= 0) && (val <= 0xf)) pout("Transport protocol: %s\n", transport_proto_arr[val]); // print current time and date and timezone dateandtimezone(timedatetz); pout("Local Time is: %s\n", timedatetz); if ((SCSI_PT_SEQUENTIAL_ACCESS == *peripheral_type) || (SCSI_PT_MEDIUM_CHANGER == *peripheral_type)) is_tape = 1; // See if unit accepts SCSI commmands from us if ((err = scsiTestUnitReady(device))) { if (SIMPLE_ERR_NOT_READY == err) { PRINT_ON(con); if (!is_tape) pout("device is NOT READY (e.g. spun down, busy)\n"); else pout("device is NOT READY (e.g. no tape)\n"); PRINT_OFF(con); } else if (SIMPLE_ERR_NO_MEDIUM == err) { PRINT_ON(con); pout("NO MEDIUM present on device\n"); PRINT_OFF(con); } else if (SIMPLE_ERR_BECOMING_READY == err) { PRINT_ON(con); pout("device becoming ready (wait)\n"); PRINT_OFF(con); } else { PRINT_ON(con); pout("device Test Unit Ready [%s]\n", scsiErrString(err)); PRINT_OFF(con); } failuretest(MANDATORY_CMD, returnval|=FAILID); } if (iec_err) { if (!is_tape) { PRINT_ON(con); pout("Device does not support SMART"); if (con->reportscsiioctl > 0) pout(" [%s]\n", scsiErrString(iec_err)); else pout("\n"); PRINT_OFF(con); } gIecMPage = 0; return 0; } if (!is_tape) pout("Device supports SMART and is %s\n", (scsi_IsExceptionControlEnabled(&iec)) ? "Enabled" : "Disabled"); pout("%s\n", (scsi_IsWarningEnabled(&iec)) ? "Temperature Warning Enabled" : "Temperature Warning Disabled or Not Supported"); return 0;}static int scsiSmartEnable(int device){ struct scsi_iec_mode_page iec; int err; if ((err = scsiFetchIECmpage(device, &iec, modese_len))) { PRINT_ON(con); pout("unable to fetch IEC (SMART) mode page [%s]\n", scsiErrString(err)); PRINT_OFF(con); return 1; } else modese_len = iec.modese_len; if ((err = scsiSetExceptionControlAndWarning(device, 1, &iec))) { PRINT_ON(con); pout("unable to enable Exception control and warning [%s]\n", scsiErrString(err)); PRINT_OFF(con); return 1; } /* Need to refetch 'iec' since could be modified by previous call */ if ((err = scsiFetchIECmpage(device, &iec, modese_len))) { pout("unable to fetch IEC (SMART) mode page [%s]\n", scsiErrString(err)); return 1; } else modese_len = iec.modese_len; pout("Informational Exceptions (SMART) %s\n", scsi_IsExceptionControlEnabled(&iec) ? "enabled" : "disabled"); pout("Temperature warning %s\n", scsi_IsWarningEnabled(&iec) ? "enabled" : "disabled"); return 0;} static int scsiSmartDisable(int device){ struct scsi_iec_mode_page iec; int err; if ((err = scsiFetchIECmpage(device, &iec, modese_len))) { PRINT_ON(con); pout("unable to fetch IEC (SMART) mode page [%s]\n", scsiErrString(err)); PRINT_OFF(con); return 1; } else modese_len = iec.modese_len; if ((err = scsiSetExceptionControlAndWarning(device, 0, &iec))) { PRINT_ON(con); pout("unable to disable Exception control and warning [%s]\n", scsiErrString(err)); PRINT_OFF(con); return 1; } /* Need to refetch 'iec' since could be modified by previous call */ if ((err = scsiFetchIECmpage(device, &iec, modese_len))) { pout("unable to fetch IEC (SMART) mode page [%s]\n", scsiErrString(err)); return 1; } else modese_len = iec.modese_len; pout("Informational Exceptions (SMART) %s\n", scsi_IsExceptionControlEnabled(&iec) ? "enabled" : "disabled"); pout("Temperature warning %s\n", scsi_IsWarningEnabled(&iec) ? "enabled" : "disabled"); return 0;}static void scsiPrintTemp(int device){ UINT8 temp = 0; UINT8 trip = 0; if (scsiGetTemp(device, &temp, &trip)) return; if (temp) { if (255 != temp) pout("Current Drive Temperature: %d C\n", temp); else pout("Current Drive Temperature: <not available>\n"); } if (trip) pout("Drive Trip Temperature: %d C\n", trip);}/* Main entry point used by smartctl command. Return 0 for success */int scsiPrintMain(int fd){ int checkedSupportedLogPages = 0; UINT8 peripheral_type = 0; int returnval = 0; int res, durationSec; res = scsiGetDriveInfo(fd, &peripheral_type, con->driveinfo); if (res) { if (2 == res) return 0; else failuretest(MANDATORY_CMD, returnval |= FAILID); } if (con->smartenable) { if (scsiSmartEnable(fd)) failuretest(MANDATORY_CMD, returnval |= FAILSMART); } if (con->smartdisable) { if (scsiSmartDisable(fd)) failuretest(MANDATORY_CMD,returnval |= FAILSMART); } if (con->smartautosaveenable) { if (scsiSetControlGLTSD(fd, 0, modese_len)) { pout("Enable autosave (clear GLTSD bit) failed\n"); failuretest(OPTIONAL_CMD,returnval |= FAILSMART); } } if (con->smartautosavedisable) { if (scsiSetControlGLTSD(fd, 1, modese_len)) { pout("Disable autosave (set GLTSD bit) failed\n"); failuretest(OPTIONAL_CMD,returnval |= FAILSMART); } } if (con->checksmart) { scsiGetSupportedLogPages(fd); checkedSupportedLogPages = 1; if ((SCSI_PT_SEQUENTIAL_ACCESS == peripheral_type) || (SCSI_PT_MEDIUM_CHANGER == peripheral_type)) { /* tape device */ if (gTapeAlertsLPage) { if (con->driveinfo) pout("TapeAlert Supported\n"); if (-1 == scsiGetTapeAlertsData(fd, peripheral_type)) failuretest(OPTIONAL_CMD, returnval |= FAILSMART); } else pout("TapeAlert Not Supported\n"); } else { /* disk, cd/dvd, enclosure, etc */ if ((res = scsiGetSmartData(fd, con->smartvendorattrib))) { if (-2 == res) returnval |= FAILSTATUS; else returnval |= FAILSMART; } } } if (con->smartvendorattrib) { if (! checkedSupportedLogPages) scsiGetSupportedLogPages(fd); if (gTempLPage) { if (con->checksmart) pout("\n"); scsiPrintTemp(fd); } if (gStartStopLPage) scsiGetStartStopData(fd); if (SCSI_PT_DIRECT_ACCESS == peripheral_type) { scsiPrintGrownDefectListLen(fd); if (gSeagateCacheLPage) scsiPrintSeagateCacheLPage(fd); if (gSeagateFactoryLPage) scsiPrintSeagateFactoryLPage(fd); } } if (con->smarterrorlog) { if (! checkedSupportedLogPages) scsiGetSupportedLogPages(fd); scsiPrintErrorCounterLog(fd); if (1 == scsiFetchControlGLTSD(fd, modese_len, 1)) pout("\n[GLTSD (Global Logging Target Save Disable) set. " "Enable Save with '-S on']\n"); } if (con->smartselftestlog) { if (! checkedSupportedLogPages) scsiGetSupportedLogPages(fd); res = 0; if (gSelfTestLPage) res = scsiPrintSelfTest(fd); else { pout("Device does not support Self Test logging\n"); failuretest(OPTIONAL_CMD, returnval|=FAILSMART); } if (0 != res) failuretest(OPTIONAL_CMD, returnval|=res); } if (con->smartbackgroundlog) { if (! checkedSupportedLogPages) scsiGetSupportedLogPages(fd); res = 0; if (gBackgroundResultsLPage) res = scsiPrintBackgroundResults(fd); else { pout("Device does not support Background scan results logging\n"); failuretest(OPTIONAL_CMD, returnval|=FAILSMART); } if (0 != res) failuretest(OPTIONAL_CMD, returnval|=res); } if (con->smartexeoffimmediate) { if (scsiSmartDefaultSelfTest(fd)) return returnval | FAILSMART; pout("Default Self Test Successful\n"); } if (con->smartshortcapselftest) { if (scsiSmartShortCapSelfTest(fd)) return returnval | FAILSMART; pout("Short Foreground Self Test Successful\n"); } if (con->smartshortselftest ) { if (scsiSmartShortSelfTest(fd)) return returnval | FAILSMART; pout("Short Background Self Test has begun\n"); pout("Use smartctl -X to abort test\n"); } if (con->smartextendselftest) { if (scsiSmartExtendSelfTest(fd)) return returnval | FAILSMART; pout("Extended Background Self Test has begun\n"); if ((0 == scsiFetchExtendedSelfTestTime(fd, &durationSec, modese_len)) && (durationSec > 0)) { time_t t = time(NULL); t += durationSec; pout("Please wait %d minutes for test to complete.\n", durationSec / 60); pout("Estimated completion time: %s\n", ctime(&t)); } pout("Use smartctl -X to abort test\n"); } if (con->smartextendcapselftest) { if (scsiSmartExtendCapSelfTest(fd)) return returnval | FAILSMART; pout("Extended Foreground Self Test Successful\n"); } if (con->smartselftestabort) { if (scsiSmartSelfTestAbort(fd)) return returnval | FAILSMART; pout("Self Test returned without error\n"); } return returnval;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -