4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2002-6 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.171 2006/10/28 11:51:25 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 formatdriveidstring(char *out
, const char *in
, int n
)
100 swapbytes(tmp
, in
, n
);
105 swapbytes(tmp
, in
, n
);
111 void infofound(char *output
) {
113 pout("%s\n", output
);
115 pout("[No Information Found]\n");
119 /* For the given Command Register (CR) and Features Register (FR), attempts
120 * to construct a string that describes the contents of the Status
121 * Register (ST) and Error Register (ER). The string is dynamically allocated
122 * memory and the return value is a pointer to this string. It is up to the
123 * caller to free this memory. If there is insufficient memory or if the
124 * meanings of the flags of the error register are not known for the given
125 * command then it returns NULL.
127 * The meanings of the flags of the error register for all commands are
128 * described in the ATA spec and could all be supported here in theory.
129 * Currently, only a few commands are supported (those that have been seen
130 * to produce errors). If many more are to be added then this function
131 * should probably be redesigned.
133 char *construct_st_er_desc(struct ata_smart_errorlog_struct
*data
) {
134 unsigned char CR
=data
->commands
[4].commandreg
;
135 unsigned char FR
=data
->commands
[4].featuresreg
;
136 unsigned char ST
=data
->error_struct
.status
;
137 unsigned char ER
=data
->error_struct
.error_register
;
139 const char *error_flag
[8];
140 int i
, print_lba
=0, print_sector
=0;
142 // Set of character strings corresponding to different error codes.
143 // Please keep in alphabetic order if you add more.
144 const char *abrt
= "ABRT"; // ABORTED
145 const char *amnf
= "AMNF"; // ADDRESS MARK NOT FOUND
146 const char *ccto
= "CCTO"; // COMMAND COMPLETION TIMED OUT
147 const char *eom
= "EOM"; // END OF MEDIA
148 const char *icrc
= "ICRC"; // INTERFACE CRC ERROR
149 const char *idnf
= "IDNF"; // ID NOT FOUND
150 const char *ili
= "ILI"; // MEANING OF THIS BIT IS COMMAND-SET SPECIFIC
151 const char *mc
= "MC"; // MEDIA CHANGED
152 const char *mcr
= "MCR"; // MEDIA CHANGE REQUEST
153 const char *nm
= "NM"; // NO MEDIA
154 const char *obs
= "obs"; // OBSOLETE
155 const char *tk0nf
= "TK0NF"; // TRACK 0 NOT FOUND
156 const char *unc
= "UNC"; // UNCORRECTABLE
157 const char *wp
= "WP"; // WRITE PROTECTED
159 /* If for any command the Device Fault flag of the status register is
160 * not used then used_device_fault should be set to 0 (in the CR switch
163 int uses_device_fault
= 1;
165 /* A value of NULL means that the error flag isn't used */
166 for (i
= 0; i
< 8; i
++)
167 error_flag
[i
] = NULL
;
170 case 0x10: // RECALIBRATE
171 error_flag
[2] = abrt
;
172 error_flag
[1] = tk0nf
;
174 case 0x20: /* READ SECTOR(S) */
175 case 0x21: // READ SECTOR(S)
176 case 0x24: // READ SECTOR(S) EXT
177 case 0xC4: /* READ MULTIPLE */
178 case 0x29: // READ MULTIPLE EXT
181 error_flag
[4] = idnf
;
183 error_flag
[2] = abrt
;
185 error_flag
[0] = amnf
;
188 case 0x22: // READ LONG (with retries)
189 case 0x23: // READ LONG (without retries)
190 error_flag
[4] = idnf
;
191 error_flag
[2] = abrt
;
192 error_flag
[0] = amnf
;
195 case 0x2a: // READ STREAM DMA
196 case 0x2b: // READ STREAM PIO
198 error_flag
[7] = icrc
;
201 error_flag
[4] = idnf
;
203 error_flag
[2] = abrt
;
205 error_flag
[0] = ccto
;
207 print_sector
=(int)data
->error_struct
.sector_count
;
209 case 0x3A: // WRITE STREAM DMA
210 case 0x3B: // WRITE STREAM PIO
212 error_flag
[7] = icrc
;
215 error_flag
[4] = idnf
;
217 error_flag
[2] = abrt
;
219 error_flag
[0] = ccto
;
221 print_sector
=(int)data
->error_struct
.sector_count
;
223 case 0x25: /* READ DMA EXT */
224 case 0x26: // READ DMA QUEUED EXT
225 case 0xC7: // READ DMA QUEUED
226 case 0xC8: /* READ DMA */
228 error_flag
[7] = icrc
;
231 error_flag
[4] = idnf
;
233 error_flag
[2] = abrt
;
235 error_flag
[0] = amnf
;
237 if (CR
==0x25 || CR
==0xC8)
238 print_sector
=(int)data
->error_struct
.sector_count
;
240 case 0x30: /* WRITE SECTOR(S) */
241 case 0x31: // WRITE SECTOR(S)
242 case 0x34: // WRITE SECTOR(S) EXT
243 case 0xC5: /* WRITE MULTIPLE */
244 case 0x39: // WRITE MULTIPLE EXT
245 case 0xCE: // WRITE MULTIPLE FUA EXT
248 error_flag
[4] = idnf
;
250 error_flag
[2] = abrt
;
254 case 0x32: // WRITE LONG (with retries)
255 case 0x33: // WRITE LONG (without retries)
256 error_flag
[4] = idnf
;
257 error_flag
[2] = abrt
;
260 case 0x3C: // WRITE VERIFY
262 error_flag
[4] = idnf
;
263 error_flag
[2] = abrt
;
264 error_flag
[0] = amnf
;
267 case 0x40: // READ VERIFY SECTOR(S) with retries
268 case 0x41: // READ VERIFY SECTOR(S) without retries
269 case 0x42: // READ VERIFY SECTOR(S) EXT
272 error_flag
[4] = idnf
;
274 error_flag
[2] = abrt
;
276 error_flag
[0] = amnf
;
279 case 0xA0: /* PACKET */
280 /* Bits 4-7 are all used for sense key (a 'command packet set specific error
281 * indication' according to the ATA/ATAPI-7 standard), so "Sense key" will
282 * be repeated in the error description string if more than one of those
285 error_flag
[7] = "Sense key (bit 3)",
286 error_flag
[6] = "Sense key (bit 2)",
287 error_flag
[5] = "Sense key (bit 1)",
288 error_flag
[4] = "Sense key (bit 0)",
289 error_flag
[2] = abrt
;
293 case 0xA1: /* IDENTIFY PACKET DEVICE */
294 case 0xEF: /* SET FEATURES */
296 case 0xC6: /* SET MULTIPLE MODE */
297 error_flag
[2] = abrt
;
299 case 0x2F: // READ LOG EXT
301 error_flag
[4] = idnf
;
302 error_flag
[2] = abrt
;
305 case 0x3F: // WRITE LOG EXT
306 error_flag
[4] = idnf
;
307 error_flag
[2] = abrt
;
310 case 0xB0: /* SMART */
312 case 0xD0: // SMART READ DATA
313 case 0xD1: // SMART READ ATTRIBUTE THRESHOLDS
314 case 0xD5: /* SMART READ LOG */
316 error_flag
[4] = idnf
;
317 error_flag
[2] = abrt
;
320 case 0xD6: /* SMART WRITE LOG */
321 error_flag
[4] = idnf
;
322 error_flag
[2] = abrt
;
325 case 0xD2: // Enable/Disable Attribute Autosave
326 case 0xD3: // SMART SAVE ATTRIBUTE VALUES (ATA-3)
327 case 0xD8: // SMART ENABLE OPERATIONS
328 case 0xD9: /* SMART DISABLE OPERATIONS */
329 case 0xDA: /* SMART RETURN STATUS */
330 case 0xDB: // Enable/Disable Auto Offline (SFF)
331 error_flag
[2] = abrt
;
333 case 0xD4: // SMART EXECUTE IMMEDIATE OFFLINE
334 error_flag
[4] = idnf
;
335 error_flag
[2] = abrt
;
342 case 0xB1: /* DEVICE CONFIGURATION */
344 case 0xC0: /* DEVICE CONFIGURATION RESTORE */
345 error_flag
[2] = abrt
;
352 case 0xCA: /* WRITE DMA */
354 case 0x35: // WRITE DMA EXT
355 case 0x3D: // WRITE DMA FUA EXT
356 case 0xCC: // WRITE DMA QUEUED
357 case 0x36: // WRITE DMA QUEUED EXT
358 case 0x3E: // WRITE DMA QUEUED FUA EXT
359 error_flag
[7] = icrc
;
362 error_flag
[4] = idnf
;
364 error_flag
[2] = abrt
;
366 error_flag
[0] = amnf
;
369 print_sector
=(int)data
->error_struct
.sector_count
;
371 case 0xE4: // READ BUFFER
372 case 0xE8: // WRITE BUFFER
373 error_flag
[2] = abrt
;
379 /* 256 bytes -- that'll be plenty (OK, this is lazy!) */
380 if (!(s
= (char *)malloc(256)))
385 /* We ignore any status flags other than Device Fault and Error */
387 if (uses_device_fault
&& (ST
& (1 << 5))) {
388 strcat(s
, "Device Fault");
389 if (ST
& 1) // Error flag
392 if (ST
& 1) { // Error flag
395 strcat(s
, "Error: ");
396 for (i
= 7; i
>= 0; i
--)
397 if ((ER
& (1 << i
)) && (error_flag
[i
])) {
400 strcat(s
, error_flag
[i
]);
404 // If the error was a READ or WRITE error, print the Logical Block
405 // Address (LBA) at which the read or write failed.
410 // bits 24-27: bits 0-3 of DH
411 lba
= 0xf & data
->error_struct
.drive_head
;
414 lba
|= data
->error_struct
.cylinder_high
;
417 lba
|= data
->error_struct
.cylinder_low
;
420 lba
|= data
->error_struct
.sector_number
;
422 // print number of sectors, if known, and append to print string
424 snprintf(tmp
, 128, " %d sectors", print_sector
);
428 // print LBA, and append to print string
429 snprintf(tmp
, 128, " at LBA = 0x%08x = %d", lba
, lba
);
436 // This returns the capacity of a disk drive and also prints this into
437 // a string, using comma separators to make it easier to read. If the
438 // drive doesn't support LBA addressing or has no user writable
439 // sectors (eg, CDROM or DVD) then routine returns zero.
440 uint64_t determine_capacity(struct ata_identify_device
*drive
, char *pstring
){
442 unsigned short command_set_2
= drive
->command_set_2
;
443 unsigned short capabilities_0
= drive
->words047_079
[49-47];
444 unsigned short sects_16
= drive
->words047_079
[60-47];
445 unsigned short sects_32
= drive
->words047_079
[61-47];
446 unsigned short lba_16
= drive
->words088_255
[100-88];
447 unsigned short lba_32
= drive
->words088_255
[101-88];
448 unsigned short lba_48
= drive
->words088_255
[102-88];
449 unsigned short lba_64
= drive
->words088_255
[103-88];
450 uint64_t capacity_short
=0, capacity
=0, threedigits
, power_of_ten
;
451 int started
=0,k
=1000000000;
454 // get correct character to use as thousands separator
456 struct lconv
*currentlocale
=NULL
;
457 setlocale (LC_ALL
, "");
458 currentlocale
=localeconv();
459 if (*(currentlocale
->thousands_sep
))
460 separator
=currentlocale
->thousands_sep
;
461 #endif // #ifdef HAVE_LOCALE_H
463 // if drive supports LBA addressing, determine 32-bit LBA capacity
464 if (capabilities_0
& 0x0200) {
465 capacity_short
= (unsigned int)sects_32
<< 16 |
466 (unsigned int)sects_16
<< 0 ;
468 // if drive supports 48-bit addressing, determine THAT capacity
469 if ((command_set_2
& 0xc000) == 0x4000 && (command_set_2
& 0x0400))
470 capacity
= (uint64_t)lba_64
<< 48 |
471 (uint64_t)lba_48
<< 32 |
472 (uint64_t)lba_32
<< 16 |
473 (uint64_t)lba_16
<< 0 ;
475 // choose the larger of the two possible capacities
476 if (capacity_short
>capacity
)
477 capacity
=capacity_short
;
480 // turn sectors into bytes
481 capacity_short
= (capacity
*= 512);
483 // print with locale-specific separators (default is comma)
487 for (k
=0; k
<7; k
++) {
488 threedigits
= capacity
/power_of_ten
;
489 capacity
-= threedigits
*power_of_ten
;
491 // we have already printed some digits
492 pstring
+= sprintf(pstring
, "%s%03"PRIu64
, separator
, threedigits
);
493 else if (threedigits
|| k
==6) {
494 // these are the first digits that we are printing
495 pstring
+= sprintf(pstring
, "%"PRIu64
, threedigits
);
499 power_of_ten
/= 1000;
502 return capacity_short
;
505 int ataPrintDriveInfo (struct ata_identify_device
*drive
){
506 int version
, drivetype
;
507 const char *description
;
508 char unknown
[64], timedatetz
[DATEANDEPOCHLEN
];
509 unsigned short minorrev
;
510 char model
[64], serial
[64], firm
[64], capacity
[64];
512 // format drive information (with byte swapping as needed)
513 formatdriveidstring(model
, (char *)drive
->model
,40);
514 formatdriveidstring(serial
, (char *)drive
->serial_no
,20);
515 formatdriveidstring(firm
, (char *)drive
->fw_rev
,8);
517 // print out model, serial # and firmware versions (byte-swap ASCI strings)
518 drivetype
=lookupdrive(model
, firm
);
520 // Print model family if known
521 if (drivetype
>=0 && knowndrives
[drivetype
].modelfamily
)
522 pout("Model Family: %s\n", knowndrives
[drivetype
].modelfamily
);
524 pout("Device Model: ");
526 pout("Serial Number: ");
528 pout("Firmware Version: ");
531 if (determine_capacity(drive
, capacity
))
532 pout("User Capacity: %s bytes\n", capacity
);
534 // See if drive is recognized
535 pout("Device is: %s\n", drivetype
<0?
536 "Not in smartctl database [for details use: -P showall]":
537 "In smartctl database [for details use: -P show]");
539 // now get ATA version info
540 version
=ataVersionInfo(&description
,drive
, &minorrev
);
542 // unrecognized minor revision code
545 sprintf(unknown
, "Exact ATA specification draft version not indicated");
547 sprintf(unknown
,"Not recognized. Minor revision code: 0x%02hx", minorrev
);
552 // SMART Support was first added into the ATA/ATAPI-3 Standard with
553 // Revision 3 of the document, July 25, 1995. Look at the "Document
554 // Status" revision commands at the beginning of
555 // http://www.t13.org/project/d2008r6.pdf to see this. So it's not
556 // enough to check if we are ATA-3. Version=-3 indicates ATA-3
557 // BEFORE Revision 3.
558 pout("ATA Version is: %d\n",(int)abs(version
));
559 pout("ATA Standard is: %s\n",description
);
561 // print current time and date and timezone
562 dateandtimezone(timedatetz
);
563 pout("Local Time is: %s\n", timedatetz
);
565 // Print warning message, if there is one
566 if (drivetype
>=0 && knowndrives
[drivetype
].warningmsg
)
567 pout("\n==> WARNING: %s\n\n", knowndrives
[drivetype
].warningmsg
);
572 pout("SMART is only available in ATA Version 3 Revision 3 or greater.\n");
573 pout("We will try to proceed in spite of this.\n");
578 const char *OfflineDataCollectionStatus(unsigned char status_byte
){
579 unsigned char stat
=status_byte
& 0x7f;
583 return "was never started";
585 return "was completed without error";
587 if (status_byte
== 0x03)
588 return "is in progress";
590 return "is in a Reserved state";
592 return "was suspended by an interrupting command from host";
594 return "was aborted by an interrupting command from host";
596 return "was aborted by the device with a fatal error";
599 return "is in a Vendor Specific state\n";
601 return "is in a Reserved state\n";
606 /* prints verbose value Off-line data collection status byte */
607 void PrintSmartOfflineStatus(struct ata_smart_values
*data
){
609 pout("Offline data collection status: (0x%02x)\t",
610 (int)data
->offline_data_collection_status
);
612 // Off-line data collection status byte is not a reserved
613 // or vendor specific value
614 pout("Offline data collection activity\n"
615 "\t\t\t\t\t%s.\n", OfflineDataCollectionStatus(data
->offline_data_collection_status
));
617 // Report on Automatic Data Collection Status. Only IBM documents
618 // this bit. See SFF 8035i Revision 2 for details.
619 if (data
->offline_data_collection_status
& 0x80)
620 pout("\t\t\t\t\tAuto Offline Data Collection: Enabled.\n");
622 pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
627 void PrintSmartSelfExecStatus(struct ata_smart_values
*data
)
629 pout("Self-test execution status: ");
631 switch (data
->self_test_exec_status
>> 4)
634 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
635 (int)data
->self_test_exec_status
);
636 pout("without error or no self-test has ever \n\t\t\t\t\tbeen run.\n");
639 pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
640 (int)data
->self_test_exec_status
);
644 pout("(%4d)\tThe self-test routine was interrupted\n\t\t\t\t\t",
645 (int)data
->self_test_exec_status
);
646 pout("by the host with a hard or soft reset.\n");
649 pout("(%4d)\tA fatal error or unknown test error\n\t\t\t\t\t",
650 (int)data
->self_test_exec_status
);
651 pout("occurred while the device was executing\n\t\t\t\t\t");
652 pout("its self-test routine and the device \n\t\t\t\t\t");
653 pout("was unable to complete the self-test \n\t\t\t\t\t");
657 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
658 (int)data
->self_test_exec_status
);
659 pout("a test element that failed and the test\n\t\t\t\t\t");
660 pout("element that failed is not known.\n");
663 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
664 (int)data
->self_test_exec_status
);
665 pout("the electrical element of the test\n\t\t\t\t\t");
669 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
670 (int)data
->self_test_exec_status
);
671 pout("the servo (and/or seek) element of the \n\t\t\t\t\t");
672 pout("test failed.\n");
675 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
676 (int)data
->self_test_exec_status
);
677 pout("the read element of the test failed.\n");
680 pout("(%4d)\tSelf-test routine in progress...\n\t\t\t\t\t",
681 (int)data
->self_test_exec_status
);
682 pout("%1d0%% of test remaining.\n",
683 (int)(data
->self_test_exec_status
& 0x0f));
686 pout("(%4d)\tReserved.\n",
687 (int)data
->self_test_exec_status
);
695 void PrintSmartTotalTimeCompleteOffline ( struct ata_smart_values
*data
){
696 pout("Total time to complete Offline \n");
697 pout("data collection: \t\t (%4d) seconds.\n",
698 (int)data
->total_time_to_complete_off_line
);
703 void PrintSmartOfflineCollectCap(struct ata_smart_values
*data
){
704 pout("Offline data collection\n");
705 pout("capabilities: \t\t\t (0x%02x) ",
706 (int)data
->offline_data_collection_capability
);
708 if (data
->offline_data_collection_capability
== 0x00){
709 pout("\tOffline data collection not supported.\n");
712 pout( "%s\n", isSupportExecuteOfflineImmediate(data
)?
713 "SMART execute Offline immediate." :
714 "No SMART execute Offline immediate.");
716 pout( "\t\t\t\t\t%s\n", isSupportAutomaticTimer(data
)?
717 "Auto Offline data collection on/off support.":
718 "No Auto Offline data collection support.");
720 pout( "\t\t\t\t\t%s\n", isSupportOfflineAbort(data
)?
721 "Abort Offline collection upon new\n\t\t\t\t\tcommand.":
722 "Suspend Offline collection upon new\n\t\t\t\t\tcommand.");
724 pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data
)?
725 "Offline surface scan supported.":
726 "No Offline surface scan supported.");
728 pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data
)?
729 "Self-test supported.":
730 "No Self-test supported.");
732 pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data
)?
733 "Conveyance Self-test supported.":
734 "No Conveyance Self-test supported.");
736 pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data
)?
737 "Selective Self-test supported.":
738 "No Selective Self-test supported.");
744 void PrintSmartCapability ( struct ata_smart_values
*data
)
746 pout("SMART capabilities: ");
747 pout("(0x%04x)\t", (int)data
->smart_capability
);
749 if (data
->smart_capability
== 0x00)
751 pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
756 pout( "%s\n", (data
->smart_capability
& 0x01)?
757 "Saves SMART data before entering\n\t\t\t\t\tpower-saving mode.":
758 "Does not save SMART data before\n\t\t\t\t\tentering power-saving mode.");
760 if ( data
->smart_capability
& 0x02 )
762 pout("\t\t\t\t\tSupports SMART auto save timer.\n");
767 void PrintSmartErrorLogCapability (struct ata_smart_values
*data
, struct ata_identify_device
*identity
)
770 pout("Error logging capability: ");
772 if ( isSmartErrorLogCapable(data
, identity
) )
774 pout(" (0x%02x)\tError logging supported.\n",
775 (int)data
->errorlog_capability
);
778 pout(" (0x%02x)\tError logging NOT supported.\n",
779 (int)data
->errorlog_capability
);
783 void PrintSmartShortSelfTestPollingTime(struct ata_smart_values
*data
){
784 pout("Short self-test routine \n");
785 if (isSupportSelfTest(data
))
786 pout("recommended polling time: \t (%4d) minutes.\n",
787 (int)data
->short_test_completion_time
);
789 pout("recommended polling time: \t Not Supported.\n");
792 void PrintSmartExtendedSelfTestPollingTime(struct ata_smart_values
*data
){
793 pout("Extended self-test routine\n");
794 if (isSupportSelfTest(data
))
795 pout("recommended polling time: \t (%4d) minutes.\n",
796 (int)data
->extend_test_completion_time
);
798 pout("recommended polling time: \t Not Supported.\n");
801 void PrintSmartConveyanceSelfTestPollingTime(struct ata_smart_values
*data
){
802 pout("Conveyance self-test routine\n");
803 if (isSupportConveyanceSelfTest(data
))
804 pout("recommended polling time: \t (%4d) minutes.\n",
805 (int)data
->conveyance_test_completion_time
);
807 pout("recommended polling time: \t Not Supported.\n");
810 // onlyfailed=0 : print all attribute values
811 // onlyfailed=1: just ones that are currently failed and have prefailure bit set
812 // onlyfailed=2: ones that are failed, or have failed with or without prefailure bit set
813 void PrintSmartAttribWithThres (struct ata_smart_values
*data
,
814 struct ata_smart_thresholds_pvt
*thresholds
,
820 // step through all vendor attributes
821 for (i
=0; i
<NUMBER_ATA_SMART_ATTRIBUTES
; i
++){
823 struct ata_smart_attribute
*disk
=data
->vendor_attributes
+i
;
824 struct ata_smart_threshold_entry
*thre
=thresholds
->thres_entries
+i
;
826 // consider only valid attributes (allowing some screw-ups in the
827 // thresholds page data to slip by)
829 const char *type
, *update
;
830 int failednow
,failedever
;
831 char attributename
[64];
833 failednow
= (disk
->current
<= thre
->threshold
);
834 failedever
= (disk
->worst
<= thre
->threshold
);
836 // These break out of the loop if we are only printing certain entries...
837 if (onlyfailed
==1 && (!ATTRIBUTE_FLAGS_PREFAILURE(disk
->flags
) || !failednow
))
840 if (onlyfailed
==2 && !failedever
)
843 // print header only if needed
846 pout("SMART Attributes Data Structure revision number: %d\n",(int)data
->revnumber
);
847 pout("Vendor Specific SMART Attributes with Thresholds:\n");
849 pout("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n");
853 // is this Attribute currently failed, or has it ever failed?
855 status
="FAILING_NOW";
857 status
="In_the_past";
861 // Print name of attribute
862 ataPrintSmartAttribName(attributename
,disk
->id
, con
->attributedefs
);
863 pout("%-28s",attributename
);
865 // printing line for each valid attribute
866 type
=ATTRIBUTE_FLAGS_PREFAILURE(disk
->flags
)?"Pre-fail":"Old_age";
867 update
=ATTRIBUTE_FLAGS_ONLINE(disk
->flags
)?"Always":"Offline";
869 pout("0x%04x %.3d %.3d %.3d %-10s%-9s%-12s",
870 (int)disk
->flags
, (int)disk
->current
, (int)disk
->worst
,
871 (int)thre
->threshold
, type
, update
, status
);
873 // print raw value of attribute
874 ataPrintSmartAttribRawValue(rawstring
, disk
, con
->attributedefs
);
875 pout("%s\n", rawstring
);
877 // print a warning if there is inconsistency here!
878 if (disk
->id
!= thre
->id
){
879 char atdat
[64],atthr
[64];
880 ataPrintSmartAttribName(atdat
, disk
->id
, con
->attributedefs
);
881 ataPrintSmartAttribName(atthr
, thre
->id
, con
->attributedefs
);
882 pout("%-28s<== Data Page | WARNING: PREVIOUS ATTRIBUTE HAS TWO\n",atdat
);
883 pout("%-28s<== Threshold Page | INCONSISTENT IDENTITIES IN THE DATA\n",atthr
);
887 if (!needheader
) pout("\n");
890 void ataPrintGeneralSmartValues(struct ata_smart_values
*data
, struct ata_identify_device
*drive
){
891 pout("General SMART Values:\n");
893 PrintSmartOfflineStatus(data
);
895 if (isSupportSelfTest(data
)){
896 PrintSmartSelfExecStatus (data
);
899 PrintSmartTotalTimeCompleteOffline(data
);
900 PrintSmartOfflineCollectCap(data
);
901 PrintSmartCapability(data
);
903 PrintSmartErrorLogCapability(data
, drive
);
905 pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive
)?
906 "General Purpose Logging supported.":
907 "No General Purpose Logging support.");
909 if (isSupportSelfTest(data
)){
910 PrintSmartShortSelfTestPollingTime (data
);
911 PrintSmartExtendedSelfTestPollingTime (data
);
913 if (isSupportConveyanceSelfTest(data
))
914 PrintSmartConveyanceSelfTestPollingTime (data
);
919 int ataPrintLogDirectory(struct ata_smart_log_directory
*data
){
923 pout("SMART Log Directory Logging Version %d%s\n",
924 data
->logversion
, data
->logversion
==1?" [multi-sector log support]":"");
925 for (i
=0; i
<=255; i
++){
928 // Directory log length
929 numsect
= i
? data
->entry
[i
-1].numsectors
: 1;
931 // If the log is not empty, what is it's name
935 name
="Log Directory"; break;
937 name
="Summary SMART error log"; break;
939 name
="Comprehensive SMART error log"; break;
941 name
="Extended Comprehensive SMART error log"; break;
943 name
="SMART self-test log"; break;
945 name
="Extended self-test log"; break;
947 name
="Selective self-test log"; break;
949 name
="Streaming performance log"; break;
951 name
="Write stream error log"; break;
953 name
="Read stream error log"; break;
955 name
="Delayed sector log"; break;
957 if (0xa0<=i
&& i
<=0xbf)
958 name
="Device vendor specific log";
959 else if (0x80<=i
&& i
<=0x9f)
960 name
="Host vendor specific log";
966 // print name and length of log
967 pout("Log at address 0x%02x has %03d sectors [%s]\n",
974 // returns number of errors
975 int ataPrintSmartErrorlog(struct ata_smart_errorlog
*data
){
978 pout("SMART Error Log Version: %d\n", (int)data
->revnumber
);
980 // if no errors logged, return
981 if (!data
->error_log_pointer
){
982 pout("No Errors Logged\n\n");
986 // If log pointer out of range, return
987 if (data
->error_log_pointer
>5){
988 pout("Invalid Error Log index = 0x%02x (T13/1321D rev 1c "
989 "Section 8.41.6.8.2.2 gives valid range from 1 to 5)\n\n",
990 (int)data
->error_log_pointer
);
994 // Some internal consistency checking of the data structures
995 if ((data
->ata_error_count
-data
->error_log_pointer
)%5 && con
->fixfirmwarebug
!= FIX_SAMSUNG2
) {
996 pout("Warning: ATA error count %d inconsistent with error log pointer %d\n\n",
997 data
->ata_error_count
,data
->error_log_pointer
);
1000 // starting printing error log info
1001 if (data
->ata_error_count
<=5)
1002 pout( "ATA Error Count: %d\n", (int)data
->ata_error_count
);
1004 pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1005 (int)data
->ata_error_count
);
1007 pout("\tCR = Command Register [HEX]\n"
1008 "\tFR = Features Register [HEX]\n"
1009 "\tSC = Sector Count Register [HEX]\n"
1010 "\tSN = Sector Number Register [HEX]\n"
1011 "\tCL = Cylinder Low Register [HEX]\n"
1012 "\tCH = Cylinder High Register [HEX]\n"
1013 "\tDH = Device/Head Register [HEX]\n"
1014 "\tDC = Device Command Register [HEX]\n"
1015 "\tER = Error register [HEX]\n"
1016 "\tST = Status register [HEX]\n"
1017 "Powered_Up_Time is measured from power on, and printed as\n"
1018 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1019 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1021 // now step through the five error log data structures (table 39 of spec)
1022 for (k
= 4; k
>= 0; k
-- ) {
1025 // The error log data structure entries are a circular buffer
1026 int j
, i
=(data
->error_log_pointer
+k
)%5;
1027 struct ata_smart_errorlog_struct
*elog
=data
->errorlog_struct
+i
;
1028 struct ata_smart_errorlog_error_struct
*summary
=&(elog
->error_struct
);
1030 // Spec says: unused error log structures shall be zero filled
1031 if (nonempty((unsigned char*)elog
,sizeof(*elog
))){
1032 // Table 57 of T13/1532D Volume 1 Revision 3
1034 int bits
=summary
->state
& 0x0f;
1035 int days
= (int)summary
->timestamp
/24;
1038 case 0x00: msgstate
="in an unknown state";break;
1039 case 0x01: msgstate
="sleeping"; break;
1040 case 0x02: msgstate
="in standby mode"; break;
1041 case 0x03: msgstate
="active or idle"; break;
1042 case 0x04: msgstate
="doing SMART Offline or Self-test"; break;
1045 msgstate
="in a reserved state";
1047 msgstate
="in a vendor specific state";
1050 // See table 42 of ATA5 spec
1052 pout("Error %d occurred at disk power-on lifetime: %d hours (%d days + %d hours)\n",
1053 (int)(data
->ata_error_count
+k
-4), (int)summary
->timestamp
, days
, (int)(summary
->timestamp
-24*days
));
1055 pout(" When the command that caused the error occurred, the device was %s.\n\n",msgstate
);
1056 pout(" After command completion occurred, registers were:\n"
1057 " ER ST SC SN CL CH DH\n"
1058 " -- -- -- -- -- -- --\n"
1059 " %02x %02x %02x %02x %02x %02x %02x",
1060 (int)summary
->error_register
,
1061 (int)summary
->status
,
1062 (int)summary
->sector_count
,
1063 (int)summary
->sector_number
,
1064 (int)summary
->cylinder_low
,
1065 (int)summary
->cylinder_high
,
1066 (int)summary
->drive_head
);
1067 // Add a description of the contents of the status and error registers
1069 st_er_desc
= construct_st_er_desc(elog
);
1071 pout(" %s", st_er_desc
);
1075 pout(" Commands leading to the command that caused the error were:\n"
1076 " CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name\n"
1077 " -- -- -- -- -- -- -- -- ---------------- --------------------\n");
1078 for ( j
= 4; j
>= 0; j
--){
1079 struct ata_smart_errorlog_command_struct
*thiscommand
=elog
->commands
+j
;
1081 // Spec says: unused data command structures shall be zero filled
1082 if (nonempty((unsigned char*)thiscommand
,sizeof(*thiscommand
))) {
1083 char timestring
[32];
1085 // Convert integer milliseconds to a text-format string
1086 MsecToText(thiscommand
->timestamp
, timestring
);
1088 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1089 (int)thiscommand
->commandreg
,
1090 (int)thiscommand
->featuresreg
,
1091 (int)thiscommand
->sector_count
,
1092 (int)thiscommand
->sector_number
,
1093 (int)thiscommand
->cylinder_low
,
1094 (int)thiscommand
->cylinder_high
,
1095 (int)thiscommand
->drive_head
,
1096 (int)thiscommand
->devicecontrolreg
,
1098 look_up_ata_command(thiscommand
->commandreg
, thiscommand
->featuresreg
));
1105 if (con
->printing_switchable
)
1108 return data
->ata_error_count
;
1111 void ataPrintSelectiveSelfTestLog(struct ata_selective_self_test_log
*log
, struct ata_smart_values
*sv
) {
1112 int i
,field1
,field2
;
1115 uint64_t maxl
=0,maxr
=0;
1116 uint64_t current
=log
->currentlba
;
1117 uint64_t currentend
=current
+65535;
1119 // print data structure revision number
1120 pout("SMART Selective self-test log data structure revision number %d\n",(int)log
->logversion
);
1121 if (1 != log
->logversion
)
1122 pout("Warning: ATA Specification requires selective self-test log data structure revision number = 1\n");
1124 switch((sv
->self_test_exec_status
)>>4){
1125 case 0:msg
="Completed";
1127 case 1:msg
="Aborted_by_host";
1129 case 2:msg
="Interrupted";
1131 case 3:msg
="Fatal_error";
1133 case 4:msg
="Completed_unknown_failure";
1135 case 5:msg
="Completed_electrical_failure";
1137 case 6:msg
="Completed_servo/seek_failure";
1139 case 7:msg
="Completed_read_failure";
1141 case 8:msg
="Completed_handling_damage??";
1143 case 15:msg
="Self_test_in_progress";
1145 default:msg
="Unknown_status ";
1149 // find the number of columns needed for printing. If in use, the
1150 // start/end of span being read-scanned...
1151 if (log
->currentspan
>5) {
1155 for (i
=0; i
<5; i
++) {
1156 uint64_t start
=log
->span
[i
].start
;
1157 uint64_t end
=log
->span
[i
].end
;
1158 // ... plus max start/end of each of the five test spans.
1165 // we need at least 7 characters wide fields to accomodate the
1167 if ((field1
=snprintf(tmp
,64, "%"PRIu64
, maxl
))<7)
1169 if ((field2
=snprintf(tmp
,64, "%"PRIu64
, maxr
))<7)
1172 // now print the five test spans
1173 pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1
, "MIN_LBA", field2
, "MAX_LBA");
1175 for (i
=0; i
<5; i
++) {
1176 uint64_t start
=log
->span
[i
].start
;
1177 uint64_t end
=log
->span
[i
].end
;
1179 if ((i
+1)==(int)log
->currentspan
)
1180 // this span is currently under test
1181 pout(" %d %*"PRIu64
" %*"PRIu64
" %s [%01d0%% left] (%"PRIu64
"-%"PRIu64
")\n",
1182 i
+1, field1
, start
, field2
, end
, msg
,
1183 (int)(sv
->self_test_exec_status
& 0xf), current
, currentend
);
1185 // this span is not currently under test
1186 pout(" %d %*"PRIu64
" %*"PRIu64
" Not_testing\n",
1187 i
+1, field1
, start
, field2
, end
);
1190 // if we are currently read-scanning, print LBAs and the status of
1192 if (log
->currentspan
>5)
1193 pout("%5d %*"PRIu64
" %*"PRIu64
" Read_scanning %s\n",
1194 (int)log
->currentspan
, field1
, current
, field2
, currentend
,
1195 OfflineDataCollectionStatus(sv
->offline_data_collection_status
));
1197 /* Print selective self-test flags. Possible flag combinations are
1198 (numbering bits from 0-15):
1202 1 0 0 Will carry out scan after selective test
1203 1 1 0 Waiting to carry out scan after powerup
1204 1 0 1 Currently scanning
1205 1 1 1 Currently scanning
1208 pout("Selective self-test flags (0x%x):\n", (unsigned int)log
->flags
);
1209 if (log
->flags
& SELECTIVE_FLAG_DOSCAN
) {
1210 if (log
->flags
& SELECTIVE_FLAG_ACTIVE
)
1211 pout(" Currently read-scanning the remainder of the disk.\n");
1212 else if (log
->flags
& SELECTIVE_FLAG_PENDING
)
1213 pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
1214 (int)log
->pendingtime
);
1216 pout(" After scanning selected spans, read-scan remainder of disk.\n");
1219 pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
1221 // print pending time
1222 pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
1223 (int)log
->pendingtime
);
1229 // bottom 8 bits: number of entries found where self-test showed an error
1230 // remaining bits: if nonzero, power on hours of last self-test where error was found
1231 int ataPrintSmartSelfTestlog(struct ata_smart_selftestlog
*data
,int allentries
){
1232 int i
,j
,noheaderprinted
=1;
1233 int retval
=0, hours
=0, testno
=0;
1236 pout("SMART Self-test log structure revision number %d\n",(int)data
->revnumber
);
1237 if ((data
->revnumber
!=0x0001) && allentries
&& con
->fixfirmwarebug
!= FIX_SAMSUNG
)
1238 pout("Warning: ATA Specification requires self-test log structure revision number = 1\n");
1239 if (data
->mostrecenttest
==0){
1241 pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
1246 for (i
=20;i
>=0;i
--){
1247 struct ata_smart_selftestlog_struct
*log
;
1249 // log is a circular buffer
1250 j
=(i
+data
->mostrecenttest
)%21;
1251 log
=data
->selftest_struct
+j
;
1253 if (nonempty((unsigned char*)log
,sizeof(*log
))){
1254 char *msgtest
,*msgstat
,percent
[64],firstlba
[64];
1257 // count entry based on non-empty structures -- needed for
1258 // Seagate only -- other vendors don't have blank entries 'in
1263 switch(log
->selftestnumber
){
1264 case 0: msgtest
="Offline "; break;
1265 case 1: msgtest
="Short offline "; break;
1266 case 2: msgtest
="Extended offline "; break;
1267 case 3: msgtest
="Conveyance offline "; break;
1268 case 4: msgtest
="Selective offline "; break;
1269 case 127: msgtest
="Abort offline test "; break;
1270 case 129: msgtest
="Short captive "; break;
1271 case 130: msgtest
="Extended captive "; break;
1272 case 131: msgtest
="Conveyance captive "; break;
1273 case 132: msgtest
="Selective captive "; break;
1275 if ( log
->selftestnumber
>=192 ||
1276 (log
->selftestnumber
>= 64 && log
->selftestnumber
<=126))
1277 msgtest
="Vendor offline ";
1279 msgtest
="Reserved offline ";
1283 switch((log
->selfteststatus
)>>4){
1284 case 0:msgstat
="Completed without error "; break;
1285 case 1:msgstat
="Aborted by host "; break;
1286 case 2:msgstat
="Interrupted (host reset) "; break;
1287 case 3:msgstat
="Fatal or unknown error "; errorfound
=1; break;
1288 case 4:msgstat
="Completed: unknown failure "; errorfound
=1; break;
1289 case 5:msgstat
="Completed: electrical failure"; errorfound
=1; break;
1290 case 6:msgstat
="Completed: servo/seek failure"; errorfound
=1; break;
1291 case 7:msgstat
="Completed: read failure "; errorfound
=1; break;
1292 case 8:msgstat
="Completed: handling damage?? "; errorfound
=1; break;
1293 case 15:msgstat
="Self-test routine in progress"; break;
1294 default:msgstat
="Unknown/reserved test status ";
1298 sprintf(percent
,"%1d0%%",(log
->selfteststatus
)&0xf);
1300 // T13/1321D revision 1c: (Data structure Rev #1)
1302 //The failing LBA shall be the LBA of the uncorrectable sector
1303 //that caused the test to fail. If the device encountered more
1304 //than one uncorrectable sector during the test, this field
1305 //shall indicate the LBA of the first uncorrectable sector
1306 //encountered. If the test passed or the test failed for some
1307 //reason other than an uncorrectable sector, the value of this
1308 //field is undefined.
1310 // This is true in ALL ATA-5 specs
1312 if (!errorfound
|| log
->lbafirstfailure
==0xffffffff || log
->lbafirstfailure
==0x00000000)
1313 sprintf(firstlba
,"%s","-");
1315 sprintf(firstlba
,"%u",log
->lbafirstfailure
);
1317 // print out a header if needed
1318 if (noheaderprinted
&& (allentries
|| errorfound
)){
1319 pout("Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error\n");
1323 // print out an entry, either if we are printing all entries OR
1324 // if an error was found
1325 if (allentries
|| errorfound
)
1326 pout("#%2d %s %s %s %8d %s\n", testno
, msgtest
, msgstat
, percent
, (int)log
->timestamp
, firstlba
);
1328 // keep track of time of most recent error
1329 if (errorfound
&& !hours
)
1330 hours
=log
->timestamp
;
1333 if (!allentries
&& retval
)
1337 return (retval
| hours
);
1340 void ataPseudoCheckSmart ( struct ata_smart_values
*data
,
1341 struct ata_smart_thresholds_pvt
*thresholds
) {
1344 for (i
= 0 ; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
1345 if (data
->vendor_attributes
[i
].id
&&
1346 thresholds
->thres_entries
[i
].id
&&
1347 ATTRIBUTE_FLAGS_PREFAILURE(data
->vendor_attributes
[i
].flags
) &&
1348 (data
->vendor_attributes
[i
].current
<= thresholds
->thres_entries
[i
].threshold
) &&
1349 (thresholds
->thres_entries
[i
].threshold
!= 0xFE)){
1350 pout("Attribute ID %d Failed\n",(int)data
->vendor_attributes
[i
].id
);
1354 pout("%s\n", ( failed
)?
1355 "SMART overall-health self-assessment test result: FAILED!\n"
1356 "Drive failure expected in less than 24 hours. SAVE ALL DATA":
1357 "SMART overall-health self-assessment test result: PASSED");
1361 // Compares failure type to policy in effect, and either exits or
1362 // simply returns to the calling routine.
1363 void failuretest(int type
, int returnvalue
){
1365 // If this is an error in an "optional" SMART command
1366 if (type
==OPTIONAL_CMD
){
1367 if (con
->conservative
){
1368 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1374 // If this is an error in a "mandatory" SMART command
1375 if (type
==MANDATORY_CMD
){
1376 if (con
->permissive
--)
1378 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1382 pout("Smartctl internal error in failuretest(type=%d). Please contact developers at " PACKAGE_HOMEPAGE
"\n",type
);
1383 EXIT(returnvalue
|FAILCMD
);
1386 // Used to warn users about invalid checksums. Action to be taken may be
1387 // altered by the user.
1388 void checksumwarning(const char *string
){
1389 // user has asked us to ignore checksum errors
1390 if (con
->checksumignore
)
1393 pout("Warning! %s error: invalid SMART checksum.\n",string
);
1395 // user has asked us to fail on checksum errors
1396 if (con
->checksumfail
)
1402 // Initialize to zero just in case some SMART routines don't work
1403 struct ata_identify_device drive
;
1404 struct ata_smart_values smartval
;
1405 struct ata_smart_thresholds_pvt smartthres
;
1406 struct ata_smart_errorlog smarterror
;
1407 struct ata_smart_selftestlog smartselftest
;
1409 int ataPrintMain (int fd
){
1411 int returnval
=0, retid
=0, supported
=0, needupdate
=0, known
=0;
1412 const char * powername
= 0; char powerchg
= 0;
1414 // If requested, check power mode first
1415 if (con
->powermode
) {
1416 unsigned char powerlimit
= 0xff;
1417 int powermode
= ataCheckPowerMode(fd
);
1418 switch (powermode
) {
1420 if (errno
== ENOSYS
) {
1421 pout("CHECK POWER STATUS not implemented, ignoring -n Option\n"); break;
1423 powername
= "SLEEP"; powerlimit
= 2;
1426 powername
= "STANDBY"; powerlimit
= 3; break;
1428 powername
= "IDLE"; powerlimit
= 4; break;
1430 powername
= "ACTIVE or IDLE"; break;
1432 pout("CHECK POWER STATUS returned %d, not ATA compliant, ignoring -n Option\n", powermode
);
1436 if (con
->powermode
>= powerlimit
) {
1437 pout("Device is in %s mode, exit(%d)\n", powername
, FAILPOWER
);
1440 powerchg
= (powermode
!= 0xff); // SMART tests will spin up drives
1444 // Start by getting Drive ID information. We need this, to know if SMART is supported.
1445 if ((retid
=ataReadHDIdentity(fd
,&drive
))<0){
1446 pout("Smartctl: Device Read Identity Failed (not an ATA/ATAPI device)\n\n");
1447 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
1450 // If requested, show which presets would be used for this drive and exit.
1451 if (con
->showpresets
) {
1452 showpresets(&drive
);
1456 // Use preset vendor attribute options unless user has requested otherwise.
1457 if (!con
->ignorepresets
){
1458 unsigned char *charptr
;
1459 if ((charptr
=con
->attributedefs
))
1460 applypresets(&drive
, &charptr
, con
);
1462 pout("Fatal internal error in ataPrintMain()\n");
1463 EXIT(returnval
|=FAILCMD
);
1467 // Print most drive identity information if requested
1468 if (con
->driveinfo
){
1469 pout("=== START OF INFORMATION SECTION ===\n");
1470 known
= ataPrintDriveInfo(&drive
);
1473 // Was this a packet device?
1475 pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n", packetdevicetype(retid
-1));
1476 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1479 // if drive does not supports SMART it's time to exit
1480 supported
=ataSmartSupport(&drive
);
1481 if (supported
!= 1){
1483 pout("SMART support is: Unavailable - device lacks SMART capability.\n");
1484 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1485 pout(" Checking to be sure by trying SMART ENABLE command.\n");
1488 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
1489 if (!known
) failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1490 pout(" Checking for SMART support by trying SMART ENABLE command.\n");
1493 if (ataEnableSmart(fd
)){
1494 pout(" SMART ENABLE failed - this establishes that this device lacks SMART functionality.\n");
1495 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1499 pout(" SMART ENABLE appeared to work! Continuing.\n");
1502 if (!con
->driveinfo
) pout("\n");
1505 // Now print remaining drive info: is SMART enabled?
1506 if (con
->driveinfo
){
1507 int ison
=ataIsSmartEnabled(&drive
),isenabled
=ison
;
1510 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
1511 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1512 // check SMART support by trying a command
1513 pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
1514 isenabled
=ataDoesSmartWork(fd
);
1517 pout("SMART support is: Available - device has SMART capability.\n");
1518 #ifdef HAVE_ATA_IDENTIFY_IS_CACHED
1519 if (ata_identify_is_cached(fd
)) {
1520 pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
1521 (isenabled
?"En":"Dis"));
1522 isenabled
=ataDoesSmartWork(fd
);
1528 pout("SMART support is: Enabled\n");
1531 pout("SMART support is: Unavailable\n");
1533 pout("SMART support is: Disabled\n");
1535 // Print the (now possibly changed) power mode if available
1537 pout("Power mode %s %s\n", (powerchg
?"was:":"is: "), powername
);
1541 // START OF THE ENABLE/DISABLE SECTION OF THE CODE
1542 if (con
->smartenable
|| con
->smartdisable
||
1543 con
->smartautosaveenable
|| con
->smartautosavedisable
||
1544 con
->smartautoofflineenable
|| con
->smartautoofflinedisable
)
1545 pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
1547 // Enable/Disable SMART commands
1548 if (con
->smartenable
){
1549 if (ataEnableSmart(fd
)) {
1550 pout("Smartctl: SMART Enable Failed.\n\n");
1551 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1554 pout("SMART Enabled.\n");
1557 // From here on, every command requires that SMART be enabled...
1558 if (!ataDoesSmartWork(fd
)) {
1559 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1563 // Turn off SMART on device
1564 if (con
->smartdisable
){
1565 if (ataDisableSmart(fd
)) {
1566 pout( "Smartctl: SMART Disable Failed.\n\n");
1567 failuretest(MANDATORY_CMD
,returnval
|=FAILSMART
);
1569 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1573 // Let's ALWAYS issue this command to get the SMART status
1574 code
=ataSmartStatus2(fd
);
1576 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1578 // Enable/Disable Auto-save attributes
1579 if (con
->smartautosaveenable
){
1580 if (ataEnableAutoSave(fd
)){
1581 pout( "Smartctl: SMART Enable Attribute Autosave Failed.\n\n");
1582 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1585 pout("SMART Attribute Autosave Enabled.\n");
1587 if (con
->smartautosavedisable
){
1588 if (ataDisableAutoSave(fd
)){
1589 pout( "Smartctl: SMART Disable Attribute Autosave Failed.\n\n");
1590 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1593 pout("SMART Attribute Autosave Disabled.\n");
1596 // for everything else read values and thresholds are needed
1597 if (ataReadSmartValues(fd
, &smartval
)){
1598 pout("Smartctl: SMART Read Values failed.\n\n");
1599 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1601 if (ataReadSmartThresholds(fd
, &smartthres
)){
1602 pout("Smartctl: SMART Read Thresholds failed.\n\n");
1603 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1606 // Enable/Disable Off-line testing
1607 if (con
->smartautoofflineenable
){
1608 if (!isSupportAutomaticTimer(&smartval
)){
1609 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1610 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1613 if (ataEnableAutoOffline(fd
)){
1614 pout( "Smartctl: SMART Enable Automatic Offline Failed.\n\n");
1615 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1618 pout("SMART Automatic Offline Testing Enabled every four hours.\n");
1620 if (con
->smartautoofflinedisable
){
1621 if (!isSupportAutomaticTimer(&smartval
)){
1622 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1623 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1626 if (ataDisableAutoOffline(fd
)){
1627 pout("Smartctl: SMART Disable Automatic Offline Failed.\n\n");
1628 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1631 pout("SMART Automatic Offline Testing Disabled.\n");
1634 if (needupdate
&& ataReadSmartValues(fd
, &smartval
)){
1635 pout("Smartctl: SMART Read Values failed.\n\n");
1636 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1639 // all this for a newline!
1640 if (con
->smartenable
|| con
->smartdisable
||
1641 con
->smartautosaveenable
|| con
->smartautosavedisable
||
1642 con
->smartautoofflineenable
|| con
->smartautoofflinedisable
)
1645 // START OF READ-ONLY OPTIONS APART FROM -V and -i
1646 if (con
->checksmart
|| con
->generalsmartvalues
|| con
->smartvendorattrib
|| con
->smarterrorlog
|| con
->smartselftestlog
)
1647 pout("=== START OF READ SMART DATA SECTION ===\n");
1649 // Check SMART status (use previously returned value)
1650 if (con
->checksmart
){
1654 // The case where the disk health is OK
1655 pout("SMART overall-health self-assessment test result: PASSED\n");
1656 if (ataCheckSmart(&smartval
, &smartthres
,0)){
1657 if (con
->smartvendorattrib
)
1658 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1661 pout("Please note the following marginal Attributes:\n");
1662 PrintSmartAttribWithThres(&smartval
, &smartthres
,2);
1671 // The case where the disk health is NOT OK
1673 pout("SMART overall-health self-assessment test result: FAILED!\n"
1674 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1676 if (ataCheckSmart(&smartval
, &smartthres
,1)){
1677 returnval
|=FAILATTR
;
1678 if (con
->smartvendorattrib
)
1679 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1682 pout("Failed Attributes:\n");
1683 PrintSmartAttribWithThres(&smartval
, &smartthres
,1);
1687 pout("No failed Attributes found.\n\n");
1688 returnval
|=FAILSTATUS
;
1694 // The case where something went wrong with HDIO_DRIVE_TASK ioctl()
1695 if (ataCheckSmart(&smartval
, &smartthres
,1)){
1697 pout("SMART overall-health self-assessment test result: FAILED!\n"
1698 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1700 returnval
|=FAILATTR
;
1701 returnval
|=FAILSTATUS
;
1702 if (con
->smartvendorattrib
)
1703 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1706 pout("Failed Attributes:\n");
1707 PrintSmartAttribWithThres(&smartval
, &smartthres
,1);
1711 pout("SMART overall-health self-assessment test result: PASSED\n");
1712 if (ataCheckSmart(&smartval
, &smartthres
,0)){
1713 if (con
->smartvendorattrib
)
1714 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1717 pout("Please note the following marginal Attributes:\n");
1718 PrintSmartAttribWithThres(&smartval
, &smartthres
,2);
1727 } // end of switch statement
1730 } // end of checking SMART Status
1732 // Print general SMART values
1733 if (con
->generalsmartvalues
)
1734 ataPrintGeneralSmartValues(&smartval
, &drive
);
1736 // Print vendor-specific attributes
1737 if (con
->smartvendorattrib
){
1739 PrintSmartAttribWithThres(&smartval
, &smartthres
,con
->printing_switchable
?2:0);
1743 // Print SMART log Directory
1744 if (con
->smartlogdirectory
){
1745 struct ata_smart_log_directory smartlogdirectory
;
1746 if (!isGeneralPurposeLoggingCapable(&drive
)){
1747 pout("Warning: device does not support General Purpose Logging\n");
1748 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1752 pout("Log Directory Supported\n");
1753 if (ataReadLogDirectory(fd
, &smartlogdirectory
)){
1755 pout("Read Log Directory failed.\n\n");
1756 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1759 ataPrintLogDirectory( &smartlogdirectory
);
1764 // Print SMART error log
1765 if (con
->smarterrorlog
){
1766 if (!isSmartErrorLogCapable(&smartval
, &drive
)){
1767 pout("Warning: device does not support Error Logging\n");
1768 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1770 if (ataReadErrorLog(fd
, &smarterror
)){
1771 pout("Smartctl: SMART Error Log Read Failed\n");
1772 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1775 // quiet mode is turned on inside ataPrintSmartErrorLog()
1776 if (ataPrintSmartErrorlog(&smarterror
))
1782 // Print SMART self-test log
1783 if (con
->smartselftestlog
){
1784 if (!isSmartTestLogCapable(&smartval
, &drive
)){
1785 pout("Warning: device does not support Self Test Logging\n");
1786 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1788 if(ataReadSelfTestLog(fd
, &smartselftest
)){
1789 pout("Smartctl: SMART Self Test Log Read Failed\n");
1790 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1794 if (ataPrintSmartSelfTestlog(&smartselftest
,!con
->printing_switchable
))
1801 // Print SMART selective self-test log
1802 if (con
->selectivetestlog
){
1803 struct ata_selective_self_test_log log
;
1805 if (!isSupportSelectiveSelfTest(&smartval
))
1806 pout("Device does not support Selective Self Tests/Logging\n");
1807 else if(ataReadSelectiveSelfTestLog(fd
, &log
)) {
1808 pout("Smartctl: SMART Selective Self Test Log Read Failed\n");
1809 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1813 ataPrintSelectiveSelfTestLog(&log
, &smartval
);
1819 // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
1820 if (con
->testcase
==-1)
1823 pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
1824 // if doing a self-test, be sure it's supported by the hardware
1825 switch (con
->testcase
){
1826 case OFFLINE_FULL_SCAN
:
1827 if (!isSupportExecuteOfflineImmediate(&smartval
)){
1828 pout("Warning: device does not support Execute Offline Immediate function.\n\n");
1829 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1832 case ABORT_SELF_TEST
:
1833 case SHORT_SELF_TEST
:
1834 case EXTEND_SELF_TEST
:
1835 case SHORT_CAPTIVE_SELF_TEST
:
1836 case EXTEND_CAPTIVE_SELF_TEST
:
1837 if (!isSupportSelfTest(&smartval
)){
1838 pout("Warning: device does not support Self-Test functions.\n\n");
1839 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1842 case CONVEYANCE_SELF_TEST
:
1843 case CONVEYANCE_CAPTIVE_SELF_TEST
:
1844 if (!isSupportConveyanceSelfTest(&smartval
)){
1845 pout("Warning: device does not support Conveyance Self-Test functions.\n\n");
1846 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1849 case SELECTIVE_SELF_TEST
:
1850 case SELECTIVE_CAPTIVE_SELF_TEST
:
1851 if (!isSupportSelectiveSelfTest(&smartval
)){
1852 pout("Warning: device does not support Selective Self-Test functions.\n\n");
1853 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1857 pout("Internal error in smartctl: con->testcase==%d not recognized\n", (int)con
->testcase
);
1858 pout("Please contact smartmontools developers at %s.\n", PACKAGE_BUGREPORT
);
1859 EXIT(returnval
|=FAILCMD
);
1862 // Now do the test. Note ataSmartTest prints its own error/success
1864 if (ataSmartTest(fd
, con
->testcase
, &smartval
))
1865 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1867 // Tell user how long test will take to complete. This is tricky
1868 // because in the case of an Offline Full Scan, the completion
1869 // timer is volatile, and needs to be read AFTER the command is
1870 // given. If this will interrupt the Offline Full Scan, we don't
1871 // do it, just warn user.
1872 if (con
->testcase
==OFFLINE_FULL_SCAN
){
1873 if (isSupportOfflineAbort(&smartval
))
1874 pout("Note: giving further SMART commands will abort Offline testing\n");
1875 else if (ataReadSmartValues(fd
, &smartval
)){
1876 pout("Smartctl: SMART Read Values failed.\n");
1877 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1881 // Now say how long the test will take to complete
1882 if ((timewait
=TestTime(&smartval
,con
->testcase
))){
1883 time_t t
=time(NULL
);
1884 if (con
->testcase
==OFFLINE_FULL_SCAN
) {
1886 pout("Please wait %d seconds for test to complete.\n", (int)timewait
);
1889 pout("Please wait %d minutes for test to complete.\n", (int)timewait
);
1891 pout("Test will complete after %s\n", ctime(&t
));
1893 if (con
->testcase
!=SHORT_CAPTIVE_SELF_TEST
&&
1894 con
->testcase
!=EXTEND_CAPTIVE_SELF_TEST
&&
1895 con
->testcase
!=CONVEYANCE_CAPTIVE_SELF_TEST
&&
1896 con
->testcase
!=SELECTIVE_CAPTIVE_SELF_TEST
)
1897 pout("Use smartctl -X to abort test.\n");