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/
32 #endif // #ifdef HAVE_LOCALE_H
35 #include "atacmdnames.h"
41 #include "knowndrives.h"
43 const char *ataprint_c_cvsid
="$Id: ataprint.c,v 1.164 2006/04/12 14:54:28 ballen4705 Exp $"
44 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
;
46 // for passing global control variables
47 extern smartmonctrl
*con
;
49 // to hold onto exit code for atexit routine
50 extern int exitstatus
;
52 // Copies n bytes (or n-1 if n is odd) from in to out, but swaps adjacents
54 void swapbytes(char *out
, const char *in
, size_t n
)
58 for (i
= 0; i
< n
; i
+= 2) {
64 // Copies in to out, but removes leading and trailing whitespace.
65 void trim(char *out
, const char *in
)
69 // Find the first non-space character (maybe none).
71 for (i
= 0; in
[i
]; i
++)
72 if (!isspace((int)in
[i
])) {
78 // There are no non-space characters.
83 // Find the last non-space character.
84 for (i
= strlen(in
)-1; i
>= first
&& isspace((int)in
[i
]); i
--)
88 strncpy(out
, in
+first
, last
-first
+1);
89 out
[last
-first
+1] = '\0';
92 // Convenience function for formatting strings from ata_identify_device
93 void formatdriveidstring(char *out
, const char *in
, int n
)
99 swapbytes(tmp
, in
, n
);
101 strncpy(tmp
, in
, n
); /* NetBSD delivers host byte order strings */
107 void infofound(char *output
) {
109 pout("%s\n", output
);
111 pout("[No Information Found]\n");
115 /* For the given Command Register (CR) and Features Register (FR), attempts
116 * to construct a string that describes the contents of the Status
117 * Register (ST) and Error Register (ER). The string is dynamically allocated
118 * memory and the return value is a pointer to this string. It is up to the
119 * caller to free this memory. If there is insufficient memory or if the
120 * meanings of the flags of the error register are not known for the given
121 * command then it returns NULL.
123 * The meanings of the flags of the error register for all commands are
124 * described in the ATA spec and could all be supported here in theory.
125 * Currently, only a few commands are supported (those that have been seen
126 * to produce errors). If many more are to be added then this function
127 * should probably be redesigned.
129 char *construct_st_er_desc(struct ata_smart_errorlog_struct
*data
) {
130 unsigned char CR
=data
->commands
[4].commandreg
;
131 unsigned char FR
=data
->commands
[4].featuresreg
;
132 unsigned char ST
=data
->error_struct
.status
;
133 unsigned char ER
=data
->error_struct
.error_register
;
135 const char *error_flag
[8];
136 int i
, print_lba
=0, print_sector
=0;
138 // Set of character strings corresponding to different error codes.
139 // Please keep in alphabetic order if you add more.
140 const char *abrt
= "ABRT"; // ABORTED
141 const char *amnf
= "AMNF"; // ADDRESS MARK NOT FOUND
142 const char *ccto
= "CCTO"; // COMMAND COMPLETTION TIMED OUT
143 const char *eom
= "EOM"; // END OF MEDIA
144 const char *icrc
= "ICRC"; // INTERFACE CRC ERROR
145 const char *idnf
= "IDNF"; // ID NOT FOUND
146 const char *ili
= "ILI"; // MEANING OF THIS BIT IS COMMAND-SET SPECIFIC
147 const char *mc
= "MC"; // MEDIA CHANGED
148 const char *mcr
= "MCR"; // MEDIA CHANGE REQUEST
149 const char *nm
= "NM"; // NO MEDIA
150 const char *obs
= "obs"; // OBSOLETE
151 const char *tk0nf
= "TK0NF"; // TRACK 0 NOT FOUND
152 const char *unc
= "UNC"; // UNCORRECTABLE
153 const char *wp
= "WP"; // WRITE PROTECTED
155 /* If for any command the Device Fault flag of the status register is
156 * not used then used_device_fault should be set to 0 (in the CR switch
159 int uses_device_fault
= 1;
161 /* A value of NULL means that the error flag isn't used */
162 for (i
= 0; i
< 8; i
++)
163 error_flag
[i
] = NULL
;
166 case 0x10: // RECALIBRATE
167 error_flag
[2] = abrt
;
168 error_flag
[1] = tk0nf
;
170 case 0x20: /* READ SECTOR(S) */
171 case 0x21: // READ SECTOR(S)
172 case 0x24: // READ SECTOR(S) EXT
173 case 0xC4: /* READ MULTIPLE */
174 case 0x29: // READ MULTIPLE EXT
177 error_flag
[4] = idnf
;
179 error_flag
[2] = abrt
;
181 error_flag
[0] = amnf
;
184 case 0x22: // READ LONG (with retries)
185 case 0x23: // READ LONG (without retries)
186 error_flag
[4] = idnf
;
187 error_flag
[2] = abrt
;
188 error_flag
[0] = amnf
;
191 case 0x2a: // READ STREAM DMA
192 case 0x2b: // READ STREAM PIO
194 error_flag
[7] = icrc
;
197 error_flag
[4] = idnf
;
199 error_flag
[2] = abrt
;
201 error_flag
[0] = ccto
;
203 print_sector
=(int)data
->error_struct
.sector_count
;
205 case 0x3A: // WRITE STREAM DMA
206 case 0x3B: // WRITE STREAM PIO
208 error_flag
[7] = icrc
;
211 error_flag
[4] = idnf
;
213 error_flag
[2] = abrt
;
215 error_flag
[0] = ccto
;
217 print_sector
=(int)data
->error_struct
.sector_count
;
219 case 0x25: /* READ DMA EXT */
220 case 0x26: // READ DMA QUEUED EXT
221 case 0xC7: // READ DMA QUEUED
222 case 0xC8: /* READ DMA */
224 error_flag
[7] = icrc
;
227 error_flag
[4] = idnf
;
229 error_flag
[2] = abrt
;
231 error_flag
[0] = amnf
;
233 if (CR
==0x25 || CR
==0xC8)
234 print_sector
=(int)data
->error_struct
.sector_count
;
236 case 0x30: /* WRITE SECTOR(S) */
237 case 0x31: // WRITE SECTOR(S)
238 case 0x34: // WRITE SECTOR(S) EXT
239 case 0xC5: /* WRITE MULTIPLE */
240 case 0x39: // WRITE MULTIPLE EXT
241 case 0xCE: // WRITE MULTIPLE FUA EXT
244 error_flag
[4] = idnf
;
246 error_flag
[2] = abrt
;
250 case 0x32: // WRITE LONG (with retries)
251 case 0x33: // WRITE LONG (without retries)
252 error_flag
[4] = idnf
;
253 error_flag
[2] = abrt
;
256 case 0x3C: // WRITE VERIFY
258 error_flag
[4] = idnf
;
259 error_flag
[2] = abrt
;
260 error_flag
[0] = amnf
;
263 case 0x40: // READ VERIFY SECTOR(S) with retries
264 case 0x41: // READ VERIFY SECTOR(S) without retries
265 case 0x42: // READ VERIFY SECTOR(S) EXT
268 error_flag
[4] = idnf
;
270 error_flag
[2] = abrt
;
272 error_flag
[0] = amnf
;
275 case 0xA0: /* PACKET */
276 /* Bits 4-7 are all used for sense key (a 'command packet set specific error
277 * indication' according to the ATA/ATAPI-7 standard), so "Sense key" will
278 * be repeated in the error description string if more than one of those
281 error_flag
[7] = "Sense key (bit 3)",
282 error_flag
[6] = "Sense key (bit 2)",
283 error_flag
[5] = "Sense key (bit 1)",
284 error_flag
[4] = "Sense key (bit 0)",
285 error_flag
[2] = abrt
;
289 case 0xA1: /* IDENTIFY PACKET DEVICE */
290 case 0xEF: /* SET FEATURES */
292 case 0xC6: /* SET MULTIPLE MODE */
293 error_flag
[2] = abrt
;
295 case 0x2F: // READ LOG EXT
297 error_flag
[4] = idnf
;
298 error_flag
[2] = abrt
;
301 case 0x3F: // WRITE LOG EXT
302 error_flag
[4] = idnf
;
303 error_flag
[2] = abrt
;
306 case 0xB0: /* SMART */
308 case 0xD0: // SMART READ DATA
309 case 0xD1: // SMART READ ATTRIBUTE THRESHOLDS
310 case 0xD5: /* SMART READ LOG */
312 error_flag
[4] = idnf
;
313 error_flag
[2] = abrt
;
316 case 0xD6: /* SMART WRITE LOG */
317 error_flag
[4] = idnf
;
318 error_flag
[2] = abrt
;
321 case 0xD2: // Enable/Disable Attribute Autosave
322 case 0xD3: // SMART SAVE ATTRIBUTE VALUES (ATA-3)
323 case 0xD8: // SMART ENABLE OPERATIONS
324 case 0xD9: /* SMART DISABLE OPERATIONS */
325 case 0xDA: /* SMART RETURN STATUS */
326 case 0xDB: // Enable/Disable Auto Offline (SFF)
327 error_flag
[2] = abrt
;
329 case 0xD4: // SMART EXECUTE IMMEDIATE OFFLINE
330 error_flag
[4] = idnf
;
331 error_flag
[2] = abrt
;
338 case 0xB1: /* DEVICE CONFIGURATION */
340 case 0xC0: /* DEVICE CONFIGURATION RESTORE */
341 error_flag
[2] = abrt
;
348 case 0xCA: /* WRITE DMA */
350 case 0x35: // WRITE DMA EXT
351 case 0x3D: // WRITE DMA FUA EXT
352 case 0xCC: // WRITE DMA QUEUED
353 case 0x36: // WRITE DMA QUEUED EXT
354 case 0x3E: // WRITE DMA QUEUED FUA EXT
355 error_flag
[7] = icrc
;
358 error_flag
[4] = idnf
;
360 error_flag
[2] = abrt
;
362 error_flag
[0] = amnf
;
365 print_sector
=(int)data
->error_struct
.sector_count
;
367 case 0xE4: // READ BUFFER
368 case 0xE8: // WRITE BUFFER
369 error_flag
[2] = abrt
;
375 /* 256 bytes -- that'll be plenty (OK, this is lazy!) */
376 if (!(s
= (char *)malloc(256)))
381 /* We ignore any status flags other than Device Fault and Error */
383 if (uses_device_fault
&& (ST
& (1 << 5))) {
384 strcat(s
, "Device Fault");
385 if (ST
& 1) // Error flag
388 if (ST
& 1) { // Error flag
391 strcat(s
, "Error: ");
392 for (i
= 7; i
>= 0; i
--)
393 if ((ER
& (1 << i
)) && (error_flag
[i
])) {
396 strcat(s
, error_flag
[i
]);
400 // If the error was a READ or WRITE error, print the Logical Block
401 // Address (LBA) at which the read or write failed.
406 // bits 24-27: bits 0-3 of DH
407 lba
= 0xf & data
->error_struct
.drive_head
;
410 lba
|= data
->error_struct
.cylinder_high
;
413 lba
|= data
->error_struct
.cylinder_low
;
416 lba
|= data
->error_struct
.sector_number
;
418 // print number of sectors, if known, and append to print string
420 snprintf(tmp
, 128, " %d sectors", print_sector
);
424 // print LBA, and append to print string
425 snprintf(tmp
, 128, " at LBA = 0x%08x = %d", lba
, lba
);
432 // This returns the capacity of a disk drive and also prints this into
433 // a string, using comma separators to make it easier to read. If the
434 // drive doesn't support LBA addressing or has no user writable
435 // sectors (eg, CDROM or DVD) then routine returns zero.
436 uint64_t determine_capacity(struct ata_identify_device
*drive
, char *pstring
){
438 unsigned short command_set_2
= drive
->command_set_2
;
439 unsigned short capabilities_0
= drive
->words047_079
[49-47];
440 unsigned short sects_16
= drive
->words047_079
[60-47];
441 unsigned short sects_32
= drive
->words047_079
[61-47];
442 unsigned short lba_16
= drive
->words088_255
[100-88];
443 unsigned short lba_32
= drive
->words088_255
[101-88];
444 unsigned short lba_48
= drive
->words088_255
[102-88];
445 unsigned short lba_64
= drive
->words088_255
[103-88];
446 uint64_t capacity_short
=0, capacity
=0, threedigits
, power_of_ten
;
447 int started
=0,k
=1000000000;
450 // get correct character to use as thousands separator
452 struct lconv
*currentlocale
=NULL
;
453 setlocale (LC_ALL
, "");
454 currentlocale
=localeconv();
455 if (*(currentlocale
->thousands_sep
))
456 separator
=*(currentlocale
->thousands_sep
);
457 #endif // #ifdef HAVE_LOCALE_H
459 // if drive supports LBA addressing, determine 32-bit LBA capacity
460 if (capabilities_0
& 0x0200) {
461 capacity_short
= (unsigned int)sects_32
<< 16 |
462 (unsigned int)sects_16
<< 0 ;
464 // if drive supports 48-bit addressing, determine THAT capacity
465 if ((command_set_2
& 0xc000) == 0x4000 && (command_set_2
& 0x0400))
466 capacity
= (uint64_t)lba_64
<< 48 |
467 (uint64_t)lba_48
<< 32 |
468 (uint64_t)lba_32
<< 16 |
469 (uint64_t)lba_16
<< 0 ;
471 // choose the larger of the two possible capacities
472 if (capacity_short
>capacity
)
473 capacity
=capacity_short
;
476 // turn sectors into bytes
477 capacity_short
= (capacity
*= 512);
479 // print with locale-specific separators (default is comma)
483 for (k
=0; k
<7; k
++) {
484 threedigits
= capacity
/power_of_ten
;
485 capacity
-= threedigits
*power_of_ten
;
487 // we have already printed some digits
488 pstring
+= sprintf(pstring
, "%c%03"PRIu64
, separator
, threedigits
);
489 else if (threedigits
|| k
==6) {
490 // these are the first digits that we are printing
491 pstring
+= sprintf(pstring
, "%"PRIu64
, threedigits
);
495 power_of_ten
/= 1000;
498 return capacity_short
;
501 void ataPrintDriveInfo (struct ata_identify_device
*drive
){
502 int version
, drivetype
;
503 const char *description
;
504 char unknown
[64], timedatetz
[DATEANDEPOCHLEN
];
505 unsigned short minorrev
;
506 char model
[64], serial
[64], firm
[64], capacity
[64];
508 // format drive information (with byte swapping as needed)
509 formatdriveidstring(model
, (char *)drive
->model
,40);
510 formatdriveidstring(serial
, (char *)drive
->serial_no
,20);
511 formatdriveidstring(firm
, (char *)drive
->fw_rev
,8);
513 // print out model, serial # and firmware versions (byte-swap ASCI strings)
514 drivetype
=lookupdrive(model
, firm
);
516 // Print model family if known
517 if (drivetype
>=0 && knowndrives
[drivetype
].modelfamily
)
518 pout("Model Family: %s\n", knowndrives
[drivetype
].modelfamily
);
520 pout("Device Model: ");
522 pout("Serial Number: ");
524 pout("Firmware Version: ");
527 if (determine_capacity(drive
, capacity
))
528 pout("User Capacity: %s bytes\n", capacity
);
530 // See if drive is recognized
531 pout("Device is: %s\n", drivetype
<0?
532 "Not in smartctl database [for details use: -P showall]":
533 "In smartctl database [for details use: -P show]");
535 // now get ATA version info
536 version
=ataVersionInfo(&description
,drive
, &minorrev
);
538 // unrecognized minor revision code
541 sprintf(unknown
, "Exact ATA specification draft version not indicated");
543 sprintf(unknown
,"Not recognized. Minor revision code: 0x%02hx", minorrev
);
548 // SMART Support was first added into the ATA/ATAPI-3 Standard with
549 // Revision 3 of the document, July 25, 1995. Look at the "Document
550 // Status" revision commands at the beginning of
551 // http://www.t13.org/project/d2008r6.pdf to see this. So it's not
552 // enough to check if we are ATA-3. Version=-3 indicates ATA-3
553 // BEFORE Revision 3.
554 pout("ATA Version is: %d\n",(int)abs(version
));
555 pout("ATA Standard is: %s\n",description
);
557 // print current time and date and timezone
558 dateandtimezone(timedatetz
);
559 pout("Local Time is: %s\n", timedatetz
);
561 // Print warning message, if there is one
562 if (drivetype
>=0 && knowndrives
[drivetype
].warningmsg
)
563 pout("\n==> WARNING: %s\n\n", knowndrives
[drivetype
].warningmsg
);
568 pout("SMART is only available in ATA Version 3 Revision 3 or greater.\n");
569 pout("We will try to proceed in spite of this.\n");
574 const char *OfflineDataCollectionStatus(unsigned char status_byte
){
575 unsigned char stat
=status_byte
& 0x7f;
579 return "was never started";
581 return "was completed without error";
583 if (status_byte
== 0x03)
584 return "is in progress";
586 return "is in a Reserved state";
588 return "was suspended by an interrupting command from host";
590 return "was aborted by an interrupting command from host";
592 return "was aborted by the device with a fatal error";
595 return "is in a Vendor Specific state\n";
597 return "is in a Reserved state\n";
602 /* prints verbose value Off-line data collection status byte */
603 void PrintSmartOfflineStatus(struct ata_smart_values
*data
){
605 pout("Offline data collection status: (0x%02x)\t",
606 (int)data
->offline_data_collection_status
);
608 // Off-line data collection status byte is not a reserved
609 // or vendor specific value
610 pout("Offline data collection activity\n"
611 "\t\t\t\t\t%s.\n", OfflineDataCollectionStatus(data
->offline_data_collection_status
));
613 // Report on Automatic Data Collection Status. Only IBM documents
614 // this bit. See SFF 8035i Revision 2 for details.
615 if (data
->offline_data_collection_status
& 0x80)
616 pout("\t\t\t\t\tAuto Offline Data Collection: Enabled.\n");
618 pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
623 void PrintSmartSelfExecStatus(struct ata_smart_values
*data
)
625 pout("Self-test execution status: ");
627 switch (data
->self_test_exec_status
>> 4)
630 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
631 (int)data
->self_test_exec_status
);
632 pout("without error or no self-test has ever \n\t\t\t\t\tbeen run.\n");
635 pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
636 (int)data
->self_test_exec_status
);
640 pout("(%4d)\tThe self-test routine was interrupted\n\t\t\t\t\t",
641 (int)data
->self_test_exec_status
);
642 pout("by the host with a hard or soft reset.\n");
645 pout("(%4d)\tA fatal error or unknown test error\n\t\t\t\t\t",
646 (int)data
->self_test_exec_status
);
647 pout("occurred while the device was executing\n\t\t\t\t\t");
648 pout("its self-test routine and the device \n\t\t\t\t\t");
649 pout("was unable to complete the self-test \n\t\t\t\t\t");
653 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
654 (int)data
->self_test_exec_status
);
655 pout("a test element that failed and the test\n\t\t\t\t\t");
656 pout("element that failed is not known.\n");
659 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
660 (int)data
->self_test_exec_status
);
661 pout("the electrical element of the test\n\t\t\t\t\t");
665 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
666 (int)data
->self_test_exec_status
);
667 pout("the servo (and/or seek) element of the \n\t\t\t\t\t");
668 pout("test failed.\n");
671 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
672 (int)data
->self_test_exec_status
);
673 pout("the read element of the test failed.\n");
676 pout("(%4d)\tSelf-test routine in progress...\n\t\t\t\t\t",
677 (int)data
->self_test_exec_status
);
678 pout("%1d0%% of test remaining.\n",
679 (int)(data
->self_test_exec_status
& 0x0f));
682 pout("(%4d)\tReserved.\n",
683 (int)data
->self_test_exec_status
);
691 void PrintSmartTotalTimeCompleteOffline ( struct ata_smart_values
*data
){
692 pout("Total time to complete Offline \n");
693 pout("data collection: \t\t (%4d) seconds.\n",
694 (int)data
->total_time_to_complete_off_line
);
699 void PrintSmartOfflineCollectCap(struct ata_smart_values
*data
){
700 pout("Offline data collection\n");
701 pout("capabilities: \t\t\t (0x%02x) ",
702 (int)data
->offline_data_collection_capability
);
704 if (data
->offline_data_collection_capability
== 0x00){
705 pout("\tOffline data collection not supported.\n");
708 pout( "%s\n", isSupportExecuteOfflineImmediate(data
)?
709 "SMART execute Offline immediate." :
710 "No SMART execute Offline immediate.");
712 pout( "\t\t\t\t\t%s\n", isSupportAutomaticTimer(data
)?
713 "Auto Offline data collection on/off support.":
714 "No Auto Offline data collection support.");
716 pout( "\t\t\t\t\t%s\n", isSupportOfflineAbort(data
)?
717 "Abort Offline collection upon new\n\t\t\t\t\tcommand.":
718 "Suspend Offline collection upon new\n\t\t\t\t\tcommand.");
720 pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data
)?
721 "Offline surface scan supported.":
722 "No Offline surface scan supported.");
724 pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data
)?
725 "Self-test supported.":
726 "No Self-test supported.");
728 pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data
)?
729 "Conveyance Self-test supported.":
730 "No Conveyance Self-test supported.");
732 pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data
)?
733 "Selective Self-test supported.":
734 "No Selective Self-test supported.");
740 void PrintSmartCapability ( struct ata_smart_values
*data
)
742 pout("SMART capabilities: ");
743 pout("(0x%04x)\t", (int)data
->smart_capability
);
745 if (data
->smart_capability
== 0x00)
747 pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
752 pout( "%s\n", (data
->smart_capability
& 0x01)?
753 "Saves SMART data before entering\n\t\t\t\t\tpower-saving mode.":
754 "Does not save SMART data before\n\t\t\t\t\tentering power-saving mode.");
756 if ( data
->smart_capability
& 0x02 )
758 pout("\t\t\t\t\tSupports SMART auto save timer.\n");
763 void PrintSmartErrorLogCapability (struct ata_smart_values
*data
, struct ata_identify_device
*identity
)
766 pout("Error logging capability: ");
768 if ( isSmartErrorLogCapable(data
, identity
) )
770 pout(" (0x%02x)\tError logging supported.\n",
771 (int)data
->errorlog_capability
);
774 pout(" (0x%02x)\tError logging NOT supported.\n",
775 (int)data
->errorlog_capability
);
779 void PrintSmartShortSelfTestPollingTime(struct ata_smart_values
*data
){
780 pout("Short self-test routine \n");
781 if (isSupportSelfTest(data
))
782 pout("recommended polling time: \t (%4d) minutes.\n",
783 (int)data
->short_test_completion_time
);
785 pout("recommended polling time: \t Not Supported.\n");
788 void PrintSmartExtendedSelfTestPollingTime(struct ata_smart_values
*data
){
789 pout("Extended self-test routine\n");
790 if (isSupportSelfTest(data
))
791 pout("recommended polling time: \t (%4d) minutes.\n",
792 (int)data
->extend_test_completion_time
);
794 pout("recommended polling time: \t Not Supported.\n");
797 void PrintSmartConveyanceSelfTestPollingTime(struct ata_smart_values
*data
){
798 pout("Conveyance self-test routine\n");
799 if (isSupportConveyanceSelfTest(data
))
800 pout("recommended polling time: \t (%4d) minutes.\n",
801 (int)data
->conveyance_test_completion_time
);
803 pout("recommended polling time: \t Not Supported.\n");
806 // onlyfailed=0 : print all attribute values
807 // onlyfailed=1: just ones that are currently failed and have prefailure bit set
808 // onlyfailed=2: ones that are failed, or have failed with or without prefailure bit set
809 void PrintSmartAttribWithThres (struct ata_smart_values
*data
,
810 struct ata_smart_thresholds_pvt
*thresholds
,
816 // step through all vendor attributes
817 for (i
=0; i
<NUMBER_ATA_SMART_ATTRIBUTES
; i
++){
819 struct ata_smart_attribute
*disk
=data
->vendor_attributes
+i
;
820 struct ata_smart_threshold_entry
*thre
=thresholds
->thres_entries
+i
;
822 // consider only valid attributes (allowing some screw-ups in the
823 // thresholds page data to slip by)
826 int failednow
,failedever
;
827 char attributename
[64];
829 failednow
= (disk
->current
<= thre
->threshold
);
830 failedever
= (disk
->worst
<= thre
->threshold
);
832 // These break out of the loop if we are only printing certain entries...
833 if (onlyfailed
==1 && (!ATTRIBUTE_FLAGS_PREFAILURE(disk
->flags
) || !failednow
))
836 if (onlyfailed
==2 && !failedever
)
839 // print header only if needed
842 pout("SMART Attributes Data Structure revision number: %d\n",(int)data
->revnumber
);
843 pout("Vendor Specific SMART Attributes with Thresholds:\n");
845 pout("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n");
849 // is this Attribute currently failed, or has it ever failed?
851 status
="FAILING_NOW";
853 status
="In_the_past";
857 // Print name of attribute
858 ataPrintSmartAttribName(attributename
,disk
->id
, con
->attributedefs
);
859 pout("%-28s",attributename
);
861 // printing line for each valid attribute
862 type
=ATTRIBUTE_FLAGS_PREFAILURE(disk
->flags
)?"Pre-fail":"Old_age";
863 update
=ATTRIBUTE_FLAGS_ONLINE(disk
->flags
)?"Always":"Offline";
865 pout("0x%04x %.3d %.3d %.3d %-10s%-9s%-12s",
866 (int)disk
->flags
, (int)disk
->current
, (int)disk
->worst
,
867 (int)thre
->threshold
, type
, update
, status
);
869 // print raw value of attribute
870 ataPrintSmartAttribRawValue(rawstring
, disk
, con
->attributedefs
);
871 pout("%s\n", rawstring
);
873 // print a warning if there is inconsistency here!
874 if (disk
->id
!= thre
->id
){
875 char atdat
[64],atthr
[64];
876 ataPrintSmartAttribName(atdat
, disk
->id
, con
->attributedefs
);
877 ataPrintSmartAttribName(atthr
, thre
->id
, con
->attributedefs
);
878 pout("%-28s<== Data Page | WARNING: PREVIOUS ATTRIBUTE HAS TWO\n",atdat
);
879 pout("%-28s<== Threshold Page | INCONSISTENT IDENTITIES IN THE DATA\n",atthr
);
883 if (!needheader
) pout("\n");
886 void ataPrintGeneralSmartValues(struct ata_smart_values
*data
, struct ata_identify_device
*drive
){
887 pout("General SMART Values:\n");
889 PrintSmartOfflineStatus(data
);
891 if (isSupportSelfTest(data
)){
892 PrintSmartSelfExecStatus (data
);
895 PrintSmartTotalTimeCompleteOffline(data
);
896 PrintSmartOfflineCollectCap(data
);
897 PrintSmartCapability(data
);
899 PrintSmartErrorLogCapability(data
, drive
);
901 pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive
)?
902 "General Purpose Logging supported.":
903 "No General Purpose Logging support.");
905 if (isSupportSelfTest(data
)){
906 PrintSmartShortSelfTestPollingTime (data
);
907 PrintSmartExtendedSelfTestPollingTime (data
);
909 if (isSupportConveyanceSelfTest(data
))
910 PrintSmartConveyanceSelfTestPollingTime (data
);
915 int ataPrintLogDirectory(struct ata_smart_log_directory
*data
){
919 pout("SMART Log Directory Logging Version %d%s\n",
920 data
->logversion
, data
->logversion
==1?" [multi-sector log support]":"");
921 for (i
=0; i
<=255; i
++){
924 // Directory log length
925 numsect
= i
? data
->entry
[i
-1].numsectors
: 1;
927 // If the log is not empty, what is it's name
931 name
="Log Directory"; break;
933 name
="Summary SMART error log"; break;
935 name
="Comprehensive SMART error log"; break;
937 name
="Extended Comprehensive SMART error log"; break;
939 name
="SMART self-test log"; break;
941 name
="Extended self-test log"; break;
943 name
="Selective self-test log"; break;
945 name
="Streaming performance log"; break;
947 name
="Write stream error log"; break;
949 name
="Read stream error log"; break;
951 name
="Delayed sector log"; break;
953 if (0xa0<=i
&& i
<=0xbf)
954 name
="Device vendor specific log";
955 else if (0x80<=i
&& i
<=0x9f)
956 name
="Host vendor specific log";
962 // print name and length of log
963 pout("Log at address 0x%02x has %03d sectors [%s]\n",
970 // returns number of errors
971 int ataPrintSmartErrorlog(struct ata_smart_errorlog
*data
){
974 pout("SMART Error Log Version: %d\n", (int)data
->revnumber
);
976 // if no errors logged, return
977 if (!data
->error_log_pointer
){
978 pout("No Errors Logged\n\n");
982 // If log pointer out of range, return
983 if (data
->error_log_pointer
>5){
984 pout("Invalid Error Log index = 0x%02x (T13/1321D rev 1c "
985 "Section 8.41.6.8.2.2 gives valid range from 1 to 5)\n\n",
986 (int)data
->error_log_pointer
);
990 // Some internal consistency checking of the data structures
991 if ((data
->ata_error_count
-data
->error_log_pointer
)%5 && con
->fixfirmwarebug
!= FIX_SAMSUNG2
) {
992 pout("Warning: ATA error count %d inconsistent with error log pointer %d\n\n",
993 data
->ata_error_count
,data
->error_log_pointer
);
996 // starting printing error log info
997 if (data
->ata_error_count
<=5)
998 pout( "ATA Error Count: %d\n", (int)data
->ata_error_count
);
1000 pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1001 (int)data
->ata_error_count
);
1003 pout("\tCR = Command Register [HEX]\n"
1004 "\tFR = Features Register [HEX]\n"
1005 "\tSC = Sector Count Register [HEX]\n"
1006 "\tSN = Sector Number Register [HEX]\n"
1007 "\tCL = Cylinder Low Register [HEX]\n"
1008 "\tCH = Cylinder High Register [HEX]\n"
1009 "\tDH = Device/Head Register [HEX]\n"
1010 "\tDC = Device Command Register [HEX]\n"
1011 "\tER = Error register [HEX]\n"
1012 "\tST = Status register [HEX]\n"
1013 "Powered_Up_Time is measured from power on, and printed as\n"
1014 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1015 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1017 // now step through the five error log data structures (table 39 of spec)
1018 for (k
= 4; k
>= 0; k
-- ) {
1021 // The error log data structure entries are a circular buffer
1022 int j
, i
=(data
->error_log_pointer
+k
)%5;
1023 struct ata_smart_errorlog_struct
*elog
=data
->errorlog_struct
+i
;
1024 struct ata_smart_errorlog_error_struct
*summary
=&(elog
->error_struct
);
1026 // Spec says: unused error log structures shall be zero filled
1027 if (nonempty((unsigned char*)elog
,sizeof(*elog
))){
1028 // Table 57 of T13/1532D Volume 1 Revision 3
1030 int bits
=summary
->state
& 0x0f;
1031 int days
= (int)summary
->timestamp
/24;
1034 case 0x00: msgstate
="in an unknown state";break;
1035 case 0x01: msgstate
="sleeping"; break;
1036 case 0x02: msgstate
="in standby mode"; break;
1037 case 0x03: msgstate
="active or idle"; break;
1038 case 0x04: msgstate
="doing SMART Offline or Self-test"; break;
1041 msgstate
="in a reserved state";
1043 msgstate
="in a vendor specific state";
1046 // See table 42 of ATA5 spec
1048 pout("Error %d occurred at disk power-on lifetime: %d hours (%d days + %d hours)\n",
1049 (int)(data
->ata_error_count
+k
-4), (int)summary
->timestamp
, days
, (int)(summary
->timestamp
-24*days
));
1051 pout(" When the command that caused the error occurred, the device was %s.\n\n",msgstate
);
1052 pout(" After command completion occurred, registers were:\n"
1053 " ER ST SC SN CL CH DH\n"
1054 " -- -- -- -- -- -- --\n"
1055 " %02x %02x %02x %02x %02x %02x %02x",
1056 (int)summary
->error_register
,
1057 (int)summary
->status
,
1058 (int)summary
->sector_count
,
1059 (int)summary
->sector_number
,
1060 (int)summary
->cylinder_low
,
1061 (int)summary
->cylinder_high
,
1062 (int)summary
->drive_head
);
1063 // Add a description of the contents of the status and error registers
1065 st_er_desc
= construct_st_er_desc(elog
);
1067 pout(" %s", st_er_desc
);
1071 pout(" Commands leading to the command that caused the error were:\n"
1072 " CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name\n"
1073 " -- -- -- -- -- -- -- -- ---------------- --------------------\n");
1074 for ( j
= 4; j
>= 0; j
--){
1075 struct ata_smart_errorlog_command_struct
*thiscommand
=elog
->commands
+j
;
1077 // Spec says: unused data command structures shall be zero filled
1078 if (nonempty((unsigned char*)thiscommand
,sizeof(*thiscommand
))) {
1079 char timestring
[32];
1081 // Convert integer milliseconds to a text-format string
1082 MsecToText(thiscommand
->timestamp
, timestring
);
1084 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1085 (int)thiscommand
->commandreg
,
1086 (int)thiscommand
->featuresreg
,
1087 (int)thiscommand
->sector_count
,
1088 (int)thiscommand
->sector_number
,
1089 (int)thiscommand
->cylinder_low
,
1090 (int)thiscommand
->cylinder_high
,
1091 (int)thiscommand
->drive_head
,
1092 (int)thiscommand
->devicecontrolreg
,
1094 look_up_ata_command(thiscommand
->commandreg
, thiscommand
->featuresreg
));
1101 if (con
->printing_switchable
)
1104 return data
->ata_error_count
;
1107 void ataPrintSelectiveSelfTestLog(struct ata_selective_self_test_log
*log
, struct ata_smart_values
*sv
) {
1108 int i
,field1
,field2
;
1111 uint64_t maxl
=0,maxr
=0;
1112 uint64_t current
=log
->currentlba
;
1113 uint64_t currentend
=current
+65535;
1115 // print data structure revision number
1116 pout("SMART Selective self-test log data structure revision number %d\n",(int)log
->logversion
);
1117 if (1 != log
->logversion
)
1118 pout("Warning: ATA Specification requires selective self-test log data structure revision number = 1\n");
1120 switch((sv
->self_test_exec_status
)>>4){
1121 case 0:msg
="Completed";
1123 case 1:msg
="Aborted_by_host";
1125 case 2:msg
="Interrupted";
1127 case 3:msg
="Fatal_error";
1129 case 4:msg
="Completed_unknown_failure";
1131 case 5:msg
="Completed_electrical_failure";
1133 case 6:msg
="Completed_servo/seek_failure";
1135 case 7:msg
="Completed_read_failure";
1137 case 8:msg
="Completed_handling_damage??";
1139 case 15:msg
="Self_test_in_progress";
1141 default:msg
="Unknown_status ";
1145 // find the number of columns needed for printing. If in use, the
1146 // start/end of span being read-scanned...
1147 if (log
->currentspan
>5) {
1151 for (i
=0; i
<5; i
++) {
1152 uint64_t start
=log
->span
[i
].start
;
1153 uint64_t end
=log
->span
[i
].end
;
1154 // ... plus max start/end of each of the five test spans.
1161 // we need at least 7 characters wide fields to accomodate the
1163 if ((field1
=snprintf(tmp
,64, "%"PRIu64
, maxl
))<7)
1165 if ((field2
=snprintf(tmp
,64, "%"PRIu64
, maxr
))<7)
1168 // now print the five test spans
1169 pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1
, "MIN_LBA", field2
, "MAX_LBA");
1171 for (i
=0; i
<5; i
++) {
1172 uint64_t start
=log
->span
[i
].start
;
1173 uint64_t end
=log
->span
[i
].end
;
1175 if ((i
+1)==(int)log
->currentspan
)
1176 // this span is currently under test
1177 pout(" %d %*"PRIu64
" %*"PRIu64
" %s [%01d0%% left] (%"PRIu64
"-%"PRIu64
")\n",
1178 i
+1, field1
, start
, field2
, end
, msg
,
1179 (int)(sv
->self_test_exec_status
& 0x7), current
, currentend
);
1181 // this span is not currently under test
1182 pout(" %d %*"PRIu64
" %*"PRIu64
" Not_testing\n",
1183 i
+1, field1
, start
, field2
, end
);
1186 // if we are currently read-scanning, print LBAs and the status of
1188 if (log
->currentspan
>5)
1189 pout("%5d %*"PRIu64
" %*"PRIu64
" Read_scanning %s\n",
1190 (int)log
->currentspan
, field1
, current
, field2
, currentend
,
1191 OfflineDataCollectionStatus(sv
->offline_data_collection_status
));
1193 /* Print selective self-test flags. Possible flag combinations are
1194 (numbering bits from 0-15):
1198 1 0 0 Will carry out scan after selective test
1199 1 1 0 Waiting to carry out scan after powerup
1200 1 0 1 Currently scanning
1201 1 1 1 Currently scanning
1204 pout("Selective self-test flags (0x%x):\n", (unsigned int)log
->flags
);
1205 if (log
->flags
& SELECTIVE_FLAG_DOSCAN
) {
1206 if (log
->flags
& SELECTIVE_FLAG_ACTIVE
)
1207 pout(" Currently read-scanning the remainder of the disk.\n");
1208 else if (log
->flags
& SELECTIVE_FLAG_PENDING
)
1209 pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
1210 (int)log
->pendingtime
);
1212 pout(" After scanning selected spans, read-scan remainder of disk.\n");
1215 pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
1217 // print pending time
1218 pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
1219 (int)log
->pendingtime
);
1225 // bottom 8 bits: number of entries found where self-test showed an error
1226 // remaining bits: if nonzero, power on hours of last self-test where error was found
1227 int ataPrintSmartSelfTestlog(struct ata_smart_selftestlog
*data
,int allentries
){
1228 int i
,j
,noheaderprinted
=1;
1229 int retval
=0, hours
=0, testno
=0;
1232 pout("SMART Self-test log structure revision number %d\n",(int)data
->revnumber
);
1233 if ((data
->revnumber
!=0x0001) && allentries
&& con
->fixfirmwarebug
!= FIX_SAMSUNG
)
1234 pout("Warning: ATA Specification requires self-test log structure revision number = 1\n");
1235 if (data
->mostrecenttest
==0){
1237 pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
1242 for (i
=20;i
>=0;i
--){
1243 struct ata_smart_selftestlog_struct
*log
;
1245 // log is a circular buffer
1246 j
=(i
+data
->mostrecenttest
)%21;
1247 log
=data
->selftest_struct
+j
;
1249 if (nonempty((unsigned char*)log
,sizeof(*log
))){
1250 char *msgtest
,*msgstat
,percent
[64],firstlba
[64];
1253 // count entry based on non-empty structures -- needed for
1254 // Seagate only -- other vendors don't have blank entries 'in
1259 switch(log
->selftestnumber
){
1260 case 0: msgtest
="Offline "; break;
1261 case 1: msgtest
="Short offline "; break;
1262 case 2: msgtest
="Extended offline "; break;
1263 case 3: msgtest
="Conveyance offline "; break;
1264 case 4: msgtest
="Selective offline "; break;
1265 case 127: msgtest
="Abort offline test "; break;
1266 case 129: msgtest
="Short captive "; break;
1267 case 130: msgtest
="Extended captive "; break;
1268 case 131: msgtest
="Conveyance captive "; break;
1269 case 132: msgtest
="Selective captive "; break;
1271 if ( log
->selftestnumber
>=192 ||
1272 (log
->selftestnumber
>= 64 && log
->selftestnumber
<=126))
1273 msgtest
="Vendor offline ";
1275 msgtest
="Reserved offline ";
1279 switch((log
->selfteststatus
)>>4){
1280 case 0:msgstat
="Completed without error "; break;
1281 case 1:msgstat
="Aborted by host "; break;
1282 case 2:msgstat
="Interrupted (host reset) "; break;
1283 case 3:msgstat
="Fatal or unknown error "; errorfound
=1; break;
1284 case 4:msgstat
="Completed: unknown failure "; errorfound
=1; break;
1285 case 5:msgstat
="Completed: electrical failure"; errorfound
=1; break;
1286 case 6:msgstat
="Completed: servo/seek failure"; errorfound
=1; break;
1287 case 7:msgstat
="Completed: read failure "; errorfound
=1; break;
1288 case 8:msgstat
="Completed: handling damage?? "; errorfound
=1; break;
1289 case 15:msgstat
="Self-test routine in progress"; break;
1290 default:msgstat
="Unknown/reserved test status ";
1294 sprintf(percent
,"%1d0%%",(log
->selfteststatus
)&0xf);
1296 // T13/1321D revision 1c: (Data structure Rev #1)
1298 //The failing LBA shall be the LBA of the uncorrectable sector
1299 //that caused the test to fail. If the device encountered more
1300 //than one uncorrectable sector during the test, this field
1301 //shall indicate the LBA of the first uncorrectable sector
1302 //encountered. If the test passed or the test failed for some
1303 //reason other than an uncorrectable sector, the value of this
1304 //field is undefined.
1306 // This is true in ALL ATA-5 specs
1308 if (!errorfound
|| log
->lbafirstfailure
==0xffffffff || log
->lbafirstfailure
==0x00000000)
1309 sprintf(firstlba
,"%s","-");
1311 sprintf(firstlba
,"%u",log
->lbafirstfailure
);
1313 // print out a header if needed
1314 if (noheaderprinted
&& (allentries
|| errorfound
)){
1315 pout("Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error\n");
1319 // print out an entry, either if we are printing all entries OR
1320 // if an error was found
1321 if (allentries
|| errorfound
)
1322 pout("#%2d %s %s %s %8d %s\n", testno
, msgtest
, msgstat
, percent
, (int)log
->timestamp
, firstlba
);
1324 // keep track of time of most recent error
1325 if (errorfound
&& !hours
)
1326 hours
=log
->timestamp
;
1329 if (!allentries
&& retval
)
1333 return (retval
| hours
);
1336 void ataPseudoCheckSmart ( struct ata_smart_values
*data
,
1337 struct ata_smart_thresholds_pvt
*thresholds
) {
1340 for (i
= 0 ; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
1341 if (data
->vendor_attributes
[i
].id
&&
1342 thresholds
->thres_entries
[i
].id
&&
1343 ATTRIBUTE_FLAGS_PREFAILURE(data
->vendor_attributes
[i
].flags
) &&
1344 (data
->vendor_attributes
[i
].current
<= thresholds
->thres_entries
[i
].threshold
) &&
1345 (thresholds
->thres_entries
[i
].threshold
!= 0xFE)){
1346 pout("Attribute ID %d Failed\n",(int)data
->vendor_attributes
[i
].id
);
1350 pout("%s\n", ( failed
)?
1351 "SMART overall-health self-assessment test result: FAILED!\n"
1352 "Drive failure expected in less than 24 hours. SAVE ALL DATA":
1353 "SMART overall-health self-assessment test result: PASSED");
1357 // Compares failure type to policy in effect, and either exits or
1358 // simply returns to the calling routine.
1359 void failuretest(int type
, int returnvalue
){
1361 // If this is an error in an "optional" SMART command
1362 if (type
==OPTIONAL_CMD
){
1363 if (con
->conservative
){
1364 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1370 // If this is an error in a "mandatory" SMART command
1371 if (type
==MANDATORY_CMD
){
1372 if (con
->permissive
--)
1374 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1378 pout("Smartctl internal error in failuretest(type=%d). Please contact developers at " PACKAGE_HOMEPAGE
"\n",type
);
1379 EXIT(returnvalue
|FAILCMD
);
1382 // Used to warn users about invalid checksums. Action to be taken may be
1383 // altered by the user.
1384 void checksumwarning(const char *string
){
1385 // user has asked us to ignore checksum errors
1386 if (con
->checksumignore
)
1389 pout("Warning! %s error: invalid SMART checksum.\n",string
);
1391 // user has asked us to fail on checksum errors
1392 if (con
->checksumfail
)
1398 // Initialize to zero just in case some SMART routines don't work
1399 struct ata_identify_device drive
;
1400 struct ata_smart_values smartval
;
1401 struct ata_smart_thresholds_pvt smartthres
;
1402 struct ata_smart_errorlog smarterror
;
1403 struct ata_smart_selftestlog smartselftest
;
1405 int ataPrintMain (int fd
){
1407 int returnval
=0, retid
=0, supported
=0, needupdate
=0;
1409 // Start by getting Drive ID information. We need this, to know if SMART is supported.
1410 if ((retid
=ataReadHDIdentity(fd
,&drive
))<0){
1411 pout("Smartctl: Device Read Identity Failed (not an ATA/ATAPI device)\n\n");
1412 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
1415 // If requested, show which presets would be used for this drive and exit.
1416 if (con
->showpresets
) {
1417 showpresets(&drive
);
1421 // Use preset vendor attribute options unless user has requested otherwise.
1422 if (!con
->ignorepresets
){
1423 unsigned char *charptr
;
1424 if ((charptr
=con
->attributedefs
))
1425 applypresets(&drive
, &charptr
, con
);
1427 pout("Fatal internal error in ataPrintMain()\n");
1428 EXIT(returnval
|=FAILCMD
);
1432 // Print most drive identity information if requested
1433 if (con
->driveinfo
){
1434 pout("=== START OF INFORMATION SECTION ===\n");
1435 ataPrintDriveInfo(&drive
);
1438 // Was this a packet device?
1440 pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n", packetdevicetype(retid
-1));
1441 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1444 // if drive does not supports SMART it's time to exit
1445 supported
=ataSmartSupport(&drive
);
1446 if (supported
!= 1){
1448 pout("SMART support is: Unavailable - device lacks SMART capability.\n");
1449 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1450 pout(" Checking to be sure by trying SMART ENABLE command.\n");
1453 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
1454 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1455 pout(" Checking for SMART support by trying SMART ENABLE command.\n");
1458 if (ataEnableSmart(fd
)){
1459 pout(" SMART ENABLE failed - this establishes that this device lacks SMART functionality.\n");
1460 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1464 pout(" SMART ENABLE appeared to work! Continuing.\n");
1467 if (!con
->driveinfo
) pout("\n");
1470 // Now print remaining drive info: is SMART enabled?
1471 if (con
->driveinfo
){
1472 int ison
=ataIsSmartEnabled(&drive
),isenabled
=ison
;
1475 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
1476 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1477 // check SMART support by trying a command
1478 pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
1479 isenabled
=ataDoesSmartWork(fd
);
1482 pout("SMART support is: Available - device has SMART capability.\n");
1483 #ifdef HAVE_ATA_IDENTIFY_IS_CACHED
1484 if (ata_identify_is_cached(fd
)) {
1485 pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
1486 (isenabled
?"En":"Dis"));
1487 isenabled
=ataDoesSmartWork(fd
);
1493 pout("SMART support is: Enabled\n");
1496 pout("SMART support is: Unavailable\n");
1498 pout("SMART support is: Disabled\n");
1503 // START OF THE ENABLE/DISABLE SECTION OF THE CODE
1504 if (con
->smartenable
|| con
->smartdisable
||
1505 con
->smartautosaveenable
|| con
->smartautosavedisable
||
1506 con
->smartautoofflineenable
|| con
->smartautoofflinedisable
)
1507 pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
1509 // Enable/Disable SMART commands
1510 if (con
->smartenable
){
1511 if (ataEnableSmart(fd
)) {
1512 pout("Smartctl: SMART Enable Failed.\n\n");
1513 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1516 pout("SMART Enabled.\n");
1519 // From here on, every command requires that SMART be enabled...
1520 if (!ataDoesSmartWork(fd
)) {
1521 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1525 // Turn off SMART on device
1526 if (con
->smartdisable
){
1527 if (ataDisableSmart(fd
)) {
1528 pout( "Smartctl: SMART Disable Failed.\n\n");
1529 failuretest(MANDATORY_CMD
,returnval
|=FAILSMART
);
1531 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1535 // Let's ALWAYS issue this command to get the SMART status
1536 code
=ataSmartStatus2(fd
);
1538 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1540 // Enable/Disable Auto-save attributes
1541 if (con
->smartautosaveenable
){
1542 if (ataEnableAutoSave(fd
)){
1543 pout( "Smartctl: SMART Enable Attribute Autosave Failed.\n\n");
1544 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1547 pout("SMART Attribute Autosave Enabled.\n");
1549 if (con
->smartautosavedisable
){
1550 if (ataDisableAutoSave(fd
)){
1551 pout( "Smartctl: SMART Disable Attribute Autosave Failed.\n\n");
1552 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1555 pout("SMART Attribute Autosave Disabled.\n");
1558 // for everything else read values and thresholds are needed
1559 if (ataReadSmartValues(fd
, &smartval
)){
1560 pout("Smartctl: SMART Read Values failed.\n\n");
1561 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1563 if (ataReadSmartThresholds(fd
, &smartthres
)){
1564 pout("Smartctl: SMART Read Thresholds failed.\n\n");
1565 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1568 // Enable/Disable Off-line testing
1569 if (con
->smartautoofflineenable
){
1570 if (!isSupportAutomaticTimer(&smartval
)){
1571 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1572 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1575 if (ataEnableAutoOffline(fd
)){
1576 pout( "Smartctl: SMART Enable Automatic Offline Failed.\n\n");
1577 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1580 pout("SMART Automatic Offline Testing Enabled every four hours.\n");
1582 if (con
->smartautoofflinedisable
){
1583 if (!isSupportAutomaticTimer(&smartval
)){
1584 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1585 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1588 if (ataDisableAutoOffline(fd
)){
1589 pout("Smartctl: SMART Disable Automatic Offline Failed.\n\n");
1590 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1593 pout("SMART Automatic Offline Testing Disabled.\n");
1596 if (needupdate
&& ataReadSmartValues(fd
, &smartval
)){
1597 pout("Smartctl: SMART Read Values failed.\n\n");
1598 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1601 // all this for a newline!
1602 if (con
->smartenable
|| con
->smartdisable
||
1603 con
->smartautosaveenable
|| con
->smartautosavedisable
||
1604 con
->smartautoofflineenable
|| con
->smartautoofflinedisable
)
1607 // START OF READ-ONLY OPTIONS APART FROM -V and -i
1608 if (con
->checksmart
|| con
->generalsmartvalues
|| con
->smartvendorattrib
|| con
->smarterrorlog
|| con
->smartselftestlog
)
1609 pout("=== START OF READ SMART DATA SECTION ===\n");
1611 // Check SMART status (use previously returned value)
1612 if (con
->checksmart
){
1616 // The case where the disk health is OK
1617 pout("SMART overall-health self-assessment test result: PASSED\n");
1618 if (ataCheckSmart(&smartval
, &smartthres
,0)){
1619 if (con
->smartvendorattrib
)
1620 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1623 pout("Please note the following marginal Attributes:\n");
1624 PrintSmartAttribWithThres(&smartval
, &smartthres
,2);
1633 // The case where the disk health is NOT OK
1635 pout("SMART overall-health self-assessment test result: FAILED!\n"
1636 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1638 if (ataCheckSmart(&smartval
, &smartthres
,1)){
1639 returnval
|=FAILATTR
;
1640 if (con
->smartvendorattrib
)
1641 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1644 pout("Failed Attributes:\n");
1645 PrintSmartAttribWithThres(&smartval
, &smartthres
,1);
1649 pout("No failed Attributes found.\n\n");
1650 returnval
|=FAILSTATUS
;
1656 // The case where something went wrong with HDIO_DRIVE_TASK ioctl()
1657 if (ataCheckSmart(&smartval
, &smartthres
,1)){
1659 pout("SMART overall-health self-assessment test result: FAILED!\n"
1660 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1662 returnval
|=FAILATTR
;
1663 returnval
|=FAILSTATUS
;
1664 if (con
->smartvendorattrib
)
1665 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1668 pout("Failed Attributes:\n");
1669 PrintSmartAttribWithThres(&smartval
, &smartthres
,1);
1673 pout("SMART overall-health self-assessment test result: PASSED\n");
1674 if (ataCheckSmart(&smartval
, &smartthres
,0)){
1675 if (con
->smartvendorattrib
)
1676 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1679 pout("Please note the following marginal Attributes:\n");
1680 PrintSmartAttribWithThres(&smartval
, &smartthres
,2);
1689 } // end of switch statement
1692 } // end of checking SMART Status
1694 // Print general SMART values
1695 if (con
->generalsmartvalues
)
1696 ataPrintGeneralSmartValues(&smartval
, &drive
);
1698 // Print vendor-specific attributes
1699 if (con
->smartvendorattrib
){
1701 PrintSmartAttribWithThres(&smartval
, &smartthres
,con
->printing_switchable
?2:0);
1705 // Print SMART log Directory
1706 if (con
->smartlogdirectory
){
1707 struct ata_smart_log_directory smartlogdirectory
;
1708 if (!isGeneralPurposeLoggingCapable(&drive
)){
1709 pout("Warning: device does not support General Purpose Logging\n");
1710 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1714 pout("Log Directory Supported\n");
1715 if (ataReadLogDirectory(fd
, &smartlogdirectory
)){
1717 pout("Read Log Directory failed.\n\n");
1718 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1721 ataPrintLogDirectory( &smartlogdirectory
);
1726 // Print SMART error log
1727 if (con
->smarterrorlog
){
1728 if (!isSmartErrorLogCapable(&smartval
, &drive
)){
1729 pout("Warning: device does not support Error Logging\n");
1730 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1732 if (ataReadErrorLog(fd
, &smarterror
)){
1733 pout("Smartctl: SMART Error Log Read Failed\n");
1734 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1737 // quiet mode is turned on inside ataPrintSmartErrorLog()
1738 if (ataPrintSmartErrorlog(&smarterror
))
1744 // Print SMART self-test log
1745 if (con
->smartselftestlog
){
1746 if (!isSmartTestLogCapable(&smartval
, &drive
)){
1747 pout("Warning: device does not support Self Test Logging\n");
1748 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1750 if(ataReadSelfTestLog(fd
, &smartselftest
)){
1751 pout("Smartctl: SMART Self Test Log Read Failed\n");
1752 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1756 if (ataPrintSmartSelfTestlog(&smartselftest
,!con
->printing_switchable
))
1763 // Print SMART selective self-test log
1764 if (con
->selectivetestlog
){
1765 struct ata_selective_self_test_log log
;
1767 if (!isSupportSelectiveSelfTest(&smartval
))
1768 pout("Device does not support Selective Self Tests/Logging\n");
1769 else if(ataReadSelectiveSelfTestLog(fd
, &log
)) {
1770 pout("Smartctl: SMART Selective Self Test Log Read Failed\n");
1771 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1775 ataPrintSelectiveSelfTestLog(&log
, &smartval
);
1781 // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
1782 if (con
->testcase
==-1)
1785 pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
1786 // if doing a self-test, be sure it's supported by the hardware
1787 switch (con
->testcase
){
1788 case OFFLINE_FULL_SCAN
:
1789 if (!isSupportExecuteOfflineImmediate(&smartval
)){
1790 pout("Warning: device does not support Execute Offline Immediate function.\n\n");
1791 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1794 case ABORT_SELF_TEST
:
1795 case SHORT_SELF_TEST
:
1796 case EXTEND_SELF_TEST
:
1797 case SHORT_CAPTIVE_SELF_TEST
:
1798 case EXTEND_CAPTIVE_SELF_TEST
:
1799 if (!isSupportSelfTest(&smartval
)){
1800 pout("Warning: device does not support Self-Test functions.\n\n");
1801 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1804 case CONVEYANCE_SELF_TEST
:
1805 case CONVEYANCE_CAPTIVE_SELF_TEST
:
1806 if (!isSupportConveyanceSelfTest(&smartval
)){
1807 pout("Warning: device does not support Conveyance Self-Test functions.\n\n");
1808 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1811 case SELECTIVE_SELF_TEST
:
1812 case SELECTIVE_CAPTIVE_SELF_TEST
:
1813 if (!isSupportSelectiveSelfTest(&smartval
)){
1814 pout("Warning: device does not support Selective Self-Test functions.\n\n");
1815 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
1819 pout("Internal error in smartctl: con->testcase==%d not recognized\n", (int)con
->testcase
);
1820 pout("Please contact smartmontools developers at %s.\n", PACKAGE_BUGREPORT
);
1821 EXIT(returnval
|=FAILCMD
);
1824 // Now do the test. Note ataSmartTest prints its own error/success
1826 if (ataSmartTest(fd
, con
->testcase
, &smartval
))
1827 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1829 // Tell user how long test will take to complete. This is tricky
1830 // because in the case of an Offline Full Scan, the completion
1831 // timer is volatile, and needs to be read AFTER the command is
1832 // given. If this will interrupt the Offline Full Scan, we don't
1833 // do it, just warn user.
1834 if (con
->testcase
==OFFLINE_FULL_SCAN
){
1835 if (isSupportOfflineAbort(&smartval
))
1836 pout("Note: giving further SMART commands will abort Offline testing\n");
1837 else if (ataReadSmartValues(fd
, &smartval
)){
1838 pout("Smartctl: SMART Read Values failed.\n");
1839 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
1843 // Now say how long the test will take to complete
1844 if ((timewait
=TestTime(&smartval
,con
->testcase
))){
1845 time_t t
=time(NULL
);
1846 if (con
->testcase
==OFFLINE_FULL_SCAN
) {
1848 pout("Please wait %d seconds for test to complete.\n", (int)timewait
);
1851 pout("Please wait %d minutes for test to complete.\n", (int)timewait
);
1853 pout("Test will complete after %s\n", ctime(&t
));
1855 if (con
->testcase
!=SHORT_CAPTIVE_SELF_TEST
&&
1856 con
->testcase
!=EXTEND_CAPTIVE_SELF_TEST
&&
1857 con
->testcase
!=CONVEYANCE_CAPTIVE_SELF_TEST
&&
1858 con
->testcase
!=SELECTIVE_CAPTIVE_SELF_TEST
)
1859 pout("Use smartctl -X to abort test.\n");