smartmontools  SVN Rev 4063
Utility to control and monitor storage systems with "S.M.A.R.T."
ataprint.cpp
Go to the documentation of this file.
1 /*
2  * ataprint.cpp
3  *
4  * Home page of code is: http://smartmontools.sourceforge.net
5  *
6  * Copyright (C) 2002-11 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7  * Copyright (C) 2008-15 Christian Franke <smartmontools-support@lists.sourceforge.net>
8  * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
9  *
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)
13  * any later version.
14  *
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/>.
17  *
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/
22  *
23  */
24 
25 #include "config.h"
26 
27 #include <ctype.h>
28 #include <errno.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 
33 #include "int64.h"
34 #include "atacmdnames.h"
35 #include "atacmds.h"
36 #include "ataidentify.h"
37 #include "dev_interface.h"
38 #include "ataprint.h"
39 #include "smartctl.h"
40 #include "utility.h"
41 #include "knowndrives.h"
42 
43 const char * ataprint_cpp_cvsid = "$Id: ataprint.cpp 4048 2015-03-29 16:09:04Z chrfranke $"
45 
46 
47 static const char * infofound(const char *output) {
48  return (*output ? output : "[No Information Found]");
49 }
50 
51 // Return true if '-T permissive' is specified,
52 // used to ignore missing capabilities
53 static bool is_permissive()
54 {
56  return false;
58  return true;
59 }
60 
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
65  * empty string.
66  *
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.
72  */
73 
74 static std::string format_st_er_desc(
75  unsigned char CR, unsigned char FR,
76  unsigned char ST, unsigned char ER,
77  unsigned short SC,
78  const ata_smart_errorlog_error_struct * lba28_regs,
79  const ata_smart_exterrlog_error * lba48_regs
80 )
81 {
82  const char *error_flag[8];
83  int i, print_lba=0, print_sector=0;
84 
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
101 
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
104  * below)
105  */
106  int uses_device_fault = 1;
107 
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;
111 
112  std::string str;
113 
114  switch (CR) {
115  case 0x10: // RECALIBRATE
116  error_flag[2] = abrt;
117  error_flag[1] = tk0nf;
118  break;
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
124  error_flag[6] = unc;
125  error_flag[5] = mc;
126  error_flag[4] = idnf;
127  error_flag[3] = mcr;
128  error_flag[2] = abrt;
129  error_flag[1] = nm;
130  error_flag[0] = amnf;
131  print_lba=1;
132  break;
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;
138  print_lba=1;
139  break;
140  case 0x2a: // READ STREAM DMA
141  case 0x2b: // READ STREAM PIO
142  if (CR==0x2a)
143  error_flag[7] = icrc;
144  error_flag[6] = unc;
145  error_flag[5] = mc;
146  error_flag[4] = idnf;
147  error_flag[3] = mcr;
148  error_flag[2] = abrt;
149  error_flag[1] = nm;
150  error_flag[0] = ccto;
151  print_lba=1;
152  print_sector=SC;
153  break;
154  case 0x3A: // WRITE STREAM DMA
155  case 0x3B: // WRITE STREAM PIO
156  if (CR==0x3A)
157  error_flag[7] = icrc;
158  error_flag[6] = wp;
159  error_flag[5] = mc;
160  error_flag[4] = idnf;
161  error_flag[3] = mcr;
162  error_flag[2] = abrt;
163  error_flag[1] = nm;
164  error_flag[0] = ccto;
165  print_lba=1;
166  print_sector=SC;
167  break;
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;
175  error_flag[6] = unc;
176  error_flag[5] = mc;
177  error_flag[4] = idnf;
178  error_flag[3] = mcr;
179  error_flag[2] = abrt;
180  error_flag[1] = nm;
181  error_flag[0] = amnf;
182  print_lba=1;
183  if (CR==0x25 || CR==0xC8)
184  print_sector=SC;
185  break;
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
192  error_flag[6] = wp;
193  error_flag[5] = mc;
194  error_flag[4] = idnf;
195  error_flag[3] = mcr;
196  error_flag[2] = abrt;
197  error_flag[1] = nm;
198  print_lba=1;
199  break;
200  case 0x32: // WRITE LONG (with retries)
201  case 0x33: // WRITE LONG (without retries)
202  error_flag[4] = idnf;
203  error_flag[2] = abrt;
204  print_lba=1;
205  break;
206  case 0x3C: // WRITE VERIFY
207  error_flag[6] = unc;
208  error_flag[4] = idnf;
209  error_flag[2] = abrt;
210  error_flag[0] = amnf;
211  print_lba=1;
212  break;
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
216  error_flag[6] = unc;
217  error_flag[5] = mc;
218  error_flag[4] = idnf;
219  error_flag[3] = mcr;
220  error_flag[2] = abrt;
221  error_flag[1] = nm;
222  error_flag[0] = amnf;
223  print_lba=1;
224  break;
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
229  * bits is set.
230  */
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;
236  error_flag[1] = eom;
237  error_flag[0] = ili;
238  break;
239  case 0xA1: /* IDENTIFY PACKET DEVICE */
240  case 0xEF: /* SET FEATURES */
241  case 0x00: /* NOP */
242  case 0xC6: /* SET MULTIPLE MODE */
243  error_flag[2] = abrt;
244  break;
245  case 0x2F: // READ LOG EXT
246  error_flag[6] = unc;
247  error_flag[4] = idnf;
248  error_flag[2] = abrt;
249  error_flag[0] = obs;
250  break;
251  case 0x3F: // WRITE LOG EXT
252  error_flag[4] = idnf;
253  error_flag[2] = abrt;
254  error_flag[0] = obs;
255  break;
256  case 0xB0: /* SMART */
257  switch(FR) {
258  case 0xD0: // SMART READ DATA
259  case 0xD1: // SMART READ ATTRIBUTE THRESHOLDS
260  case 0xD5: /* SMART READ LOG */
261  error_flag[6] = unc;
262  error_flag[4] = idnf;
263  error_flag[2] = abrt;
264  error_flag[0] = obs;
265  break;
266  case 0xD6: /* SMART WRITE LOG */
267  error_flag[4] = idnf;
268  error_flag[2] = abrt;
269  error_flag[0] = obs;
270  break;
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;
278  break;
279  case 0xD4: // SMART EXECUTE IMMEDIATE OFFLINE
280  error_flag[4] = idnf;
281  error_flag[2] = abrt;
282  break;
283  default:
284  return str; // ""
285  break;
286  }
287  break;
288  case 0xB1: /* DEVICE CONFIGURATION */
289  switch (FR) {
290  case 0xC0: /* DEVICE CONFIGURATION RESTORE */
291  error_flag[2] = abrt;
292  break;
293  default:
294  return str; // ""
295  break;
296  }
297  break;
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;
307  error_flag[6] = wp;
308  error_flag[5] = mc;
309  error_flag[4] = idnf;
310  error_flag[3] = mcr;
311  error_flag[2] = abrt;
312  error_flag[1] = nm;
313  error_flag[0] = amnf;
314  print_lba=1;
315  if (CR==0x35)
316  print_sector=SC;
317  break;
318  case 0xE4: // READ BUFFER
319  case 0xE8: // WRITE BUFFER
320  error_flag[2] = abrt;
321  break;
322  default:
323  return str; // ""
324  }
325 
326  /* We ignore any status flags other than Device Fault and Error */
327 
328  if (uses_device_fault && (ST & (1 << 5))) {
329  str = "Device Fault";
330  if (ST & 1) // Error flag
331  str += "; ";
332  }
333  if (ST & 1) { // Error flag
334  int count = 0;
335 
336  str += "Error: ";
337  for (i = 7; i >= 0; i--)
338  if ((ER & (1 << i)) && (error_flag[i])) {
339  if (count++ > 0)
340  str += ", ";
341  str += error_flag[i];
342  }
343  }
344 
345  // If the error was a READ or WRITE error, print the Logical Block
346  // Address (LBA) at which the read or write failed.
347  if (print_lba) {
348  // print number of sectors, if known, and append to print string
349  if (print_sector)
350  str += strprintf(" %d sectors", print_sector);
351 
352  if (lba28_regs) {
353  unsigned lba;
354  // bits 24-27: bits 0-3 of DH
355  lba = 0xf & lba28_regs->drive_head;
356  lba <<= 8;
357  // bits 16-23: CH
358  lba |= lba28_regs->cylinder_high;
359  lba <<= 8;
360  // bits 8-15: CL
361  lba |= lba28_regs->cylinder_low;
362  lba <<= 8;
363  // bits 0-7: SN
364  lba |= lba28_regs->sector_number;
365  str += strprintf(" at LBA = 0x%08x = %u", lba, lba);
366  }
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)
370  uint64_t lba48;
371  lba48 = lba48_regs->lba_high_register_hi;
372  lba48 <<= 8;
373  lba48 |= lba48_regs->lba_mid_register_hi;
374  lba48 <<= 8;
375  lba48 |= lba48_regs->lba_low_register_hi;
376  lba48 |= lba48_regs->device_register & 0xf;
377  lba48 <<= 8;
378  lba48 |= lba48_regs->lba_high_register;
379  lba48 <<= 8;
380  lba48 |= lba48_regs->lba_mid_register;
381  lba48 <<= 8;
382  lba48 |= lba48_regs->lba_low_register;
383  str += strprintf(" at LBA = 0x%08" PRIx64 " = %" PRIu64, lba48, lba48);
384  }
385  }
386 
387  return str;
388 }
389 
390 static inline std::string format_st_er_desc(
392 {
393  return format_st_er_desc(
394  data->commands[4].commandreg,
395  data->commands[4].featuresreg,
396  data->error_struct.status,
399  &data->error_struct, (const ata_smart_exterrlog_error *)0);
400 }
401 
402 static inline std::string format_st_er_desc(
404 {
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);
412 }
413 
414 
415 static const char * get_form_factor(unsigned short word168)
416 {
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
419  switch (word168) {
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
429  default : return 0;
430  }
431 }
432 
433 static int find_msb(unsigned short word)
434 {
435  for (int bit = 15; bit >= 0; bit--)
436  if (word & (1 << bit))
437  return bit;
438  return -1;
439 }
440 
441 static const char * get_ata_major_version(const ata_identify_device * drive)
442 {
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";
454  default: return 0;
455  }
456 }
457 
458 static const char * get_ata_minor_version(const ata_identify_device * drive)
459 {
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";
496 
497  case 0x0021: return "ATA/ATAPI-7 T13/1532D revision 4a";
498  case 0x0022: return "ATA/ATAPI-6 published, ANSI INCITS 361-2002";
499 
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";
503 
504  case 0x0031: return "ACS-2 T13/2015-D revision 2";
505 
506  case 0x0033: return "ATA8-ACS T13/1699-D revision 3e";
507 
508  case 0x0039: return "ATA8-ACS T13/1699-D revision 4c";
509 
510  case 0x0042: return "ATA8-ACS T13/1699-D revision 3f";
511 
512  case 0x0052: return "ATA8-ACS T13/1699-D revision 3b";
513 
514  case 0x006d: return "ACS-3 T13/2161-D revision 5";
515 
516  case 0x0082: return "ACS-2 published, ANSI INCITS 482-2012";
517 
518  case 0x0107: return "ATA8-ACS T13/1699-D revision 2d";
519 
520  case 0x0110: return "ACS-2 T13/2015-D revision 3";
521 
522  case 0x011b: return "ACS-3 T13/2161-D revision 4";
523 
524  default: return 0;
525  }
526 }
527 
528 static const char * get_sata_version(const ata_identify_device * drive)
529 {
530  unsigned short word222 = drive->words088_255[222-88];
531  if ((word222 & 0xf000) != 0x1000)
532  return 0;
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";
543  case -1: return 0;
544  }
545 }
546 
547 static const char * get_sata_speed(int level)
548 {
549  if (level <= 0)
550  return 0;
551  switch (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";
556  }
557 }
558 
559 static const char * get_sata_maxspeed(const ata_identify_device * drive)
560 {
561  unsigned short word076 = drive->words047_079[76-47];
562  if (word076 & 0x0001)
563  return 0;
564  return get_sata_speed(find_msb(word076 & 0x00fe));
565 }
566 
567 static const char * get_sata_curspeed(const ata_identify_device * drive)
568 {
569  unsigned short word077 = drive->words047_079[77-47];
570  if (word077 & 0x0001)
571  return 0;
572  return get_sata_speed((word077 >> 1) & 0x7);
573 }
574 
575 
576 static void print_drive_info(const ata_identify_device * drive,
577  const ata_size_info & sizes, int rpm,
578  const drive_settings * dbentry)
579 {
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);
585 
586  // Print model family if known
587  if (dbentry && *dbentry->modelfamily)
588  pout("Model Family: %s\n", dbentry->modelfamily);
589 
590  pout("Device Model: %s\n", infofound(model));
592  pout("Serial Number: %s\n", infofound(serial));
593 
594  unsigned oui = 0; uint64_t unique_id = 0;
595  int naa = ata_get_wwn(drive, oui, unique_id);
596  if (naa >= 0)
597  pout("LU WWN Device Id: %x %06x %09" PRIx64 "\n", naa, oui, unique_id);
598 
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) {
602  char add[8+1];
603  ata_format_id_string(add, (const unsigned char *)(drive->words088_255+170-88), sizeof(add)-1);
604  if (add[0])
605  pout("Add. Product Id: %s\n", add);
606  }
607  }
608  pout("Firmware Version: %s\n", infofound(firmware));
609 
610  if (sizes.capacity) {
611  // Print 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));
616 
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);
620  else {
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);
625  pout("\n");
626  }
627  }
628 
629  // Print nominal media rotation rate if reported
630  if (rpm) {
631  if (rpm == 1)
632  pout("Rotation Rate: Solid State Device\n");
633  else if (rpm > 1)
634  pout("Rotation Rate: %d rpm\n", rpm);
635  else
636  pout("Rotation Rate: Unknown (0x%04x)\n", -rpm);
637  }
638 
639  // Print form factor if reported
640  unsigned short word168 = drive->words088_255[168-88];
641  if (word168) {
642  const char * form_factor = get_form_factor(word168);
643  if (form_factor)
644  pout("Form Factor: %s\n", form_factor);
645  else
646  pout("Form Factor: Unknown (0x%04x)\n", word168);
647  }
648 
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]");
653 
654  // Print ATA version
655  std::string ataver;
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);
660 
661  if (majorver && minorver && str_starts_with(minorver, majorver)) {
662  // Major and minor strings match, print minor string only
663  ataver = minorver;
664  }
665  else {
666  if (majorver)
667  ataver = majorver;
668  else
669  ataver = strprintf("Unknown(0x%04x)", drive->major_rev_num);
670 
671  if (minorver)
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);
675  else
676  ataver += " (minor revision not indicated)";
677  }
678  }
679  pout("ATA Version is: %s\n", infofound(ataver.c_str()));
680 
681  // If SATA drive print SATA version and speed
682  const char * sataver = get_sata_version(drive);
683  if (sataver) {
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 ? ")" : ""));
690  }
691 
692  // print current time and date and timezone
693  char timedatetz[DATEANDEPOCHLEN]; dateandtimezone(timedatetz);
694  pout("Local Time is: %s\n", timedatetz);
695 
696  // Print warning message, if there is one
697  if (dbentry && *dbentry->warningmsg)
698  pout("\n==> WARNING: %s\n\n", dbentry->warningmsg);
699 }
700 
701 static const char *OfflineDataCollectionStatus(unsigned char status_byte)
702 {
703  unsigned char stat=status_byte & 0x7f;
704 
705  switch(stat){
706  case 0x00:
707  return "was never started";
708  case 0x02:
709  return "was completed without error";
710  case 0x03:
711  if (status_byte == 0x03)
712  return "is in progress";
713  else
714  return "is in a Reserved state";
715  case 0x04:
716  return "was suspended by an interrupting command from host";
717  case 0x05:
718  return "was aborted by an interrupting command from host";
719  case 0x06:
720  return "was aborted by the device with a fatal error";
721  default:
722  if (stat >= 0x40)
723  return "is in a Vendor Specific state";
724  else
725  return "is in a Reserved state";
726  }
727 }
728 
729 
730 // prints verbose value Off-line data collection status byte
732 {
733  pout("Offline data collection status: (0x%02x)\t",
734  (int)data->offline_data_collection_status);
735 
736  // Off-line data collection status byte is not a reserved
737  // or vendor specific value
738  pout("Offline data collection activity\n"
740 
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");
745  else
746  pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
747 
748  return;
749 }
750 
752  firmwarebug_defs firmwarebugs)
753 {
754  pout("Self-test execution status: ");
755 
756  switch (data->self_test_exec_status >> 4)
757  {
758  case 0:
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");
762  break;
763  case 1:
764  pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
765  (int)data->self_test_exec_status);
766  pout("the host.\n");
767  break;
768  case 2:
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");
772  break;
773  case 3:
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");
779  pout("routine.\n");
780  break;
781  case 4:
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");
786  break;
787  case 5:
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");
791  pout("failed.\n");
792  break;
793  case 6:
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");
798  break;
799  case 7:
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");
803  break;
804  case 8:
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");
809  pout("damage.\n");
810  break;
811  case 15:
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");
817  }
818  else {
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));
823  }
824  break;
825  default:
826  pout("(%4d)\tReserved.\n",
827  (int)data->self_test_exec_status);
828  break;
829  }
830 
831 }
832 
834 {
835  pout("Total time to complete Offline \n");
836  pout("data collection: \t\t(%5d) seconds.\n",
838 }
839 
841 {
842  pout("Offline data collection\n");
843  pout("capabilities: \t\t\t (0x%02x) ",
845 
846  if (data->offline_data_collection_capability == 0x00){
847  pout("\tOffline data collection not supported.\n");
848  }
849  else {
850  pout( "%s\n", isSupportExecuteOfflineImmediate(data)?
851  "SMART execute Offline immediate." :
852  "No SMART execute Offline immediate.");
853 
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.");
857 
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.");
861 
862  pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data)?
863  "Offline surface scan supported.":
864  "No Offline surface scan supported.");
865 
866  pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data)?
867  "Self-test supported.":
868  "No Self-test supported.");
869 
870  pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data)?
871  "Conveyance Self-test supported.":
872  "No Conveyance Self-test supported.");
873 
874  pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data)?
875  "Selective Self-test supported.":
876  "No Selective Self-test supported.");
877  }
878 }
879 
881 {
882  pout("SMART capabilities: ");
883  pout("(0x%04x)\t", (int)data->smart_capability);
884 
885  if (data->smart_capability == 0x00)
886  {
887  pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
888  }
889  else
890  {
891 
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.");
895 
896  if ( data->smart_capability & 0x02 )
897  {
898  pout("\t\t\t\t\tSupports SMART auto save timer.\n");
899  }
900  }
901 }
902 
904 {
905  pout("Error logging capability: ");
906 
907  if ( isSmartErrorLogCapable(data, identity) )
908  {
909  pout(" (0x%02x)\tError logging supported.\n",
910  (int)data->errorlog_capability);
911  }
912  else {
913  pout(" (0x%02x)\tError logging NOT supported.\n",
914  (int)data->errorlog_capability);
915  }
916 }
917 
919 {
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);
924  else
925  pout("recommended polling time: \t Not Supported.\n");
926 }
927 
929 {
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));
934  else
935  pout("recommended polling time: \t Not Supported.\n");
936 }
937 
939 {
940  pout("Conveyance self-test routine\n");
941  if (isSupportConveyanceSelfTest(data))
942  pout("recommended polling time: \t (%4d) minutes.\n",
944  else
945  pout("recommended polling time: \t Not Supported.\n");
946 }
947 
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
952  const ata_smart_thresholds_pvt * thresholds,
953  const ata_vendor_attr_defs & defs, int onlyfailed)
954 {
955  for (int i = 0; i < NUMBER_ATA_SMART_ATTRIBUTES; i++) {
956  const ata_smart_attribute & attr = data->vendor_attributes[i];
957 
958  ata_attr_state state = ata_get_attr_state(attr, i, thresholds->thres_entries, defs);
959 
960  if (!onlyfailed) {
961  if (state >= ATTRSTATE_FAILED_PAST)
962  return attr.id;
963  }
964  else {
966  return attr.id;
967  }
968  }
969  return 0;
970 }
971 
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
976  const ata_smart_thresholds_pvt * thresholds,
977  const ata_vendor_attr_defs & defs, int rpm,
978  int onlyfailed, unsigned char format)
979 {
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;
984 
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];
988 
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)
993  continue;
994 
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))
997  continue;
998 
999  if (onlyfailed == 2 && state < ATTRSTATE_FAILED_PAST)
1000  continue;
1001 
1002  // print header only if needed
1003  if (needheader) {
1004  if (!onlyfailed) {
1005  pout("SMART Attributes Data Structure revision number: %d\n",(int)data->revnumber);
1006  pout("Vendor Specific SMART Attributes with Thresholds:\n");
1007  }
1008  if (!brief)
1009  pout("ID#%s ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n",
1010  (!hexid ? "" : " "));
1011  else
1012  pout("ID#%s ATTRIBUTE_NAME FLAGS VALUE WORST THRESH FAIL RAW_VALUE\n",
1013  (!hexid ? "" : " "));
1014  needheader = false;
1015  }
1016 
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));
1022  else
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));
1027  else
1028  worstr = (!hexval ? "---" : "----");
1029  if (state > ATTRSTATE_NO_THRESHOLD)
1030  threstr = (!hexval ? strprintf("%.3d", threshold)
1031  : strprintf("0x%02x", threshold));
1032  else
1033  threstr = (!hexval ? "---" : "----");
1034 
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);
1040 
1041  if (!brief)
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"
1049  : " -" ) ,
1050  rawstr.c_str());
1051  else
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"
1064  : "-" ),
1065  rawstr.c_str());
1066 
1067  }
1068 
1069  if (!needheader) {
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, "");
1079  }
1080  pout("\n");
1081  }
1082 }
1083 
1084 // Print SMART related SCT capabilities
1086 {
1087  unsigned short sctcaps = drive->words088_255[206-88];
1088  if (!(sctcaps & 0x01))
1089  return;
1090  pout("SCT capabilities: \t (0x%04x)\tSCT Status supported.\n", sctcaps);
1091  if (sctcaps & 0x08)
1092  pout("\t\t\t\t\tSCT Error Recovery Control supported.\n");
1093  if (sctcaps & 0x10)
1094  pout("\t\t\t\t\tSCT Feature Control supported.\n");
1095  if (sctcaps & 0x20)
1096  pout("\t\t\t\t\tSCT Data Table supported.\n");
1097 }
1098 
1099 
1101  firmwarebug_defs firmwarebugs)
1102 {
1103  pout("General SMART Values:\n");
1104 
1105  PrintSmartOfflineStatus(data);
1106 
1107  if (isSupportSelfTest(data)){
1108  PrintSmartSelfExecStatus(data, firmwarebugs);
1109  }
1110 
1113  PrintSmartCapability(data);
1114 
1115  PrintSmartErrorLogCapability(data, drive);
1116 
1117  pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive)?
1118  "General Purpose Logging supported.":
1119  "No General Purpose Logging support.");
1120 
1121  if (isSupportSelfTest(data)){
1124  }
1125  if (isSupportConveyanceSelfTest(data))
1127 
1128  ataPrintSCTCapability(drive);
1129 
1130  pout("\n");
1131 }
1132 
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)
1135 {
1136  if (!logdir)
1137  return 0;
1138  if (logaddr > 0xff)
1139  return 0;
1140  if (logaddr == 0)
1141  return 1;
1142  unsigned n = logdir->entry[logaddr-1].numsectors;
1143  if (gpl)
1144  // GP logs may have >255 sectors
1145  n |= logdir->entry[logaddr-1].reserved << 8;
1146  return n;
1147 }
1148 
1149 // Get name of log.
1150 static const char * GetLogName(unsigned logaddr)
1151 {
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
1154  switch (logaddr) {
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
1169 
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
1177  case 0x16:
1178  case 0x17: return "Reserved for Serial ATA";
1179 
1180  case 0x19: return "LBA Status log"; // ACS-3
1181 
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
1188 
1189  case 0x30: return "IDENTIFY DEVICE data log"; // ACS-3
1190 
1191  case 0xe0: return "SCT Command/Status";
1192  case 0xe1: return "SCT Data Transfer";
1193  default:
1194  if (0xa0 <= logaddr && logaddr <= 0xdf)
1195  return "Device vendor specific log";
1196  if (0x80 <= logaddr && logaddr <= 0x9f)
1197  return "Host vendor specific log";
1198  return "Reserved";
1199  }
1200  /*NOTREACHED*/
1201 }
1202 
1203 // Get log access permissions
1204 static const char * get_log_rw(unsigned logaddr)
1205 {
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))
1212  return "R/O";
1213 
1214  if ( (0x09 <= logaddr && logaddr <= 0x0a)
1215  || (0x15 == logaddr)
1216  || (0x80 <= logaddr && logaddr <= 0x9f)
1217  || (0xe0 <= logaddr && logaddr <= 0xe1))
1218  return "R/W";
1219 
1220  if (0xa0 <= logaddr && logaddr <= 0xdf)
1221  return "VS"; // Vendor specific
1222 
1223  return "-"; // Unknown/Reserved
1224 }
1225 
1226 // Init a fake log directory, assume that standard logs are supported
1228  const ata_print_options & options)
1229 {
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;
1239  return logdir;
1240 }
1241 
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)
1245 {
1246  if (gplogdir)
1247  pout("General Purpose Log Directory Version %u\n", gplogdir->logversion);
1248  if (smartlogdir)
1249  pout("SMART %sLog Directory Version %u%s\n",
1250  (gplogdir ? " " : ""), smartlogdir->logversion,
1251  (smartlogdir->logversion==1 ? " [multi-sector log support]" : ""));
1252 
1253  pout("Address Access R/W Size Description\n");
1254 
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 );
1259 
1260  if (!(smart_numsect || gp_numsect))
1261  continue; // Log does not exist
1262 
1263  const char * acc; unsigned size;
1264  if (smart_numsect == gp_numsect) {
1265  acc = "GPL,SL"; size = gp_numsect;
1266  }
1267  else if (!smart_numsect) {
1268  acc = "GPL"; size = gp_numsect;
1269  }
1270  else if (!gp_numsect) {
1271  acc = " SL"; size = smart_numsect;
1272  }
1273  else {
1274  acc = 0; size = 0;
1275  }
1276 
1277  unsigned i2 = i;
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 );
1284 
1285  if (!(sn == smart_numsect && gn == gp_numsect))
1286  break;
1287  i2 = j;
1288  }
1289  }
1290 
1291  const char * name = GetLogName(i);
1292  const char * rw = get_log_rw(i);
1293 
1294  if (i2 > i) {
1295  pout("0x%02x-0x%02x %-6s %-3s %5u %s\n", i, i2, acc, rw, size, name);
1296  i = i2;
1297  }
1298  else if (acc)
1299  pout( "0x%02x %-6s %-3s %5u %s\n", i, acc, rw, size, name);
1300  else {
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);
1304  }
1305  }
1306  pout("\n");
1307 }
1308 
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)
1314 {
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 ",
1321  (page * 512) + i,
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));
1329 #undef P
1330  if ((i & 0x1ff) == 0x1f0)
1331  pout("\n");
1332  }
1333 }
1334 
1335 ///////////////////////////////////////////////////////////////////////
1336 // Device statistics (Log 0x04)
1337 
1338 // See Section A.5 of
1339 // ATA/ATAPI Command Set - 3 (ACS-3)
1340 // T13/2161-D Revision 2, February 21, 2012.
1341 
1343 {
1344  short size; // #bytes of value, -1 for signed char
1345  const char * name;
1346 };
1347 
1349  { 2, "List of supported log pages" },
1350  { 0, 0 }
1351 };
1352 
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
1362  { 0, 0 }
1363 };
1364 
1366  { 2, "Free-Fall Statistics" },
1367  { 4, "Number of Free-Fall Events Detected" },
1368  { 4, "Overlimit Shock Events" },
1369  { 0, 0 }
1370 };
1371 
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
1381  { 0, 0 }
1382 };
1383 
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" },
1389  { 0, 0 }
1390 };
1391 
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" },
1407  { 0, 0 }
1408 };
1409 
1411  { 2, "Transport Statistics" },
1412  { 4, "Number of Hardware Resets" },
1413  { 4, "Number of ASR Events" },
1414  { 4, "Number of Interface CRC Errors" },
1415  { 0, 0 }
1416 };
1417 
1419  { 2, "Solid State Device Statistics" },
1420  { 1, "Percentage Used Endurance Indicator" },
1421  { 0, 0 }
1422 };
1423 
1432  devstat_info_0x07
1433 };
1434 
1435 const int num_devstat_infos = sizeof(devstat_infos)/sizeof(devstat_infos[0]);
1436 
1437 static void print_device_statistics_page(const unsigned char * data, int page,
1438  bool & need_trailer)
1439 {
1440  const devstat_entry_info * info = (page < num_devstat_infos ? devstat_infos[page] : 0);
1441  const char * name = (info ? info[0].name : "Unknown Statistics");
1442 
1443  // Check page number in header
1444  static const char line[] = " ===== = = == ";
1445  if (!data[2]) {
1446  pout("%3d%s%s (empty) ==\n", page, line, name);
1447  return;
1448  }
1449  if (data[2] != page) {
1450  pout("%3d%s%s (invalid page %d in header) ==\n", page, line, name, data[2]);
1451  return;
1452  }
1453 
1454  pout("%3d%s%s (rev %d) ==\n", page, line, name, data[0]);
1455 
1456  // Print entries
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)
1460  info = 0;
1461 
1462  // Skip unsupported entries
1463  unsigned char flags = data[offset+7];
1464  if (!(flags & 0x80))
1465  continue;
1466 
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);
1470  break;
1471  }
1472 
1473  // Get value size, default to max if unknown
1474  int size = (info ? info[i].size : 7);
1475 
1476  // Format value
1477  char valstr[32];
1478  if (flags & 0x40) { // valid flag
1479  // Get value
1480  int64_t val;
1481  if (size < 0) {
1482  val = (signed char)data[offset];
1483  }
1484  else {
1485  val = 0;
1486  for (int j = 0; j < size; j++)
1487  val |= (int64_t)data[offset+j] << (j*8);
1488  }
1489  snprintf(valstr, sizeof(valstr), "%" PRId64, val);
1490  }
1491  else {
1492  // Value not known (yet)
1493  valstr[0] = '-'; valstr[1] = 0;
1494  }
1495 
1496  pout("%3d 0x%03x %d%c %15s%c %s\n",
1497  page, offset,
1498  abs(size),
1499  (flags & 0x1f ? '+' : ' '), // unknown flags
1500  valstr,
1501  (flags & 0x20 ? '~' : ' '), // normalized flag
1502  (info ? info[i].name : "Unknown"));
1503  if (flags & 0x20)
1504  need_trailer = true;
1505  }
1506 }
1507 
1508 static bool print_device_statistics(ata_device * device, unsigned nsectors,
1509  const std::vector<int> & single_pages, bool all_pages, bool ssd_page,
1510  bool use_gplog)
1511 {
1512  // Read list of supported pages from page 0
1513  unsigned char page_0[512] = {0, };
1514  int rc;
1515 
1516  if (use_gplog)
1517  rc = ataReadLogExt(device, 0x04, 0, 0, page_0, 1);
1518  else
1519  rc = ataReadSmartLog(device, 0x04, page_0, 1);
1520  if (!rc) {
1521  pout("Read Device Statistics page 0 failed\n\n");
1522  return false;
1523  }
1524 
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);
1528  return false;
1529  }
1530 
1531  // Prepare list of pages to print
1532  std::vector<int> pages;
1533  unsigned i;
1534  if (all_pages) {
1535  // Add all supported pages
1536  for (i = 0; i < nentries; i++) {
1537  int page = page_0[8+1+i];
1538  if (page)
1539  pages.push_back(page);
1540  }
1541  ssd_page = false;
1542  }
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);
1547  if (!page)
1548  print_page_0 = true;
1549  else if (page >= (int)nsectors)
1550  pout("Device Statistics Log has only %u pages\n", nsectors);
1551  else
1552  pages.push_back(page);
1553  if (page == 7)
1554  ssd_page = false;
1555  }
1556 
1557  // Print list of supported pages if requested
1558  if (print_page_0) {
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"));
1566  }
1567  pout("\n");
1568  }
1569 
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;
1576  int max_page = 0;
1577 
1578  if (!use_gplog)
1579  for (i = 0; i < pages.size(); i++) {
1580  int page = pages[i];
1581  if (max_page < page && page < 0xff)
1582  max_page = page;
1583  }
1584 
1585  raw_buffer pages_buf((max_page+1) * 512);
1586 
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);
1589  return false;
1590  }
1591 
1592  for (i = 0; i < pages.size(); i++) {
1593  int page = pages[i];
1594  if (use_gplog) {
1595  if (!ataReadLogExt(device, 0x04, 0, page, pages_buf.data(), 1)) {
1596  pout("Read Device Statistics page %d failed\n\n", page);
1597  return false;
1598  }
1599  }
1600  else if (page > max_page)
1601  continue;
1602 
1603  int offset = (use_gplog ? 0 : page * 512);
1604  print_device_statistics_page(pages_buf.data() + offset, page, need_trailer);
1605  }
1606 
1607  if (need_trailer)
1608  pout("%30s|_ ~ normalized value\n", "");
1609  pout("\n");
1610  }
1611 
1612  return true;
1613 }
1614 
1615 
1616 ///////////////////////////////////////////////////////////////////////
1617 
1618 // Print log 0x11
1619 static void PrintSataPhyEventCounters(const unsigned char * data, bool reset)
1620 {
1621  if (checksum(data))
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");
1628 
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;
1633  id &= 0x8fff;
1634 
1635  // End of counter table ?
1636  if (!id)
1637  break;
1638  i += 2;
1639 
1640  if (!(2 <= size && size <= 8 && i + size < 512)) {
1641  pout("0x%04x %u: Invalid entry\n", id, size);
1642  break;
1643  }
1644 
1645  // Get value
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);
1650  }
1651  i += size;
1652 
1653  // Get name
1654  const char * name;
1655  switch (id) {
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;
1673  }
1674 
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);
1678  }
1679  if (reset)
1680  pout("All counters reset\n");
1681  pout("\n");
1682 }
1683 
1684 // Format milliseconds from error log entry as "DAYS+H:M:S.MSEC"
1685 static std::string format_milliseconds(unsigned msec)
1686 {
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;
1695 
1696  std::string str;
1697  if (days)
1698  str = strprintf("%2ud+", days);
1699  str += strprintf("%02u:%02u:%02u.%03u", hours, min, sec, msec);
1700  return str;
1701 }
1702 
1703 // Get description for 'state' value from SMART Error Logs
1704 static const char * get_error_log_state_desc(unsigned state)
1705 {
1706  state &= 0x0f;
1707  switch (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";
1713  default:
1714  return (state < 0xb ? "in a reserved state"
1715  : "in a vendor specific state");
1716  }
1717 }
1718 
1719 // returns number of errors
1721  firmwarebug_defs firmwarebugs)
1722 {
1723  pout("SMART Error Log Version: %d\n", (int)data->revnumber);
1724 
1725  // if no errors logged, return
1726  if (!data->error_log_pointer){
1727  pout("No Errors Logged\n\n");
1728  return 0;
1729  }
1730  print_on();
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);
1736  return 0;
1737  }
1738 
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);
1743  }
1744 
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);
1748  else
1749  pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1750  (int)data->ata_error_count);
1751  print_off();
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");
1765 
1766  // now step through the five error log data structures (table 39 of spec)
1767  for (int k = 4; k >= 0; k-- ) {
1768 
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);
1773 
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;
1779 
1780  // See table 42 of ATA5 spec
1781  print_on();
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));
1784  print_off();
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
1798  // if possible
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());
1802  pout("\n\n");
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;
1808 
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));
1822  }
1823  }
1824  pout("\n");
1825  }
1826  }
1827  print_on();
1829  pout("\n");
1830  print_off();
1831  return data->ata_error_count;
1832 }
1833 
1834 // Print SMART Extended Comprehensive Error Log (GP Log 0x03)
1835 static int PrintSmartExtErrorLog(ata_device * device,
1836  const firmwarebug_defs & firmwarebugs,
1837  const ata_smart_exterrlog * log,
1838  unsigned nsectors, unsigned max_errors)
1839 {
1840  pout("SMART Extended Comprehensive Error Log Version: %u (%u sectors)\n",
1841  log->version, nsectors);
1842 
1843  if (!log->device_error_count) {
1844  pout("No Errors Logged\n\n");
1845  return 0;
1846  }
1847  print_on();
1848 
1849  // Check index
1850  unsigned nentries = nsectors * 4;
1851  unsigned erridx = log->error_log_index;
1852  if (!(1 <= erridx && erridx <= nentries)){
1853  // Some Samsung disks (at least SP1614C/SW100-25, HD300LJ/ZT100-12) use the
1854  // former index from Summary Error Log (byte 1, now reserved) and set byte 2-3
1855  // to 0.
1856  if (!(erridx == 0 && 1 <= log->reserved1 && log->reserved1 <= nentries)) {
1857  pout("Invalid Error Log index = 0x%04x (reserved = 0x%02x)\n", erridx, log->reserved1);
1858  return 0;
1859  }
1860  pout("Invalid Error Log index = 0x%04x, trying reserved byte (0x%02x) instead\n", erridx, log->reserved1);
1861  erridx = log->reserved1;
1862  }
1863 
1864  // Index base is not clearly specified by ATA8-ACS (T13/1699-D Revision 6a),
1865  // it is 1-based in practice.
1866  erridx--;
1867 
1868  // Calculate #errors to print
1869  unsigned errcnt = log->device_error_count;
1870 
1871  if (errcnt <= nentries)
1872  pout("Device Error Count: %u\n", log->device_error_count);
1873  else {
1874  errcnt = nentries;
1875  pout("Device Error Count: %u (device log contains only the most recent %u errors)\n",
1876  log->device_error_count, errcnt);
1877  }
1878 
1879  if (max_errors < errcnt)
1880  errcnt = max_errors;
1881 
1882  print_off();
1883  pout("\tCR = Command Register\n"
1884  "\tFEATR = Features Register\n"
1885  "\tCOUNT = Count (was: Sector Count) Register\n"
1886  "\tLBA_48 = Upper bytes of LBA High/Mid/Low Registers ] ATA-8\n"
1887  "\tLH = LBA High (was: Cylinder High) Register ] LBA\n"
1888  "\tLM = LBA Mid (was: Cylinder Low) Register ] Register\n"
1889  "\tLL = LBA Low (was: Sector Number) Register ]\n"
1890  "\tDV = Device (was: Device/Head) Register\n"
1891  "\tDC = Device Control Register\n"
1892  "\tER = Error register\n"
1893  "\tST = Status register\n"
1894  "Powered_Up_Time is measured from power on, and printed as\n"
1895  "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1896  "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1897 
1898  // Recently read log page
1899  ata_smart_exterrlog log_buf;
1900  unsigned log_buf_page = ~0;
1901 
1902  // Iterate through circular buffer in reverse direction
1903  for (unsigned i = 0, errnum = log->device_error_count;
1904  i < errcnt; i++, errnum--, erridx = (erridx > 0 ? erridx - 1 : nentries - 1)) {
1905 
1906  // Read log page if needed
1907  const ata_smart_exterrlog * log_p;
1908  unsigned page = erridx / 4;
1909  if (page == 0)
1910  log_p = log;
1911  else {
1912  if (page != log_buf_page) {
1913  memset(&log_buf, 0, sizeof(log_buf));
1914  if (!ataReadExtErrorLog(device, &log_buf, page, 1, firmwarebugs))
1915  break;
1916  log_buf_page = page;
1917  }
1918  log_p = &log_buf;
1919  }
1920 
1921  const ata_smart_exterrlog_error_log & entry = log_p->error_logs[erridx % 4];
1922 
1923  // Skip unused entries
1924  if (!nonempty(&entry, sizeof(entry))) {
1925  pout("Error %u [%u] log entry is empty\n", errnum, erridx);
1926  continue;
1927  }
1928 
1929  // Print error information
1930  print_on();
1931  const ata_smart_exterrlog_error & err = entry.error;
1932  pout("Error %u [%u] occurred at disk power-on lifetime: %u hours (%u days + %u hours)\n",
1933  errnum, erridx, err.timestamp, err.timestamp / 24, err.timestamp % 24);
1934  print_off();
1935 
1936  pout(" When the command that caused the error occurred, the device was %s.\n\n",
1938 
1939  // Print registers
1940  pout(" After command completion occurred, registers were:\n"
1941  " ER -- ST COUNT LBA_48 LH LM LL DV DC\n"
1942  " -- -- -- == -- == == == -- -- -- -- --\n"
1943  " %02x -- %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
1944  err.error_register,
1945  err.status_register,
1946  err.count_register_hi,
1947  err.count_register,
1949  err.lba_mid_register_hi,
1950  err.lba_low_register_hi,
1951  err.lba_high_register,
1952  err.lba_mid_register,
1953  err.lba_low_register,
1954  err.device_register,
1956 
1957  // Add a description of the contents of the status and error registers
1958  // if possible
1959  std::string st_er_desc = format_st_er_desc(&entry);
1960  if (!st_er_desc.empty())
1961  pout(" %s", st_er_desc.c_str());
1962  pout("\n\n");
1963 
1964  // Print command history
1965  pout(" Commands leading to the command that caused the error were:\n"
1966  " CR FEATR COUNT LBA_48 LH LM LL DV DC Powered_Up_Time Command/Feature_Name\n"
1967  " -- == -- == -- == == == -- -- -- -- -- --------------- --------------------\n");
1968  for (int ci = 4; ci >= 0; ci--) {
1969  const ata_smart_exterrlog_command & cmd = entry.commands[ci];
1970 
1971  // Skip unused entries
1972  if (!nonempty(&cmd, sizeof(cmd)))
1973  continue;
1974 
1975  // Print registers, timestamp and ATA command name
1976  pout(" %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1977  cmd.command_register,
1979  cmd.features_register,
1980  cmd.count_register_hi,
1981  cmd.count_register,
1983  cmd.lba_mid_register_hi,
1984  cmd.lba_low_register_hi,
1985  cmd.lba_high_register,
1986  cmd.lba_mid_register,
1987  cmd.lba_low_register,
1988  cmd.device_register,
1990  format_milliseconds(cmd.timestamp).c_str(),
1992  }
1993  pout("\n");
1994  }
1995 
1996  print_on();
1998  pout("\n");
1999  print_off();
2000  return log->device_error_count;
2001 }
2002 
2003 // Print SMART Extended Self-test Log (GP Log 0x07)
2005  unsigned nsectors, unsigned max_entries)
2006 {
2007  pout("SMART Extended Self-test Log Version: %u (%u sectors)\n",
2008  log->version, nsectors);
2009 
2010  if (!log->log_desc_index){
2011  pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
2012  return 0;
2013  }
2014 
2015  // Check index
2016  unsigned nentries = nsectors * 19;
2017  unsigned logidx = log->log_desc_index;
2018  if (logidx > nentries) {
2019  pout("Invalid Self-test Log index = 0x%04x (reserved = 0x%02x)\n", logidx, log->reserved1);
2020  return 0;
2021  }
2022 
2023  // Index base is not clearly specified by ATA8-ACS (T13/1699-D Revision 6a),
2024  // it is 1-based in practice.
2025  logidx--;
2026 
2027  bool print_header = true;
2028  int errcnt = 0, igncnt = 0;
2029  int ext_ok_testnum = -1;
2030 
2031  // Iterate through circular buffer in reverse direction
2032  for (unsigned i = 0, testnum = 1;
2033  i < nentries && testnum <= max_entries;
2034  i++, logidx = (logidx > 0 ? logidx - 1 : nentries - 1)) {
2035 
2036  const ata_smart_extselftestlog_desc & entry = log[logidx / 19].log_descs[logidx % 19];
2037 
2038  // Skip unused entries
2039  if (!nonempty(&entry, sizeof(entry)))
2040  continue;
2041 
2042  // Get LBA
2043  const unsigned char * b = entry.failing_lba;
2044  uint64_t lba48 = b[0]
2045  | ( b[1] << 8)
2046  | ( b[2] << 16)
2047  | ((uint64_t)b[3] << 24)
2048  | ((uint64_t)b[4] << 32)
2049  | ((uint64_t)b[5] << 40);
2050 
2051  // Print entry
2052  int state = ataPrintSmartSelfTestEntry(testnum, entry.self_test_type,
2053  entry.self_test_status, entry.timestamp, lba48,
2054  false /*!print_error_only*/, print_header);
2055 
2056  if (state < 0) {
2057  // Self-test showed an error
2058  if (ext_ok_testnum < 0)
2059  errcnt++;
2060  else
2061  // Newer successful extended self-test exits
2062  igncnt++;
2063  }
2064  else if (state > 0 && ext_ok_testnum < 0) {
2065  // Latest successful extended self-test
2066  ext_ok_testnum = testnum;
2067  }
2068  testnum++;
2069  }
2070 
2071  if (igncnt)
2072  pout("%d of %d failed self-tests are outdated by newer successful extended offline self-test #%2d\n",
2073  igncnt, igncnt+errcnt, ext_ok_testnum);
2074 
2075  pout("\n");
2076  return errcnt;
2077 }
2078 
2080 {
2081  int i,field1,field2;
2082  const char *msg;
2083  char tmp[64];
2084  uint64_t maxl=0,maxr=0;
2085  uint64_t current=log->currentlba;
2086  uint64_t currentend=current+65535;
2087 
2088  // print data structure revision number
2089  pout("SMART Selective self-test log data structure revision number %d\n",(int)log->logversion);
2090  if (1 != log->logversion)
2091  pout("Note: revision number not 1 implies that no selective self-test has ever been run\n");
2092 
2093  switch((sv->self_test_exec_status)>>4){
2094  case 0:msg="Completed";
2095  break;
2096  case 1:msg="Aborted_by_host";
2097  break;
2098  case 2:msg="Interrupted";
2099  break;
2100  case 3:msg="Fatal_error";
2101  break;
2102  case 4:msg="Completed_unknown_failure";
2103  break;
2104  case 5:msg="Completed_electrical_failure";
2105  break;
2106  case 6:msg="Completed_servo/seek_failure";
2107  break;
2108  case 7:msg="Completed_read_failure";
2109  break;
2110  case 8:msg="Completed_handling_damage??";
2111  break;
2112  case 15:msg="Self_test_in_progress";
2113  break;
2114  default:msg="Unknown_status ";
2115  break;
2116  }
2117 
2118  // find the number of columns needed for printing. If in use, the
2119  // start/end of span being read-scanned...
2120  if (log->currentspan>5) {
2121  maxl=current;
2122  maxr=currentend;
2123  }
2124  for (i=0; i<5; i++) {
2125  uint64_t start=log->span[i].start;
2126  uint64_t end =log->span[i].end;
2127  // ... plus max start/end of each of the five test spans.
2128  if (start>maxl)
2129  maxl=start;
2130  if (end > maxr)
2131  maxr=end;
2132  }
2133 
2134  // we need at least 7 characters wide fields to accomodate the
2135  // labels
2136  if ((field1=snprintf(tmp,64, "%" PRIu64, maxl))<7)
2137  field1=7;
2138  if ((field2=snprintf(tmp,64, "%" PRIu64, maxr))<7)
2139  field2=7;
2140 
2141  // now print the five test spans
2142  pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1, "MIN_LBA", field2, "MAX_LBA");
2143 
2144  for (i=0; i<5; i++) {
2145  uint64_t start=log->span[i].start;
2146  uint64_t end=log->span[i].end;
2147 
2148  if ((i+1)==(int)log->currentspan)
2149  // this span is currently under test
2150  pout(" %d %*" PRIu64 " %*" PRIu64 " %s [%01d0%% left] (%" PRIu64 "-%" PRIu64 ")\n",
2151  i+1, field1, start, field2, end, msg,
2152  (int)(sv->self_test_exec_status & 0xf), current, currentend);
2153  else
2154  // this span is not currently under test
2155  pout(" %d %*" PRIu64 " %*" PRIu64 " Not_testing\n",
2156  i+1, field1, start, field2, end);
2157  }
2158 
2159  // if we are currently read-scanning, print LBAs and the status of
2160  // the read scan
2161  if (log->currentspan>5)
2162  pout("%5d %*" PRIu64 " %*" PRIu64 " Read_scanning %s\n",
2163  (int)log->currentspan, field1, current, field2, currentend,
2165 
2166  /* Print selective self-test flags. Possible flag combinations are
2167  (numbering bits from 0-15):
2168  Bit-1 Bit-3 Bit-4
2169  Scan Pending Active
2170  0 * * Don't scan
2171  1 0 0 Will carry out scan after selective test
2172  1 1 0 Waiting to carry out scan after powerup
2173  1 0 1 Currently scanning
2174  1 1 1 Currently scanning
2175  */
2176 
2177  pout("Selective self-test flags (0x%x):\n", (unsigned int)log->flags);
2178  if (log->flags & SELECTIVE_FLAG_DOSCAN) {
2179  if (log->flags & SELECTIVE_FLAG_ACTIVE)
2180  pout(" Currently read-scanning the remainder of the disk.\n");
2181  else if (log->flags & SELECTIVE_FLAG_PENDING)
2182  pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
2183  (int)log->pendingtime);
2184  else
2185  pout(" After scanning selected spans, read-scan remainder of disk.\n");
2186  }
2187  else
2188  pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
2189 
2190  // print pending time
2191  pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
2192  (int)log->pendingtime);
2193 
2194  return;
2195 }
2196 
2197 // Format SCT Temperature value
2198 static const char * sct_ptemp(signed char x, char (& buf)[20])
2199 {
2200  if (x == -128 /*0x80 = unknown*/)
2201  return " ?";
2202  snprintf(buf, sizeof(buf), "%2d", x);
2203  return buf;
2204 }
2205 
2206 static const char * sct_pbar(int x, char (& buf)[64])
2207 {
2208  if (x <= 19)
2209  x = 0;
2210  else
2211  x -= 19;
2212  bool ov = false;
2213  if (x > 40) {
2214  x = 40; ov = true;
2215  }
2216  if (x > 0) {
2217  memset(buf, '*', x);
2218  if (ov)
2219  buf[x-1] = '+';
2220  buf[x] = 0;
2221  }
2222  else {
2223  buf[0] = '-'; buf[1] = 0;
2224  }
2225  return buf;
2226 }
2227 
2228 static const char * sct_device_state_msg(unsigned char state)
2229 {
2230  switch (state) {
2231  case 0: return "Active";
2232  case 1: return "Stand-by";
2233  case 2: return "Sleep";
2234  case 3: return "DST executing in background";
2235  case 4: return "SMART Off-line Data Collection executing in background";
2236  case 5: return "SCT command executing in background";
2237  default:return "Unknown";
2238  }
2239 }
2240 
2241 // Print SCT Status
2243 {
2244  pout("SCT Status Version: %u\n", sts->format_version);
2245  pout("SCT Version (vendor specific): %u (0x%04x)\n", sts->sct_version, sts->sct_version);
2246  pout("SCT Support Level: %u\n", sts->sct_spec);
2247  pout("Device State: %s (%u)\n",
2249  char buf1[20], buf2[20];
2250  if ( !sts->min_temp && !sts->life_min_temp
2251  && !sts->under_limit_count && !sts->over_limit_count) {
2252  // "Reserved" fields not set, assume "old" format version 2
2253  // Table 11 of T13/1701DT-N (SMART Command Transport) Revision 5, February 2005
2254  // Table 54 of T13/1699-D (ATA8-ACS) Revision 3e, July 2006
2255  pout("Current Temperature: %s Celsius\n",
2256  sct_ptemp(sts->hda_temp, buf1));
2257  pout("Power Cycle Max Temperature: %s Celsius\n",
2258  sct_ptemp(sts->max_temp, buf2));
2259  pout("Lifetime Max Temperature: %s Celsius\n",
2260  sct_ptemp(sts->life_max_temp, buf2));
2261  }
2262  else {
2263  // Assume "new" format version 2 or version 3
2264  // T13/e06152r0-3 (Additional SCT Temperature Statistics), August - October 2006
2265  // Table 60 of T13/1699-D (ATA8-ACS) Revision 3f, December 2006 (format version 2)
2266  // Table 80 of T13/1699-D (ATA8-ACS) Revision 6a, September 2008 (format version 3)
2267  // Table 182 of T13/BSR INCITS 529 (ACS-4) Revision 02a, May 22, 2014 (smart_status field)
2268  pout("Current Temperature: %s Celsius\n",
2269  sct_ptemp(sts->hda_temp, buf1));
2270  pout("Power Cycle Min/Max Temperature: %s/%s Celsius\n",
2271  sct_ptemp(sts->min_temp, buf1), sct_ptemp(sts->max_temp, buf2));
2272  pout("Lifetime Min/Max Temperature: %s/%s Celsius\n",
2273  sct_ptemp(sts->life_min_temp, buf1), sct_ptemp(sts->life_max_temp, buf2));
2274  signed char avg = sts->byte205; // Average Temperature from e06152r0-2, removed in e06152r3
2275  if (0 < avg && sts->life_min_temp <= avg && avg <= sts->life_max_temp)
2276  pout("Lifetime Average Temperature: %2d Celsius\n", avg);
2277  pout("Under/Over Temperature Limit Count: %2u/%u\n",
2278  sts->under_limit_count, sts->over_limit_count);
2279 
2280  if (sts->smart_status) // ACS-4
2281  pout("SMART Status: 0x%04x (%s)\n", sts->smart_status,
2282  (sts->smart_status == 0x2cf4 ? "FAILED" :
2283  sts->smart_status == 0xc24f ? "PASSED" : "Reserved"));
2284 
2285  if (nonempty(sts->vendor_specific, sizeof(sts->vendor_specific))) {
2286  pout("Vendor specific:\n");
2287  for (unsigned i = 0; i < sizeof(sts->vendor_specific); i++)
2288  pout("%02x%c", sts->vendor_specific[i], ((i & 0xf) != 0xf ? ' ' : '\n'));
2289  }
2290  }
2291  return 0;
2292 }
2293 
2294 // Print SCT Temperature History Table
2296 {
2297  char buf1[20], buf2[20], buf3[64];
2298  pout("SCT Temperature History Version: %u%s\n", tmh->format_version,
2299  (tmh->format_version != 2 ? " (Unknown, should be 2)" : ""));
2300  pout("Temperature Sampling Period: %u minute%s\n",
2301  tmh->sampling_period, (tmh->sampling_period==1?"":"s"));
2302  pout("Temperature Logging Interval: %u minute%s\n",
2303  tmh->interval, (tmh->interval==1?"":"s"));
2304  pout("Min/Max recommended Temperature: %s/%s Celsius\n",
2305  sct_ptemp(tmh->min_op_limit, buf1), sct_ptemp(tmh->max_op_limit, buf2));
2306  pout("Min/Max Temperature Limit: %s/%s Celsius\n",
2307  sct_ptemp(tmh->under_limit, buf1), sct_ptemp(tmh->over_limit, buf2));
2308  pout("Temperature History Size (Index): %u (%u)\n", tmh->cb_size, tmh->cb_index);
2309 
2310  if (!(0 < tmh->cb_size && tmh->cb_size <= sizeof(tmh->cb) && tmh->cb_index < tmh->cb_size)) {
2311  if (!tmh->cb_size)
2312  pout("Temperature History is empty\n");
2313  else
2314  pout("Invalid Temperature History Size or Index\n");
2315  return 0;
2316  }
2317 
2318  // Print table
2319  pout("\nIndex Estimated Time Temperature Celsius\n");
2320  unsigned n = 0, i = (tmh->cb_index+1) % tmh->cb_size;
2321  unsigned interval = (tmh->interval > 0 ? tmh->interval : 1);
2322  time_t t = time(0) - (tmh->cb_size-1) * interval * 60;
2323  t -= t % (interval * 60);
2324  while (n < tmh->cb_size) {
2325  // Find range of identical temperatures
2326  unsigned n1 = n, n2 = n+1, i2 = (i+1) % tmh->cb_size;
2327  while (n2 < tmh->cb_size && tmh->cb[i2] == tmh->cb[i]) {
2328  n2++; i2 = (i2+1) % tmh->cb_size;
2329  }
2330  // Print range
2331  while (n < n2) {
2332  if (n == n1 || n == n2-1 || n2 <= n1+3) {
2333  char date[30];
2334  // TODO: Don't print times < boot time
2335  strftime(date, sizeof(date), "%Y-%m-%d %H:%M", localtime(&t));
2336  pout(" %3u %s %s %s\n", i, date,
2337  sct_ptemp(tmh->cb[i], buf1), sct_pbar(tmh->cb[i], buf3));
2338  }
2339  else if (n == n1+1) {
2340  pout(" ... ..(%3u skipped). .. %s\n",
2341  n2-n1-2, sct_pbar(tmh->cb[i], buf3));
2342  }
2343  t += interval * 60; i = (i+1) % tmh->cb_size; n++;
2344  }
2345  }
2346  //assert(n == tmh->cb_size && i == (tmh->cb_index+1) % tmh->cb_size);
2347 
2348  return 0;
2349 }
2350 
2351 // Print SCT Error Recovery Control timers
2352 static void ataPrintSCTErrorRecoveryControl(bool set, unsigned short read_timer, unsigned short write_timer)
2353 {
2354  pout("SCT Error Recovery Control%s:\n", (set ? " set to" : ""));
2355  if (!read_timer)
2356  pout(" Read: Disabled\n");
2357  else
2358  pout(" Read: %6d (%0.1f seconds)\n", read_timer, read_timer/10.0);
2359  if (!write_timer)
2360  pout(" Write: Disabled\n");
2361  else
2362  pout(" Write: %6d (%0.1f seconds)\n", write_timer, write_timer/10.0);
2363 }
2364 
2365 static void print_aam_level(const char * msg, int level, int recommended = -1)
2366 {
2367  // Table 56 of T13/1699-D (ATA8-ACS) Revision 6a, September 6, 2008
2368  // Obsolete since T13/2015-D (ACS-2) Revision 4a, December 9, 2010
2369  const char * s;
2370  if (level == 0)
2371  s = "vendor specific";
2372  else if (level < 128)
2373  s = "unknown/retired";
2374  else if (level == 128)
2375  s = "quiet";
2376  else if (level < 254)
2377  s = "intermediate";
2378  else if (level == 254)
2379  s = "maximum performance";
2380  else
2381  s = "reserved";
2382 
2383  if (recommended >= 0)
2384  pout("%s%d (%s), recommended: %d\n", msg, level, s, recommended);
2385  else
2386  pout("%s%d (%s)\n", msg, level, s);
2387 }
2388 
2389 static void print_apm_level(const char * msg, int level)
2390 {
2391  // Table 120 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2392  const char * s;
2393  if (!(1 <= level && level <= 254))
2394  s = "reserved";
2395  else if (level == 1)
2396  s = "minimum power consumption with standby";
2397  else if (level < 128)
2398  s = "intermediate level with standby";
2399  else if (level == 128)
2400  s = "minimum power consumption without standby";
2401  else if (level < 254)
2402  s = "intermediate level without standby";
2403  else
2404  s = "maximum performance";
2405 
2406  pout("%s%d (%s)\n", msg, level, s);
2407 }
2408 
2409 static void print_ata_security_status(const char * msg, unsigned short state)
2410 {
2411  const char * s1, * s2 = "", * s3 = "", * s4 = "";
2412 
2413  // Table 6 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2414  if (!(state & 0x0001))
2415  s1 = "Unavailable";
2416  else if (!(state & 0x0002)) {
2417  s1 = "Disabled, ";
2418  if (!(state & 0x0008))
2419  s2 = "NOT FROZEN [SEC1]";
2420  else
2421  s2 = "frozen [SEC2]";
2422  }
2423  else {
2424  s1 = "ENABLED, PW level ";
2425  if (!(state & 0x0020))
2426  s2 = "HIGH";
2427  else
2428  s2 = "MAX";
2429 
2430  if (!(state & 0x0004)) {
2431  s3 = ", not locked, ";
2432  if (!(state & 0x0008))
2433  s4 = "not frozen [SEC5]";
2434  else
2435  s4 = "frozen [SEC6]";
2436  }
2437  else {
2438  s3 = ", **LOCKED** [SEC4]";
2439  if (state & 0x0010)
2440  s4 = ", PW ATTEMPTS EXCEEDED";
2441  }
2442  }
2443 
2444  pout("%s%s%s%s%s\n", msg, s1, s2, s3, s4);
2445 }
2446 
2447 static void print_standby_timer(const char * msg, int timer, const ata_identify_device & drive)
2448 {
2449  const char * s1 = 0;
2450  int hours = 0, minutes = 0 , seconds = 0;
2451 
2452  // Table 63 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
2453  if (timer == 0)
2454  s1 = "disabled";
2455  else if (timer <= 240)
2456  seconds = timer * 5, minutes = seconds / 60, seconds %= 60;
2457  else if (timer <= 251)
2458  minutes = (timer - 240) * 30, hours = minutes / 60, minutes %= 60;
2459  else if (timer == 252)
2460  minutes = 21;
2461  else if (timer == 253)
2462  s1 = "between 8 hours and 12 hours";
2463  else if (timer == 255)
2464  minutes = 21, seconds = 15;
2465  else
2466  s1 = "reserved";
2467 
2468  const char * s2 = "", * s3 = "";
2469  if (!(drive.words047_079[49-47] & 0x2000))
2470  s2 = " or vendor-specific";
2471  if (timer > 0 && (drive.words047_079[50-47] & 0xc001) == 0x4001)
2472  s3 = ", a vendor-specific minimum applies";
2473 
2474  if (s1)
2475  pout("%s%d (%s%s%s)\n", msg, timer, s1, s2, s3);
2476  else
2477  pout("%s%d (%02d:%02d:%02d%s%s)\n", msg, timer, hours, minutes, seconds, s2, s3);
2478 }
2479 
2480 
2481 int ataPrintMain (ata_device * device, const ata_print_options & options)
2482 {
2483  // If requested, check power mode first
2484  const char * powername = 0;
2485  bool powerchg = false;
2486  if (options.powermode) {
2487  unsigned char powerlimit = 0xff;
2488  int powermode = ataCheckPowerMode(device);
2489  switch (powermode) {
2490  case -1:
2491  if (device->is_syscall_unsup()) {
2492  pout("CHECK POWER MODE not implemented, ignoring -n option\n"); break;
2493  }
2494  powername = "SLEEP"; powerlimit = 2;
2495  break;
2496  case 0:
2497  powername = "STANDBY"; powerlimit = 3; break;
2498  case 0x80:
2499  powername = "IDLE"; powerlimit = 4; break;
2500  case 0xff:
2501  powername = "ACTIVE or IDLE"; break;
2502  default:
2503  pout("CHECK POWER MODE returned unknown value 0x%02x, ignoring -n option\n", powermode);
2504  break;
2505  }
2506  if (powername) {
2507  if (options.powermode >= powerlimit) {
2508  pout("Device is in %s mode, exit(%d)\n", powername, FAILPOWER);
2509  return FAILPOWER;
2510  }
2511  powerchg = (powermode != 0xff); // SMART tests will spin up drives
2512  }
2513  }
2514 
2515  // SMART values needed ?
2516  bool need_smart_val = (
2517  options.smart_check_status
2518  || options.smart_general_values
2519  || options.smart_vendor_attrib
2520  || options.smart_error_log
2521  || options.smart_selftest_log
2522  || options.smart_selective_selftest_log
2523  || options.smart_ext_error_log
2524  || options.smart_ext_selftest_log
2525  || options.smart_auto_offl_enable
2526  || options.smart_auto_offl_disable
2527  || options.smart_selftest_type != -1
2528  );
2529 
2530  // SMART must be enabled ?
2531  bool need_smart_enabled = (
2532  need_smart_val
2533  || options.smart_auto_save_enable
2534  || options.smart_auto_save_disable
2535  );
2536 
2537  // SMART feature set needed ?
2538  bool need_smart_support = (
2539  need_smart_enabled
2540  || options.smart_enable
2541  || options.smart_disable
2542  );
2543 
2544  // SMART and GP log directories needed ?
2545  bool need_smart_logdir = (
2546  options.smart_logdir
2547  || options.devstat_all_pages // devstat fallback to smartlog if needed
2548  || options.devstat_ssd_page
2549  || !options.devstat_pages.empty()
2550  );
2551 
2552  bool need_gp_logdir = (
2553  options.gp_logdir
2554  || options.smart_ext_error_log
2555  || options.smart_ext_selftest_log
2556  || options.devstat_all_pages
2557  || options.devstat_ssd_page
2558  || !options.devstat_pages.empty()
2559  );
2560 
2561  unsigned i;
2562  for (i = 0; i < options.log_requests.size(); i++) {
2563  if (options.log_requests[i].gpl)
2564  need_gp_logdir = true;
2565  else
2566  need_smart_logdir = true;
2567  }
2568 
2569  // SCT commands needed ?
2570  bool need_sct_support = (
2571  options.sct_temp_sts
2572  || options.sct_temp_hist
2573  || options.sct_temp_int
2574  || options.sct_erc_get
2575  || options.sct_erc_set
2576  || options.sct_wcache_reorder_get
2577  || options.sct_wcache_reorder_set
2578  );
2579 
2580  // Exit if no further options specified
2581  if (!( options.drive_info || options.show_presets
2582  || need_smart_support || need_smart_logdir
2583  || need_gp_logdir || need_sct_support
2584  || options.sataphy
2585  || options.identify_word_level >= 0
2586  || options.get_set_used )) {
2587  if (powername)
2588  pout("Device is in %s mode\n", powername);
2589  else
2590  pout("ATA device successfully opened\n\n"
2591  "Use 'smartctl -a' (or '-x') to print SMART (and more) information\n\n");
2592  return 0;
2593  }
2594 
2595  // Start by getting Drive ID information. We need this, to know if SMART is supported.
2596  int returnval = 0;
2597  ata_identify_device drive; memset(&drive, 0, sizeof(drive));
2598  unsigned char raw_drive[sizeof(drive)]; memset(&raw_drive, 0, sizeof(raw_drive));
2599 
2600  device->clear_err();
2601  int retid = ata_read_identity(device, &drive, options.fix_swapped_id, raw_drive);
2602  if (retid < 0) {
2603  pout("Read Device Identity failed: %s\n\n",
2604  (device->get_errno() ? device->get_errmsg() : "Unknown error"));
2605  failuretest(MANDATORY_CMD, returnval|=FAILID);
2606  }
2607  else if (!nonempty(&drive, sizeof(drive))) {
2608  pout("Read Device Identity failed: empty IDENTIFY data\n\n");
2609  failuretest(MANDATORY_CMD, returnval|=FAILID);
2610  }
2611 
2612  // If requested, show which presets would be used for this drive and exit.
2613  if (options.show_presets) {
2614  show_presets(&drive);
2615  return 0;
2616  }
2617 
2618  // Use preset vendor attribute options unless user has requested otherwise.
2619  ata_vendor_attr_defs attribute_defs = options.attribute_defs;
2620  firmwarebug_defs firmwarebugs = options.firmwarebugs;
2621  const drive_settings * dbentry = 0;
2622  if (!options.ignore_presets)
2623  dbentry = lookup_drive_apply_presets(&drive, attribute_defs,
2624  firmwarebugs);
2625 
2626  // Get capacity, sector sizes and rotation rate
2627  ata_size_info sizes;
2628  ata_get_size_info(&drive, sizes);
2629  int rpm = ata_get_rotation_rate(&drive);
2630 
2631  // Print ATA IDENTIFY info if requested
2632  if (options.identify_word_level >= 0) {
2633  pout("=== ATA IDENTIFY DATA ===\n");
2634  // Pass raw data without endianness adjustments
2635  ata_print_identify_data(raw_drive, (options.identify_word_level > 0), options.identify_bit_level);
2636  }
2637 
2638  // Print most drive identity information if requested
2639  if (options.drive_info) {
2640  pout("=== START OF INFORMATION SECTION ===\n");
2641  print_drive_info(&drive, sizes, rpm, dbentry);
2642  }
2643 
2644  // Check and print SMART support and state
2645  int smart_supported = -1, smart_enabled = -1;
2646  if (need_smart_support || options.drive_info) {
2647 
2648  // Packet device ?
2649  if (retid > 0) {
2650  pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n",
2651  packetdevicetype(retid-1));
2652  }
2653  else {
2654  // Disk device: SMART supported and enabled ?
2655  smart_supported = ataSmartSupport(&drive);
2656  smart_enabled = ataIsSmartEnabled(&drive);
2657 
2658  if (smart_supported < 0)
2659  pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
2660  if (smart_supported && smart_enabled < 0) {
2661  pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
2662  if (need_smart_support) {
2663  failuretest(MANDATORY_CMD, returnval|=FAILSMART);
2664  // check SMART support by trying a command
2665  pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
2666  if (ataDoesSmartWork(device))
2667  smart_supported = smart_enabled = 1;
2668  }
2669  }
2670  else if (smart_supported < 0 && (smart_enabled > 0 || dbentry))
2671  // Assume supported if enabled or in drive database
2672  smart_supported = 1;
2673 
2674  if (smart_supported < 0)
2675  pout("SMART support is: Unknown - Try option -s with argument 'on' to enable it.");
2676  else if (!smart_supported)
2677  pout("SMART support is: Unavailable - device lacks SMART capability.\n");
2678  else {
2679  if (options.drive_info)
2680  pout("SMART support is: Available - device has SMART capability.\n");
2681  if (smart_enabled >= 0) {
2682  if (device->ata_identify_is_cached()) {
2683  if (options.drive_info)
2684  pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
2685  (smart_enabled?"En":"Dis"));
2686  smart_enabled = ataDoesSmartWork(device);
2687  }
2688  if (options.drive_info)
2689  pout("SMART support is: %s\n",
2690  (smart_enabled ? "Enabled" : "Disabled"));
2691  }
2692  }
2693  }
2694  }
2695 
2696  // Print AAM status
2697  if (options.get_aam) {
2698  if ((drive.command_set_2 & 0xc200) != 0x4200) // word083
2699  pout("AAM feature is: Unavailable\n");
2700  else if (!(drive.word086 & 0x0200))
2701  pout("AAM feature is: Disabled\n");
2702  else
2703  print_aam_level("AAM level is: ", drive.words088_255[94-88] & 0xff,
2704  drive.words088_255[94-88] >> 8);
2705  }
2706 
2707  // Print APM status
2708  if (options.get_apm) {
2709  if ((drive.command_set_2 & 0xc008) != 0x4008) // word083
2710  pout("APM feature is: Unavailable\n");
2711  else if (!(drive.word086 & 0x0008))
2712  pout("APM feature is: Disabled\n");
2713  else
2714  print_apm_level("APM level is: ", drive.words088_255[91-88] & 0xff);
2715  }
2716 
2717  // Print read look-ahead status
2718  if (options.get_lookahead) {
2719  pout("Rd look-ahead is: %s\n",
2720  ( (drive.command_set_2 & 0xc000) != 0x4000 // word083
2721  || !(drive.command_set_1 & 0x0040)) ? "Unavailable" : // word082
2722  !(drive.cfs_enable_1 & 0x0040) ? "Disabled" : "Enabled"); // word085
2723  }
2724 
2725  // Print write cache status
2726  if (options.get_wcache) {
2727  pout("Write cache is: %s\n",
2728  ( (drive.command_set_2 & 0xc000) != 0x4000 // word083
2729  || !(drive.command_set_1 & 0x0020)) ? "Unavailable" : // word082
2730  !(drive.cfs_enable_1 & 0x0020) ? "Disabled" : "Enabled"); // word085
2731  }
2732 
2733  // Print ATA security status
2734  if (options.get_security)
2735  print_ata_security_status("ATA Security is: ", drive.words088_255[128-88]);
2736 
2737  // Print write cache reordering status
2738  if (options.sct_wcache_reorder_get) {
2739  if (isSCTFeatureControlCapable(&drive)) {
2740  int wcache_reorder = ataGetSetSCTWriteCacheReordering(device,
2741  false /*enable*/, false /*persistent*/, false /*set*/);
2742 
2743  if (-1 <= wcache_reorder && wcache_reorder <= 2)
2744  pout("Wt Cache Reorder: %s\n",
2745  (wcache_reorder == -1 ? "Unknown (SCT Feature Control command failed)" :
2746  wcache_reorder == 0 ? "Unknown" : // not defined in standard but returned on some drives if not set
2747  wcache_reorder == 1 ? "Enabled" : "Disabled"));
2748  else
2749  pout("Wt Cache Reorder: Unknown (0x%02x)\n", wcache_reorder);
2750  }
2751  else
2752  pout("Wt Cache Reorder: Unavailable\n");
2753  }
2754 
2755  // Print remaining drive info
2756  if (options.drive_info) {
2757  // Print the (now possibly changed) power mode if available
2758  if (powername)
2759  pout("Power mode %s %s\n", (powerchg?"was:":"is: "), powername);
2760  pout("\n");
2761  }
2762 
2763  // Exit if SMART is not supported but must be available to proceed
2764  if (smart_supported <= 0 && need_smart_support)
2765  failuretest(MANDATORY_CMD, returnval|=FAILSMART);
2766 
2767  // START OF THE ENABLE/DISABLE SECTION OF THE CODE
2768  if ( options.smart_disable || options.smart_enable
2769  || options.smart_auto_save_disable || options.smart_auto_save_enable
2770  || options.smart_auto_offl_disable || options.smart_auto_offl_enable
2771  || options.set_aam || options.set_apm || options.set_lookahead
2772  || options.set_wcache || options.set_security_freeze || options.set_standby
2773  || options.sct_wcache_reorder_set)
2774  pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
2775 
2776  // Enable/Disable AAM
2777  if (options.set_aam) {
2778  if (options.set_aam > 0) {
2779  if (!ata_set_features(device, ATA_ENABLE_AAM, options.set_aam-1)) {
2780  pout("AAM enable failed: %s\n", device->get_errmsg());
2781  returnval |= FAILSMART;
2782  }
2783  else
2784  print_aam_level("AAM set to level ", options.set_aam-1);
2785  }
2786  else {
2787  if (!ata_set_features(device, ATA_DISABLE_AAM)) {
2788  pout("AAM disable failed: %s\n", device->get_errmsg());
2789  returnval |= FAILSMART;
2790  }
2791  else
2792  pout("AAM disabled\n");
2793  }
2794  }
2795 
2796  // Enable/Disable APM
2797  if (options.set_apm) {
2798  if (options.set_apm > 0) {
2799  if (!ata_set_features(device, ATA_ENABLE_APM, options.set_apm-1)) {
2800  pout("APM enable failed: %s\n", device->get_errmsg());
2801  returnval |= FAILSMART;
2802  }
2803  else
2804  print_apm_level("APM set to level ", options.set_apm-1);
2805  }
2806  else {
2807  if (!ata_set_features(device, ATA_DISABLE_APM)) {
2808  pout("APM disable failed: %s\n", device->get_errmsg());
2809  returnval |= FAILSMART;
2810  }
2811  else
2812  pout("APM disabled\n");
2813  }
2814  }
2815 
2816  // Enable/Disable read look-ahead
2817  if (options.set_lookahead) {
2818  bool enable = (options.set_lookahead > 0);
2820  pout("Read look-ahead %sable failed: %s\n", (enable ? "en" : "dis"), device->get_errmsg());
2821  returnval |= FAILSMART;
2822  }
2823  else
2824  pout("Read look-ahead %sabled\n", (enable ? "en" : "dis"));
2825  }
2826 
2827  // Enable/Disable write cache
2828  if (options.set_wcache) {
2829  bool enable = (options.set_wcache > 0);
2831  pout("Write cache %sable failed: %s\n", (enable ? "en" : "dis"), device->get_errmsg());
2832  returnval |= FAILSMART;
2833  }
2834  else
2835  pout("Write cache %sabled\n", (enable ? "en" : "dis"));
2836  }
2837 
2838  // Enable/Disable write cache reordering
2839  if (options.sct_wcache_reorder_set) {
2840  bool enable = (options.sct_wcache_reorder_set > 0);
2841  if (!isSCTFeatureControlCapable(&drive))
2842  pout("Write cache reordering %sable failed: SCT Feature Control command not supported\n",
2843  (enable ? "en" : "dis"));
2844  else if (ataGetSetSCTWriteCacheReordering(device,
2845  enable, false /*persistent*/, true /*set*/) < 0) {
2846  pout("Write cache reordering %sable failed: %s\n", (enable ? "en" : "dis"), device->get_errmsg());
2847  returnval |= FAILSMART;
2848  }
2849  else
2850  pout("Write cache reordering %sabled\n", (enable ? "en" : "dis"));
2851  }
2852 
2853  // Freeze ATA security
2854  if (options.set_security_freeze) {
2856  pout("ATA SECURITY FREEZE LOCK failed: %s\n", device->get_errmsg());
2857  returnval |= FAILSMART;
2858  }
2859  else
2860  pout("ATA Security set to frozen mode\n");
2861  }
2862 
2863  // Set standby timer
2864  if (options.set_standby) {
2865  if (!ata_nodata_command(device, ATA_IDLE, options.set_standby-1)) {
2866  pout("ATA IDLE command failed: %s\n", device->get_errmsg());
2867  returnval |= FAILSMART;
2868  }
2869  else
2870  print_standby_timer("Standby timer set to ", options.set_standby-1, drive);
2871  }
2872 
2873  // Enable/Disable SMART commands
2874  if (options.smart_enable) {
2875  if (ataEnableSmart(device)) {
2876  pout("SMART Enable failed: %s\n\n", device->get_errmsg());
2877  failuretest(MANDATORY_CMD, returnval|=FAILSMART);
2878  }
2879  else {
2880  pout("SMART Enabled.\n");
2881  smart_enabled = 1;
2882  }
2883  }
2884 
2885  // Turn off SMART on device
2886  if (options.smart_disable) {
2887  if (ataDisableSmart(device)) {
2888  pout("SMART Disable failed: %s\n\n", device->get_errmsg());
2889  failuretest(MANDATORY_CMD,returnval|=FAILSMART);
2890  }
2891  }
2892 
2893  // Exit if SMART is disabled but must be enabled to proceed
2894  if (options.smart_disable || (smart_enabled <= 0 && need_smart_enabled && !is_permissive())) {
2895  pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
2896  if (!options.smart_disable)
2897  pout("(override with '-T permissive' option)\n");
2898  return returnval;
2899  }
2900 
2901  // Enable/Disable Auto-save attributes
2902  if (options.smart_auto_save_enable) {
2903  if (ataEnableAutoSave(device)){
2904  pout("SMART Enable Attribute Autosave failed: %s\n\n", device->get_errmsg());
2905  failuretest(MANDATORY_CMD, returnval|=FAILSMART);
2906  }
2907  else
2908  pout("SMART Attribute Autosave Enabled.\n");
2909  }
2910 
2911  if (options.smart_auto_save_disable) {
2912  if (ataDisableAutoSave(device)){
2913  pout("SMART Disable Attribute Autosave failed: %s\n\n", device->get_errmsg());
2914  failuretest(MANDATORY_CMD, returnval|=FAILSMART);
2915  }
2916  else
2917  pout("SMART Attribute Autosave Disabled.\n");
2918  }
2919 
2920  // Read SMART values and thresholds if necessary
2921  ata_smart_values smartval; memset(&smartval, 0, sizeof(smartval));
2922  ata_smart_thresholds_pvt smartthres; memset(&smartthres, 0, sizeof(smartthres));
2923  bool smart_val_ok = false, smart_thres_ok = false;
2924 
2925  if (need_smart_val) {
2926  if (ataReadSmartValues(device, &smartval)) {
2927  pout("Read SMART Data failed: %s\n\n", device->get_errmsg());
2928  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2929  }
2930  else {
2931  smart_val_ok = true;
2932 
2933  if (options.smart_check_status || options.smart_vendor_attrib) {
2934  if (ataReadSmartThresholds(device, &smartthres)){
2935  pout("Read SMART Thresholds failed: %s\n\n", device->get_errmsg());
2936  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2937  }
2938  else
2939  smart_thres_ok = true;
2940  }
2941  }
2942  }
2943 
2944  // Enable/Disable Off-line testing
2945  bool needupdate = false;
2946  if (options.smart_auto_offl_enable) {
2947  if (!isSupportAutomaticTimer(&smartval)){
2948  pout("SMART Automatic Timers not supported\n\n");
2949  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2950  }
2951  needupdate = smart_val_ok;
2952  if (ataEnableAutoOffline(device)){
2953  pout("SMART Enable Automatic Offline failed: %s\n\n", device->get_errmsg());
2954  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2955  }
2956  else
2957  pout("SMART Automatic Offline Testing Enabled every four hours.\n");
2958  }
2959 
2960  if (options.smart_auto_offl_disable) {
2961  if (!isSupportAutomaticTimer(&smartval)){
2962  pout("SMART Automatic Timers not supported\n\n");
2963  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2964  }
2965  needupdate = smart_val_ok;
2966  if (ataDisableAutoOffline(device)){
2967  pout("SMART Disable Automatic Offline failed: %s\n\n", device->get_errmsg());
2968  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2969  }
2970  else
2971  pout("SMART Automatic Offline Testing Disabled.\n");
2972  }
2973 
2974  if (needupdate && ataReadSmartValues(device, &smartval)){
2975  pout("Read SMART Data failed: %s\n\n", device->get_errmsg());
2976  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
2977  smart_val_ok = false;
2978  }
2979 
2980  // all this for a newline!
2981  if ( options.smart_disable || options.smart_enable
2982  || options.smart_auto_save_disable || options.smart_auto_save_enable
2983  || options.smart_auto_offl_disable || options.smart_auto_offl_enable
2984  || options.set_aam || options.set_apm || options.set_lookahead
2985  || options.set_wcache || options.set_security_freeze || options.set_standby
2986  || options.sct_wcache_reorder_set)
2987  pout("\n");
2988 
2989  // START OF READ-ONLY OPTIONS APART FROM -V and -i
2990  if ( options.smart_check_status || options.smart_general_values
2991  || options.smart_vendor_attrib || options.smart_error_log
2992  || options.smart_selftest_log || options.smart_selective_selftest_log
2993  || options.smart_ext_error_log || options.smart_ext_selftest_log
2994  || options.sct_temp_sts || options.sct_temp_hist )
2995  pout("=== START OF READ SMART DATA SECTION ===\n");
2996 
2997  // Check SMART status
2998  if (options.smart_check_status) {
2999 
3000  switch (ataSmartStatus2(device)) {
3001 
3002  case 0:
3003  // The case where the disk health is OK
3004  pout("SMART overall-health self-assessment test result: PASSED\n");
3005  if (smart_thres_ok && find_failed_attr(&smartval, &smartthres, attribute_defs, 0)) {
3006  if (options.smart_vendor_attrib)
3007  pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
3008  else {
3009  print_on();
3010  pout("Please note the following marginal Attributes:\n");
3011  PrintSmartAttribWithThres(&smartval, &smartthres, attribute_defs, rpm, 2, options.output_format);
3012  }
3013  returnval|=FAILAGE;
3014  }
3015  else
3016  pout("\n");
3017  break;
3018 
3019  case 1:
3020  // The case where the disk health is NOT OK
3021  print_on();
3022  pout("SMART overall-health self-assessment test result: FAILED!\n"
3023  "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
3024  print_off();
3025  if (smart_thres_ok && find_failed_attr(&smartval, &smartthres, attribute_defs, 1)) {
3026  returnval|=FAILATTR;
3027  if (options.smart_vendor_attrib)
3028  pout("See vendor-specific Attribute list for failed Attributes.\n\n");
3029  else {
3030  print_on();
3031  pout("Failed Attributes:\n");
3032  PrintSmartAttribWithThres(&smartval, &smartthres, attribute_defs, rpm, 1, options.output_format);
3033  }
3034  }
3035  else
3036  pout("No failed Attributes found.\n\n");
3037  returnval|=FAILSTATUS;
3038  print_off();
3039  break;
3040 
3041  case -1:
3042  default:
3043  // Something went wrong with the SMART STATUS command.
3044  // The ATA SMART RETURN STATUS command provides the result in the ATA output
3045  // registers. Buggy ATA/SATA drivers and SAT Layers often do not properly
3046  // return the registers values.
3047  pout("SMART Status %s: %s\n",
3048  (device->is_syscall_unsup() ? "not supported" : "command failed"),
3049  device->get_errmsg());
3050  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3051 
3052  if (!(smart_val_ok && smart_thres_ok)) {
3053  print_on();
3054  pout("SMART overall-health self-assessment test result: UNKNOWN!\n"
3055  "SMART Status, Attributes and Thresholds cannot be read.\n\n");
3056  }
3057  else if (find_failed_attr(&smartval, &smartthres, attribute_defs, 1)) {
3058  print_on();
3059  pout("SMART overall-health self-assessment test result: FAILED!\n"
3060  "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
3061  pout("Warning: This result is based on an Attribute check.\n");
3062  print_off();
3063  returnval|=FAILATTR;
3064  returnval|=FAILSTATUS;
3065  if (options.smart_vendor_attrib)
3066  pout("See vendor-specific Attribute list for failed Attributes.\n\n");
3067  else {
3068  print_on();
3069  pout("Failed Attributes:\n");
3070  PrintSmartAttribWithThres(&smartval, &smartthres, attribute_defs, rpm, 1, options.output_format);
3071  }
3072  }
3073  else {
3074  pout("SMART overall-health self-assessment test result: PASSED\n");
3075  pout("Warning: This result is based on an Attribute check.\n");
3076  if (find_failed_attr(&smartval, &smartthres, attribute_defs, 0)) {
3077  if (options.smart_vendor_attrib)
3078  pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
3079  else {
3080  print_on();
3081  pout("Please note the following marginal Attributes:\n");
3082  PrintSmartAttribWithThres(&smartval, &smartthres, attribute_defs, rpm, 2, options.output_format);
3083  }
3084  returnval|=FAILAGE;
3085  }
3086  else
3087  pout("\n");
3088  }
3089  print_off();
3090  break;
3091  } // end of switch statement
3092 
3093  print_off();
3094  } // end of checking SMART Status
3095 
3096  // Print general SMART values
3097  if (smart_val_ok && options.smart_general_values)
3098  PrintGeneralSmartValues(&smartval, &drive, firmwarebugs);
3099 
3100  // Print vendor-specific attributes
3101  if (smart_val_ok && options.smart_vendor_attrib) {
3102  print_on();
3103  PrintSmartAttribWithThres(&smartval, &smartthres, attribute_defs, rpm,
3104  (printing_is_switchable ? 2 : 0), options.output_format);
3105  print_off();
3106  }
3107 
3108  // If GP Log is supported use smart log directory for
3109  // error and selftest log support check.
3110  if ( isGeneralPurposeLoggingCapable(&drive)
3111  && ( options.smart_error_log || options.smart_selftest_log
3112  || options.retry_error_log || options.retry_selftest_log))
3113  need_smart_logdir = true;
3114 
3115  ata_smart_log_directory smartlogdir_buf, gplogdir_buf;
3116  const ata_smart_log_directory * smartlogdir = 0, * gplogdir = 0;
3117 
3118  // Read SMART Log directory
3119  if (need_smart_logdir) {
3120  if (firmwarebugs.is_set(BUG_NOLOGDIR))
3121  smartlogdir = fake_logdir(&smartlogdir_buf, options);
3122  else if (ataReadLogDirectory(device, &smartlogdir_buf, false)) {
3123  pout("Read SMART Log Directory failed: %s\n\n", device->get_errmsg());
3124  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3125  }
3126  else
3127  smartlogdir = &smartlogdir_buf;
3128  }
3129 
3130  // Read GP Log directory
3131  if (need_gp_logdir) {
3132  if (firmwarebugs.is_set(BUG_NOLOGDIR))
3133  gplogdir = fake_logdir(&gplogdir_buf, options);
3134  else if (ataReadLogDirectory(device, &gplogdir_buf, true)) {
3135  pout("Read GP Log Directory failed\n\n");
3136  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3137  }
3138  else
3139  gplogdir = &gplogdir_buf;
3140  }
3141 
3142  // Print log directories
3143  if ((options.gp_logdir && gplogdir) || (options.smart_logdir && smartlogdir)) {
3144  if (firmwarebugs.is_set(BUG_NOLOGDIR))
3145  pout("Log Directories not read due to '-F nologdir' option\n\n");
3146  else
3147  PrintLogDirectories(gplogdir, smartlogdir);
3148  }
3149 
3150  // Print log pages
3151  for (i = 0; i < options.log_requests.size(); i++) {
3152  const ata_log_request & req = options.log_requests[i];
3153 
3154  const char * type;
3155  unsigned max_nsectors;
3156  if (req.gpl) {
3157  type = "General Purpose";
3158  max_nsectors = GetNumLogSectors(gplogdir, req.logaddr, true);
3159  }
3160  else {
3161  type = "SMART";
3162  max_nsectors = GetNumLogSectors(smartlogdir, req.logaddr, false);
3163  }
3164 
3165  if (!max_nsectors) {
3166  if (!is_permissive()) {
3167  pout("%s Log 0x%02x does not exist (override with '-T permissive' option)\n", type, req.logaddr);
3168  continue;
3169  }
3170  max_nsectors = req.page+1;
3171  }
3172  if (max_nsectors <= req.page) {
3173  pout("%s Log 0x%02x has only %u sectors, output skipped\n", type, req.logaddr, max_nsectors);
3174  continue;
3175  }
3176 
3177  unsigned ns = req.nsectors;
3178  if (ns > max_nsectors - req.page) {
3179  if (req.nsectors != ~0U) // "FIRST-max"
3180  pout("%s Log 0x%02x has only %u sectors, output truncated\n", type, req.logaddr, max_nsectors);
3181  ns = max_nsectors - req.page;
3182  }
3183 
3184  // SMART log don't support sector offset, start with first sector
3185  unsigned offs = (req.gpl ? 0 : req.page);
3186 
3187  raw_buffer log_buf((offs + ns) * 512);
3188  bool ok;
3189  if (req.gpl)
3190  ok = ataReadLogExt(device, req.logaddr, 0x00, req.page, log_buf.data(), ns);
3191  else
3192  ok = ataReadSmartLog(device, req.logaddr, log_buf.data(), offs + ns);
3193  if (!ok)
3194  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3195  else
3196  PrintLogPages(type, log_buf.data() + offs*512, req.logaddr, req.page, ns, max_nsectors);
3197  }
3198 
3199  // Print SMART Extendend Comprehensive Error Log
3200  bool do_smart_error_log = options.smart_error_log;
3201  if (options.smart_ext_error_log) {
3202  bool ok = false;
3203  unsigned nsectors = GetNumLogSectors(gplogdir, 0x03, true);
3204  if (!nsectors)
3205  pout("SMART Extended Comprehensive Error Log (GP Log 0x03) not supported\n\n");
3206  else {
3207  // Read only first sector to get error count and index
3208  // Print function will read more sectors as needed
3209  ata_smart_exterrlog log_03; memset(&log_03, 0, sizeof(log_03));
3210  if (!ataReadExtErrorLog(device, &log_03, 0, 1, firmwarebugs)) {
3211  pout("Read SMART Extended Comprehensive Error Log failed\n\n");
3212  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3213  }
3214  else {
3215  if (PrintSmartExtErrorLog(device, firmwarebugs, &log_03, nsectors, options.smart_ext_error_log))
3216  returnval |= FAILERR;
3217  ok = true;
3218  }
3219  }
3220 
3221  if (!ok) {
3222  if (options.retry_error_log)
3223  do_smart_error_log = true;
3224  else if (!do_smart_error_log)
3225  pout("Try '-l [xerror,]error' to read traditional SMART Error Log\n");
3226  }
3227  }
3228 
3229  // Print SMART error log
3230  if (do_smart_error_log) {
3231  if (!( ( smartlogdir && GetNumLogSectors(smartlogdir, 0x01, false))
3232  || (!smartlogdir && isSmartErrorLogCapable(&smartval, &drive) )
3233  || is_permissive() )) {
3234  pout("SMART Error Log not supported\n\n");
3235  }
3236  else {
3237  ata_smart_errorlog smarterror; memset(&smarterror, 0, sizeof(smarterror));
3238  if (ataReadErrorLog(device, &smarterror, firmwarebugs)) {
3239  pout("Read SMART Error Log failed: %s\n\n", device->get_errmsg());
3240  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3241  }
3242  else {
3243  // quiet mode is turned on inside PrintSmartErrorLog()
3244  if (PrintSmartErrorlog(&smarterror, firmwarebugs))
3245  returnval|=FAILERR;
3246  print_off();
3247  }
3248  }
3249  }
3250 
3251  // Print SMART Extendend Self-test Log
3252  bool do_smart_selftest_log = options.smart_selftest_log;
3253  if (options.smart_ext_selftest_log) {
3254  bool ok = false;
3255  unsigned nsectors = GetNumLogSectors(gplogdir, 0x07, true);
3256  if (!nsectors)
3257  pout("SMART Extended Self-test Log (GP Log 0x07) not supported\n\n");
3258  else if (nsectors >= 256)
3259  pout("SMART Extended Self-test Log size %u not supported\n\n", nsectors);
3260  else {
3261  raw_buffer log_07_buf(nsectors * 512);
3262  ata_smart_extselftestlog * log_07 = (ata_smart_extselftestlog *)log_07_buf.data();
3263  if (!ataReadExtSelfTestLog(device, log_07, nsectors)) {
3264  pout("Read SMART Extended Self-test Log failed\n\n");
3265  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3266  }
3267  else {
3268  if (PrintSmartExtSelfTestLog(log_07, nsectors, options.smart_ext_selftest_log))
3269  returnval |= FAILLOG;
3270  ok = true;
3271  }
3272  }
3273 
3274  if (!ok) {
3275  if (options.retry_selftest_log)
3276  do_smart_selftest_log = true;
3277  else if (!do_smart_selftest_log)
3278  pout("Try '-l [xselftest,]selftest' to read traditional SMART Self Test Log\n");
3279  }
3280  }
3281 
3282  // Print SMART self-test log
3283  if (do_smart_selftest_log) {
3284  if (!( ( smartlogdir && GetNumLogSectors(smartlogdir, 0x06, false))
3285  || (!smartlogdir && isSmartTestLogCapable(&smartval, &drive) )
3286  || is_permissive() )) {
3287  pout("SMART Self-test Log not supported\n\n");
3288  }
3289  else {
3290  ata_smart_selftestlog smartselftest; memset(&smartselftest, 0, sizeof(smartselftest));
3291  if (ataReadSelfTestLog(device, &smartselftest, firmwarebugs)) {
3292  pout("Read SMART Self-test Log failed: %s\n\n", device->get_errmsg());
3293  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3294  }
3295  else {
3296  print_on();
3297  if (ataPrintSmartSelfTestlog(&smartselftest, !printing_is_switchable, firmwarebugs))
3298  returnval |= FAILLOG;
3299  print_off();
3300  pout("\n");
3301  }
3302  }
3303  }
3304 
3305  // Print SMART selective self-test log
3306  if (options.smart_selective_selftest_log) {
3308 
3309  if (!isSupportSelectiveSelfTest(&smartval))
3310  pout("Selective Self-tests/Logging not supported\n\n");
3311  else if(ataReadSelectiveSelfTestLog(device, &log)) {
3312  pout("Read SMART Selective Self-test Log failed: %s\n\n", device->get_errmsg());
3313  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3314  }
3315  else {
3316  print_on();
3317  // If any errors were found, they are logged in the SMART Self-test log.
3318  // So there is no need to print the Selective Self Test log in silent
3319  // mode.
3321  ataPrintSelectiveSelfTestLog(&log, &smartval);
3322  print_off();
3323  pout("\n");
3324  }
3325  }
3326 
3327  // Check if SCT commands available
3328  bool sct_ok = isSCTCapable(&drive);
3329  if(!sct_ok && (options.sct_temp_sts || options.sct_temp_hist || options.sct_temp_int
3330  || options.sct_erc_get || options.sct_erc_set ))
3331  pout("SCT Commands not supported\n\n");
3332 
3333  // Print SCT status and temperature history table
3334  if (sct_ok && (options.sct_temp_sts || options.sct_temp_hist || options.sct_temp_int)) {
3335  for (;;) {
3336  bool sct_temp_hist_ok = isSCTDataTableCapable(&drive);
3338 
3339  if (options.sct_temp_sts || (options.sct_temp_hist && sct_temp_hist_ok)) {
3340  // Read SCT status
3341  if (ataReadSCTStatus(device, &sts)) {
3342  pout("\n");
3343  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3344  break;
3345  }
3346  if (options.sct_temp_sts) {
3347  ataPrintSCTStatus(&sts);
3348  pout("\n");
3349  }
3350  }
3351 
3352  if (!sct_temp_hist_ok && (options.sct_temp_hist || options.sct_temp_int)) {
3353  pout("SCT Data Table command not supported\n\n");
3354  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3355  break;
3356  }
3357 
3358  if (options.sct_temp_hist) {
3359  // Read SCT temperature history,
3360  // requires initial SCT status from above
3362  if (ataReadSCTTempHist(device, &tmh, &sts)) {
3363  pout("Read SCT Temperature History failed\n\n");
3364  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3365  break;
3366  }
3367  ataPrintSCTTempHist(&tmh);
3368  pout("\n");
3369  }
3370 
3371  if (options.sct_temp_int) {
3372  // Set new temperature logging interval
3373  if (!isSCTFeatureControlCapable(&drive)) {
3374  pout("SCT Feature Control command not supported\n\n");
3375  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3376  break;
3377  }
3378  if (ataSetSCTTempInterval(device, options.sct_temp_int, options.sct_temp_int_pers)) {
3379  pout("Write Temperature Logging Interval failed\n\n");
3380  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3381  break;
3382  }
3383  pout("Temperature Logging Interval set to %u minute%s (%s)\n",
3384  options.sct_temp_int, (options.sct_temp_int == 1 ? "" : "s"),
3385  (options.sct_temp_int_pers ? "persistent" : "volatile"));
3386  }
3387  break;
3388  }
3389  }
3390 
3391  // SCT Error Recovery Control
3392  if (sct_ok && (options.sct_erc_get || options.sct_erc_set)) {
3393  if (!isSCTErrorRecoveryControlCapable(&drive)) {
3394  pout("SCT Error Recovery Control command not supported\n\n");
3395  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3396  }
3397  else {
3398  bool sct_erc_get = options.sct_erc_get;
3399  if (options.sct_erc_set) {
3400  // Set SCT Error Recovery Control
3401  if ( ataSetSCTErrorRecoveryControltime(device, 1, options.sct_erc_readtime )
3402  || ataSetSCTErrorRecoveryControltime(device, 2, options.sct_erc_writetime)) {
3403  pout("SCT (Set) Error Recovery Control command failed\n");
3404  if (!( (options.sct_erc_readtime == 70 && options.sct_erc_writetime == 70)
3405  || (options.sct_erc_readtime == 0 && options.sct_erc_writetime == 0)))
3406  pout("Retry with: 'scterc,70,70' to enable ERC or 'scterc,0,0' to disable\n");
3407  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3408  sct_erc_get = false;
3409  }
3410  else if (!sct_erc_get)
3412  options.sct_erc_writetime);
3413  }
3414 
3415  if (sct_erc_get) {
3416  // Print SCT Error Recovery Control
3417  unsigned short read_timer, write_timer;
3418  if ( ataGetSCTErrorRecoveryControltime(device, 1, read_timer )
3419  || ataGetSCTErrorRecoveryControltime(device, 2, write_timer)) {
3420  pout("SCT (Get) Error Recovery Control command failed\n");
3421  if (options.sct_erc_set) {
3422  pout("The previous SCT (Set) Error Recovery Control command succeeded\n");
3424  options.sct_erc_writetime);
3425  }
3426  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3427  }
3428  else
3429  ataPrintSCTErrorRecoveryControl(false, read_timer, write_timer);
3430  }
3431  pout("\n");
3432  }
3433  }
3434 
3435  // Print Device Statistics
3436  if (options.devstat_all_pages || options.devstat_ssd_page || !options.devstat_pages.empty()) {
3437  bool use_gplog = true;
3438  unsigned nsectors = 0;
3439  if (gplogdir)
3440  nsectors = GetNumLogSectors(gplogdir, 0x04, false);
3441  else if (smartlogdir){ // for systems without ATA_READ_LOG_EXT
3442  nsectors = GetNumLogSectors(smartlogdir, 0x04, false);
3443  use_gplog = false;
3444  }
3445  if (!nsectors)
3446  pout("Device Statistics (GP/SMART Log 0x04) not supported\n\n");
3447  else if (!print_device_statistics(device, nsectors, options.devstat_pages,
3448  options.devstat_all_pages, options.devstat_ssd_page, use_gplog))
3449  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3450  }
3451 
3452  // Print SATA Phy Event Counters
3453  if (options.sataphy) {
3454  unsigned nsectors = GetNumLogSectors(gplogdir, 0x11, true);
3455  // Packet interface devices do not provide a log directory, check support bit
3456  if (!nsectors && (drive.words047_079[76-47] & 0x0401) == 0x0400)
3457  nsectors = 1;
3458  if (!nsectors)
3459  pout("SATA Phy Event Counters (GP Log 0x11) not supported\n\n");
3460  else if (nsectors != 1)
3461  pout("SATA Phy Event Counters with %u sectors not supported\n\n", nsectors);
3462  else {
3463  unsigned char log_11[512] = {0, };
3464  unsigned char features = (options.sataphy_reset ? 0x01 : 0x00);
3465  if (!ataReadLogExt(device, 0x11, features, 0, log_11, 1)) {
3466  pout("Read SATA Phy Event Counters failed\n\n");
3467  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3468  }
3469  else
3470  PrintSataPhyEventCounters(log_11, options.sataphy_reset);
3471  }
3472  }
3473 
3474  // Set to standby (spindown) mode
3475  // (Above commands may spinup drive)
3476  if (options.set_standby_now) {
3477  if (!ata_nodata_command(device, ATA_STANDBY_IMMEDIATE)) {
3478  pout("ATA STANDBY IMMEDIATE command failed: %s\n", device->get_errmsg());
3479  returnval |= FAILSMART;
3480  }
3481  else
3482  pout("Device placed in STANDBY mode\n");
3483  }
3484 
3485  // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
3486  if (!smart_val_ok || options.smart_selftest_type == -1)
3487  return returnval;
3488 
3489  pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
3490  // if doing a self-test, be sure it's supported by the hardware
3491  switch (options.smart_selftest_type) {
3492  case OFFLINE_FULL_SCAN:
3493  if (!isSupportExecuteOfflineImmediate(&smartval)){
3494  pout("Execute Offline Immediate function not supported\n\n");
3495  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3496  }
3497  break;
3498  case ABORT_SELF_TEST:
3499  case SHORT_SELF_TEST:
3500  case EXTEND_SELF_TEST:
3503  if (!isSupportSelfTest(&smartval)){
3504  pout("Self-test functions not supported\n\n");
3505  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3506  }
3507  break;
3508  case CONVEYANCE_SELF_TEST:
3510  if (!isSupportConveyanceSelfTest(&smartval)){
3511  pout("Conveyance Self-test functions not supported\n\n");
3512  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3513  }
3514  break;
3515  case SELECTIVE_SELF_TEST:
3517  if (!isSupportSelectiveSelfTest(&smartval)){
3518  pout("Selective Self-test functions not supported\n\n");
3519  failuretest(MANDATORY_CMD, returnval|=FAILSMART);
3520  }
3521  break;
3522  default:
3523  break; // Vendor specific type
3524  }
3525 
3526  // Now do the test. Note ataSmartTest prints its own error/success
3527  // messages
3528  if (ataSmartTest(device, options.smart_selftest_type, options.smart_selftest_force,
3529  options.smart_selective_args, &smartval, sizes.sectors ))
3530  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3531  else {
3532  // Tell user how long test will take to complete. This is tricky
3533  // because in the case of an Offline Full Scan, the completion
3534  // timer is volatile, and needs to be read AFTER the command is
3535  // given. If this will interrupt the Offline Full Scan, we don't
3536  // do it, just warn user.
3537  if (options.smart_selftest_type == OFFLINE_FULL_SCAN) {
3538  if (isSupportOfflineAbort(&smartval))
3539  pout("Note: giving further SMART commands will abort Offline testing\n");
3540  else if (ataReadSmartValues(device, &smartval)){
3541  pout("Read SMART Data failed: %s\n\n", device->get_errmsg());
3542  failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
3543  }
3544  }
3545 
3546  // Now say how long the test will take to complete
3547  int timewait = TestTime(&smartval, options.smart_selftest_type);
3548  if (timewait) {
3549  time_t t=time(NULL);
3550  if (options.smart_selftest_type == OFFLINE_FULL_SCAN) {
3551  t+=timewait;
3552  pout("Please wait %d seconds for test to complete.\n", (int)timewait);
3553  } else {
3554  t+=timewait*60;
3555  pout("Please wait %d minutes for test to complete.\n", (int)timewait);
3556  }
3557  pout("Test will complete after %s\n", ctime(&t));
3558 
3563  pout("Use smartctl -X to abort test.\n");
3564  }
3565  }
3566 
3567  return returnval;
3568 }
#define CONVEYANCE_CAPTIVE_SELF_TEST
Definition: atacmds.h:119
unsigned short minor_rev_num
Definition: atacmds.h:137
unsigned char self_test_status
Definition: atacmds.h:444
unsigned char errorlog_capability
Definition: atacmds.h:221
int isSupportSelectiveSelfTest(const ata_smart_values *data)
Definition: atacmds.cpp:1807
#define PRIu64
Definition: int64.h:76
int ataIsSmartEnabled(const ata_identify_device *drive)
Definition: atacmds.cpp:958
unsigned short words047_079[33]
Definition: atacmds.h:135
const char * packetdevicetype(int type)
Definition: utility.cpp:257
const drive_settings * lookup_drive_apply_presets(const ata_identify_device *drive, ata_vendor_attr_defs &defs, firmwarebug_defs &firmwarebugs)
u16 s[6]
Definition: megaraid.h:97
const devstat_entry_info devstat_info_0x06[]
Definition: ataprint.cpp:1410
static const char * get_log_rw(unsigned logaddr)
Definition: ataprint.cpp:1204
static void PrintSmartOfflineStatus(const ata_smart_values *data)
Definition: ataprint.cpp:731
bool ataReadExtErrorLog(ata_device *device, ata_smart_exterrlog *log, unsigned page, unsigned nsectors, firmwarebug_defs firmwarebugs)
Definition: atacmds.cpp:1468
unsigned page
Definition: ataprint.h:37
unsigned phy_sector_size
Definition: atacmds.h:990
static void PrintLogPages(const char *type, const unsigned char *data, unsigned char logaddr, unsigned page, unsigned num_pages, unsigned max_pages)
Definition: ataprint.cpp:1311
uint64_t end
Definition: atacmds.h:491
#define NUMBER_ATA_SMART_ATTRIBUTES
Definition: atacmds.h:124
u32 size
Definition: megaraid.h:79
ata_vendor_attr_defs attribute_defs
Definition: ataprint.h:90
unsigned char reserved1
Definition: atacmds.h:459
std::string ata_get_smart_attr_name(unsigned char id, const ata_vendor_attr_defs &defs, int rpm)
Definition: atacmds.cpp:2360
static void PrintSmartAttribWithThres(const ata_smart_values *data, const ata_smart_thresholds_pvt *thresholds, const ata_vendor_attr_defs &defs, int rpm, int onlyfailed, unsigned char format)
Definition: ataprint.cpp:975
int isSupportExecuteOfflineImmediate(const ata_smart_values *data)
Definition: atacmds.cpp:1777
unsigned char features_register
Definition: atacmds.h:335
firmwarebug_defs firmwarebugs
Definition: ataprint.h:87
struct test_span span[5]
Definition: atacmds.h:499
unsigned char checksum(const void *data)
Definition: atacmds.cpp:703
static const char * get_sata_curspeed(const ata_identify_device *drive)
Definition: ataprint.cpp:567
#define ATA_ENABLE_APM
Definition: atacmds.h:86
unsigned char current
Definition: atacmds.h:156
unsigned short currentspan
Definition: atacmds.h:503
bool smart_error_log
Definition: ataprint.h:53
bool sct_wcache_reorder_get
Definition: ataprint.h:109
int get_errno() const
Get last error number.
ata_smart_exterrlog_error error
Definition: atacmds.h:385
const char * warningmsg
Definition: knowndrives.h:30
int smart_selftest_type
Definition: ataprint.h:77
static const char * get_error_log_state_desc(unsigned state)
Definition: ataprint.cpp:1704
#define FAILERR
Definition: smartctl.h:59
unsigned char self_test_type
Definition: atacmds.h:443
void dateandtimezone(char *buffer)
Definition: utility.cpp:337
bool str_starts_with(const char *str, const char *prefix)
Definition: utility.h:57
unsigned short format_version
Definition: atacmds.h:528
int ata_read_identity(ata_device *device, ata_identify_device *buf, bool fix_swapped_id, unsigned char *raw_buf)
Definition: atacmds.cpp:818
unsigned short int ata_error_count
Definition: atacmds.h:316
#define ATA_DISABLE_READ_LOOK_AHEAD
Definition: atacmds.h:84
const devstat_entry_info devstat_info_0x00[]
Definition: ataprint.cpp:1348
unsigned char device_state
Definition: atacmds.h:532
unsigned char lba_mid_register_hi
Definition: atacmds.h:366
unsigned short smart_status
Definition: atacmds.h:548
unsigned char lba_low_register_hi
Definition: atacmds.h:340
unsigned short error_log_index
Definition: atacmds.h:397
static const char * get_sata_speed(int level)
Definition: ataprint.cpp:547
static int PrintSmartExtErrorLog(ata_device *device, const firmwarebug_defs &firmwarebugs, const ata_smart_exterrlog *log, unsigned nsectors, unsigned max_errors)
Definition: ataprint.cpp:1835
unsigned short word086
Definition: atacmds.h:142
ata_smart_exterrlog_error_log error_logs[4]
Definition: atacmds.h:398
static const char * get_ata_major_version(const ata_identify_device *drive)
Definition: ataprint.cpp:441
int ataReadSelectiveSelfTestLog(ata_device *device, struct ata_selective_self_test_log *data)
Definition: atacmds.cpp:1161
bool smart_selective_selftest_log
Definition: ataprint.h:55
int TestTime(const ata_smart_values *data, int testtype)
Definition: atacmds.cpp:1677
bool smart_disable
Definition: ataprint.h:73
unsigned char device_control_register
Definition: atacmds.h:334
bool sct_temp_hist
Definition: ataprint.h:67
void ata_get_size_info(const ata_identify_device *id, ata_size_info &sizes)
Definition: atacmds.cpp:645
#define ATTRIBUTE_FLAGS_ONLINE(x)
Definition: atacmds.h:188
static const char * get_sata_version(const ata_identify_device *drive)
Definition: ataprint.cpp:528
unsigned char lba_high_register_hi
Definition: atacmds.h:368
int identify_bit_level
Definition: ataprint.h:49
#define ATA_DISABLE_AAM
Definition: atacmds.h:81
static const char * GetLogName(unsigned logaddr)
Definition: ataprint.cpp:1150
#define FAILAGE
Definition: smartctl.h:56
struct ata_smart_log_entry entry[255]
Definition: atacmds.h:481
unsigned char count_register
Definition: atacmds.h:337
unsigned char lba_low_register_hi
Definition: atacmds.h:364
u32 count
Definition: megaraid.h:80
static unsigned GetNumLogSectors(const ata_smart_log_directory *logdir, unsigned logaddr, bool gpl)
Definition: ataprint.cpp:1134
int ataGetSCTErrorRecoveryControltime(ata_device *device, unsigned type, unsigned short &time_limit)
Definition: atacmds.cpp:2707
bool smart_selftest_force
Definition: ataprint.h:78
#define EXTEND_SELF_TEST
Definition: atacmds.h:113
signed char max_temp
Definition: atacmds.h:542
int ataReadSelfTestLog(ata_device *device, ata_smart_selftestlog *data, firmwarebug_defs firmwarebugs)
Definition: atacmds.cpp:1020
#define FAILSMART
Definition: smartctl.h:46
static const char * get_form_factor(unsigned short word168)
Definition: ataprint.cpp:415
#define snprintf
Definition: utility.h:68
static const char * sct_pbar(int x, char(&buf)[64])
Definition: ataprint.cpp:2206
int ataEnableAutoSave(ata_device *device)
Definition: atacmds.cpp:1528
u16 flags
Definition: megaraid.h:93
unsigned char self_test_exec_status
Definition: atacmds.h:216
ata_smart_exterrlog_command commands[5]
Definition: atacmds.h:384
static int ataPrintSCTTempHist(const ata_sct_temperature_history_table *tmh)
Definition: ataprint.cpp:2295
bool ataReadExtSelfTestLog(ata_device *device, ata_smart_extselftestlog *log, unsigned nsectors)
Definition: atacmds.cpp:1068
#define FAILATTR
Definition: smartctl.h:52
uint64_t sectors
Definition: atacmds.h:987
static void print_device_statistics_page(const unsigned char *data, int page, bool &need_trailer)
Definition: ataprint.cpp:1437
unsigned char offline_data_collection_status
Definition: atacmds.h:215
#define FAILPOWER
Definition: smartctl.h:40
bool is_set(firmwarebug_t bug) const
Definition: atacmds.h:739
const char * ataprint_cpp_cvsid
Definition: ataprint.cpp:43
unsigned char lba_high_register_hi
Definition: atacmds.h:344
void print_off()
Definition: smartctl.h:92
ata_attr_state ata_get_attr_state(const ata_smart_attribute &attr, int attridx, const ata_smart_threshold_entry *thresholds, const ata_vendor_attr_defs &defs, unsigned char *threshval)
Definition: atacmds.cpp:1813
struct ata_smart_extselftestlog_desc log_descs[19]
Definition: atacmds.h:461
unsigned short log_desc_index
Definition: atacmds.h:460
static void PrintSmartSelfExecStatus(const ata_smart_values *data, firmwarebug_defs firmwarebugs)
Definition: ataprint.cpp:751
std::vector< int > devstat_pages
Definition: ataprint.h:65
bool ata_nodata_command(ata_device *device, unsigned char command, int sector_count)
Definition: atacmds.cpp:788
unsigned char device_register
Definition: atacmds.h:345
int ataGetSetSCTWriteCacheReordering(ata_device *device, bool enable, bool persistent, bool set)
Definition: atacmds.cpp:2504
bool nonempty(const void *data, int size)
Definition: utility.cpp:695
unsigned short sampling_period
Definition: atacmds.h:603
static std::string format_st_er_desc(unsigned char CR, unsigned char FR, unsigned char ST, unsigned char ER, unsigned short SC, const ata_smart_errorlog_error_struct *lba28_regs, const ata_smart_exterrlog_error *lba48_regs)
Definition: ataprint.cpp:74
void ata_print_identify_data(const void *id, bool all_words, int bit_level)
static void print_drive_info(const ata_identify_device *drive, const ata_size_info &sizes, int rpm, const drive_settings *dbentry)
Definition: ataprint.cpp:576
struct ata_smart_attribute vendor_attributes[NUMBER_ATA_SMART_ATTRIBUTES]
Definition: atacmds.h:214
unsigned sct_erc_writetime
Definition: ataprint.h:70
unsigned short command_set_1
Definition: atacmds.h:138
int ataDisableSmart(ata_device *device)
Definition: atacmds.cpp:1520
unsigned smart_ext_selftest_log
Definition: ataprint.h:59
unsigned char count_register_hi
Definition: atacmds.h:338
unsigned short flags
Definition: atacmds.h:155
ptr_t data
Definition: megaraid.h:94
static const char * sct_ptemp(signed char x, char(&buf)[20])
Definition: ataprint.cpp:2198
int ata_get_rotation_rate(const ata_identify_device *id)
Definition: atacmds.cpp:927
unsigned char device_register
Definition: atacmds.h:369
std::string ata_format_attr_raw_value(const ata_smart_attribute &attr, const ata_vendor_attr_defs &defs)
Definition: atacmds.cpp:1960
unsigned short command_set_2
Definition: atacmds.h:139
#define SELECTIVE_SELF_TEST
Definition: atacmds.h:115
const devstat_entry_info devstat_info_0x03[]
Definition: ataprint.cpp:1372
ata_selective_selftest_args smart_selective_args
Definition: ataprint.h:79
unsigned short pendingtime
Definition: atacmds.h:506
uint64_t start
Definition: atacmds.h:490
bool retry_error_log
Definition: ataprint.h:60
unsigned short timestamp
Definition: atacmds.h:374
#define DATEANDEPOCHLEN
Definition: utility.h:80
#define PRId64
Definition: int64.h:72
bool ataReadLogExt(ata_device *device, unsigned char logaddr, unsigned char features, unsigned page, void *data, unsigned nsectors)
Definition: atacmds.cpp:1088
#define ATA_STANDBY_IMMEDIATE
Definition: atacmds.h:78
unsigned char lba_mid_register
Definition: atacmds.h:341
bool fix_swapped_id
Definition: ataprint.h:88
const int num_devstat_infos
Definition: ataprint.cpp:1435
static void PrintSmartCapability(const ata_smart_values *data)
Definition: ataprint.cpp:880
int ataSmartSupport(const ata_identify_device *drive)
Definition: atacmds.cpp:943
unsigned char reserved
Definition: atacmds.h:473
unsigned short int smart_capability
Definition: atacmds.h:220
unsigned log_sector_offset
Definition: atacmds.h:991
static void PrintSmartExtendedSelfTestPollingTime(const ata_smart_values *data)
Definition: ataprint.cpp:928
unsigned short words088_255[168]
Definition: atacmds.h:144
#define FAILSTATUS
Definition: smartctl.h:49
int ataReadSCTStatus(ata_device *device, ata_sct_status_response *sts)
Definition: atacmds.cpp:2412
bool set_security_freeze
Definition: ataprint.h:106
static void print_apm_level(const char *msg, int level)
Definition: ataprint.cpp:2389
int ataReadSmartValues(ata_device *device, struct ata_smart_values *data)
Definition: atacmds.cpp:974
unsigned char output_format
Definition: ataprint.h:85
unsigned short sct_spec
Definition: atacmds.h:530
unsigned int over_limit_count
Definition: atacmds.h:546
unsigned log_sector_size
Definition: atacmds.h:989
static const char * get_ata_minor_version(const ata_identify_device *drive)
Definition: ataprint.cpp:458
unsigned short device_error_count
Definition: atacmds.h:399
ata_attr_state
Definition: atacmds.h:888
bool smart_auto_save_enable
Definition: ataprint.h:75
#define ABORT_SELF_TEST
Definition: atacmds.h:116
static void PrintSmartErrorLogCapability(const ata_smart_values *data, const ata_identify_device *identity)
Definition: ataprint.cpp:903
int isSupportOfflineSurfaceScan(const ata_smart_values *data)
Definition: atacmds.cpp:1795
const char * get_errmsg() const
Get last error message.
long long int64_t
Definition: int64.h:51
bool ata_set_features(ata_device *device, unsigned char features, int sector_count)
Definition: atacmds.cpp:800
bool isSCTCapable(const ata_identify_device *drive)
Definition: atacmds.h:873
static int PrintSmartExtSelfTestLog(const ata_smart_extselftestlog *log, unsigned nsectors, unsigned max_entries)
Definition: ataprint.cpp:2004
unsigned char logaddr
Definition: ataprint.h:36
unsigned char lba_low_register
Definition: atacmds.h:363
void print_on()
Definition: smartctl.h:87
unsigned char lba_low_register
Definition: atacmds.h:339
bool dont_print_serial_number
Definition: atacmds.cpp:46
#define ATTRIBUTE_FLAGS_PREFAILURE(x)
Definition: atacmds.h:178
unsigned char id
Definition: atacmds.h:152
unsigned char failuretest_permissive
Definition: smartctl.cpp:1110
static int PrintSmartErrorlog(const ata_smart_errorlog *data, firmwarebug_defs firmwarebugs)
Definition: ataprint.cpp:1720
unsigned char numsectors
Definition: atacmds.h:472
#define FAILID
Definition: smartctl.h:43
struct ata_smart_errorlog_struct errorlog_struct[5]
Definition: atacmds.h:315
bool smart_general_values
Definition: ataprint.h:51
#define ATA_ENABLE_WRITE_CACHE
Definition: atacmds.h:87
unsigned char revnumber
Definition: atacmds.h:313
unsigned short int total_time_to_complete_off_line
Definition: atacmds.h:217
const char * format_capacity(char *str, int strsize, uint64_t val, const char *decimal_point)
Definition: utility.cpp:736
unsigned int timestamp
Definition: atacmds.h:349
int isSupportConveyanceSelfTest(const ata_smart_values *data)
Definition: atacmds.cpp:1803
static void ataPrintSCTCapability(const ata_identify_device *drive)
Definition: ataprint.cpp:1085
void pout(const char *fmt,...)
Definition: smartctl.cpp:1091
#define OFFLINE_FULL_SCAN
Definition: atacmds.h:111
static void PrintLogDirectories(const ata_smart_log_directory *gplogdir, const ata_smart_log_directory *smartlogdir)
Definition: ataprint.cpp:1243
unsigned sct_temp_int
Definition: ataprint.h:81
static int ataPrintSCTStatus(const ata_sct_status_response *sts)
Definition: ataprint.cpp:2242
bool smart_selftest_log
Definition: ataprint.h:54
unsigned char fw_rev[8]
Definition: atacmds.h:133
const devstat_entry_info devstat_info_0x04[]
Definition: ataprint.cpp:1384
short size
Definition: ataprint.cpp:1344
#define ATTRIBUTE_FLAGS_SELFPRESERVING(x)
Definition: atacmds.h:203
int ataEnableAutoOffline(ata_device *device)
Definition: atacmds.cpp:1547
static const char * sct_device_state_msg(unsigned char state)
Definition: ataprint.cpp:2228
unsigned char lba_high_register
Definition: atacmds.h:367
const char * name
Definition: ataprint.cpp:1345
bool sct_temp_int_pers
Definition: ataprint.h:82
bool retry_selftest_log
Definition: ataprint.h:60
int isSupportOfflineAbort(const ata_smart_values *data)
Definition: atacmds.cpp:1791
static void print_aam_level(const char *msg, int level, int recommended=-1)
Definition: ataprint.cpp:2365
const char * modelfamily
Definition: knowndrives.h:27
const devstat_entry_info devstat_info_0x05[]
Definition: ataprint.cpp:1392
struct ata_smart_errorlog_command_struct commands[5]
Definition: atacmds.h:304
int ataPrintSmartSelfTestEntry(unsigned testnum, unsigned char test_type, unsigned char test_status, unsigned short timestamp, uint64_t failing_lba, bool print_error_only, bool &print_header)
Definition: atacmds.cpp:2724
int ataPrintMain(ata_device *device, const ata_print_options &options)
Definition: ataprint.cpp:2481
static const char * infofound(const char *output)
Definition: ataprint.cpp:47
int ataEnableSmart(ata_device *device)
Definition: atacmds.cpp:1513
bool smart_auto_offl_disable
Definition: ataprint.h:74
#define CONVEYANCE_SELF_TEST
Definition: atacmds.h:114
static const char * OfflineDataCollectionStatus(unsigned char status_byte)
Definition: ataprint.cpp:701
unsigned char error_register
Definition: atacmds.h:270
int ataReadSmartThresholds(ata_device *device, struct ata_smart_thresholds_pvt *data)
Definition: atacmds.cpp:1495
int ataDisableAutoSave(ata_device *device)
Definition: atacmds.cpp:1535
u8 b[12]
Definition: megaraid.h:96
#define SELECTIVE_FLAG_PENDING
Definition: atacmds.h:514
unsigned short cfs_enable_1
Definition: atacmds.h:141
int ataSetSCTTempInterval(ata_device *device, unsigned interval, bool persistent)
Definition: atacmds.cpp:2571
unsigned short major_rev_num
Definition: atacmds.h:136
static void PrintSmartTotalTimeCompleteOffline(const ata_smart_values *data)
Definition: ataprint.cpp:833
int isGeneralPurposeLoggingCapable(const ata_identify_device *identity)
Definition: atacmds.cpp:1746
#define ATA_ENABLE_AAM
Definition: atacmds.h:85
#define P(n)
int ata_get_wwn(const ata_identify_device *id, unsigned &oui, uint64_t &unique_id)
Definition: atacmds.cpp:907
void checksumwarning(const char *string)
Definition: smartctl.cpp:1138
bool isSCTDataTableCapable(const ata_identify_device *drive)
Definition: atacmds.h:882
#define EXTEND_CAPTIVE_SELF_TEST
Definition: atacmds.h:118
#define SELECTIVE_CAPTIVE_SELF_TEST
Definition: atacmds.h:120
unsigned char short_test_completion_time
Definition: atacmds.h:223
const ata_smart_log_directory * fake_logdir(ata_smart_log_directory *logdir, const ata_print_options &options)
Definition: ataprint.cpp:1227
static bool is_permissive()
Definition: ataprint.cpp:53
#define ATTRIBUTE_FLAGS_EVENTCOUNT(x)
Definition: atacmds.h:200
unsigned short sct_version
Definition: atacmds.h:529
unsigned char lba_mid_register
Definition: atacmds.h:365
Definition: ataprint.cpp:1342
static void PrintSmartShortSelfTestPollingTime(const ata_smart_values *data)
Definition: ataprint.cpp:918
const char * format_with_thousands_sep(char *str, int strsize, uint64_t val, const char *thousands_sep)
Definition: utility.cpp:704
static void print_standby_timer(const char *msg, int timer, const ata_identify_device &drive)
Definition: ataprint.cpp:2447
static int find_msb(unsigned short word)
Definition: ataprint.cpp:433
unsigned char device_control_register
Definition: atacmds.h:359
int ataSmartTest(ata_device *device, int testtype, bool force, const ata_selective_selftest_args &selargs, const ata_smart_values *sv, uint64_t num_sectors)
Definition: atacmds.cpp:1588
void ata_format_id_string(char *out, const unsigned char *in, int n)
Definition: atacmds.cpp:749
static void PrintSmartOfflineCollectCap(const ata_smart_values *data)
Definition: ataprint.cpp:840
unsigned char failing_lba[6]
Definition: atacmds.h:447
signed char min_temp
Definition: atacmds.h:541
unsigned char version
Definition: atacmds.h:395
#define ATTRIBUTE_FLAGS_OTHER(x)
Definition: atacmds.h:206
bool ignore_presets
Definition: ataprint.h:92
#define ATA_DISABLE_APM
Definition: atacmds.h:82
unsigned char version
Definition: atacmds.h:458
bool set_standby_now
Definition: ataprint.h:104
ATA device access.
#define SHORT_SELF_TEST
Definition: atacmds.h:112
static void PrintSataPhyEventCounters(const unsigned char *data, bool reset)
Definition: ataprint.cpp:1619
static void print_ata_security_status(const char *msg, unsigned short state)
Definition: ataprint.cpp:2409
signed char life_min_temp
Definition: atacmds.h:543
unsigned char state
Definition: atacmds.h:373
unsigned char serial_no[20]
Definition: atacmds.h:131
int ataPrintSmartSelfTestlog(const ata_smart_selftestlog *data, bool allentries, firmwarebug_defs firmwarebugs)
Definition: atacmds.cpp:2804
unsigned char * data()
Definition: utility.h:166
unsigned long long uint64_t
Definition: int64.h:54
static const char * get_sata_maxspeed(const ata_identify_device *drive)
Definition: ataprint.cpp:559
unsigned short timestamp
Definition: atacmds.h:445
#define ATA_IDLE
Definition: atacmds.h:74
unsigned short int logversion
Definition: atacmds.h:480
unsigned char conveyance_test_completion_time
Definition: atacmds.h:225
unsigned char reserved1
Definition: atacmds.h:396
int isSupportAutomaticTimer(const ata_smart_values *data)
Definition: atacmds.cpp:1787
struct ata_smart_threshold_entry thres_entries[NUMBER_ATA_SMART_ATTRIBUTES]
Definition: atacmds.h:258
const devstat_entry_info devstat_info_0x01[]
Definition: ataprint.cpp:1353
bool devstat_all_pages
Definition: ataprint.h:64
bool isSCTErrorRecoveryControlCapable(const ata_identify_device *drive)
Definition: atacmds.h:876
int ataSmartStatus2(ata_device *device)
Definition: atacmds.cpp:1581
unsigned int under_limit_count
Definition: atacmds.h:547
bool smart_vendor_attrib
Definition: ataprint.h:52
const devstat_entry_info devstat_info_0x07[]
Definition: ataprint.cpp:1418
unsigned char offline_data_collection_capability
Definition: atacmds.h:219
unsigned char powermode
Definition: ataprint.h:94
signed char life_max_temp
Definition: atacmds.h:544
bool smart_check_status
Definition: ataprint.h:50
static bool print_device_statistics(ata_device *device, unsigned nsectors, const std::vector< int > &single_pages, bool all_pages, bool ssd_page, bool use_gplog)
Definition: ataprint.cpp:1508
unsigned char status_register
Definition: atacmds.h:370
unsigned short flags
Definition: atacmds.h:504
int ataReadSCTTempHist(ata_device *device, ata_sct_temperature_history_table *tmh, ata_sct_status_response *sts)
Definition: atacmds.cpp:2443
static std::string format_milliseconds(unsigned msec)
Definition: ataprint.cpp:1685
unsigned sct_erc_readtime
Definition: ataprint.h:70
std::string strprintf(const char *fmt,...)
Definition: utility.cpp:787
unsigned char byte205
Definition: atacmds.h:545
static void ataPrintSCTErrorRecoveryControl(bool set, unsigned short read_timer, unsigned short write_timer)
Definition: ataprint.cpp:2352
bool smart_auto_save_disable
Definition: ataprint.h:75
unsigned nsectors
Definition: ataprint.h:38
#define ATTRIBUTE_FLAGS_PERFORMANCE(x)
Definition: atacmds.h:194
int ataDisableAutoOffline(ata_device *device)
Definition: atacmds.cpp:1558
const devstat_entry_info devstat_info_0x02[]
Definition: ataprint.cpp:1365
void failuretest(failure_type type, int returnvalue)
Definition: smartctl.cpp:1115
unsigned short int revnumber
Definition: atacmds.h:213
uint64_t capacity
Definition: atacmds.h:988
unsigned char vendor_specific[32]
Definition: atacmds.h:550
unsigned char model[40]
Definition: atacmds.h:134
std::vector< ata_log_request > log_requests
Definition: ataprint.h:62
#define ATA_ENABLE_READ_LOOK_AHEAD
Definition: atacmds.h:88
int isSmartErrorLogCapable(const ata_smart_values *data, const ata_identify_device *identity)
Definition: atacmds.cpp:1708
int isSupportSelfTest(const ata_smart_values *data)
Definition: atacmds.cpp:1799
u8 cmd
Definition: megaraid.h:80
unsigned char worst
Definition: atacmds.h:157
static void PrintSmartConveyanceSelfTestPollingTime(const ata_smart_values *data)
Definition: ataprint.cpp:938
bool devstat_ssd_page
Definition: ataprint.h:64
static void PrintGeneralSmartValues(const ata_smart_values *data, const ata_identify_device *drive, firmwarebug_defs firmwarebugs)
Definition: ataprint.cpp:1100
int ataReadErrorLog(ata_device *device, ata_smart_errorlog *data, firmwarebug_defs firmwarebugs)
Definition: atacmds.cpp:1401
void clear_err()
Clear last error info.
unsigned smart_ext_error_log
Definition: ataprint.h:58
unsigned char error_log_pointer
Definition: atacmds.h:314
#define ATAPRINT_H_CVSID
Definition: ataprint.h:28
static void ataPrintSelectiveSelfTestLog(const ata_selective_self_test_log *log, const ata_smart_values *sv)
Definition: ataprint.cpp:2079
unsigned char lba_mid_register_hi
Definition: atacmds.h:342
int ataSetSCTErrorRecoveryControltime(ata_device *device, unsigned type, unsigned short time_limit)
Definition: atacmds.cpp:2713
#define SELECTIVE_FLAG_ACTIVE
Definition: atacmds.h:515
int identify_word_level
Definition: ataprint.h:49
void show_presets(const ata_identify_device *drive)
int ataDoesSmartWork(ata_device *device)
Definition: atacmds.cpp:1570
unsigned char features_register_hi
Definition: atacmds.h:336
bool isSCTFeatureControlCapable(const ata_identify_device *drive)
Definition: atacmds.h:879
signed char hda_temp
Definition: atacmds.h:540
#define SELECTIVE_FLAG_DOSCAN
Definition: atacmds.h:513
int sct_wcache_reorder_set
Definition: ataprint.h:110
virtual bool ata_identify_is_cached() const
Return true if OS caches ATA identify sector.
#define ATA_SECURITY_FREEZE_LOCK
Definition: atacmds.h:76
unsigned char count_register_hi
Definition: atacmds.h:362
const devstat_entry_info * devstat_infos[]
Definition: ataprint.cpp:1424
int ataReadLogDirectory(ata_device *device, ata_smart_log_directory *data, bool gpl)
Definition: atacmds.cpp:1141
struct ata_smart_errorlog_error_struct error_struct
Definition: atacmds.h:305
bool ataReadSmartLog(ata_device *device, unsigned char logaddr, void *data, unsigned nsectors)
Definition: atacmds.cpp:1120
#define PRIx64
Definition: int64.h:80
virtual bool is_syscall_unsup() const
Return true if last error indicates an unsupported system call.
unsigned char command_register
Definition: atacmds.h:346
int ataCheckPowerMode(ata_device *device)
Definition: atacmds.cpp:775
#define ATA_DISABLE_WRITE_CACHE
Definition: atacmds.h:83
bool printing_is_switchable
Definition: smartctl.cpp:58
#define ATTRIBUTE_FLAGS_ERRORRATE(x)
Definition: atacmds.h:197
unsigned char count_register
Definition: atacmds.h:361
unsigned short logversion
Definition: atacmds.h:498
static int find_failed_attr(const ata_smart_values *data, const ata_smart_thresholds_pvt *thresholds, const ata_vendor_attr_defs &defs, int onlyfailed)
Definition: ataprint.cpp:951
#define FAILLOG
Definition: smartctl.h:62
unsigned char error_register
Definition: atacmds.h:360
bool sataphy_reset
Definition: ataprint.h:71
#define SHORT_CAPTIVE_SELF_TEST
Definition: atacmds.h:117
unsigned char lba_high_register
Definition: atacmds.h:343
bool smart_auto_offl_enable
Definition: ataprint.h:74
const char * look_up_ata_command(unsigned char c_code, unsigned char f_reg)
int isSmartTestLogCapable(const ata_smart_values *data, const ata_identify_device *identity)
Definition: atacmds.cpp:1727