smartmontools SVN Rev 5382
Utility to control and monitor storage systems with "S.M.A.R.T."
smartctl.cpp
Go to the documentation of this file.
1/*
2 * smartctl.cpp
3 *
4 * Home page of code is: https://www.smartmontools.org
5 *
6 * Copyright (C) 2002-11 Bruce Allen
7 * Copyright (C) 2008-22 Christian Franke
8 * Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13#include "config.h"
14#define __STDC_FORMAT_MACROS 1 // enable PRI* for C++
15
16#include <errno.h>
17#include <inttypes.h>
18#include <stdio.h>
19#include <sys/types.h>
20#include <string.h>
21#include <stdlib.h>
22#include <stdarg.h>
23#include <stdexcept>
24#include <getopt.h>
25
26#ifdef HAVE_UNISTD_H
27#include <unistd.h>
28#endif
29
30#if defined(__FreeBSD__)
31#include <sys/param.h>
32#endif
33
34#include "atacmds.h"
35#include "dev_interface.h"
36#include "ataprint.h"
37#include "knowndrives.h"
38#include "scsicmds.h"
39#include "scsiprint.h"
40#include "nvmeprint.h"
41#include "smartctl.h"
42#include "utility.h"
43#include "svnversion.h"
44
45const char * smartctl_cpp_cvsid = "$Id: smartctl.cpp 5354 2022-04-22 19:14:42Z chrfranke $"
46 CONFIG_H_CVSID SMARTCTL_H_CVSID;
47
48// Globals to control printing
50bool printing_is_off = false;
51
52// Control JSON output
54static bool print_as_json = false;
56static bool print_as_json_output = false;
57static bool print_as_json_impl = false;
58static bool print_as_json_unimpl = false;
59
60static void printslogan()
61{
62 jout("%s\n", format_version_info("smartctl").c_str());
63}
64
65static void UsageSummary()
66{
67 pout("\nUse smartctl -h to get a usage summary\n\n");
68 return;
69}
70
71static void js_initialize(int argc, char **argv, bool verbose)
72{
73 if (jglb.is_enabled())
74 return;
75 jglb.enable();
76 if (verbose)
78
79 // Major.minor version of JSON format
80 jglb["json_format_version"][0] = 1;
81 jglb["json_format_version"][1] = 0;
82
83 // Smartctl version info
84 json::ref jref = jglb["smartctl"];
85 int ver[3] = { 0, 0, 0 };
86 sscanf(PACKAGE_VERSION, "%d.%d.%d", ver, ver+1, ver+2);
87 jref["version"][0] = ver[0];
88 jref["version"][1] = ver[1];
89 if (ver[2] > 0)
90 jref["version"][2] = ver[2];
91
92#ifdef SMARTMONTOOLS_RELEASE_DATE
93 jref["pre_release"] = false;
94#else
95 jref["pre_release"] = true;
96#endif
97#ifdef SMARTMONTOOLS_SVN_REV
98 jref["svn_revision"] = SMARTMONTOOLS_SVN_REV;
99#endif
100 jref["platform_info"] = smi()->get_os_version_str();
101#ifdef BUILD_INFO
102 jref["build_info"] = BUILD_INFO;
103#endif
104
105 jref["argv"][0] = "smartctl";
106 for (int i = 1; i < argc; i++)
107 jref["argv"][i] = argv[i];
108}
109
110static std::string getvalidarglist(int opt);
111
112/* void prints help information for command syntax */
113static void Usage()
114{
115 pout("Usage: smartctl [options] device\n\n");
116 pout(
117"============================================ SHOW INFORMATION OPTIONS =====\n\n"
118" -h, --help, --usage\n"
119" Display this help and exit\n\n"
120" -V, --version, --copyright, --license\n"
121" Print license, copyright, and version information and exit\n\n"
122" -i, --info\n"
123" Show identity information for device\n\n"
124" --identify[=[w][nvb]]\n"
125" Show words and bits from IDENTIFY DEVICE data (ATA)\n\n"
126" -g NAME, --get=NAME\n"
127" Get device setting: all, aam, apm, dsn, lookahead, security,\n"
128" wcache, rcache, wcreorder, wcache-sct\n\n"
129" -a, --all\n"
130" Show all SMART information for device\n\n"
131" -x, --xall\n"
132" Show all information for device\n\n"
133" --scan\n"
134" Scan for devices\n\n"
135" --scan-open\n"
136" Scan for devices and try to open each device\n\n"
137 );
138 pout(
139"================================== SMARTCTL RUN-TIME BEHAVIOR OPTIONS =====\n\n"
140" -j, --json[=cgiosuvy]\n"
141" Print output in JSON or YAML format\n\n"
142" -q TYPE, --quietmode=TYPE (ATA)\n"
143" Set smartctl quiet mode to one of: errorsonly, silent, noserial\n\n"
144" -d TYPE, --device=TYPE\n"
145" Specify device type to one of:\n"
146" %s\n\n" // TODO: fold this string
147" -T TYPE, --tolerance=TYPE (ATA)\n"
148" Tolerance: normal, conservative, permissive, verypermissive\n\n"
149" -b TYPE, --badsum=TYPE (ATA)\n"
150" Set action on bad checksum to one of: warn, exit, ignore\n\n"
151" -r TYPE, --report=TYPE\n"
152" Report transactions (see man page)\n\n"
153" -n MODE[,STATUS[,STATUS2]], --nocheck=MODE[,STATUS[,STATUS2]] (ATA, SCSI)\n"
154" No check if: never, sleep, standby, idle (see man page)\n\n",
155 getvalidarglist('d').c_str()); // TODO: Use this function also for other options ?
156 pout(
157"============================== DEVICE FEATURE ENABLE/DISABLE COMMANDS =====\n\n"
158" -s VALUE, --smart=VALUE\n"
159" Enable/disable SMART on device (on/off)\n\n"
160" -o VALUE, --offlineauto=VALUE (ATA)\n"
161" Enable/disable automatic offline testing on device (on/off)\n\n"
162" -S VALUE, --saveauto=VALUE (ATA)\n"
163" Enable/disable Attribute autosave on device (on/off)\n\n"
164" -s NAME[,VALUE], --set=NAME[,VALUE]\n"
165" Enable/disable/change device setting: aam,[N|off], apm,[N|off],\n"
166" dsn,[on|off], lookahead,[on|off], security-freeze,\n"
167" standby,[N|off|now], wcache,[on|off], rcache,[on|off],\n"
168" wcreorder,[on|off[,p]], wcache-sct,[ata|on|off[,p]]\n\n"
169 );
170 pout(
171"======================================= READ AND DISPLAY DATA OPTIONS =====\n\n"
172" -H, --health\n"
173" Show device SMART health status\n\n"
174" -c, --capabilities (ATA, NVMe)\n"
175" Show device SMART capabilities\n\n"
176" -A, --attributes\n"
177" Show device SMART vendor-specific Attributes and values\n\n"
178" -f FORMAT, --format=FORMAT (ATA)\n"
179" Set output format for attributes: old, brief, hex[,id|val]\n\n"
180" -l TYPE, --log=TYPE\n"
181" Show device log. TYPE: error, selftest, selective, directory[,g|s],\n"
182" xerror[,N][,error], xselftest[,N][,selftest], background,\n"
183" sasphy[,reset], sataphy[,reset], scttemp[sts,hist],\n"
184" scttempint,N[,p], scterc[,N,M][,p|reset], devstat[,N], defects[,N],\n"
185" ssd, gplog,N[,RANGE], smartlog,N[,RANGE], nvmelog,N,SIZE\n"
186" tapedevstat, zdevstat, envrep\n\n"
187" -v N,OPTION , --vendorattribute=N,OPTION (ATA)\n"
188" Set display OPTION for vendor Attribute N (see man page)\n\n"
189" -F TYPE, --firmwarebug=TYPE (ATA)\n"
190" Use firmware bug workaround:\n"
191" %s, swapid\n\n"
192" -P TYPE, --presets=TYPE (ATA)\n"
193" Drive-specific presets: use, ignore, show, showall\n\n"
194" -B [+]FILE, --drivedb=[+]FILE (ATA)\n"
195" Read and replace [add] drive database from FILE\n"
196" [default is +%s",
199 );
200#ifdef SMARTMONTOOLS_DRIVEDBDIR
201 pout(
202 "\n"
203" and then %s",
204 get_drivedb_path_default()
205 );
206#endif
207 pout(
208 "]\n\n"
209"============================================ DEVICE SELF-TEST OPTIONS =====\n\n"
210" -t TEST, --test=TEST\n"
211" Run test. TEST: offline, short, long, conveyance, force, vendor,N,\n"
212" select,M-N, pending,N, afterselect,[on|off]\n\n"
213" -C, --captive\n"
214" Do test in captive mode (along with -t)\n\n"
215" -X, --abort\n"
216" Abort any non-captive test on device\n\n"
217);
218 std::string examples = smi()->get_app_examples("smartctl");
219 if (!examples.empty())
220 pout("%s\n", examples.c_str());
221}
222
223// Values for --long only options, see parse_options()
225
226/* Returns a string containing a formatted list of the valid arguments
227 to the option opt or empty on failure. Note 'v' case different */
228static std::string getvalidarglist(int opt)
229{
230 switch (opt) {
231 case 'q':
232 return "errorsonly, silent, noserial";
233 case 'd':
234 return smi()->get_valid_dev_types_str() + ", auto, test";
235 case 'T':
236 return "normal, conservative, permissive, verypermissive";
237 case 'b':
238 return "warn, exit, ignore";
239 case 'B':
240 return "[+]<FILE_NAME>";
241 case 'r':
242 return "ioctl[,N], ataioctl[,N], scsiioctl[,N], nvmeioctl[,N]";
243 case opt_smart:
244 case 'o':
245 case 'S':
246 return "on, off";
247 case 'l':
248 return "error, selftest, selective, directory[,g|s], "
249 "xerror[,N][,error], xselftest[,N][,selftest], "
250 "background, sasphy[,reset], sataphy[,reset], "
251 "scttemp[sts,hist], scttempint,N[,p], "
252 "scterc[,N,M][,p|reset], devstat[,N], defects[,N], "
253 "ssd, gplog,N[,RANGE], smartlog,N[,RANGE], "
254 "nvmelog,N,SIZE, tapedevstat, zdevstat, envrep";
255 case 'P':
256 return "use, ignore, show, showall";
257 case 't':
258 return "offline, short, long, conveyance, force, vendor,N, select,M-N, "
259 "pending,N, afterselect,[on|off]";
260 case 'F':
261 return std::string(get_valid_firmwarebug_args()) + ", swapid";
262 case 'n':
263 return "never, sleep[,STATUS[,STATUS2]], standby[,STATUS[,STATUS2]], "
264 "idle[,STATUS[,STATUS2]]";
265 case 'f':
266 return "old, brief, hex[,id|val]";
267 case 'g':
268 return "aam, apm, dsn, lookahead, security, wcache, rcache, wcreorder, wcache-sct";
269 case opt_set:
270 return "aam,[N|off], apm,[N|off], dsn,[on|off], lookahead,[on|off], security-freeze, "
271 "standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]], "
272 "wcache-sct,[ata|on|off[,p]]";
273 case 's':
275 case 'j':
276 return "c, g, i, o, s, u, v, y";
277 case opt_identify:
278 return "n, wn, w, v, wv, wb";
279 case 'v':
280 default:
281 return "";
282 }
283}
284
285/* Prints the message "=======> VALID ARGUMENTS ARE: <LIST> \n", where
286 <LIST> is the list of valid arguments for option opt. */
287static void printvalidarglistmessage(int opt)
288{
289 if (opt=='v'){
290 jerr("=======> VALID ARGUMENTS ARE:\n\thelp\n%s\n<=======\n",
292 }
293 else {
294 // getvalidarglist() might produce a multiline or single line string. We
295 // need to figure out which to get the formatting right.
296 std::string s = getvalidarglist(opt);
297 char separator = strchr(s.c_str(), '\n') ? '\n' : ' ';
298 jerr("=======> VALID ARGUMENTS ARE:%c%s%c<=======\n", separator, s.c_str(), separator);
299 }
300
301 return;
302}
303
304// Checksum error mode
308
310
311static void scan_devices(const smart_devtype_list & types, bool with_open, char ** argv);
312
313
314/* Takes command options and sets features to be run */
315static int parse_options(int argc, char** argv, const char * & type,
316 ata_print_options & ataopts, scsi_print_options & scsiopts,
317 nvme_print_options & nvmeopts, bool & print_type_only)
318{
319 // Please update getvalidarglist() if you edit shortopts
320 const char *shortopts = "h?Vq:d:T:b:r:s:o:S:HcAl:iaxv:P:t:CXF:n:B:f:g:j";
321 // Please update getvalidarglist() if you edit longopts
322 struct option longopts[] = {
323 { "help", no_argument, 0, 'h' },
324 { "usage", no_argument, 0, 'h' },
325 { "version", no_argument, 0, 'V' },
326 { "copyright", no_argument, 0, 'V' },
327 { "license", no_argument, 0, 'V' },
328 { "quietmode", required_argument, 0, 'q' },
329 { "device", required_argument, 0, 'd' },
330 { "tolerance", required_argument, 0, 'T' },
331 { "badsum", required_argument, 0, 'b' },
332 { "report", required_argument, 0, 'r' },
333 { "smart", required_argument, 0, opt_smart },
334 { "offlineauto", required_argument, 0, 'o' },
335 { "saveauto", required_argument, 0, 'S' },
336 { "health", no_argument, 0, 'H' },
337 { "capabilities", no_argument, 0, 'c' },
338 { "attributes", no_argument, 0, 'A' },
339 { "log", required_argument, 0, 'l' },
340 { "info", no_argument, 0, 'i' },
341 { "all", no_argument, 0, 'a' },
342 { "xall", no_argument, 0, 'x' },
343 { "vendorattribute", required_argument, 0, 'v' },
344 { "presets", required_argument, 0, 'P' },
345 { "test", required_argument, 0, 't' },
346 { "captive", no_argument, 0, 'C' },
347 { "abort", no_argument, 0, 'X' },
348 { "firmwarebug", required_argument, 0, 'F' },
349 { "nocheck", required_argument, 0, 'n' },
350 { "drivedb", required_argument, 0, 'B' },
351 { "format", required_argument, 0, 'f' },
352 { "get", required_argument, 0, 'g' },
353 { "json", optional_argument, 0, 'j' },
354 { "identify", optional_argument, 0, opt_identify },
355 { "set", required_argument, 0, opt_set },
356 { "scan", no_argument, 0, opt_scan },
357 { "scan-open", no_argument, 0, opt_scan_open },
358 { 0, 0, 0, 0 }
359 };
360
361 char extraerror[256];
362 memset(extraerror, 0, sizeof(extraerror));
363 opterr=optopt=0;
364
365 smart_devtype_list scan_types; // multiple -d TYPE options for --scan
366 bool use_default_db = true; // set false on '-B FILE'
367 bool output_format_set = false; // set true on '-f FORMAT'
368 int scan = 0; // set by --scan, --scan-open
369 bool badarg = false, captive = false;
370 int testcnt = 0; // number of self-tests requested
371
372 int optchar;
373 char *arg;
374
375 while ((optchar = getopt_long(argc, argv, shortopts, longopts, 0)) != -1) {
376
377 // Clang analyzer: Workaround for false positive messages
378 // 'Dereference of null pointer' and 'Null pointer argument'
379 bool optarg_is_set = !!optarg;
380 #ifdef __clang_analyzer__
381 if (!optarg_is_set) optarg = (char *)"";
382 #endif
383
384 switch (optchar){
385 case 'V':
386 printing_is_off = false;
387 pout("%s", format_version_info("smartctl", true /*full*/).c_str());
388 return 0;
389 case 'q':
390 if (!strcmp(optarg,"errorsonly")) {
392 printing_is_off = false;
393 } else if (!strcmp(optarg,"silent")) {
395 printing_is_off = true;
396 } else if (!strcmp(optarg,"noserial")) {
398 } else {
399 badarg = true;
400 }
401 break;
402 case 'd':
403 if (!strcmp(optarg, "test"))
404 print_type_only = true;
405 else if (!strcmp(optarg, "auto")) {
406 type = 0;
407 scan_types.clear();
408 }
409 else {
410 type = optarg;
411 scan_types.push_back(optarg);
412 }
413 break;
414 case 'T':
415 if (!strcmp(optarg,"normal")) {
418 } else if (!strcmp(optarg,"conservative")) {
420 } else if (!strcmp(optarg,"permissive")) {
421 if (failuretest_permissive < 0xff)
423 } else if (!strcmp(optarg,"verypermissive")) {
425 } else {
426 badarg = true;
427 }
428 break;
429 case 'b':
430 if (!strcmp(optarg,"warn")) {
432 } else if (!strcmp(optarg,"exit")) {
434 } else if (!strcmp(optarg,"ignore")) {
436 } else {
437 badarg = true;
438 }
439 break;
440 case 'r':
441 {
442 int n1 = -1, n2 = -1, len = strlen(optarg);
443 char s[9+1]; unsigned i = 1;
444 sscanf(optarg, "%9[a-z]%n,%u%n", s, &n1, &i, &n2);
445 if (!((n1 == len || n2 == len) && 1 <= i && i <= 4)) {
446 badarg = true;
447 } else if (!strcmp(s,"ioctl")) {
449 } else if (!strcmp(s,"ataioctl")) {
450 ata_debugmode = i;
451 } else if (!strcmp(s,"scsiioctl")) {
452 scsi_debugmode = i;
453 } else if (!strcmp(s,"nvmeioctl")) {
454 nvme_debugmode = i;
455 } else {
456 badarg = true;
457 }
458 }
459 break;
460
461 case 's':
462 case opt_smart: // --smart
463 if (!strcmp(optarg,"on")) {
464 ataopts.smart_enable = scsiopts.smart_enable = true;
465 ataopts.smart_disable = scsiopts.smart_disable = false;
466 } else if (!strcmp(optarg,"off")) {
467 ataopts.smart_disable = scsiopts.smart_disable = true;
468 ataopts.smart_enable = scsiopts.smart_enable = false;
469 } else if (optchar == 's') {
470 goto case_s_continued; // --set, see below
471 } else {
472 badarg = true;
473 }
474 break;
475
476 case 'o':
477 if (!strcmp(optarg,"on")) {
478 ataopts.smart_auto_offl_enable = true;
479 ataopts.smart_auto_offl_disable = false;
480 } else if (!strcmp(optarg,"off")) {
481 ataopts.smart_auto_offl_disable = true;
482 ataopts.smart_auto_offl_enable = false;
483 } else {
484 badarg = true;
485 }
486 break;
487 case 'S':
488 if (!strcmp(optarg,"on")) {
489 ataopts.smart_auto_save_enable = scsiopts.smart_auto_save_enable = true;
490 ataopts.smart_auto_save_disable = scsiopts.smart_auto_save_disable = false;
491 } else if (!strcmp(optarg,"off")) {
492 ataopts.smart_auto_save_disable = scsiopts.smart_auto_save_disable = true;
493 ataopts.smart_auto_save_enable = scsiopts.smart_auto_save_enable = false;
494 } else {
495 badarg = true;
496 }
497 break;
498 case 'H':
499 ataopts.smart_check_status = scsiopts.smart_check_status = nvmeopts.smart_check_status = true;
500 scsiopts.smart_ss_media_log = true;
501 ++scsiopts.health_opt_count;
502 break;
503 case 'F':
504 if (!strcmp(optarg, "swapid"))
505 ataopts.fix_swapped_id = true;
506 else if (!parse_firmwarebug_def(optarg, ataopts.firmwarebugs))
507 badarg = true;
508 break;
509 case 'c':
510 ataopts.smart_general_values = nvmeopts.drive_capabilities = true;
511 break;
512 case 'A':
513 ataopts.smart_vendor_attrib = scsiopts.smart_vendor_attrib = nvmeopts.smart_vendor_attrib = true;
514 break;
515 case 'l':
516 if (str_starts_with(optarg, "error")) {
517 int n1 = -1, n2 = -1, len = strlen(optarg);
518 unsigned val = ~0;
519 sscanf(optarg, "error%n,%u%n", &n1, &val, &n2);
520 ataopts.smart_error_log = scsiopts.smart_error_log = true;
521 if (n1 == len)
522 nvmeopts.error_log_entries = 16;
523 else if (n2 == len && val > 0)
524 nvmeopts.error_log_entries = val;
525 else
526 badarg = true;
527 } else if (!strcmp(optarg,"selftest")) {
528 ataopts.smart_selftest_log = scsiopts.smart_selftest_log = true;
529 } else if (!strcmp(optarg, "selective")) {
530 ataopts.smart_selective_selftest_log = true;
531 } else if (!strcmp(optarg,"directory")) {
532 ataopts.smart_logdir = ataopts.gp_logdir = true; // SMART+GPL
533 } else if (!strcmp(optarg,"directory,s")) {
534 ataopts.smart_logdir = true; // SMART
535 } else if (!strcmp(optarg,"directory,g")) {
536 ataopts.gp_logdir = true; // GPL
537 } else if (!strcmp(optarg,"sasphy")) {
538 scsiopts.sasphy = true;
539 } else if (!strcmp(optarg,"sasphy,reset")) {
540 scsiopts.sasphy = scsiopts.sasphy_reset = true;
541 } else if (!strcmp(optarg,"sataphy")) {
542 ataopts.sataphy = true;
543 } else if (!strcmp(optarg,"sataphy,reset")) {
544 ataopts.sataphy = ataopts.sataphy_reset = true;
545 } else if (!strcmp(optarg,"background")) {
546 scsiopts.smart_background_log = true;
547 } else if (!strcmp(optarg,"ssd")) {
548 ataopts.devstat_ssd_page = true;
549 scsiopts.smart_ss_media_log = true;
550 } else if (!strcmp(optarg,"scterc")) {
551 ataopts.sct_erc_get = 1;
552 } else if (!strcmp(optarg,"scttemp")) {
553 ataopts.sct_temp_sts = ataopts.sct_temp_hist = true;
554 } else if (!strcmp(optarg,"envrep")) {
555 scsiopts.smart_env_rep = true;
556 } else if (!strcmp(optarg,"scttempsts")) {
557 ataopts.sct_temp_sts = true;
558 } else if (!strcmp(optarg,"scttemphist")) {
559 ataopts.sct_temp_hist = true;
560 } else if (!strcmp(optarg,"tapealert")) {
561 scsiopts.tape_alert = true;
562 } else if (!strcmp(optarg,"tapedevstat")) {
563 scsiopts.tape_device_stats = true;
564 } else if (!strcmp(optarg,"zdevstat")) {
565 scsiopts.zoned_device_stats = true;
566 } else if (!strncmp(optarg, "scttempint,", sizeof("scstempint,")-1)) {
567 unsigned interval = 0; int n1 = -1, n2 = -1, len = strlen(optarg);
568 if (!( sscanf(optarg,"scttempint,%u%n,p%n", &interval, &n1, &n2) == 1
569 && 0 < interval && interval <= 0xffff && (n1 == len || n2 == len))) {
570 snprintf(extraerror, sizeof(extraerror), "Option -l scttempint,N[,p] must have positive integer N\n");
571 badarg = true;
572 }
573 ataopts.sct_temp_int = interval;
574 ataopts.sct_temp_int_pers = (n2 == len);
575
576 } else if (!strncmp(optarg, "devstat", sizeof("devstat")-1)) {
577 int n1 = -1, n2 = -1, len = strlen(optarg);
578 unsigned val = ~0;
579 sscanf(optarg, "devstat%n,%u%n", &n1, &val, &n2);
580 if (n1 == len)
581 ataopts.devstat_all_pages = true;
582 else {
583 if (n2 != len) // retry with hex
584 sscanf(optarg, "devstat,0x%x%n", &val, &n2);
585 if (n2 == len && val <= 0xff)
586 ataopts.devstat_pages.push_back(val);
587 else
588 badarg = true;
589 }
590
591 } else if (str_starts_with(optarg, "defects")) {
592 int n1 = -1, n2 = -1, len = strlen(optarg);
593 unsigned val = ~0;
594 sscanf(optarg, "defects%n,%u%n", &n1, &val, &n2);
595 scsiopts.scsi_pending_defects = true;
596 if (n1 == len)
597 ataopts.pending_defects_log = 31; // Entries of first page
598 else if (n2 == len && val <= 0xffff * 32 - 1)
599 ataopts.pending_defects_log = val;
600 else
601 badarg = true;
602
603 } else if (!strncmp(optarg, "xerror", sizeof("xerror")-1)) {
604 int n1 = -1, n2 = -1, len = strlen(optarg);
605 unsigned val = 8;
606 sscanf(optarg, "xerror%n,error%n", &n1, &n2);
607 if (!(n1 == len || n2 == len)) {
608 n1 = n2 = -1;
609 sscanf(optarg, "xerror,%u%n,error%n", &val, &n1, &n2);
610 }
611 if ((n1 == len || n2 == len) && val > 0) {
612 ataopts.smart_ext_error_log = val;
613 ataopts.retry_error_log = (n2 == len);
614 }
615 else
616 badarg = true;
617
618 } else if (!strncmp(optarg, "xselftest", sizeof("xselftest")-1)) {
619 int n1 = -1, n2 = -1, len = strlen(optarg);
620 unsigned val = 25;
621 sscanf(optarg, "xselftest%n,selftest%n", &n1, &n2);
622 if (!(n1 == len || n2 == len)) {
623 n1 = n2 = -1;
624 sscanf(optarg, "xselftest,%u%n,selftest%n", &val, &n1, &n2);
625 }
626 if ((n1 == len || n2 == len) && val > 0) {
627 ataopts.smart_ext_selftest_log = val;
628 ataopts.retry_selftest_log = (n2 == len);
629 }
630 else
631 badarg = true;
632
633 } else if (!strncmp(optarg, "scterc,", sizeof("scterc,")-1)) {
634 int n1 = -1, n2 = -1, len = strlen(optarg);
635 unsigned rt = ~0, wt = ~0;
636 sscanf(optarg, "scterc,%u,%u%n,p%n", &rt, &wt, &n1, &n2);
637 if ((n1 == len || n2 == len) && rt <= 999 && wt <= 999) {
638 ataopts.sct_erc_set = (n2 == len ? 2 : 1);
639 ataopts.sct_erc_readtime = rt;
640 ataopts.sct_erc_writetime = wt;
641 } else if (!strcmp(optarg, "scterc,p")) {
642 ataopts.sct_erc_get = 2;
643 } else if (!strcmp(optarg, "scterc,reset")) {
644 ataopts.sct_erc_set = 3;
645 ataopts.sct_erc_readtime = ataopts.sct_erc_writetime = 0;
646 } else {
647 snprintf(extraerror, sizeof(extraerror), "Option -l scterc[,READTIME,WRITETIME][,p|reset] syntax error\n");
648 badarg = true;
649 }
650 } else if ( !strncmp(optarg, "gplog," , sizeof("gplog," )-1)
651 || !strncmp(optarg, "smartlog,", sizeof("smartlog,")-1)) {
652 unsigned logaddr = ~0U; unsigned page = 0, nsectors = 1; char sign = 0;
653 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
654 sscanf(optarg, "%*[a-z],0x%x%n,%u%n%c%u%n",
655 &logaddr, &n1, &page, &n2, &sign, &nsectors, &n3);
656 if (len > n2 && n3 == -1 && !strcmp(optarg+n2, "-max")) {
657 nsectors = ~0U; sign = '+'; n3 = len;
658 }
659 bool gpl = (optarg[0] == 'g');
660 const char * erropt = (gpl ? "gplog" : "smartlog");
661 if (!( n1 == len || n2 == len
662 || (n3 == len && (sign == '+' || sign == '-')))) {
663 snprintf(extraerror, sizeof(extraerror), "Option -l %s,ADDR[,FIRST[-LAST|+SIZE]] syntax error\n", erropt);
664 badarg = true;
665 }
666 else if (!( logaddr <= 0xff && page <= (gpl ? 0xffffU : 0x00ffU)
667 && 0 < nsectors
668 && (nsectors <= (gpl ? 0xffffU : 0xffU) || nsectors == ~0U)
669 && (sign != '-' || page <= nsectors) )) {
670 snprintf(extraerror, sizeof(extraerror), "Option -l %s,ADDR[,FIRST[-LAST|+SIZE]] parameter out of range\n", erropt);
671 badarg = true;
672 }
673 else {
674 ata_log_request req;
675 req.gpl = gpl; req.logaddr = logaddr; req.page = page;
676 req.nsectors = (sign == '-' ? nsectors-page+1 : nsectors);
677 ataopts.log_requests.push_back(req);
678 }
679 }
680
681 else if (str_starts_with(optarg, "nvmelog,")) {
682 int n = -1, len = strlen(optarg);
683 unsigned page = 0, size = 0;
684 sscanf(optarg, "nvmelog,0x%x,0x%x%n", &page, &size, &n);
685 if (n == len && page <= 0xff && 0 < size && size <= 0x4000) {
686 nvmeopts.log_page = page; nvmeopts.log_page_size = size;
687 }
688 else
689 badarg = true;
690 }
691
692 else {
693 badarg = true;
694 }
695 break;
696 case 'i':
697 ataopts.drive_info = scsiopts.drive_info = nvmeopts.drive_info = true;
698 break;
699
700 case opt_identify:
701 ataopts.identify_word_level = ataopts.identify_bit_level = 0;
702 if (optarg_is_set) {
703 for (int i = 0; optarg[i]; i++) {
704 switch (optarg[i]) {
705 case 'w': ataopts.identify_word_level = 1; break;
706 case 'n': ataopts.identify_bit_level = -1; break;
707 case 'v': ataopts.identify_bit_level = 1; break;
708 case 'b': ataopts.identify_bit_level = 2; break;
709 default: badarg = true;
710 }
711 }
712 }
713 break;
714
715 case 'a':
716 ataopts.drive_info = scsiopts.drive_info = nvmeopts.drive_info = true;
717 ataopts.smart_check_status = scsiopts.smart_check_status = nvmeopts.smart_check_status = true;
718 ataopts.smart_general_values = nvmeopts.drive_capabilities = true;
719 ataopts.smart_vendor_attrib = scsiopts.smart_vendor_attrib = nvmeopts.smart_vendor_attrib = true;
720 ataopts.smart_error_log = scsiopts.smart_error_log = true;
721 nvmeopts.error_log_entries = 16;
722 ataopts.smart_selftest_log = scsiopts.smart_selftest_log = true;
723 ataopts.smart_selective_selftest_log = true;
724 /* scsiopts.smart_background_log = true; */
725 scsiopts.smart_ss_media_log = true;
726 break;
727 case 'x':
728 ataopts.drive_info = scsiopts.drive_info = nvmeopts.drive_info = true;
729 ataopts.smart_check_status = scsiopts.smart_check_status = nvmeopts.smart_check_status = true;
730 ataopts.smart_general_values = nvmeopts.drive_capabilities = true;
731 ataopts.smart_vendor_attrib = scsiopts.smart_vendor_attrib = nvmeopts.smart_vendor_attrib = true;
732 ataopts.smart_ext_error_log = 8;
733 ataopts.retry_error_log = true;
734 nvmeopts.error_log_entries = 16;
735 ataopts.smart_ext_selftest_log = 25;
736 ataopts.retry_selftest_log = true;
737 scsiopts.smart_error_log = scsiopts.smart_selftest_log = true;
738 ataopts.smart_selective_selftest_log = true;
739 ataopts.smart_logdir = ataopts.gp_logdir = true;
740 ataopts.sct_temp_sts = ataopts.sct_temp_hist = true;
741 ataopts.sct_erc_get = 1;
742 ataopts.sct_wcache_reorder_get = true;
743 ataopts.devstat_all_pages = true;
744 ataopts.pending_defects_log = 31;
745 ataopts.sataphy = true;
746 ataopts.get_set_used = true;
747 ataopts.get_aam = ataopts.get_apm = true;
748 ataopts.get_security = true;
749 ataopts.get_lookahead = ataopts.get_wcache = true;
750 ataopts.get_dsn = true;
751 scsiopts.get_rcd = scsiopts.get_wce = true;
752 scsiopts.smart_background_log = true;
753 scsiopts.smart_ss_media_log = true;
754 scsiopts.sasphy = true;
755 scsiopts.smart_env_rep = true;
756 scsiopts.scsi_pending_defects = true;
757 scsiopts.tape_device_stats = true;
758 scsiopts.zoned_device_stats = true;
759 if (!output_format_set)
761 break;
762 case 'v':
763 // parse vendor-specific definitions of attributes
764 if (!strcmp(optarg,"help")) {
765 printing_is_off = false;
766 printslogan();
767 pout("The valid arguments to -v are:\n\thelp\n%s\n",
769 return 0;
770 }
771 if (!parse_attribute_def(optarg, ataopts.attribute_defs, PRIOR_USER))
772 badarg = true;
773 break;
774 case 'P':
775 if (!strcmp(optarg, "use")) {
776 ataopts.ignore_presets = false;
777 } else if (!strcmp(optarg, "ignore")) {
778 ataopts.ignore_presets = true;
779 } else if (!strcmp(optarg, "show")) {
780 ataopts.show_presets = true;
781 } else if (!strcmp(optarg, "showall")) {
782 if (!init_drive_database(use_default_db))
783 return FAILCMD;
784 if (optind < argc) { // -P showall MODEL [FIRMWARE]
785 int cnt = showmatchingpresets(argv[optind], (optind+1<argc ? argv[optind+1] : NULL));
786 return (cnt >= 0 ? cnt : 0);
787 }
788 if (showallpresets())
789 return FAILCMD; // report regexp syntax error
790 return 0;
791 } else {
792 badarg = true;
793 }
794 break;
795 case 't':
796 if (!strcmp(optarg,"offline")) {
797 testcnt++;
799 scsiopts.smart_default_selftest = true;
800 } else if (!strcmp(optarg,"short")) {
801 testcnt++;
803 scsiopts.smart_short_selftest = true;
804 } else if (!strcmp(optarg,"long")) {
805 testcnt++;
807 scsiopts.smart_extend_selftest = true;
808 } else if (!strcmp(optarg,"conveyance")) {
809 testcnt++;
811 } else if (!strcmp(optarg,"force")) {
812 ataopts.smart_selftest_force = true;
813 scsiopts.smart_selftest_force = true;
814 } else if (!strcmp(optarg,"afterselect,on")) {
815 // scan remainder of disk after doing selected segment
817 } else if (!strcmp(optarg,"afterselect,off")) {
818 // don't scan remainder of disk after doing selected segments
820 } else if (!strncmp(optarg,"pending,",strlen("pending,"))) {
821 // parse number of minutes that test should be pending
822 int i;
823 char *tailptr=NULL;
824 errno=0;
825 i=(int)strtol(optarg+strlen("pending,"), &tailptr, 10);
826 if (errno || *tailptr != '\0') {
827 snprintf(extraerror, sizeof(extraerror), "Option -t pending,N requires N to be a non-negative integer\n");
828 badarg = true;
829 } else if (i<0 || i>65535) {
830 snprintf(extraerror, sizeof(extraerror), "Option -t pending,N (N=%d) must have 0 <= N <= 65535\n", i);
831 badarg = true;
832 } else {
834 }
835 } else if (!strncmp(optarg,"select",strlen("select"))) {
836 if (ataopts.smart_selective_args.num_spans == 0)
837 testcnt++;
838 // parse range of LBAs to test
839 uint64_t start, stop; int mode;
840 if (split_selective_arg(optarg, &start, &stop, &mode)) {
841 snprintf(extraerror, sizeof(extraerror), "Option -t select,M-N must have non-negative integer M and N\n");
842 badarg = true;
843 } else {
844 if (ataopts.smart_selective_args.num_spans >= 5 || start > stop) {
845 if (start > stop) {
846 snprintf(extraerror, sizeof(extraerror), "ERROR: Start LBA (%" PRIu64 ") > ending LBA (%" PRId64 ") in argument \"%s\"\n",
847 start, stop, optarg);
848 } else {
849 snprintf(extraerror, sizeof(extraerror),"ERROR: No more than five selective self-test spans may be"
850 " defined\n");
851 }
852 badarg = true;
853 }
859 }
860 } else if (!strncmp(optarg, "scttempint", sizeof("scstempint")-1)) {
861 snprintf(extraerror, sizeof(extraerror), "-t scttempint is no longer supported, use -l scttempint instead\n");
862 badarg = true;
863 } else if (!strncmp(optarg, "vendor,", sizeof("vendor,")-1)) {
864 unsigned subcmd = ~0U; int n = -1;
865 if (!( sscanf(optarg, "%*[a-z],0x%x%n", &subcmd, &n) == 1
866 && subcmd <= 0xff && n == (int)strlen(optarg))) {
867 snprintf(extraerror, sizeof(extraerror), "Option -t vendor,0xNN syntax error\n");
868 badarg = true;
869 }
870 else
871 ataopts.smart_selftest_type = subcmd;
872 } else {
873 badarg = true;
874 }
875 break;
876 case 'C':
877 captive = true;
878 break;
879 case 'X':
880 testcnt++;
881 scsiopts.smart_selftest_abort = true;
883 break;
884 case 'n':
885 // skip disk check if in low-power mode
886 if (!strcmp(optarg, "never")) {
887 ataopts.powermode = 1; // do not skip, but print mode
888 scsiopts.powermode = 1;
889 }
890 else {
891 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
892 char s[7+1]; unsigned i = FAILPOWER, j = 0;
893 sscanf(optarg, "%7[a-z]%n,%u%n,%u%n", s, &n1, &i, &n2, &j, &n3);
894 if (!((n1 == len || n2 == len || n3 == len) && i <= 255 && j <= 255))
895 badarg = true;
896 else if (!strcmp(s, "sleep")) {
897 ataopts.powermode = 2;
898 scsiopts.powermode = 2;
899 } else if (!strcmp(s, "standby")) {
900 ataopts.powermode = 3;
901 scsiopts.powermode = 3;
902 } else if (!strcmp(s, "idle")) {
903 ataopts.powermode = 4;
904 scsiopts.powermode = 4;
905 } else
906 badarg = true;
907
908 ataopts.powerexit = i;
909 ataopts.powerexit_unsup = (n3 == len ? j : -1);
910 scsiopts.powerexit = i;
911 }
912 break;
913 case 'f':
914 if (!strcmp(optarg, "old")) {
915 ataopts.output_format &= ~ata_print_options::FMT_BRIEF;
916 output_format_set = true;
917 }
918 else if (!strcmp(optarg, "brief")) {
920 output_format_set = true;
921 }
922 else if (!strcmp(optarg, "hex"))
925 else if (!strcmp(optarg, "hex,id"))
927 else if (!strcmp(optarg, "hex,val"))
929 else
930 badarg = true;
931 break;
932 case 'B':
933 {
934 const char * path = optarg;
935 if (*path == '+' && path[1])
936 path++;
937 else
938 use_default_db = false;
939 if (!read_drive_database(path))
940 return FAILCMD;
941 }
942 break;
943 case 'h':
944 printing_is_off = false;
945 printslogan();
946 Usage();
947 return 0;
948
949 case 'g':
950 case_s_continued: // -s, see above
951 case opt_set: // --set
952 {
953 ataopts.get_set_used = true;
954 bool get = (optchar == 'g');
955 char name[16+1]; unsigned val;
956 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
957 if (sscanf(optarg, "%16[^,=]%n%*[,=]%n%u%n", name, &n1, &n2, &val, &n3) >= 1
958 && (n1 == len || (!get && n2 > 0))) {
959 bool on = false;
960 bool off = false;
961 bool ata = false;
962 bool persistent = false;
963
964 if (n2 > 0) {
965 int len2 = strlen(optarg + n2);
966 char * tmp = strstr(optarg+n2, ",p");
967 // handle ",p" in persistent options like: wcache-sct,[ata|on|off],p
968 if (tmp && (strlen(tmp) == 2)) {
969 persistent = true;
970 len2 = strlen(optarg+n2) - 2;
971
972 // the ,p option only works for set of SCT Feature Control command
973 if (strcmp(name, "wcache-sct") != 0 &&
974 strcmp(name, "wcreorder") != 0)
975 badarg = true;
976 }
977 on = !strncmp(optarg+n2, "on", len2);
978 off = !strncmp(optarg+n2, "off", len2);
979 ata = !strncmp(optarg+n2, "ata", len2);
980 }
981 if (n3 != len)
982 val = ~0U;
983
984 if (get && !strcmp(name, "all")) {
985 ataopts.get_aam = ataopts.get_apm = true;
986 ataopts.get_security = true;
987 ataopts.get_lookahead = ataopts.get_wcache = true;
988 ataopts.get_dsn = true;
989 scsiopts.get_rcd = scsiopts.get_wce = true;
990 }
991 else if (!strcmp(name, "aam")) {
992 if (get)
993 ataopts.get_aam = true;
994 else if (off)
995 ataopts.set_aam = -1;
996 else if (val <= 254)
997 ataopts.set_aam = val + 1;
998 else {
999 snprintf(extraerror, sizeof(extraerror), "Option -s aam,N must have 0 <= N <= 254\n");
1000 badarg = true;
1001 }
1002 }
1003 else if (!strcmp(name, "apm")) {
1004 if (get)
1005 ataopts.get_apm = true;
1006 else if (off)
1007 ataopts.set_apm = -1;
1008 else if (1 <= val && val <= 254)
1009 ataopts.set_apm = val + 1;
1010 else {
1011 snprintf(extraerror, sizeof(extraerror), "Option -s apm,N must have 1 <= N <= 254\n");
1012 badarg = true;
1013 }
1014 }
1015 else if (!strcmp(name, "lookahead")) {
1016 if (get) {
1017 ataopts.get_lookahead = true;
1018 }
1019 else if (off)
1020 ataopts.set_lookahead = -1;
1021 else if (on)
1022 ataopts.set_lookahead = 1;
1023 else
1024 badarg = true;
1025 }
1026 else if (!strcmp(name, "wcreorder")) {
1027 ataopts.sct_wcache_reorder_set_pers = persistent;
1028 if (get) {
1029 ataopts.sct_wcache_reorder_get = true;
1030 }
1031 else if (off)
1032 ataopts.sct_wcache_reorder_set = -1;
1033 else if (on)
1034 ataopts.sct_wcache_reorder_set = 1;
1035 else
1036 badarg = true;
1037 }
1038 else if (!strcmp(name, "wcache-sct")) {
1039 ataopts.sct_wcache_sct_set_pers = persistent;
1040 if (get) {
1041 ataopts.sct_wcache_sct_get = true;
1042 }
1043 else if (off)
1044 ataopts.sct_wcache_sct_set = 3;
1045 else if (on)
1046 ataopts.sct_wcache_sct_set = 2;
1047 else if (ata)
1048 ataopts.sct_wcache_sct_set = 1;
1049 else
1050 badarg = true;
1051 }
1052 else if (!strcmp(name, "rcache")) {
1053 if (get)
1054 scsiopts.get_rcd = true;
1055 else if (off)
1056 scsiopts.set_rcd = -1;
1057 else if (on)
1058 scsiopts.set_rcd = 1;
1059 else
1060 badarg = true;
1061 }
1062 else if (get && !strcmp(name, "security")) {
1063 ataopts.get_security = true;
1064 }
1065 else if (!get && !strcmp(optarg, "security-freeze")) {
1066 ataopts.set_security_freeze = true;
1067 }
1068 else if (!get && !strcmp(optarg, "standby,now")) {
1069 ataopts.set_standby_now = true;
1070 scsiopts.set_standby_now = true;
1071 }
1072 else if (!get && !strcmp(name, "standby")) {
1073 if (off) {
1074 ataopts.set_standby = 0 + 1;
1075 scsiopts.set_standby = 0 + 1;
1076 } else if (val <= 255) {
1077 ataopts.set_standby = val + 1;
1078 scsiopts.set_standby = val + 1;
1079 } else {
1080 snprintf(extraerror, sizeof(extraerror), "Option -s standby,N must have 0 <= N <= 255\n");
1081 badarg = true;
1082 }
1083 }
1084 else if (!strcmp(name, "wcache")) {
1085 if (get) {
1086 ataopts.get_wcache = true;
1087 scsiopts.get_wce = true;
1088 }
1089 else if (off) {
1090 ataopts.set_wcache = -1;
1091 scsiopts.set_wce = -1;
1092 }
1093 else if (on) {
1094 ataopts.set_wcache = 1;
1095 scsiopts.set_wce = 1;
1096 }
1097 else
1098 badarg = true;
1099 }
1100 else if (!strcmp(name, "dsn")) {
1101 if (get) {
1102 ataopts.get_dsn = true;
1103 }
1104 else if (off) {
1105 ataopts.set_dsn = -1;
1106 }
1107 else if (on) {
1108 ataopts.set_dsn = 1;
1109 }
1110 else
1111 badarg = true;
1112 }
1113 else
1114 badarg = true;
1115 }
1116 else
1117 badarg = true;
1118 }
1119 break;
1120
1121 case opt_scan:
1122 case opt_scan_open:
1123 scan = optchar;
1124 break;
1125
1126 case 'j':
1127 {
1128 print_as_json = true;
1132 print_as_json_output = false;
1134 bool json_verbose = false;
1135 if (optarg_is_set) {
1136 for (int i = 0; optarg[i]; i++) {
1137 switch (optarg[i]) {
1138 case 'c': print_as_json_options.pretty = false; break;
1139 case 'g': print_as_json_options.format = 'g'; break;
1140 case 'i': print_as_json_impl = true; break;
1141 case 'o': print_as_json_output = true; break;
1142 case 's': print_as_json_options.sorted = true; break;
1143 case 'u': print_as_json_unimpl = true; break;
1144 case 'v': json_verbose = true; break;
1145 case 'y': print_as_json_options.format = 'y'; break;
1146 default: badarg = true;
1147 }
1148 }
1149 }
1150 js_initialize(argc, argv, json_verbose);
1151 }
1152 break;
1153
1154 case '?':
1155 default:
1156 printing_is_off = false;
1157 printslogan();
1158 // Point arg to the argument in which this option was found.
1159 arg = argv[optind-1];
1160 // Check whether the option is a long option that doesn't map to -h.
1161 if (arg[1] == '-' && optchar != 'h') {
1162 // Iff optopt holds a valid option then argument must be missing.
1163 if (optopt && (optopt > '~' || strchr(shortopts, optopt))) {
1164 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %s\n", arg+2);
1166 } else
1167 jerr("=======> UNRECOGNIZED OPTION: %s\n",arg+2);
1168 if (extraerror[0])
1169 pout("=======> %s", extraerror);
1170 UsageSummary();
1171 return FAILCMD;
1172 }
1173 if (0 < optopt && optopt < '~') {
1174 // Iff optopt holds a valid option then argument must be
1175 // missing. Note (BA) this logic seems to fail using Solaris
1176 // getopt!
1177 if (strchr(shortopts, optopt) != NULL) {
1178 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %c\n", optopt);
1180 } else
1181 jerr("=======> UNRECOGNIZED OPTION: %c\n",optopt);
1182 if (extraerror[0])
1183 pout("=======> %s", extraerror);
1184 UsageSummary();
1185 return FAILCMD;
1186 }
1187 Usage();
1188 return 0;
1189 } // closes switch statement to process command-line options
1190
1191 // Check to see if option had an unrecognized or incorrect argument.
1192 if (badarg) {
1193 printslogan();
1194 // It would be nice to print the actual option name given by the user
1195 // here, but we just print the short form. Please fix this if you know
1196 // a clean way to do it.
1197 char optstr[] = { (char)optchar, 0 };
1198 jerr("=======> INVALID ARGUMENT TO -%s: %s\n",
1199 (optchar == opt_identify ? "-identify" :
1200 optchar == opt_set ? "-set" :
1201 optchar == opt_smart ? "-smart" :
1202 optchar == 'j' ? "-json" : optstr), optarg);
1203 printvalidarglistmessage(optchar);
1204 if (extraerror[0])
1205 pout("=======> %s", extraerror);
1206 UsageSummary();
1207 return FAILCMD;
1208 }
1209 }
1210
1211 // Special handling of --scan, --scanopen
1212 if (scan) {
1213 // Read or init drive database to allow USB ID check.
1214 if (!init_drive_database(use_default_db))
1215 return FAILCMD;
1216 scan_devices(scan_types, (scan == opt_scan_open), argv + optind);
1217 return 0;
1218 }
1219
1220 // At this point we have processed all command-line options. If the
1221 // print output is switchable, then start with the print output
1222 // turned off
1224 printing_is_off = true;
1225
1226 // Check for multiple -d TYPE options
1227 if (scan_types.size() > 1) {
1228 printing_is_off = false;
1229 printslogan();
1230 jerr("ERROR: multiple -d TYPE options are only allowed with --scan\n");
1231 UsageSummary();
1232 return FAILCMD;
1233 }
1234
1235 // error message if user has asked for more than one test
1236 if (testcnt > 1) {
1237 printing_is_off = false;
1238 printslogan();
1239 jerr("\nERROR: smartctl can only run a single test type (or abort) at a time.\n");
1240 UsageSummary();
1241 return FAILCMD;
1242 }
1243
1244 // error message if user has set selective self-test options without
1245 // asking for a selective self-test
1246 if ( (ataopts.smart_selective_args.pending_time || ataopts.smart_selective_args.scan_after_select)
1247 && !ataopts.smart_selective_args.num_spans) {
1248 printing_is_off = false;
1249 printslogan();
1250 if (ataopts.smart_selective_args.pending_time)
1251 jerr("\nERROR: smartctl -t pending,N must be used with -t select,N-M.\n");
1252 else
1253 jerr("\nERROR: smartctl -t afterselect,(on|off) must be used with -t select,N-M.\n");
1254 UsageSummary();
1255 return FAILCMD;
1256 }
1257
1258 // If captive option was used, change test type if appropriate.
1259 if (captive)
1260 switch (ataopts.smart_selftest_type) {
1261 case SHORT_SELF_TEST:
1262 ataopts.smart_selftest_type = SHORT_CAPTIVE_SELF_TEST;
1263 scsiopts.smart_short_selftest = false;
1264 scsiopts.smart_short_cap_selftest = true;
1265 break;
1266 case EXTEND_SELF_TEST:
1267 ataopts.smart_selftest_type = EXTEND_CAPTIVE_SELF_TEST;
1268 scsiopts.smart_extend_selftest = false;
1269 scsiopts.smart_extend_cap_selftest = true;
1270 break;
1272 ataopts.smart_selftest_type = CONVEYANCE_CAPTIVE_SELF_TEST;
1273 break;
1275 ataopts.smart_selftest_type = SELECTIVE_CAPTIVE_SELF_TEST;
1276 break;
1277 }
1278
1279 // From here on, normal operations...
1280 printslogan();
1281
1282 // Warn if the user has provided no device name
1283 if (argc-optind<1){
1284 jerr("ERROR: smartctl requires a device name as the final command-line argument.\n\n");
1285 UsageSummary();
1286 return FAILCMD;
1287 }
1288
1289 // Warn if the user has provided more than one device name
1290 if (argc-optind>1){
1291 int i;
1292 jerr("ERROR: smartctl takes ONE device name as the final command-line argument.\n");
1293 pout("You have provided %d device names:\n",argc-optind);
1294 for (i=0; i<argc-optind; i++)
1295 pout("%s\n",argv[optind+i]);
1296 UsageSummary();
1297 return FAILCMD;
1298 }
1299
1300 // Read or init drive database
1301 if (!init_drive_database(use_default_db))
1302 return FAILCMD;
1303
1304 // No error, continue in main_worker()
1305 return -1;
1306}
1307
1308// Printing functions
1309
1311static void vjpout(bool is_js_impl, const char * msg_severity,
1312 const char *fmt, va_list ap)
1313{
1314 if (!print_as_json) {
1315 // Print out directly
1316 vprintf(fmt, ap);
1317 fflush(stdout);
1318 }
1319 else {
1320 // Add lines to JSON output
1321 static char buf[1024];
1322 static char * bufnext = buf;
1323 vsnprintf(bufnext, sizeof(buf) - (bufnext - buf), fmt, ap);
1324 for (char * p = buf, *q; ; p = q) {
1325 if (!(q = strchr(p, '\n'))) {
1326 // Keep remaining line for next call
1327 for (bufnext = buf; *p; bufnext++, p++)
1328 *bufnext = *p;
1329 break;
1330 }
1331 *q++ = 0; // '\n' -> '\0'
1332
1333 static int lineno = 0;
1334 lineno++;
1336 // Collect full output in array
1337 static int outindex = 0;
1338 jglb["smartctl"]["output"][outindex++] = p;
1339 }
1340 if (!*p)
1341 continue; // Skip empty line
1342
1343 if (msg_severity) {
1344 // Collect non-empty messages in array
1345 static int errindex = 0;
1346 json::ref jref = jglb["smartctl"]["messages"][errindex++];
1347 jref["string"] = p;
1348 jref["severity"] = msg_severity;
1349 }
1350
1351 if ( ( is_js_impl && print_as_json_impl )
1352 || (!is_js_impl && print_as_json_unimpl)) {
1353 // Add (un)implemented non-empty lines to global object
1354 jglb[strprintf("smartctl_%04d_%c", lineno,
1355 (is_js_impl ? 'i' : 'u')).c_str()] = p;
1356 }
1357 }
1358 }
1359}
1360
1361// Default: print to stdout
1362// --json: ignore
1363// --json=o: append to "output" array
1364// --json=u: add "smartctl_NNNN_u" element(s)
1365void pout(const char *fmt, ...)
1366{
1367 if (printing_is_off)
1368 return;
1371 return;
1372
1373 va_list ap;
1374 va_start(ap, fmt);
1375 vjpout(false, 0, fmt, ap);
1376 va_end(ap);
1377}
1378
1379// Default: Print to stdout
1380// --json: ignore
1381// --json=o: append to "output" array
1382// --json=i: add "smartctl_NNNN_i" element(s)
1383void jout(const char *fmt, ...)
1384{
1385 if (printing_is_off)
1386 return;
1389 return;
1390
1391 va_list ap;
1392 va_start(ap, fmt);
1393 vjpout(true, 0, fmt, ap);
1394 va_end(ap);
1395}
1396
1397// Default: print to stdout
1398// --json: append to "messages"
1399// --json=o: append to "output" array
1400// --json=i: add "smartctl_NNNN_i" element(s)
1401void jinf(const char *fmt, ...)
1402{
1403 if (printing_is_off)
1404 return;
1405
1406 va_list ap;
1407 va_start(ap, fmt);
1408 vjpout(true, "information", fmt, ap);
1409 va_end(ap);
1410}
1411
1412void jwrn(const char *fmt, ...)
1413{
1414 if (printing_is_off)
1415 return;
1416
1417 va_list ap;
1418 va_start(ap, fmt);
1419 vjpout(true, "warning", fmt, ap);
1420 va_end(ap);
1421}
1422
1423void jerr(const char *fmt, ...)
1424{
1425 if (printing_is_off)
1426 return;
1427
1428 va_list ap;
1429 va_start(ap, fmt);
1430 vjpout(true, "error", fmt, ap);
1431 va_end(ap);
1432}
1433
1434static char startup_datetime_buf[DATEANDEPOCHLEN];
1435
1436// Print smartctl start-up date and time and timezone
1437void jout_startup_datetime(const char *prefix)
1438{
1439 jout("%s%s\n", prefix, startup_datetime_buf);
1440}
1441
1442// Globals to set failuretest() policy
1444unsigned char failuretest_permissive = 0;
1445
1446// Compares failure type to policy in effect, and either exits or
1447// simply returns to the calling routine.
1448// Used in ataprint.cpp and scsiprint.cpp.
1449void failuretest(failure_type type, int returnvalue)
1450{
1451 // If this is an error in an "optional" SMART command
1452 if (type == OPTIONAL_CMD) {
1454 return;
1455 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1456 throw int(returnvalue);
1457 }
1458
1459 // If this is an error in a "mandatory" SMART command
1460 if (type == MANDATORY_CMD) {
1462 return;
1463 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1464 throw int(returnvalue);
1465 }
1466
1467 throw std::logic_error("failuretest: Unknown type");
1468}
1469
1470// Used to warn users about invalid checksums. Called from atacmds.cpp.
1471// Action to be taken may be altered by the user.
1472void checksumwarning(const char * string)
1473{
1474 // user has asked us to ignore checksum errors
1476 return;
1477
1478 pout("Warning! %s error: invalid SMART checksum.\n", string);
1479
1480 // user has asked us to fail on checksum errors
1482 throw int(FAILSMART);
1483}
1484
1485// Return info string about device protocol
1486static const char * get_protocol_info(const smart_device * dev)
1487{
1488 switch ( (int)dev->is_ata()
1489 | ((int)dev->is_scsi() << 1)
1490 | ((int)dev->is_nvme() << 2)) {
1491 case 0x1: return "ATA";
1492 case 0x2: return "SCSI";
1493 case 0x3: return "ATA+SCSI";
1494 case 0x4: return "NVMe";
1495 default: return "Unknown";
1496 }
1497}
1498
1499// Add JSON device info
1500static void js_device_info(const json::ref & jref, const smart_device * dev)
1501{
1502 jref["name"] = dev->get_dev_name();
1503 jref["info_name"] = dev->get_info_name();
1504 jref["type"] = dev->get_dev_type();
1505 jref["protocol"] = get_protocol_info(dev);
1506}
1507
1508// Device scan
1509// smartctl [-d type] --scan[-open] -- [PATTERN] [smartd directive ...]
1510void scan_devices(const smart_devtype_list & types, bool with_open, char ** argv)
1511{
1512 bool dont_print = !(ata_debugmode || scsi_debugmode || nvme_debugmode);
1513
1514 const char * pattern = 0;
1515 int ai = 0;
1516 if (argv[ai] && argv[ai][0] != '-')
1517 pattern = argv[ai++];
1518
1519 smart_device_list devlist;
1520 printing_is_off = dont_print;
1521 bool ok = smi()->scan_smart_devices(devlist, types, pattern);
1522 printing_is_off = false;
1523
1524 if (!ok) {
1525 pout("# scan_smart_devices: %s\n", smi()->get_errmsg());
1526 return;
1527 }
1528
1529 for (unsigned i = 0; i < devlist.size(); i++) {
1530 smart_device_auto_ptr dev( devlist.release(i) );
1531 json::ref jref = jglb["devices"][i];
1532
1533 if (with_open) {
1534 printing_is_off = dont_print;
1535 dev.replace ( dev->autodetect_open() );
1536 printing_is_off = false;
1537 }
1538
1539 js_device_info(jref, dev.get());
1540
1541 if (with_open && !dev->is_open()) {
1542 jout("# %s -d %s # %s, %s device open failed: %s\n", dev->get_dev_name(),
1543 dev->get_dev_type(), dev->get_info_name(),
1544 get_protocol_info(dev.get()), dev->get_errmsg());
1545 jref["open_error"] = dev->get_errmsg();
1546 continue;
1547 }
1548
1549 jout("%s -d %s", dev->get_dev_name(), dev->get_dev_type());
1550 if (!argv[ai])
1551 jout(" # %s, %s device\n", dev->get_info_name(), get_protocol_info(dev.get()));
1552 else {
1553 for (int j = ai; argv[j]; j++)
1554 jout(" %s", argv[j]);
1555 jout("\n");
1556 }
1557
1558 if (dev->is_open())
1559 dev->close();
1560 }
1561}
1562
1563// Main program without exception handling
1564static int main_worker(int argc, char **argv)
1565{
1566 // Throw if runtime environment does not match compile time test.
1567 check_config();
1568
1569 // Initialize interface
1571 if (!smi())
1572 return 1;
1573
1574 // Parse input arguments
1575 const char * type = 0;
1576 ata_print_options ataopts;
1577 scsi_print_options scsiopts;
1578 nvme_print_options nvmeopts;
1579 bool print_type_only = false;
1580 {
1581 int status = parse_options(argc, argv, type, ataopts, scsiopts, nvmeopts, print_type_only);
1582 if (status >= 0)
1583 return status;
1584 }
1585
1586 // Store formatted current time for jout_startup_datetime()
1587 // Output as JSON regardless of '-i' option
1588 {
1589 time_t now = time(nullptr);
1590 dateandtimezoneepoch(startup_datetime_buf, now);
1591 jglb["local_time"] += { {"time_t", now}, {"asctime", startup_datetime_buf} };
1592 }
1593
1594 const char * name = argv[argc-1];
1595
1597 if (!strcmp(name,"-")) {
1598 // Parse "smartctl -r ataioctl,2 ..." output from stdin
1599 if (type || print_type_only) {
1600 pout("-d option is not allowed in conjunction with device name \"-\".\n");
1601 UsageSummary();
1602 return FAILCMD;
1603 }
1604 dev = get_parsed_ata_device(smi(), name);
1605 }
1606 else
1607 // get device of appropriate type
1608 dev = smi()->get_smart_device(name, type);
1609
1610 if (!dev) {
1611 jerr("%s: %s\n", name, smi()->get_errmsg());
1612 if (type)
1614 else
1615 pout("Please specify device type with the -d option.\n");
1616 UsageSummary();
1617 return FAILCMD;
1618 }
1619
1620 if (print_type_only)
1621 // Report result of first autodetection
1622 pout("%s: Device of type '%s' [%s] detected\n",
1623 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1624
1625 if (dev->is_ata() && ataopts.powermode>=2 && dev->is_powered_down()) {
1626 jinf("Device is in STANDBY (OS) mode, exit(%d)\n", ataopts.powerexit);
1627 return ataopts.powerexit;
1628 }
1629
1630 // Open device
1631 {
1632 // Save old info
1633 smart_device::device_info oldinfo = dev->get_info();
1634
1635 // Open with autodetect support, may return 'better' device
1636 dev.replace( dev->autodetect_open() );
1637
1638 // Report if type has changed
1639 if ( (ata_debugmode || scsi_debugmode || nvme_debugmode || print_type_only)
1640 && oldinfo.dev_type != dev->get_dev_type() )
1641 pout("%s: Device open changed type from '%s' to '%s'\n",
1642 dev->get_info_name(), oldinfo.dev_type.c_str(), dev->get_dev_type());
1643 }
1644 if (!dev->is_open()) {
1645 jerr("Smartctl open device: %s failed: %s\n", dev->get_info_name(), dev->get_errmsg());
1646 return FAILDEV;
1647 }
1648
1649 // Add JSON info similar to --scan output
1650 js_device_info(jglb["device"], dev.get());
1651
1652 // now call appropriate ATA or SCSI routine
1653 int retval = 0;
1654 if (print_type_only)
1655 jout("%s: Device of type '%s' [%s] opened\n",
1656 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1657 else if (dev->is_ata())
1658 retval = ataPrintMain(dev->to_ata(), ataopts);
1659 else if (dev->is_scsi())
1660 retval = scsiPrintMain(dev->to_scsi(), scsiopts);
1661 else if (dev->is_nvme())
1662 retval = nvmePrintMain(dev->to_nvme(), nvmeopts);
1663 else
1664 // we should never fall into this branch!
1665 pout("%s: Neither ATA, SCSI nor NVMe device\n", dev->get_info_name());
1666
1667 dev->close();
1668 return retval;
1669}
1670
1671
1672// Main program
1673int main(int argc, char **argv)
1674{
1675 int status;
1676 bool badcode = false;
1677
1678 try {
1679 try {
1680 // Do the real work ...
1681 status = main_worker(argc, argv);
1682 }
1683 catch (int ex) {
1684 // Exit status from checksumwarning() and failuretest() arrives here
1685 status = ex;
1686 }
1687 // Print JSON if enabled
1689 jglb["smartctl"]["uint128_precision_bits"] = uint128_to_str_precision_bits();
1690 jglb["smartctl"]["exit_status"] = status;
1692 }
1693 catch (const std::bad_alloc & /*ex*/) {
1694 // Memory allocation failed (also thrown by std::operator new)
1695 printf("Smartctl: Out of memory\n");
1696 status = FAILCMD;
1697 }
1698 catch (const std::exception & ex) {
1699 // Other fatal errors
1700 printf("Smartctl: Exception: %s\n", ex.what());
1701 badcode = true;
1702 status = FAILCMD;
1703 }
1704
1705 // Check for remaining device objects
1706 if (smart_device::get_num_objects() != 0) {
1707 printf("Smartctl: Internal Error: %d device object(s) left at exit.\n",
1709 badcode = true;
1710 status = FAILCMD;
1711 }
1712
1713 if (badcode)
1714 printf("Please inform " PACKAGE_BUGREPORT ", including output of smartctl -V.\n");
1715
1716 return status;
1717}
1718
ata_device * get_parsed_ata_device(smart_interface *intf, const char *dev_name)
Definition: atacmds.cpp:2838
bool parse_attribute_def(const char *opt, ata_vendor_attr_defs &defs, ata_vendor_def_prior priority)
Definition: atacmds.cpp:149
std::string create_vendor_attribute_arg_list()
Definition: atacmds.cpp:262
bool parse_firmwarebug_def(const char *opt, firmwarebug_defs &firmwarebugs)
Definition: atacmds.cpp:277
unsigned char ata_debugmode
Definition: atacmds.cpp:33
const char * get_valid_firmwarebug_args()
Definition: atacmds.cpp:297
bool dont_print_serial_number
Definition: atacmds.cpp:37
#define SELECTIVE_SELF_TEST
Definition: atacmds.h:101
#define OFFLINE_FULL_SCAN
Definition: atacmds.h:97
#define SHORT_SELF_TEST
Definition: atacmds.h:98
#define EXTEND_SELF_TEST
Definition: atacmds.h:99
@ PRIOR_USER
Definition: atacmds.h:644
#define ABORT_SELF_TEST
Definition: atacmds.h:102
#define EXTEND_CAPTIVE_SELF_TEST
Definition: atacmds.h:104
#define CONVEYANCE_CAPTIVE_SELF_TEST
Definition: atacmds.h:105
#define CONVEYANCE_SELF_TEST
Definition: atacmds.h:100
#define SHORT_CAPTIVE_SELF_TEST
Definition: atacmds.h:103
#define SELECTIVE_CAPTIVE_SELF_TEST
Definition: atacmds.h:106
int ataPrintMain(ata_device *device, const ata_print_options &options)
Definition: ataprint.cpp:3330
Smart pointer class for device pointers.
device_type * get() const
Return the pointer.
void replace(device_type *dev)
Replace the pointer.
Reference to a JSON element.
Definition: json.h:105
Create and print JSON output.
Definition: json.h:24
bool has_uint128_output() const
Return true if any 128-bit value has been output.
Definition: json.h:195
bool is_enabled() const
Return true if enabled.
Definition: json.h:187
void set_verbose(bool yes=true)
Enable/disable extra string output for safe integers also.
Definition: json.h:191
void enable(bool yes=true)
Enable/disable JSON output.
Definition: json.h:183
void print(FILE *f, const print_options &options) const
Print JSON tree to a file.
Definition: json.cpp:646
List of devices for DEVICESCAN.
unsigned size() const
smart_device * release(unsigned i)
Base class for all devices.
Definition: dev_interface.h:33
bool is_scsi() const
Return true if SCSI device.
Definition: dev_interface.h:89
bool is_nvme() const
Return true if NVMe device.
Definition: dev_interface.h:92
const char * get_dev_type() const
Get device type.
const char * get_info_name() const
Get informal name.
static int get_num_objects()
Get current number of allocated 'smart_device' objects.
bool is_ata() const
Return true if ATA device.
Definition: dev_interface.h:86
const char * get_dev_name() const
Get device (path)name.
virtual std::string get_app_examples(const char *appname)
Return example string for program 'appname'.
virtual smart_device * get_smart_device(const char *name, const char *type)
Return device object for device 'name' with some 'type'.
static void init()
Initialize platform interface and register with smi().
Definition: dev_legacy.cpp:334
virtual std::string get_os_version_str()
Return info string about build host and/or OS version.
virtual bool scan_smart_devices(smart_device_list &devlist, const char *type, const char *pattern=0)
Fill 'devlist' with devices of some 'type' with device names specified by some optional 'pattern'.
virtual std::string get_valid_dev_types_str()
Return valid args for device type option/directive.
std::vector< std::string > smart_devtype_list
List of types for DEVICESCAN.
smart_interface * smi()
Global access to the (usually singleton) smart_interface.
bool init_drive_database(bool use_default_db)
const char * get_drivedb_path_add()
bool read_drive_database(const char *path)
int showmatchingpresets(const char *model, const char *firmware)
int showallpresets()
u16 s[6]
Definition: megaraid.h:18
u32 size
Definition: megaraid.h:0
unsigned char nvme_debugmode
Definition: nvmecmds.cpp:27
int nvmePrintMain(nvme_device *device, const nvme_print_options &options)
Definition: nvmeprint.cpp:492
unsigned char scsi_debugmode
Definition: scsicmds.cpp:45
int scsiPrintMain(scsi_device *device, const scsi_print_options &options)
Definition: scsiprint.cpp:3126
bool failuretest_conservative
Definition: smartctl.cpp:1443
static std::string getvalidarglist(int opt)
Definition: smartctl.cpp:228
void jout_startup_datetime(const char *prefix)
Definition: smartctl.cpp:1437
unsigned char failuretest_permissive
Definition: smartctl.cpp:1444
bool printing_is_off
Definition: smartctl.cpp:50
static int parse_options(int argc, char **argv, const char *&type, ata_print_options &ataopts, scsi_print_options &scsiopts, nvme_print_options &nvmeopts, bool &print_type_only)
Definition: smartctl.cpp:315
checksum_err_mode_t
Definition: smartctl.cpp:305
@ CHECKSUM_ERR_IGNORE
Definition: smartctl.cpp:306
@ CHECKSUM_ERR_EXIT
Definition: smartctl.cpp:306
@ CHECKSUM_ERR_WARN
Definition: smartctl.cpp:306
@ opt_scan_open
Definition: smartctl.cpp:224
@ opt_set
Definition: smartctl.cpp:224
@ opt_identify
Definition: smartctl.cpp:224
@ opt_scan
Definition: smartctl.cpp:224
@ opt_smart
Definition: smartctl.cpp:224
int main(int argc, char **argv)
Definition: smartctl.cpp:1673
static json::print_options print_as_json_options
Definition: smartctl.cpp:55
static bool print_as_json_output
Definition: smartctl.cpp:56
static void js_device_info(const json::ref &jref, const smart_device *dev)
Definition: smartctl.cpp:1500
__attribute_format_printf(3, 0) static void vjpout(bool is_js_impl
void checksumwarning(const char *string)
Definition: smartctl.cpp:1472
static const char * get_protocol_info(const smart_device *dev)
Definition: smartctl.cpp:1486
json jglb
Definition: smartctl.cpp:53
static checksum_err_mode_t checksum_err_mode
Definition: smartctl.cpp:309
static void printvalidarglistmessage(int opt)
Definition: smartctl.cpp:287
static bool print_as_json_impl
Definition: smartctl.cpp:57
static bool print_as_json_unimpl
Definition: smartctl.cpp:58
static void js_initialize(int argc, char **argv, bool verbose)
Definition: smartctl.cpp:71
void failuretest(failure_type type, int returnvalue)
Definition: smartctl.cpp:1449
static int main_worker(int argc, char **argv)
Definition: smartctl.cpp:1564
static bool print_as_json
Definition: smartctl.cpp:54
static void UsageSummary()
Definition: smartctl.cpp:65
const char * smartctl_cpp_cvsid
Definition: smartctl.cpp:45
static void printslogan()
Definition: smartctl.cpp:60
const char const char * fmt
Definition: smartctl.cpp:1312
static void Usage()
Definition: smartctl.cpp:113
bool printing_is_switchable
Definition: smartctl.cpp:49
const char * msg_severity
Definition: smartctl.cpp:1311
static void scan_devices(const smart_devtype_list &types, bool with_open, char **argv)
Definition: smartctl.cpp:1510
const char const char va_list ap
Definition: smartctl.cpp:1313
void void jinf(const char *fmt,...) __attribute_format_printf(1
#define FAILPOWER
Definition: smartctl.h:27
#define SMARTCTL_H_CVSID
Definition: smartctl.h:16
#define FAILSMART
Definition: smartctl.h:33
void void void jwrn(const char *fmt,...) __attribute_format_printf(1
#define FAILDEV
Definition: smartctl.h:24
#define FAILCMD
Definition: smartctl.h:21
void void void void jerr(const char *fmt,...) __attribute_format_printf(1
void jout(const char *fmt,...) __attribute_format_printf(1
failure_type
Definition: smartctl.h:56
@ OPTIONAL_CMD
Definition: smartctl.h:57
@ MANDATORY_CMD
Definition: smartctl.h:58
vsnprintf(buf, sizeof(buf), fmt, ap)
void pout(const char *fmt,...)
Definition: smartd.cpp:1309
unsigned page
Definition: ataprint.h:25
unsigned char logaddr
Definition: ataprint.h:24
unsigned nsectors
Definition: ataprint.h:26
bool sct_wcache_sct_get
Definition: ataprint.h:100
bool sct_temp_hist
Definition: ataprint.h:53
bool smart_auto_offl_disable
Definition: ataprint.h:60
bool sct_wcache_reorder_get
Definition: ataprint.h:97
bool smart_auto_save_enable
Definition: ataprint.h:61
bool smart_general_values
Definition: ataprint.h:35
unsigned sct_erc_writetime
Definition: ataprint.h:56
bool devstat_all_pages
Definition: ataprint.h:48
bool set_security_freeze
Definition: ataprint.h:94
unsigned pending_defects_log
Definition: ataprint.h:51
bool set_standby_now
Definition: ataprint.h:92
int identify_word_level
Definition: ataprint.h:33
int smart_selftest_type
Definition: ataprint.h:63
bool smart_selftest_log
Definition: ataprint.h:38
int identify_bit_level
Definition: ataprint.h:33
bool smart_disable
Definition: ataprint.h:59
ata_selective_selftest_args smart_selective_args
Definition: ataprint.h:65
unsigned char powerexit
Definition: ataprint.h:81
std::vector< int > devstat_pages
Definition: ataprint.h:49
bool smart_check_status
Definition: ataprint.h:34
unsigned smart_ext_error_log
Definition: ataprint.h:42
bool fix_swapped_id
Definition: ataprint.h:74
unsigned smart_ext_selftest_log
Definition: ataprint.h:43
firmwarebug_defs firmwarebugs
Definition: ataprint.h:73
bool ignore_presets
Definition: ataprint.h:78
unsigned char powermode
Definition: ataprint.h:80
bool get_lookahead
Definition: ataprint.h:89
bool sataphy_reset
Definition: ataprint.h:57
unsigned char output_format
Definition: ataprint.h:71
int sct_wcache_reorder_set
Definition: ataprint.h:98
bool sct_temp_int_pers
Definition: ataprint.h:68
bool smart_selftest_force
Definition: ataprint.h:64
bool smart_selective_selftest_log
Definition: ataprint.h:39
bool devstat_ssd_page
Definition: ataprint.h:48
ata_vendor_attr_defs attribute_defs
Definition: ataprint.h:76
unsigned sct_temp_int
Definition: ataprint.h:67
unsigned sct_erc_readtime
Definition: ataprint.h:56
bool smart_vendor_attrib
Definition: ataprint.h:36
std::vector< ata_log_request > log_requests
Definition: ataprint.h:46
bool sct_wcache_sct_set_pers
Definition: ataprint.h:102
bool retry_error_log
Definition: ataprint.h:44
bool sct_wcache_reorder_set_pers
Definition: ataprint.h:99
bool smart_auto_offl_enable
Definition: ataprint.h:60
bool retry_selftest_log
Definition: ataprint.h:44
bool smart_error_log
Definition: ataprint.h:37
bool smart_auto_save_disable
Definition: ataprint.h:61
int sct_wcache_sct_set
Definition: ataprint.h:101
Options for print().
Definition: json.h:199
unsigned char log_page
Definition: nvmeprint.h:26
unsigned log_page_size
Definition: nvmeprint.h:27
bool smart_vendor_attrib
Definition: nvmeprint.h:24
unsigned error_log_entries
Definition: nvmeprint.h:25
bool drive_capabilities
Definition: nvmeprint.h:22
bool smart_check_status
Definition: nvmeprint.h:23
short int set_rcd
Definition: scsiprint.h:52
bool smart_background_log
Definition: scsiprint.h:29
bool smart_selftest_abort
Definition: scsiprint.h:38
bool smart_auto_save_disable
Definition: scsiprint.h:33
bool smart_selftest_force
Definition: scsiprint.h:39
short int set_wce
Definition: scsiprint.h:52
unsigned char powerexit
Definition: scsiprint.h:55
bool smart_vendor_attrib
Definition: scsiprint.h:26
bool smart_default_selftest
Definition: scsiprint.h:35
bool smart_selftest_log
Definition: scsiprint.h:28
bool smart_check_status
Definition: scsiprint.h:25
bool smart_short_selftest
Definition: scsiprint.h:36
bool smart_extend_selftest
Definition: scsiprint.h:37
bool tape_device_stats
Definition: scsiprint.h:46
bool smart_auto_save_enable
Definition: scsiprint.h:33
bool smart_ss_media_log
Definition: scsiprint.h:30
unsigned char powermode
Definition: scsiprint.h:54
bool scsi_pending_defects
Definition: scsiprint.h:40
bool zoned_device_stats
Definition: scsiprint.h:49
Device info strings.
Definition: dev_interface.h:37
std::string dev_type
Actual device type.
Definition: dev_interface.h:47
void dateandtimezoneepoch(char(&buffer)[DATEANDEPOCHLEN], time_t tval)
Definition: utility.cpp:330
std::string strprintf(const char *fmt,...)
Definition: utility.cpp:780
int split_selective_arg(char *s, uint64_t *start, uint64_t *stop, int *mode)
Definition: utility.cpp:611
void check_config()
Definition: utility.cpp:900
#define BUILD_INFO
Definition: utility.cpp:82
std::string format_version_info(const char *prog_name, bool full)
Definition: utility.cpp:86
#define DATEANDEPOCHLEN
Definition: utility.h:63
int uint128_to_str_precision_bits()
Definition: utility.h:295
bool str_starts_with(const char *str, const char *prefix)
Definition: utility.h:51