4 * Home page of code is: http://smartmontools.sourceforge.net
6 * Copyright (C) 2002-11 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 2008-14 Christian Franke <smartmontools-support@lists.sourceforge.net>
8 * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * You should have received a copy of the GNU General Public License
16 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
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/
34 #include "atacmdnames.h"
36 #include "ataidentify.h"
37 #include "dev_interface.h"
41 #include "knowndrives.h"
43 const char * ataprint_cpp_cvsid
= "$Id: ataprint.cpp 3982 2014-08-16 21:07:19Z samm2 $"
47 static const char * infofound(const char *output
) {
48 return (*output
? output
: "[No Information Found]");
51 // Return true if '-T permissive' is specified,
52 // used to ignore missing capabilities
53 static bool is_permissive()
55 if (!failuretest_permissive
)
57 failuretest_permissive
--;
61 /* For the given Command Register (CR) and Features Register (FR), attempts
62 * to construct a string that describes the contents of the Status
63 * Register (ST) and Error Register (ER). If the meanings of the flags of
64 * the error register are not known for the given command then it returns an
67 * The meanings of the flags of the error register for all commands are
68 * described in the ATA spec and could all be supported here in theory.
69 * Currently, only a few commands are supported (those that have been seen
70 * to produce errors). If many more are to be added then this function
71 * should probably be redesigned.
74 static std::string
format_st_er_desc(
75 unsigned char CR
, unsigned char FR
,
76 unsigned char ST
, unsigned char ER
,
78 const ata_smart_errorlog_error_struct
* lba28_regs
,
79 const ata_smart_exterrlog_error
* lba48_regs
82 const char *error_flag
[8];
83 int i
, print_lba
=0, print_sector
=0;
85 // Set of character strings corresponding to different error codes.
86 // Please keep in alphabetic order if you add more.
87 const char *abrt
= "ABRT"; // ABORTED
88 const char *amnf
= "AMNF"; // ADDRESS MARK NOT FOUND
89 const char *ccto
= "CCTO"; // COMMAND COMPLETION TIMED OUT
90 const char *eom
= "EOM"; // END OF MEDIA
91 const char *icrc
= "ICRC"; // INTERFACE CRC ERROR
92 const char *idnf
= "IDNF"; // ID NOT FOUND
93 const char *ili
= "ILI"; // MEANING OF THIS BIT IS COMMAND-SET SPECIFIC
94 const char *mc
= "MC"; // MEDIA CHANGED
95 const char *mcr
= "MCR"; // MEDIA CHANGE REQUEST
96 const char *nm
= "NM"; // NO MEDIA
97 const char *obs
= "obs"; // OBSOLETE
98 const char *tk0nf
= "TK0NF"; // TRACK 0 NOT FOUND
99 const char *unc
= "UNC"; // UNCORRECTABLE
100 const char *wp
= "WP"; // WRITE PROTECTED
102 /* If for any command the Device Fault flag of the status register is
103 * not used then used_device_fault should be set to 0 (in the CR switch
106 int uses_device_fault
= 1;
108 /* A value of NULL means that the error flag isn't used */
109 for (i
= 0; i
< 8; i
++)
110 error_flag
[i
] = NULL
;
115 case 0x10: // RECALIBRATE
116 error_flag
[2] = abrt
;
117 error_flag
[1] = tk0nf
;
119 case 0x20: /* READ SECTOR(S) */
120 case 0x21: // READ SECTOR(S)
121 case 0x24: // READ SECTOR(S) EXT
122 case 0xC4: /* READ MULTIPLE */
123 case 0x29: // READ MULTIPLE EXT
126 error_flag
[4] = idnf
;
128 error_flag
[2] = abrt
;
130 error_flag
[0] = amnf
;
133 case 0x22: // READ LONG (with retries)
134 case 0x23: // READ LONG (without retries)
135 error_flag
[4] = idnf
;
136 error_flag
[2] = abrt
;
137 error_flag
[0] = amnf
;
140 case 0x2a: // READ STREAM DMA
141 case 0x2b: // READ STREAM PIO
143 error_flag
[7] = icrc
;
146 error_flag
[4] = idnf
;
148 error_flag
[2] = abrt
;
150 error_flag
[0] = ccto
;
154 case 0x3A: // WRITE STREAM DMA
155 case 0x3B: // WRITE STREAM PIO
157 error_flag
[7] = icrc
;
160 error_flag
[4] = idnf
;
162 error_flag
[2] = abrt
;
164 error_flag
[0] = ccto
;
168 case 0x25: // READ DMA EXT
169 case 0x26: // READ DMA QUEUED EXT
170 case 0xC7: // READ DMA QUEUED
171 case 0xC8: // READ DMA (with retries)
172 case 0xC9: // READ DMA (without retries, obsolete since ATA-5)
173 case 0x60: // READ FPDMA QUEUED (NCQ)
174 error_flag
[7] = icrc
;
177 error_flag
[4] = idnf
;
179 error_flag
[2] = abrt
;
181 error_flag
[0] = amnf
;
183 if (CR
==0x25 || CR
==0xC8)
186 case 0x30: /* WRITE SECTOR(S) */
187 case 0x31: // WRITE SECTOR(S)
188 case 0x34: // WRITE SECTOR(S) EXT
189 case 0xC5: /* WRITE MULTIPLE */
190 case 0x39: // WRITE MULTIPLE EXT
191 case 0xCE: // WRITE MULTIPLE FUA EXT
194 error_flag
[4] = idnf
;
196 error_flag
[2] = abrt
;
200 case 0x32: // WRITE LONG (with retries)
201 case 0x33: // WRITE LONG (without retries)
202 error_flag
[4] = idnf
;
203 error_flag
[2] = abrt
;
206 case 0x3C: // WRITE VERIFY
208 error_flag
[4] = idnf
;
209 error_flag
[2] = abrt
;
210 error_flag
[0] = amnf
;
213 case 0x40: // READ VERIFY SECTOR(S) with retries
214 case 0x41: // READ VERIFY SECTOR(S) without retries
215 case 0x42: // READ VERIFY SECTOR(S) EXT
218 error_flag
[4] = idnf
;
220 error_flag
[2] = abrt
;
222 error_flag
[0] = amnf
;
225 case 0xA0: /* PACKET */
226 /* Bits 4-7 are all used for sense key (a 'command packet set specific error
227 * indication' according to the ATA/ATAPI-7 standard), so "Sense key" will
228 * be repeated in the error description string if more than one of those
231 error_flag
[7] = "Sense key (bit 3)",
232 error_flag
[6] = "Sense key (bit 2)",
233 error_flag
[5] = "Sense key (bit 1)",
234 error_flag
[4] = "Sense key (bit 0)",
235 error_flag
[2] = abrt
;
239 case 0xA1: /* IDENTIFY PACKET DEVICE */
240 case 0xEF: /* SET FEATURES */
242 case 0xC6: /* SET MULTIPLE MODE */
243 error_flag
[2] = abrt
;
245 case 0x2F: // READ LOG EXT
247 error_flag
[4] = idnf
;
248 error_flag
[2] = abrt
;
251 case 0x3F: // WRITE LOG EXT
252 error_flag
[4] = idnf
;
253 error_flag
[2] = abrt
;
256 case 0xB0: /* SMART */
258 case 0xD0: // SMART READ DATA
259 case 0xD1: // SMART READ ATTRIBUTE THRESHOLDS
260 case 0xD5: /* SMART READ LOG */
262 error_flag
[4] = idnf
;
263 error_flag
[2] = abrt
;
266 case 0xD6: /* SMART WRITE LOG */
267 error_flag
[4] = idnf
;
268 error_flag
[2] = abrt
;
271 case 0xD2: // Enable/Disable Attribute Autosave
272 case 0xD3: // SMART SAVE ATTRIBUTE VALUES (ATA-3)
273 case 0xD8: // SMART ENABLE OPERATIONS
274 case 0xD9: /* SMART DISABLE OPERATIONS */
275 case 0xDA: /* SMART RETURN STATUS */
276 case 0xDB: // Enable/Disable Auto Offline (SFF)
277 error_flag
[2] = abrt
;
279 case 0xD4: // SMART EXECUTE IMMEDIATE OFFLINE
280 error_flag
[4] = idnf
;
281 error_flag
[2] = abrt
;
288 case 0xB1: /* DEVICE CONFIGURATION */
290 case 0xC0: /* DEVICE CONFIGURATION RESTORE */
291 error_flag
[2] = abrt
;
298 case 0xCA: // WRITE DMA (with retries)
299 case 0xCB: // WRITE DMA (without retries, obsolete since ATA-5)
300 case 0x35: // WRITE DMA EXT
301 case 0x3D: // WRITE DMA FUA EXT
302 case 0xCC: // WRITE DMA QUEUED
303 case 0x36: // WRITE DMA QUEUED EXT
304 case 0x3E: // WRITE DMA QUEUED FUA EXT
305 case 0x61: // WRITE FPDMA QUEUED (NCQ)
306 error_flag
[7] = icrc
;
309 error_flag
[4] = idnf
;
311 error_flag
[2] = abrt
;
313 error_flag
[0] = amnf
;
318 case 0xE4: // READ BUFFER
319 case 0xE8: // WRITE BUFFER
320 error_flag
[2] = abrt
;
326 /* We ignore any status flags other than Device Fault and Error */
328 if (uses_device_fault
&& (ST
& (1 << 5))) {
329 str
= "Device Fault";
330 if (ST
& 1) // Error flag
333 if (ST
& 1) { // Error flag
337 for (i
= 7; i
>= 0; i
--)
338 if ((ER
& (1 << i
)) && (error_flag
[i
])) {
341 str
+= error_flag
[i
];
345 // If the error was a READ or WRITE error, print the Logical Block
346 // Address (LBA) at which the read or write failed.
348 // print number of sectors, if known, and append to print string
350 str
+= strprintf(" %d sectors", print_sector
);
354 // bits 24-27: bits 0-3 of DH
355 lba
= 0xf & lba28_regs
->drive_head
;
358 lba
|= lba28_regs
->cylinder_high
;
361 lba
|= lba28_regs
->cylinder_low
;
364 lba
|= lba28_regs
->sector_number
;
365 str
+= strprintf(" at LBA = 0x%08x = %u", lba
, lba
);
367 else if (lba48_regs
) {
368 // This assumes that upper LBA registers are 0 for 28-bit commands
369 // (TODO: detect 48-bit commands above)
371 lba48
= lba48_regs
->lba_high_register_hi
;
373 lba48
|= lba48_regs
->lba_mid_register_hi
;
375 lba48
|= lba48_regs
->lba_low_register_hi
;
376 lba48
|= lba48_regs
->device_register
& 0xf;
378 lba48
|= lba48_regs
->lba_high_register
;
380 lba48
|= lba48_regs
->lba_mid_register
;
382 lba48
|= lba48_regs
->lba_low_register
;
383 str
+= strprintf(" at LBA = 0x%08" PRIx64
" = %" PRIu64
, lba48
, lba48
);
390 static inline std::string
format_st_er_desc(
391 const ata_smart_errorlog_struct
* data
)
393 return format_st_er_desc(
394 data
->commands
[4].commandreg
,
395 data
->commands
[4].featuresreg
,
396 data
->error_struct
.status
,
397 data
->error_struct
.error_register
,
398 data
->error_struct
.sector_count
,
399 &data
->error_struct
, (const ata_smart_exterrlog_error
*)0);
402 static inline std::string
format_st_er_desc(
403 const ata_smart_exterrlog_error_log
* data
)
405 return format_st_er_desc(
406 data
->commands
[4].command_register
,
407 data
->commands
[4].features_register
,
408 data
->error
.status_register
,
409 data
->error
.error_register
,
410 data
->error
.count_register_hi
<< 8 | data
->error
.count_register
,
411 (const ata_smart_errorlog_error_struct
*)0, &data
->error
);
415 static int find_msb(unsigned short word
)
417 for (int bit
= 15; bit
>= 0; bit
--)
418 if (word
& (1 << bit
))
423 static const char * get_ata_major_version(const ata_identify_device
* drive
)
425 switch (find_msb(drive
->major_rev_num
)) {
426 case 10: return "ACS-3";
427 case 9: return "ACS-2";
428 case 8: return "ATA8-ACS";
429 case 7: return "ATA/ATAPI-7";
430 case 6: return "ATA/ATAPI-6";
431 case 5: return "ATA/ATAPI-5";
432 case 4: return "ATA/ATAPI-4";
433 case 3: return "ATA-3";
434 case 2: return "ATA-2";
435 case 1: return "ATA-1";
440 static const char * get_ata_minor_version(const ata_identify_device
* drive
)
442 switch (drive
->minor_rev_num
) {
443 case 0x0001: return "ATA-1 X3T9.2/781D prior to revision 4";
444 case 0x0002: return "ATA-1 published, ANSI X3.221-1994";
445 case 0x0003: return "ATA-1 X3T9.2/781D revision 4";
446 case 0x0004: return "ATA-2 published, ANSI X3.279-1996";
447 case 0x0005: return "ATA-2 X3T10/948D prior to revision 2k";
448 case 0x0006: return "ATA-3 X3T10/2008D revision 1";
449 case 0x0007: return "ATA-2 X3T10/948D revision 2k";
450 case 0x0008: return "ATA-3 X3T10/2008D revision 0";
451 case 0x0009: return "ATA-2 X3T10/948D revision 3";
452 case 0x000a: return "ATA-3 published, ANSI X3.298-1997";
453 case 0x000b: return "ATA-3 X3T10/2008D revision 6"; // 1st ATA-3 revision with SMART
454 case 0x000c: return "ATA-3 X3T13/2008D revision 7 and 7a";
455 case 0x000d: return "ATA/ATAPI-4 X3T13/1153D revision 6";
456 case 0x000e: return "ATA/ATAPI-4 T13/1153D revision 13";
457 case 0x000f: return "ATA/ATAPI-4 X3T13/1153D revision 7";
458 case 0x0010: return "ATA/ATAPI-4 T13/1153D revision 18";
459 case 0x0011: return "ATA/ATAPI-4 T13/1153D revision 15";
460 case 0x0012: return "ATA/ATAPI-4 published, ANSI NCITS 317-1998";
461 case 0x0013: return "ATA/ATAPI-5 T13/1321D revision 3";
462 case 0x0014: return "ATA/ATAPI-4 T13/1153D revision 14";
463 case 0x0015: return "ATA/ATAPI-5 T13/1321D revision 1";
464 case 0x0016: return "ATA/ATAPI-5 published, ANSI NCITS 340-2000";
465 case 0x0017: return "ATA/ATAPI-4 T13/1153D revision 17";
466 case 0x0018: return "ATA/ATAPI-6 T13/1410D revision 0";
467 case 0x0019: return "ATA/ATAPI-6 T13/1410D revision 3a";
468 case 0x001a: return "ATA/ATAPI-7 T13/1532D revision 1";
469 case 0x001b: return "ATA/ATAPI-6 T13/1410D revision 2";
470 case 0x001c: return "ATA/ATAPI-6 T13/1410D revision 1";
471 case 0x001d: return "ATA/ATAPI-7 published, ANSI INCITS 397-2005";
472 case 0x001e: return "ATA/ATAPI-7 T13/1532D revision 0";
473 case 0x001f: return "ACS-3 T13/2161-D revision 3b";
475 case 0x0021: return "ATA/ATAPI-7 T13/1532D revision 4a";
476 case 0x0022: return "ATA/ATAPI-6 published, ANSI INCITS 361-2002";
478 case 0x0027: return "ATA8-ACS T13/1699-D revision 3c";
479 case 0x0028: return "ATA8-ACS T13/1699-D revision 6";
480 case 0x0029: return "ATA8-ACS T13/1699-D revision 4";
482 case 0x0031: return "ACS-2 T13/2015-D revision 2";
484 case 0x0033: return "ATA8-ACS T13/1699-D revision 3e";
486 case 0x0039: return "ATA8-ACS T13/1699-D revision 4c";
488 case 0x0042: return "ATA8-ACS T13/1699-D revision 3f";
490 case 0x0052: return "ATA8-ACS T13/1699-D revision 3b";
492 case 0x0107: return "ATA8-ACS T13/1699-D revision 2d";
494 case 0x0110: return "ACS-2 T13/2015-D revision 3";
500 static const char * get_sata_version(const ata_identify_device
* drive
)
502 unsigned short word222
= drive
->words088_255
[222-88];
503 if ((word222
& 0xf000) != 0x1000)
505 switch (find_msb(word222
& 0x0fff)) {
506 default: return "SATA >3.1";
507 case 6: return "SATA 3.1";
508 case 5: return "SATA 3.0";
509 case 4: return "SATA 2.6";
510 case 3: return "SATA 2.5";
511 case 2: return "SATA II Ext";
512 case 1: return "SATA 1.0a";
513 case 0: return "ATA8-AST";
518 static const char * get_sata_speed(int level
)
523 default: return ">6.0 Gb/s";
524 case 3: return "6.0 Gb/s";
525 case 2: return "3.0 Gb/s";
526 case 1: return "1.5 Gb/s";
530 static const char * get_sata_maxspeed(const ata_identify_device
* drive
)
532 unsigned short word076
= drive
->words047_079
[76-47];
533 if (word076
& 0x0001)
535 return get_sata_speed(find_msb(word076
& 0x00fe));
538 static const char * get_sata_curspeed(const ata_identify_device
* drive
)
540 unsigned short word077
= drive
->words047_079
[77-47];
541 if (word077
& 0x0001)
543 return get_sata_speed((word077
>> 1) & 0x7);
547 static void print_drive_info(const ata_identify_device
* drive
,
548 const ata_size_info
& sizes
, int rpm
,
549 const drive_settings
* dbentry
)
551 // format drive information (with byte swapping as needed)
552 char model
[40+1], serial
[20+1], firmware
[8+1];
553 ata_format_id_string(model
, drive
->model
, sizeof(model
)-1);
554 ata_format_id_string(serial
, drive
->serial_no
, sizeof(serial
)-1);
555 ata_format_id_string(firmware
, drive
->fw_rev
, sizeof(firmware
)-1);
557 // Print model family if known
558 if (dbentry
&& *dbentry
->modelfamily
)
559 pout("Model Family: %s\n", dbentry
->modelfamily
);
561 pout("Device Model: %s\n", infofound(model
));
562 if (!dont_print_serial_number
) {
563 pout("Serial Number: %s\n", infofound(serial
));
565 unsigned oui
= 0; uint64_t unique_id
= 0;
566 int naa
= ata_get_wwn(drive
, oui
, unique_id
);
568 pout("LU WWN Device Id: %x %06x %09" PRIx64
"\n", naa
, oui
, unique_id
);
570 // Additional Product Identifier (OEM Id) string in words 170-173
571 // (e08130r1, added in ACS-2 Revision 1, December 17, 2008)
572 if (0x2020 <= drive
->words088_255
[170-88] && drive
->words088_255
[170-88] <= 0x7e7e) {
574 ata_format_id_string(add
, (const unsigned char *)(drive
->words088_255
+170-88), sizeof(add
)-1);
576 pout("Add. Product Id: %s\n", add
);
579 pout("Firmware Version: %s\n", infofound(firmware
));
581 if (sizes
.capacity
) {
583 char num
[64], cap
[32];
584 pout("User Capacity: %s bytes [%s]\n",
585 format_with_thousands_sep(num
, sizeof(num
), sizes
.capacity
),
586 format_capacity(cap
, sizeof(cap
), sizes
.capacity
));
588 // Print sector sizes.
589 if (sizes
.phy_sector_size
== sizes
.log_sector_size
)
590 pout("Sector Size: %u bytes logical/physical\n", sizes
.log_sector_size
);
592 pout("Sector Sizes: %u bytes logical, %u bytes physical",
593 sizes
.log_sector_size
, sizes
.phy_sector_size
);
594 if (sizes
.log_sector_offset
)
595 pout(" (offset %u bytes)", sizes
.log_sector_offset
);
600 // Print nominal media rotation rate if reported
603 pout("Rotation Rate: Solid State Device\n");
605 pout("Rotation Rate: %d rpm\n", rpm
);
607 pout("Rotation Rate: Unknown (0x%04x)\n", -rpm
);
610 // Print form factor if reported
611 unsigned short word168
= drive
->words088_255
[168-88];
615 case 0x1: inches
= "5.25"; break;
616 case 0x2: inches
= "3.5"; break;
617 case 0x3: inches
= "2.5"; break;
618 case 0x4: inches
= "1.8"; break;
619 case 0x5: inches
= "< 1.8"; break;
620 default : inches
= 0;
623 pout("Form Factor: %s inches\n", inches
);
625 pout("Form Factor: Unknown (0x%04x)\n", word168
);
628 // See if drive is recognized
629 pout("Device is: %s\n", !dbentry
?
630 "Not in smartctl database [for details use: -P showall]":
631 "In smartctl database [for details use: -P show]");
635 if ( (drive
->major_rev_num
!= 0x0000 && drive
->major_rev_num
!= 0xffff)
636 || (drive
->minor_rev_num
!= 0x0000 && drive
->minor_rev_num
!= 0xffff)) {
637 const char * majorver
= get_ata_major_version(drive
);
638 const char * minorver
= get_ata_minor_version(drive
);
640 if (majorver
&& minorver
&& str_starts_with(minorver
, majorver
)) {
641 // Major and minor strings match, print minor string only
648 ataver
= strprintf("Unknown(0x%04x)", drive
->major_rev_num
);
651 ataver
+= strprintf(", %s", minorver
);
652 else if (drive
->minor_rev_num
!= 0x0000 && drive
->minor_rev_num
!= 0xffff)
653 ataver
+= strprintf(" (unknown minor revision code: 0x%04x)", drive
->minor_rev_num
);
655 ataver
+= " (minor revision not indicated)";
658 pout("ATA Version is: %s\n", infofound(ataver
.c_str()));
660 // If SATA drive print SATA version and speed
661 const char * sataver
= get_sata_version(drive
);
663 const char * maxspeed
= get_sata_maxspeed(drive
);
664 const char * curspeed
= get_sata_curspeed(drive
);
665 pout("SATA Version is: %s%s%s%s%s%s\n", sataver
,
666 (maxspeed
? ", " : ""), (maxspeed
? maxspeed
: ""),
667 (curspeed
? " (current: " : ""), (curspeed
? curspeed
: ""),
668 (curspeed
? ")" : ""));
671 // print current time and date and timezone
672 char timedatetz
[DATEANDEPOCHLEN
]; dateandtimezone(timedatetz
);
673 pout("Local Time is: %s\n", timedatetz
);
675 // Print warning message, if there is one
676 if (dbentry
&& *dbentry
->warningmsg
)
677 pout("\n==> WARNING: %s\n\n", dbentry
->warningmsg
);
680 static const char *OfflineDataCollectionStatus(unsigned char status_byte
)
682 unsigned char stat
=status_byte
& 0x7f;
686 return "was never started";
688 return "was completed without error";
690 if (status_byte
== 0x03)
691 return "is in progress";
693 return "is in a Reserved state";
695 return "was suspended by an interrupting command from host";
697 return "was aborted by an interrupting command from host";
699 return "was aborted by the device with a fatal error";
702 return "is in a Vendor Specific state";
704 return "is in a Reserved state";
709 // prints verbose value Off-line data collection status byte
710 static void PrintSmartOfflineStatus(const ata_smart_values
* data
)
712 pout("Offline data collection status: (0x%02x)\t",
713 (int)data
->offline_data_collection_status
);
715 // Off-line data collection status byte is not a reserved
716 // or vendor specific value
717 pout("Offline data collection activity\n"
718 "\t\t\t\t\t%s.\n", OfflineDataCollectionStatus(data
->offline_data_collection_status
));
720 // Report on Automatic Data Collection Status. Only IBM documents
721 // this bit. See SFF 8035i Revision 2 for details.
722 if (data
->offline_data_collection_status
& 0x80)
723 pout("\t\t\t\t\tAuto Offline Data Collection: Enabled.\n");
725 pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
730 static void PrintSmartSelfExecStatus(const ata_smart_values
* data
,
731 firmwarebug_defs firmwarebugs
)
733 pout("Self-test execution status: ");
735 switch (data
->self_test_exec_status
>> 4)
738 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
739 (int)data
->self_test_exec_status
);
740 pout("without error or no self-test has ever \n\t\t\t\t\tbeen run.\n");
743 pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
744 (int)data
->self_test_exec_status
);
748 pout("(%4d)\tThe self-test routine was interrupted\n\t\t\t\t\t",
749 (int)data
->self_test_exec_status
);
750 pout("by the host with a hard or soft reset.\n");
753 pout("(%4d)\tA fatal error or unknown test error\n\t\t\t\t\t",
754 (int)data
->self_test_exec_status
);
755 pout("occurred while the device was executing\n\t\t\t\t\t");
756 pout("its self-test routine and the device \n\t\t\t\t\t");
757 pout("was unable to complete the self-test \n\t\t\t\t\t");
761 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
762 (int)data
->self_test_exec_status
);
763 pout("a test element that failed and the test\n\t\t\t\t\t");
764 pout("element that failed is not known.\n");
767 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
768 (int)data
->self_test_exec_status
);
769 pout("the electrical element of the test\n\t\t\t\t\t");
773 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
774 (int)data
->self_test_exec_status
);
775 pout("the servo (and/or seek) element of the \n\t\t\t\t\t");
776 pout("test failed.\n");
779 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
780 (int)data
->self_test_exec_status
);
781 pout("the read element of the test failed.\n");
784 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
785 (int)data
->self_test_exec_status
);
786 pout("a test element that failed and the\n\t\t\t\t\t");
787 pout("device is suspected of having handling\n\t\t\t\t\t");
791 if (firmwarebugs
.is_set(BUG_SAMSUNG3
) && data
->self_test_exec_status
== 0xf0) {
792 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
793 (int)data
->self_test_exec_status
);
794 pout("with unknown result or self-test in\n\t\t\t\t\t");
795 pout("progress with less than 10%% remaining.\n");
798 pout("(%4d)\tSelf-test routine in progress...\n\t\t\t\t\t",
799 (int)data
->self_test_exec_status
);
800 pout("%1d0%% of test remaining.\n",
801 (int)(data
->self_test_exec_status
& 0x0f));
805 pout("(%4d)\tReserved.\n",
806 (int)data
->self_test_exec_status
);
812 static void PrintSmartTotalTimeCompleteOffline (const ata_smart_values
* data
)
814 pout("Total time to complete Offline \n");
815 pout("data collection: \t\t(%5d) seconds.\n",
816 (int)data
->total_time_to_complete_off_line
);
819 static void PrintSmartOfflineCollectCap(const ata_smart_values
*data
)
821 pout("Offline data collection\n");
822 pout("capabilities: \t\t\t (0x%02x) ",
823 (int)data
->offline_data_collection_capability
);
825 if (data
->offline_data_collection_capability
== 0x00){
826 pout("\tOffline data collection not supported.\n");
829 pout( "%s\n", isSupportExecuteOfflineImmediate(data
)?
830 "SMART execute Offline immediate." :
831 "No SMART execute Offline immediate.");
833 pout( "\t\t\t\t\t%s\n", isSupportAutomaticTimer(data
)?
834 "Auto Offline data collection on/off support.":
835 "No Auto Offline data collection support.");
837 pout( "\t\t\t\t\t%s\n", isSupportOfflineAbort(data
)?
838 "Abort Offline collection upon new\n\t\t\t\t\tcommand.":
839 "Suspend Offline collection upon new\n\t\t\t\t\tcommand.");
841 pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data
)?
842 "Offline surface scan supported.":
843 "No Offline surface scan supported.");
845 pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data
)?
846 "Self-test supported.":
847 "No Self-test supported.");
849 pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data
)?
850 "Conveyance Self-test supported.":
851 "No Conveyance Self-test supported.");
853 pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data
)?
854 "Selective Self-test supported.":
855 "No Selective Self-test supported.");
859 static void PrintSmartCapability(const ata_smart_values
*data
)
861 pout("SMART capabilities: ");
862 pout("(0x%04x)\t", (int)data
->smart_capability
);
864 if (data
->smart_capability
== 0x00)
866 pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
871 pout( "%s\n", (data
->smart_capability
& 0x01)?
872 "Saves SMART data before entering\n\t\t\t\t\tpower-saving mode.":
873 "Does not save SMART data before\n\t\t\t\t\tentering power-saving mode.");
875 if ( data
->smart_capability
& 0x02 )
877 pout("\t\t\t\t\tSupports SMART auto save timer.\n");
882 static void PrintSmartErrorLogCapability(const ata_smart_values
* data
, const ata_identify_device
* identity
)
884 pout("Error logging capability: ");
886 if ( isSmartErrorLogCapable(data
, identity
) )
888 pout(" (0x%02x)\tError logging supported.\n",
889 (int)data
->errorlog_capability
);
892 pout(" (0x%02x)\tError logging NOT supported.\n",
893 (int)data
->errorlog_capability
);
897 static void PrintSmartShortSelfTestPollingTime(const ata_smart_values
* data
)
899 pout("Short self-test routine \n");
900 if (isSupportSelfTest(data
))
901 pout("recommended polling time: \t (%4d) minutes.\n",
902 (int)data
->short_test_completion_time
);
904 pout("recommended polling time: \t Not Supported.\n");
907 static void PrintSmartExtendedSelfTestPollingTime(const ata_smart_values
* data
)
909 pout("Extended self-test routine\n");
910 if (isSupportSelfTest(data
))
911 pout("recommended polling time: \t (%4d) minutes.\n",
912 TestTime(data
, EXTEND_SELF_TEST
));
914 pout("recommended polling time: \t Not Supported.\n");
917 static void PrintSmartConveyanceSelfTestPollingTime(const ata_smart_values
* data
)
919 pout("Conveyance self-test routine\n");
920 if (isSupportConveyanceSelfTest(data
))
921 pout("recommended polling time: \t (%4d) minutes.\n",
922 (int)data
->conveyance_test_completion_time
);
924 pout("recommended polling time: \t Not Supported.\n");
927 // Check SMART attribute table for Threshold failure
928 // onlyfailed=0: are or were any age or prefailure attributes <= threshold
929 // onlyfailed=1: are any prefailure attributes <= threshold now
930 static int find_failed_attr(const ata_smart_values
* data
,
931 const ata_smart_thresholds_pvt
* thresholds
,
932 const ata_vendor_attr_defs
& defs
, int onlyfailed
)
934 for (int i
= 0; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
935 const ata_smart_attribute
& attr
= data
->vendor_attributes
[i
];
937 ata_attr_state state
= ata_get_attr_state(attr
, i
, thresholds
->thres_entries
, defs
);
940 if (state
>= ATTRSTATE_FAILED_PAST
)
944 if (state
== ATTRSTATE_FAILED_NOW
&& ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
))
951 // onlyfailed=0 : print all attribute values
952 // onlyfailed=1: just ones that are currently failed and have prefailure bit set
953 // onlyfailed=2: ones that are failed, or have failed with or without prefailure bit set
954 static void PrintSmartAttribWithThres(const ata_smart_values
* data
,
955 const ata_smart_thresholds_pvt
* thresholds
,
956 const ata_vendor_attr_defs
& defs
, int rpm
,
957 int onlyfailed
, unsigned char format
)
959 bool brief
= !!(format
& ata_print_options::FMT_BRIEF
);
960 bool hexid
= !!(format
& ata_print_options::FMT_HEX_ID
);
961 bool hexval
= !!(format
& ata_print_options::FMT_HEX_VAL
);
962 bool needheader
= true;
964 // step through all vendor attributes
965 for (int i
= 0; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
966 const ata_smart_attribute
& attr
= data
->vendor_attributes
[i
];
968 // Check attribute and threshold
969 unsigned char threshold
= 0;
970 ata_attr_state state
= ata_get_attr_state(attr
, i
, thresholds
->thres_entries
, defs
, &threshold
);
971 if (state
== ATTRSTATE_NON_EXISTING
)
974 // These break out of the loop if we are only printing certain entries...
975 if (onlyfailed
== 1 && !(ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
) && state
== ATTRSTATE_FAILED_NOW
))
978 if (onlyfailed
== 2 && state
< ATTRSTATE_FAILED_PAST
)
981 // print header only if needed
984 pout("SMART Attributes Data Structure revision number: %d\n",(int)data
->revnumber
);
985 pout("Vendor Specific SMART Attributes with Thresholds:\n");
988 pout("ID#%s ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n",
989 (!hexid
? "" : " "));
991 pout("ID#%s ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE\n",
992 (!hexid
? "" : " "));
996 // Format value, worst, threshold
997 std::string valstr
, worstr
, threstr
;
998 if (state
> ATTRSTATE_NO_NORMVAL
)
999 valstr
= (!hexval
? strprintf("%.3d", attr
.current
)
1000 : strprintf("0x%02x", attr
.current
));
1002 valstr
= (!hexval
? "---" : "----");
1003 if (!(defs
[attr
.id
].flags
& ATTRFLAG_NO_WORSTVAL
))
1004 worstr
= (!hexval
? strprintf("%.3d", attr
.worst
)
1005 : strprintf("0x%02x", attr
.worst
));
1007 worstr
= (!hexval
? "---" : "----");
1008 if (state
> ATTRSTATE_NO_THRESHOLD
)
1009 threstr
= (!hexval
? strprintf("%.3d", threshold
)
1010 : strprintf("0x%02x", threshold
));
1012 threstr
= (!hexval
? "---" : "----");
1014 // Print line for each valid attribute
1015 std::string idstr
= (!hexid
? strprintf("%3d", attr
.id
)
1016 : strprintf("0x%02x", attr
.id
));
1017 std::string attrname
= ata_get_smart_attr_name(attr
.id
, defs
, rpm
);
1018 std::string rawstr
= ata_format_attr_raw_value(attr
, defs
);
1021 pout("%s %-24s0x%04x %-4s %-4s %-4s %-10s%-9s%-12s%s\n",
1022 idstr
.c_str(), attrname
.c_str(), attr
.flags
,
1023 valstr
.c_str(), worstr
.c_str(), threstr
.c_str(),
1024 (ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
) ? "Pre-fail" : "Old_age"),
1025 (ATTRIBUTE_FLAGS_ONLINE(attr
.flags
) ? "Always" : "Offline"),
1026 (state
== ATTRSTATE_FAILED_NOW
? "FAILING_NOW" :
1027 state
== ATTRSTATE_FAILED_PAST
? "In_the_past"
1031 pout("%s %-24s%c%c%c%c%c%c%c %-4s %-4s %-4s %-5s%s\n",
1032 idstr
.c_str(), attrname
.c_str(),
1033 (ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
) ? 'P' : '-'),
1034 (ATTRIBUTE_FLAGS_ONLINE(attr
.flags
) ? 'O' : '-'),
1035 (ATTRIBUTE_FLAGS_PERFORMANCE(attr
.flags
) ? 'S' : '-'),
1036 (ATTRIBUTE_FLAGS_ERRORRATE(attr
.flags
) ? 'R' : '-'),
1037 (ATTRIBUTE_FLAGS_EVENTCOUNT(attr
.flags
) ? 'C' : '-'),
1038 (ATTRIBUTE_FLAGS_SELFPRESERVING(attr
.flags
) ? 'K' : '-'),
1039 (ATTRIBUTE_FLAGS_OTHER(attr
.flags
) ? '+' : ' '),
1040 valstr
.c_str(), worstr
.c_str(), threstr
.c_str(),
1041 (state
== ATTRSTATE_FAILED_NOW
? "NOW" :
1042 state
== ATTRSTATE_FAILED_PAST
? "Past"
1049 if (!onlyfailed
&& brief
) {
1050 int n
= (!hexid
? 28 : 29);
1051 pout("%*s||||||_ K auto-keep\n"
1052 "%*s|||||__ C event count\n"
1053 "%*s||||___ R error rate\n"
1054 "%*s|||____ S speed/performance\n"
1055 "%*s||_____ O updated online\n"
1056 "%*s|______ P prefailure warning\n",
1057 n
, "", n
, "", n
, "", n
, "", n
, "", n
, "");
1063 // Print SMART related SCT capabilities
1064 static void ataPrintSCTCapability(const ata_identify_device
*drive
)
1066 unsigned short sctcaps
= drive
->words088_255
[206-88];
1067 if (!(sctcaps
& 0x01))
1069 pout("SCT capabilities: \t (0x%04x)\tSCT Status supported.\n", sctcaps
);
1071 pout("\t\t\t\t\tSCT Error Recovery Control supported.\n");
1073 pout("\t\t\t\t\tSCT Feature Control supported.\n");
1075 pout("\t\t\t\t\tSCT Data Table supported.\n");
1079 static void PrintGeneralSmartValues(const ata_smart_values
*data
, const ata_identify_device
*drive
,
1080 firmwarebug_defs firmwarebugs
)
1082 pout("General SMART Values:\n");
1084 PrintSmartOfflineStatus(data
);
1086 if (isSupportSelfTest(data
)){
1087 PrintSmartSelfExecStatus(data
, firmwarebugs
);
1090 PrintSmartTotalTimeCompleteOffline(data
);
1091 PrintSmartOfflineCollectCap(data
);
1092 PrintSmartCapability(data
);
1094 PrintSmartErrorLogCapability(data
, drive
);
1096 pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive
)?
1097 "General Purpose Logging supported.":
1098 "No General Purpose Logging support.");
1100 if (isSupportSelfTest(data
)){
1101 PrintSmartShortSelfTestPollingTime (data
);
1102 PrintSmartExtendedSelfTestPollingTime (data
);
1104 if (isSupportConveyanceSelfTest(data
))
1105 PrintSmartConveyanceSelfTestPollingTime (data
);
1107 ataPrintSCTCapability(drive
);
1112 // Get # sectors of a log addr, 0 if log does not exist.
1113 static unsigned GetNumLogSectors(const ata_smart_log_directory
* logdir
, unsigned logaddr
, bool gpl
)
1121 unsigned n
= logdir
->entry
[logaddr
-1].numsectors
;
1123 // GP logs may have >255 sectors
1124 n
|= logdir
->entry
[logaddr
-1].reserved
<< 8;
1129 // Table A.2 of T13/2161-D (ACS-3) Revision 4, September 4, 2012
1130 static const char * GetLogName(unsigned logaddr
)
1133 case 0x00: return "Log Directory";
1134 case 0x01: return "Summary SMART error log";
1135 case 0x02: return "Comprehensive SMART error log";
1136 case 0x03: return "Ext. Comprehensive SMART error log";
1137 case 0x04: return "Device Statistics log";
1138 case 0x05: return "Reserved for CFA"; // ACS-2
1139 case 0x06: return "SMART self-test log";
1140 case 0x07: return "Extended self-test log";
1141 case 0x08: return "Power Conditions log"; // ACS-2
1142 case 0x09: return "Selective self-test log";
1143 case 0x0a: return "Device Statistics Notification"; // ACS-3
1144 case 0x0b: return "Reserved for CFA"; // ACS-3
1145 case 0x0c: return "Pending Defects log"; // ACS-4
1146 case 0x0d: return "LPS Mis-alignment log"; // ACS-2
1148 case 0x10: return "NCQ Command Error log";
1149 case 0x11: return "SATA Phy Event Counters";
1150 case 0x12: return "SATA NCQ Queue Management log"; // ACS-3
1151 case 0x13: return "SATA NCQ Send and Receive log"; // ACS-3
1155 case 0x17: return "Reserved for Serial ATA";
1157 case 0x19: return "LBA Status log"; // ACS-3
1159 case 0x20: return "Streaming performance log [OBS-8]";
1160 case 0x21: return "Write stream error log";
1161 case 0x22: return "Read stream error log";
1162 case 0x23: return "Delayed sector log [OBS-8]";
1163 case 0x24: return "Current Device Internal Status Data log"; // ACS-3
1164 case 0x25: return "Saved Device Internal Status Data log"; // ACS-3
1166 case 0x30: return "IDENTIFY DEVICE data log"; // ACS-3
1168 case 0xe0: return "SCT Command/Status";
1169 case 0xe1: return "SCT Data Transfer";
1171 if (0xa0 <= logaddr
&& logaddr
<= 0xdf)
1172 return "Device vendor specific log";
1173 if (0x80 <= logaddr
&& logaddr
<= 0x9f)
1174 return "Host vendor specific log";
1180 // Get log access permissions
1181 static const char * get_log_rw(unsigned logaddr
)
1183 if ( ( logaddr
<= 0x08)
1184 || (0x0c <= logaddr
&& logaddr
<= 0x0d)
1185 || (0x10 <= logaddr
&& logaddr
<= 0x13)
1186 || (0x19 == logaddr
)
1187 || (0x20 <= logaddr
&& logaddr
<= 0x25)
1188 || (0x30 == logaddr
))
1191 if ( (0x09 <= logaddr
&& logaddr
<= 0x0a)
1192 || (0x80 <= logaddr
&& logaddr
<= 0x9f)
1193 || (0xe0 <= logaddr
&& logaddr
<= 0xe1))
1196 if (0xa0 <= logaddr
&& logaddr
<= 0xdf)
1197 return "VS"; // Vendor specific
1199 return "-"; // Unknown/Reserved
1202 // Init a fake log directory, assume that standard logs are supported
1203 const ata_smart_log_directory
* fake_logdir(ata_smart_log_directory
* logdir
,
1204 const ata_print_options
& options
)
1206 memset(logdir
, 0, sizeof(*logdir
));
1207 logdir
->logversion
= 255;
1208 logdir
->entry
[0x01-1].numsectors
= 1;
1209 logdir
->entry
[0x03-1].numsectors
= (options
.smart_ext_error_log
+ (4-1)) / 4;
1210 logdir
->entry
[0x04-1].numsectors
= 8;
1211 logdir
->entry
[0x06-1].numsectors
= 1;
1212 logdir
->entry
[0x07-1].numsectors
= (options
.smart_ext_selftest_log
+ (19-1)) / 19;
1213 logdir
->entry
[0x09-1].numsectors
= 1;
1214 logdir
->entry
[0x11-1].numsectors
= 1;
1218 // Print SMART and/or GP Log Directory
1219 static void PrintLogDirectories(const ata_smart_log_directory
* gplogdir
,
1220 const ata_smart_log_directory
* smartlogdir
)
1223 pout("General Purpose Log Directory Version %u\n", gplogdir
->logversion
);
1225 pout("SMART %sLog Directory Version %u%s\n",
1226 (gplogdir
? " " : ""), smartlogdir
->logversion
,
1227 (smartlogdir
->logversion
==1 ? " [multi-sector log support]" : ""));
1229 pout("Address Access R/W Size Description\n");
1231 for (unsigned i
= 0; i
<= 0xff; i
++) {
1232 // Get number of sectors
1233 unsigned smart_numsect
= GetNumLogSectors(smartlogdir
, i
, false);
1234 unsigned gp_numsect
= GetNumLogSectors(gplogdir
, i
, true );
1236 if (!(smart_numsect
|| gp_numsect
))
1237 continue; // Log does not exist
1239 const char * acc
; unsigned size
;
1240 if (smart_numsect
== gp_numsect
) {
1241 acc
= "GPL,SL"; size
= gp_numsect
;
1243 else if (!smart_numsect
) {
1244 acc
= "GPL"; size
= gp_numsect
;
1246 else if (!gp_numsect
) {
1247 acc
= " SL"; size
= smart_numsect
;
1254 if (acc
&& ((0x80 <= i
&& i
< 0x9f) || (0xa0 <= i
&& i
< 0xdf))) {
1255 // Find range of Host/Device vendor specific logs with same size
1256 unsigned imax
= (i
< 0x9f ? 0x9f : 0xdf);
1257 for (unsigned j
= i
+1; j
<= imax
; j
++) {
1258 unsigned sn
= GetNumLogSectors(smartlogdir
, j
, false);
1259 unsigned gn
= GetNumLogSectors(gplogdir
, j
, true );
1261 if (!(sn
== smart_numsect
&& gn
== gp_numsect
))
1267 const char * name
= GetLogName(i
);
1268 const char * rw
= get_log_rw(i
);
1271 pout("0x%02x-0x%02x %-6s %-3s %5u %s\n", i
, i2
, acc
, rw
, size
, name
);
1275 pout( "0x%02x %-6s %-3s %5u %s\n", i
, acc
, rw
, size
, name
);
1277 // GPL and SL support different sizes
1278 pout( "0x%02x %-6s %-3s %5u %s\n", i
, "GPL", rw
, gp_numsect
, name
);
1279 pout( "0x%02x %-6s %-3s %5u %s\n", i
, "SL", rw
, smart_numsect
, name
);
1285 // Print hexdump of log pages.
1286 // Format is compatible with 'xxd -r'.
1287 static void PrintLogPages(const char * type
, const unsigned char * data
,
1288 unsigned char logaddr
, unsigned page
,
1289 unsigned num_pages
, unsigned max_pages
)
1291 pout("%s Log 0x%02x [%s], Page %u-%u (of %u)\n",
1292 type
, logaddr
, GetLogName(logaddr
), page
, page
+num_pages
-1, max_pages
);
1293 for (unsigned i
= 0; i
< num_pages
* 512; i
+= 16) {
1294 const unsigned char * p
= data
+i
;
1295 pout("%07x: %02x %02x %02x %02x %02x %02x %02x %02x "
1296 "%02x %02x %02x %02x %02x %02x %02x %02x ",
1298 p
[ 0], p
[ 1], p
[ 2], p
[ 3], p
[ 4], p
[ 5], p
[ 6], p
[ 7],
1299 p
[ 8], p
[ 9], p
[10], p
[11], p
[12], p
[13], p
[14], p
[15]);
1300 #define P(n) (' ' <= p[n] && p[n] <= '~' ? (int)p[n] : '.')
1301 pout("|%c%c%c%c%c%c%c%c"
1302 "%c%c%c%c%c%c%c%c|\n",
1303 P( 0), P( 1), P( 2), P( 3), P( 4), P( 5), P( 6), P( 7),
1304 P( 8), P( 9), P(10), P(11), P(12), P(13), P(14), P(15));
1306 if ((i
& 0x1ff) == 0x1f0)
1311 ///////////////////////////////////////////////////////////////////////
1312 // Device statistics (Log 0x04)
1314 // See Section A.5 of
1315 // ATA/ATAPI Command Set - 3 (ACS-3)
1316 // T13/2161-D Revision 2, February 21, 2012.
1318 struct devstat_entry_info
1320 short size
; // #bytes of value, -1 for signed char
1324 const devstat_entry_info devstat_info_0x00
[] = {
1325 { 2, "List of supported log pages" },
1329 const devstat_entry_info devstat_info_0x01
[] = {
1330 { 2, "General Statistics" },
1331 { 4, "Lifetime Power-On Resets" },
1332 { 4, "Power-on Hours" }, // spec says no flags(?)
1333 { 6, "Logical Sectors Written" },
1334 { 6, "Number of Write Commands" },
1335 { 6, "Logical Sectors Read" },
1336 { 6, "Number of Read Commands" },
1337 { 6, "Date and Time TimeStamp" }, // ACS-3
1341 const devstat_entry_info devstat_info_0x02
[] = {
1342 { 2, "Free-Fall Statistics" },
1343 { 4, "Number of Free-Fall Events Detected" },
1344 { 4, "Overlimit Shock Events" },
1348 const devstat_entry_info devstat_info_0x03
[] = {
1349 { 2, "Rotating Media Statistics" },
1350 { 4, "Spindle Motor Power-on Hours" },
1351 { 4, "Head Flying Hours" },
1352 { 4, "Head Load Events" },
1353 { 4, "Number of Reallocated Logical Sectors" },
1354 { 4, "Read Recovery Attempts" },
1355 { 4, "Number of Mechanical Start Failures" },
1356 { 4, "Number of Realloc. Candidate Logical Sectors" }, // ACS-3
1360 const devstat_entry_info devstat_info_0x04
[] = {
1361 { 2, "General Errors Statistics" },
1362 { 4, "Number of Reported Uncorrectable Errors" },
1363 //{ 4, "Number of Resets Between Command Acceptance and Command Completion" },
1364 { 4, "Resets Between Cmd Acceptance and Completion" },
1368 const devstat_entry_info devstat_info_0x05
[] = {
1369 { 2, "Temperature Statistics" },
1370 { -1, "Current Temperature" },
1371 { -1, "Average Short Term Temperature" },
1372 { -1, "Average Long Term Temperature" },
1373 { -1, "Highest Temperature" },
1374 { -1, "Lowest Temperature" },
1375 { -1, "Highest Average Short Term Temperature" },
1376 { -1, "Lowest Average Short Term Temperature" },
1377 { -1, "Highest Average Long Term Temperature" },
1378 { -1, "Lowest Average Long Term Temperature" },
1379 { 4, "Time in Over-Temperature" },
1380 { -1, "Specified Maximum Operating Temperature" },
1381 { 4, "Time in Under-Temperature" },
1382 { -1, "Specified Minimum Operating Temperature" },
1386 const devstat_entry_info devstat_info_0x06
[] = {
1387 { 2, "Transport Statistics" },
1388 { 4, "Number of Hardware Resets" },
1389 { 4, "Number of ASR Events" },
1390 { 4, "Number of Interface CRC Errors" },
1394 const devstat_entry_info devstat_info_0x07
[] = {
1395 { 2, "Solid State Device Statistics" },
1396 { 1, "Percentage Used Endurance Indicator" },
1400 const devstat_entry_info
* devstat_infos
[] = {
1411 const int num_devstat_infos
= sizeof(devstat_infos
)/sizeof(devstat_infos
[0]);
1413 static void print_device_statistics_page(const unsigned char * data
, int page
,
1414 bool & need_trailer
)
1416 const devstat_entry_info
* info
= (page
< num_devstat_infos
? devstat_infos
[page
] : 0);
1417 const char * name
= (info
? info
[0].name
: "Unknown Statistics");
1419 // Check page number in header
1420 static const char line
[] = " ===== = = == ";
1422 pout("%3d%s%s (empty) ==\n", page
, line
, name
);
1425 if (data
[2] != page
) {
1426 pout("%3d%s%s (invalid page %d in header) ==\n", page
, line
, name
, data
[2]);
1430 pout("%3d%s%s (rev %d) ==\n", page
, line
, name
, data
[0]);
1433 for (int i
= 1, offset
= 8; offset
< 512-7; i
++, offset
+=8) {
1434 // Check for last known entry
1435 if (info
&& !info
[i
].size
)
1438 // Skip unsupported entries
1439 unsigned char flags
= data
[offset
+7];
1440 if (!(flags
& 0x80))
1443 // Stop if unknown entries contain garbage data due to buggy firmware
1444 if (!info
&& (data
[offset
+5] || data
[offset
+6])) {
1445 pout("%3d 0x%03x - - [Trailing garbage ignored]\n", page
, offset
);
1449 // Get value size, default to max if unknown
1450 int size
= (info
? info
[i
].size
: 7);
1454 if (flags
& 0x40) { // valid flag
1458 val
= (signed char)data
[offset
];
1462 for (int j
= 0; j
< size
; j
++)
1463 val
|= (int64_t)data
[offset
+j
] << (j
*8);
1465 snprintf(valstr
, sizeof(valstr
), "%" PRId64
, val
);
1468 // Value not known (yet)
1469 valstr
[0] = '-'; valstr
[1] = 0;
1472 pout("%3d 0x%03x %d%c %15s%c %s\n",
1475 (flags
& 0x1f ? '+' : ' '), // unknown flags
1477 (flags
& 0x20 ? '~' : ' '), // normalized flag
1478 (info
? info
[i
].name
: "Unknown"));
1480 need_trailer
= true;
1484 static bool print_device_statistics(ata_device
* device
, unsigned nsectors
,
1485 const std::vector
<int> & single_pages
, bool all_pages
, bool ssd_page
,
1488 // Read list of supported pages from page 0
1489 unsigned char page_0
[512] = {0, };
1493 rc
= ataReadLogExt(device
, 0x04, 0, 0, page_0
, 1);
1495 rc
= ataReadSmartLog(device
, 0x04, page_0
, 1);
1497 pout("Read Device Statistics page 0 failed\n\n");
1501 unsigned char nentries
= page_0
[8];
1502 if (!(page_0
[2] == 0 && nentries
> 0)) {
1503 pout("Device Statistics page 0 is invalid (page=%d, nentries=%d)\n\n", page_0
[2], nentries
);
1507 // Prepare list of pages to print
1508 std::vector
<int> pages
;
1511 // Add all supported pages
1512 for (i
= 0; i
< nentries
; i
++) {
1513 int page
= page_0
[8+1+i
];
1515 pages
.push_back(page
);
1519 // Add manually specified pages
1520 bool print_page_0
= false;
1521 for (i
= 0; i
< single_pages
.size() || ssd_page
; i
++) {
1522 int page
= (i
< single_pages
.size() ? single_pages
[i
] : 7);
1524 print_page_0
= true;
1525 else if (page
>= (int)nsectors
)
1526 pout("Device Statistics Log has only %u pages\n", nsectors
);
1528 pages
.push_back(page
);
1533 // Print list of supported pages if requested
1535 pout("Device Statistics (%s Log 0x04) supported pages\n",
1536 use_gplog
? "GP" : "SMART");
1537 pout("Page Description\n");
1538 for (i
= 0; i
< nentries
; i
++) {
1539 int page
= page_0
[8+1+i
];
1540 pout("%3d %s\n", page
,
1541 (page
< num_devstat_infos
? devstat_infos
[page
][0].name
: "Unknown Statistics"));
1546 // Read & print pages
1547 if (!pages
.empty()) {
1548 pout("Device Statistics (%s Log 0x04)\n",
1549 use_gplog
? "GP" : "SMART");
1550 pout("Page Offset Size Value Description\n");
1551 bool need_trailer
= false;
1555 for (i
= 0; i
< pages
.size(); i
++) {
1556 int page
= pages
[i
];
1557 if (max_page
< page
&& page
< 0xff)
1561 raw_buffer
pages_buf((max_page
+1) * 512);
1563 if (!use_gplog
&& !ataReadSmartLog(device
, 0x04, pages_buf
.data(), max_page
+1)) {
1564 pout("Read Device Statistics pages 0-%d failed\n\n", max_page
);
1568 for (i
= 0; i
< pages
.size(); i
++) {
1569 int page
= pages
[i
];
1570 if (use_gplog
&& !ataReadLogExt(device
, 0x04, 0, page
, pages_buf
.data(), 1)) {
1571 pout("Read Device Statistics page %d failed\n\n", page
);
1575 int offset
= (use_gplog
? 0 : page
* 512);
1576 print_device_statistics_page(pages_buf
.data() + offset
, page
, need_trailer
);
1580 pout("%30s|_ ~ normalized value\n", "");
1588 ///////////////////////////////////////////////////////////////////////
1591 static void PrintSataPhyEventCounters(const unsigned char * data
, bool reset
)
1594 checksumwarning("SATA Phy Event Counters");
1595 pout("SATA Phy Event Counters (GP Log 0x11)\n");
1596 if (data
[0] || data
[1] || data
[2] || data
[3])
1597 pout("[Reserved: 0x%02x 0x%02x 0x%02x 0x%02x]\n",
1598 data
[0], data
[1], data
[2], data
[3]);
1599 pout("ID Size Value Description\n");
1601 for (unsigned i
= 4; ; ) {
1602 // Get counter id and size (bits 14:12)
1603 unsigned id
= data
[i
] | (data
[i
+1] << 8);
1604 unsigned size
= ((id
>> 12) & 0x7) << 1;
1607 // End of counter table ?
1612 if (!(2 <= size
&& size
<= 8 && i
+ size
< 512)) {
1613 pout("0x%04x %u: Invalid entry\n", id
, size
);
1618 uint64_t val
= 0, max_val
= 0;
1619 for (unsigned j
= 0; j
< size
; j
+=2) {
1620 val
|= (uint64_t)(data
[i
+j
] | (data
[i
+j
+1] << 8)) << (j
*8);
1621 max_val
|= (uint64_t)0xffffU
<< (j
*8);
1628 case 0x001: name
= "Command failed due to ICRC error"; break; // Mandatory
1629 case 0x002: name
= "R_ERR response for data FIS"; break;
1630 case 0x003: name
= "R_ERR response for device-to-host data FIS"; break;
1631 case 0x004: name
= "R_ERR response for host-to-device data FIS"; break;
1632 case 0x005: name
= "R_ERR response for non-data FIS"; break;
1633 case 0x006: name
= "R_ERR response for device-to-host non-data FIS"; break;
1634 case 0x007: name
= "R_ERR response for host-to-device non-data FIS"; break;
1635 case 0x008: name
= "Device-to-host non-data FIS retries"; break;
1636 case 0x009: name
= "Transition from drive PhyRdy to drive PhyNRdy"; break;
1637 case 0x00A: name
= "Device-to-host register FISes sent due to a COMRESET"; break; // Mandatory
1638 case 0x00B: name
= "CRC errors within host-to-device FIS"; break;
1639 case 0x00D: name
= "Non-CRC errors within host-to-device FIS"; break;
1640 case 0x00F: name
= "R_ERR response for host-to-device data FIS, CRC"; break;
1641 case 0x010: name
= "R_ERR response for host-to-device data FIS, non-CRC"; break;
1642 case 0x012: name
= "R_ERR response for host-to-device non-data FIS, CRC"; break;
1643 case 0x013: name
= "R_ERR response for host-to-device non-data FIS, non-CRC"; break;
1644 default: name
= (id
& 0x8000 ? "Vendor specific" : "Unknown"); break;
1647 // Counters stop at max value, add '+' in this case
1648 pout("0x%04x %u %12" PRIu64
"%c %s\n", id
, size
, val
,
1649 (val
== max_val
? '+' : ' '), name
);
1652 pout("All counters reset\n");
1656 // Format milliseconds from error log entry as "DAYS+H:M:S.MSEC"
1657 static std::string
format_milliseconds(unsigned msec
)
1659 unsigned days
= msec
/ 86400000U;
1660 msec
-= days
* 86400000U;
1661 unsigned hours
= msec
/ 3600000U;
1662 msec
-= hours
* 3600000U;
1663 unsigned min
= msec
/ 60000U;
1664 msec
-= min
* 60000U;
1665 unsigned sec
= msec
/ 1000U;
1666 msec
-= sec
* 1000U;
1670 str
= strprintf("%2ud+", days
);
1671 str
+= strprintf("%02u:%02u:%02u.%03u", hours
, min
, sec
, msec
);
1675 // Get description for 'state' value from SMART Error Logs
1676 static const char * get_error_log_state_desc(unsigned state
)
1680 case 0x0: return "in an unknown state";
1681 case 0x1: return "sleeping";
1682 case 0x2: return "in standby mode";
1683 case 0x3: return "active or idle";
1684 case 0x4: return "doing SMART Offline or Self-test";
1686 return (state
< 0xb ? "in a reserved state"
1687 : "in a vendor specific state");
1691 // returns number of errors
1692 static int PrintSmartErrorlog(const ata_smart_errorlog
*data
,
1693 firmwarebug_defs firmwarebugs
)
1695 pout("SMART Error Log Version: %d\n", (int)data
->revnumber
);
1697 // if no errors logged, return
1698 if (!data
->error_log_pointer
){
1699 pout("No Errors Logged\n\n");
1703 // If log pointer out of range, return
1704 if (data
->error_log_pointer
>5){
1705 pout("Invalid Error Log index = 0x%02x (T13/1321D rev 1c "
1706 "Section 8.41.6.8.2.2 gives valid range from 1 to 5)\n\n",
1707 (int)data
->error_log_pointer
);
1711 // Some internal consistency checking of the data structures
1712 if ((data
->ata_error_count
-data
->error_log_pointer
) % 5 && !firmwarebugs
.is_set(BUG_SAMSUNG2
)) {
1713 pout("Warning: ATA error count %d inconsistent with error log pointer %d\n\n",
1714 data
->ata_error_count
,data
->error_log_pointer
);
1717 // starting printing error log info
1718 if (data
->ata_error_count
<=5)
1719 pout( "ATA Error Count: %d\n", (int)data
->ata_error_count
);
1721 pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1722 (int)data
->ata_error_count
);
1724 pout("\tCR = Command Register [HEX]\n"
1725 "\tFR = Features Register [HEX]\n"
1726 "\tSC = Sector Count Register [HEX]\n"
1727 "\tSN = Sector Number Register [HEX]\n"
1728 "\tCL = Cylinder Low Register [HEX]\n"
1729 "\tCH = Cylinder High Register [HEX]\n"
1730 "\tDH = Device/Head Register [HEX]\n"
1731 "\tDC = Device Command Register [HEX]\n"
1732 "\tER = Error register [HEX]\n"
1733 "\tST = Status register [HEX]\n"
1734 "Powered_Up_Time is measured from power on, and printed as\n"
1735 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1736 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1738 // now step through the five error log data structures (table 39 of spec)
1739 for (int k
= 4; k
>= 0; k
-- ) {
1741 // The error log data structure entries are a circular buffer
1742 int j
, i
=(data
->error_log_pointer
+k
)%5;
1743 const ata_smart_errorlog_struct
* elog
= data
->errorlog_struct
+i
;
1744 const ata_smart_errorlog_error_struct
* summary
= &(elog
->error_struct
);
1746 // Spec says: unused error log structures shall be zero filled
1747 if (nonempty(elog
, sizeof(*elog
))){
1748 // Table 57 of T13/1532D Volume 1 Revision 3
1749 const char *msgstate
= get_error_log_state_desc(summary
->state
);
1750 int days
= (int)summary
->timestamp
/24;
1752 // See table 42 of ATA5 spec
1754 pout("Error %d occurred at disk power-on lifetime: %d hours (%d days + %d hours)\n",
1755 (int)(data
->ata_error_count
+k
-4), (int)summary
->timestamp
, days
, (int)(summary
->timestamp
-24*days
));
1757 pout(" When the command that caused the error occurred, the device was %s.\n\n",msgstate
);
1758 pout(" After command completion occurred, registers were:\n"
1759 " ER ST SC SN CL CH DH\n"
1760 " -- -- -- -- -- -- --\n"
1761 " %02x %02x %02x %02x %02x %02x %02x",
1762 (int)summary
->error_register
,
1763 (int)summary
->status
,
1764 (int)summary
->sector_count
,
1765 (int)summary
->sector_number
,
1766 (int)summary
->cylinder_low
,
1767 (int)summary
->cylinder_high
,
1768 (int)summary
->drive_head
);
1769 // Add a description of the contents of the status and error registers
1771 std::string st_er_desc
= format_st_er_desc(elog
);
1772 if (!st_er_desc
.empty())
1773 pout(" %s", st_er_desc
.c_str());
1775 pout(" Commands leading to the command that caused the error were:\n"
1776 " CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name\n"
1777 " -- -- -- -- -- -- -- -- ---------------- --------------------\n");
1778 for ( j
= 4; j
>= 0; j
--){
1779 const ata_smart_errorlog_command_struct
* thiscommand
= elog
->commands
+j
;
1781 // Spec says: unused data command structures shall be zero filled
1782 if (nonempty(thiscommand
, sizeof(*thiscommand
))) {
1783 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1784 (int)thiscommand
->commandreg
,
1785 (int)thiscommand
->featuresreg
,
1786 (int)thiscommand
->sector_count
,
1787 (int)thiscommand
->sector_number
,
1788 (int)thiscommand
->cylinder_low
,
1789 (int)thiscommand
->cylinder_high
,
1790 (int)thiscommand
->drive_head
,
1791 (int)thiscommand
->devicecontrolreg
,
1792 format_milliseconds(thiscommand
->timestamp
).c_str(),
1793 look_up_ata_command(thiscommand
->commandreg
, thiscommand
->featuresreg
));
1800 if (printing_is_switchable
)
1803 return data
->ata_error_count
;
1806 // Print SMART Extended Comprehensive Error Log (GP Log 0x03)
1807 static int PrintSmartExtErrorLog(const ata_smart_exterrlog
* log
,
1808 unsigned nsectors
, unsigned max_errors
)
1810 pout("SMART Extended Comprehensive Error Log Version: %u (%u sectors)\n",
1811 log
->version
, nsectors
);
1813 if (!log
->device_error_count
) {
1814 pout("No Errors Logged\n\n");
1820 unsigned nentries
= nsectors
* 4;
1821 unsigned erridx
= log
->error_log_index
;
1822 if (!(1 <= erridx
&& erridx
<= nentries
)){
1823 // Some Samsung disks (at least SP1614C/SW100-25, HD300LJ/ZT100-12) use the
1824 // former index from Summary Error Log (byte 1, now reserved) and set byte 2-3
1826 if (!(erridx
== 0 && 1 <= log
->reserved1
&& log
->reserved1
<= nentries
)) {
1827 pout("Invalid Error Log index = 0x%04x (reserved = 0x%02x)\n", erridx
, log
->reserved1
);
1830 pout("Invalid Error Log index = 0x%04x, trying reserved byte (0x%02x) instead\n", erridx
, log
->reserved1
);
1831 erridx
= log
->reserved1
;
1834 // Index base is not clearly specified by ATA8-ACS (T13/1699-D Revision 6a),
1835 // it is 1-based in practice.
1838 // Calculate #errors to print
1839 unsigned errcnt
= log
->device_error_count
;
1841 if (errcnt
<= nentries
)
1842 pout("Device Error Count: %u\n", log
->device_error_count
);
1845 pout("Device Error Count: %u (device log contains only the most recent %u errors)\n",
1846 log
->device_error_count
, errcnt
);
1849 if (max_errors
< errcnt
)
1850 errcnt
= max_errors
;
1853 pout("\tCR = Command Register\n"
1854 "\tFEATR = Features Register\n"
1855 "\tCOUNT = Count (was: Sector Count) Register\n"
1856 "\tLBA_48 = Upper bytes of LBA High/Mid/Low Registers ] ATA-8\n"
1857 "\tLH = LBA High (was: Cylinder High) Register ] LBA\n"
1858 "\tLM = LBA Mid (was: Cylinder Low) Register ] Register\n"
1859 "\tLL = LBA Low (was: Sector Number) Register ]\n"
1860 "\tDV = Device (was: Device/Head) Register\n"
1861 "\tDC = Device Control Register\n"
1862 "\tER = Error register\n"
1863 "\tST = Status register\n"
1864 "Powered_Up_Time is measured from power on, and printed as\n"
1865 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1866 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1868 // Iterate through circular buffer in reverse direction
1869 for (unsigned i
= 0, errnum
= log
->device_error_count
;
1870 i
< errcnt
; i
++, errnum
--, erridx
= (erridx
> 0 ? erridx
- 1 : nentries
- 1)) {
1872 const ata_smart_exterrlog_error_log
& entry
= log
[erridx
/ 4].error_logs
[erridx
% 4];
1874 // Skip unused entries
1875 if (!nonempty(&entry
, sizeof(entry
))) {
1876 pout("Error %u [%u] log entry is empty\n", errnum
, erridx
);
1880 // Print error information
1882 const ata_smart_exterrlog_error
& err
= entry
.error
;
1883 pout("Error %u [%u] occurred at disk power-on lifetime: %u hours (%u days + %u hours)\n",
1884 errnum
, erridx
, err
.timestamp
, err
.timestamp
/ 24, err
.timestamp
% 24);
1887 pout(" When the command that caused the error occurred, the device was %s.\n\n",
1888 get_error_log_state_desc(err
.state
));
1891 pout(" After command completion occurred, registers were:\n"
1892 " ER -- ST COUNT LBA_48 LH LM LL DV DC\n"
1893 " -- -- -- == -- == == == -- -- -- -- --\n"
1894 " %02x -- %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
1896 err
.status_register
,
1897 err
.count_register_hi
,
1899 err
.lba_high_register_hi
,
1900 err
.lba_mid_register_hi
,
1901 err
.lba_low_register_hi
,
1902 err
.lba_high_register
,
1903 err
.lba_mid_register
,
1904 err
.lba_low_register
,
1905 err
.device_register
,
1906 err
.device_control_register
);
1908 // Add a description of the contents of the status and error registers
1910 std::string st_er_desc
= format_st_er_desc(&entry
);
1911 if (!st_er_desc
.empty())
1912 pout(" %s", st_er_desc
.c_str());
1915 // Print command history
1916 pout(" Commands leading to the command that caused the error were:\n"
1917 " CR FEATR COUNT LBA_48 LH LM LL DV DC Powered_Up_Time Command/Feature_Name\n"
1918 " -- == -- == -- == == == -- -- -- -- -- --------------- --------------------\n");
1919 for (int ci
= 4; ci
>= 0; ci
--) {
1920 const ata_smart_exterrlog_command
& cmd
= entry
.commands
[ci
];
1922 // Skip unused entries
1923 if (!nonempty(&cmd
, sizeof(cmd
)))
1926 // Print registers, timestamp and ATA command name
1927 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1928 cmd
.command_register
,
1929 cmd
.features_register_hi
,
1930 cmd
.features_register
,
1931 cmd
.count_register_hi
,
1933 cmd
.lba_high_register_hi
,
1934 cmd
.lba_mid_register_hi
,
1935 cmd
.lba_low_register_hi
,
1936 cmd
.lba_high_register
,
1937 cmd
.lba_mid_register
,
1938 cmd
.lba_low_register
,
1939 cmd
.device_register
,
1940 cmd
.device_control_register
,
1941 format_milliseconds(cmd
.timestamp
).c_str(),
1942 look_up_ata_command(cmd
.command_register
, cmd
.features_register
));
1948 if (printing_is_switchable
)
1951 return log
->device_error_count
;
1954 // Print SMART Extended Self-test Log (GP Log 0x07)
1955 static int PrintSmartExtSelfTestLog(const ata_smart_extselftestlog
* log
,
1956 unsigned nsectors
, unsigned max_entries
)
1958 pout("SMART Extended Self-test Log Version: %u (%u sectors)\n",
1959 log
->version
, nsectors
);
1961 if (!log
->log_desc_index
){
1962 pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
1967 unsigned nentries
= nsectors
* 19;
1968 unsigned logidx
= log
->log_desc_index
;
1969 if (logidx
> nentries
) {
1970 pout("Invalid Self-test Log index = 0x%04x (reserved = 0x%02x)\n", logidx
, log
->reserved1
);
1974 // Index base is not clearly specified by ATA8-ACS (T13/1699-D Revision 6a),
1975 // it is 1-based in practice.
1978 bool print_header
= true;
1979 int errcnt
= 0, igncnt
= 0;
1980 int ext_ok_testnum
= -1;
1982 // Iterate through circular buffer in reverse direction
1983 for (unsigned i
= 0, testnum
= 1;
1984 i
< nentries
&& testnum
<= max_entries
;
1985 i
++, logidx
= (logidx
> 0 ? logidx
- 1 : nentries
- 1)) {
1987 const ata_smart_extselftestlog_desc
& entry
= log
[logidx
/ 19].log_descs
[logidx
% 19];
1989 // Skip unused entries
1990 if (!nonempty(&entry
, sizeof(entry
)))
1994 const unsigned char * b
= entry
.failing_lba
;
1995 uint64_t lba48
= b
[0]
1998 | ((uint64_t)b
[3] << 24)
1999 | ((uint64_t)b
[4] << 32)
2000 | ((uint64_t)b
[5] << 40);
2003 int state
= ataPrintSmartSelfTestEntry(testnum
, entry
.self_test_type
,
2004 entry
.self_test_status
, entry
.timestamp
, lba48
,
2005 false /*!print_error_only*/, print_header
);
2008 // Self-test showed an error
2009 if (ext_ok_testnum
< 0)
2012 // Newer successful extended self-test exits
2015 else if (state
> 0 && ext_ok_testnum
< 0) {
2016 // Latest successful extended self-test
2017 ext_ok_testnum
= testnum
;
2023 pout("%d of %d failed self-tests are outdated by newer successful extended offline self-test #%2d\n",
2024 igncnt
, igncnt
+errcnt
, ext_ok_testnum
);
2030 static void ataPrintSelectiveSelfTestLog(const ata_selective_self_test_log
* log
, const ata_smart_values
* sv
)
2032 int i
,field1
,field2
;
2035 uint64_t maxl
=0,maxr
=0;
2036 uint64_t current
=log
->currentlba
;
2037 uint64_t currentend
=current
+65535;
2039 // print data structure revision number
2040 pout("SMART Selective self-test log data structure revision number %d\n",(int)log
->logversion
);
2041 if (1 != log
->logversion
)
2042 pout("Note: revision number not 1 implies that no selective self-test has ever been run\n");
2044 switch((sv
->self_test_exec_status
)>>4){
2045 case 0:msg
="Completed";
2047 case 1:msg
="Aborted_by_host";
2049 case 2:msg
="Interrupted";
2051 case 3:msg
="Fatal_error";
2053 case 4:msg
="Completed_unknown_failure";
2055 case 5:msg
="Completed_electrical_failure";
2057 case 6:msg
="Completed_servo/seek_failure";
2059 case 7:msg
="Completed_read_failure";
2061 case 8:msg
="Completed_handling_damage??";
2063 case 15:msg
="Self_test_in_progress";
2065 default:msg
="Unknown_status ";
2069 // find the number of columns needed for printing. If in use, the
2070 // start/end of span being read-scanned...
2071 if (log
->currentspan
>5) {
2075 for (i
=0; i
<5; i
++) {
2076 uint64_t start
=log
->span
[i
].start
;
2077 uint64_t end
=log
->span
[i
].end
;
2078 // ... plus max start/end of each of the five test spans.
2085 // we need at least 7 characters wide fields to accomodate the
2087 if ((field1
=snprintf(tmp
,64, "%" PRIu64
, maxl
))<7)
2089 if ((field2
=snprintf(tmp
,64, "%" PRIu64
, maxr
))<7)
2092 // now print the five test spans
2093 pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1
, "MIN_LBA", field2
, "MAX_LBA");
2095 for (i
=0; i
<5; i
++) {
2096 uint64_t start
=log
->span
[i
].start
;
2097 uint64_t end
=log
->span
[i
].end
;
2099 if ((i
+1)==(int)log
->currentspan
)
2100 // this span is currently under test
2101 pout(" %d %*" PRIu64
" %*" PRIu64
" %s [%01d0%% left] (%" PRIu64
"-%" PRIu64
")\n",
2102 i
+1, field1
, start
, field2
, end
, msg
,
2103 (int)(sv
->self_test_exec_status
& 0xf), current
, currentend
);
2105 // this span is not currently under test
2106 pout(" %d %*" PRIu64
" %*" PRIu64
" Not_testing\n",
2107 i
+1, field1
, start
, field2
, end
);
2110 // if we are currently read-scanning, print LBAs and the status of
2112 if (log
->currentspan
>5)
2113 pout("%5d %*" PRIu64
" %*" PRIu64
" Read_scanning %s\n",
2114 (int)log
->currentspan
, field1
, current
, field2
, currentend
,
2115 OfflineDataCollectionStatus(sv
->offline_data_collection_status
));
2117 /* Print selective self-test flags. Possible flag combinations are
2118 (numbering bits from 0-15):
2122 1 0 0 Will carry out scan after selective test
2123 1 1 0 Waiting to carry out scan after powerup
2124 1 0 1 Currently scanning
2125 1 1 1 Currently scanning
2128 pout("Selective self-test flags (0x%x):\n", (unsigned int)log
->flags
);
2129 if (log
->flags
& SELECTIVE_FLAG_DOSCAN
) {
2130 if (log
->flags
& SELECTIVE_FLAG_ACTIVE
)
2131 pout(" Currently read-scanning the remainder of the disk.\n");
2132 else if (log
->flags
& SELECTIVE_FLAG_PENDING
)
2133 pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
2134 (int)log
->pendingtime
);
2136 pout(" After scanning selected spans, read-scan remainder of disk.\n");
2139 pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
2141 // print pending time
2142 pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
2143 (int)log
->pendingtime
);
2148 // Format SCT Temperature value
2149 static const char * sct_ptemp(signed char x
, char (& buf
)[20])
2151 if (x
== -128 /*0x80 = unknown*/)
2153 snprintf(buf
, sizeof(buf
), "%2d", x
);
2157 static const char * sct_pbar(int x
, char (& buf
)[64])
2168 memset(buf
, '*', x
);
2174 buf
[0] = '-'; buf
[1] = 0;
2179 static const char * sct_device_state_msg(unsigned char state
)
2182 case 0: return "Active";
2183 case 1: return "Stand-by";
2184 case 2: return "Sleep";
2185 case 3: return "DST executing in background";
2186 case 4: return "SMART Off-line Data Collection executing in background";
2187 case 5: return "SCT command executing in background";
2188 default:return "Unknown";
2193 static int ataPrintSCTStatus(const ata_sct_status_response
* sts
)
2195 pout("SCT Status Version: %u\n", sts
->format_version
);
2196 pout("SCT Version (vendor specific): %u (0x%04x)\n", sts
->sct_version
, sts
->sct_version
);
2197 pout("SCT Support Level: %u\n", sts
->sct_spec
);
2198 pout("Device State: %s (%u)\n",
2199 sct_device_state_msg(sts
->device_state
), sts
->device_state
);
2200 char buf1
[20], buf2
[20];
2201 if ( !sts
->min_temp
&& !sts
->life_min_temp
2202 && !sts
->under_limit_count
&& !sts
->over_limit_count
) {
2203 // "Reserved" fields not set, assume "old" format version 2
2204 // Table 11 of T13/1701DT-N (SMART Command Transport) Revision 5, February 2005
2205 // Table 54 of T13/1699-D (ATA8-ACS) Revision 3e, July 2006
2206 pout("Current Temperature: %s Celsius\n",
2207 sct_ptemp(sts
->hda_temp
, buf1
));
2208 pout("Power Cycle Max Temperature: %s Celsius\n",
2209 sct_ptemp(sts
->max_temp
, buf2
));
2210 pout("Lifetime Max Temperature: %s Celsius\n",
2211 sct_ptemp(sts
->life_max_temp
, buf2
));
2214 // Assume "new" format version 2 or version 3
2215 // T13/e06152r0-3 (Additional SCT Temperature Statistics), August - October 2006
2216 // Table 60 of T13/1699-D (ATA8-ACS) Revision 3f, December 2006 (format version 2)
2217 // Table 80 of T13/1699-D (ATA8-ACS) Revision 6a, September 2008 (format version 3)
2218 pout("Current Temperature: %s Celsius\n",
2219 sct_ptemp(sts
->hda_temp
, buf1
));
2220 pout("Power Cycle Min/Max Temperature: %s/%s Celsius\n",
2221 sct_ptemp(sts
->min_temp
, buf1
), sct_ptemp(sts
->max_temp
, buf2
));
2222 pout("Lifetime Min/Max Temperature: %s/%s Celsius\n",
2223 sct_ptemp(sts
->life_min_temp
, buf1
), sct_ptemp(sts
->life_max_temp
, buf2
));
2224 signed char avg
= sts
->byte205
; // Average Temperature from e06152r0-2, removed in e06152r3
2225 if (0 < avg
&& sts
->life_min_temp
<= avg
&& avg
<= sts
->life_max_temp
)
2226 pout("Lifetime Average Temperature: %2d Celsius\n", avg
);
2227 pout("Under/Over Temperature Limit Count: %2u/%u\n",
2228 sts
->under_limit_count
, sts
->over_limit_count
);
2233 // Print SCT Temperature History Table
2234 static int ataPrintSCTTempHist(const ata_sct_temperature_history_table
* tmh
)
2236 char buf1
[20], buf2
[20], buf3
[64];
2237 pout("SCT Temperature History Version: %u%s\n", tmh
->format_version
,
2238 (tmh
->format_version
!= 2 ? " (Unknown, should be 2)" : ""));
2239 pout("Temperature Sampling Period: %u minute%s\n",
2240 tmh
->sampling_period
, (tmh
->sampling_period
==1?"":"s"));
2241 pout("Temperature Logging Interval: %u minute%s\n",
2242 tmh
->interval
, (tmh
->interval
==1?"":"s"));
2243 pout("Min/Max recommended Temperature: %s/%s Celsius\n",
2244 sct_ptemp(tmh
->min_op_limit
, buf1
), sct_ptemp(tmh
->max_op_limit
, buf2
));
2245 pout("Min/Max Temperature Limit: %s/%s Celsius\n",
2246 sct_ptemp(tmh
->under_limit
, buf1
), sct_ptemp(tmh
->over_limit
, buf2
));
2247 pout("Temperature History Size (Index): %u (%u)\n", tmh
->cb_size
, tmh
->cb_index
);
2249 if (!(0 < tmh
->cb_size
&& tmh
->cb_size
<= sizeof(tmh
->cb
) && tmh
->cb_index
< tmh
->cb_size
)) {
2251 pout("Temperature History is empty\n");
2253 pout("Invalid Temperature History Size or Index\n");
2258 pout("\nIndex Estimated Time Temperature Celsius\n");
2259 unsigned n
= 0, i
= (tmh
->cb_index
+1) % tmh
->cb_size
;
2260 unsigned interval
= (tmh
->interval
> 0 ? tmh
->interval
: 1);
2261 time_t t
= time(0) - (tmh
->cb_size
-1) * interval
* 60;
2262 t
-= t
% (interval
* 60);
2263 while (n
< tmh
->cb_size
) {
2264 // Find range of identical temperatures
2265 unsigned n1
= n
, n2
= n
+1, i2
= (i
+1) % tmh
->cb_size
;
2266 while (n2
< tmh
->cb_size
&& tmh
->cb
[i2
] == tmh
->cb
[i
]) {
2267 n2
++; i2
= (i2
+1) % tmh
->cb_size
;
2271 if (n
== n1
|| n
== n2
-1 || n2
<= n1
+3) {
2273 // TODO: Don't print times < boot time
2274 strftime(date
, sizeof(date
), "%Y-%m-%d %H:%M", localtime(&t
));
2275 pout(" %3u %s %s %s\n", i
, date
,
2276 sct_ptemp(tmh
->cb
[i
], buf1
), sct_pbar(tmh
->cb
[i
], buf3
));
2278 else if (n
== n1
+1) {
2279 pout(" ... ..(%3u skipped). .. %s\n",
2280 n2
-n1
-2, sct_pbar(tmh
->cb
[i
], buf3
));
2282 t
+= interval
* 60; i
= (i
+1) % tmh
->cb_size
; n
++;
2285 //assert(n == tmh->cb_size && i == (tmh->cb_index+1) % tmh->cb_size);
2290 // Print SCT Error Recovery Control timers
2291 static void ataPrintSCTErrorRecoveryControl(bool set
, unsigned short read_timer
, unsigned short write_timer
)
2293 pout("SCT Error Recovery Control%s:\n", (set
? " set to" : ""));
2295 pout(" Read: Disabled\n");
2297 pout(" Read: %6d (%0.1f seconds)\n", read_timer
, read_timer
/10.0);
2299 pout(" Write: Disabled\n");
2301 pout(" Write: %6d (%0.1f seconds)\n", write_timer
, write_timer
/10.0);
2304 static void print_aam_level(const char * msg
, int level
, int recommended
= -1)
2306 // Table 56 of T13/1699-D (ATA8-ACS) Revision 6a, September 6, 2008
2307 // Obsolete since T13/2015-D (ACS-2) Revision 4a, December 9, 2010
2310 s
= "vendor specific";
2311 else if (level
< 128)
2312 s
= "unknown/retired";
2313 else if (level
== 128)
2315 else if (level
< 254)
2317 else if (level
== 254)
2318 s
= "maximum performance";
2322 if (recommended
>= 0)
2323 pout("%s%d (%s), recommended: %d\n", msg
, level
, s
, recommended
);
2325 pout("%s%d (%s)\n", msg
, level
, s
);
2328 static void print_apm_level(const char * msg
, int level
)
2330 // Table 120 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2332 if (!(1 <= level
&& level
<= 254))
2334 else if (level
== 1)
2335 s
= "minimum power consumption with standby";
2336 else if (level
< 128)
2337 s
= "intermediate level with standby";
2338 else if (level
== 128)
2339 s
= "minimum power consumption without standby";
2340 else if (level
< 254)
2341 s
= "intermediate level without standby";
2343 s
= "maximum performance";
2345 pout("%s%d (%s)\n", msg
, level
, s
);
2348 static void print_ata_security_status(const char * msg
, unsigned short state
)
2350 const char * s1
, * s2
= "", * s3
= "", * s4
= "";
2352 // Table 6 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2353 if (!(state
& 0x0001))
2355 else if (!(state
& 0x0002)) {
2357 if (!(state
& 0x0008))
2358 s2
= "NOT FROZEN [SEC1]";
2360 s2
= "frozen [SEC2]";
2363 s1
= "ENABLED, PW level ";
2364 if (!(state
& 0x0020))
2369 if (!(state
& 0x0004)) {
2370 s3
= ", not locked, ";
2371 if (!(state
& 0x0008))
2372 s4
= "not frozen [SEC5]";
2374 s4
= "frozen [SEC6]";
2377 s3
= ", **LOCKED** [SEC4]";
2379 s4
= ", PW ATTEMPTS EXCEEDED";
2383 pout("%s%s%s%s%s\n", msg
, s1
, s2
, s3
, s4
);
2386 static void print_standby_timer(const char * msg
, int timer
, const ata_identify_device
& drive
)
2388 const char * s1
= 0;
2389 int hours
= 0, minutes
= 0 , seconds
= 0;
2391 // Table 63 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2394 else if (timer
<= 240)
2395 seconds
= timer
* 5, minutes
= seconds
/ 60, seconds
%= 60;
2396 else if (timer
<= 251)
2397 minutes
= (timer
- 240) * 30, hours
= minutes
/ 60, minutes
%= 60;
2398 else if (timer
== 252)
2400 else if (timer
== 253)
2401 s1
= "between 8 hours and 12 hours";
2402 else if (timer
== 255)
2403 minutes
= 21, seconds
= 15;
2407 const char * s2
= "", * s3
= "";
2408 if (!(drive
.words047_079
[49-47] & 0x2000))
2409 s2
= " or vendor-specific";
2410 if (timer
> 0 && (drive
.words047_079
[50-47] & 0xc001) == 0x4001)
2411 s3
= ", a vendor-specific minimum applies";
2414 pout("%s%d (%s%s%s)\n", msg
, timer
, s1
, s2
, s3
);
2416 pout("%s%d (%02d:%02d:%02d%s%s)\n", msg
, timer
, hours
, minutes
, seconds
, s2
, s3
);
2420 int ataPrintMain (ata_device
* device
, const ata_print_options
& options
)
2422 // If requested, check power mode first
2423 const char * powername
= 0;
2424 bool powerchg
= false;
2425 if (options
.powermode
) {
2426 unsigned char powerlimit
= 0xff;
2427 int powermode
= ataCheckPowerMode(device
);
2428 switch (powermode
) {
2430 if (device
->is_syscall_unsup()) {
2431 pout("CHECK POWER MODE not implemented, ignoring -n option\n"); break;
2433 powername
= "SLEEP"; powerlimit
= 2;
2436 powername
= "STANDBY"; powerlimit
= 3; break;
2438 powername
= "IDLE"; powerlimit
= 4; break;
2440 powername
= "ACTIVE or IDLE"; break;
2442 pout("CHECK POWER MODE returned unknown value 0x%02x, ignoring -n option\n", powermode
);
2446 if (options
.powermode
>= powerlimit
) {
2447 pout("Device is in %s mode, exit(%d)\n", powername
, FAILPOWER
);
2450 powerchg
= (powermode
!= 0xff); // SMART tests will spin up drives
2454 // SMART values needed ?
2455 bool need_smart_val
= (
2456 options
.smart_check_status
2457 || options
.smart_general_values
2458 || options
.smart_vendor_attrib
2459 || options
.smart_error_log
2460 || options
.smart_selftest_log
2461 || options
.smart_selective_selftest_log
2462 || options
.smart_ext_error_log
2463 || options
.smart_ext_selftest_log
2464 || options
.smart_auto_offl_enable
2465 || options
.smart_auto_offl_disable
2466 || options
.smart_selftest_type
!= -1
2469 // SMART must be enabled ?
2470 bool need_smart_enabled
= (
2472 || options
.smart_auto_save_enable
2473 || options
.smart_auto_save_disable
2476 // SMART feature set needed ?
2477 bool need_smart_support
= (
2479 || options
.smart_enable
2480 || options
.smart_disable
2483 // SMART and GP log directories needed ?
2484 bool need_smart_logdir
= (
2485 options
.smart_logdir
2486 || options
.devstat_all_pages
// devstat fallback to smartlog if needed
2487 || options
.devstat_ssd_page
2488 || !options
.devstat_pages
.empty()
2491 bool need_gp_logdir
= (
2493 || options
.smart_ext_error_log
2494 || options
.smart_ext_selftest_log
2495 || options
.devstat_all_pages
2496 || options
.devstat_ssd_page
2497 || !options
.devstat_pages
.empty()
2501 for (i
= 0; i
< options
.log_requests
.size(); i
++) {
2502 if (options
.log_requests
[i
].gpl
)
2503 need_gp_logdir
= true;
2505 need_smart_logdir
= true;
2508 // SCT commands needed ?
2509 bool need_sct_support
= (
2510 options
.sct_temp_sts
2511 || options
.sct_temp_hist
2512 || options
.sct_temp_int
2513 || options
.sct_erc_get
2514 || options
.sct_erc_set
2515 || options
.sct_wcache_reorder_get
2516 || options
.sct_wcache_reorder_set
2519 // Exit if no further options specified
2520 if (!( options
.drive_info
|| options
.show_presets
2521 || need_smart_support
|| need_smart_logdir
2522 || need_gp_logdir
|| need_sct_support
2524 || options
.identify_word_level
>= 0
2525 || options
.get_set_used
)) {
2527 pout("Device is in %s mode\n", powername
);
2529 pout("ATA device successfully opened\n\n"
2530 "Use 'smartctl -a' (or '-x') to print SMART (and more) information\n\n");
2534 // Start by getting Drive ID information. We need this, to know if SMART is supported.
2536 ata_identify_device drive
; memset(&drive
, 0, sizeof(drive
));
2537 unsigned char raw_drive
[sizeof(drive
)]; memset(&raw_drive
, 0, sizeof(raw_drive
));
2539 device
->clear_err();
2540 int retid
= ata_read_identity(device
, &drive
, options
.fix_swapped_id
, raw_drive
);
2542 pout("Read Device Identity failed: %s\n\n",
2543 (device
->get_errno() ? device
->get_errmsg() : "Unknown error"));
2544 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
2546 else if (!nonempty(&drive
, sizeof(drive
))) {
2547 pout("Read Device Identity failed: empty IDENTIFY data\n\n");
2548 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
2551 // If requested, show which presets would be used for this drive and exit.
2552 if (options
.show_presets
) {
2553 show_presets(&drive
);
2557 // Use preset vendor attribute options unless user has requested otherwise.
2558 ata_vendor_attr_defs attribute_defs
= options
.attribute_defs
;
2559 firmwarebug_defs firmwarebugs
= options
.firmwarebugs
;
2560 const drive_settings
* dbentry
= 0;
2561 if (!options
.ignore_presets
)
2562 dbentry
= lookup_drive_apply_presets(&drive
, attribute_defs
,
2565 // Get capacity, sector sizes and rotation rate
2566 ata_size_info sizes
;
2567 ata_get_size_info(&drive
, sizes
);
2568 int rpm
= ata_get_rotation_rate(&drive
);
2570 // Print ATA IDENTIFY info if requested
2571 if (options
.identify_word_level
>= 0) {
2572 pout("=== ATA IDENTIFY DATA ===\n");
2573 // Pass raw data without endianness adjustments
2574 ata_print_identify_data(raw_drive
, (options
.identify_word_level
> 0), options
.identify_bit_level
);
2577 // Print most drive identity information if requested
2578 if (options
.drive_info
) {
2579 pout("=== START OF INFORMATION SECTION ===\n");
2580 print_drive_info(&drive
, sizes
, rpm
, dbentry
);
2583 // Check and print SMART support and state
2584 int smart_supported
= -1, smart_enabled
= -1;
2585 if (need_smart_support
|| options
.drive_info
) {
2589 pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n",
2590 packetdevicetype(retid
-1));
2593 // Disk device: SMART supported and enabled ?
2594 smart_supported
= ataSmartSupport(&drive
);
2595 smart_enabled
= ataIsSmartEnabled(&drive
);
2597 if (smart_supported
< 0)
2598 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
2599 if (smart_supported
&& smart_enabled
< 0) {
2600 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
2601 if (need_smart_support
) {
2602 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2603 // check SMART support by trying a command
2604 pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
2605 if (ataDoesSmartWork(device
))
2606 smart_supported
= smart_enabled
= 1;
2609 else if (smart_supported
< 0 && (smart_enabled
> 0 || dbentry
))
2610 // Assume supported if enabled or in drive database
2611 smart_supported
= 1;
2613 if (smart_supported
< 0)
2614 pout("SMART support is: Unknown - Try option -s with argument 'on' to enable it.");
2615 else if (!smart_supported
)
2616 pout("SMART support is: Unavailable - device lacks SMART capability.\n");
2618 if (options
.drive_info
)
2619 pout("SMART support is: Available - device has SMART capability.\n");
2620 if (smart_enabled
>= 0) {
2621 if (device
->ata_identify_is_cached()) {
2622 if (options
.drive_info
)
2623 pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
2624 (smart_enabled
?"En":"Dis"));
2625 smart_enabled
= ataDoesSmartWork(device
);
2627 if (options
.drive_info
)
2628 pout("SMART support is: %s\n",
2629 (smart_enabled
? "Enabled" : "Disabled"));
2636 if (options
.get_aam
) {
2637 if ((drive
.command_set_2
& 0xc200) != 0x4200) // word083
2638 pout("AAM feature is: Unavailable\n");
2639 else if (!(drive
.word086
& 0x0200))
2640 pout("AAM feature is: Disabled\n");
2642 print_aam_level("AAM level is: ", drive
.words088_255
[94-88] & 0xff,
2643 drive
.words088_255
[94-88] >> 8);
2647 if (options
.get_apm
) {
2648 if ((drive
.command_set_2
& 0xc008) != 0x4008) // word083
2649 pout("APM feature is: Unavailable\n");
2650 else if (!(drive
.word086
& 0x0008))
2651 pout("APM feature is: Disabled\n");
2653 print_apm_level("APM level is: ", drive
.words088_255
[91-88] & 0xff);
2656 // Print read look-ahead status
2657 if (options
.get_lookahead
) {
2658 pout("Rd look-ahead is: %s\n",
2659 ( (drive
.command_set_2
& 0xc000) != 0x4000 // word083
2660 || !(drive
.command_set_1
& 0x0040)) ? "Unavailable" : // word082
2661 !(drive
.cfs_enable_1
& 0x0040) ? "Disabled" : "Enabled"); // word085
2664 // Print write cache status
2665 if (options
.get_wcache
) {
2666 pout("Write cache is: %s\n",
2667 ( (drive
.command_set_2
& 0xc000) != 0x4000 // word083
2668 || !(drive
.command_set_1
& 0x0020)) ? "Unavailable" : // word082
2669 !(drive
.cfs_enable_1
& 0x0020) ? "Disabled" : "Enabled"); // word085
2672 // Print ATA security status
2673 if (options
.get_security
)
2674 print_ata_security_status("ATA Security is: ", drive
.words088_255
[128-88]);
2676 // Print write cache reordering status
2677 if (options
.sct_wcache_reorder_get
) {
2678 if (isSCTFeatureControlCapable(&drive
)) {
2679 int wcache_reorder
= ataGetSetSCTWriteCacheReordering(device
,
2680 false /*enable*/, false /*persistent*/, false /*set*/);
2682 if (-1 <= wcache_reorder
&& wcache_reorder
<= 2)
2683 pout("Wt Cache Reorder: %s\n",
2684 (wcache_reorder
== -1 ? "Unknown (SCT Feature Control command failed)" :
2685 wcache_reorder
== 0 ? "Unknown" : // not defined in standard but returned on some drives if not set
2686 wcache_reorder
== 1 ? "Enabled" : "Disabled"));
2688 pout("Wt Cache Reorder: Unknown (0x%02x)\n", wcache_reorder
);
2691 pout("Wt Cache Reorder: Unavailable\n");
2694 // Print remaining drive info
2695 if (options
.drive_info
) {
2696 // Print the (now possibly changed) power mode if available
2698 pout("Power mode %s %s\n", (powerchg
?"was:":"is: "), powername
);
2702 // Exit if SMART is not supported but must be available to proceed
2703 if (smart_supported
<= 0 && need_smart_support
)
2704 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2706 // START OF THE ENABLE/DISABLE SECTION OF THE CODE
2707 if ( options
.smart_disable
|| options
.smart_enable
2708 || options
.smart_auto_save_disable
|| options
.smart_auto_save_enable
2709 || options
.smart_auto_offl_disable
|| options
.smart_auto_offl_enable
2710 || options
.set_aam
|| options
.set_apm
|| options
.set_lookahead
2711 || options
.set_wcache
|| options
.set_security_freeze
|| options
.set_standby
2712 || options
.sct_wcache_reorder_set
)
2713 pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
2715 // Enable/Disable AAM
2716 if (options
.set_aam
) {
2717 if (options
.set_aam
> 0) {
2718 if (!ata_set_features(device
, ATA_ENABLE_AAM
, options
.set_aam
-1)) {
2719 pout("AAM enable failed: %s\n", device
->get_errmsg());
2720 returnval
|= FAILSMART
;
2723 print_aam_level("AAM set to level ", options
.set_aam
-1);
2726 if (!ata_set_features(device
, ATA_DISABLE_AAM
)) {
2727 pout("AAM disable failed: %s\n", device
->get_errmsg());
2728 returnval
|= FAILSMART
;
2731 pout("AAM disabled\n");
2735 // Enable/Disable APM
2736 if (options
.set_apm
) {
2737 if (options
.set_apm
> 0) {
2738 if (!ata_set_features(device
, ATA_ENABLE_APM
, options
.set_apm
-1)) {
2739 pout("APM enable failed: %s\n", device
->get_errmsg());
2740 returnval
|= FAILSMART
;
2743 print_apm_level("APM set to level ", options
.set_apm
-1);
2746 if (!ata_set_features(device
, ATA_DISABLE_APM
)) {
2747 pout("APM disable failed: %s\n", device
->get_errmsg());
2748 returnval
|= FAILSMART
;
2751 pout("APM disabled\n");
2755 // Enable/Disable read look-ahead
2756 if (options
.set_lookahead
) {
2757 bool enable
= (options
.set_lookahead
> 0);
2758 if (!ata_set_features(device
, (enable
? ATA_ENABLE_READ_LOOK_AHEAD
: ATA_DISABLE_READ_LOOK_AHEAD
))) {
2759 pout("Read look-ahead %sable failed: %s\n", (enable
? "en" : "dis"), device
->get_errmsg());
2760 returnval
|= FAILSMART
;
2763 pout("Read look-ahead %sabled\n", (enable
? "en" : "dis"));
2766 // Enable/Disable write cache
2767 if (options
.set_wcache
) {
2768 bool enable
= (options
.set_wcache
> 0);
2769 if (!ata_set_features(device
, (enable
? ATA_ENABLE_WRITE_CACHE
: ATA_DISABLE_WRITE_CACHE
))) {
2770 pout("Write cache %sable failed: %s\n", (enable
? "en" : "dis"), device
->get_errmsg());
2771 returnval
|= FAILSMART
;
2774 pout("Write cache %sabled\n", (enable
? "en" : "dis"));
2777 // Enable/Disable write cache reordering
2778 if (options
.sct_wcache_reorder_set
) {
2779 bool enable
= (options
.sct_wcache_reorder_set
> 0);
2780 if (!isSCTFeatureControlCapable(&drive
))
2781 pout("Write cache reordering %sable failed: SCT Feature Control command not supported\n",
2782 (enable
? "en" : "dis"));
2783 else if (ataGetSetSCTWriteCacheReordering(device
,
2784 enable
, false /*persistent*/, true /*set*/) < 0) {
2785 pout("Write cache reordering %sable failed: %s\n", (enable
? "en" : "dis"), device
->get_errmsg());
2786 returnval
|= FAILSMART
;
2789 pout("Write cache reordering %sabled\n", (enable
? "en" : "dis"));
2792 // Freeze ATA security
2793 if (options
.set_security_freeze
) {
2794 if (!ata_nodata_command(device
, ATA_SECURITY_FREEZE_LOCK
)) {
2795 pout("ATA SECURITY FREEZE LOCK failed: %s\n", device
->get_errmsg());
2796 returnval
|= FAILSMART
;
2799 pout("ATA Security set to frozen mode\n");
2802 // Set standby timer
2803 if (options
.set_standby
) {
2804 if (!ata_nodata_command(device
, ATA_IDLE
, options
.set_standby
-1)) {
2805 pout("ATA IDLE command failed: %s\n", device
->get_errmsg());
2806 returnval
|= FAILSMART
;
2809 print_standby_timer("Standby timer set to ", options
.set_standby
-1, drive
);
2812 // Enable/Disable SMART commands
2813 if (options
.smart_enable
) {
2814 if (ataEnableSmart(device
)) {
2815 pout("SMART Enable failed: %s\n\n", device
->get_errmsg());
2816 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2819 pout("SMART Enabled.\n");
2824 // Turn off SMART on device
2825 if (options
.smart_disable
) {
2826 if (ataDisableSmart(device
)) {
2827 pout("SMART Disable failed: %s\n\n", device
->get_errmsg());
2828 failuretest(MANDATORY_CMD
,returnval
|=FAILSMART
);
2832 // Exit if SMART is disabled but must be enabled to proceed
2833 if (options
.smart_disable
|| (smart_enabled
<= 0 && need_smart_enabled
&& !is_permissive())) {
2834 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
2835 if (!options
.smart_disable
)
2836 pout("(override with '-T permissive' option)\n");
2840 // Enable/Disable Auto-save attributes
2841 if (options
.smart_auto_save_enable
) {
2842 if (ataEnableAutoSave(device
)){
2843 pout("SMART Enable Attribute Autosave failed: %s\n\n", device
->get_errmsg());
2844 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2847 pout("SMART Attribute Autosave Enabled.\n");
2850 if (options
.smart_auto_save_disable
) {
2851 if (ataDisableAutoSave(device
)){
2852 pout("SMART Disable Attribute Autosave failed: %s\n\n", device
->get_errmsg());
2853 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2856 pout("SMART Attribute Autosave Disabled.\n");
2859 // Read SMART values and thresholds if necessary
2860 ata_smart_values smartval
; memset(&smartval
, 0, sizeof(smartval
));
2861 ata_smart_thresholds_pvt smartthres
; memset(&smartthres
, 0, sizeof(smartthres
));
2862 bool smart_val_ok
= false, smart_thres_ok
= false;
2864 if (need_smart_val
) {
2865 if (ataReadSmartValues(device
, &smartval
)) {
2866 pout("Read SMART Data failed: %s\n\n", device
->get_errmsg());
2867 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2870 smart_val_ok
= true;
2872 if (options
.smart_check_status
|| options
.smart_vendor_attrib
) {
2873 if (ataReadSmartThresholds(device
, &smartthres
)){
2874 pout("Read SMART Thresholds failed: %s\n\n", device
->get_errmsg());
2875 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2878 smart_thres_ok
= true;
2883 // Enable/Disable Off-line testing
2884 bool needupdate
= false;
2885 if (options
.smart_auto_offl_enable
) {
2886 if (!isSupportAutomaticTimer(&smartval
)){
2887 pout("SMART Automatic Timers not supported\n\n");
2888 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2890 needupdate
= smart_val_ok
;
2891 if (ataEnableAutoOffline(device
)){
2892 pout("SMART Enable Automatic Offline failed: %s\n\n", device
->get_errmsg());
2893 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2896 pout("SMART Automatic Offline Testing Enabled every four hours.\n");
2899 if (options
.smart_auto_offl_disable
) {
2900 if (!isSupportAutomaticTimer(&smartval
)){
2901 pout("SMART Automatic Timers not supported\n\n");
2902 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2904 needupdate
= smart_val_ok
;
2905 if (ataDisableAutoOffline(device
)){
2906 pout("SMART Disable Automatic Offline failed: %s\n\n", device
->get_errmsg());
2907 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2910 pout("SMART Automatic Offline Testing Disabled.\n");
2913 if (needupdate
&& ataReadSmartValues(device
, &smartval
)){
2914 pout("Read SMART Data failed: %s\n\n", device
->get_errmsg());
2915 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2916 smart_val_ok
= false;
2919 // all this for a newline!
2920 if ( options
.smart_disable
|| options
.smart_enable
2921 || options
.smart_auto_save_disable
|| options
.smart_auto_save_enable
2922 || options
.smart_auto_offl_disable
|| options
.smart_auto_offl_enable
2923 || options
.set_aam
|| options
.set_apm
|| options
.set_lookahead
2924 || options
.set_wcache
|| options
.set_security_freeze
|| options
.set_standby
2925 || options
.sct_wcache_reorder_set
)
2928 // START OF READ-ONLY OPTIONS APART FROM -V and -i
2929 if ( options
.smart_check_status
|| options
.smart_general_values
2930 || options
.smart_vendor_attrib
|| options
.smart_error_log
2931 || options
.smart_selftest_log
|| options
.smart_selective_selftest_log
2932 || options
.smart_ext_error_log
|| options
.smart_ext_selftest_log
2933 || options
.sct_temp_sts
|| options
.sct_temp_hist
)
2934 pout("=== START OF READ SMART DATA SECTION ===\n");
2936 // Check SMART status
2937 if (options
.smart_check_status
) {
2939 switch (ataSmartStatus2(device
)) {
2942 // The case where the disk health is OK
2943 pout("SMART overall-health self-assessment test result: PASSED\n");
2944 if (smart_thres_ok
&& find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 0)) {
2945 if (options
.smart_vendor_attrib
)
2946 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
2949 pout("Please note the following marginal Attributes:\n");
2950 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 2, options
.output_format
);
2959 // The case where the disk health is NOT OK
2961 pout("SMART overall-health self-assessment test result: FAILED!\n"
2962 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
2964 if (smart_thres_ok
&& find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 1)) {
2965 returnval
|=FAILATTR
;
2966 if (options
.smart_vendor_attrib
)
2967 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
2970 pout("Failed Attributes:\n");
2971 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 1, options
.output_format
);
2975 pout("No failed Attributes found.\n\n");
2976 returnval
|=FAILSTATUS
;
2982 // Something went wrong with the SMART STATUS command.
2983 // The ATA SMART RETURN STATUS command provides the result in the ATA output
2984 // registers. Buggy ATA/SATA drivers and SAT Layers often do not properly
2985 // return the registers values.
2986 pout("SMART Status %s: %s\n",
2987 (device
->is_syscall_unsup() ? "not supported" : "command failed"),
2988 device
->get_errmsg());
2989 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2991 if (!(smart_val_ok
&& smart_thres_ok
)) {
2993 pout("SMART overall-health self-assessment test result: UNKNOWN!\n"
2994 "SMART Status, Attributes and Thresholds cannot be read.\n\n");
2996 else if (find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 1)) {
2998 pout("SMART overall-health self-assessment test result: FAILED!\n"
2999 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
3000 pout("Warning: This result is based on an Attribute check.\n");
3002 returnval
|=FAILATTR
;
3003 returnval
|=FAILSTATUS
;
3004 if (options
.smart_vendor_attrib
)
3005 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
3008 pout("Failed Attributes:\n");
3009 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 1, options
.output_format
);
3013 pout("SMART overall-health self-assessment test result: PASSED\n");
3014 pout("Warning: This result is based on an Attribute check.\n");
3015 if (find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 0)) {
3016 if (options
.smart_vendor_attrib
)
3017 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
3020 pout("Please note the following marginal Attributes:\n");
3021 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 2, options
.output_format
);
3030 } // end of switch statement
3033 } // end of checking SMART Status
3035 // Print general SMART values
3036 if (smart_val_ok
&& options
.smart_general_values
)
3037 PrintGeneralSmartValues(&smartval
, &drive
, firmwarebugs
);
3039 // Print vendor-specific attributes
3040 if (smart_val_ok
&& options
.smart_vendor_attrib
) {
3042 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
,
3043 (printing_is_switchable
? 2 : 0), options
.output_format
);
3047 // If GP Log is supported use smart log directory for
3048 // error and selftest log support check.
3049 if ( isGeneralPurposeLoggingCapable(&drive
)
3050 && ( options
.smart_error_log
|| options
.smart_selftest_log
3051 || options
.retry_error_log
|| options
.retry_selftest_log
))
3052 need_smart_logdir
= true;
3054 ata_smart_log_directory smartlogdir_buf
, gplogdir_buf
;
3055 const ata_smart_log_directory
* smartlogdir
= 0, * gplogdir
= 0;
3057 // Read SMART Log directory
3058 if (need_smart_logdir
) {
3059 if (firmwarebugs
.is_set(BUG_NOLOGDIR
))
3060 smartlogdir
= fake_logdir(&smartlogdir_buf
, options
);
3061 else if (ataReadLogDirectory(device
, &smartlogdir_buf
, false)) {
3062 pout("Read SMART Log Directory failed: %s\n\n", device
->get_errmsg());
3063 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3066 smartlogdir
= &smartlogdir_buf
;
3069 // Read GP Log directory
3070 if (need_gp_logdir
) {
3071 if (firmwarebugs
.is_set(BUG_NOLOGDIR
))
3072 gplogdir
= fake_logdir(&gplogdir_buf
, options
);
3073 else if (ataReadLogDirectory(device
, &gplogdir_buf
, true)) {
3074 pout("Read GP Log Directory failed\n\n");
3075 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3078 gplogdir
= &gplogdir_buf
;
3081 // Print log directories
3082 if ((options
.gp_logdir
&& gplogdir
) || (options
.smart_logdir
&& smartlogdir
)) {
3083 if (firmwarebugs
.is_set(BUG_NOLOGDIR
))
3084 pout("Log Directories not read due to '-F nologdir' option\n\n");
3086 PrintLogDirectories(gplogdir
, smartlogdir
);
3090 for (i
= 0; i
< options
.log_requests
.size(); i
++) {
3091 const ata_log_request
& req
= options
.log_requests
[i
];
3094 unsigned max_nsectors
;
3096 type
= "General Purpose";
3097 max_nsectors
= GetNumLogSectors(gplogdir
, req
.logaddr
, true);
3101 max_nsectors
= GetNumLogSectors(smartlogdir
, req
.logaddr
, false);
3104 if (!max_nsectors
) {
3105 if (!is_permissive()) {
3106 pout("%s Log 0x%02x does not exist (override with '-T permissive' option)\n", type
, req
.logaddr
);
3109 max_nsectors
= req
.page
+1;
3111 if (max_nsectors
<= req
.page
) {
3112 pout("%s Log 0x%02x has only %u sectors, output skipped\n", type
, req
.logaddr
, max_nsectors
);
3116 unsigned ns
= req
.nsectors
;
3117 if (ns
> max_nsectors
- req
.page
) {
3118 if (req
.nsectors
!= ~0U) // "FIRST-max"
3119 pout("%s Log 0x%02x has only %u sectors, output truncated\n", type
, req
.logaddr
, max_nsectors
);
3120 ns
= max_nsectors
- req
.page
;
3123 // SMART log don't support sector offset, start with first sector
3124 unsigned offs
= (req
.gpl
? 0 : req
.page
);
3126 raw_buffer
log_buf((offs
+ ns
) * 512);
3129 ok
= ataReadLogExt(device
, req
.logaddr
, 0x00, req
.page
, log_buf
.data(), ns
);
3131 ok
= ataReadSmartLog(device
, req
.logaddr
, log_buf
.data(), offs
+ ns
);
3133 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3135 PrintLogPages(type
, log_buf
.data() + offs
*512, req
.logaddr
, req
.page
, ns
, max_nsectors
);
3138 // Print SMART Extendend Comprehensive Error Log
3139 bool do_smart_error_log
= options
.smart_error_log
;
3140 if (options
.smart_ext_error_log
) {
3142 unsigned nsectors
= GetNumLogSectors(gplogdir
, 0x03, true);
3144 pout("SMART Extended Comprehensive Error Log (GP Log 0x03) not supported\n\n");
3145 else if (nsectors
>= 256)
3146 pout("SMART Extended Comprehensive Error Log size %u not supported\n\n", nsectors
);
3148 raw_buffer
log_03_buf(nsectors
* 512);
3149 ata_smart_exterrlog
* log_03
= (ata_smart_exterrlog
*)log_03_buf
.data();
3150 if (!ataReadExtErrorLog(device
, log_03
, nsectors
, firmwarebugs
)) {
3151 pout("Read SMART Extended Comprehensive Error Log failed\n\n");
3152 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3155 if (PrintSmartExtErrorLog(log_03
, nsectors
, options
.smart_ext_error_log
))
3156 returnval
|= FAILERR
;
3162 if (options
.retry_error_log
)
3163 do_smart_error_log
= true;
3164 else if (!do_smart_error_log
)
3165 pout("Try '-l [xerror,]error' to read traditional SMART Error Log\n");
3169 // Print SMART error log
3170 if (do_smart_error_log
) {
3171 if (!( ( smartlogdir
&& GetNumLogSectors(smartlogdir
, 0x01, false))
3172 || (!smartlogdir
&& isSmartErrorLogCapable(&smartval
, &drive
) )
3173 || is_permissive() )) {
3174 pout("SMART Error Log not supported\n\n");
3177 ata_smart_errorlog smarterror
; memset(&smarterror
, 0, sizeof(smarterror
));
3178 if (ataReadErrorLog(device
, &smarterror
, firmwarebugs
)) {
3179 pout("Read SMART Error Log failed: %s\n\n", device
->get_errmsg());
3180 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3183 // quiet mode is turned on inside PrintSmartErrorLog()
3184 if (PrintSmartErrorlog(&smarterror
, firmwarebugs
))
3191 // Print SMART Extendend Self-test Log
3192 bool do_smart_selftest_log
= options
.smart_selftest_log
;
3193 if (options
.smart_ext_selftest_log
) {
3195 unsigned nsectors
= GetNumLogSectors(gplogdir
, 0x07, true);
3197 pout("SMART Extended Self-test Log (GP Log 0x07) not supported\n\n");
3198 else if (nsectors
>= 256)
3199 pout("SMART Extended Self-test Log size %u not supported\n\n", nsectors
);
3201 raw_buffer
log_07_buf(nsectors
* 512);
3202 ata_smart_extselftestlog
* log_07
= (ata_smart_extselftestlog
*)log_07_buf
.data();
3203 if (!ataReadExtSelfTestLog(device
, log_07
, nsectors
)) {
3204 pout("Read SMART Extended Self-test Log failed\n\n");
3205 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3208 if (PrintSmartExtSelfTestLog(log_07
, nsectors
, options
.smart_ext_selftest_log
))
3209 returnval
|= FAILLOG
;
3215 if (options
.retry_selftest_log
)
3216 do_smart_selftest_log
= true;
3217 else if (!do_smart_selftest_log
)
3218 pout("Try '-l [xselftest,]selftest' to read traditional SMART Self Test Log\n");
3222 // Print SMART self-test log
3223 if (do_smart_selftest_log
) {
3224 if (!( ( smartlogdir
&& GetNumLogSectors(smartlogdir
, 0x06, false))
3225 || (!smartlogdir
&& isSmartTestLogCapable(&smartval
, &drive
) )
3226 || is_permissive() )) {
3227 pout("SMART Self-test Log not supported\n\n");
3230 ata_smart_selftestlog smartselftest
; memset(&smartselftest
, 0, sizeof(smartselftest
));
3231 if (ataReadSelfTestLog(device
, &smartselftest
, firmwarebugs
)) {
3232 pout("Read SMART Self-test Log failed: %s\n\n", device
->get_errmsg());
3233 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3237 if (ataPrintSmartSelfTestlog(&smartselftest
, !printing_is_switchable
, firmwarebugs
))
3238 returnval
|= FAILLOG
;
3245 // Print SMART selective self-test log
3246 if (options
.smart_selective_selftest_log
) {
3247 ata_selective_self_test_log log
;
3249 if (!isSupportSelectiveSelfTest(&smartval
))
3250 pout("Selective Self-tests/Logging not supported\n\n");
3251 else if(ataReadSelectiveSelfTestLog(device
, &log
)) {
3252 pout("Read SMART Selective Self-test Log failed: %s\n\n", device
->get_errmsg());
3253 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3257 // If any errors were found, they are logged in the SMART Self-test log.
3258 // So there is no need to print the Selective Self Test log in silent
3260 if (!printing_is_switchable
)
3261 ataPrintSelectiveSelfTestLog(&log
, &smartval
);
3267 // Check if SCT commands available
3268 bool sct_ok
= isSCTCapable(&drive
);
3269 if(!sct_ok
&& (options
.sct_temp_sts
|| options
.sct_temp_hist
|| options
.sct_temp_int
3270 || options
.sct_erc_get
|| options
.sct_erc_set
))
3271 pout("SCT Commands not supported\n\n");
3273 // Print SCT status and temperature history table
3274 if (sct_ok
&& (options
.sct_temp_sts
|| options
.sct_temp_hist
|| options
.sct_temp_int
)) {
3276 bool sct_temp_hist_ok
= isSCTDataTableCapable(&drive
);
3277 ata_sct_status_response sts
;
3279 if (options
.sct_temp_sts
|| (options
.sct_temp_hist
&& sct_temp_hist_ok
)) {
3281 if (ataReadSCTStatus(device
, &sts
)) {
3283 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3286 if (options
.sct_temp_sts
) {
3287 ataPrintSCTStatus(&sts
);
3292 if (!sct_temp_hist_ok
&& (options
.sct_temp_hist
|| options
.sct_temp_int
)) {
3293 pout("SCT Data Table command not supported\n\n");
3294 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3298 if (options
.sct_temp_hist
) {
3299 // Read SCT temperature history,
3300 // requires initial SCT status from above
3301 ata_sct_temperature_history_table tmh
;
3302 if (ataReadSCTTempHist(device
, &tmh
, &sts
)) {
3303 pout("Read SCT Temperature History failed\n\n");
3304 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3307 ataPrintSCTTempHist(&tmh
);
3311 if (options
.sct_temp_int
) {
3312 // Set new temperature logging interval
3313 if (!isSCTFeatureControlCapable(&drive
)) {
3314 pout("SCT Feature Control command not supported\n\n");
3315 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3318 if (ataSetSCTTempInterval(device
, options
.sct_temp_int
, options
.sct_temp_int_pers
)) {
3319 pout("Write Temperature Logging Interval failed\n\n");
3320 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3323 pout("Temperature Logging Interval set to %u minute%s (%s)\n",
3324 options
.sct_temp_int
, (options
.sct_temp_int
== 1 ? "" : "s"),
3325 (options
.sct_temp_int_pers
? "persistent" : "volatile"));
3331 // SCT Error Recovery Control
3332 if (sct_ok
&& (options
.sct_erc_get
|| options
.sct_erc_set
)) {
3333 if (!isSCTErrorRecoveryControlCapable(&drive
)) {
3334 pout("SCT Error Recovery Control command not supported\n\n");
3335 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3338 bool sct_erc_get
= options
.sct_erc_get
;
3339 if (options
.sct_erc_set
) {
3340 // Set SCT Error Recovery Control
3341 if ( ataSetSCTErrorRecoveryControltime(device
, 1, options
.sct_erc_readtime
)
3342 || ataSetSCTErrorRecoveryControltime(device
, 2, options
.sct_erc_writetime
)) {
3343 pout("SCT (Set) Error Recovery Control command failed\n");
3344 if (!( (options
.sct_erc_readtime
== 70 && options
.sct_erc_writetime
== 70)
3345 || (options
.sct_erc_readtime
== 0 && options
.sct_erc_writetime
== 0)))
3346 pout("Retry with: 'scterc,70,70' to enable ERC or 'scterc,0,0' to disable\n");
3347 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3348 sct_erc_get
= false;
3350 else if (!sct_erc_get
)
3351 ataPrintSCTErrorRecoveryControl(true, options
.sct_erc_readtime
,
3352 options
.sct_erc_writetime
);
3356 // Print SCT Error Recovery Control
3357 unsigned short read_timer
, write_timer
;
3358 if ( ataGetSCTErrorRecoveryControltime(device
, 1, read_timer
)
3359 || ataGetSCTErrorRecoveryControltime(device
, 2, write_timer
)) {
3360 pout("SCT (Get) Error Recovery Control command failed\n");
3361 if (options
.sct_erc_set
) {
3362 pout("The previous SCT (Set) Error Recovery Control command succeeded\n");
3363 ataPrintSCTErrorRecoveryControl(true, options
.sct_erc_readtime
,
3364 options
.sct_erc_writetime
);
3366 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3369 ataPrintSCTErrorRecoveryControl(false, read_timer
, write_timer
);
3375 // Print Device Statistics
3376 if (options
.devstat_all_pages
|| options
.devstat_ssd_page
|| !options
.devstat_pages
.empty()) {
3377 bool use_gplog
= true;
3378 unsigned nsectors
= 0;
3380 nsectors
= GetNumLogSectors(gplogdir
, 0x04, false);
3381 else if (smartlogdir
){ // for systems without ATA_READ_LOG_EXT
3382 nsectors
= GetNumLogSectors(smartlogdir
, 0x04, false);
3386 pout("Device Statistics (GP/SMART Log 0x04) not supported\n\n");
3387 else if (!print_device_statistics(device
, nsectors
, options
.devstat_pages
,
3388 options
.devstat_all_pages
, options
.devstat_ssd_page
, use_gplog
))
3389 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3392 // Print SATA Phy Event Counters
3393 if (options
.sataphy
) {
3394 unsigned nsectors
= GetNumLogSectors(gplogdir
, 0x11, true);
3395 // Packet interface devices do not provide a log directory, check support bit
3396 if (!nsectors
&& (drive
.words047_079
[76-47] & 0x0401) == 0x0400)
3399 pout("SATA Phy Event Counters (GP Log 0x11) not supported\n\n");
3400 else if (nsectors
!= 1)
3401 pout("SATA Phy Event Counters with %u sectors not supported\n\n", nsectors
);
3403 unsigned char log_11
[512] = {0, };
3404 unsigned char features
= (options
.sataphy_reset
? 0x01 : 0x00);
3405 if (!ataReadLogExt(device
, 0x11, features
, 0, log_11
, 1)) {
3406 pout("Read SATA Phy Event Counters failed\n\n");
3407 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3410 PrintSataPhyEventCounters(log_11
, options
.sataphy_reset
);
3414 // Set to standby (spindown) mode
3415 // (Above commands may spinup drive)
3416 if (options
.set_standby_now
) {
3417 if (!ata_nodata_command(device
, ATA_STANDBY_IMMEDIATE
)) {
3418 pout("ATA STANDBY IMMEDIATE command failed: %s\n", device
->get_errmsg());
3419 returnval
|= FAILSMART
;
3422 pout("Device placed in STANDBY mode\n");
3425 // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
3426 if (!smart_val_ok
|| options
.smart_selftest_type
== -1)
3429 pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
3430 // if doing a self-test, be sure it's supported by the hardware
3431 switch (options
.smart_selftest_type
) {
3432 case OFFLINE_FULL_SCAN
:
3433 if (!isSupportExecuteOfflineImmediate(&smartval
)){
3434 pout("Execute Offline Immediate function not supported\n\n");
3435 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3438 case ABORT_SELF_TEST
:
3439 case SHORT_SELF_TEST
:
3440 case EXTEND_SELF_TEST
:
3441 case SHORT_CAPTIVE_SELF_TEST
:
3442 case EXTEND_CAPTIVE_SELF_TEST
:
3443 if (!isSupportSelfTest(&smartval
)){
3444 pout("Self-test functions not supported\n\n");
3445 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3448 case CONVEYANCE_SELF_TEST
:
3449 case CONVEYANCE_CAPTIVE_SELF_TEST
:
3450 if (!isSupportConveyanceSelfTest(&smartval
)){
3451 pout("Conveyance Self-test functions not supported\n\n");
3452 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3455 case SELECTIVE_SELF_TEST
:
3456 case SELECTIVE_CAPTIVE_SELF_TEST
:
3457 if (!isSupportSelectiveSelfTest(&smartval
)){
3458 pout("Selective Self-test functions not supported\n\n");
3459 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
3463 break; // Vendor specific type
3466 // Now do the test. Note ataSmartTest prints its own error/success
3468 if (ataSmartTest(device
, options
.smart_selftest_type
, options
.smart_selftest_force
,
3469 options
.smart_selective_args
, &smartval
, sizes
.sectors
))
3470 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3472 // Tell user how long test will take to complete. This is tricky
3473 // because in the case of an Offline Full Scan, the completion
3474 // timer is volatile, and needs to be read AFTER the command is
3475 // given. If this will interrupt the Offline Full Scan, we don't
3476 // do it, just warn user.
3477 if (options
.smart_selftest_type
== OFFLINE_FULL_SCAN
) {
3478 if (isSupportOfflineAbort(&smartval
))
3479 pout("Note: giving further SMART commands will abort Offline testing\n");
3480 else if (ataReadSmartValues(device
, &smartval
)){
3481 pout("Read SMART Data failed: %s\n\n", device
->get_errmsg());
3482 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3486 // Now say how long the test will take to complete
3487 int timewait
= TestTime(&smartval
, options
.smart_selftest_type
);
3489 time_t t
=time(NULL
);
3490 if (options
.smart_selftest_type
== OFFLINE_FULL_SCAN
) {
3492 pout("Please wait %d seconds for test to complete.\n", (int)timewait
);
3495 pout("Please wait %d minutes for test to complete.\n", (int)timewait
);
3497 pout("Test will complete after %s\n", ctime(&t
));
3499 if ( options
.smart_selftest_type
!= SHORT_CAPTIVE_SELF_TEST
3500 && options
.smart_selftest_type
!= EXTEND_CAPTIVE_SELF_TEST
3501 && options
.smart_selftest_type
!= CONVEYANCE_CAPTIVE_SELF_TEST
3502 && options
.smart_selftest_type
!= SELECTIVE_CAPTIVE_SELF_TEST
)
3503 pout("Use smartctl -X to abort test.\n");