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 3999 2014-10-06 15:57:52Z chrfranke $"
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 const char * get_form_factor(unsigned short word168
)
417 // Table A.32 of T13/2161-D (ACS-3) Revision 4p, September 19, 2013
418 // Table 236 of T13/BSR INCITS 529 (ACS-4) Revision 04, August 25, 2014
420 case 0x1: return "5.25 inches";
421 case 0x2: return "3.5 inches";
422 case 0x3: return "2.5 inches";
423 case 0x4: return "1.8 inches";
424 case 0x5: return "< 1.8 inches";
425 case 0x6: return "mSATA"; // ACS-4
426 case 0x7: return "M.2"; // ACS-4
427 case 0x8: return "MicroSSD"; // ACS-4
428 case 0x9: return "CFast"; // ACS-4
433 static int find_msb(unsigned short word
)
435 for (int bit
= 15; bit
>= 0; bit
--)
436 if (word
& (1 << bit
))
441 static const char * get_ata_major_version(const ata_identify_device
* drive
)
443 switch (find_msb(drive
->major_rev_num
)) {
444 case 10: return "ACS-3";
445 case 9: return "ACS-2";
446 case 8: return "ATA8-ACS";
447 case 7: return "ATA/ATAPI-7";
448 case 6: return "ATA/ATAPI-6";
449 case 5: return "ATA/ATAPI-5";
450 case 4: return "ATA/ATAPI-4";
451 case 3: return "ATA-3";
452 case 2: return "ATA-2";
453 case 1: return "ATA-1";
458 static const char * get_ata_minor_version(const ata_identify_device
* drive
)
460 // Table 10 of X3T13/2008D (ATA-3) Revision 7b, January 27, 1997
461 // Table 28 of T13/1410D (ATA/ATAPI-6) Revision 3b, February 26, 2002
462 // Table 31 of T13/1699-D (ATA8-ACS) Revision 6a, September 6, 2008
463 // Table 45 of T13/BSR INCITS 529 (ACS-4) Revision 04, August 25, 2014
464 switch (drive
->minor_rev_num
) {
465 case 0x0001: return "ATA-1 X3T9.2/781D prior to revision 4";
466 case 0x0002: return "ATA-1 published, ANSI X3.221-1994";
467 case 0x0003: return "ATA-1 X3T9.2/781D revision 4";
468 case 0x0004: return "ATA-2 published, ANSI X3.279-1996";
469 case 0x0005: return "ATA-2 X3T10/948D prior to revision 2k";
470 case 0x0006: return "ATA-3 X3T10/2008D revision 1";
471 case 0x0007: return "ATA-2 X3T10/948D revision 2k";
472 case 0x0008: return "ATA-3 X3T10/2008D revision 0";
473 case 0x0009: return "ATA-2 X3T10/948D revision 3";
474 case 0x000a: return "ATA-3 published, ANSI X3.298-1997";
475 case 0x000b: return "ATA-3 X3T10/2008D revision 6"; // 1st ATA-3 revision with SMART
476 case 0x000c: return "ATA-3 X3T13/2008D revision 7 and 7a";
477 case 0x000d: return "ATA/ATAPI-4 X3T13/1153D revision 6";
478 case 0x000e: return "ATA/ATAPI-4 T13/1153D revision 13";
479 case 0x000f: return "ATA/ATAPI-4 X3T13/1153D revision 7";
480 case 0x0010: return "ATA/ATAPI-4 T13/1153D revision 18";
481 case 0x0011: return "ATA/ATAPI-4 T13/1153D revision 15";
482 case 0x0012: return "ATA/ATAPI-4 published, ANSI NCITS 317-1998";
483 case 0x0013: return "ATA/ATAPI-5 T13/1321D revision 3";
484 case 0x0014: return "ATA/ATAPI-4 T13/1153D revision 14";
485 case 0x0015: return "ATA/ATAPI-5 T13/1321D revision 1";
486 case 0x0016: return "ATA/ATAPI-5 published, ANSI NCITS 340-2000";
487 case 0x0017: return "ATA/ATAPI-4 T13/1153D revision 17";
488 case 0x0018: return "ATA/ATAPI-6 T13/1410D revision 0";
489 case 0x0019: return "ATA/ATAPI-6 T13/1410D revision 3a";
490 case 0x001a: return "ATA/ATAPI-7 T13/1532D revision 1";
491 case 0x001b: return "ATA/ATAPI-6 T13/1410D revision 2";
492 case 0x001c: return "ATA/ATAPI-6 T13/1410D revision 1";
493 case 0x001d: return "ATA/ATAPI-7 published, ANSI INCITS 397-2005";
494 case 0x001e: return "ATA/ATAPI-7 T13/1532D revision 0";
495 case 0x001f: return "ACS-3 T13/2161-D revision 3b";
497 case 0x0021: return "ATA/ATAPI-7 T13/1532D revision 4a";
498 case 0x0022: return "ATA/ATAPI-6 published, ANSI INCITS 361-2002";
500 case 0x0027: return "ATA8-ACS T13/1699-D revision 3c";
501 case 0x0028: return "ATA8-ACS T13/1699-D revision 6";
502 case 0x0029: return "ATA8-ACS T13/1699-D revision 4";
504 case 0x0031: return "ACS-2 T13/2015-D revision 2";
506 case 0x0033: return "ATA8-ACS T13/1699-D revision 3e";
508 case 0x0039: return "ATA8-ACS T13/1699-D revision 4c";
510 case 0x0042: return "ATA8-ACS T13/1699-D revision 3f";
512 case 0x0052: return "ATA8-ACS T13/1699-D revision 3b";
514 case 0x006d: return "ACS-3 T13/2161-D revision 5";
516 case 0x0082: return "ACS-2 published, ANSI INCITS 482-2012";
518 case 0x0107: return "ATA8-ACS T13/1699-D revision 2d";
520 case 0x0110: return "ACS-2 T13/2015-D revision 3";
522 case 0x011b: return "ACS-3 T13/2161-D revision 4";
528 static const char * get_sata_version(const ata_identify_device
* drive
)
530 unsigned short word222
= drive
->words088_255
[222-88];
531 if ((word222
& 0xf000) != 0x1000)
533 switch (find_msb(word222
& 0x0fff)) {
534 default: return "SATA >3.2";
535 case 7: return "SATA 3.2";
536 case 6: return "SATA 3.1";
537 case 5: return "SATA 3.0";
538 case 4: return "SATA 2.6";
539 case 3: return "SATA 2.5";
540 case 2: return "SATA II Ext";
541 case 1: return "SATA 1.0a";
542 case 0: return "ATA8-AST";
547 static const char * get_sata_speed(int level
)
552 default: return ">6.0 Gb/s";
553 case 3: return "6.0 Gb/s";
554 case 2: return "3.0 Gb/s";
555 case 1: return "1.5 Gb/s";
559 static const char * get_sata_maxspeed(const ata_identify_device
* drive
)
561 unsigned short word076
= drive
->words047_079
[76-47];
562 if (word076
& 0x0001)
564 return get_sata_speed(find_msb(word076
& 0x00fe));
567 static const char * get_sata_curspeed(const ata_identify_device
* drive
)
569 unsigned short word077
= drive
->words047_079
[77-47];
570 if (word077
& 0x0001)
572 return get_sata_speed((word077
>> 1) & 0x7);
576 static void print_drive_info(const ata_identify_device
* drive
,
577 const ata_size_info
& sizes
, int rpm
,
578 const drive_settings
* dbentry
)
580 // format drive information (with byte swapping as needed)
581 char model
[40+1], serial
[20+1], firmware
[8+1];
582 ata_format_id_string(model
, drive
->model
, sizeof(model
)-1);
583 ata_format_id_string(serial
, drive
->serial_no
, sizeof(serial
)-1);
584 ata_format_id_string(firmware
, drive
->fw_rev
, sizeof(firmware
)-1);
586 // Print model family if known
587 if (dbentry
&& *dbentry
->modelfamily
)
588 pout("Model Family: %s\n", dbentry
->modelfamily
);
590 pout("Device Model: %s\n", infofound(model
));
591 if (!dont_print_serial_number
) {
592 pout("Serial Number: %s\n", infofound(serial
));
594 unsigned oui
= 0; uint64_t unique_id
= 0;
595 int naa
= ata_get_wwn(drive
, oui
, unique_id
);
597 pout("LU WWN Device Id: %x %06x %09" PRIx64
"\n", naa
, oui
, unique_id
);
599 // Additional Product Identifier (OEM Id) string in words 170-173
600 // (e08130r1, added in ACS-2 Revision 1, December 17, 2008)
601 if (0x2020 <= drive
->words088_255
[170-88] && drive
->words088_255
[170-88] <= 0x7e7e) {
603 ata_format_id_string(add
, (const unsigned char *)(drive
->words088_255
+170-88), sizeof(add
)-1);
605 pout("Add. Product Id: %s\n", add
);
608 pout("Firmware Version: %s\n", infofound(firmware
));
610 if (sizes
.capacity
) {
612 char num
[64], cap
[32];
613 pout("User Capacity: %s bytes [%s]\n",
614 format_with_thousands_sep(num
, sizeof(num
), sizes
.capacity
),
615 format_capacity(cap
, sizeof(cap
), sizes
.capacity
));
617 // Print sector sizes.
618 if (sizes
.phy_sector_size
== sizes
.log_sector_size
)
619 pout("Sector Size: %u bytes logical/physical\n", sizes
.log_sector_size
);
621 pout("Sector Sizes: %u bytes logical, %u bytes physical",
622 sizes
.log_sector_size
, sizes
.phy_sector_size
);
623 if (sizes
.log_sector_offset
)
624 pout(" (offset %u bytes)", sizes
.log_sector_offset
);
629 // Print nominal media rotation rate if reported
632 pout("Rotation Rate: Solid State Device\n");
634 pout("Rotation Rate: %d rpm\n", rpm
);
636 pout("Rotation Rate: Unknown (0x%04x)\n", -rpm
);
639 // Print form factor if reported
640 unsigned short word168
= drive
->words088_255
[168-88];
642 const char * form_factor
= get_form_factor(word168
);
644 pout("Form Factor: %s\n", form_factor
);
646 pout("Form Factor: Unknown (0x%04x)\n", word168
);
649 // See if drive is recognized
650 pout("Device is: %s\n", !dbentry
?
651 "Not in smartctl database [for details use: -P showall]":
652 "In smartctl database [for details use: -P show]");
656 if ( (drive
->major_rev_num
!= 0x0000 && drive
->major_rev_num
!= 0xffff)
657 || (drive
->minor_rev_num
!= 0x0000 && drive
->minor_rev_num
!= 0xffff)) {
658 const char * majorver
= get_ata_major_version(drive
);
659 const char * minorver
= get_ata_minor_version(drive
);
661 if (majorver
&& minorver
&& str_starts_with(minorver
, majorver
)) {
662 // Major and minor strings match, print minor string only
669 ataver
= strprintf("Unknown(0x%04x)", drive
->major_rev_num
);
672 ataver
+= strprintf(", %s", minorver
);
673 else if (drive
->minor_rev_num
!= 0x0000 && drive
->minor_rev_num
!= 0xffff)
674 ataver
+= strprintf(" (unknown minor revision code: 0x%04x)", drive
->minor_rev_num
);
676 ataver
+= " (minor revision not indicated)";
679 pout("ATA Version is: %s\n", infofound(ataver
.c_str()));
681 // If SATA drive print SATA version and speed
682 const char * sataver
= get_sata_version(drive
);
684 const char * maxspeed
= get_sata_maxspeed(drive
);
685 const char * curspeed
= get_sata_curspeed(drive
);
686 pout("SATA Version is: %s%s%s%s%s%s\n", sataver
,
687 (maxspeed
? ", " : ""), (maxspeed
? maxspeed
: ""),
688 (curspeed
? " (current: " : ""), (curspeed
? curspeed
: ""),
689 (curspeed
? ")" : ""));
692 // print current time and date and timezone
693 char timedatetz
[DATEANDEPOCHLEN
]; dateandtimezone(timedatetz
);
694 pout("Local Time is: %s\n", timedatetz
);
696 // Print warning message, if there is one
697 if (dbentry
&& *dbentry
->warningmsg
)
698 pout("\n==> WARNING: %s\n\n", dbentry
->warningmsg
);
701 static const char *OfflineDataCollectionStatus(unsigned char status_byte
)
703 unsigned char stat
=status_byte
& 0x7f;
707 return "was never started";
709 return "was completed without error";
711 if (status_byte
== 0x03)
712 return "is in progress";
714 return "is in a Reserved state";
716 return "was suspended by an interrupting command from host";
718 return "was aborted by an interrupting command from host";
720 return "was aborted by the device with a fatal error";
723 return "is in a Vendor Specific state";
725 return "is in a Reserved state";
730 // prints verbose value Off-line data collection status byte
731 static void PrintSmartOfflineStatus(const ata_smart_values
* data
)
733 pout("Offline data collection status: (0x%02x)\t",
734 (int)data
->offline_data_collection_status
);
736 // Off-line data collection status byte is not a reserved
737 // or vendor specific value
738 pout("Offline data collection activity\n"
739 "\t\t\t\t\t%s.\n", OfflineDataCollectionStatus(data
->offline_data_collection_status
));
741 // Report on Automatic Data Collection Status. Only IBM documents
742 // this bit. See SFF 8035i Revision 2 for details.
743 if (data
->offline_data_collection_status
& 0x80)
744 pout("\t\t\t\t\tAuto Offline Data Collection: Enabled.\n");
746 pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
751 static void PrintSmartSelfExecStatus(const ata_smart_values
* data
,
752 firmwarebug_defs firmwarebugs
)
754 pout("Self-test execution status: ");
756 switch (data
->self_test_exec_status
>> 4)
759 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
760 (int)data
->self_test_exec_status
);
761 pout("without error or no self-test has ever \n\t\t\t\t\tbeen run.\n");
764 pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
765 (int)data
->self_test_exec_status
);
769 pout("(%4d)\tThe self-test routine was interrupted\n\t\t\t\t\t",
770 (int)data
->self_test_exec_status
);
771 pout("by the host with a hard or soft reset.\n");
774 pout("(%4d)\tA fatal error or unknown test error\n\t\t\t\t\t",
775 (int)data
->self_test_exec_status
);
776 pout("occurred while the device was executing\n\t\t\t\t\t");
777 pout("its self-test routine and the device \n\t\t\t\t\t");
778 pout("was unable to complete the self-test \n\t\t\t\t\t");
782 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
783 (int)data
->self_test_exec_status
);
784 pout("a test element that failed and the test\n\t\t\t\t\t");
785 pout("element that failed is not known.\n");
788 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
789 (int)data
->self_test_exec_status
);
790 pout("the electrical element of the test\n\t\t\t\t\t");
794 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
795 (int)data
->self_test_exec_status
);
796 pout("the servo (and/or seek) element of the \n\t\t\t\t\t");
797 pout("test failed.\n");
800 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
801 (int)data
->self_test_exec_status
);
802 pout("the read element of the test failed.\n");
805 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
806 (int)data
->self_test_exec_status
);
807 pout("a test element that failed and the\n\t\t\t\t\t");
808 pout("device is suspected of having handling\n\t\t\t\t\t");
812 if (firmwarebugs
.is_set(BUG_SAMSUNG3
) && data
->self_test_exec_status
== 0xf0) {
813 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
814 (int)data
->self_test_exec_status
);
815 pout("with unknown result or self-test in\n\t\t\t\t\t");
816 pout("progress with less than 10%% remaining.\n");
819 pout("(%4d)\tSelf-test routine in progress...\n\t\t\t\t\t",
820 (int)data
->self_test_exec_status
);
821 pout("%1d0%% of test remaining.\n",
822 (int)(data
->self_test_exec_status
& 0x0f));
826 pout("(%4d)\tReserved.\n",
827 (int)data
->self_test_exec_status
);
833 static void PrintSmartTotalTimeCompleteOffline (const ata_smart_values
* data
)
835 pout("Total time to complete Offline \n");
836 pout("data collection: \t\t(%5d) seconds.\n",
837 (int)data
->total_time_to_complete_off_line
);
840 static void PrintSmartOfflineCollectCap(const ata_smart_values
*data
)
842 pout("Offline data collection\n");
843 pout("capabilities: \t\t\t (0x%02x) ",
844 (int)data
->offline_data_collection_capability
);
846 if (data
->offline_data_collection_capability
== 0x00){
847 pout("\tOffline data collection not supported.\n");
850 pout( "%s\n", isSupportExecuteOfflineImmediate(data
)?
851 "SMART execute Offline immediate." :
852 "No SMART execute Offline immediate.");
854 pout( "\t\t\t\t\t%s\n", isSupportAutomaticTimer(data
)?
855 "Auto Offline data collection on/off support.":
856 "No Auto Offline data collection support.");
858 pout( "\t\t\t\t\t%s\n", isSupportOfflineAbort(data
)?
859 "Abort Offline collection upon new\n\t\t\t\t\tcommand.":
860 "Suspend Offline collection upon new\n\t\t\t\t\tcommand.");
862 pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data
)?
863 "Offline surface scan supported.":
864 "No Offline surface scan supported.");
866 pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data
)?
867 "Self-test supported.":
868 "No Self-test supported.");
870 pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data
)?
871 "Conveyance Self-test supported.":
872 "No Conveyance Self-test supported.");
874 pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data
)?
875 "Selective Self-test supported.":
876 "No Selective Self-test supported.");
880 static void PrintSmartCapability(const ata_smart_values
*data
)
882 pout("SMART capabilities: ");
883 pout("(0x%04x)\t", (int)data
->smart_capability
);
885 if (data
->smart_capability
== 0x00)
887 pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
892 pout( "%s\n", (data
->smart_capability
& 0x01)?
893 "Saves SMART data before entering\n\t\t\t\t\tpower-saving mode.":
894 "Does not save SMART data before\n\t\t\t\t\tentering power-saving mode.");
896 if ( data
->smart_capability
& 0x02 )
898 pout("\t\t\t\t\tSupports SMART auto save timer.\n");
903 static void PrintSmartErrorLogCapability(const ata_smart_values
* data
, const ata_identify_device
* identity
)
905 pout("Error logging capability: ");
907 if ( isSmartErrorLogCapable(data
, identity
) )
909 pout(" (0x%02x)\tError logging supported.\n",
910 (int)data
->errorlog_capability
);
913 pout(" (0x%02x)\tError logging NOT supported.\n",
914 (int)data
->errorlog_capability
);
918 static void PrintSmartShortSelfTestPollingTime(const ata_smart_values
* data
)
920 pout("Short self-test routine \n");
921 if (isSupportSelfTest(data
))
922 pout("recommended polling time: \t (%4d) minutes.\n",
923 (int)data
->short_test_completion_time
);
925 pout("recommended polling time: \t Not Supported.\n");
928 static void PrintSmartExtendedSelfTestPollingTime(const ata_smart_values
* data
)
930 pout("Extended self-test routine\n");
931 if (isSupportSelfTest(data
))
932 pout("recommended polling time: \t (%4d) minutes.\n",
933 TestTime(data
, EXTEND_SELF_TEST
));
935 pout("recommended polling time: \t Not Supported.\n");
938 static void PrintSmartConveyanceSelfTestPollingTime(const ata_smart_values
* data
)
940 pout("Conveyance self-test routine\n");
941 if (isSupportConveyanceSelfTest(data
))
942 pout("recommended polling time: \t (%4d) minutes.\n",
943 (int)data
->conveyance_test_completion_time
);
945 pout("recommended polling time: \t Not Supported.\n");
948 // Check SMART attribute table for Threshold failure
949 // onlyfailed=0: are or were any age or prefailure attributes <= threshold
950 // onlyfailed=1: are any prefailure attributes <= threshold now
951 static int find_failed_attr(const ata_smart_values
* data
,
952 const ata_smart_thresholds_pvt
* thresholds
,
953 const ata_vendor_attr_defs
& defs
, int onlyfailed
)
955 for (int i
= 0; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
956 const ata_smart_attribute
& attr
= data
->vendor_attributes
[i
];
958 ata_attr_state state
= ata_get_attr_state(attr
, i
, thresholds
->thres_entries
, defs
);
961 if (state
>= ATTRSTATE_FAILED_PAST
)
965 if (state
== ATTRSTATE_FAILED_NOW
&& ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
))
972 // onlyfailed=0 : print all attribute values
973 // onlyfailed=1: just ones that are currently failed and have prefailure bit set
974 // onlyfailed=2: ones that are failed, or have failed with or without prefailure bit set
975 static void PrintSmartAttribWithThres(const ata_smart_values
* data
,
976 const ata_smart_thresholds_pvt
* thresholds
,
977 const ata_vendor_attr_defs
& defs
, int rpm
,
978 int onlyfailed
, unsigned char format
)
980 bool brief
= !!(format
& ata_print_options::FMT_BRIEF
);
981 bool hexid
= !!(format
& ata_print_options::FMT_HEX_ID
);
982 bool hexval
= !!(format
& ata_print_options::FMT_HEX_VAL
);
983 bool needheader
= true;
985 // step through all vendor attributes
986 for (int i
= 0; i
< NUMBER_ATA_SMART_ATTRIBUTES
; i
++) {
987 const ata_smart_attribute
& attr
= data
->vendor_attributes
[i
];
989 // Check attribute and threshold
990 unsigned char threshold
= 0;
991 ata_attr_state state
= ata_get_attr_state(attr
, i
, thresholds
->thres_entries
, defs
, &threshold
);
992 if (state
== ATTRSTATE_NON_EXISTING
)
995 // These break out of the loop if we are only printing certain entries...
996 if (onlyfailed
== 1 && !(ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
) && state
== ATTRSTATE_FAILED_NOW
))
999 if (onlyfailed
== 2 && state
< ATTRSTATE_FAILED_PAST
)
1002 // print header only if needed
1005 pout("SMART Attributes Data Structure revision number: %d\n",(int)data
->revnumber
);
1006 pout("Vendor Specific SMART Attributes with Thresholds:\n");
1009 pout("ID#%s ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n",
1010 (!hexid
? "" : " "));
1012 pout("ID#%s ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE\n",
1013 (!hexid
? "" : " "));
1017 // Format value, worst, threshold
1018 std::string valstr
, worstr
, threstr
;
1019 if (state
> ATTRSTATE_NO_NORMVAL
)
1020 valstr
= (!hexval
? strprintf("%.3d", attr
.current
)
1021 : strprintf("0x%02x", attr
.current
));
1023 valstr
= (!hexval
? "---" : "----");
1024 if (!(defs
[attr
.id
].flags
& ATTRFLAG_NO_WORSTVAL
))
1025 worstr
= (!hexval
? strprintf("%.3d", attr
.worst
)
1026 : strprintf("0x%02x", attr
.worst
));
1028 worstr
= (!hexval
? "---" : "----");
1029 if (state
> ATTRSTATE_NO_THRESHOLD
)
1030 threstr
= (!hexval
? strprintf("%.3d", threshold
)
1031 : strprintf("0x%02x", threshold
));
1033 threstr
= (!hexval
? "---" : "----");
1035 // Print line for each valid attribute
1036 std::string idstr
= (!hexid
? strprintf("%3d", attr
.id
)
1037 : strprintf("0x%02x", attr
.id
));
1038 std::string attrname
= ata_get_smart_attr_name(attr
.id
, defs
, rpm
);
1039 std::string rawstr
= ata_format_attr_raw_value(attr
, defs
);
1042 pout("%s %-24s0x%04x %-4s %-4s %-4s %-10s%-9s%-12s%s\n",
1043 idstr
.c_str(), attrname
.c_str(), attr
.flags
,
1044 valstr
.c_str(), worstr
.c_str(), threstr
.c_str(),
1045 (ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
) ? "Pre-fail" : "Old_age"),
1046 (ATTRIBUTE_FLAGS_ONLINE(attr
.flags
) ? "Always" : "Offline"),
1047 (state
== ATTRSTATE_FAILED_NOW
? "FAILING_NOW" :
1048 state
== ATTRSTATE_FAILED_PAST
? "In_the_past"
1052 pout("%s %-24s%c%c%c%c%c%c%c %-4s %-4s %-4s %-5s%s\n",
1053 idstr
.c_str(), attrname
.c_str(),
1054 (ATTRIBUTE_FLAGS_PREFAILURE(attr
.flags
) ? 'P' : '-'),
1055 (ATTRIBUTE_FLAGS_ONLINE(attr
.flags
) ? 'O' : '-'),
1056 (ATTRIBUTE_FLAGS_PERFORMANCE(attr
.flags
) ? 'S' : '-'),
1057 (ATTRIBUTE_FLAGS_ERRORRATE(attr
.flags
) ? 'R' : '-'),
1058 (ATTRIBUTE_FLAGS_EVENTCOUNT(attr
.flags
) ? 'C' : '-'),
1059 (ATTRIBUTE_FLAGS_SELFPRESERVING(attr
.flags
) ? 'K' : '-'),
1060 (ATTRIBUTE_FLAGS_OTHER(attr
.flags
) ? '+' : ' '),
1061 valstr
.c_str(), worstr
.c_str(), threstr
.c_str(),
1062 (state
== ATTRSTATE_FAILED_NOW
? "NOW" :
1063 state
== ATTRSTATE_FAILED_PAST
? "Past"
1070 if (!onlyfailed
&& brief
) {
1071 int n
= (!hexid
? 28 : 29);
1072 pout("%*s||||||_ K auto-keep\n"
1073 "%*s|||||__ C event count\n"
1074 "%*s||||___ R error rate\n"
1075 "%*s|||____ S speed/performance\n"
1076 "%*s||_____ O updated online\n"
1077 "%*s|______ P prefailure warning\n",
1078 n
, "", n
, "", n
, "", n
, "", n
, "", n
, "");
1084 // Print SMART related SCT capabilities
1085 static void ataPrintSCTCapability(const ata_identify_device
*drive
)
1087 unsigned short sctcaps
= drive
->words088_255
[206-88];
1088 if (!(sctcaps
& 0x01))
1090 pout("SCT capabilities: \t (0x%04x)\tSCT Status supported.\n", sctcaps
);
1092 pout("\t\t\t\t\tSCT Error Recovery Control supported.\n");
1094 pout("\t\t\t\t\tSCT Feature Control supported.\n");
1096 pout("\t\t\t\t\tSCT Data Table supported.\n");
1100 static void PrintGeneralSmartValues(const ata_smart_values
*data
, const ata_identify_device
*drive
,
1101 firmwarebug_defs firmwarebugs
)
1103 pout("General SMART Values:\n");
1105 PrintSmartOfflineStatus(data
);
1107 if (isSupportSelfTest(data
)){
1108 PrintSmartSelfExecStatus(data
, firmwarebugs
);
1111 PrintSmartTotalTimeCompleteOffline(data
);
1112 PrintSmartOfflineCollectCap(data
);
1113 PrintSmartCapability(data
);
1115 PrintSmartErrorLogCapability(data
, drive
);
1117 pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive
)?
1118 "General Purpose Logging supported.":
1119 "No General Purpose Logging support.");
1121 if (isSupportSelfTest(data
)){
1122 PrintSmartShortSelfTestPollingTime (data
);
1123 PrintSmartExtendedSelfTestPollingTime (data
);
1125 if (isSupportConveyanceSelfTest(data
))
1126 PrintSmartConveyanceSelfTestPollingTime (data
);
1128 ataPrintSCTCapability(drive
);
1133 // Get # sectors of a log addr, 0 if log does not exist.
1134 static unsigned GetNumLogSectors(const ata_smart_log_directory
* logdir
, unsigned logaddr
, bool gpl
)
1142 unsigned n
= logdir
->entry
[logaddr
-1].numsectors
;
1144 // GP logs may have >255 sectors
1145 n
|= logdir
->entry
[logaddr
-1].reserved
<< 8;
1150 static const char * GetLogName(unsigned logaddr
)
1152 // Table 201 of T13/BSR INCITS 529 (ACS-4) Revision 04, August 25, 2014
1153 // Table 112 of Serial ATA Revision 3.2, August 7, 2013
1155 case 0x00: return "Log Directory";
1156 case 0x01: return "Summary SMART error log";
1157 case 0x02: return "Comprehensive SMART error log";
1158 case 0x03: return "Ext. Comprehensive SMART error log";
1159 case 0x04: return "Device Statistics log";
1160 case 0x05: return "Reserved for CFA"; // ACS-2
1161 case 0x06: return "SMART self-test log";
1162 case 0x07: return "Extended self-test log";
1163 case 0x08: return "Power Conditions log"; // ACS-2
1164 case 0x09: return "Selective self-test log";
1165 case 0x0a: return "Device Statistics Notification"; // ACS-3
1166 case 0x0b: return "Reserved for CFA"; // ACS-3
1167 case 0x0c: return "Pending Defects log"; // ACS-4
1168 case 0x0d: return "LPS Mis-alignment log"; // ACS-2
1170 case 0x10: return "SATA NCQ Queued Error log";
1171 case 0x11: return "SATA Phy Event Counters log";
1172 //case 0x12: return "SATA NCQ Queue Management log"; // SATA 3.0/3.1
1173 case 0x12: return "SATA NCQ NON-DATA log"; // SATA 3.2
1174 case 0x13: return "SATA NCQ Send and Receive log"; // SATA 3.1
1175 case 0x14: return "SATA Hybrid Information log"; // SATA 3.2
1176 case 0x15: return "SATA Rebuild Assist log"; // SATA 3.2
1178 case 0x17: return "Reserved for Serial ATA";
1180 case 0x19: return "LBA Status log"; // ACS-3
1182 case 0x20: return "Streaming performance log [OBS-8]";
1183 case 0x21: return "Write stream error log";
1184 case 0x22: return "Read stream error log";
1185 case 0x23: return "Delayed sector log [OBS-8]";
1186 case 0x24: return "Current Device Internal Status Data log"; // ACS-3
1187 case 0x25: return "Saved Device Internal Status Data log"; // ACS-3
1189 case 0x30: return "IDENTIFY DEVICE data log"; // ACS-3
1191 case 0xe0: return "SCT Command/Status";
1192 case 0xe1: return "SCT Data Transfer";
1194 if (0xa0 <= logaddr
&& logaddr
<= 0xdf)
1195 return "Device vendor specific log";
1196 if (0x80 <= logaddr
&& logaddr
<= 0x9f)
1197 return "Host vendor specific log";
1203 // Get log access permissions
1204 static const char * get_log_rw(unsigned logaddr
)
1206 if ( ( logaddr
<= 0x08)
1207 || (0x0c <= logaddr
&& logaddr
<= 0x0d)
1208 || (0x10 <= logaddr
&& logaddr
<= 0x14)
1209 || (0x19 == logaddr
)
1210 || (0x20 <= logaddr
&& logaddr
<= 0x25)
1211 || (0x30 == logaddr
))
1214 if ( (0x09 <= logaddr
&& logaddr
<= 0x0a)
1215 || (0x15 == logaddr
)
1216 || (0x80 <= logaddr
&& logaddr
<= 0x9f)
1217 || (0xe0 <= logaddr
&& logaddr
<= 0xe1))
1220 if (0xa0 <= logaddr
&& logaddr
<= 0xdf)
1221 return "VS"; // Vendor specific
1223 return "-"; // Unknown/Reserved
1226 // Init a fake log directory, assume that standard logs are supported
1227 const ata_smart_log_directory
* fake_logdir(ata_smart_log_directory
* logdir
,
1228 const ata_print_options
& options
)
1230 memset(logdir
, 0, sizeof(*logdir
));
1231 logdir
->logversion
= 255;
1232 logdir
->entry
[0x01-1].numsectors
= 1;
1233 logdir
->entry
[0x03-1].numsectors
= (options
.smart_ext_error_log
+ (4-1)) / 4;
1234 logdir
->entry
[0x04-1].numsectors
= 8;
1235 logdir
->entry
[0x06-1].numsectors
= 1;
1236 logdir
->entry
[0x07-1].numsectors
= (options
.smart_ext_selftest_log
+ (19-1)) / 19;
1237 logdir
->entry
[0x09-1].numsectors
= 1;
1238 logdir
->entry
[0x11-1].numsectors
= 1;
1242 // Print SMART and/or GP Log Directory
1243 static void PrintLogDirectories(const ata_smart_log_directory
* gplogdir
,
1244 const ata_smart_log_directory
* smartlogdir
)
1247 pout("General Purpose Log Directory Version %u\n", gplogdir
->logversion
);
1249 pout("SMART %sLog Directory Version %u%s\n",
1250 (gplogdir
? " " : ""), smartlogdir
->logversion
,
1251 (smartlogdir
->logversion
==1 ? " [multi-sector log support]" : ""));
1253 pout("Address Access R/W Size Description\n");
1255 for (unsigned i
= 0; i
<= 0xff; i
++) {
1256 // Get number of sectors
1257 unsigned smart_numsect
= GetNumLogSectors(smartlogdir
, i
, false);
1258 unsigned gp_numsect
= GetNumLogSectors(gplogdir
, i
, true );
1260 if (!(smart_numsect
|| gp_numsect
))
1261 continue; // Log does not exist
1263 const char * acc
; unsigned size
;
1264 if (smart_numsect
== gp_numsect
) {
1265 acc
= "GPL,SL"; size
= gp_numsect
;
1267 else if (!smart_numsect
) {
1268 acc
= "GPL"; size
= gp_numsect
;
1270 else if (!gp_numsect
) {
1271 acc
= " SL"; size
= smart_numsect
;
1278 if (acc
&& ((0x80 <= i
&& i
< 0x9f) || (0xa0 <= i
&& i
< 0xdf))) {
1279 // Find range of Host/Device vendor specific logs with same size
1280 unsigned imax
= (i
< 0x9f ? 0x9f : 0xdf);
1281 for (unsigned j
= i
+1; j
<= imax
; j
++) {
1282 unsigned sn
= GetNumLogSectors(smartlogdir
, j
, false);
1283 unsigned gn
= GetNumLogSectors(gplogdir
, j
, true );
1285 if (!(sn
== smart_numsect
&& gn
== gp_numsect
))
1291 const char * name
= GetLogName(i
);
1292 const char * rw
= get_log_rw(i
);
1295 pout("0x%02x-0x%02x %-6s %-3s %5u %s\n", i
, i2
, acc
, rw
, size
, name
);
1299 pout( "0x%02x %-6s %-3s %5u %s\n", i
, acc
, rw
, size
, name
);
1301 // GPL and SL support different sizes
1302 pout( "0x%02x %-6s %-3s %5u %s\n", i
, "GPL", rw
, gp_numsect
, name
);
1303 pout( "0x%02x %-6s %-3s %5u %s\n", i
, "SL", rw
, smart_numsect
, name
);
1309 // Print hexdump of log pages.
1310 // Format is compatible with 'xxd -r'.
1311 static void PrintLogPages(const char * type
, const unsigned char * data
,
1312 unsigned char logaddr
, unsigned page
,
1313 unsigned num_pages
, unsigned max_pages
)
1315 pout("%s Log 0x%02x [%s], Page %u-%u (of %u)\n",
1316 type
, logaddr
, GetLogName(logaddr
), page
, page
+num_pages
-1, max_pages
);
1317 for (unsigned i
= 0; i
< num_pages
* 512; i
+= 16) {
1318 const unsigned char * p
= data
+i
;
1319 pout("%07x: %02x %02x %02x %02x %02x %02x %02x %02x "
1320 "%02x %02x %02x %02x %02x %02x %02x %02x ",
1322 p
[ 0], p
[ 1], p
[ 2], p
[ 3], p
[ 4], p
[ 5], p
[ 6], p
[ 7],
1323 p
[ 8], p
[ 9], p
[10], p
[11], p
[12], p
[13], p
[14], p
[15]);
1324 #define P(n) (' ' <= p[n] && p[n] <= '~' ? (int)p[n] : '.')
1325 pout("|%c%c%c%c%c%c%c%c"
1326 "%c%c%c%c%c%c%c%c|\n",
1327 P( 0), P( 1), P( 2), P( 3), P( 4), P( 5), P( 6), P( 7),
1328 P( 8), P( 9), P(10), P(11), P(12), P(13), P(14), P(15));
1330 if ((i
& 0x1ff) == 0x1f0)
1335 ///////////////////////////////////////////////////////////////////////
1336 // Device statistics (Log 0x04)
1338 // See Section A.5 of
1339 // ATA/ATAPI Command Set - 3 (ACS-3)
1340 // T13/2161-D Revision 2, February 21, 2012.
1342 struct devstat_entry_info
1344 short size
; // #bytes of value, -1 for signed char
1348 const devstat_entry_info devstat_info_0x00
[] = {
1349 { 2, "List of supported log pages" },
1353 const devstat_entry_info devstat_info_0x01
[] = {
1354 { 2, "General Statistics" },
1355 { 4, "Lifetime Power-On Resets" },
1356 { 4, "Power-on Hours" }, // spec says no flags(?)
1357 { 6, "Logical Sectors Written" },
1358 { 6, "Number of Write Commands" },
1359 { 6, "Logical Sectors Read" },
1360 { 6, "Number of Read Commands" },
1361 { 6, "Date and Time TimeStamp" }, // ACS-3
1365 const devstat_entry_info devstat_info_0x02
[] = {
1366 { 2, "Free-Fall Statistics" },
1367 { 4, "Number of Free-Fall Events Detected" },
1368 { 4, "Overlimit Shock Events" },
1372 const devstat_entry_info devstat_info_0x03
[] = {
1373 { 2, "Rotating Media Statistics" },
1374 { 4, "Spindle Motor Power-on Hours" },
1375 { 4, "Head Flying Hours" },
1376 { 4, "Head Load Events" },
1377 { 4, "Number of Reallocated Logical Sectors" },
1378 { 4, "Read Recovery Attempts" },
1379 { 4, "Number of Mechanical Start Failures" },
1380 { 4, "Number of Realloc. Candidate Logical Sectors" }, // ACS-3
1384 const devstat_entry_info devstat_info_0x04
[] = {
1385 { 2, "General Errors Statistics" },
1386 { 4, "Number of Reported Uncorrectable Errors" },
1387 //{ 4, "Number of Resets Between Command Acceptance and Command Completion" },
1388 { 4, "Resets Between Cmd Acceptance and Completion" },
1392 const devstat_entry_info devstat_info_0x05
[] = {
1393 { 2, "Temperature Statistics" },
1394 { -1, "Current Temperature" },
1395 { -1, "Average Short Term Temperature" },
1396 { -1, "Average Long Term Temperature" },
1397 { -1, "Highest Temperature" },
1398 { -1, "Lowest Temperature" },
1399 { -1, "Highest Average Short Term Temperature" },
1400 { -1, "Lowest Average Short Term Temperature" },
1401 { -1, "Highest Average Long Term Temperature" },
1402 { -1, "Lowest Average Long Term Temperature" },
1403 { 4, "Time in Over-Temperature" },
1404 { -1, "Specified Maximum Operating Temperature" },
1405 { 4, "Time in Under-Temperature" },
1406 { -1, "Specified Minimum Operating Temperature" },
1410 const devstat_entry_info devstat_info_0x06
[] = {
1411 { 2, "Transport Statistics" },
1412 { 4, "Number of Hardware Resets" },
1413 { 4, "Number of ASR Events" },
1414 { 4, "Number of Interface CRC Errors" },
1418 const devstat_entry_info devstat_info_0x07
[] = {
1419 { 2, "Solid State Device Statistics" },
1420 { 1, "Percentage Used Endurance Indicator" },
1424 const devstat_entry_info
* devstat_infos
[] = {
1435 const int num_devstat_infos
= sizeof(devstat_infos
)/sizeof(devstat_infos
[0]);
1437 static void print_device_statistics_page(const unsigned char * data
, int page
,
1438 bool & need_trailer
)
1440 const devstat_entry_info
* info
= (page
< num_devstat_infos
? devstat_infos
[page
] : 0);
1441 const char * name
= (info
? info
[0].name
: "Unknown Statistics");
1443 // Check page number in header
1444 static const char line
[] = " ===== = = == ";
1446 pout("%3d%s%s (empty) ==\n", page
, line
, name
);
1449 if (data
[2] != page
) {
1450 pout("%3d%s%s (invalid page %d in header) ==\n", page
, line
, name
, data
[2]);
1454 pout("%3d%s%s (rev %d) ==\n", page
, line
, name
, data
[0]);
1457 for (int i
= 1, offset
= 8; offset
< 512-7; i
++, offset
+=8) {
1458 // Check for last known entry
1459 if (info
&& !info
[i
].size
)
1462 // Skip unsupported entries
1463 unsigned char flags
= data
[offset
+7];
1464 if (!(flags
& 0x80))
1467 // Stop if unknown entries contain garbage data due to buggy firmware
1468 if (!info
&& (data
[offset
+5] || data
[offset
+6])) {
1469 pout("%3d 0x%03x - - [Trailing garbage ignored]\n", page
, offset
);
1473 // Get value size, default to max if unknown
1474 int size
= (info
? info
[i
].size
: 7);
1478 if (flags
& 0x40) { // valid flag
1482 val
= (signed char)data
[offset
];
1486 for (int j
= 0; j
< size
; j
++)
1487 val
|= (int64_t)data
[offset
+j
] << (j
*8);
1489 snprintf(valstr
, sizeof(valstr
), "%" PRId64
, val
);
1492 // Value not known (yet)
1493 valstr
[0] = '-'; valstr
[1] = 0;
1496 pout("%3d 0x%03x %d%c %15s%c %s\n",
1499 (flags
& 0x1f ? '+' : ' '), // unknown flags
1501 (flags
& 0x20 ? '~' : ' '), // normalized flag
1502 (info
? info
[i
].name
: "Unknown"));
1504 need_trailer
= true;
1508 static bool print_device_statistics(ata_device
* device
, unsigned nsectors
,
1509 const std::vector
<int> & single_pages
, bool all_pages
, bool ssd_page
,
1512 // Read list of supported pages from page 0
1513 unsigned char page_0
[512] = {0, };
1517 rc
= ataReadLogExt(device
, 0x04, 0, 0, page_0
, 1);
1519 rc
= ataReadSmartLog(device
, 0x04, page_0
, 1);
1521 pout("Read Device Statistics page 0 failed\n\n");
1525 unsigned char nentries
= page_0
[8];
1526 if (!(page_0
[2] == 0 && nentries
> 0)) {
1527 pout("Device Statistics page 0 is invalid (page=%d, nentries=%d)\n\n", page_0
[2], nentries
);
1531 // Prepare list of pages to print
1532 std::vector
<int> pages
;
1535 // Add all supported pages
1536 for (i
= 0; i
< nentries
; i
++) {
1537 int page
= page_0
[8+1+i
];
1539 pages
.push_back(page
);
1543 // Add manually specified pages
1544 bool print_page_0
= false;
1545 for (i
= 0; i
< single_pages
.size() || ssd_page
; i
++) {
1546 int page
= (i
< single_pages
.size() ? single_pages
[i
] : 7);
1548 print_page_0
= true;
1549 else if (page
>= (int)nsectors
)
1550 pout("Device Statistics Log has only %u pages\n", nsectors
);
1552 pages
.push_back(page
);
1557 // Print list of supported pages if requested
1559 pout("Device Statistics (%s Log 0x04) supported pages\n",
1560 use_gplog
? "GP" : "SMART");
1561 pout("Page Description\n");
1562 for (i
= 0; i
< nentries
; i
++) {
1563 int page
= page_0
[8+1+i
];
1564 pout("%3d %s\n", page
,
1565 (page
< num_devstat_infos
? devstat_infos
[page
][0].name
: "Unknown Statistics"));
1570 // Read & print pages
1571 if (!pages
.empty()) {
1572 pout("Device Statistics (%s Log 0x04)\n",
1573 use_gplog
? "GP" : "SMART");
1574 pout("Page Offset Size Value Description\n");
1575 bool need_trailer
= false;
1579 for (i
= 0; i
< pages
.size(); i
++) {
1580 int page
= pages
[i
];
1581 if (max_page
< page
&& page
< 0xff)
1585 raw_buffer
pages_buf((max_page
+1) * 512);
1587 if (!use_gplog
&& !ataReadSmartLog(device
, 0x04, pages_buf
.data(), max_page
+1)) {
1588 pout("Read Device Statistics pages 0-%d failed\n\n", max_page
);
1592 for (i
= 0; i
< pages
.size(); i
++) {
1593 int page
= pages
[i
];
1595 if (!ataReadLogExt(device
, 0x04, 0, page
, pages_buf
.data(), 1)) {
1596 pout("Read Device Statistics page %d failed\n\n", page
);
1600 else if (page
> max_page
)
1603 int offset
= (use_gplog
? 0 : page
* 512);
1604 print_device_statistics_page(pages_buf
.data() + offset
, page
, need_trailer
);
1608 pout("%30s|_ ~ normalized value\n", "");
1616 ///////////////////////////////////////////////////////////////////////
1619 static void PrintSataPhyEventCounters(const unsigned char * data
, bool reset
)
1622 checksumwarning("SATA Phy Event Counters");
1623 pout("SATA Phy Event Counters (GP Log 0x11)\n");
1624 if (data
[0] || data
[1] || data
[2] || data
[3])
1625 pout("[Reserved: 0x%02x 0x%02x 0x%02x 0x%02x]\n",
1626 data
[0], data
[1], data
[2], data
[3]);
1627 pout("ID Size Value Description\n");
1629 for (unsigned i
= 4; ; ) {
1630 // Get counter id and size (bits 14:12)
1631 unsigned id
= data
[i
] | (data
[i
+1] << 8);
1632 unsigned size
= ((id
>> 12) & 0x7) << 1;
1635 // End of counter table ?
1640 if (!(2 <= size
&& size
<= 8 && i
+ size
< 512)) {
1641 pout("0x%04x %u: Invalid entry\n", id
, size
);
1646 uint64_t val
= 0, max_val
= 0;
1647 for (unsigned j
= 0; j
< size
; j
+=2) {
1648 val
|= (uint64_t)(data
[i
+j
] | (data
[i
+j
+1] << 8)) << (j
*8);
1649 max_val
|= (uint64_t)0xffffU
<< (j
*8);
1656 case 0x001: name
= "Command failed due to ICRC error"; break; // Mandatory
1657 case 0x002: name
= "R_ERR response for data FIS"; break;
1658 case 0x003: name
= "R_ERR response for device-to-host data FIS"; break;
1659 case 0x004: name
= "R_ERR response for host-to-device data FIS"; break;
1660 case 0x005: name
= "R_ERR response for non-data FIS"; break;
1661 case 0x006: name
= "R_ERR response for device-to-host non-data FIS"; break;
1662 case 0x007: name
= "R_ERR response for host-to-device non-data FIS"; break;
1663 case 0x008: name
= "Device-to-host non-data FIS retries"; break;
1664 case 0x009: name
= "Transition from drive PhyRdy to drive PhyNRdy"; break;
1665 case 0x00A: name
= "Device-to-host register FISes sent due to a COMRESET"; break; // Mandatory
1666 case 0x00B: name
= "CRC errors within host-to-device FIS"; break;
1667 case 0x00D: name
= "Non-CRC errors within host-to-device FIS"; break;
1668 case 0x00F: name
= "R_ERR response for host-to-device data FIS, CRC"; break;
1669 case 0x010: name
= "R_ERR response for host-to-device data FIS, non-CRC"; break;
1670 case 0x012: name
= "R_ERR response for host-to-device non-data FIS, CRC"; break;
1671 case 0x013: name
= "R_ERR response for host-to-device non-data FIS, non-CRC"; break;
1672 default: name
= (id
& 0x8000 ? "Vendor specific" : "Unknown"); break;
1675 // Counters stop at max value, add '+' in this case
1676 pout("0x%04x %u %12" PRIu64
"%c %s\n", id
, size
, val
,
1677 (val
== max_val
? '+' : ' '), name
);
1680 pout("All counters reset\n");
1684 // Format milliseconds from error log entry as "DAYS+H:M:S.MSEC"
1685 static std::string
format_milliseconds(unsigned msec
)
1687 unsigned days
= msec
/ 86400000U;
1688 msec
-= days
* 86400000U;
1689 unsigned hours
= msec
/ 3600000U;
1690 msec
-= hours
* 3600000U;
1691 unsigned min
= msec
/ 60000U;
1692 msec
-= min
* 60000U;
1693 unsigned sec
= msec
/ 1000U;
1694 msec
-= sec
* 1000U;
1698 str
= strprintf("%2ud+", days
);
1699 str
+= strprintf("%02u:%02u:%02u.%03u", hours
, min
, sec
, msec
);
1703 // Get description for 'state' value from SMART Error Logs
1704 static const char * get_error_log_state_desc(unsigned state
)
1708 case 0x0: return "in an unknown state";
1709 case 0x1: return "sleeping";
1710 case 0x2: return "in standby mode";
1711 case 0x3: return "active or idle";
1712 case 0x4: return "doing SMART Offline or Self-test";
1714 return (state
< 0xb ? "in a reserved state"
1715 : "in a vendor specific state");
1719 // returns number of errors
1720 static int PrintSmartErrorlog(const ata_smart_errorlog
*data
,
1721 firmwarebug_defs firmwarebugs
)
1723 pout("SMART Error Log Version: %d\n", (int)data
->revnumber
);
1725 // if no errors logged, return
1726 if (!data
->error_log_pointer
){
1727 pout("No Errors Logged\n\n");
1731 // If log pointer out of range, return
1732 if (data
->error_log_pointer
>5){
1733 pout("Invalid Error Log index = 0x%02x (T13/1321D rev 1c "
1734 "Section 8.41.6.8.2.2 gives valid range from 1 to 5)\n\n",
1735 (int)data
->error_log_pointer
);
1739 // Some internal consistency checking of the data structures
1740 if ((data
->ata_error_count
-data
->error_log_pointer
) % 5 && !firmwarebugs
.is_set(BUG_SAMSUNG2
)) {
1741 pout("Warning: ATA error count %d inconsistent with error log pointer %d\n\n",
1742 data
->ata_error_count
,data
->error_log_pointer
);
1745 // starting printing error log info
1746 if (data
->ata_error_count
<=5)
1747 pout( "ATA Error Count: %d\n", (int)data
->ata_error_count
);
1749 pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1750 (int)data
->ata_error_count
);
1752 pout("\tCR = Command Register [HEX]\n"
1753 "\tFR = Features Register [HEX]\n"
1754 "\tSC = Sector Count Register [HEX]\n"
1755 "\tSN = Sector Number Register [HEX]\n"
1756 "\tCL = Cylinder Low Register [HEX]\n"
1757 "\tCH = Cylinder High Register [HEX]\n"
1758 "\tDH = Device/Head Register [HEX]\n"
1759 "\tDC = Device Command Register [HEX]\n"
1760 "\tER = Error register [HEX]\n"
1761 "\tST = Status register [HEX]\n"
1762 "Powered_Up_Time is measured from power on, and printed as\n"
1763 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1764 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1766 // now step through the five error log data structures (table 39 of spec)
1767 for (int k
= 4; k
>= 0; k
-- ) {
1769 // The error log data structure entries are a circular buffer
1770 int j
, i
=(data
->error_log_pointer
+k
)%5;
1771 const ata_smart_errorlog_struct
* elog
= data
->errorlog_struct
+i
;
1772 const ata_smart_errorlog_error_struct
* summary
= &(elog
->error_struct
);
1774 // Spec says: unused error log structures shall be zero filled
1775 if (nonempty(elog
, sizeof(*elog
))){
1776 // Table 57 of T13/1532D Volume 1 Revision 3
1777 const char *msgstate
= get_error_log_state_desc(summary
->state
);
1778 int days
= (int)summary
->timestamp
/24;
1780 // See table 42 of ATA5 spec
1782 pout("Error %d occurred at disk power-on lifetime: %d hours (%d days + %d hours)\n",
1783 (int)(data
->ata_error_count
+k
-4), (int)summary
->timestamp
, days
, (int)(summary
->timestamp
-24*days
));
1785 pout(" When the command that caused the error occurred, the device was %s.\n\n",msgstate
);
1786 pout(" After command completion occurred, registers were:\n"
1787 " ER ST SC SN CL CH DH\n"
1788 " -- -- -- -- -- -- --\n"
1789 " %02x %02x %02x %02x %02x %02x %02x",
1790 (int)summary
->error_register
,
1791 (int)summary
->status
,
1792 (int)summary
->sector_count
,
1793 (int)summary
->sector_number
,
1794 (int)summary
->cylinder_low
,
1795 (int)summary
->cylinder_high
,
1796 (int)summary
->drive_head
);
1797 // Add a description of the contents of the status and error registers
1799 std::string st_er_desc
= format_st_er_desc(elog
);
1800 if (!st_er_desc
.empty())
1801 pout(" %s", st_er_desc
.c_str());
1803 pout(" Commands leading to the command that caused the error were:\n"
1804 " CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name\n"
1805 " -- -- -- -- -- -- -- -- ---------------- --------------------\n");
1806 for ( j
= 4; j
>= 0; j
--){
1807 const ata_smart_errorlog_command_struct
* thiscommand
= elog
->commands
+j
;
1809 // Spec says: unused data command structures shall be zero filled
1810 if (nonempty(thiscommand
, sizeof(*thiscommand
))) {
1811 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1812 (int)thiscommand
->commandreg
,
1813 (int)thiscommand
->featuresreg
,
1814 (int)thiscommand
->sector_count
,
1815 (int)thiscommand
->sector_number
,
1816 (int)thiscommand
->cylinder_low
,
1817 (int)thiscommand
->cylinder_high
,
1818 (int)thiscommand
->drive_head
,
1819 (int)thiscommand
->devicecontrolreg
,
1820 format_milliseconds(thiscommand
->timestamp
).c_str(),
1821 look_up_ata_command(thiscommand
->commandreg
, thiscommand
->featuresreg
));
1828 if (printing_is_switchable
)
1831 return data
->ata_error_count
;
1834 // Print SMART Extended Comprehensive Error Log (GP Log 0x03)
1835 static int PrintSmartExtErrorLog(const ata_smart_exterrlog
* log
,
1836 unsigned nsectors
, unsigned max_errors
)
1838 pout("SMART Extended Comprehensive Error Log Version: %u (%u sectors)\n",
1839 log
->version
, nsectors
);
1841 if (!log
->device_error_count
) {
1842 pout("No Errors Logged\n\n");
1848 unsigned nentries
= nsectors
* 4;
1849 unsigned erridx
= log
->error_log_index
;
1850 if (!(1 <= erridx
&& erridx
<= nentries
)){
1851 // Some Samsung disks (at least SP1614C/SW100-25, HD300LJ/ZT100-12) use the
1852 // former index from Summary Error Log (byte 1, now reserved) and set byte 2-3
1854 if (!(erridx
== 0 && 1 <= log
->reserved1
&& log
->reserved1
<= nentries
)) {
1855 pout("Invalid Error Log index = 0x%04x (reserved = 0x%02x)\n", erridx
, log
->reserved1
);
1858 pout("Invalid Error Log index = 0x%04x, trying reserved byte (0x%02x) instead\n", erridx
, log
->reserved1
);
1859 erridx
= log
->reserved1
;
1862 // Index base is not clearly specified by ATA8-ACS (T13/1699-D Revision 6a),
1863 // it is 1-based in practice.
1866 // Calculate #errors to print
1867 unsigned errcnt
= log
->device_error_count
;
1869 if (errcnt
<= nentries
)
1870 pout("Device Error Count: %u\n", log
->device_error_count
);
1873 pout("Device Error Count: %u (device log contains only the most recent %u errors)\n",
1874 log
->device_error_count
, errcnt
);
1877 if (max_errors
< errcnt
)
1878 errcnt
= max_errors
;
1881 pout("\tCR = Command Register\n"
1882 "\tFEATR = Features Register\n"
1883 "\tCOUNT = Count (was: Sector Count) Register\n"
1884 "\tLBA_48 = Upper bytes of LBA High/Mid/Low Registers ] ATA-8\n"
1885 "\tLH = LBA High (was: Cylinder High) Register ] LBA\n"
1886 "\tLM = LBA Mid (was: Cylinder Low) Register ] Register\n"
1887 "\tLL = LBA Low (was: Sector Number) Register ]\n"
1888 "\tDV = Device (was: Device/Head) Register\n"
1889 "\tDC = Device Control Register\n"
1890 "\tER = Error register\n"
1891 "\tST = Status register\n"
1892 "Powered_Up_Time is measured from power on, and printed as\n"
1893 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1894 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1896 // Iterate through circular buffer in reverse direction
1897 for (unsigned i
= 0, errnum
= log
->device_error_count
;
1898 i
< errcnt
; i
++, errnum
--, erridx
= (erridx
> 0 ? erridx
- 1 : nentries
- 1)) {
1900 const ata_smart_exterrlog_error_log
& entry
= log
[erridx
/ 4].error_logs
[erridx
% 4];
1902 // Skip unused entries
1903 if (!nonempty(&entry
, sizeof(entry
))) {
1904 pout("Error %u [%u] log entry is empty\n", errnum
, erridx
);
1908 // Print error information
1910 const ata_smart_exterrlog_error
& err
= entry
.error
;
1911 pout("Error %u [%u] occurred at disk power-on lifetime: %u hours (%u days + %u hours)\n",
1912 errnum
, erridx
, err
.timestamp
, err
.timestamp
/ 24, err
.timestamp
% 24);
1915 pout(" When the command that caused the error occurred, the device was %s.\n\n",
1916 get_error_log_state_desc(err
.state
));
1919 pout(" After command completion occurred, registers were:\n"
1920 " ER -- ST COUNT LBA_48 LH LM LL DV DC\n"
1921 " -- -- -- == -- == == == -- -- -- -- --\n"
1922 " %02x -- %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
1924 err
.status_register
,
1925 err
.count_register_hi
,
1927 err
.lba_high_register_hi
,
1928 err
.lba_mid_register_hi
,
1929 err
.lba_low_register_hi
,
1930 err
.lba_high_register
,
1931 err
.lba_mid_register
,
1932 err
.lba_low_register
,
1933 err
.device_register
,
1934 err
.device_control_register
);
1936 // Add a description of the contents of the status and error registers
1938 std::string st_er_desc
= format_st_er_desc(&entry
);
1939 if (!st_er_desc
.empty())
1940 pout(" %s", st_er_desc
.c_str());
1943 // Print command history
1944 pout(" Commands leading to the command that caused the error were:\n"
1945 " CR FEATR COUNT LBA_48 LH LM LL DV DC Powered_Up_Time Command/Feature_Name\n"
1946 " -- == -- == -- == == == -- -- -- -- -- --------------- --------------------\n");
1947 for (int ci
= 4; ci
>= 0; ci
--) {
1948 const ata_smart_exterrlog_command
& cmd
= entry
.commands
[ci
];
1950 // Skip unused entries
1951 if (!nonempty(&cmd
, sizeof(cmd
)))
1954 // Print registers, timestamp and ATA command name
1955 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1956 cmd
.command_register
,
1957 cmd
.features_register_hi
,
1958 cmd
.features_register
,
1959 cmd
.count_register_hi
,
1961 cmd
.lba_high_register_hi
,
1962 cmd
.lba_mid_register_hi
,
1963 cmd
.lba_low_register_hi
,
1964 cmd
.lba_high_register
,
1965 cmd
.lba_mid_register
,
1966 cmd
.lba_low_register
,
1967 cmd
.device_register
,
1968 cmd
.device_control_register
,
1969 format_milliseconds(cmd
.timestamp
).c_str(),
1970 look_up_ata_command(cmd
.command_register
, cmd
.features_register
));
1976 if (printing_is_switchable
)
1979 return log
->device_error_count
;
1982 // Print SMART Extended Self-test Log (GP Log 0x07)
1983 static int PrintSmartExtSelfTestLog(const ata_smart_extselftestlog
* log
,
1984 unsigned nsectors
, unsigned max_entries
)
1986 pout("SMART Extended Self-test Log Version: %u (%u sectors)\n",
1987 log
->version
, nsectors
);
1989 if (!log
->log_desc_index
){
1990 pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
1995 unsigned nentries
= nsectors
* 19;
1996 unsigned logidx
= log
->log_desc_index
;
1997 if (logidx
> nentries
) {
1998 pout("Invalid Self-test Log index = 0x%04x (reserved = 0x%02x)\n", logidx
, log
->reserved1
);
2002 // Index base is not clearly specified by ATA8-ACS (T13/1699-D Revision 6a),
2003 // it is 1-based in practice.
2006 bool print_header
= true;
2007 int errcnt
= 0, igncnt
= 0;
2008 int ext_ok_testnum
= -1;
2010 // Iterate through circular buffer in reverse direction
2011 for (unsigned i
= 0, testnum
= 1;
2012 i
< nentries
&& testnum
<= max_entries
;
2013 i
++, logidx
= (logidx
> 0 ? logidx
- 1 : nentries
- 1)) {
2015 const ata_smart_extselftestlog_desc
& entry
= log
[logidx
/ 19].log_descs
[logidx
% 19];
2017 // Skip unused entries
2018 if (!nonempty(&entry
, sizeof(entry
)))
2022 const unsigned char * b
= entry
.failing_lba
;
2023 uint64_t lba48
= b
[0]
2026 | ((uint64_t)b
[3] << 24)
2027 | ((uint64_t)b
[4] << 32)
2028 | ((uint64_t)b
[5] << 40);
2031 int state
= ataPrintSmartSelfTestEntry(testnum
, entry
.self_test_type
,
2032 entry
.self_test_status
, entry
.timestamp
, lba48
,
2033 false /*!print_error_only*/, print_header
);
2036 // Self-test showed an error
2037 if (ext_ok_testnum
< 0)
2040 // Newer successful extended self-test exits
2043 else if (state
> 0 && ext_ok_testnum
< 0) {
2044 // Latest successful extended self-test
2045 ext_ok_testnum
= testnum
;
2051 pout("%d of %d failed self-tests are outdated by newer successful extended offline self-test #%2d\n",
2052 igncnt
, igncnt
+errcnt
, ext_ok_testnum
);
2058 static void ataPrintSelectiveSelfTestLog(const ata_selective_self_test_log
* log
, const ata_smart_values
* sv
)
2060 int i
,field1
,field2
;
2063 uint64_t maxl
=0,maxr
=0;
2064 uint64_t current
=log
->currentlba
;
2065 uint64_t currentend
=current
+65535;
2067 // print data structure revision number
2068 pout("SMART Selective self-test log data structure revision number %d\n",(int)log
->logversion
);
2069 if (1 != log
->logversion
)
2070 pout("Note: revision number not 1 implies that no selective self-test has ever been run\n");
2072 switch((sv
->self_test_exec_status
)>>4){
2073 case 0:msg
="Completed";
2075 case 1:msg
="Aborted_by_host";
2077 case 2:msg
="Interrupted";
2079 case 3:msg
="Fatal_error";
2081 case 4:msg
="Completed_unknown_failure";
2083 case 5:msg
="Completed_electrical_failure";
2085 case 6:msg
="Completed_servo/seek_failure";
2087 case 7:msg
="Completed_read_failure";
2089 case 8:msg
="Completed_handling_damage??";
2091 case 15:msg
="Self_test_in_progress";
2093 default:msg
="Unknown_status ";
2097 // find the number of columns needed for printing. If in use, the
2098 // start/end of span being read-scanned...
2099 if (log
->currentspan
>5) {
2103 for (i
=0; i
<5; i
++) {
2104 uint64_t start
=log
->span
[i
].start
;
2105 uint64_t end
=log
->span
[i
].end
;
2106 // ... plus max start/end of each of the five test spans.
2113 // we need at least 7 characters wide fields to accomodate the
2115 if ((field1
=snprintf(tmp
,64, "%" PRIu64
, maxl
))<7)
2117 if ((field2
=snprintf(tmp
,64, "%" PRIu64
, maxr
))<7)
2120 // now print the five test spans
2121 pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1
, "MIN_LBA", field2
, "MAX_LBA");
2123 for (i
=0; i
<5; i
++) {
2124 uint64_t start
=log
->span
[i
].start
;
2125 uint64_t end
=log
->span
[i
].end
;
2127 if ((i
+1)==(int)log
->currentspan
)
2128 // this span is currently under test
2129 pout(" %d %*" PRIu64
" %*" PRIu64
" %s [%01d0%% left] (%" PRIu64
"-%" PRIu64
")\n",
2130 i
+1, field1
, start
, field2
, end
, msg
,
2131 (int)(sv
->self_test_exec_status
& 0xf), current
, currentend
);
2133 // this span is not currently under test
2134 pout(" %d %*" PRIu64
" %*" PRIu64
" Not_testing\n",
2135 i
+1, field1
, start
, field2
, end
);
2138 // if we are currently read-scanning, print LBAs and the status of
2140 if (log
->currentspan
>5)
2141 pout("%5d %*" PRIu64
" %*" PRIu64
" Read_scanning %s\n",
2142 (int)log
->currentspan
, field1
, current
, field2
, currentend
,
2143 OfflineDataCollectionStatus(sv
->offline_data_collection_status
));
2145 /* Print selective self-test flags. Possible flag combinations are
2146 (numbering bits from 0-15):
2150 1 0 0 Will carry out scan after selective test
2151 1 1 0 Waiting to carry out scan after powerup
2152 1 0 1 Currently scanning
2153 1 1 1 Currently scanning
2156 pout("Selective self-test flags (0x%x):\n", (unsigned int)log
->flags
);
2157 if (log
->flags
& SELECTIVE_FLAG_DOSCAN
) {
2158 if (log
->flags
& SELECTIVE_FLAG_ACTIVE
)
2159 pout(" Currently read-scanning the remainder of the disk.\n");
2160 else if (log
->flags
& SELECTIVE_FLAG_PENDING
)
2161 pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
2162 (int)log
->pendingtime
);
2164 pout(" After scanning selected spans, read-scan remainder of disk.\n");
2167 pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
2169 // print pending time
2170 pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
2171 (int)log
->pendingtime
);
2176 // Format SCT Temperature value
2177 static const char * sct_ptemp(signed char x
, char (& buf
)[20])
2179 if (x
== -128 /*0x80 = unknown*/)
2181 snprintf(buf
, sizeof(buf
), "%2d", x
);
2185 static const char * sct_pbar(int x
, char (& buf
)[64])
2196 memset(buf
, '*', x
);
2202 buf
[0] = '-'; buf
[1] = 0;
2207 static const char * sct_device_state_msg(unsigned char state
)
2210 case 0: return "Active";
2211 case 1: return "Stand-by";
2212 case 2: return "Sleep";
2213 case 3: return "DST executing in background";
2214 case 4: return "SMART Off-line Data Collection executing in background";
2215 case 5: return "SCT command executing in background";
2216 default:return "Unknown";
2221 static int ataPrintSCTStatus(const ata_sct_status_response
* sts
)
2223 pout("SCT Status Version: %u\n", sts
->format_version
);
2224 pout("SCT Version (vendor specific): %u (0x%04x)\n", sts
->sct_version
, sts
->sct_version
);
2225 pout("SCT Support Level: %u\n", sts
->sct_spec
);
2226 pout("Device State: %s (%u)\n",
2227 sct_device_state_msg(sts
->device_state
), sts
->device_state
);
2228 char buf1
[20], buf2
[20];
2229 if ( !sts
->min_temp
&& !sts
->life_min_temp
2230 && !sts
->under_limit_count
&& !sts
->over_limit_count
) {
2231 // "Reserved" fields not set, assume "old" format version 2
2232 // Table 11 of T13/1701DT-N (SMART Command Transport) Revision 5, February 2005
2233 // Table 54 of T13/1699-D (ATA8-ACS) Revision 3e, July 2006
2234 pout("Current Temperature: %s Celsius\n",
2235 sct_ptemp(sts
->hda_temp
, buf1
));
2236 pout("Power Cycle Max Temperature: %s Celsius\n",
2237 sct_ptemp(sts
->max_temp
, buf2
));
2238 pout("Lifetime Max Temperature: %s Celsius\n",
2239 sct_ptemp(sts
->life_max_temp
, buf2
));
2242 // Assume "new" format version 2 or version 3
2243 // T13/e06152r0-3 (Additional SCT Temperature Statistics), August - October 2006
2244 // Table 60 of T13/1699-D (ATA8-ACS) Revision 3f, December 2006 (format version 2)
2245 // Table 80 of T13/1699-D (ATA8-ACS) Revision 6a, September 2008 (format version 3)
2246 // Table 182 of T13/BSR INCITS 529 (ACS-4) Revision 02a, May 22, 2014 (smart_status field)
2247 pout("Current Temperature: %s Celsius\n",
2248 sct_ptemp(sts
->hda_temp
, buf1
));
2249 pout("Power Cycle Min/Max Temperature: %s/%s Celsius\n",
2250 sct_ptemp(sts
->min_temp
, buf1
), sct_ptemp(sts
->max_temp
, buf2
));
2251 pout("Lifetime Min/Max Temperature: %s/%s Celsius\n",
2252 sct_ptemp(sts
->life_min_temp
, buf1
), sct_ptemp(sts
->life_max_temp
, buf2
));
2253 signed char avg
= sts
->byte205
; // Average Temperature from e06152r0-2, removed in e06152r3
2254 if (0 < avg
&& sts
->life_min_temp
<= avg
&& avg
<= sts
->life_max_temp
)
2255 pout("Lifetime Average Temperature: %2d Celsius\n", avg
);
2256 pout("Under/Over Temperature Limit Count: %2u/%u\n",
2257 sts
->under_limit_count
, sts
->over_limit_count
);
2259 if (sts
->smart_status
) // ACS-4
2260 pout("SMART Status: 0x%04x (%s)\n", sts
->smart_status
,
2261 (sts
->smart_status
== 0x2cf4 ? "FAILED" :
2262 sts
->smart_status
== 0xc24f ? "PASSED" : "Reserved"));
2264 if (nonempty(sts
->vendor_specific
, sizeof(sts
->vendor_specific
))) {
2265 pout("Vendor specific:\n");
2266 for (unsigned i
= 0; i
< sizeof(sts
->vendor_specific
); i
++)
2267 pout("%02x%c", sts
->vendor_specific
[i
], ((i
& 0xf) != 0xf ? ' ' : '\n'));
2273 // Print SCT Temperature History Table
2274 static int ataPrintSCTTempHist(const ata_sct_temperature_history_table
* tmh
)
2276 char buf1
[20], buf2
[20], buf3
[64];
2277 pout("SCT Temperature History Version: %u%s\n", tmh
->format_version
,
2278 (tmh
->format_version
!= 2 ? " (Unknown, should be 2)" : ""));
2279 pout("Temperature Sampling Period: %u minute%s\n",
2280 tmh
->sampling_period
, (tmh
->sampling_period
==1?"":"s"));
2281 pout("Temperature Logging Interval: %u minute%s\n",
2282 tmh
->interval
, (tmh
->interval
==1?"":"s"));
2283 pout("Min/Max recommended Temperature: %s/%s Celsius\n",
2284 sct_ptemp(tmh
->min_op_limit
, buf1
), sct_ptemp(tmh
->max_op_limit
, buf2
));
2285 pout("Min/Max Temperature Limit: %s/%s Celsius\n",
2286 sct_ptemp(tmh
->under_limit
, buf1
), sct_ptemp(tmh
->over_limit
, buf2
));
2287 pout("Temperature History Size (Index): %u (%u)\n", tmh
->cb_size
, tmh
->cb_index
);
2289 if (!(0 < tmh
->cb_size
&& tmh
->cb_size
<= sizeof(tmh
->cb
) && tmh
->cb_index
< tmh
->cb_size
)) {
2291 pout("Temperature History is empty\n");
2293 pout("Invalid Temperature History Size or Index\n");
2298 pout("\nIndex Estimated Time Temperature Celsius\n");
2299 unsigned n
= 0, i
= (tmh
->cb_index
+1) % tmh
->cb_size
;
2300 unsigned interval
= (tmh
->interval
> 0 ? tmh
->interval
: 1);
2301 time_t t
= time(0) - (tmh
->cb_size
-1) * interval
* 60;
2302 t
-= t
% (interval
* 60);
2303 while (n
< tmh
->cb_size
) {
2304 // Find range of identical temperatures
2305 unsigned n1
= n
, n2
= n
+1, i2
= (i
+1) % tmh
->cb_size
;
2306 while (n2
< tmh
->cb_size
&& tmh
->cb
[i2
] == tmh
->cb
[i
]) {
2307 n2
++; i2
= (i2
+1) % tmh
->cb_size
;
2311 if (n
== n1
|| n
== n2
-1 || n2
<= n1
+3) {
2313 // TODO: Don't print times < boot time
2314 strftime(date
, sizeof(date
), "%Y-%m-%d %H:%M", localtime(&t
));
2315 pout(" %3u %s %s %s\n", i
, date
,
2316 sct_ptemp(tmh
->cb
[i
], buf1
), sct_pbar(tmh
->cb
[i
], buf3
));
2318 else if (n
== n1
+1) {
2319 pout(" ... ..(%3u skipped). .. %s\n",
2320 n2
-n1
-2, sct_pbar(tmh
->cb
[i
], buf3
));
2322 t
+= interval
* 60; i
= (i
+1) % tmh
->cb_size
; n
++;
2325 //assert(n == tmh->cb_size && i == (tmh->cb_index+1) % tmh->cb_size);
2330 // Print SCT Error Recovery Control timers
2331 static void ataPrintSCTErrorRecoveryControl(bool set
, unsigned short read_timer
, unsigned short write_timer
)
2333 pout("SCT Error Recovery Control%s:\n", (set
? " set to" : ""));
2335 pout(" Read: Disabled\n");
2337 pout(" Read: %6d (%0.1f seconds)\n", read_timer
, read_timer
/10.0);
2339 pout(" Write: Disabled\n");
2341 pout(" Write: %6d (%0.1f seconds)\n", write_timer
, write_timer
/10.0);
2344 static void print_aam_level(const char * msg
, int level
, int recommended
= -1)
2346 // Table 56 of T13/1699-D (ATA8-ACS) Revision 6a, September 6, 2008
2347 // Obsolete since T13/2015-D (ACS-2) Revision 4a, December 9, 2010
2350 s
= "vendor specific";
2351 else if (level
< 128)
2352 s
= "unknown/retired";
2353 else if (level
== 128)
2355 else if (level
< 254)
2357 else if (level
== 254)
2358 s
= "maximum performance";
2362 if (recommended
>= 0)
2363 pout("%s%d (%s), recommended: %d\n", msg
, level
, s
, recommended
);
2365 pout("%s%d (%s)\n", msg
, level
, s
);
2368 static void print_apm_level(const char * msg
, int level
)
2370 // Table 120 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2372 if (!(1 <= level
&& level
<= 254))
2374 else if (level
== 1)
2375 s
= "minimum power consumption with standby";
2376 else if (level
< 128)
2377 s
= "intermediate level with standby";
2378 else if (level
== 128)
2379 s
= "minimum power consumption without standby";
2380 else if (level
< 254)
2381 s
= "intermediate level without standby";
2383 s
= "maximum performance";
2385 pout("%s%d (%s)\n", msg
, level
, s
);
2388 static void print_ata_security_status(const char * msg
, unsigned short state
)
2390 const char * s1
, * s2
= "", * s3
= "", * s4
= "";
2392 // Table 6 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2393 if (!(state
& 0x0001))
2395 else if (!(state
& 0x0002)) {
2397 if (!(state
& 0x0008))
2398 s2
= "NOT FROZEN [SEC1]";
2400 s2
= "frozen [SEC2]";
2403 s1
= "ENABLED, PW level ";
2404 if (!(state
& 0x0020))
2409 if (!(state
& 0x0004)) {
2410 s3
= ", not locked, ";
2411 if (!(state
& 0x0008))
2412 s4
= "not frozen [SEC5]";
2414 s4
= "frozen [SEC6]";
2417 s3
= ", **LOCKED** [SEC4]";
2419 s4
= ", PW ATTEMPTS EXCEEDED";
2423 pout("%s%s%s%s%s\n", msg
, s1
, s2
, s3
, s4
);
2426 static void print_standby_timer(const char * msg
, int timer
, const ata_identify_device
& drive
)
2428 const char * s1
= 0;
2429 int hours
= 0, minutes
= 0 , seconds
= 0;
2431 // Table 63 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2434 else if (timer
<= 240)
2435 seconds
= timer
* 5, minutes
= seconds
/ 60, seconds
%= 60;
2436 else if (timer
<= 251)
2437 minutes
= (timer
- 240) * 30, hours
= minutes
/ 60, minutes
%= 60;
2438 else if (timer
== 252)
2440 else if (timer
== 253)
2441 s1
= "between 8 hours and 12 hours";
2442 else if (timer
== 255)
2443 minutes
= 21, seconds
= 15;
2447 const char * s2
= "", * s3
= "";
2448 if (!(drive
.words047_079
[49-47] & 0x2000))
2449 s2
= " or vendor-specific";
2450 if (timer
> 0 && (drive
.words047_079
[50-47] & 0xc001) == 0x4001)
2451 s3
= ", a vendor-specific minimum applies";
2454 pout("%s%d (%s%s%s)\n", msg
, timer
, s1
, s2
, s3
);
2456 pout("%s%d (%02d:%02d:%02d%s%s)\n", msg
, timer
, hours
, minutes
, seconds
, s2
, s3
);
2460 int ataPrintMain (ata_device
* device
, const ata_print_options
& options
)
2462 // If requested, check power mode first
2463 const char * powername
= 0;
2464 bool powerchg
= false;
2465 if (options
.powermode
) {
2466 unsigned char powerlimit
= 0xff;
2467 int powermode
= ataCheckPowerMode(device
);
2468 switch (powermode
) {
2470 if (device
->is_syscall_unsup()) {
2471 pout("CHECK POWER MODE not implemented, ignoring -n option\n"); break;
2473 powername
= "SLEEP"; powerlimit
= 2;
2476 powername
= "STANDBY"; powerlimit
= 3; break;
2478 powername
= "IDLE"; powerlimit
= 4; break;
2480 powername
= "ACTIVE or IDLE"; break;
2482 pout("CHECK POWER MODE returned unknown value 0x%02x, ignoring -n option\n", powermode
);
2486 if (options
.powermode
>= powerlimit
) {
2487 pout("Device is in %s mode, exit(%d)\n", powername
, FAILPOWER
);
2490 powerchg
= (powermode
!= 0xff); // SMART tests will spin up drives
2494 // SMART values needed ?
2495 bool need_smart_val
= (
2496 options
.smart_check_status
2497 || options
.smart_general_values
2498 || options
.smart_vendor_attrib
2499 || options
.smart_error_log
2500 || options
.smart_selftest_log
2501 || options
.smart_selective_selftest_log
2502 || options
.smart_ext_error_log
2503 || options
.smart_ext_selftest_log
2504 || options
.smart_auto_offl_enable
2505 || options
.smart_auto_offl_disable
2506 || options
.smart_selftest_type
!= -1
2509 // SMART must be enabled ?
2510 bool need_smart_enabled
= (
2512 || options
.smart_auto_save_enable
2513 || options
.smart_auto_save_disable
2516 // SMART feature set needed ?
2517 bool need_smart_support
= (
2519 || options
.smart_enable
2520 || options
.smart_disable
2523 // SMART and GP log directories needed ?
2524 bool need_smart_logdir
= (
2525 options
.smart_logdir
2526 || options
.devstat_all_pages
// devstat fallback to smartlog if needed
2527 || options
.devstat_ssd_page
2528 || !options
.devstat_pages
.empty()
2531 bool need_gp_logdir
= (
2533 || options
.smart_ext_error_log
2534 || options
.smart_ext_selftest_log
2535 || options
.devstat_all_pages
2536 || options
.devstat_ssd_page
2537 || !options
.devstat_pages
.empty()
2541 for (i
= 0; i
< options
.log_requests
.size(); i
++) {
2542 if (options
.log_requests
[i
].gpl
)
2543 need_gp_logdir
= true;
2545 need_smart_logdir
= true;
2548 // SCT commands needed ?
2549 bool need_sct_support
= (
2550 options
.sct_temp_sts
2551 || options
.sct_temp_hist
2552 || options
.sct_temp_int
2553 || options
.sct_erc_get
2554 || options
.sct_erc_set
2555 || options
.sct_wcache_reorder_get
2556 || options
.sct_wcache_reorder_set
2559 // Exit if no further options specified
2560 if (!( options
.drive_info
|| options
.show_presets
2561 || need_smart_support
|| need_smart_logdir
2562 || need_gp_logdir
|| need_sct_support
2564 || options
.identify_word_level
>= 0
2565 || options
.get_set_used
)) {
2567 pout("Device is in %s mode\n", powername
);
2569 pout("ATA device successfully opened\n\n"
2570 "Use 'smartctl -a' (or '-x') to print SMART (and more) information\n\n");
2574 // Start by getting Drive ID information. We need this, to know if SMART is supported.
2576 ata_identify_device drive
; memset(&drive
, 0, sizeof(drive
));
2577 unsigned char raw_drive
[sizeof(drive
)]; memset(&raw_drive
, 0, sizeof(raw_drive
));
2579 device
->clear_err();
2580 int retid
= ata_read_identity(device
, &drive
, options
.fix_swapped_id
, raw_drive
);
2582 pout("Read Device Identity failed: %s\n\n",
2583 (device
->get_errno() ? device
->get_errmsg() : "Unknown error"));
2584 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
2586 else if (!nonempty(&drive
, sizeof(drive
))) {
2587 pout("Read Device Identity failed: empty IDENTIFY data\n\n");
2588 failuretest(MANDATORY_CMD
, returnval
|=FAILID
);
2591 // If requested, show which presets would be used for this drive and exit.
2592 if (options
.show_presets
) {
2593 show_presets(&drive
);
2597 // Use preset vendor attribute options unless user has requested otherwise.
2598 ata_vendor_attr_defs attribute_defs
= options
.attribute_defs
;
2599 firmwarebug_defs firmwarebugs
= options
.firmwarebugs
;
2600 const drive_settings
* dbentry
= 0;
2601 if (!options
.ignore_presets
)
2602 dbentry
= lookup_drive_apply_presets(&drive
, attribute_defs
,
2605 // Get capacity, sector sizes and rotation rate
2606 ata_size_info sizes
;
2607 ata_get_size_info(&drive
, sizes
);
2608 int rpm
= ata_get_rotation_rate(&drive
);
2610 // Print ATA IDENTIFY info if requested
2611 if (options
.identify_word_level
>= 0) {
2612 pout("=== ATA IDENTIFY DATA ===\n");
2613 // Pass raw data without endianness adjustments
2614 ata_print_identify_data(raw_drive
, (options
.identify_word_level
> 0), options
.identify_bit_level
);
2617 // Print most drive identity information if requested
2618 if (options
.drive_info
) {
2619 pout("=== START OF INFORMATION SECTION ===\n");
2620 print_drive_info(&drive
, sizes
, rpm
, dbentry
);
2623 // Check and print SMART support and state
2624 int smart_supported
= -1, smart_enabled
= -1;
2625 if (need_smart_support
|| options
.drive_info
) {
2629 pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n",
2630 packetdevicetype(retid
-1));
2633 // Disk device: SMART supported and enabled ?
2634 smart_supported
= ataSmartSupport(&drive
);
2635 smart_enabled
= ataIsSmartEnabled(&drive
);
2637 if (smart_supported
< 0)
2638 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
2639 if (smart_supported
&& smart_enabled
< 0) {
2640 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
2641 if (need_smart_support
) {
2642 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2643 // check SMART support by trying a command
2644 pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
2645 if (ataDoesSmartWork(device
))
2646 smart_supported
= smart_enabled
= 1;
2649 else if (smart_supported
< 0 && (smart_enabled
> 0 || dbentry
))
2650 // Assume supported if enabled or in drive database
2651 smart_supported
= 1;
2653 if (smart_supported
< 0)
2654 pout("SMART support is: Unknown - Try option -s with argument 'on' to enable it.");
2655 else if (!smart_supported
)
2656 pout("SMART support is: Unavailable - device lacks SMART capability.\n");
2658 if (options
.drive_info
)
2659 pout("SMART support is: Available - device has SMART capability.\n");
2660 if (smart_enabled
>= 0) {
2661 if (device
->ata_identify_is_cached()) {
2662 if (options
.drive_info
)
2663 pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
2664 (smart_enabled
?"En":"Dis"));
2665 smart_enabled
= ataDoesSmartWork(device
);
2667 if (options
.drive_info
)
2668 pout("SMART support is: %s\n",
2669 (smart_enabled
? "Enabled" : "Disabled"));
2676 if (options
.get_aam
) {
2677 if ((drive
.command_set_2
& 0xc200) != 0x4200) // word083
2678 pout("AAM feature is: Unavailable\n");
2679 else if (!(drive
.word086
& 0x0200))
2680 pout("AAM feature is: Disabled\n");
2682 print_aam_level("AAM level is: ", drive
.words088_255
[94-88] & 0xff,
2683 drive
.words088_255
[94-88] >> 8);
2687 if (options
.get_apm
) {
2688 if ((drive
.command_set_2
& 0xc008) != 0x4008) // word083
2689 pout("APM feature is: Unavailable\n");
2690 else if (!(drive
.word086
& 0x0008))
2691 pout("APM feature is: Disabled\n");
2693 print_apm_level("APM level is: ", drive
.words088_255
[91-88] & 0xff);
2696 // Print read look-ahead status
2697 if (options
.get_lookahead
) {
2698 pout("Rd look-ahead is: %s\n",
2699 ( (drive
.command_set_2
& 0xc000) != 0x4000 // word083
2700 || !(drive
.command_set_1
& 0x0040)) ? "Unavailable" : // word082
2701 !(drive
.cfs_enable_1
& 0x0040) ? "Disabled" : "Enabled"); // word085
2704 // Print write cache status
2705 if (options
.get_wcache
) {
2706 pout("Write cache is: %s\n",
2707 ( (drive
.command_set_2
& 0xc000) != 0x4000 // word083
2708 || !(drive
.command_set_1
& 0x0020)) ? "Unavailable" : // word082
2709 !(drive
.cfs_enable_1
& 0x0020) ? "Disabled" : "Enabled"); // word085
2712 // Print ATA security status
2713 if (options
.get_security
)
2714 print_ata_security_status("ATA Security is: ", drive
.words088_255
[128-88]);
2716 // Print write cache reordering status
2717 if (options
.sct_wcache_reorder_get
) {
2718 if (isSCTFeatureControlCapable(&drive
)) {
2719 int wcache_reorder
= ataGetSetSCTWriteCacheReordering(device
,
2720 false /*enable*/, false /*persistent*/, false /*set*/);
2722 if (-1 <= wcache_reorder
&& wcache_reorder
<= 2)
2723 pout("Wt Cache Reorder: %s\n",
2724 (wcache_reorder
== -1 ? "Unknown (SCT Feature Control command failed)" :
2725 wcache_reorder
== 0 ? "Unknown" : // not defined in standard but returned on some drives if not set
2726 wcache_reorder
== 1 ? "Enabled" : "Disabled"));
2728 pout("Wt Cache Reorder: Unknown (0x%02x)\n", wcache_reorder
);
2731 pout("Wt Cache Reorder: Unavailable\n");
2734 // Print remaining drive info
2735 if (options
.drive_info
) {
2736 // Print the (now possibly changed) power mode if available
2738 pout("Power mode %s %s\n", (powerchg
?"was:":"is: "), powername
);
2742 // Exit if SMART is not supported but must be available to proceed
2743 if (smart_supported
<= 0 && need_smart_support
)
2744 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2746 // START OF THE ENABLE/DISABLE SECTION OF THE CODE
2747 if ( options
.smart_disable
|| options
.smart_enable
2748 || options
.smart_auto_save_disable
|| options
.smart_auto_save_enable
2749 || options
.smart_auto_offl_disable
|| options
.smart_auto_offl_enable
2750 || options
.set_aam
|| options
.set_apm
|| options
.set_lookahead
2751 || options
.set_wcache
|| options
.set_security_freeze
|| options
.set_standby
2752 || options
.sct_wcache_reorder_set
)
2753 pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
2755 // Enable/Disable AAM
2756 if (options
.set_aam
) {
2757 if (options
.set_aam
> 0) {
2758 if (!ata_set_features(device
, ATA_ENABLE_AAM
, options
.set_aam
-1)) {
2759 pout("AAM enable failed: %s\n", device
->get_errmsg());
2760 returnval
|= FAILSMART
;
2763 print_aam_level("AAM set to level ", options
.set_aam
-1);
2766 if (!ata_set_features(device
, ATA_DISABLE_AAM
)) {
2767 pout("AAM disable failed: %s\n", device
->get_errmsg());
2768 returnval
|= FAILSMART
;
2771 pout("AAM disabled\n");
2775 // Enable/Disable APM
2776 if (options
.set_apm
) {
2777 if (options
.set_apm
> 0) {
2778 if (!ata_set_features(device
, ATA_ENABLE_APM
, options
.set_apm
-1)) {
2779 pout("APM enable failed: %s\n", device
->get_errmsg());
2780 returnval
|= FAILSMART
;
2783 print_apm_level("APM set to level ", options
.set_apm
-1);
2786 if (!ata_set_features(device
, ATA_DISABLE_APM
)) {
2787 pout("APM disable failed: %s\n", device
->get_errmsg());
2788 returnval
|= FAILSMART
;
2791 pout("APM disabled\n");
2795 // Enable/Disable read look-ahead
2796 if (options
.set_lookahead
) {
2797 bool enable
= (options
.set_lookahead
> 0);
2798 if (!ata_set_features(device
, (enable
? ATA_ENABLE_READ_LOOK_AHEAD
: ATA_DISABLE_READ_LOOK_AHEAD
))) {
2799 pout("Read look-ahead %sable failed: %s\n", (enable
? "en" : "dis"), device
->get_errmsg());
2800 returnval
|= FAILSMART
;
2803 pout("Read look-ahead %sabled\n", (enable
? "en" : "dis"));
2806 // Enable/Disable write cache
2807 if (options
.set_wcache
) {
2808 bool enable
= (options
.set_wcache
> 0);
2809 if (!ata_set_features(device
, (enable
? ATA_ENABLE_WRITE_CACHE
: ATA_DISABLE_WRITE_CACHE
))) {
2810 pout("Write cache %sable failed: %s\n", (enable
? "en" : "dis"), device
->get_errmsg());
2811 returnval
|= FAILSMART
;
2814 pout("Write cache %sabled\n", (enable
? "en" : "dis"));
2817 // Enable/Disable write cache reordering
2818 if (options
.sct_wcache_reorder_set
) {
2819 bool enable
= (options
.sct_wcache_reorder_set
> 0);
2820 if (!isSCTFeatureControlCapable(&drive
))
2821 pout("Write cache reordering %sable failed: SCT Feature Control command not supported\n",
2822 (enable
? "en" : "dis"));
2823 else if (ataGetSetSCTWriteCacheReordering(device
,
2824 enable
, false /*persistent*/, true /*set*/) < 0) {
2825 pout("Write cache reordering %sable failed: %s\n", (enable
? "en" : "dis"), device
->get_errmsg());
2826 returnval
|= FAILSMART
;
2829 pout("Write cache reordering %sabled\n", (enable
? "en" : "dis"));
2832 // Freeze ATA security
2833 if (options
.set_security_freeze
) {
2834 if (!ata_nodata_command(device
, ATA_SECURITY_FREEZE_LOCK
)) {
2835 pout("ATA SECURITY FREEZE LOCK failed: %s\n", device
->get_errmsg());
2836 returnval
|= FAILSMART
;
2839 pout("ATA Security set to frozen mode\n");
2842 // Set standby timer
2843 if (options
.set_standby
) {
2844 if (!ata_nodata_command(device
, ATA_IDLE
, options
.set_standby
-1)) {
2845 pout("ATA IDLE command failed: %s\n", device
->get_errmsg());
2846 returnval
|= FAILSMART
;
2849 print_standby_timer("Standby timer set to ", options
.set_standby
-1, drive
);
2852 // Enable/Disable SMART commands
2853 if (options
.smart_enable
) {
2854 if (ataEnableSmart(device
)) {
2855 pout("SMART Enable failed: %s\n\n", device
->get_errmsg());
2856 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2859 pout("SMART Enabled.\n");
2864 // Turn off SMART on device
2865 if (options
.smart_disable
) {
2866 if (ataDisableSmart(device
)) {
2867 pout("SMART Disable failed: %s\n\n", device
->get_errmsg());
2868 failuretest(MANDATORY_CMD
,returnval
|=FAILSMART
);
2872 // Exit if SMART is disabled but must be enabled to proceed
2873 if (options
.smart_disable
|| (smart_enabled
<= 0 && need_smart_enabled
&& !is_permissive())) {
2874 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
2875 if (!options
.smart_disable
)
2876 pout("(override with '-T permissive' option)\n");
2880 // Enable/Disable Auto-save attributes
2881 if (options
.smart_auto_save_enable
) {
2882 if (ataEnableAutoSave(device
)){
2883 pout("SMART Enable Attribute Autosave failed: %s\n\n", device
->get_errmsg());
2884 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2887 pout("SMART Attribute Autosave Enabled.\n");
2890 if (options
.smart_auto_save_disable
) {
2891 if (ataDisableAutoSave(device
)){
2892 pout("SMART Disable Attribute Autosave failed: %s\n\n", device
->get_errmsg());
2893 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
2896 pout("SMART Attribute Autosave Disabled.\n");
2899 // Read SMART values and thresholds if necessary
2900 ata_smart_values smartval
; memset(&smartval
, 0, sizeof(smartval
));
2901 ata_smart_thresholds_pvt smartthres
; memset(&smartthres
, 0, sizeof(smartthres
));
2902 bool smart_val_ok
= false, smart_thres_ok
= false;
2904 if (need_smart_val
) {
2905 if (ataReadSmartValues(device
, &smartval
)) {
2906 pout("Read SMART Data failed: %s\n\n", device
->get_errmsg());
2907 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2910 smart_val_ok
= true;
2912 if (options
.smart_check_status
|| options
.smart_vendor_attrib
) {
2913 if (ataReadSmartThresholds(device
, &smartthres
)){
2914 pout("Read SMART Thresholds failed: %s\n\n", device
->get_errmsg());
2915 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2918 smart_thres_ok
= true;
2923 // Enable/Disable Off-line testing
2924 bool needupdate
= false;
2925 if (options
.smart_auto_offl_enable
) {
2926 if (!isSupportAutomaticTimer(&smartval
)){
2927 pout("SMART Automatic Timers not supported\n\n");
2928 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2930 needupdate
= smart_val_ok
;
2931 if (ataEnableAutoOffline(device
)){
2932 pout("SMART Enable Automatic Offline failed: %s\n\n", device
->get_errmsg());
2933 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2936 pout("SMART Automatic Offline Testing Enabled every four hours.\n");
2939 if (options
.smart_auto_offl_disable
) {
2940 if (!isSupportAutomaticTimer(&smartval
)){
2941 pout("SMART Automatic Timers not supported\n\n");
2942 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2944 needupdate
= smart_val_ok
;
2945 if (ataDisableAutoOffline(device
)){
2946 pout("SMART Disable Automatic Offline failed: %s\n\n", device
->get_errmsg());
2947 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2950 pout("SMART Automatic Offline Testing Disabled.\n");
2953 if (needupdate
&& ataReadSmartValues(device
, &smartval
)){
2954 pout("Read SMART Data failed: %s\n\n", device
->get_errmsg());
2955 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
2956 smart_val_ok
= false;
2959 // all this for a newline!
2960 if ( options
.smart_disable
|| options
.smart_enable
2961 || options
.smart_auto_save_disable
|| options
.smart_auto_save_enable
2962 || options
.smart_auto_offl_disable
|| options
.smart_auto_offl_enable
2963 || options
.set_aam
|| options
.set_apm
|| options
.set_lookahead
2964 || options
.set_wcache
|| options
.set_security_freeze
|| options
.set_standby
2965 || options
.sct_wcache_reorder_set
)
2968 // START OF READ-ONLY OPTIONS APART FROM -V and -i
2969 if ( options
.smart_check_status
|| options
.smart_general_values
2970 || options
.smart_vendor_attrib
|| options
.smart_error_log
2971 || options
.smart_selftest_log
|| options
.smart_selective_selftest_log
2972 || options
.smart_ext_error_log
|| options
.smart_ext_selftest_log
2973 || options
.sct_temp_sts
|| options
.sct_temp_hist
)
2974 pout("=== START OF READ SMART DATA SECTION ===\n");
2976 // Check SMART status
2977 if (options
.smart_check_status
) {
2979 switch (ataSmartStatus2(device
)) {
2982 // The case where the disk health is OK
2983 pout("SMART overall-health self-assessment test result: PASSED\n");
2984 if (smart_thres_ok
&& find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 0)) {
2985 if (options
.smart_vendor_attrib
)
2986 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
2989 pout("Please note the following marginal Attributes:\n");
2990 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 2, options
.output_format
);
2999 // The case where the disk health is NOT OK
3001 pout("SMART overall-health self-assessment test result: FAILED!\n"
3002 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
3004 if (smart_thres_ok
&& find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 1)) {
3005 returnval
|=FAILATTR
;
3006 if (options
.smart_vendor_attrib
)
3007 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
3010 pout("Failed Attributes:\n");
3011 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 1, options
.output_format
);
3015 pout("No failed Attributes found.\n\n");
3016 returnval
|=FAILSTATUS
;
3022 // Something went wrong with the SMART STATUS command.
3023 // The ATA SMART RETURN STATUS command provides the result in the ATA output
3024 // registers. Buggy ATA/SATA drivers and SAT Layers often do not properly
3025 // return the registers values.
3026 pout("SMART Status %s: %s\n",
3027 (device
->is_syscall_unsup() ? "not supported" : "command failed"),
3028 device
->get_errmsg());
3029 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3031 if (!(smart_val_ok
&& smart_thres_ok
)) {
3033 pout("SMART overall-health self-assessment test result: UNKNOWN!\n"
3034 "SMART Status, Attributes and Thresholds cannot be read.\n\n");
3036 else if (find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 1)) {
3038 pout("SMART overall-health self-assessment test result: FAILED!\n"
3039 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
3040 pout("Warning: This result is based on an Attribute check.\n");
3042 returnval
|=FAILATTR
;
3043 returnval
|=FAILSTATUS
;
3044 if (options
.smart_vendor_attrib
)
3045 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
3048 pout("Failed Attributes:\n");
3049 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 1, options
.output_format
);
3053 pout("SMART overall-health self-assessment test result: PASSED\n");
3054 pout("Warning: This result is based on an Attribute check.\n");
3055 if (find_failed_attr(&smartval
, &smartthres
, attribute_defs
, 0)) {
3056 if (options
.smart_vendor_attrib
)
3057 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
3060 pout("Please note the following marginal Attributes:\n");
3061 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
, 2, options
.output_format
);
3070 } // end of switch statement
3073 } // end of checking SMART Status
3075 // Print general SMART values
3076 if (smart_val_ok
&& options
.smart_general_values
)
3077 PrintGeneralSmartValues(&smartval
, &drive
, firmwarebugs
);
3079 // Print vendor-specific attributes
3080 if (smart_val_ok
&& options
.smart_vendor_attrib
) {
3082 PrintSmartAttribWithThres(&smartval
, &smartthres
, attribute_defs
, rpm
,
3083 (printing_is_switchable
? 2 : 0), options
.output_format
);
3087 // If GP Log is supported use smart log directory for
3088 // error and selftest log support check.
3089 if ( isGeneralPurposeLoggingCapable(&drive
)
3090 && ( options
.smart_error_log
|| options
.smart_selftest_log
3091 || options
.retry_error_log
|| options
.retry_selftest_log
))
3092 need_smart_logdir
= true;
3094 ata_smart_log_directory smartlogdir_buf
, gplogdir_buf
;
3095 const ata_smart_log_directory
* smartlogdir
= 0, * gplogdir
= 0;
3097 // Read SMART Log directory
3098 if (need_smart_logdir
) {
3099 if (firmwarebugs
.is_set(BUG_NOLOGDIR
))
3100 smartlogdir
= fake_logdir(&smartlogdir_buf
, options
);
3101 else if (ataReadLogDirectory(device
, &smartlogdir_buf
, false)) {
3102 pout("Read SMART Log Directory failed: %s\n\n", device
->get_errmsg());
3103 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3106 smartlogdir
= &smartlogdir_buf
;
3109 // Read GP Log directory
3110 if (need_gp_logdir
) {
3111 if (firmwarebugs
.is_set(BUG_NOLOGDIR
))
3112 gplogdir
= fake_logdir(&gplogdir_buf
, options
);
3113 else if (ataReadLogDirectory(device
, &gplogdir_buf
, true)) {
3114 pout("Read GP Log Directory failed\n\n");
3115 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3118 gplogdir
= &gplogdir_buf
;
3121 // Print log directories
3122 if ((options
.gp_logdir
&& gplogdir
) || (options
.smart_logdir
&& smartlogdir
)) {
3123 if (firmwarebugs
.is_set(BUG_NOLOGDIR
))
3124 pout("Log Directories not read due to '-F nologdir' option\n\n");
3126 PrintLogDirectories(gplogdir
, smartlogdir
);
3130 for (i
= 0; i
< options
.log_requests
.size(); i
++) {
3131 const ata_log_request
& req
= options
.log_requests
[i
];
3134 unsigned max_nsectors
;
3136 type
= "General Purpose";
3137 max_nsectors
= GetNumLogSectors(gplogdir
, req
.logaddr
, true);
3141 max_nsectors
= GetNumLogSectors(smartlogdir
, req
.logaddr
, false);
3144 if (!max_nsectors
) {
3145 if (!is_permissive()) {
3146 pout("%s Log 0x%02x does not exist (override with '-T permissive' option)\n", type
, req
.logaddr
);
3149 max_nsectors
= req
.page
+1;
3151 if (max_nsectors
<= req
.page
) {
3152 pout("%s Log 0x%02x has only %u sectors, output skipped\n", type
, req
.logaddr
, max_nsectors
);
3156 unsigned ns
= req
.nsectors
;
3157 if (ns
> max_nsectors
- req
.page
) {
3158 if (req
.nsectors
!= ~0U) // "FIRST-max"
3159 pout("%s Log 0x%02x has only %u sectors, output truncated\n", type
, req
.logaddr
, max_nsectors
);
3160 ns
= max_nsectors
- req
.page
;
3163 // SMART log don't support sector offset, start with first sector
3164 unsigned offs
= (req
.gpl
? 0 : req
.page
);
3166 raw_buffer
log_buf((offs
+ ns
) * 512);
3169 ok
= ataReadLogExt(device
, req
.logaddr
, 0x00, req
.page
, log_buf
.data(), ns
);
3171 ok
= ataReadSmartLog(device
, req
.logaddr
, log_buf
.data(), offs
+ ns
);
3173 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3175 PrintLogPages(type
, log_buf
.data() + offs
*512, req
.logaddr
, req
.page
, ns
, max_nsectors
);
3178 // Print SMART Extendend Comprehensive Error Log
3179 bool do_smart_error_log
= options
.smart_error_log
;
3180 if (options
.smart_ext_error_log
) {
3182 unsigned nsectors
= GetNumLogSectors(gplogdir
, 0x03, true);
3184 pout("SMART Extended Comprehensive Error Log (GP Log 0x03) not supported\n\n");
3185 else if (nsectors
>= 256)
3186 pout("SMART Extended Comprehensive Error Log size %u not supported\n\n", nsectors
);
3188 raw_buffer
log_03_buf(nsectors
* 512);
3189 ata_smart_exterrlog
* log_03
= (ata_smart_exterrlog
*)log_03_buf
.data();
3190 if (!ataReadExtErrorLog(device
, log_03
, nsectors
, firmwarebugs
)) {
3191 pout("Read SMART Extended Comprehensive Error Log failed\n\n");
3192 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3195 if (PrintSmartExtErrorLog(log_03
, nsectors
, options
.smart_ext_error_log
))
3196 returnval
|= FAILERR
;
3202 if (options
.retry_error_log
)
3203 do_smart_error_log
= true;
3204 else if (!do_smart_error_log
)
3205 pout("Try '-l [xerror,]error' to read traditional SMART Error Log\n");
3209 // Print SMART error log
3210 if (do_smart_error_log
) {
3211 if (!( ( smartlogdir
&& GetNumLogSectors(smartlogdir
, 0x01, false))
3212 || (!smartlogdir
&& isSmartErrorLogCapable(&smartval
, &drive
) )
3213 || is_permissive() )) {
3214 pout("SMART Error Log not supported\n\n");
3217 ata_smart_errorlog smarterror
; memset(&smarterror
, 0, sizeof(smarterror
));
3218 if (ataReadErrorLog(device
, &smarterror
, firmwarebugs
)) {
3219 pout("Read SMART Error Log failed: %s\n\n", device
->get_errmsg());
3220 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3223 // quiet mode is turned on inside PrintSmartErrorLog()
3224 if (PrintSmartErrorlog(&smarterror
, firmwarebugs
))
3231 // Print SMART Extendend Self-test Log
3232 bool do_smart_selftest_log
= options
.smart_selftest_log
;
3233 if (options
.smart_ext_selftest_log
) {
3235 unsigned nsectors
= GetNumLogSectors(gplogdir
, 0x07, true);
3237 pout("SMART Extended Self-test Log (GP Log 0x07) not supported\n\n");
3238 else if (nsectors
>= 256)
3239 pout("SMART Extended Self-test Log size %u not supported\n\n", nsectors
);
3241 raw_buffer
log_07_buf(nsectors
* 512);
3242 ata_smart_extselftestlog
* log_07
= (ata_smart_extselftestlog
*)log_07_buf
.data();
3243 if (!ataReadExtSelfTestLog(device
, log_07
, nsectors
)) {
3244 pout("Read SMART Extended Self-test Log failed\n\n");
3245 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3248 if (PrintSmartExtSelfTestLog(log_07
, nsectors
, options
.smart_ext_selftest_log
))
3249 returnval
|= FAILLOG
;
3255 if (options
.retry_selftest_log
)
3256 do_smart_selftest_log
= true;
3257 else if (!do_smart_selftest_log
)
3258 pout("Try '-l [xselftest,]selftest' to read traditional SMART Self Test Log\n");
3262 // Print SMART self-test log
3263 if (do_smart_selftest_log
) {
3264 if (!( ( smartlogdir
&& GetNumLogSectors(smartlogdir
, 0x06, false))
3265 || (!smartlogdir
&& isSmartTestLogCapable(&smartval
, &drive
) )
3266 || is_permissive() )) {
3267 pout("SMART Self-test Log not supported\n\n");
3270 ata_smart_selftestlog smartselftest
; memset(&smartselftest
, 0, sizeof(smartselftest
));
3271 if (ataReadSelfTestLog(device
, &smartselftest
, firmwarebugs
)) {
3272 pout("Read SMART Self-test Log failed: %s\n\n", device
->get_errmsg());
3273 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3277 if (ataPrintSmartSelfTestlog(&smartselftest
, !printing_is_switchable
, firmwarebugs
))
3278 returnval
|= FAILLOG
;
3285 // Print SMART selective self-test log
3286 if (options
.smart_selective_selftest_log
) {
3287 ata_selective_self_test_log log
;
3289 if (!isSupportSelectiveSelfTest(&smartval
))
3290 pout("Selective Self-tests/Logging not supported\n\n");
3291 else if(ataReadSelectiveSelfTestLog(device
, &log
)) {
3292 pout("Read SMART Selective Self-test Log failed: %s\n\n", device
->get_errmsg());
3293 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3297 // If any errors were found, they are logged in the SMART Self-test log.
3298 // So there is no need to print the Selective Self Test log in silent
3300 if (!printing_is_switchable
)
3301 ataPrintSelectiveSelfTestLog(&log
, &smartval
);
3307 // Check if SCT commands available
3308 bool sct_ok
= isSCTCapable(&drive
);
3309 if(!sct_ok
&& (options
.sct_temp_sts
|| options
.sct_temp_hist
|| options
.sct_temp_int
3310 || options
.sct_erc_get
|| options
.sct_erc_set
))
3311 pout("SCT Commands not supported\n\n");
3313 // Print SCT status and temperature history table
3314 if (sct_ok
&& (options
.sct_temp_sts
|| options
.sct_temp_hist
|| options
.sct_temp_int
)) {
3316 bool sct_temp_hist_ok
= isSCTDataTableCapable(&drive
);
3317 ata_sct_status_response sts
;
3319 if (options
.sct_temp_sts
|| (options
.sct_temp_hist
&& sct_temp_hist_ok
)) {
3321 if (ataReadSCTStatus(device
, &sts
)) {
3323 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3326 if (options
.sct_temp_sts
) {
3327 ataPrintSCTStatus(&sts
);
3332 if (!sct_temp_hist_ok
&& (options
.sct_temp_hist
|| options
.sct_temp_int
)) {
3333 pout("SCT Data Table command not supported\n\n");
3334 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3338 if (options
.sct_temp_hist
) {
3339 // Read SCT temperature history,
3340 // requires initial SCT status from above
3341 ata_sct_temperature_history_table tmh
;
3342 if (ataReadSCTTempHist(device
, &tmh
, &sts
)) {
3343 pout("Read SCT Temperature History failed\n\n");
3344 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3347 ataPrintSCTTempHist(&tmh
);
3351 if (options
.sct_temp_int
) {
3352 // Set new temperature logging interval
3353 if (!isSCTFeatureControlCapable(&drive
)) {
3354 pout("SCT Feature Control command not supported\n\n");
3355 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3358 if (ataSetSCTTempInterval(device
, options
.sct_temp_int
, options
.sct_temp_int_pers
)) {
3359 pout("Write Temperature Logging Interval failed\n\n");
3360 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3363 pout("Temperature Logging Interval set to %u minute%s (%s)\n",
3364 options
.sct_temp_int
, (options
.sct_temp_int
== 1 ? "" : "s"),
3365 (options
.sct_temp_int_pers
? "persistent" : "volatile"));
3371 // SCT Error Recovery Control
3372 if (sct_ok
&& (options
.sct_erc_get
|| options
.sct_erc_set
)) {
3373 if (!isSCTErrorRecoveryControlCapable(&drive
)) {
3374 pout("SCT Error Recovery Control command not supported\n\n");
3375 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3378 bool sct_erc_get
= options
.sct_erc_get
;
3379 if (options
.sct_erc_set
) {
3380 // Set SCT Error Recovery Control
3381 if ( ataSetSCTErrorRecoveryControltime(device
, 1, options
.sct_erc_readtime
)
3382 || ataSetSCTErrorRecoveryControltime(device
, 2, options
.sct_erc_writetime
)) {
3383 pout("SCT (Set) Error Recovery Control command failed\n");
3384 if (!( (options
.sct_erc_readtime
== 70 && options
.sct_erc_writetime
== 70)
3385 || (options
.sct_erc_readtime
== 0 && options
.sct_erc_writetime
== 0)))
3386 pout("Retry with: 'scterc,70,70' to enable ERC or 'scterc,0,0' to disable\n");
3387 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3388 sct_erc_get
= false;
3390 else if (!sct_erc_get
)
3391 ataPrintSCTErrorRecoveryControl(true, options
.sct_erc_readtime
,
3392 options
.sct_erc_writetime
);
3396 // Print SCT Error Recovery Control
3397 unsigned short read_timer
, write_timer
;
3398 if ( ataGetSCTErrorRecoveryControltime(device
, 1, read_timer
)
3399 || ataGetSCTErrorRecoveryControltime(device
, 2, write_timer
)) {
3400 pout("SCT (Get) Error Recovery Control command failed\n");
3401 if (options
.sct_erc_set
) {
3402 pout("The previous SCT (Set) Error Recovery Control command succeeded\n");
3403 ataPrintSCTErrorRecoveryControl(true, options
.sct_erc_readtime
,
3404 options
.sct_erc_writetime
);
3406 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3409 ataPrintSCTErrorRecoveryControl(false, read_timer
, write_timer
);
3415 // Print Device Statistics
3416 if (options
.devstat_all_pages
|| options
.devstat_ssd_page
|| !options
.devstat_pages
.empty()) {
3417 bool use_gplog
= true;
3418 unsigned nsectors
= 0;
3420 nsectors
= GetNumLogSectors(gplogdir
, 0x04, false);
3421 else if (smartlogdir
){ // for systems without ATA_READ_LOG_EXT
3422 nsectors
= GetNumLogSectors(smartlogdir
, 0x04, false);
3426 pout("Device Statistics (GP/SMART Log 0x04) not supported\n\n");
3427 else if (!print_device_statistics(device
, nsectors
, options
.devstat_pages
,
3428 options
.devstat_all_pages
, options
.devstat_ssd_page
, use_gplog
))
3429 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3432 // Print SATA Phy Event Counters
3433 if (options
.sataphy
) {
3434 unsigned nsectors
= GetNumLogSectors(gplogdir
, 0x11, true);
3435 // Packet interface devices do not provide a log directory, check support bit
3436 if (!nsectors
&& (drive
.words047_079
[76-47] & 0x0401) == 0x0400)
3439 pout("SATA Phy Event Counters (GP Log 0x11) not supported\n\n");
3440 else if (nsectors
!= 1)
3441 pout("SATA Phy Event Counters with %u sectors not supported\n\n", nsectors
);
3443 unsigned char log_11
[512] = {0, };
3444 unsigned char features
= (options
.sataphy_reset
? 0x01 : 0x00);
3445 if (!ataReadLogExt(device
, 0x11, features
, 0, log_11
, 1)) {
3446 pout("Read SATA Phy Event Counters failed\n\n");
3447 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3450 PrintSataPhyEventCounters(log_11
, options
.sataphy_reset
);
3454 // Set to standby (spindown) mode
3455 // (Above commands may spinup drive)
3456 if (options
.set_standby_now
) {
3457 if (!ata_nodata_command(device
, ATA_STANDBY_IMMEDIATE
)) {
3458 pout("ATA STANDBY IMMEDIATE command failed: %s\n", device
->get_errmsg());
3459 returnval
|= FAILSMART
;
3462 pout("Device placed in STANDBY mode\n");
3465 // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
3466 if (!smart_val_ok
|| options
.smart_selftest_type
== -1)
3469 pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
3470 // if doing a self-test, be sure it's supported by the hardware
3471 switch (options
.smart_selftest_type
) {
3472 case OFFLINE_FULL_SCAN
:
3473 if (!isSupportExecuteOfflineImmediate(&smartval
)){
3474 pout("Execute Offline Immediate function not supported\n\n");
3475 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3478 case ABORT_SELF_TEST
:
3479 case SHORT_SELF_TEST
:
3480 case EXTEND_SELF_TEST
:
3481 case SHORT_CAPTIVE_SELF_TEST
:
3482 case EXTEND_CAPTIVE_SELF_TEST
:
3483 if (!isSupportSelfTest(&smartval
)){
3484 pout("Self-test functions not supported\n\n");
3485 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3488 case CONVEYANCE_SELF_TEST
:
3489 case CONVEYANCE_CAPTIVE_SELF_TEST
:
3490 if (!isSupportConveyanceSelfTest(&smartval
)){
3491 pout("Conveyance Self-test functions not supported\n\n");
3492 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3495 case SELECTIVE_SELF_TEST
:
3496 case SELECTIVE_CAPTIVE_SELF_TEST
:
3497 if (!isSupportSelectiveSelfTest(&smartval
)){
3498 pout("Selective Self-test functions not supported\n\n");
3499 failuretest(MANDATORY_CMD
, returnval
|=FAILSMART
);
3503 break; // Vendor specific type
3506 // Now do the test. Note ataSmartTest prints its own error/success
3508 if (ataSmartTest(device
, options
.smart_selftest_type
, options
.smart_selftest_force
,
3509 options
.smart_selective_args
, &smartval
, sizes
.sectors
))
3510 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3512 // Tell user how long test will take to complete. This is tricky
3513 // because in the case of an Offline Full Scan, the completion
3514 // timer is volatile, and needs to be read AFTER the command is
3515 // given. If this will interrupt the Offline Full Scan, we don't
3516 // do it, just warn user.
3517 if (options
.smart_selftest_type
== OFFLINE_FULL_SCAN
) {
3518 if (isSupportOfflineAbort(&smartval
))
3519 pout("Note: giving further SMART commands will abort Offline testing\n");
3520 else if (ataReadSmartValues(device
, &smartval
)){
3521 pout("Read SMART Data failed: %s\n\n", device
->get_errmsg());
3522 failuretest(OPTIONAL_CMD
, returnval
|=FAILSMART
);
3526 // Now say how long the test will take to complete
3527 int timewait
= TestTime(&smartval
, options
.smart_selftest_type
);
3529 time_t t
=time(NULL
);
3530 if (options
.smart_selftest_type
== OFFLINE_FULL_SCAN
) {
3532 pout("Please wait %d seconds for test to complete.\n", (int)timewait
);
3535 pout("Please wait %d minutes for test to complete.\n", (int)timewait
);
3537 pout("Test will complete after %s\n", ctime(&t
));
3539 if ( options
.smart_selftest_type
!= SHORT_CAPTIVE_SELF_TEST
3540 && options
.smart_selftest_type
!= EXTEND_CAPTIVE_SELF_TEST
3541 && options
.smart_selftest_type
!= CONVEYANCE_CAPTIVE_SELF_TEST
3542 && options
.smart_selftest_type
!= SELECTIVE_CAPTIVE_SELF_TEST
)
3543 pout("Use smartctl -X to abort test.\n");