]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - ataprint.cpp
Imported smartmontools-5.27.cvs20061002
[mirror_smartmontools-debian.git] / ataprint.cpp
1 /*
2 * ataprint.cpp
3 *
4 * Home page of code is: http://smartmontools.sourceforge.net
5 *
6 * Copyright (C) 2002-6 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * You should have received a copy of the GNU General Public License
15 * (for example COPYING); if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 <string.h>
31 #ifdef HAVE_LOCALE_H
32 #include <locale.h>
33 #endif // #ifdef HAVE_LOCALE_H
34
35 #include "int64.h"
36 #include "atacmdnames.h"
37 #include "atacmds.h"
38 #include "ataprint.h"
39 #include "smartctl.h"
40 #include "extern.h"
41 #include "utility.h"
42 #include "knowndrives.h"
43
44 const char *ataprint_c_cvsid="$Id: ataprint.cpp,v 1.168 2006/09/17 09:34:29 shattered Exp $"
45 ATACMDNAMES_H_CVSID ATACMDS_H_CVSID ATAPRINT_H_CVSID CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID KNOWNDRIVES_H_CVSID SMARTCTL_H_CVSID UTILITY_H_CVSID;
46
47 // for passing global control variables
48 extern smartmonctrl *con;
49
50 // to hold onto exit code for atexit routine
51 extern int exitstatus;
52
53 // Copies n bytes (or n-1 if n is odd) from in to out, but swaps adjacents
54 // bytes.
55 void swapbytes(char *out, const char *in, size_t n)
56 {
57 size_t i;
58
59 for (i = 0; i < n; i += 2) {
60 out[i] = in[i+1];
61 out[i+1] = in[i];
62 }
63 }
64
65 // Copies in to out, but removes leading and trailing whitespace.
66 void trim(char *out, const char *in)
67 {
68 int i, first, last;
69
70 // Find the first non-space character (maybe none).
71 first = -1;
72 for (i = 0; in[i]; i++)
73 if (!isspace((int)in[i])) {
74 first = i;
75 break;
76 }
77
78 if (first == -1) {
79 // There are no non-space characters.
80 out[0] = '\0';
81 return;
82 }
83
84 // Find the last non-space character.
85 for (i = strlen(in)-1; i >= first && isspace((int)in[i]); i--)
86 ;
87 last = i;
88
89 strncpy(out, in+first, last-first+1);
90 out[last-first+1] = '\0';
91 }
92
93 // Convenience function for formatting strings from ata_identify_device
94 void formatdriveidstring(char *out, const char *in, int n)
95 {
96 char tmp[65];
97
98 n = n > 64 ? 64 : n;
99 #ifndef __NetBSD__
100 swapbytes(tmp, in, n);
101 #else
102 if (isbigendian())
103 strncpy(tmp, in, n);
104 else
105 swapbytes(tmp, in, n);
106 #endif
107 tmp[n] = '\0';
108 trim(out, tmp);
109 }
110
111 void infofound(char *output) {
112 if (*output)
113 pout("%s\n", output);
114 else
115 pout("[No Information Found]\n");
116 }
117
118
119 /* For the given Command Register (CR) and Features Register (FR), attempts
120 * to construct a string that describes the contents of the Status
121 * Register (ST) and Error Register (ER). The string is dynamically allocated
122 * memory and the return value is a pointer to this string. It is up to the
123 * caller to free this memory. If there is insufficient memory or if the
124 * meanings of the flags of the error register are not known for the given
125 * command then it returns NULL.
126 *
127 * The meanings of the flags of the error register for all commands are
128 * described in the ATA spec and could all be supported here in theory.
129 * Currently, only a few commands are supported (those that have been seen
130 * to produce errors). If many more are to be added then this function
131 * should probably be redesigned.
132 */
133 char *construct_st_er_desc(struct ata_smart_errorlog_struct *data) {
134 unsigned char CR=data->commands[4].commandreg;
135 unsigned char FR=data->commands[4].featuresreg;
136 unsigned char ST=data->error_struct.status;
137 unsigned char ER=data->error_struct.error_register;
138 char *s;
139 const char *error_flag[8];
140 int i, print_lba=0, print_sector=0;
141
142 // Set of character strings corresponding to different error codes.
143 // Please keep in alphabetic order if you add more.
144 const char *abrt = "ABRT"; // ABORTED
145 const char *amnf = "AMNF"; // ADDRESS MARK NOT FOUND
146 const char *ccto = "CCTO"; // COMMAND COMPLETTION TIMED OUT
147 const char *eom = "EOM"; // END OF MEDIA
148 const char *icrc = "ICRC"; // INTERFACE CRC ERROR
149 const char *idnf = "IDNF"; // ID NOT FOUND
150 const char *ili = "ILI"; // MEANING OF THIS BIT IS COMMAND-SET SPECIFIC
151 const char *mc = "MC"; // MEDIA CHANGED
152 const char *mcr = "MCR"; // MEDIA CHANGE REQUEST
153 const char *nm = "NM"; // NO MEDIA
154 const char *obs = "obs"; // OBSOLETE
155 const char *tk0nf = "TK0NF"; // TRACK 0 NOT FOUND
156 const char *unc = "UNC"; // UNCORRECTABLE
157 const char *wp = "WP"; // WRITE PROTECTED
158
159 /* If for any command the Device Fault flag of the status register is
160 * not used then used_device_fault should be set to 0 (in the CR switch
161 * below)
162 */
163 int uses_device_fault = 1;
164
165 /* A value of NULL means that the error flag isn't used */
166 for (i = 0; i < 8; i++)
167 error_flag[i] = NULL;
168
169 switch (CR) {
170 case 0x10: // RECALIBRATE
171 error_flag[2] = abrt;
172 error_flag[1] = tk0nf;
173 break;
174 case 0x20: /* READ SECTOR(S) */
175 case 0x21: // READ SECTOR(S)
176 case 0x24: // READ SECTOR(S) EXT
177 case 0xC4: /* READ MULTIPLE */
178 case 0x29: // READ MULTIPLE EXT
179 error_flag[6] = unc;
180 error_flag[5] = mc;
181 error_flag[4] = idnf;
182 error_flag[3] = mcr;
183 error_flag[2] = abrt;
184 error_flag[1] = nm;
185 error_flag[0] = amnf;
186 print_lba=1;
187 break;
188 case 0x22: // READ LONG (with retries)
189 case 0x23: // READ LONG (without retries)
190 error_flag[4] = idnf;
191 error_flag[2] = abrt;
192 error_flag[0] = amnf;
193 print_lba=1;
194 break;
195 case 0x2a: // READ STREAM DMA
196 case 0x2b: // READ STREAM PIO
197 if (CR==0x2a)
198 error_flag[7] = icrc;
199 error_flag[6] = unc;
200 error_flag[5] = mc;
201 error_flag[4] = idnf;
202 error_flag[3] = mcr;
203 error_flag[2] = abrt;
204 error_flag[1] = nm;
205 error_flag[0] = ccto;
206 print_lba=1;
207 print_sector=(int)data->error_struct.sector_count;
208 break;
209 case 0x3A: // WRITE STREAM DMA
210 case 0x3B: // WRITE STREAM PIO
211 if (CR==0x3A)
212 error_flag[7] = icrc;
213 error_flag[6] = wp;
214 error_flag[5] = mc;
215 error_flag[4] = idnf;
216 error_flag[3] = mcr;
217 error_flag[2] = abrt;
218 error_flag[1] = nm;
219 error_flag[0] = ccto;
220 print_lba=1;
221 print_sector=(int)data->error_struct.sector_count;
222 break;
223 case 0x25: /* READ DMA EXT */
224 case 0x26: // READ DMA QUEUED EXT
225 case 0xC7: // READ DMA QUEUED
226 case 0xC8: /* READ DMA */
227 case 0xC9:
228 error_flag[7] = icrc;
229 error_flag[6] = unc;
230 error_flag[5] = mc;
231 error_flag[4] = idnf;
232 error_flag[3] = mcr;
233 error_flag[2] = abrt;
234 error_flag[1] = nm;
235 error_flag[0] = amnf;
236 print_lba=1;
237 if (CR==0x25 || CR==0xC8)
238 print_sector=(int)data->error_struct.sector_count;
239 break;
240 case 0x30: /* WRITE SECTOR(S) */
241 case 0x31: // WRITE SECTOR(S)
242 case 0x34: // WRITE SECTOR(S) EXT
243 case 0xC5: /* WRITE MULTIPLE */
244 case 0x39: // WRITE MULTIPLE EXT
245 case 0xCE: // WRITE MULTIPLE FUA EXT
246 error_flag[6] = wp;
247 error_flag[5] = mc;
248 error_flag[4] = idnf;
249 error_flag[3] = mcr;
250 error_flag[2] = abrt;
251 error_flag[1] = nm;
252 print_lba=1;
253 break;
254 case 0x32: // WRITE LONG (with retries)
255 case 0x33: // WRITE LONG (without retries)
256 error_flag[4] = idnf;
257 error_flag[2] = abrt;
258 print_lba=1;
259 break;
260 case 0x3C: // WRITE VERIFY
261 error_flag[6] = unc;
262 error_flag[4] = idnf;
263 error_flag[2] = abrt;
264 error_flag[0] = amnf;
265 print_lba=1;
266 break;
267 case 0x40: // READ VERIFY SECTOR(S) with retries
268 case 0x41: // READ VERIFY SECTOR(S) without retries
269 case 0x42: // READ VERIFY SECTOR(S) EXT
270 error_flag[6] = unc;
271 error_flag[5] = mc;
272 error_flag[4] = idnf;
273 error_flag[3] = mcr;
274 error_flag[2] = abrt;
275 error_flag[1] = nm;
276 error_flag[0] = amnf;
277 print_lba=1;
278 break;
279 case 0xA0: /* PACKET */
280 /* Bits 4-7 are all used for sense key (a 'command packet set specific error
281 * indication' according to the ATA/ATAPI-7 standard), so "Sense key" will
282 * be repeated in the error description string if more than one of those
283 * bits is set.
284 */
285 error_flag[7] = "Sense key (bit 3)",
286 error_flag[6] = "Sense key (bit 2)",
287 error_flag[5] = "Sense key (bit 1)",
288 error_flag[4] = "Sense key (bit 0)",
289 error_flag[2] = abrt;
290 error_flag[1] = eom;
291 error_flag[0] = ili;
292 break;
293 case 0xA1: /* IDENTIFY PACKET DEVICE */
294 case 0xEF: /* SET FEATURES */
295 case 0x00: /* NOP */
296 case 0xC6: /* SET MULTIPLE MODE */
297 error_flag[2] = abrt;
298 break;
299 case 0x2F: // READ LOG EXT
300 error_flag[6] = unc;
301 error_flag[4] = idnf;
302 error_flag[2] = abrt;
303 error_flag[0] = obs;
304 break;
305 case 0x3F: // WRITE LOG EXT
306 error_flag[4] = idnf;
307 error_flag[2] = abrt;
308 error_flag[0] = obs;
309 break;
310 case 0xB0: /* SMART */
311 switch(FR) {
312 case 0xD0: // SMART READ DATA
313 case 0xD1: // SMART READ ATTRIBUTE THRESHOLDS
314 case 0xD5: /* SMART READ LOG */
315 error_flag[6] = unc;
316 error_flag[4] = idnf;
317 error_flag[2] = abrt;
318 error_flag[0] = obs;
319 break;
320 case 0xD6: /* SMART WRITE LOG */
321 error_flag[4] = idnf;
322 error_flag[2] = abrt;
323 error_flag[0] = obs;
324 break;
325 case 0xD2: // Enable/Disable Attribute Autosave
326 case 0xD3: // SMART SAVE ATTRIBUTE VALUES (ATA-3)
327 case 0xD8: // SMART ENABLE OPERATIONS
328 case 0xD9: /* SMART DISABLE OPERATIONS */
329 case 0xDA: /* SMART RETURN STATUS */
330 case 0xDB: // Enable/Disable Auto Offline (SFF)
331 error_flag[2] = abrt;
332 break;
333 case 0xD4: // SMART EXECUTE IMMEDIATE OFFLINE
334 error_flag[4] = idnf;
335 error_flag[2] = abrt;
336 break;
337 default:
338 return NULL;
339 break;
340 }
341 break;
342 case 0xB1: /* DEVICE CONFIGURATION */
343 switch (FR) {
344 case 0xC0: /* DEVICE CONFIGURATION RESTORE */
345 error_flag[2] = abrt;
346 break;
347 default:
348 return NULL;
349 break;
350 }
351 break;
352 case 0xCA: /* WRITE DMA */
353 case 0xCB:
354 case 0x35: // WRITE DMA EXT
355 case 0x3D: // WRITE DMA FUA EXT
356 case 0xCC: // WRITE DMA QUEUED
357 case 0x36: // WRITE DMA QUEUED EXT
358 case 0x3E: // WRITE DMA QUEUED FUA EXT
359 error_flag[7] = icrc;
360 error_flag[6] = wp;
361 error_flag[5] = mc;
362 error_flag[4] = idnf;
363 error_flag[3] = mcr;
364 error_flag[2] = abrt;
365 error_flag[1] = nm;
366 error_flag[0] = amnf;
367 print_lba=1;
368 if (CR==0x35)
369 print_sector=(int)data->error_struct.sector_count;
370 break;
371 case 0xE4: // READ BUFFER
372 case 0xE8: // WRITE BUFFER
373 error_flag[2] = abrt;
374 break;
375 default:
376 return NULL;
377 }
378
379 /* 256 bytes -- that'll be plenty (OK, this is lazy!) */
380 if (!(s = (char *)malloc(256)))
381 return s;
382
383 s[0] = '\0';
384
385 /* We ignore any status flags other than Device Fault and Error */
386
387 if (uses_device_fault && (ST & (1 << 5))) {
388 strcat(s, "Device Fault");
389 if (ST & 1) // Error flag
390 strcat(s, "; ");
391 }
392 if (ST & 1) { // Error flag
393 int count = 0;
394
395 strcat(s, "Error: ");
396 for (i = 7; i >= 0; i--)
397 if ((ER & (1 << i)) && (error_flag[i])) {
398 if (count++ > 0)
399 strcat(s, ", ");
400 strcat(s, error_flag[i]);
401 }
402 }
403
404 // If the error was a READ or WRITE error, print the Logical Block
405 // Address (LBA) at which the read or write failed.
406 if (print_lba) {
407 char tmp[128];
408 int lba;
409
410 // bits 24-27: bits 0-3 of DH
411 lba = 0xf & data->error_struct.drive_head;
412 lba <<= 8;
413 // bits 16-23: CH
414 lba |= data->error_struct.cylinder_high;
415 lba <<= 8;
416 // bits 8-15: CL
417 lba |= data->error_struct.cylinder_low;
418 lba <<= 8;
419 // bits 0-7: SN
420 lba |= data->error_struct.sector_number;
421
422 // print number of sectors, if known, and append to print string
423 if (print_sector) {
424 snprintf(tmp, 128, " %d sectors", print_sector);
425 strcat(s, tmp);
426 }
427
428 // print LBA, and append to print string
429 snprintf(tmp, 128, " at LBA = 0x%08x = %d", lba, lba);
430 strcat(s, tmp);
431 }
432
433 return s;
434 }
435
436 // This returns the capacity of a disk drive and also prints this into
437 // a string, using comma separators to make it easier to read. If the
438 // drive doesn't support LBA addressing or has no user writable
439 // sectors (eg, CDROM or DVD) then routine returns zero.
440 uint64_t determine_capacity(struct ata_identify_device *drive, char *pstring){
441
442 unsigned short command_set_2 = drive->command_set_2;
443 unsigned short capabilities_0 = drive->words047_079[49-47];
444 unsigned short sects_16 = drive->words047_079[60-47];
445 unsigned short sects_32 = drive->words047_079[61-47];
446 unsigned short lba_16 = drive->words088_255[100-88];
447 unsigned short lba_32 = drive->words088_255[101-88];
448 unsigned short lba_48 = drive->words088_255[102-88];
449 unsigned short lba_64 = drive->words088_255[103-88];
450 uint64_t capacity_short=0, capacity=0, threedigits, power_of_ten;
451 int started=0,k=1000000000;
452 char separator=',';
453
454 // get correct character to use as thousands separator
455 #ifdef HAVE_LOCALE_H
456 struct lconv *currentlocale=NULL;
457 setlocale (LC_ALL, "");
458 currentlocale=localeconv();
459 if (*(currentlocale->thousands_sep))
460 separator=*(currentlocale->thousands_sep);
461 #endif // #ifdef HAVE_LOCALE_H
462
463 // if drive supports LBA addressing, determine 32-bit LBA capacity
464 if (capabilities_0 & 0x0200) {
465 capacity_short = (unsigned int)sects_32 << 16 |
466 (unsigned int)sects_16 << 0 ;
467
468 // if drive supports 48-bit addressing, determine THAT capacity
469 if ((command_set_2 & 0xc000) == 0x4000 && (command_set_2 & 0x0400))
470 capacity = (uint64_t)lba_64 << 48 |
471 (uint64_t)lba_48 << 32 |
472 (uint64_t)lba_32 << 16 |
473 (uint64_t)lba_16 << 0 ;
474
475 // choose the larger of the two possible capacities
476 if (capacity_short>capacity)
477 capacity=capacity_short;
478 }
479
480 // turn sectors into bytes
481 capacity_short = (capacity *= 512);
482
483 // print with locale-specific separators (default is comma)
484 power_of_ten = k;
485 power_of_ten *= k;
486
487 for (k=0; k<7; k++) {
488 threedigits = capacity/power_of_ten;
489 capacity -= threedigits*power_of_ten;
490 if (started)
491 // we have already printed some digits
492 pstring += sprintf(pstring, "%c%03"PRIu64, separator, threedigits);
493 else if (threedigits || k==6) {
494 // these are the first digits that we are printing
495 pstring += sprintf(pstring, "%"PRIu64, threedigits);
496 started = 1;
497 }
498 if (k!=6)
499 power_of_ten /= 1000;
500 }
501
502 return capacity_short;
503 }
504
505 int ataPrintDriveInfo (struct ata_identify_device *drive){
506 int version, drivetype;
507 const char *description;
508 char unknown[64], timedatetz[DATEANDEPOCHLEN];
509 unsigned short minorrev;
510 char model[64], serial[64], firm[64], capacity[64];
511
512 // format drive information (with byte swapping as needed)
513 formatdriveidstring(model, (char *)drive->model,40);
514 formatdriveidstring(serial, (char *)drive->serial_no,20);
515 formatdriveidstring(firm, (char *)drive->fw_rev,8);
516
517 // print out model, serial # and firmware versions (byte-swap ASCI strings)
518 drivetype=lookupdrive(model, firm);
519
520 // Print model family if known
521 if (drivetype>=0 && knowndrives[drivetype].modelfamily)
522 pout("Model Family: %s\n", knowndrives[drivetype].modelfamily);
523
524 pout("Device Model: ");
525 infofound(model);
526 pout("Serial Number: ");
527 infofound(serial);
528 pout("Firmware Version: ");
529 infofound(firm);
530
531 if (determine_capacity(drive, capacity))
532 pout("User Capacity: %s bytes\n", capacity);
533
534 // See if drive is recognized
535 pout("Device is: %s\n", drivetype<0?
536 "Not in smartctl database [for details use: -P showall]":
537 "In smartctl database [for details use: -P show]");
538
539 // now get ATA version info
540 version=ataVersionInfo(&description,drive, &minorrev);
541
542 // unrecognized minor revision code
543 if (!description){
544 if (!minorrev)
545 sprintf(unknown, "Exact ATA specification draft version not indicated");
546 else
547 sprintf(unknown,"Not recognized. Minor revision code: 0x%02hx", minorrev);
548 description=unknown;
549 }
550
551
552 // SMART Support was first added into the ATA/ATAPI-3 Standard with
553 // Revision 3 of the document, July 25, 1995. Look at the "Document
554 // Status" revision commands at the beginning of
555 // http://www.t13.org/project/d2008r6.pdf to see this. So it's not
556 // enough to check if we are ATA-3. Version=-3 indicates ATA-3
557 // BEFORE Revision 3.
558 pout("ATA Version is: %d\n",(int)abs(version));
559 pout("ATA Standard is: %s\n",description);
560
561 // print current time and date and timezone
562 dateandtimezone(timedatetz);
563 pout("Local Time is: %s\n", timedatetz);
564
565 // Print warning message, if there is one
566 if (drivetype>=0 && knowndrives[drivetype].warningmsg)
567 pout("\n==> WARNING: %s\n\n", knowndrives[drivetype].warningmsg);
568
569 if (version>=3)
570 return drivetype;
571
572 pout("SMART is only available in ATA Version 3 Revision 3 or greater.\n");
573 pout("We will try to proceed in spite of this.\n");
574 return drivetype;
575 }
576
577
578 const char *OfflineDataCollectionStatus(unsigned char status_byte){
579 unsigned char stat=status_byte & 0x7f;
580
581 switch(stat){
582 case 0x00:
583 return "was never started";
584 case 0x02:
585 return "was completed without error";
586 case 0x03:
587 if (status_byte == 0x03)
588 return "is in progress";
589 else
590 return "is in a Reserved state";
591 case 0x04:
592 return "was suspended by an interrupting command from host";
593 case 0x05:
594 return "was aborted by an interrupting command from host";
595 case 0x06:
596 return "was aborted by the device with a fatal error";
597 default:
598 if (stat >= 0x40)
599 return "is in a Vendor Specific state\n";
600 else
601 return "is in a Reserved state\n";
602 }
603 }
604
605
606 /* prints verbose value Off-line data collection status byte */
607 void PrintSmartOfflineStatus(struct ata_smart_values *data){
608
609 pout("Offline data collection status: (0x%02x)\t",
610 (int)data->offline_data_collection_status);
611
612 // Off-line data collection status byte is not a reserved
613 // or vendor specific value
614 pout("Offline data collection activity\n"
615 "\t\t\t\t\t%s.\n", OfflineDataCollectionStatus(data->offline_data_collection_status));
616
617 // Report on Automatic Data Collection Status. Only IBM documents
618 // this bit. See SFF 8035i Revision 2 for details.
619 if (data->offline_data_collection_status & 0x80)
620 pout("\t\t\t\t\tAuto Offline Data Collection: Enabled.\n");
621 else
622 pout("\t\t\t\t\tAuto Offline Data Collection: Disabled.\n");
623
624 return;
625 }
626
627 void PrintSmartSelfExecStatus(struct ata_smart_values *data)
628 {
629 pout("Self-test execution status: ");
630
631 switch (data->self_test_exec_status >> 4)
632 {
633 case 0:
634 pout("(%4d)\tThe previous self-test routine completed\n\t\t\t\t\t",
635 (int)data->self_test_exec_status);
636 pout("without error or no self-test has ever \n\t\t\t\t\tbeen run.\n");
637 break;
638 case 1:
639 pout("(%4d)\tThe self-test routine was aborted by\n\t\t\t\t\t",
640 (int)data->self_test_exec_status);
641 pout("the host.\n");
642 break;
643 case 2:
644 pout("(%4d)\tThe self-test routine was interrupted\n\t\t\t\t\t",
645 (int)data->self_test_exec_status);
646 pout("by the host with a hard or soft reset.\n");
647 break;
648 case 3:
649 pout("(%4d)\tA fatal error or unknown test error\n\t\t\t\t\t",
650 (int)data->self_test_exec_status);
651 pout("occurred while the device was executing\n\t\t\t\t\t");
652 pout("its self-test routine and the device \n\t\t\t\t\t");
653 pout("was unable to complete the self-test \n\t\t\t\t\t");
654 pout("routine.\n");
655 break;
656 case 4:
657 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
658 (int)data->self_test_exec_status);
659 pout("a test element that failed and the test\n\t\t\t\t\t");
660 pout("element that failed is not known.\n");
661 break;
662 case 5:
663 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
664 (int)data->self_test_exec_status);
665 pout("the electrical element of the test\n\t\t\t\t\t");
666 pout("failed.\n");
667 break;
668 case 6:
669 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
670 (int)data->self_test_exec_status);
671 pout("the servo (and/or seek) element of the \n\t\t\t\t\t");
672 pout("test failed.\n");
673 break;
674 case 7:
675 pout("(%4d)\tThe previous self-test completed having\n\t\t\t\t\t",
676 (int)data->self_test_exec_status);
677 pout("the read element of the test failed.\n");
678 break;
679 case 15:
680 pout("(%4d)\tSelf-test routine in progress...\n\t\t\t\t\t",
681 (int)data->self_test_exec_status);
682 pout("%1d0%% of test remaining.\n",
683 (int)(data->self_test_exec_status & 0x0f));
684 break;
685 default:
686 pout("(%4d)\tReserved.\n",
687 (int)data->self_test_exec_status);
688 break;
689 }
690
691 }
692
693
694
695 void PrintSmartTotalTimeCompleteOffline ( struct ata_smart_values *data){
696 pout("Total time to complete Offline \n");
697 pout("data collection: \t\t (%4d) seconds.\n",
698 (int)data->total_time_to_complete_off_line);
699 }
700
701
702
703 void PrintSmartOfflineCollectCap(struct ata_smart_values *data){
704 pout("Offline data collection\n");
705 pout("capabilities: \t\t\t (0x%02x) ",
706 (int)data->offline_data_collection_capability);
707
708 if (data->offline_data_collection_capability == 0x00){
709 pout("\tOffline data collection not supported.\n");
710 }
711 else {
712 pout( "%s\n", isSupportExecuteOfflineImmediate(data)?
713 "SMART execute Offline immediate." :
714 "No SMART execute Offline immediate.");
715
716 pout( "\t\t\t\t\t%s\n", isSupportAutomaticTimer(data)?
717 "Auto Offline data collection on/off support.":
718 "No Auto Offline data collection support.");
719
720 pout( "\t\t\t\t\t%s\n", isSupportOfflineAbort(data)?
721 "Abort Offline collection upon new\n\t\t\t\t\tcommand.":
722 "Suspend Offline collection upon new\n\t\t\t\t\tcommand.");
723
724 pout( "\t\t\t\t\t%s\n", isSupportOfflineSurfaceScan(data)?
725 "Offline surface scan supported.":
726 "No Offline surface scan supported.");
727
728 pout( "\t\t\t\t\t%s\n", isSupportSelfTest(data)?
729 "Self-test supported.":
730 "No Self-test supported.");
731
732 pout( "\t\t\t\t\t%s\n", isSupportConveyanceSelfTest(data)?
733 "Conveyance Self-test supported.":
734 "No Conveyance Self-test supported.");
735
736 pout( "\t\t\t\t\t%s\n", isSupportSelectiveSelfTest(data)?
737 "Selective Self-test supported.":
738 "No Selective Self-test supported.");
739 }
740 }
741
742
743
744 void PrintSmartCapability ( struct ata_smart_values *data)
745 {
746 pout("SMART capabilities: ");
747 pout("(0x%04x)\t", (int)data->smart_capability);
748
749 if (data->smart_capability == 0x00)
750 {
751 pout("Automatic saving of SMART data\t\t\t\t\tis not implemented.\n");
752 }
753 else
754 {
755
756 pout( "%s\n", (data->smart_capability & 0x01)?
757 "Saves SMART data before entering\n\t\t\t\t\tpower-saving mode.":
758 "Does not save SMART data before\n\t\t\t\t\tentering power-saving mode.");
759
760 if ( data->smart_capability & 0x02 )
761 {
762 pout("\t\t\t\t\tSupports SMART auto save timer.\n");
763 }
764 }
765 }
766
767 void PrintSmartErrorLogCapability (struct ata_smart_values *data, struct ata_identify_device *identity)
768 {
769
770 pout("Error logging capability: ");
771
772 if ( isSmartErrorLogCapable(data, identity) )
773 {
774 pout(" (0x%02x)\tError logging supported.\n",
775 (int)data->errorlog_capability);
776 }
777 else {
778 pout(" (0x%02x)\tError logging NOT supported.\n",
779 (int)data->errorlog_capability);
780 }
781 }
782
783 void PrintSmartShortSelfTestPollingTime(struct ata_smart_values *data){
784 pout("Short self-test routine \n");
785 if (isSupportSelfTest(data))
786 pout("recommended polling time: \t (%4d) minutes.\n",
787 (int)data->short_test_completion_time);
788 else
789 pout("recommended polling time: \t Not Supported.\n");
790 }
791
792 void PrintSmartExtendedSelfTestPollingTime(struct ata_smart_values *data){
793 pout("Extended self-test routine\n");
794 if (isSupportSelfTest(data))
795 pout("recommended polling time: \t (%4d) minutes.\n",
796 (int)data->extend_test_completion_time);
797 else
798 pout("recommended polling time: \t Not Supported.\n");
799 }
800
801 void PrintSmartConveyanceSelfTestPollingTime(struct ata_smart_values *data){
802 pout("Conveyance self-test routine\n");
803 if (isSupportConveyanceSelfTest(data))
804 pout("recommended polling time: \t (%4d) minutes.\n",
805 (int)data->conveyance_test_completion_time);
806 else
807 pout("recommended polling time: \t Not Supported.\n");
808 }
809
810 // onlyfailed=0 : print all attribute values
811 // onlyfailed=1: just ones that are currently failed and have prefailure bit set
812 // onlyfailed=2: ones that are failed, or have failed with or without prefailure bit set
813 void PrintSmartAttribWithThres (struct ata_smart_values *data,
814 struct ata_smart_thresholds_pvt *thresholds,
815 int onlyfailed){
816 int i;
817 int needheader=1;
818 char rawstring[64];
819
820 // step through all vendor attributes
821 for (i=0; i<NUMBER_ATA_SMART_ATTRIBUTES; i++){
822 char *status;
823 struct ata_smart_attribute *disk=data->vendor_attributes+i;
824 struct ata_smart_threshold_entry *thre=thresholds->thres_entries+i;
825
826 // consider only valid attributes (allowing some screw-ups in the
827 // thresholds page data to slip by)
828 if (disk->id){
829 const char *type, *update;
830 int failednow,failedever;
831 char attributename[64];
832
833 failednow = (disk->current <= thre->threshold);
834 failedever= (disk->worst <= thre->threshold);
835
836 // These break out of the loop if we are only printing certain entries...
837 if (onlyfailed==1 && (!ATTRIBUTE_FLAGS_PREFAILURE(disk->flags) || !failednow))
838 continue;
839
840 if (onlyfailed==2 && !failedever)
841 continue;
842
843 // print header only if needed
844 if (needheader){
845 if (!onlyfailed){
846 pout("SMART Attributes Data Structure revision number: %d\n",(int)data->revnumber);
847 pout("Vendor Specific SMART Attributes with Thresholds:\n");
848 }
849 pout("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE\n");
850 needheader=0;
851 }
852
853 // is this Attribute currently failed, or has it ever failed?
854 if (failednow)
855 status="FAILING_NOW";
856 else if (failedever)
857 status="In_the_past";
858 else
859 status=" -";
860
861 // Print name of attribute
862 ataPrintSmartAttribName(attributename,disk->id, con->attributedefs);
863 pout("%-28s",attributename);
864
865 // printing line for each valid attribute
866 type=ATTRIBUTE_FLAGS_PREFAILURE(disk->flags)?"Pre-fail":"Old_age";
867 update=ATTRIBUTE_FLAGS_ONLINE(disk->flags)?"Always":"Offline";
868
869 pout("0x%04x %.3d %.3d %.3d %-10s%-9s%-12s",
870 (int)disk->flags, (int)disk->current, (int)disk->worst,
871 (int)thre->threshold, type, update, status);
872
873 // print raw value of attribute
874 ataPrintSmartAttribRawValue(rawstring, disk, con->attributedefs);
875 pout("%s\n", rawstring);
876
877 // print a warning if there is inconsistency here!
878 if (disk->id != thre->id){
879 char atdat[64],atthr[64];
880 ataPrintSmartAttribName(atdat, disk->id, con->attributedefs);
881 ataPrintSmartAttribName(atthr, thre->id, con->attributedefs);
882 pout("%-28s<== Data Page | WARNING: PREVIOUS ATTRIBUTE HAS TWO\n",atdat);
883 pout("%-28s<== Threshold Page | INCONSISTENT IDENTITIES IN THE DATA\n",atthr);
884 }
885 }
886 }
887 if (!needheader) pout("\n");
888 }
889
890 void ataPrintGeneralSmartValues(struct ata_smart_values *data, struct ata_identify_device *drive){
891 pout("General SMART Values:\n");
892
893 PrintSmartOfflineStatus(data);
894
895 if (isSupportSelfTest(data)){
896 PrintSmartSelfExecStatus (data);
897 }
898
899 PrintSmartTotalTimeCompleteOffline(data);
900 PrintSmartOfflineCollectCap(data);
901 PrintSmartCapability(data);
902
903 PrintSmartErrorLogCapability(data, drive);
904
905 pout( "\t\t\t\t\t%s\n", isGeneralPurposeLoggingCapable(drive)?
906 "General Purpose Logging supported.":
907 "No General Purpose Logging support.");
908
909 if (isSupportSelfTest(data)){
910 PrintSmartShortSelfTestPollingTime (data);
911 PrintSmartExtendedSelfTestPollingTime (data);
912 }
913 if (isSupportConveyanceSelfTest(data))
914 PrintSmartConveyanceSelfTestPollingTime (data);
915
916 pout("\n");
917 }
918
919 int ataPrintLogDirectory(struct ata_smart_log_directory *data){
920 int i;
921 char *name;
922
923 pout("SMART Log Directory Logging Version %d%s\n",
924 data->logversion, data->logversion==1?" [multi-sector log support]":"");
925 for (i=0; i<=255; i++){
926 int numsect;
927
928 // Directory log length
929 numsect = i? data->entry[i-1].numsectors : 1;
930
931 // If the log is not empty, what is it's name
932 if (numsect){
933 switch (i) {
934 case 0:
935 name="Log Directory"; break;
936 case 1:
937 name="Summary SMART error log"; break;
938 case 2:
939 name="Comprehensive SMART error log"; break;
940 case 3:
941 name="Extended Comprehensive SMART error log"; break;
942 case 6:
943 name="SMART self-test log"; break;
944 case 7:
945 name="Extended self-test log"; break;
946 case 9:
947 name="Selective self-test log"; break;
948 case 0x20:
949 name="Streaming performance log"; break;
950 case 0x21:
951 name="Write stream error log"; break;
952 case 0x22:
953 name="Read stream error log"; break;
954 case 0x23:
955 name="Delayed sector log"; break;
956 default:
957 if (0xa0<=i && i<=0xbf)
958 name="Device vendor specific log";
959 else if (0x80<=i && i<=0x9f)
960 name="Host vendor specific log";
961 else
962 name="Reserved log";
963 break;
964 }
965
966 // print name and length of log
967 pout("Log at address 0x%02x has %03d sectors [%s]\n",
968 i, numsect, name);
969 }
970 }
971 return 0;
972 }
973
974 // returns number of errors
975 int ataPrintSmartErrorlog(struct ata_smart_errorlog *data){
976 int k;
977
978 pout("SMART Error Log Version: %d\n", (int)data->revnumber);
979
980 // if no errors logged, return
981 if (!data->error_log_pointer){
982 pout("No Errors Logged\n\n");
983 return 0;
984 }
985 PRINT_ON(con);
986 // If log pointer out of range, return
987 if (data->error_log_pointer>5){
988 pout("Invalid Error Log index = 0x%02x (T13/1321D rev 1c "
989 "Section 8.41.6.8.2.2 gives valid range from 1 to 5)\n\n",
990 (int)data->error_log_pointer);
991 return 0;
992 }
993
994 // Some internal consistency checking of the data structures
995 if ((data->ata_error_count-data->error_log_pointer)%5 && con->fixfirmwarebug != FIX_SAMSUNG2) {
996 pout("Warning: ATA error count %d inconsistent with error log pointer %d\n\n",
997 data->ata_error_count,data->error_log_pointer);
998 }
999
1000 // starting printing error log info
1001 if (data->ata_error_count<=5)
1002 pout( "ATA Error Count: %d\n", (int)data->ata_error_count);
1003 else
1004 pout( "ATA Error Count: %d (device log contains only the most recent five errors)\n",
1005 (int)data->ata_error_count);
1006 PRINT_OFF(con);
1007 pout("\tCR = Command Register [HEX]\n"
1008 "\tFR = Features Register [HEX]\n"
1009 "\tSC = Sector Count Register [HEX]\n"
1010 "\tSN = Sector Number Register [HEX]\n"
1011 "\tCL = Cylinder Low Register [HEX]\n"
1012 "\tCH = Cylinder High Register [HEX]\n"
1013 "\tDH = Device/Head Register [HEX]\n"
1014 "\tDC = Device Command Register [HEX]\n"
1015 "\tER = Error register [HEX]\n"
1016 "\tST = Status register [HEX]\n"
1017 "Powered_Up_Time is measured from power on, and printed as\n"
1018 "DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,\n"
1019 "SS=sec, and sss=millisec. It \"wraps\" after 49.710 days.\n\n");
1020
1021 // now step through the five error log data structures (table 39 of spec)
1022 for (k = 4; k >= 0; k-- ) {
1023 char *st_er_desc;
1024
1025 // The error log data structure entries are a circular buffer
1026 int j, i=(data->error_log_pointer+k)%5;
1027 struct ata_smart_errorlog_struct *elog=data->errorlog_struct+i;
1028 struct ata_smart_errorlog_error_struct *summary=&(elog->error_struct);
1029
1030 // Spec says: unused error log structures shall be zero filled
1031 if (nonempty((unsigned char*)elog,sizeof(*elog))){
1032 // Table 57 of T13/1532D Volume 1 Revision 3
1033 char *msgstate;
1034 int bits=summary->state & 0x0f;
1035 int days = (int)summary->timestamp/24;
1036
1037 switch (bits){
1038 case 0x00: msgstate="in an unknown state";break;
1039 case 0x01: msgstate="sleeping"; break;
1040 case 0x02: msgstate="in standby mode"; break;
1041 case 0x03: msgstate="active or idle"; break;
1042 case 0x04: msgstate="doing SMART Offline or Self-test"; break;
1043 default:
1044 if (bits<0x0b)
1045 msgstate="in a reserved state";
1046 else
1047 msgstate="in a vendor specific state";
1048 }
1049
1050 // See table 42 of ATA5 spec
1051 PRINT_ON(con);
1052 pout("Error %d occurred at disk power-on lifetime: %d hours (%d days + %d hours)\n",
1053 (int)(data->ata_error_count+k-4), (int)summary->timestamp, days, (int)(summary->timestamp-24*days));
1054 PRINT_OFF(con);
1055 pout(" When the command that caused the error occurred, the device was %s.\n\n",msgstate);
1056 pout(" After command completion occurred, registers were:\n"
1057 " ER ST SC SN CL CH DH\n"
1058 " -- -- -- -- -- -- --\n"
1059 " %02x %02x %02x %02x %02x %02x %02x",
1060 (int)summary->error_register,
1061 (int)summary->status,
1062 (int)summary->sector_count,
1063 (int)summary->sector_number,
1064 (int)summary->cylinder_low,
1065 (int)summary->cylinder_high,
1066 (int)summary->drive_head);
1067 // Add a description of the contents of the status and error registers
1068 // if possible
1069 st_er_desc = construct_st_er_desc(elog);
1070 if (st_er_desc) {
1071 pout(" %s", st_er_desc);
1072 free(st_er_desc);
1073 }
1074 pout("\n\n");
1075 pout(" Commands leading to the command that caused the error were:\n"
1076 " CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name\n"
1077 " -- -- -- -- -- -- -- -- ---------------- --------------------\n");
1078 for ( j = 4; j >= 0; j--){
1079 struct ata_smart_errorlog_command_struct *thiscommand=elog->commands+j;
1080
1081 // Spec says: unused data command structures shall be zero filled
1082 if (nonempty((unsigned char*)thiscommand,sizeof(*thiscommand))) {
1083 char timestring[32];
1084
1085 // Convert integer milliseconds to a text-format string
1086 MsecToText(thiscommand->timestamp, timestring);
1087
1088 pout(" %02x %02x %02x %02x %02x %02x %02x %02x %16s %s\n",
1089 (int)thiscommand->commandreg,
1090 (int)thiscommand->featuresreg,
1091 (int)thiscommand->sector_count,
1092 (int)thiscommand->sector_number,
1093 (int)thiscommand->cylinder_low,
1094 (int)thiscommand->cylinder_high,
1095 (int)thiscommand->drive_head,
1096 (int)thiscommand->devicecontrolreg,
1097 timestring,
1098 look_up_ata_command(thiscommand->commandreg, thiscommand->featuresreg));
1099 }
1100 }
1101 pout("\n");
1102 }
1103 }
1104 PRINT_ON(con);
1105 if (con->printing_switchable)
1106 pout("\n");
1107 PRINT_OFF(con);
1108 return data->ata_error_count;
1109 }
1110
1111 void ataPrintSelectiveSelfTestLog(struct ata_selective_self_test_log *log, struct ata_smart_values *sv) {
1112 int i,field1,field2;
1113 char *msg;
1114 char tmp[64];
1115 uint64_t maxl=0,maxr=0;
1116 uint64_t current=log->currentlba;
1117 uint64_t currentend=current+65535;
1118
1119 // print data structure revision number
1120 pout("SMART Selective self-test log data structure revision number %d\n",(int)log->logversion);
1121 if (1 != log->logversion)
1122 pout("Warning: ATA Specification requires selective self-test log data structure revision number = 1\n");
1123
1124 switch((sv->self_test_exec_status)>>4){
1125 case 0:msg="Completed";
1126 break;
1127 case 1:msg="Aborted_by_host";
1128 break;
1129 case 2:msg="Interrupted";
1130 break;
1131 case 3:msg="Fatal_error";
1132 break;
1133 case 4:msg="Completed_unknown_failure";
1134 break;
1135 case 5:msg="Completed_electrical_failure";
1136 break;
1137 case 6:msg="Completed_servo/seek_failure";
1138 break;
1139 case 7:msg="Completed_read_failure";
1140 break;
1141 case 8:msg="Completed_handling_damage??";
1142 break;
1143 case 15:msg="Self_test_in_progress";
1144 break;
1145 default:msg="Unknown_status ";
1146 break;
1147 }
1148
1149 // find the number of columns needed for printing. If in use, the
1150 // start/end of span being read-scanned...
1151 if (log->currentspan>5) {
1152 maxl=current;
1153 maxr=currentend;
1154 }
1155 for (i=0; i<5; i++) {
1156 uint64_t start=log->span[i].start;
1157 uint64_t end =log->span[i].end;
1158 // ... plus max start/end of each of the five test spans.
1159 if (start>maxl)
1160 maxl=start;
1161 if (end > maxr)
1162 maxr=end;
1163 }
1164
1165 // we need at least 7 characters wide fields to accomodate the
1166 // labels
1167 if ((field1=snprintf(tmp,64, "%"PRIu64, maxl))<7)
1168 field1=7;
1169 if ((field2=snprintf(tmp,64, "%"PRIu64, maxr))<7)
1170 field2=7;
1171
1172 // now print the five test spans
1173 pout(" SPAN %*s %*s CURRENT_TEST_STATUS\n", field1, "MIN_LBA", field2, "MAX_LBA");
1174
1175 for (i=0; i<5; i++) {
1176 uint64_t start=log->span[i].start;
1177 uint64_t end=log->span[i].end;
1178
1179 if ((i+1)==(int)log->currentspan)
1180 // this span is currently under test
1181 pout(" %d %*"PRIu64" %*"PRIu64" %s [%01d0%% left] (%"PRIu64"-%"PRIu64")\n",
1182 i+1, field1, start, field2, end, msg,
1183 (int)(sv->self_test_exec_status & 0x7), current, currentend);
1184 else
1185 // this span is not currently under test
1186 pout(" %d %*"PRIu64" %*"PRIu64" Not_testing\n",
1187 i+1, field1, start, field2, end);
1188 }
1189
1190 // if we are currently read-scanning, print LBAs and the status of
1191 // the read scan
1192 if (log->currentspan>5)
1193 pout("%5d %*"PRIu64" %*"PRIu64" Read_scanning %s\n",
1194 (int)log->currentspan, field1, current, field2, currentend,
1195 OfflineDataCollectionStatus(sv->offline_data_collection_status));
1196
1197 /* Print selective self-test flags. Possible flag combinations are
1198 (numbering bits from 0-15):
1199 Bit-1 Bit-3 Bit-4
1200 Scan Pending Active
1201 0 * * Don't scan
1202 1 0 0 Will carry out scan after selective test
1203 1 1 0 Waiting to carry out scan after powerup
1204 1 0 1 Currently scanning
1205 1 1 1 Currently scanning
1206 */
1207
1208 pout("Selective self-test flags (0x%x):\n", (unsigned int)log->flags);
1209 if (log->flags & SELECTIVE_FLAG_DOSCAN) {
1210 if (log->flags & SELECTIVE_FLAG_ACTIVE)
1211 pout(" Currently read-scanning the remainder of the disk.\n");
1212 else if (log->flags & SELECTIVE_FLAG_PENDING)
1213 pout(" Read-scan of remainder of disk interrupted; will resume %d min after power-up.\n",
1214 (int)log->pendingtime);
1215 else
1216 pout(" After scanning selected spans, read-scan remainder of disk.\n");
1217 }
1218 else
1219 pout(" After scanning selected spans, do NOT read-scan remainder of disk.\n");
1220
1221 // print pending time
1222 pout("If Selective self-test is pending on power-up, resume after %d minute delay.\n",
1223 (int)log->pendingtime);
1224
1225 return;
1226 }
1227
1228 // return value is:
1229 // bottom 8 bits: number of entries found where self-test showed an error
1230 // remaining bits: if nonzero, power on hours of last self-test where error was found
1231 int ataPrintSmartSelfTestlog(struct ata_smart_selftestlog *data,int allentries){
1232 int i,j,noheaderprinted=1;
1233 int retval=0, hours=0, testno=0;
1234
1235 if (allentries)
1236 pout("SMART Self-test log structure revision number %d\n",(int)data->revnumber);
1237 if ((data->revnumber!=0x0001) && allentries && con->fixfirmwarebug != FIX_SAMSUNG)
1238 pout("Warning: ATA Specification requires self-test log structure revision number = 1\n");
1239 if (data->mostrecenttest==0){
1240 if (allentries)
1241 pout("No self-tests have been logged. [To run self-tests, use: smartctl -t]\n\n");
1242 return 0;
1243 }
1244
1245 // print log
1246 for (i=20;i>=0;i--){
1247 struct ata_smart_selftestlog_struct *log;
1248
1249 // log is a circular buffer
1250 j=(i+data->mostrecenttest)%21;
1251 log=data->selftest_struct+j;
1252
1253 if (nonempty((unsigned char*)log,sizeof(*log))){
1254 char *msgtest,*msgstat,percent[64],firstlba[64];
1255 int errorfound=0;
1256
1257 // count entry based on non-empty structures -- needed for
1258 // Seagate only -- other vendors don't have blank entries 'in
1259 // the middle'
1260 testno++;
1261
1262 // test name
1263 switch(log->selftestnumber){
1264 case 0: msgtest="Offline "; break;
1265 case 1: msgtest="Short offline "; break;
1266 case 2: msgtest="Extended offline "; break;
1267 case 3: msgtest="Conveyance offline "; break;
1268 case 4: msgtest="Selective offline "; break;
1269 case 127: msgtest="Abort offline test "; break;
1270 case 129: msgtest="Short captive "; break;
1271 case 130: msgtest="Extended captive "; break;
1272 case 131: msgtest="Conveyance captive "; break;
1273 case 132: msgtest="Selective captive "; break;
1274 default:
1275 if ( log->selftestnumber>=192 ||
1276 (log->selftestnumber>= 64 && log->selftestnumber<=126))
1277 msgtest="Vendor offline ";
1278 else
1279 msgtest="Reserved offline ";
1280 }
1281
1282 // test status
1283 switch((log->selfteststatus)>>4){
1284 case 0:msgstat="Completed without error "; break;
1285 case 1:msgstat="Aborted by host "; break;
1286 case 2:msgstat="Interrupted (host reset) "; break;
1287 case 3:msgstat="Fatal or unknown error "; errorfound=1; break;
1288 case 4:msgstat="Completed: unknown failure "; errorfound=1; break;
1289 case 5:msgstat="Completed: electrical failure"; errorfound=1; break;
1290 case 6:msgstat="Completed: servo/seek failure"; errorfound=1; break;
1291 case 7:msgstat="Completed: read failure "; errorfound=1; break;
1292 case 8:msgstat="Completed: handling damage?? "; errorfound=1; break;
1293 case 15:msgstat="Self-test routine in progress"; break;
1294 default:msgstat="Unknown/reserved test status ";
1295 }
1296
1297 retval+=errorfound;
1298 sprintf(percent,"%1d0%%",(log->selfteststatus)&0xf);
1299
1300 // T13/1321D revision 1c: (Data structure Rev #1)
1301
1302 //The failing LBA shall be the LBA of the uncorrectable sector
1303 //that caused the test to fail. If the device encountered more
1304 //than one uncorrectable sector during the test, this field
1305 //shall indicate the LBA of the first uncorrectable sector
1306 //encountered. If the test passed or the test failed for some
1307 //reason other than an uncorrectable sector, the value of this
1308 //field is undefined.
1309
1310 // This is true in ALL ATA-5 specs
1311
1312 if (!errorfound || log->lbafirstfailure==0xffffffff || log->lbafirstfailure==0x00000000)
1313 sprintf(firstlba,"%s","-");
1314 else
1315 sprintf(firstlba,"%u",log->lbafirstfailure);
1316
1317 // print out a header if needed
1318 if (noheaderprinted && (allentries || errorfound)){
1319 pout("Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error\n");
1320 noheaderprinted=0;
1321 }
1322
1323 // print out an entry, either if we are printing all entries OR
1324 // if an error was found
1325 if (allentries || errorfound)
1326 pout("#%2d %s %s %s %8d %s\n", testno, msgtest, msgstat, percent, (int)log->timestamp, firstlba);
1327
1328 // keep track of time of most recent error
1329 if (errorfound && !hours)
1330 hours=log->timestamp;
1331 }
1332 }
1333 if (!allentries && retval)
1334 pout("\n");
1335
1336 hours = hours << 8;
1337 return (retval | hours);
1338 }
1339
1340 void ataPseudoCheckSmart ( struct ata_smart_values *data,
1341 struct ata_smart_thresholds_pvt *thresholds) {
1342 int i;
1343 int failed = 0;
1344 for (i = 0 ; i < NUMBER_ATA_SMART_ATTRIBUTES ; i++) {
1345 if (data->vendor_attributes[i].id &&
1346 thresholds->thres_entries[i].id &&
1347 ATTRIBUTE_FLAGS_PREFAILURE(data->vendor_attributes[i].flags) &&
1348 (data->vendor_attributes[i].current <= thresholds->thres_entries[i].threshold) &&
1349 (thresholds->thres_entries[i].threshold != 0xFE)){
1350 pout("Attribute ID %d Failed\n",(int)data->vendor_attributes[i].id);
1351 failed = 1;
1352 }
1353 }
1354 pout("%s\n", ( failed )?
1355 "SMART overall-health self-assessment test result: FAILED!\n"
1356 "Drive failure expected in less than 24 hours. SAVE ALL DATA":
1357 "SMART overall-health self-assessment test result: PASSED");
1358 }
1359
1360
1361 // Compares failure type to policy in effect, and either exits or
1362 // simply returns to the calling routine.
1363 void failuretest(int type, int returnvalue){
1364
1365 // If this is an error in an "optional" SMART command
1366 if (type==OPTIONAL_CMD){
1367 if (con->conservative){
1368 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1369 EXIT(returnvalue);
1370 }
1371 return;
1372 }
1373
1374 // If this is an error in a "mandatory" SMART command
1375 if (type==MANDATORY_CMD){
1376 if (con->permissive--)
1377 return;
1378 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1379 EXIT(returnvalue);
1380 }
1381
1382 pout("Smartctl internal error in failuretest(type=%d). Please contact developers at " PACKAGE_HOMEPAGE "\n",type);
1383 EXIT(returnvalue|FAILCMD);
1384 }
1385
1386 // Used to warn users about invalid checksums. Action to be taken may be
1387 // altered by the user.
1388 void checksumwarning(const char *string){
1389 // user has asked us to ignore checksum errors
1390 if (con->checksumignore)
1391 return;
1392
1393 pout("Warning! %s error: invalid SMART checksum.\n",string);
1394
1395 // user has asked us to fail on checksum errors
1396 if (con->checksumfail)
1397 EXIT(FAILSMART);
1398
1399 return;
1400 }
1401
1402 // Initialize to zero just in case some SMART routines don't work
1403 struct ata_identify_device drive;
1404 struct ata_smart_values smartval;
1405 struct ata_smart_thresholds_pvt smartthres;
1406 struct ata_smart_errorlog smarterror;
1407 struct ata_smart_selftestlog smartselftest;
1408
1409 int ataPrintMain (int fd){
1410 int timewait,code;
1411 int returnval=0, retid=0, supported=0, needupdate=0, known=0;
1412 const char * powername = 0; char powerchg = 0;
1413
1414 // If requested, check power mode first
1415 if (con->powermode) {
1416 unsigned char powerlimit = 0xff;
1417 int powermode = ataCheckPowerMode(fd);
1418 switch (powermode) {
1419 case -1:
1420 if (errno == ENOSYS) {
1421 pout("CHECK POWER STATUS not implemented, ignoring -n Option\n"); break;
1422 }
1423 powername = "SLEEP"; powerlimit = 2;
1424 break;
1425 case 0:
1426 powername = "STANDBY"; powerlimit = 3; break;
1427 case 0x80:
1428 powername = "IDLE"; powerlimit = 4; break;
1429 case 0xff:
1430 powername = "ACTIVE or IDLE"; break;
1431 default:
1432 pout("CHECK POWER STATUS returned %d, not ATA compliant, ignoring -n Option\n", powermode);
1433 break;
1434 }
1435 if (powername) {
1436 if (con->powermode >= powerlimit) {
1437 pout("Device is in %s mode, exit(%d)\n", powername, FAILPOWER);
1438 return FAILPOWER;
1439 }
1440 powerchg = (powermode != 0xff); // SMART tests will spin up drives
1441 }
1442 }
1443
1444 // Start by getting Drive ID information. We need this, to know if SMART is supported.
1445 if ((retid=ataReadHDIdentity(fd,&drive))<0){
1446 pout("Smartctl: Device Read Identity Failed (not an ATA/ATAPI device)\n\n");
1447 failuretest(MANDATORY_CMD, returnval|=FAILID);
1448 }
1449
1450 // If requested, show which presets would be used for this drive and exit.
1451 if (con->showpresets) {
1452 showpresets(&drive);
1453 EXIT(0);
1454 }
1455
1456 // Use preset vendor attribute options unless user has requested otherwise.
1457 if (!con->ignorepresets){
1458 unsigned char *charptr;
1459 if ((charptr=con->attributedefs))
1460 applypresets(&drive, &charptr, con);
1461 else {
1462 pout("Fatal internal error in ataPrintMain()\n");
1463 EXIT(returnval|=FAILCMD);
1464 }
1465 }
1466
1467 // Print most drive identity information if requested
1468 if (con->driveinfo){
1469 pout("=== START OF INFORMATION SECTION ===\n");
1470 known = ataPrintDriveInfo(&drive);
1471 }
1472
1473 // Was this a packet device?
1474 if (retid>0){
1475 pout("SMART support is: Unavailable - Packet Interface Devices [this device: %s] don't support ATA SMART\n", packetdevicetype(retid-1));
1476 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1477 }
1478
1479 // if drive does not supports SMART it's time to exit
1480 supported=ataSmartSupport(&drive);
1481 if (supported != 1){
1482 if (supported==0) {
1483 pout("SMART support is: Unavailable - device lacks SMART capability.\n");
1484 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1485 pout(" Checking to be sure by trying SMART ENABLE command.\n");
1486 }
1487 else {
1488 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 82-83 don't show if SMART supported.\n");
1489 if (!known) failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1490 pout(" Checking for SMART support by trying SMART ENABLE command.\n");
1491 }
1492
1493 if (ataEnableSmart(fd)){
1494 pout(" SMART ENABLE failed - this establishes that this device lacks SMART functionality.\n");
1495 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1496 supported=0;
1497 }
1498 else {
1499 pout(" SMART ENABLE appeared to work! Continuing.\n");
1500 supported=1;
1501 }
1502 if (!con->driveinfo) pout("\n");
1503 }
1504
1505 // Now print remaining drive info: is SMART enabled?
1506 if (con->driveinfo){
1507 int ison=ataIsSmartEnabled(&drive),isenabled=ison;
1508
1509 if (ison==-1) {
1510 pout("SMART support is: Ambiguous - ATA IDENTIFY DEVICE words 85-87 don't show if SMART is enabled.\n");
1511 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1512 // check SMART support by trying a command
1513 pout(" Checking to be sure by trying SMART RETURN STATUS command.\n");
1514 isenabled=ataDoesSmartWork(fd);
1515 }
1516 else {
1517 pout("SMART support is: Available - device has SMART capability.\n");
1518 #ifdef HAVE_ATA_IDENTIFY_IS_CACHED
1519 if (ata_identify_is_cached(fd)) {
1520 pout(" %sabled status cached by OS, trying SMART RETURN STATUS cmd.\n",
1521 (isenabled?"En":"Dis"));
1522 isenabled=ataDoesSmartWork(fd);
1523 }
1524 #endif
1525 }
1526
1527 if (isenabled)
1528 pout("SMART support is: Enabled\n");
1529 else {
1530 if (ison==-1)
1531 pout("SMART support is: Unavailable\n");
1532 else
1533 pout("SMART support is: Disabled\n");
1534 }
1535 // Print the (now possibly changed) power mode if available
1536 if (powername)
1537 pout("Power mode %s %s\n", (powerchg?"was:":"is: "), powername);
1538 pout("\n");
1539 }
1540
1541 // START OF THE ENABLE/DISABLE SECTION OF THE CODE
1542 if (con->smartenable || con->smartdisable ||
1543 con->smartautosaveenable || con->smartautosavedisable ||
1544 con->smartautoofflineenable || con->smartautoofflinedisable)
1545 pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
1546
1547 // Enable/Disable SMART commands
1548 if (con->smartenable){
1549 if (ataEnableSmart(fd)) {
1550 pout("Smartctl: SMART Enable Failed.\n\n");
1551 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1552 }
1553 else
1554 pout("SMART Enabled.\n");
1555 }
1556
1557 // From here on, every command requires that SMART be enabled...
1558 if (!ataDoesSmartWork(fd)) {
1559 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1560 return returnval;
1561 }
1562
1563 // Turn off SMART on device
1564 if (con->smartdisable){
1565 if (ataDisableSmart(fd)) {
1566 pout( "Smartctl: SMART Disable Failed.\n\n");
1567 failuretest(MANDATORY_CMD,returnval|=FAILSMART);
1568 }
1569 pout("SMART Disabled. Use option -s with argument 'on' to enable it.\n");
1570 return returnval;
1571 }
1572
1573 // Let's ALWAYS issue this command to get the SMART status
1574 code=ataSmartStatus2(fd);
1575 if (code==-1)
1576 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1577
1578 // Enable/Disable Auto-save attributes
1579 if (con->smartautosaveenable){
1580 if (ataEnableAutoSave(fd)){
1581 pout( "Smartctl: SMART Enable Attribute Autosave Failed.\n\n");
1582 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1583 }
1584 else
1585 pout("SMART Attribute Autosave Enabled.\n");
1586 }
1587 if (con->smartautosavedisable){
1588 if (ataDisableAutoSave(fd)){
1589 pout( "Smartctl: SMART Disable Attribute Autosave Failed.\n\n");
1590 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1591 }
1592 else
1593 pout("SMART Attribute Autosave Disabled.\n");
1594 }
1595
1596 // for everything else read values and thresholds are needed
1597 if (ataReadSmartValues(fd, &smartval)){
1598 pout("Smartctl: SMART Read Values failed.\n\n");
1599 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1600 }
1601 if (ataReadSmartThresholds(fd, &smartthres)){
1602 pout("Smartctl: SMART Read Thresholds failed.\n\n");
1603 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1604 }
1605
1606 // Enable/Disable Off-line testing
1607 if (con->smartautoofflineenable){
1608 if (!isSupportAutomaticTimer(&smartval)){
1609 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1610 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1611 }
1612 needupdate=1;
1613 if (ataEnableAutoOffline(fd)){
1614 pout( "Smartctl: SMART Enable Automatic Offline Failed.\n\n");
1615 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1616 }
1617 else
1618 pout("SMART Automatic Offline Testing Enabled every four hours.\n");
1619 }
1620 if (con->smartautoofflinedisable){
1621 if (!isSupportAutomaticTimer(&smartval)){
1622 pout("Warning: device does not support SMART Automatic Timers.\n\n");
1623 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1624 }
1625 needupdate=1;
1626 if (ataDisableAutoOffline(fd)){
1627 pout("Smartctl: SMART Disable Automatic Offline Failed.\n\n");
1628 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1629 }
1630 else
1631 pout("SMART Automatic Offline Testing Disabled.\n");
1632 }
1633
1634 if (needupdate && ataReadSmartValues(fd, &smartval)){
1635 pout("Smartctl: SMART Read Values failed.\n\n");
1636 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1637 }
1638
1639 // all this for a newline!
1640 if (con->smartenable || con->smartdisable ||
1641 con->smartautosaveenable || con->smartautosavedisable ||
1642 con->smartautoofflineenable || con->smartautoofflinedisable)
1643 pout("\n");
1644
1645 // START OF READ-ONLY OPTIONS APART FROM -V and -i
1646 if (con->checksmart || con->generalsmartvalues || con->smartvendorattrib || con->smarterrorlog || con->smartselftestlog)
1647 pout("=== START OF READ SMART DATA SECTION ===\n");
1648
1649 // Check SMART status (use previously returned value)
1650 if (con->checksmart){
1651 switch (code) {
1652
1653 case 0:
1654 // The case where the disk health is OK
1655 pout("SMART overall-health self-assessment test result: PASSED\n");
1656 if (ataCheckSmart(&smartval, &smartthres,0)){
1657 if (con->smartvendorattrib)
1658 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1659 else {
1660 PRINT_ON(con);
1661 pout("Please note the following marginal Attributes:\n");
1662 PrintSmartAttribWithThres(&smartval, &smartthres,2);
1663 }
1664 returnval|=FAILAGE;
1665 }
1666 else
1667 pout("\n");
1668 break;
1669
1670 case 1:
1671 // The case where the disk health is NOT OK
1672 PRINT_ON(con);
1673 pout("SMART overall-health self-assessment test result: FAILED!\n"
1674 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1675 PRINT_OFF(con);
1676 if (ataCheckSmart(&smartval, &smartthres,1)){
1677 returnval|=FAILATTR;
1678 if (con->smartvendorattrib)
1679 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1680 else {
1681 PRINT_ON(con);
1682 pout("Failed Attributes:\n");
1683 PrintSmartAttribWithThres(&smartval, &smartthres,1);
1684 }
1685 }
1686 else
1687 pout("No failed Attributes found.\n\n");
1688 returnval|=FAILSTATUS;
1689 PRINT_OFF(con);
1690 break;
1691
1692 case -1:
1693 default:
1694 // The case where something went wrong with HDIO_DRIVE_TASK ioctl()
1695 if (ataCheckSmart(&smartval, &smartthres,1)){
1696 PRINT_ON(con);
1697 pout("SMART overall-health self-assessment test result: FAILED!\n"
1698 "Drive failure expected in less than 24 hours. SAVE ALL DATA.\n");
1699 PRINT_OFF(con);
1700 returnval|=FAILATTR;
1701 returnval|=FAILSTATUS;
1702 if (con->smartvendorattrib)
1703 pout("See vendor-specific Attribute list for failed Attributes.\n\n");
1704 else {
1705 PRINT_ON(con);
1706 pout("Failed Attributes:\n");
1707 PrintSmartAttribWithThres(&smartval, &smartthres,1);
1708 }
1709 }
1710 else {
1711 pout("SMART overall-health self-assessment test result: PASSED\n");
1712 if (ataCheckSmart(&smartval, &smartthres,0)){
1713 if (con->smartvendorattrib)
1714 pout("See vendor-specific Attribute list for marginal Attributes.\n\n");
1715 else {
1716 PRINT_ON(con);
1717 pout("Please note the following marginal Attributes:\n");
1718 PrintSmartAttribWithThres(&smartval, &smartthres,2);
1719 }
1720 returnval|=FAILAGE;
1721 }
1722 else
1723 pout("\n");
1724 }
1725 PRINT_OFF(con);
1726 break;
1727 } // end of switch statement
1728
1729 PRINT_OFF(con);
1730 } // end of checking SMART Status
1731
1732 // Print general SMART values
1733 if (con->generalsmartvalues)
1734 ataPrintGeneralSmartValues(&smartval, &drive);
1735
1736 // Print vendor-specific attributes
1737 if (con->smartvendorattrib){
1738 PRINT_ON(con);
1739 PrintSmartAttribWithThres(&smartval, &smartthres,con->printing_switchable?2:0);
1740 PRINT_OFF(con);
1741 }
1742
1743 // Print SMART log Directory
1744 if (con->smartlogdirectory){
1745 struct ata_smart_log_directory smartlogdirectory;
1746 if (!isGeneralPurposeLoggingCapable(&drive)){
1747 pout("Warning: device does not support General Purpose Logging\n");
1748 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1749 }
1750 else {
1751 PRINT_ON(con);
1752 pout("Log Directory Supported\n");
1753 if (ataReadLogDirectory(fd, &smartlogdirectory)){
1754 PRINT_OFF(con);
1755 pout("Read Log Directory failed.\n\n");
1756 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1757 }
1758 else
1759 ataPrintLogDirectory( &smartlogdirectory);
1760 }
1761 PRINT_OFF(con);
1762 }
1763
1764 // Print SMART error log
1765 if (con->smarterrorlog){
1766 if (!isSmartErrorLogCapable(&smartval, &drive)){
1767 pout("Warning: device does not support Error Logging\n");
1768 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1769 }
1770 if (ataReadErrorLog(fd, &smarterror)){
1771 pout("Smartctl: SMART Error Log Read Failed\n");
1772 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1773 }
1774 else {
1775 // quiet mode is turned on inside ataPrintSmartErrorLog()
1776 if (ataPrintSmartErrorlog(&smarterror))
1777 returnval|=FAILERR;
1778 PRINT_OFF(con);
1779 }
1780 }
1781
1782 // Print SMART self-test log
1783 if (con->smartselftestlog){
1784 if (!isSmartTestLogCapable(&smartval, &drive)){
1785 pout("Warning: device does not support Self Test Logging\n");
1786 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1787 }
1788 if(ataReadSelfTestLog(fd, &smartselftest)){
1789 pout("Smartctl: SMART Self Test Log Read Failed\n");
1790 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1791 }
1792 else {
1793 PRINT_ON(con);
1794 if (ataPrintSmartSelfTestlog(&smartselftest,!con->printing_switchable))
1795 returnval|=FAILLOG;
1796 PRINT_OFF(con);
1797 pout("\n");
1798 }
1799 }
1800
1801 // Print SMART selective self-test log
1802 if (con->selectivetestlog){
1803 struct ata_selective_self_test_log log;
1804
1805 if (!isSupportSelectiveSelfTest(&smartval))
1806 pout("Device does not support Selective Self Tests/Logging\n");
1807 else if(ataReadSelectiveSelfTestLog(fd, &log)) {
1808 pout("Smartctl: SMART Selective Self Test Log Read Failed\n");
1809 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1810 }
1811 else {
1812 PRINT_ON(con);
1813 ataPrintSelectiveSelfTestLog(&log, &smartval);
1814 PRINT_OFF(con);
1815 pout("\n");
1816 }
1817 }
1818
1819 // START OF THE TESTING SECTION OF THE CODE. IF NO TESTING, RETURN
1820 if (con->testcase==-1)
1821 return returnval;
1822
1823 pout("=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===\n");
1824 // if doing a self-test, be sure it's supported by the hardware
1825 switch (con->testcase){
1826 case OFFLINE_FULL_SCAN:
1827 if (!isSupportExecuteOfflineImmediate(&smartval)){
1828 pout("Warning: device does not support Execute Offline Immediate function.\n\n");
1829 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1830 }
1831 break;
1832 case ABORT_SELF_TEST:
1833 case SHORT_SELF_TEST:
1834 case EXTEND_SELF_TEST:
1835 case SHORT_CAPTIVE_SELF_TEST:
1836 case EXTEND_CAPTIVE_SELF_TEST:
1837 if (!isSupportSelfTest(&smartval)){
1838 pout("Warning: device does not support Self-Test functions.\n\n");
1839 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1840 }
1841 break;
1842 case CONVEYANCE_SELF_TEST:
1843 case CONVEYANCE_CAPTIVE_SELF_TEST:
1844 if (!isSupportConveyanceSelfTest(&smartval)){
1845 pout("Warning: device does not support Conveyance Self-Test functions.\n\n");
1846 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1847 }
1848 break;
1849 case SELECTIVE_SELF_TEST:
1850 case SELECTIVE_CAPTIVE_SELF_TEST:
1851 if (!isSupportSelectiveSelfTest(&smartval)){
1852 pout("Warning: device does not support Selective Self-Test functions.\n\n");
1853 failuretest(MANDATORY_CMD, returnval|=FAILSMART);
1854 }
1855 break;
1856 default:
1857 pout("Internal error in smartctl: con->testcase==%d not recognized\n", (int)con->testcase);
1858 pout("Please contact smartmontools developers at %s.\n", PACKAGE_BUGREPORT);
1859 EXIT(returnval|=FAILCMD);
1860 }
1861
1862 // Now do the test. Note ataSmartTest prints its own error/success
1863 // messages
1864 if (ataSmartTest(fd, con->testcase, &smartval))
1865 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1866 else {
1867 // Tell user how long test will take to complete. This is tricky
1868 // because in the case of an Offline Full Scan, the completion
1869 // timer is volatile, and needs to be read AFTER the command is
1870 // given. If this will interrupt the Offline Full Scan, we don't
1871 // do it, just warn user.
1872 if (con->testcase==OFFLINE_FULL_SCAN){
1873 if (isSupportOfflineAbort(&smartval))
1874 pout("Note: giving further SMART commands will abort Offline testing\n");
1875 else if (ataReadSmartValues(fd, &smartval)){
1876 pout("Smartctl: SMART Read Values failed.\n");
1877 failuretest(OPTIONAL_CMD, returnval|=FAILSMART);
1878 }
1879 }
1880
1881 // Now say how long the test will take to complete
1882 if ((timewait=TestTime(&smartval,con->testcase))){
1883 time_t t=time(NULL);
1884 if (con->testcase==OFFLINE_FULL_SCAN) {
1885 t+=timewait;
1886 pout("Please wait %d seconds for test to complete.\n", (int)timewait);
1887 } else {
1888 t+=timewait*60;
1889 pout("Please wait %d minutes for test to complete.\n", (int)timewait);
1890 }
1891 pout("Test will complete after %s\n", ctime(&t));
1892
1893 if (con->testcase!=SHORT_CAPTIVE_SELF_TEST &&
1894 con->testcase!=EXTEND_CAPTIVE_SELF_TEST &&
1895 con->testcase!=CONVEYANCE_CAPTIVE_SELF_TEST &&
1896 con->testcase!=SELECTIVE_CAPTIVE_SELF_TEST)
1897 pout("Use smartctl -X to abort test.\n");
1898 }
1899 }
1900
1901 return returnval;
1902 }