4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2002-7 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * You should have received a copy of the GNU General Public License
15 * (for example COPYING); if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * This code was originally developed as a Senior Thesis by Michael Cornwell
19 * at the Concurrent Systems Laboratory (now part of the Storage Systems
20 * Research Center), Jack Baskin School of Engineering, University of
21 * California, Santa Cruz. http://ssrc.soe.ucsc.edu/
33 #endif // #ifdef HAVE_LOCALE_H
36 #include "atacmdnames.h"
42 #include "knowndrives.h"
44 const char *ataprint_c_cvsid
="$Id: ataprint.cpp,v 1.184 2007/12/08 13:04:05 chrfranke Exp $"
45 ATACMDNAMES_H_CVSID ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID KNOWNDRIVES_H_CVSID SMARTCTL_H_CVSID UTILITY_H_CVSID
;
47 // for passing global control variables
48 extern smartmonctrl
*con
;
50 // to hold onto exit code for atexit routine
51 extern int exitstatus
;
53 // Copies n bytes (or n-1 if n is odd) from in to out, but swaps adjacents
55 void swapbytes(char *out
, const char *in
, size_t n
)
59 for (i
= 0; i
< n
; i
+= 2) {
65 // Copies in to out, but removes leading and trailing whitespace.
66 void trim(char *out
, const char *in
)
70 // Find the first non-space character (maybe none).
72 for (i
= 0; in
[i
]; i
++)
73 if (!isspace((int)in
[i
])) {
79 // There are no non-space characters.
84 // Find the last non-space character.
85 for (i
= strlen(in
)-1; i
>= first
&& isspace((int)in
[i
]); i
--)
89 strncpy(out
, in
+first
, last
-first
+1);
90 out
[last
-first
+1] = '\0';
93 // Convenience function for formatting strings from ata_identify_device
94 void format_ata_string(char *out
, const char *in
, int n
)
96 bool must_swap
= !con
->fixswappedid
;
98 /* NetBSD kernel delivers IDENTIFY data in host byte order (but all else is LE) */
100 must_swap
= !must_swap
;
108 swapbytes(tmp
, in
, n
);
113 static const char * infofound(const char *output
) {
114 return (*output
? output
: "[No Information Found]");
118 /* For the given Command Register (CR) and Features Register (FR), attempts
119 * to construct a string that describes the contents of the Status
120 * Register (ST) and Error Register (ER). The string is dynamically allocated
121 * memory and the return value is a pointer to this string. It is up to the
122 * caller to free this memory. If there is insufficient memory or if the
123 * meanings of the flags of the error register are not known for the given
124 * command then it returns NULL.
126 * The meanings of the flags of the error register for all commands are
127 * described in the ATA spec and could all be supported here in theory.
128 * Currently, only a few commands are supported (those that have been seen
129 * to produce errors). If many more are to be added then this function
130 * should probably be redesigned.
132 char *construct_st_er_desc(struct ata_smart_errorlog_struct
*data
) {
133 unsigned char CR
=data
->commands
[4].commandreg
;
134 unsigned char FR
=data
->commands
[4].featuresreg
;
135 unsigned char ST
=data
->error_struct
.status
;
136 unsigned char ER
=data
->error_struct
.error_register
;
138 const char *error_flag
[8];
139 int i
, print_lba
=0, print_sector
=0;
141 // Set of character strings corresponding to different error codes.
142 // Please keep in alphabetic order if you add more.
143 const char *abrt
= "ABRT"; // ABORTED
144 const char *amnf
= "AMNF"; // ADDRESS MARK NOT FOUND
145 const char *ccto
= "CCTO"; // COMMAND COMPLETION TIMED OUT
146 const char *eom
= "EOM"; // END OF MEDIA
147 const char *icrc
= "ICRC"; // INTERFACE CRC ERROR
148 const char *idnf
= "IDNF"; // ID NOT FOUND
149 const char *ili
= "ILI"; // MEANING OF THIS BIT IS COMMAND-SET SPECIFIC
150 const char *mc
= "MC"; // MEDIA CHANGED
151 const char *mcr
= "MCR"; // MEDIA CHANGE REQUEST
152 const char *nm
= "NM"; // NO MEDIA
153 const char *obs
= "obs"; // OBSOLETE
154 const char *tk0nf
= "TK0NF"; // TRACK 0 NOT FOUND
155 const char *unc
= "UNC"; // UNCORRECTABLE
156 const char *wp
= "WP"; // WRITE PROTECTED
158 /* If for any command the Device Fault flag of the status register is
159 * not used then used_device_fault should be set to 0 (in the CR switch
162 int uses_device_fault
= 1;
164 /* A value of NULL means that the error flag isn't used */
165 for (i
= 0; i
< 8; i
++)
166 error_flag
[i
] = NULL
;
169 case 0x10: // RECALIBRATE
170 error_flag
[2] = abrt
;
171 error_flag
[1] = tk0nf
;
173 case 0x20: /* READ SECTOR(S) */
174 case 0x21: // READ SECTOR(S)
175 case 0x24: // READ SECTOR(S) EXT
176 case 0xC4: /* READ MULTIPLE */
177 case 0x29: // READ MULTIPLE EXT
180 error_flag
[4] = idnf
;
182 error_flag
[2] = abrt
;
184 error_flag
[0] = amnf
;
187 case 0x22: // READ LONG (with retries)
188 case 0x23: // READ LONG (without retries)
189 error_flag
[4] = idnf
;
190 error_flag
[2] = abrt
;
191 error_flag
[0] = amnf
;
194 case 0x2a: // READ STREAM DMA
195 case 0x2b: // READ STREAM PIO
197 error_flag
[7] = icrc
;
200 error_flag
[4] = idnf
;
202 error_flag
[2] = abrt
;
204 error_flag
[0] = ccto
;
206 print_sector
=(int)data
->error_struct
.sector_count
;
208 case 0x3A: // WRITE STREAM DMA
209 case 0x3B: // WRITE STREAM PIO
211 error_flag
[7] = icrc
;
214 error_flag
[4] = idnf
;
216 error_flag
[2] = abrt
;
218 error_flag
[0] = ccto
;
220 print_sector
=(int)data
->error_struct
.sector_count
;
222 case 0x25: /* READ DMA EXT */
223 case 0x26: // READ DMA QUEUED EXT
224 case 0xC7: // READ DMA QUEUED
225 case 0xC8: /* READ DMA */
227 error_flag
[7] = icrc
;
230 error_flag
[4] = idnf
;
232 error_flag
[2] = abrt
;
234 error_flag
[0] = amnf
;
236 if (CR
==0x25 || CR
==0xC8)
237 print_sector
=(int)data
->error_struct
.sector_count
;
239 case 0x30: /* WRITE SECTOR(S) */
240 case 0x31: // WRITE SECTOR(S)
241 case 0x34: // WRITE SECTOR(S) EXT
242 case 0xC5: /* WRITE MULTIPLE */
243 case 0x39: // WRITE MULTIPLE EXT
244 case 0xCE: // WRITE MULTIPLE FUA EXT
247 error_flag
[4] = idnf
;
249 error_flag
[2] = abrt
;
253 case 0x32: // WRITE LONG (with retries)
254 case 0x33: // WRITE LONG (without retries)
255 error_flag
[4] = idnf
;
256 error_flag
[2] = abrt
;
259 case 0x3C: // WRITE VERIFY
261 error_flag
[4] = idnf
;
262 error_flag
[2] = abrt
;
263 error_flag
[0] = amnf
;
266 case 0x40: // READ VERIFY SECTOR(S) with retries
267 case 0x41: // READ VERIFY SECTOR(S) without retries
268 case 0x42: // READ VERIFY SECTOR(S) EXT
271 error_flag
[4] = idnf
;
273 error_flag
[2] = abrt
;
275 error_flag
[0] = amnf
;
278 case 0xA0: /* PACKET */
279 /* Bits 4-7 are all used for sense key (a 'command packet set specific error
280 * indication' according to the ATA/ATAPI-7 standard), so "Sense key" will
281 * be repeated in the error description string if more than one of those
284 error_flag
[7] = "Sense key (bit 3)",
285 error_flag
[6] = "Sense key (bit 2)",
286 error_flag
[5] = "Sense key (bit 1)",
287 error_flag
[4] = "Sense key (bit 0)",
288 error_flag
[2] = abrt
;
292 case 0xA1: /* IDENTIFY PACKET DEVICE */
293 case 0xEF: /* SET FEATURES */
295 case 0xC6: /* SET MULTIPLE MODE */
296 error_flag
[2] = abrt
;
298 case 0x2F: // READ LOG EXT
300 error_flag
[4] = idnf
;
301 error_flag
[2] = abrt
;
304 case 0x3F: // WRITE LOG EXT
305 error_flag
[4] = idnf
;
306 error_flag
[2] = abrt
;
309 case 0xB0: /* SMART */
311 case 0xD0: // SMART READ DATA
312 case 0xD1: // SMART READ ATTRIBUTE THRESHOLDS
313 case 0xD5: /* SMART READ LOG */
315 error_flag
[4] = idnf
;
316 error_flag
[2] = abrt
;
319 case 0xD6: /* SMART WRITE LOG */
320 error_flag
[4] = idnf
;
321 error_flag
[2] = abrt
;
324 case 0xD2: // Enable/Disable Attribute Autosave
325 case 0xD3: // SMART SAVE ATTRIBUTE VALUES (ATA-3)
326 case 0xD8: // SMART ENABLE OPERATIONS
327 case 0xD9: /* SMART DISABLE OPERATIONS */
328 case 0xDA: /* SMART RETURN STATUS */
329 case 0xDB: // Enable/Disable Auto Offline (SFF)
330 error_flag
[2] = abrt
;
332 case 0xD4: // SMART EXECUTE IMMEDIATE OFFLINE
333 error_flag
[4] = idnf
;
334 error_flag
[2] = abrt
;
341 case 0xB1: /* DEVICE CONFIGURATION */
343 case 0xC0: /* DEVICE CONFIGURATION RESTORE */
344 error_flag
[2] = abrt
;
351 case 0xCA: /* WRITE DMA */
353 case 0x35: // WRITE DMA EXT
354 case 0x3D: // WRITE DMA FUA EXT
355 case 0xCC: // WRITE DMA QUEUED
356 case 0x36: // WRITE DMA QUEUED EXT
357 case 0x3E: // WRITE DMA QUEUED FUA EXT
358 error_flag
[7] = icrc
;
361 error_flag
[4] = idnf
;
363 error_flag
[2] = abrt
;
365 error_flag
[0] = amnf
;
368 print_sector
=(int)data
->error_struct
.sector_count
;
370 case 0xE4: // READ BUFFER
371 case 0xE8: // WRITE BUFFER
372 error_flag
[2] = abrt
;
378 /* 256 bytes -- that'll be plenty (OK, this is lazy!) */
379 if (!(s
= (char *)malloc(256)))
384 /* We ignore any status flags other than Device Fault and Error */
386 if (uses_device_fault
&& (ST
& (1 << 5))) {
387 strcat(s
, "Device Fault");
388 if (ST
& 1) // Error flag
391 if (ST
& 1) { // Error flag
394 strcat(s
, "Error: ");
395 for (i
= 7; i
>= 0; i
--)
396 if ((ER
& (1 << i
)) && (error_flag
[i
])) {
399 strcat(s
, error_flag
[i
]);
403 // If the error was a READ or WRITE error, print the Logical Block
404 // Address (LBA) at which the read or write failed.
409 // bits 24-27: bits 0-3 of DH
410 lba
= 0xf & data
->error_struct
.drive_head
;
413 lba
|= data
->error_struct
.cylinder_high
;
416 lba
|= data
->error_struct
.cylinder_low
;
419 lba
|= data
->error_struct
.sector_number
;
421 // print number of sectors, if known, and append to print string
423 snprintf(tmp
, 128, " %d sectors", print_sector
);
427 // print LBA, and append to print string
428 snprintf(tmp
, 128, " at LBA = 0x%08x = %d", lba
, lba
);
436 // Get number of sectors from IDENTIFY sector. If the drive doesn't
437 // support LBA addressing or has no user writable sectors
438 // (eg, CDROM or DVD) then routine returns zero.
439 static uint64_t get_num_sectors(const ata_identify_device
*drive
)
441 unsigned short command_set_2
= drive
->command_set_2
;
442 unsigned short capabilities_0
= drive
->words047_079
[49-47];
443 unsigned short sects_16
= drive
->words047_079
[60-47];
444 unsigned short sects_32
= drive
->words047_079
[61-47];
445 unsigned short lba_16
= drive
->words088_255
[100-88];
446 unsigned short lba_32
= drive
->words088_255
[101-88];
447 unsigned short lba_48
= drive
->words088_255
[102-88];
448 unsigned short lba_64
= drive
->words088_255
[103-88];
451 if (!(capabilities_0
& 0x0200))
454 // if drive supports LBA addressing, determine 32-bit LBA capacity
455 uint64_t lba32
= (unsigned int)sects_32
<< 16 |
456 (unsigned int)sects_16
<< 0 ;
459 // if drive supports 48-bit addressing, determine THAT capacity
460 if ((command_set_2
& 0xc000) == 0x4000 && (command_set_2
& 0x0400))
461 lba64
= (uint64_t)lba_64
<< 48 |
462 (uint64_t)lba_48
<< 32 |
463 (uint64_t)lba_32
<< 16 |
464 (uint64_t)lba_16
<< 0 ;
466 // return the larger of the two possible capacities
467 return (lba32
> lba64
? lba32
: lba64
);
471 // This returns the capacity of a disk drive and also prints this into
472 // a string, using comma separators to make it easier to read. If the
473 // drive doesn't support LBA addressing or has no user writable
474 // sectors (eg, CDROM or DVD) then routine returns zero.
475 uint64_t determine_capacity(struct ata_identify_device
*drive
, char *pstring
){
477 // get correct character to use as thousands separator
480 struct lconv
*currentlocale
=NULL
;
481 setlocale (LC_ALL
, "");
482 currentlocale
=localeconv();
483 if (*(currentlocale
->thousands_sep
))
484 separator
=(char *)currentlocale
->thousands_sep
;
485 #endif // #ifdef HAVE_LOCALE_H
487 // get #sectors and turn into bytes
488 uint64_t capacity
= get_num_sectors(drive
) * 512;
489 uint64_t retval
= capacity
;
491 // print with locale-specific separators (default is comma)
492 int started
=0, k
=1000000000;
493 uint64_t power_of_ten
= k
;
496 for (k
=0; k
<7; k
++) {
497 uint64_t threedigits
= capacity
/power_of_ten
;
498 capacity
-= threedigits
*power_of_ten
;
500 // we have already printed some digits
501 pstring
+= sprintf(pstring
, "%s%03"PRIu64
, separator
, threedigits
);
502 else if (threedigits
|| k
==6) {
503 // these are the first digits that we are printing
504 pstring
+= sprintf(pstring
, "%"PRIu64
, threedigits
);
508 power_of_ten
/= 1000;
514 int ataPrintDriveInfo (struct ata_identify_device
*drive
){
515 int version
, drivetype
;
516 const char *description
;
517 char unknown
[64], timedatetz
[DATEANDEPOCHLEN
];
518 unsigned short minorrev
;
519 char model
[64], serial
[64], firm
[64], capacity
[64];
521 // format drive information (with byte swapping as needed)
522 format_ata_string(model
, (char *)drive
->model
,40);
523 format_ata_string(serial
, (char *)drive
->serial_no
,20);
524 format_ata_string(firm
, (char *)drive
->fw_rev
,8);
526 // print out model, serial # and firmware versions (byte-swap ASCI strings)
527 drivetype
=lookupdrive(model
, firm
);
529 // Print model family if known
530 if (drivetype
>=0 && knowndrives
[drivetype
].modelfamily
)
531 pout("Model Family: %s\n", knowndrives
[drivetype
].modelfamily
);
533 pout("Device Model: %s\n", infofound(model
));
534 if (!con
->dont_print_serial
)
535 pout("Serial Number: %s\n", infofound(serial
));
536 pout("Firmware Version: %s\n", infofound(firm
));
538 if (determine_capacity(drive
, capacity
))
539 pout("User Capacity: %s bytes\n", capacity
);
541 // See if drive is recognized
542 pout("Device is: %s\n", drivetype
<0?
543 "Not in smartctl database [for details use: -P showall]":
544 "In smartctl database [for details use: -P show]");
546 // now get ATA version info
547 version
=ataVersionInfo(&description
,drive
, &minorrev
);
549 // unrecognized minor revision code
552 sprintf(unknown
, "Exact ATA specification draft version not indicated");
554 sprintf(unknown
,"Not recognized. Minor revision code: 0x%02hx", minorrev
);
559 // SMART Support was first added into the ATA/ATAPI-3 Standard with
560 // Revision 3 of the document, July 25, 1995. Look at the "Document
561 // Status" revision commands at the beginning of
562 // http://www.t13.org/project/d2008r6.pdf to see this. So it's not
563 // enough to check if we are ATA-3. Version=-3 indicates ATA-3
564 // BEFORE Revision 3.
565 pout("ATA Version is: %d\n",(int)abs(version
));
566 pout("ATA Standard is: %s\n",description
);
568 // print current time and date and timezone
569 dateandtimezone(timedatetz
);
570 pout("Local Time is: %s\n", timedatetz
);
572 // Print warning message, if there is one
573 if (drivetype
>=0 && knowndrives
[drivetype
].warningmsg
)
574 pout("\n==> WARNING: %s\n\n", knowndrives
[drivetype
].warningmsg
);
579 pout("SMART is only available in ATA Version 3 Revision 3 or greater.\n");
580 pout("We will try to proceed in spite of this.\n");
585 const char *OfflineDataCollectionStatus(unsigned char status_byte
){
586 unsigned char stat
=status_byte
& 0x7f;
590 return "was never started";
592 return "was completed without error";
594 if (status_byte
== 0x03)
595 return "is in progress";
597 return "is in a Reserved state";
599 return "was suspended by an interrupting command from host";
601 return "was aborted by an interrupting command from host";
603 return "was aborted by the device with a fatal error";
606 return "is in a Vendor Specific state\n";
608 return "is in a Reserved state\n";
613 /* prints verbose value Off-line data collection status byte */
614 void PrintSmartOfflineStatus(struct ata_smart_values
*data
){
616 pout("Offline data collection status: (0x%02x)\t",
617 (int)data
->offline_data_collection_status
);
619 // Off-line data collection status byte is not a reserved
620 // or vendor specific value
621 pout("Offline data collection activity\n"
622 "\t\t\t\t\t%s.\n", OfflineDataCollectionStatus(data
->offline_data_collection_status
));
624 // Report on Automatic Data Collection Status. Only IBM documents
625 // this bit. See SFF 8035i Revision 2 for details.
626 if (data
->offline_data_collection_status
& 0x80)
627 pout("\t\t\t\t\tAuto Offline Data Collection: Enabled.\n");
629 pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
634 void PrintSmartSelfExecStatus(struct ata_smart_values
*data
)
636 pout("Self-test execution status: ");
638 switch (data
->self_test_exec_status
>> 4)
641 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
642 (int)data
->self_test_exec_status
);
643 pout("without error or no self-test has ever \n\t\t\t\t\tbeen run.\n");
646 pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
647 (int)data
->self_test_exec_status
);
651 pout("(%4d)\tThe self-test routine was interrupted\n\t\t\t\t\t",
652 (int)data
->self_test_exec_status
);
653 pout("by the host with a hard or soft reset.\n");
656 pout("(%4d)\tA fatal error or unknown test error\n\t\t\t\t\t",
657 (int)data
->self_test_exec_status
);
658 pout("occurred while the device was executing\n\t\t\t\t\t");
659 pout("its self-test routine and the device \n\t\t\t\t\t");
660 pout("was unable to complete the self-test \n\t\t\t\t\t");
664 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
665 (int)data
->self_test_exec_status
);
666 pout("a test element that failed and the test\n\t\t\t\t\t");
667 pout("element that failed is not known.\n");
670 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
671 (int)data
->self_test_exec_status
);
672 pout("the electrical element of the test\n\t\t\t\t\t");
676 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
677 (int)data
->self_test_exec_status
);
678 pout("the servo (and/or seek) element of the \n\t\t\t\t\t");
679 pout("test failed.\n");
682 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
683 (int)data
->self_test_exec_status
);
684 pout("the read element of the test failed.\n");
687 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
688 (int)data
->self_test_exec_status
);
689 pout("a test element that failed and the\n\t\t\t\t\t");
690 pout("device is suspected of having handling\n\t\t\t\t\t");
694 if (con
->fixfirmwarebug
== FIX_SAMSUNG3
&& data
->self_test_exec_status
== 0xf0) {
695 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
696 (int)data
->self_test_exec_status
);
697 pout("with unknown result or self-test in\n\t\t\t\t\t");
698 pout("progress with less than 10%% remaining.\n");
701 pout("(%4d)\tSelf-test routine in progress...\n\t\t\t\t\t",
702 (int)data
->self_test_exec_status
);
703 pout("%1d0%% of test remaining.\n",
704 (int)(data
->self_test_exec_status
& 0x0f));
708 pout("(%4d)\tReserved.\n",
709 (int)data
->self_test_exec_status
);
717 void PrintSmartTotalTimeCompleteOffline ( struct ata_smart_values
*data
){
718 pout("Total time to complete Offline \n");
719 pout("data collection: \t\t (%4d) seconds.\n",
720 (int)data
->total_time_to_complete_off_line
);
725 void PrintSmartOfflineCollectCap(struct ata_smart_values
*data
){
726 pout("Offline data collection\n");
727 pout("capabilities: \t\t\t (0x%02x) ",
728 (int)data
->offline_data_collection_capability
);
730 if (data
->offline_data_collection_capability
== 0x00){
731 pout("\tOffline data collection not supported.\n");
734 pout( "%s\n", isSupportExecuteOfflineImmediate(data
)?
735 "SMART execute Offline immediate." :
736 "No SMART execute Offline immediate.");
738 pout( "\t\t\t\t\t%s\n", isSupportAutomaticTimer(data
)?
739 "Auto Offline data collection on/off support.":
740 "No Auto Offline data collection support.");
742 pout( "\t\t\t\t\t%s\n", isSupportOfflineAbort(data
)?
743 "Abort Offline collection upon new\n\t\t\t\t\tcommand.":
744 "Suspend Offline collection upon new\n\t\t\t\t\tcommand.");
746 pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data
)?
747 "Offline surface scan supported.":
748 "No Offline surface scan supported.");
750 pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data
)?
751 "Self-test supported.":
752 "No Self-test supported.");
754 pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data
)?
755 "Conveyance Self-test supported.":
756 "No Conveyance Self-test supported.");
758 pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data
)?
759 "Selective Self-test supported.":
760 "No Selective Self-test supported.");
766 void PrintSmartCapability ( struct ata_smart_values
*data
)
768 pout("SMART capabilities: ");
769 pout("(0x%04x)\t", (int)data
->smart_capability
);
771 if (data
->smart_capability
== 0x00)
773 pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
778 pout( "%s\n", (data
->smart_capability
& 0x01)?
779 "Saves SMART data before entering\n\t\t\t\t\tpower-saving mode.":
780 "Does not save SMART data before\n\t\t\t\t\tentering power-saving mode.");
782 if ( data
->smart_capability
& 0x02 )
784 pout("\t\t\t\t\tSupports SMART auto save timer.\n");
789 void PrintSmartErrorLogCapability (struct ata_smart_values
*data
, struct ata_identify_device
*identity
)
792 pout("Error logging capability: ");
794 if ( isSmartErrorLogCapable(data
, identity
) )
796 pout(" (0x%02x)\tError logging supported.\n",
797 (int)data
->errorlog_capability
);
800 pout(" (0x%02x)\tError logging NOT supported.\n",
801 (int)data
->errorlog_capability
);
805 void PrintSmartShortSelfTestPollingTime(struct ata_smart_values
*data
){
806 pout("Short self-test routine \n");
807 if (isSupportSelfTest(data
))
808 pout("recommended polling time: \t (%4d) minutes.\n",
809 (int)data
->short_test_completion_time
);
811 pout("recommended polling time: \t Not Supported.\n");
814 void PrintSmartExtendedSelfTestPollingTime(struct ata_smart_values
*data
){
815 pout("Extended self-test routine\n");
816 if (isSupportSelfTest(data
))
817 pout("recommended polling time: \t (%4d) minutes.\n",
818 (int)data
->extend_test_completion_time
);
820 pout("recommended polling time: \t Not Supported.\n");
823 void PrintSmartConveyanceSelfTestPollingTime(struct ata_smart_values
*data
){
824 pout("Conveyance self-test routine\n");
825 if (isSupportConveyanceSelfTest(data
))
826 pout("recommended polling time: \t (%4d) minutes.\n",
827 (int)data
->conveyance_test_completion_time
);
829 pout("recommended polling time: \t Not Supported.\n");
832 // onlyfailed=0 : print all attribute values
833 // onlyfailed=1: just ones that are currently failed and have prefailure bit set
834 // onlyfailed=2: ones that are failed, or have failed with or without prefailure bit set
835 void PrintSmartAttribWithThres (struct ata_smart_values
*data
,
836 struct ata_smart_thresholds_pvt
*thresholds
,
842 // step through all vendor attributes
843 for (i
=0; i
<NUMBER_ATA_SMART_ATTRIBUTES
; i
++){
845 struct ata_smart_attribute
*disk
=data
->vendor_attributes
+i
;
846 struct ata_smart_threshold_entry
*thre
=thresholds
->thres_entries
+i
;
848 // consider only valid attributes (allowing some screw-ups in the
849 // thresholds page data to slip by)
851 const char *type
, *update
;
852 int failednow
,failedever
;
853 char attributename
[64];
855 failednow
= (disk
->current
<= thre
->threshold
);
856 failedever
= (disk
->worst
<= thre
->threshold
);
858 // These break out of the loop if we are only printing certain entries...
859 if (onlyfailed
==1 && (!ATTRIBUTE_FLAGS_PREFAILURE(disk
->flags
) || !failednow
))
862 if (onlyfailed
==2 && !failedever
)
865 // print header only if needed
868 pout("SMART Attributes Data Structure revision number: %d\n",(int)data
->revnumber
);
869 pout("Vendor Specific SMART Attributes with Thresholds:\n");
871 pout("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n");
875 // is this Attribute currently failed, or has it ever failed?
877 status
="FAILING_NOW";
879 status
="In_the_past";
883 // Print name of attribute
884 ataPrintSmartAttribName(attributename
,disk
->id
, con
->attributedefs
);
885 pout("%-28s",attributename
);
887 // printing line for each valid attribute
888 type
=ATTRIBUTE_FLAGS_PREFAILURE(disk
->flags
)?"Pre-fail":"Old_age";
889 update
=ATTRIBUTE_FLAGS_ONLINE(disk
->flags
)?"Always":"Offline";
891 pout("0x%04x %.3d %.3d %.3d %-10s%-9s%-12s",
892 (int)disk
->flags
, (int)disk
->current
, (int)disk
->worst
,
893 (int)thre
->threshold
, type
, update
, status
);
895 // print raw value of attribute
896 ataPrintSmartAttribRawValue(rawstring
, disk
, con
->attributedefs
);
897 pout("%s\n", rawstring
);
899 // print a warning if there is inconsistency here!
900 if (disk
->id
!= thre
->id
){
901 char atdat
[64],atthr
[64];
902 ataPrintSmartAttribName(atdat
, disk
->id
, con
->attributedefs
);
903 ataPrintSmartAttribName(atthr
, thre
->id
, con
->attributedefs
);
904 pout("%-28s<== Data Page | WARNING: PREVIOUS ATTRIBUTE HAS TWO\n",atdat
);
905 pout("%-28s<== Threshold Page | INCONSISTENT IDENTITIES IN THE DATA\n",atthr
);
909 if (!needheader
) pout("\n");
912 // Print SMART related SCT capabilities
913 static void ataPrintSCTCapability(const ata_identify_device
*drive
)
915 unsigned short sctcaps
= drive
->words088_255
[206-88];
916 if (!(sctcaps
& 0x01))
918 pout("SCT capabilities: \t (0x%04x)\tSCT Status supported.\n", sctcaps
);
920 pout("\t\t\t\t\tSCT Feature Control supported.\n");
922 pout("\t\t\t\t\tSCT Data Table supported.\n");
926 void ataPrintGeneralSmartValues(struct ata_smart_values
*data
, struct ata_identify_device
*drive
){
927 pout("General SMART Values:\n");
929 PrintSmartOfflineStatus(data
);
931 if (isSupportSelfTest(data
)){
932 PrintSmartSelfExecStatus (data
);
935 PrintSmartTotalTimeCompleteOffline(data
);
936 PrintSmartOfflineCollectCap(data
);
937 PrintSmartCapability(data
);
939 PrintSmartErrorLogCapability(data
, drive
);
941 pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive
)?
942 "General Purpose Logging supported.":
943 "No General Purpose Logging support.");
945 if (isSupportSelfTest(data
)){
946 PrintSmartShortSelfTestPollingTime (data
);
947 PrintSmartExtendedSelfTestPollingTime (data
);
949 if (isSupportConveyanceSelfTest(data
))
950 PrintSmartConveyanceSelfTestPollingTime (data
);
952 ataPrintSCTCapability(drive
);
957 int ataPrintLogDirectory(struct ata_smart_log_directory
*data
){
961 pout("SMART Log Directory Logging Version %d%s\n",
962 data
->logversion
, data
->logversion
==1?" [multi-sector log support]":"");
963 for (i
=0; i
<=255; i
++){
966 // Directory log length
967 numsect
= i
? data
->entry
[i
-1].numsectors
: 1;
969 // If the log is not empty, what is it's name
973 name
="Log Directory"; break;
975 name
="Summary SMART error log"; break;
977 name
="Comprehensive SMART error log"; break;
979 name
="Extended Comprehensive SMART error log"; break;
981 name
="SMART self-test log"; break;
983 name
="Extended self-test log"; break;
985 name
="Selective self-test log"; break;
987 name
="Streaming performance log"; break;
989 name
="Write stream error log"; break;
991 name
="Read stream error log"; break;
993 name
="Delayed sector log"; break;
995 if (0xa0<=i
&& i
<=0xbf)
996 name
="Device vendor specific log";
997 else if (0x80<=i
&& i
<=0x9f)
998 name
="Host vendor specific log";
1000 name
="Reserved log";
1004 // print name and length of log
1005 pout("Log at address 0x%02x has %03d sectors [%s]\n",
1012 // returns number of errors
1013 int ataPrintSmartErrorlog(struct ata_smart_errorlog
*data
){
1016 pout("SMART Error Log Version: %d\n", (int)data
->revnumber
);
1018 // if no errors logged, return
1019 if (!data
->error_log_pointer
){
1020 pout("No Errors Logged\n\n");
1024 // If log pointer out of range, return
1025 if (data
->error_log_pointer
>5){
1026 pout("Invalid Error Log index = 0x%02x (T13/1321D rev 1c "
1027 "Section 8.41.6.8.2.2 gives valid range from 1 to 5)\n\n",
1028 (int)data
->error_log_pointer
);
1032 // Some internal consistency checking of the data structures
1033 if ((data
->ata_error_count
-data
->error_log_pointer
)%5 && con
->fixfirmwarebug
!= FIX_SAMSUNG2
) {
1034 pout("Warning: ATA error count %d inconsistent with error log pointer %d\n\n",
1035 data
->ata_error_count
,data
->error_log_pointer
);
1038 // starting printing error log info
1039 if (data
->ata_error_count
<=5)
1040 pout( "ATA Error Count: %d\n", (int)data
->ata_error_count
);
1042 pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1043 (int)data
->ata_error_count
);
1045 pout("\tCR = Command Register [HEX]\n"
1046 "\tFR = Features Register [HEX]\n"
1047 "\tSC = Sector Count Register [HEX]\n"
1048 "\tSN = Sector Number Register [HEX]\n"
1049 "\tCL = Cylinder Low Register [HEX]\n"
1050 "\tCH = Cylinder High Register [HEX]\n"
1051 "\tDH = Device/Head Register [HEX]\n"
1052 "\tDC = Device Command Register [HEX]\n"
1053 "\tER = Error register [HEX]\n"
1054 "\tST = Status register [HEX]\n"
1055 "Powered_Up_Time is measured from power on, and printed as\n"
1056 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1057 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1059 // now step through the five error log data structures (table 39 of spec)
1060 for (k
= 4; k
>= 0; k
-- ) {
1063 // The error log data structure entries are a circular buffer
1064 int j
, i
=(data
->error_log_pointer
+k
)%5;
1065 struct ata_smart_errorlog_struct
*elog
=data
->errorlog_struct
+i
;
1066 struct ata_smart_errorlog_error_struct
*summary
=&(elog
->error_struct
);
1068 // Spec says: unused error log structures shall be zero filled
1069 if (nonempty((unsigned char*)elog
,sizeof(*elog
))){
1070 // Table 57 of T13/1532D Volume 1 Revision 3
1072 int bits
=summary
->state
& 0x0f;
1073 int days
= (int)summary
->timestamp
/24;
1076 case 0x00: msgstate
="in an unknown state";break;
1077 case 0x01: msgstate
="sleeping"; break;
1078 case 0x02: msgstate
="in standby mode"; break;
1079 case 0x03: msgstate
="active or idle"; break;
1080 case 0x04: msgstate
="doing SMART Offline or Self-test"; break;
1083 msgstate
="in a reserved state";
1085 msgstate
="in a vendor specific state";
1088 // See table 42 of ATA5 spec
1090 pout("Error %d occurred at disk power-on lifetime: %d hours (%d days + %d hours)\n",
1091 (int)(data
->ata_error_count
+k
-4), (int)summary
->timestamp
, days
, (int)(summary
->timestamp
-24*days
));
1093 pout(" When the command that caused the error occurred, the device was %s.\n\n",msgstate
);
1094 pout(" After command completion occurred, registers were:\n"
1095 " ER ST SC SN CL CH DH\n"
1096 " -- -- -- -- -- -- --\n"
1097 " %02x %02x %02x %02x %02x %02x %02x",
1098 (int)summary
->error_register
,
1099 (int)summary
->status
,
1100 (int)summary
->sector_count
,
1101 (int)summary
->sector_number
,
1102 (int)summary
->cylinder_low
,
1103 (int)summary
->cylinder_high
,
1104 (int)summary
->drive_head
);
1105 // Add a description of the contents of the status and error registers
1107 st_er_desc
= construct_st_er_desc(elog
);
1109 pout(" %s", st_er_desc
);
1113 pout(" Commands leading to the command that caused the error were:\n"
1114 " CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name\n"
1115 " -- -- -- -- -- -- -- -- ---------------- --------------------\n");
1116 for ( j
= 4; j
>= 0; j
--){
1117 struct ata_smart_errorlog_command_struct
*thiscommand
=elog
->commands
+j
;
1119 // Spec says: unused data command structures shall be zero filled
1120 if (nonempty((unsigned char*)thiscommand
,sizeof(*thiscommand
))) {
1121 char timestring
[32];
1123 // Convert integer milliseconds to a text-format string
1124 MsecToText(thiscommand
->timestamp
, timestring
);
1126 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1127 (int)thiscommand
->commandreg
,
1128 (int)thiscommand
->featuresreg
,
1129 (int)thiscommand
->sector_count
,
1130 (int)thiscommand
->sector_number
,
1131 (int)thiscommand
->cylinder_low
,
1132 (int)thiscommand
->cylinder_high
,
1133 (int)thiscommand
->drive_head
,
1134 (int)thiscommand
->devicecontrolreg
,
1136 look_up_ata_command(thiscommand
->commandreg
, thiscommand
->featuresreg
));
1143 if (con
->printing_switchable
)
1146 return data
->ata_error_count
;
1149 void ataPrintSelectiveSelfTestLog(struct ata_selective_self_test_log
*log
, struct ata_smart_values
*sv
) {
1150 int i
,field1
,field2
;
1153 uint64_t maxl
=0,maxr
=0;
1154 uint64_t current
=log
->currentlba
;
1155 uint64_t currentend
=current
+65535;
1157 // print data structure revision number
1158 pout("SMART Selective self-test log data structure revision number %d\n",(int)log
->logversion
);
1159 if (1 != log
->logversion
)
1160 pout("Warning: ATA Specification requires selective self-test log data structure revision number = 1\n");
1162 switch((sv
->self_test_exec_status
)>>4){
1163 case 0:msg
="Completed";
1165 case 1:msg
="Aborted_by_host";
1167 case 2:msg
="Interrupted";
1169 case 3:msg
="Fatal_error";
1171 case 4:msg
="Completed_unknown_failure";
1173 case 5:msg
="Completed_electrical_failure";
1175 case 6:msg
="Completed_servo/seek_failure";
1177 case 7:msg
="Completed_read_failure";
1179 case 8:msg
="Completed_handling_damage??";
1181 case 15:msg
="Self_test_in_progress";
1183 default:msg
="Unknown_status ";
1187 // find the number of columns needed for printing. If in use, the
1188 // start/end of span being read-scanned...
1189 if (log
->currentspan
>5) {
1193 for (i
=0; i
<5; i
++) {
1194 uint64_t start
=log
->span
[i
].start
;
1195 uint64_t end
=log
->span
[i
].end
;
1196 // ... plus max start/end of each of the five test spans.
1203 // we need at least 7 characters wide fields to accomodate the
1205 if ((field1
=snprintf(tmp
,64, "%"PRIu64
, maxl
))<7)
1207 if ((field2
=snprintf(tmp
,64, "%"PRIu64
, maxr
))<7)
1210 // now print the five test spans
1211 pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1
, "MIN_LBA", field2
, "MAX_LBA");
1213 for (i
=0; i
<5; i
++) {
1214 uint64_t start
=log
->span
[i
].start
;
1215 uint64_t end
=log
->span
[i
].end
;
1217 if ((i
+1)==(int)log
->currentspan
)
1218 // this span is currently under test
1219 pout(" %d %*"PRIu64
" %*"PRIu64
" %s [%01d0%% left] (%"PRIu64
"-%"PRIu64
")\n",
1220 i
+1, field1
, start
, field2
, end
, msg
,
1221 (int)(sv
->self_test_exec_status
& 0xf), current
, currentend
);
1223 // this span is not currently under test
1224 pout(" %d %*"PRIu64
" %*"PRIu64
" Not_testing\n",
1225 i
+1, field1
, start
, field2
, end
);
1228 // if we are currently read-scanning, print LBAs and the status of
1230 if (log
->currentspan
>5)
1231 pout("%5d %*"PRIu64
" %*"PRIu64
" Read_scanning %s\n",
1232 (int)log
->currentspan
, field1
, current
, field2
, currentend
,
1233 OfflineDataCollectionStatus(sv
->offline_data_collection_status
));
1235 /* Print selective self-test flags. Possible flag combinations are
1236 (numbering bits from 0-15):
1240 1 0 0 Will carry out scan after selective test
1241 1 1 0 Waiting to carry out scan after powerup
1242 1 0 1 Currently scanning
1243 1 1 1 Currently scanning
1246 pout("Selective self-test flags (0x%x):\n", (unsigned int)log
->flags
);
1247 if (log
->flags
& SELECTIVE_FLAG_DOSCAN
) {
1248 if (log
->flags
& SELECTIVE_FLAG_ACTIVE
)
1249 pout(" Currently read-scanning the remainder of the disk.\n");
1250 else if (log
->flags
& SELECTIVE_FLAG_PENDING
)
1251 pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
1252 (int)log
->pendingtime
);
1254 pout(" After scanning selected spans, read-scan remainder of disk.\n");
1257 pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
1259 // print pending time
1260 pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
1261 (int)log
->pendingtime
);
1267 // bottom 8 bits: number of entries found where self-test showed an error
1268 // remaining bits: if nonzero, power on hours of last self-test where error was found
1269 int ataPrintSmartSelfTestlog(struct ata_smart_selftestlog
*data
,int allentries
){
1270 int i
,j
,noheaderprinted
=1;
1271 int retval
=0, hours
=0, testno
=0;
1274 pout("SMART Self-test log structure revision number %d\n",(int)data
->revnumber
);
1275 if ((data
->revnumber
!=0x0001) && allentries
&& con
->fixfirmwarebug
!= FIX_SAMSUNG
)
1276 pout("Warning: ATA Specification requires self-test log structure revision number = 1\n");
1277 if (data
->mostrecenttest
==0){
1279 pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
1284 for (i
=20;i
>=0;i
--){
1285 struct ata_smart_selftestlog_struct
*log
;
1287 // log is a circular buffer
1288 j
=(i
+data
->mostrecenttest
)%21;
1289 log
=data
->selftest_struct
+j
;
1291 if (nonempty((unsigned char*)log
,sizeof(*log
))){
1292 char *msgtest
,*msgstat
,percent
[64],firstlba
[64];
1295 // count entry based on non-empty structures -- needed for
1296 // Seagate only -- other vendors don't have blank entries 'in
1301 switch(log
->selftestnumber
){
1302 case 0: msgtest
="Offline "; break;
1303 case 1: msgtest
="Short offline "; break;
1304 case 2: msgtest
="Extended offline "; break;
1305 case 3: msgtest
="Conveyance offline "; break;
1306 case 4: msgtest
="Selective offline "; break;
1307 case 127: msgtest
="Abort offline test "; break;
1308 case 129: msgtest
="Short captive "; break;
1309 case 130: msgtest
="Extended captive "; break;
1310 case 131: msgtest
="Conveyance captive "; break;
1311 case 132: msgtest
="Selective captive "; break;
1313 if ( log
->selftestnumber
>=192 ||
1314 (log
->selftestnumber
>= 64 && log
->selftestnumber
<=126))
1315 msgtest
="Vendor offline ";
1317 msgtest
="Reserved offline ";
1321 switch((log
->selfteststatus
)>>4){
1322 case 0:msgstat
="Completed without error "; break;
1323 case 1:msgstat
="Aborted by host "; break;
1324 case 2:msgstat
="Interrupted (host reset) "; break;
1325 case 3:msgstat
="Fatal or unknown error "; errorfound
=1; break;
1326 case 4:msgstat
="Completed: unknown failure "; errorfound
=1; break;
1327 case 5:msgstat
="Completed: electrical failure"; errorfound
=1; break;
1328 case 6:msgstat
="Completed: servo/seek failure"; errorfound
=1; break;
1329 case 7:msgstat
="Completed: read failure "; errorfound
=1; break;
1330 case 8:msgstat
="Completed: handling damage?? "; errorfound
=1; break;
1331 case 15:msgstat
="Self-test routine in progress"; break;
1332 default:msgstat
="Unknown/reserved test status ";
1336 sprintf(percent
,"%1d0%%",(log
->selfteststatus
)&0xf);
1338 // T13/1321D revision 1c: (Data structure Rev #1)
1340 //The failing LBA shall be the LBA of the uncorrectable sector
1341 //that caused the test to fail. If the device encountered more
1342 //than one uncorrectable sector during the test, this field
1343 //shall indicate the LBA of the first uncorrectable sector
1344 //encountered. If the test passed or the test failed for some
1345 //reason other than an uncorrectable sector, the value of this
1346 //field is undefined.
1348 // This is true in ALL ATA-5 specs
1350 if (!errorfound
|| log
->lbafirstfailure
==0xffffffff || log
->lbafirstfailure
==0x00000000)
1351 sprintf(firstlba
,"%s","-");
1353 sprintf(firstlba
,"%u",log
->lbafirstfailure
);
1355 // print out a header if needed
1356 if (noheaderprinted
&& (allentries
|| errorfound
)){
1357 pout("Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error\n");
1361 // print out an entry, either if we are printing all entries OR
1362 // if an error was found
1363 if (allentries
|| errorfound
)
1364 pout("#%2d %s %s %s %8d %s\n", testno
, msgtest
, msgstat
, percent
, (int)log
->timestamp
, firstlba
);
1366 // keep track of time of most recent error
1367 if (errorfound
&& !hours
)
1368 hours
=log
->timestamp
;
1371 if (!allentries
&& retval
)
1375 return (retval
| hours
);
1378 void ataPseudoCheckSmart ( struct ata_smart_values
*data
,
1379 struct ata_smart_thresholds_pvt
*thresholds
) {
1382 for (i
= 0 ; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
1383 if (data
->vendor_attributes
[i
].id
&&
1384 thresholds
->thres_entries
[i
].id
&&
1385 ATTRIBUTE_FLAGS_PREFAILURE(data
->vendor_attributes
[i
].flags
) &&
1386 (data
->vendor_attributes
[i
].current
<= thresholds
->thres_entries
[i
].threshold
) &&
1387 (thresholds
->thres_entries
[i
].threshold
!= 0xFE)){
1388 pout("Attribute ID %d Failed\n",(int)data
->vendor_attributes
[i
].id
);
1392 pout("%s\n", ( failed
)?
1393 "SMART overall-health self-assessment test result: FAILED!\n"
1394 "Drive failure expected in less than 24 hours. SAVE ALL DATA":
1395 "SMART overall-health self-assessment test result: PASSED");
1399 // Format SCT Temperature value
1400 static const char * sct_ptemp(signed char x
, char * buf
)
1402 if (x
== -128 /*0x80 = unknown*/)
1405 sprintf(buf
, "%2d", x
);
1409 static const char * sct_pbar(int x
, char * buf
)
1420 memset(buf
, '*', x
);
1426 buf
[0] = '-'; buf
[1] = 0;
1431 static const char * sct_device_state_msg(unsigned char state
)
1434 case 0: return "Active";
1435 case 1: return "Stand-by";
1436 case 2: return "Sleep";
1437 case 3: return "DST executing in background";
1438 case 4: return "SMART Off-line Data Collection executing in background";
1439 case 5: return "SCT command executing in background";
1440 default:return "Unknown";
1445 static int ataPrintSCTStatus(const ata_sct_status_response
* sts
)
1447 pout("SCT Status Version: %u\n", sts
->format_version
);
1448 pout("SCT Version (vendor specific): %u (0x%04x)\n", sts
->sct_version
, sts
->sct_version
);
1449 pout("SCT Support Level: %u\n", sts
->sct_spec
);
1450 pout("Device State: %s (%u)\n",
1451 sct_device_state_msg(sts
->device_state
), sts
->device_state
);
1452 char buf1
[20], buf2
[20];
1453 if ( !sts
->min_temp
&& !sts
->life_min_temp
&& !sts
->byte205
1454 && !sts
->under_limit_count
&& !sts
->over_limit_count
) {
1455 // "Reserved" fields not set, assume "old" format version 2
1456 // Table 11 of T13/1701DT Revision 5
1457 // Table 54 of T13/1699-D Revision 3e
1458 pout("Current Temperature: %s Celsius\n",
1459 sct_ptemp(sts
->hda_temp
, buf1
));
1460 pout("Power Cycle Max Temperature: %s Celsius\n",
1461 sct_ptemp(sts
->max_temp
, buf2
));
1462 pout("Lifetime Max Temperature: %s Celsius\n",
1463 sct_ptemp(sts
->life_max_temp
, buf2
));
1466 // Assume "new" format version 2 or version 3
1467 // T13/e06152r0-3 (Additional SCT Temperature Statistics)
1468 // Table 60 of T13/1699-D Revision 3f
1469 pout("Current Temperature: %s Celsius\n",
1470 sct_ptemp(sts
->hda_temp
, buf1
));
1471 pout("Power Cycle Min/Max Temperature: %s/%s Celsius\n",
1472 sct_ptemp(sts
->min_temp
, buf1
), sct_ptemp(sts
->max_temp
, buf2
));
1473 pout("Lifetime Min/Max Temperature: %s/%s Celsius\n",
1474 sct_ptemp(sts
->life_min_temp
, buf1
), sct_ptemp(sts
->life_max_temp
, buf2
));
1475 if (sts
->byte205
) // e06152r0-2, removed in e06152r3
1476 pout("Lifetime Average Temperature: %s Celsius\n",
1477 sct_ptemp((signed char)sts
->byte205
, buf1
));
1478 pout("Under/Over Temperature Limit Count: %2u/%u\n",
1479 sts
->under_limit_count
, sts
->over_limit_count
);
1484 // Print SCT Temperature History Table
1485 static int ataPrintSCTTempHist(const ata_sct_temperature_history_table
* tmh
)
1487 char buf1
[20], buf2
[80];
1488 pout("SCT Temperature History Version: %u\n", tmh
->format_version
);
1489 pout("Temperature Sampling Period: %u minute%s\n",
1490 tmh
->sampling_period
, (tmh
->sampling_period
==1?"":"s"));
1491 pout("Temperature Logging Interval: %u minute%s\n",
1492 tmh
->interval
, (tmh
->interval
==1?"":"s"));
1493 pout("Min/Max recommended Temperature: %s/%s Celsius\n",
1494 sct_ptemp(tmh
->min_op_limit
, buf1
), sct_ptemp(tmh
->max_op_limit
, buf2
));
1495 pout("Min/Max Temperature Limit: %s/%s Celsius\n",
1496 sct_ptemp(tmh
->under_limit
, buf1
), sct_ptemp(tmh
->over_limit
, buf2
));
1497 pout("Temperature History Size (Index): %u (%u)\n", tmh
->cb_size
, tmh
->cb_index
);
1498 if (!(0 < tmh
->cb_size
&& tmh
->cb_size
<= sizeof(tmh
->cb
) && tmh
->cb_index
< tmh
->cb_size
)) {
1499 pout("Error invalid Temperature History Size or Index\n");
1504 pout("\nIndex Estimated Time Temperature Celsius\n");
1505 unsigned n
= 0, i
= (tmh
->cb_index
+1) % tmh
->cb_size
;
1506 unsigned interval
= (tmh
->interval
> 0 ? tmh
->interval
: 1);
1507 time_t t
= time(0) - (tmh
->cb_size
-1) * interval
* 60;
1508 t
-= t
% (interval
* 60);
1509 while (n
< tmh
->cb_size
) {
1510 // Find range of identical temperatures
1511 unsigned n1
= n
, n2
= n
+1, i2
= (i
+1) % tmh
->cb_size
;
1512 while (n2
< tmh
->cb_size
&& tmh
->cb
[i2
] == tmh
->cb
[i
]) {
1513 n2
++; i2
= (i2
+1) % tmh
->cb_size
;
1517 if (n
== n1
|| n
== n2
-1 || n2
<= n1
+3) {
1519 // TODO: Don't print times < boot time
1520 strftime(date
, sizeof(date
), "%Y-%m-%d %H:%M", localtime(&t
));
1521 pout(" %3u %s %s %s\n", i
, date
,
1522 sct_ptemp(tmh
->cb
[i
], buf1
), sct_pbar(tmh
->cb
[i
], buf2
));
1524 else if (n
== n1
+1) {
1525 pout(" ... ..(%3u skipped). .. %s\n",
1526 n2
-n1
-2, sct_pbar(tmh
->cb
[i
], buf2
));
1528 t
+= interval
* 60; i
= (i
+1) % tmh
->cb_size
; n
++;
1531 //assert(n == tmh->cb_size && i == (tmh->cb_index+1) % tmh->cb_size);
1537 // Compares failure type to policy in effect, and either exits or
1538 // simply returns to the calling routine.
1539 void failuretest(int type
, int returnvalue
){
1541 // If this is an error in an "optional" SMART command
1542 if (type
==OPTIONAL_CMD
){
1543 if (con
->conservative
){
1544 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1550 // If this is an error in a "mandatory" SMART command
1551 if (type
==MANDATORY_CMD
){
1552 if (con
->permissive
--)
1554 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1558 pout("Smartctl internal error in failuretest(type=%d). Please contact developers at " PACKAGE_HOMEPAGE
"\n",type
);
1559 EXIT(returnvalue
|FAILCMD
);
1562 // Used to warn users about invalid checksums. Action to be taken may be
1563 // altered by the user.
1564 void checksumwarning(const char *string
){
1565 // user has asked us to ignore checksum errors
1566 if (con
->checksumignore
)
1569 pout("Warning! %s error: invalid SMART checksum.\n",string
);
1571 // user has asked us to fail on checksum errors
1572 if (con
->checksumfail
)
1578 // Initialize to zero just in case some SMART routines don't work
1579 struct ata_identify_device drive
;
1580 struct ata_smart_values smartval
;
1581 struct ata_smart_thresholds_pvt smartthres
;
1582 struct ata_smart_errorlog smarterror
;
1583 struct ata_smart_selftestlog smartselftest
;
1585 int ataPrintMain (int fd
){
1587 int returnval
=0, retid
=0, supported
=0, needupdate
=0, known
=0;
1588 const char * powername
= 0; char powerchg
= 0;
1590 // If requested, check power mode first
1591 if (con
->powermode
) {
1592 unsigned char powerlimit
= 0xff;
1593 int powermode
= ataCheckPowerMode(fd
);
1594 switch (powermode
) {
1596 if (errno
== ENOSYS
) {
1597 pout("CHECK POWER STATUS not implemented, ignoring -n Option\n"); break;
1599 powername
= "SLEEP"; powerlimit
= 2;
1602 powername
= "STANDBY"; powerlimit
= 3; break;
1604 powername
= "IDLE"; powerlimit
= 4; break;
1606 powername
= "ACTIVE or IDLE"; break;
1608 pout("CHECK POWER STATUS returned %d, not ATA compliant, ignoring -n Option\n", powermode
);
1612 if (con
->powermode
>= powerlimit
) {
1613 pout("Device is in %s mode, exit(%d)\n", powername
, FAILPOWER
);
1616 powerchg
= (powermode
!= 0xff); // SMART tests will spin up drives
1620 // Start by getting Drive ID information. We need this, to know if SMART is supported.
1621 if ((retid
=ataReadHDIdentity(fd
,&drive
))<0){
1622 pout("Smartctl: Device Read Identity Failed (not an ATA/ATAPI device)\n\n");
1623 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
1626 // If requested, show which presets would be used for this drive and exit.
1627 if (con
->showpresets
) {
1628 showpresets(&drive
);
1632 // Use preset vendor attribute options unless user has requested otherwise.
1633 if (!con
->ignorepresets
){
1634 unsigned char *charptr
;
1635 if ((charptr
=con
->attributedefs
))
1636 applypresets(&drive
, &charptr
, con
);
1638 pout("Fatal internal error in ataPrintMain()\n");
1639 EXIT(returnval
|=FAILCMD
);
1643 // Print most drive identity information if requested
1644 if (con
->driveinfo
){
1645 pout("=== START OF INFORMATION SECTION ===\n");
1646 known
= ataPrintDriveInfo(&drive
);
1649 // Was this a packet device?
1651 pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n", packetdevicetype(retid
-1));
1652 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1655 // if drive does not supports SMART it's time to exit
1656 supported
=ataSmartSupport(&drive
);
1657 if (supported
!= 1){
1659 pout("SMART support is: Unavailable - device lacks SMART capability.\n");
1660 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1661 pout(" Checking to be sure by trying SMART ENABLE command.\n");
1664 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
1665 if (!known
) failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1666 pout(" Checking for SMART support by trying SMART ENABLE command.\n");
1669 if (ataEnableSmart(fd
)){
1670 pout(" SMART ENABLE failed - this establishes that this device lacks SMART functionality.\n");
1671 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1675 pout(" SMART ENABLE appeared to work! Continuing.\n");
1678 if (!con
->driveinfo
) pout("\n");
1681 // Now print remaining drive info: is SMART enabled?
1682 if (con
->driveinfo
){
1683 int ison
=ataIsSmartEnabled(&drive
),isenabled
=ison
;
1686 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
1687 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1688 // check SMART support by trying a command
1689 pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
1690 isenabled
=ataDoesSmartWork(fd
);
1693 pout("SMART support is: Available - device has SMART capability.\n");
1694 #ifdef HAVE_ATA_IDENTIFY_IS_CACHED
1695 if (ata_identify_is_cached(fd
)) {
1696 pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
1697 (isenabled
?"En":"Dis"));
1698 isenabled
=ataDoesSmartWork(fd
);
1704 pout("SMART support is: Enabled\n");
1707 pout("SMART support is: Unavailable\n");
1709 pout("SMART support is: Disabled\n");
1711 // Print the (now possibly changed) power mode if available
1713 pout("Power mode %s %s\n", (powerchg
?"was:":"is: "), powername
);
1717 // START OF THE ENABLE/DISABLE SECTION OF THE CODE
1718 if (con
->smartenable
|| con
->smartdisable
||
1719 con
->smartautosaveenable
|| con
->smartautosavedisable
||
1720 con
->smartautoofflineenable
|| con
->smartautoofflinedisable
)
1721 pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
1723 // Enable/Disable SMART commands
1724 if (con
->smartenable
){
1725 if (ataEnableSmart(fd
)) {
1726 pout("Smartctl: SMART Enable Failed.\n\n");
1727 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1730 pout("SMART Enabled.\n");
1733 // From here on, every command requires that SMART be enabled...
1734 if (!ataDoesSmartWork(fd
)) {
1735 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1739 // Turn off SMART on device
1740 if (con
->smartdisable
){
1741 if (ataDisableSmart(fd
)) {
1742 pout( "Smartctl: SMART Disable Failed.\n\n");
1743 failuretest(MANDATORY_CMD
,returnval
|=FAILSMART
);
1745 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1749 // Let's ALWAYS issue this command to get the SMART status
1750 code
=ataSmartStatus2(fd
);
1752 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1754 // Enable/Disable Auto-save attributes
1755 if (con
->smartautosaveenable
){
1756 if (ataEnableAutoSave(fd
)){
1757 pout( "Smartctl: SMART Enable Attribute Autosave Failed.\n\n");
1758 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1761 pout("SMART Attribute Autosave Enabled.\n");
1763 if (con
->smartautosavedisable
){
1764 if (ataDisableAutoSave(fd
)){
1765 pout( "Smartctl: SMART Disable Attribute Autosave Failed.\n\n");
1766 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1769 pout("SMART Attribute Autosave Disabled.\n");
1772 // for everything else read values and thresholds are needed
1773 if (ataReadSmartValues(fd
, &smartval
)){
1774 pout("Smartctl: SMART Read Values failed.\n\n");
1775 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1777 if (ataReadSmartThresholds(fd
, &smartthres
)){
1778 pout("Smartctl: SMART Read Thresholds failed.\n\n");
1779 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1782 // Enable/Disable Off-line testing
1783 if (con
->smartautoofflineenable
){
1784 if (!isSupportAutomaticTimer(&smartval
)){
1785 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1786 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1789 if (ataEnableAutoOffline(fd
)){
1790 pout( "Smartctl: SMART Enable Automatic Offline Failed.\n\n");
1791 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1794 pout("SMART Automatic Offline Testing Enabled every four hours.\n");
1796 if (con
->smartautoofflinedisable
){
1797 if (!isSupportAutomaticTimer(&smartval
)){
1798 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1799 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1802 if (ataDisableAutoOffline(fd
)){
1803 pout("Smartctl: SMART Disable Automatic Offline Failed.\n\n");
1804 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1807 pout("SMART Automatic Offline Testing Disabled.\n");
1810 if (needupdate
&& ataReadSmartValues(fd
, &smartval
)){
1811 pout("Smartctl: SMART Read Values failed.\n\n");
1812 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1815 // all this for a newline!
1816 if (con
->smartenable
|| con
->smartdisable
||
1817 con
->smartautosaveenable
|| con
->smartautosavedisable
||
1818 con
->smartautoofflineenable
|| con
->smartautoofflinedisable
)
1821 // START OF READ-ONLY OPTIONS APART FROM -V and -i
1822 if ( con
->checksmart
|| con
->generalsmartvalues
|| con
->smartvendorattrib
|| con
->smarterrorlog
1823 || con
->smartselftestlog
|| con
->selectivetestlog
|| con
->scttempsts
|| con
->scttemphist
)
1824 pout("=== START OF READ SMART DATA SECTION ===\n");
1826 // Check SMART status (use previously returned value)
1827 if (con
->checksmart
){
1831 // The case where the disk health is OK
1832 pout("SMART overall-health self-assessment test result: PASSED\n");
1833 if (ataCheckSmart(&smartval
, &smartthres
,0)){
1834 if (con
->smartvendorattrib
)
1835 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1838 pout("Please note the following marginal Attributes:\n");
1839 PrintSmartAttribWithThres(&smartval
, &smartthres
,2);
1848 // The case where the disk health is NOT OK
1850 pout("SMART overall-health self-assessment test result: FAILED!\n"
1851 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1853 if (ataCheckSmart(&smartval
, &smartthres
,1)){
1854 returnval
|=FAILATTR
;
1855 if (con
->smartvendorattrib
)
1856 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1859 pout("Failed Attributes:\n");
1860 PrintSmartAttribWithThres(&smartval
, &smartthres
,1);
1864 pout("No failed Attributes found.\n\n");
1865 returnval
|=FAILSTATUS
;
1871 // The case where something went wrong with HDIO_DRIVE_TASK ioctl()
1872 if (ataCheckSmart(&smartval
, &smartthres
,1)){
1874 pout("SMART overall-health self-assessment test result: FAILED!\n"
1875 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1877 returnval
|=FAILATTR
;
1878 returnval
|=FAILSTATUS
;
1879 if (con
->smartvendorattrib
)
1880 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1883 pout("Failed Attributes:\n");
1884 PrintSmartAttribWithThres(&smartval
, &smartthres
,1);
1888 pout("SMART overall-health self-assessment test result: PASSED\n");
1889 if (ataCheckSmart(&smartval
, &smartthres
,0)){
1890 if (con
->smartvendorattrib
)
1891 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1894 pout("Please note the following marginal Attributes:\n");
1895 PrintSmartAttribWithThres(&smartval
, &smartthres
,2);
1904 } // end of switch statement
1907 } // end of checking SMART Status
1909 // Print general SMART values
1910 if (con
->generalsmartvalues
)
1911 ataPrintGeneralSmartValues(&smartval
, &drive
);
1913 // Print vendor-specific attributes
1914 if (con
->smartvendorattrib
){
1916 PrintSmartAttribWithThres(&smartval
, &smartthres
,con
->printing_switchable
?2:0);
1920 // Print SMART log Directory
1921 if (con
->smartlogdirectory
){
1922 struct ata_smart_log_directory smartlogdirectory
;
1923 if (!isGeneralPurposeLoggingCapable(&drive
)){
1924 pout("Warning: device does not support General Purpose Logging\n");
1925 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1929 pout("Log Directory Supported\n");
1930 if (ataReadLogDirectory(fd
, &smartlogdirectory
)){
1932 pout("Read Log Directory failed.\n\n");
1933 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1936 ataPrintLogDirectory( &smartlogdirectory
);
1941 // Print SMART error log
1942 if (con
->smarterrorlog
){
1943 if (!isSmartErrorLogCapable(&smartval
, &drive
)){
1944 pout("Warning: device does not support Error Logging\n");
1945 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1947 if (ataReadErrorLog(fd
, &smarterror
)){
1948 pout("Smartctl: SMART Error Log Read Failed\n");
1949 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1952 // quiet mode is turned on inside ataPrintSmartErrorLog()
1953 if (ataPrintSmartErrorlog(&smarterror
))
1959 // Print SMART self-test log
1960 if (con
->smartselftestlog
){
1961 if (!isSmartTestLogCapable(&smartval
, &drive
)){
1962 pout("Warning: device does not support Self Test Logging\n");
1963 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1965 if(ataReadSelfTestLog(fd
, &smartselftest
)){
1966 pout("Smartctl: SMART Self Test Log Read Failed\n");
1967 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1971 if (ataPrintSmartSelfTestlog(&smartselftest
,!con
->printing_switchable
))
1978 // Print SMART selective self-test log
1979 if (con
->selectivetestlog
){
1980 struct ata_selective_self_test_log log
;
1982 if (!isSupportSelectiveSelfTest(&smartval
))
1983 pout("Device does not support Selective Self Tests/Logging\n");
1984 else if(ataReadSelectiveSelfTestLog(fd
, &log
)) {
1985 pout("Smartctl: SMART Selective Self Test Log Read Failed\n");
1986 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1990 ataPrintSelectiveSelfTestLog(&log
, &smartval
);
1996 // Print SMART SCT status and temperature history table
1997 if (con
->scttempsts
|| con
->scttemphist
|| con
->scttempint
) {
1999 if (!isSCTCapable(&drive
)) {
2000 pout("Warning: device does not support SCT Commands\n");
2001 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2004 if (con
->scttempsts
|| con
->scttemphist
) {
2005 ata_sct_status_response sts
;
2006 ata_sct_temperature_history_table tmh
;
2007 if (!con
->scttemphist
) {
2008 // Read SCT status only
2009 if (ataReadSCTStatus(fd
, &sts
)) {
2010 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2015 if (!isSCTDataTableCapable(&drive
)) {
2016 pout("Warning: device does not support SCT Data Table command\n");
2017 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2020 // Read SCT status and temperature history
2021 if (ataReadSCTTempHist(fd
, &tmh
, &sts
)) {
2022 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2026 if (con
->scttempsts
)
2027 ataPrintSCTStatus(&sts
);
2028 if (con
->scttemphist
)
2029 ataPrintSCTTempHist(&tmh
);
2032 if (con
->scttempint
) {
2033 // Set new temperature logging interval
2034 if (!isSCTFeatureControlCapable(&drive
)) {
2035 pout("Warning: device does not support SCT Feature Control command\n");
2036 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2039 if (ataSetSCTTempInterval(fd
, con
->scttempint
, !!con
->scttempintp
)) {
2040 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2043 pout("Temperature Logging Interval set to %u minute%s (%s)\n",
2044 con
->scttempint
, (con
->scttempint
==1?"":"s"), (con
->scttempintp
?"persistent":"volatile"));
2050 // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
2051 if (con
->testcase
==-1)
2054 pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
2055 // if doing a self-test, be sure it's supported by the hardware
2056 switch (con
->testcase
){
2057 case OFFLINE_FULL_SCAN
:
2058 if (!isSupportExecuteOfflineImmediate(&smartval
)){
2059 pout("Warning: device does not support Execute Offline Immediate function.\n\n");
2060 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2063 case ABORT_SELF_TEST
:
2064 case SHORT_SELF_TEST
:
2065 case EXTEND_SELF_TEST
:
2066 case SHORT_CAPTIVE_SELF_TEST
:
2067 case EXTEND_CAPTIVE_SELF_TEST
:
2068 if (!isSupportSelfTest(&smartval
)){
2069 pout("Warning: device does not support Self-Test functions.\n\n");
2070 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2073 case CONVEYANCE_SELF_TEST
:
2074 case CONVEYANCE_CAPTIVE_SELF_TEST
:
2075 if (!isSupportConveyanceSelfTest(&smartval
)){
2076 pout("Warning: device does not support Conveyance Self-Test functions.\n\n");
2077 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2080 case SELECTIVE_SELF_TEST
:
2081 case SELECTIVE_CAPTIVE_SELF_TEST
:
2082 if (!isSupportSelectiveSelfTest(&smartval
)){
2083 pout("Warning: device does not support Selective Self-Test functions.\n\n");
2084 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2088 pout("Internal error in smartctl: con->testcase==%d not recognized\n", (int)con
->testcase
);
2089 pout("Please contact smartmontools developers at %s.\n", PACKAGE_BUGREPORT
);
2090 EXIT(returnval
|=FAILCMD
);
2093 // Now do the test. Note ataSmartTest prints its own error/success
2095 if (ataSmartTest(fd
, con
->testcase
, &smartval
, get_num_sectors(&drive
)))
2096 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2098 // Tell user how long test will take to complete. This is tricky
2099 // because in the case of an Offline Full Scan, the completion
2100 // timer is volatile, and needs to be read AFTER the command is
2101 // given. If this will interrupt the Offline Full Scan, we don't
2102 // do it, just warn user.
2103 if (con
->testcase
==OFFLINE_FULL_SCAN
){
2104 if (isSupportOfflineAbort(&smartval
))
2105 pout("Note: giving further SMART commands will abort Offline testing\n");
2106 else if (ataReadSmartValues(fd
, &smartval
)){
2107 pout("Smartctl: SMART Read Values failed.\n");
2108 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2112 // Now say how long the test will take to complete
2113 if ((timewait
=TestTime(&smartval
,con
->testcase
))){
2114 time_t t
=time(NULL
);
2115 if (con
->testcase
==OFFLINE_FULL_SCAN
) {
2117 pout("Please wait %d seconds for test to complete.\n", (int)timewait
);
2120 pout("Please wait %d minutes for test to complete.\n", (int)timewait
);
2122 pout("Test will complete after %s\n", ctime(&t
));
2124 if (con
->testcase
!=SHORT_CAPTIVE_SELF_TEST
&&
2125 con
->testcase
!=EXTEND_CAPTIVE_SELF_TEST
&&
2126 con
->testcase
!=CONVEYANCE_CAPTIVE_SELF_TEST
&&
2127 con
->testcase
!=SELECTIVE_CAPTIVE_SELF_TEST
)
2128 pout("Use smartctl -X to abort test.\n");