📄 ataprint.c
字号:
data.errorlog_struct[i].error_struct.state); printf ( "Number of Hours in Drive Life: %u (life of the drive in hours)\n", data.errorlog_struct[i].error_struct.timestamp ); } }} void ataPrintSmartSelfTestlog (struct ata_smart_selftestlog data){ /* excluded from first release */}void ataPsuedoCheckSmart ( struct ata_smart_values data, struct ata_smart_thresholds thresholds){ int i; int failed = 0; for ( i = 0 ; i < 30 ; i++ ) { if ( (data.vendor_attributes[i].id !=0) && (thresholds.thres_entries[i].id != 0) && ( data.vendor_attributes[i].status.flag.prefailure) && ( data.vendor_attributes[i].current < thresholds.thres_entries[i].threshold) && (thresholds.thres_entries[i].threshold != 0xFE) ) { printf("Attribute ID %i Failed\n", data.vendor_attributes[i].id); failed = 1; } } printf("%s\n", ( failed )? "Please save all data and call drive manufacture immediately.": "Check S.M.A.R.T. Passed.");}void ataPrintSmartAttribName ( unsigned char id ){ switch (id) { case 1: printf("( 1)Raw Read Error Rate "); break; case 2: printf("( 2)Throughput Performance "); break; case 3: printf("( 3)Spin Up Time "); break; case 4: printf("( 4)Start Stop Count "); break; case 5: printf("( 5)Reallocated Sector Ct "); break; case 6: printf("( 6)Read Channel Margin "); break; case 7: printf("( 7)Seek Error Rate "); break; case 8: printf("( 8)Seek Time Preformance "); break; case 9: printf("( 9)Power On Hours "); break; case 10: printf("( 10)Spin Retry Count "); break; case 11: printf("( 11)Calibration Retry Count"); break; case 12: printf("( 12)Power Cycle Count "); break; case 13: printf("( 13)Read Soft Error Rate "); break; case 191: printf("(191)Gsense Error Rate "); break; case 192: printf("(192)Power-Off Retract Count"); break; case 193: printf("(193)Load Cycle Count "); break; case 194: printf("(194)Temperature "); break; case 195: printf("(195)Hardware ECC Recovered "); break; case 196: printf("(196)Reallocated Event Count"); break; case 197: printf("(197)Current Pending Sector "); break; case 198: printf("(198)Offline Uncorrectable "); break; case 199: printf("(199)UDMA CRC Error Count "); break; default: printf("(%3d)Unknown Attribute ", id); break; }} /**** Called by smartctl to access ataprint **/void ataPrintMain ( int fd ){ struct hd_driveid drive; struct ata_smart_values smartval; struct ata_smart_thresholds smartthres; struct ata_smart_errorlog smarterror; struct ata_smart_selftestlog smartselftest; if ( driveinfo ) { if ( ataReadHDIdentity ( fd, &drive) != 0 ) { printf("Smartctl: Hard Drive Identity Failed\n"); exit(0); } ataPrintDriveInfo(drive); if (ataSmartSupport(drive)) { printf ("Drive supports S.M.A.R.T. and is "); if ( ataSmartStatus(fd) != 0) { printf( "disabled\n"); printf( "Use option -%c to enable\n", SMARTENABLE ); exit(0); } else { printf( "enabled\n"); } } else { printf("Drive does not support S.M.A.R.T.\n"); exit (0); } } if ( smartdisable ) { if ( ataDisableSmart(fd) != 0) { printf( "Smartctl: Smart Enable Failed\n"); exit(-1); } printf("S.M.A.R.T. Disabled\n"); exit (0); } if ( smartenable ) { if ( ataEnableSmart(fd) != 0) { printf( "Smartctl: Smart Enable Failed\n"); exit(-1); } /* printstatus here */ } /* for everything else read values and thresholds are needed */ if ( ataReadSmartValues ( fd, &smartval) != 0 ) { printf("Smartctl: Smart Values Read Failed\n"); exit (-1); } if ( ataReadSmartThresholds ( fd, &smartthres) != 0 ) { printf("Smartctl: Smart THresholds Read Failed\n"); exit (-1); } if ( checksmart ) { /* pseudo is used because linux does not support access to Task Fiule registers */ ataPsuedoCheckSmart ( smartval , smartthres); } if ( generalsmartvalues ) { ataPrintGeneralSmartValues( smartval ); } if ( smartvendorattrib ) { PrintSmartAttribWithThres( smartval, smartthres); } if ( smarterrorlog ) { if ( isSmartErrorLogCapable(smartval) == 0) { printf("Device does not support Error Logging\n"); } else { if ( ataReadErrorLog ( fd, &smarterror) != 0 ) { printf("Smartctl: Smart Errorlog Read Failed\n"); } else { ataPrintSmartErrorlog ( smarterror); } } } if ( smartselftestlog ) { if ( isSmartErrorLogCapable(smartval) == 0) { printf("Device does not support Self Test Logging\n"); } else { if ( ataReadSelfTestLog( fd, &smartselftest) != 0 ) { printf("Smartctl: Smart Self Test log Read Failed\n"); } else { ataPrintSmartSelfTestlog (smartselftest); } } } if ( smartautoofflineenable ) { if ( !isSupportAutomaticTimer (smartval)) { printf("Device does not support S.M.A.R.T. Automatic Timers\n"); exit(-1); } if ( ataEnableAutoOffline (fd) != 0) { printf( "Smartctl: Smart Enable Automatic Offline Failed\n"); exit(-1); } printf ("S.M.A.R.T. Automatic Offline Testing Enabled every four hours\n"); } if ( smartautoofflinedisable ) { if ( !isSupportAutomaticTimer (smartval)) { printf("Device does not support S.M.A.R.T. Automatic Timers\n"); exit(-1); } if ( ataDisableAutoOffline (fd) != 0) { printf( "Smartctl: Smart Disable Automatic Offline Failed\n"); exit(-1); } printf ("S.M.A.R.T. Automatic Offline Testing Disabled\n"); } if ( smartexeoffimmediate ) { if ( ataSmartOfflineTest (fd) != 0) { printf( "Smartctl: Smart Offline Failed\n"); exit(-1); } printf ("Drive Command Successful offline test has begun\n"); printf ("Please wait %d seconds for test to complete\n", isOfflineTestTime(smartval) ); printf ("Use smartctl -%c to abort test\n", SMARTSELFTESTABORT); exit (0); } if ( smartshortcapselftest ) { if ( ! isSupportSelfTest(smartval) ) { printf (" ERROR: device does not support Self-Test function\n"); exit(-1); } if ( ataSmartShortCapSelfTest (fd) != 0) { printf( "Smartctl: Smart Short Self Test Failed\n"); exit(-1); } printf ("Drive Command Successful offline test has begun\n"); printf ("Please wait %d minutes for test to complete\n", isShortSelfTestTime (smartval) ); printf ("Use smartctl -%c to abort test\n", SMARTSELFTESTABORT); /* Make sure Offline testing is last thing done */ exit (0); } if ( smartshortselftest ) { if ( ! isSupportSelfTest(smartval) ) { printf (" ERROR: device does not support Self-Test function\n"); exit(-1); } if ( ataSmartShortSelfTest (fd) != 0) { printf( "Smartctl: Smart Short Self Test Failed\n"); exit(-1); } printf ("Drive Command Successful offline test has begun\n"); printf ("Please wait %d minutes for test to complete\n", isShortSelfTestTime (smartval) ); printf ("Use smartctl -%c to abort test\n", SMARTSELFTESTABORT); /* Make sure Offline testing is last thing done */ exit (0); } if ( smartextendselftest ) { if ( ! isSupportSelfTest(smartval) ) { printf (" ERROR: device does not support Self-Test function\n"); exit(-1); } if ( ataSmartExtendSelfTest (fd) != 0) { printf( "S.M.A.R.T. Extendend Self Test Failed\n"); exit(-1); } printf ("Drive Command Successful self test has begun\n"); printf ("Please wait %d minutes for test to complete\n", isExtendedSelfTestTime(smartval) ); printf ("Use smartctl -%c to abort test\n", SMARTSELFTESTABORT); exit (0); } if ( smartextendcapselftest ) { if ( ! isSupportSelfTest(smartval) ) { printf (" ERROR: device does not support self test function\n"); exit(-1); } if ( ataSmartExtendCapSelfTest (fd) != 0) { printf( "S.M.A.R.T. Extendend Self Test Failed\n"); exit(-1); } printf ("Drive Command Successful captive extended self test has begun\n"); printf ("Please wait %d minutes for test to complete\n", isExtendedSelfTestTime(smartval) ); printf ("Use smartctl -%c to abort test\n", SMARTSELFTESTABORT); exit (0); } if ( smartselftestabort ) { if ( ! isSupportSelfTest(smartval) ) { printf (" ERROR: device does not support Self-Test function\n"); exit(-1); } if ( ataSmartSelfTestAbort (fd) != 0) { printf( "S.M.A.R.T. Self Test Abort Failed\n"); exit(-1); } printf ("Drive Command Successful self test aborted\n"); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -