smartmontools SVN Rev 5409
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 5408 2022-09-18 14:50:33Z 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 = nvmeopts.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 = nvmeopts.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 = nvmeopts.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 nvmeopts.smart_selftest_type = 0x1; // TODO: enum
805 } else if (!strcmp(optarg,"long")) {
806 testcnt++;
808 scsiopts.smart_extend_selftest = true;
809 nvmeopts.smart_selftest_type = 0x2;
810 } else if (!strcmp(optarg,"conveyance")) {
811 testcnt++;
813 } else if (!strcmp(optarg,"force")) {
814 ataopts.smart_selftest_force = true;
815 scsiopts.smart_selftest_force = true;
816 } else if (!strcmp(optarg,"afterselect,on")) {
817 // scan remainder of disk after doing selected segment
819 } else if (!strcmp(optarg,"afterselect,off")) {
820 // don't scan remainder of disk after doing selected segments
822 } else if (!strncmp(optarg,"pending,",strlen("pending,"))) {
823 // parse number of minutes that test should be pending
824 int i;
825 char *tailptr=NULL;
826 errno=0;
827 i=(int)strtol(optarg+strlen("pending,"), &tailptr, 10);
828 if (errno || *tailptr != '\0') {
829 snprintf(extraerror, sizeof(extraerror), "Option -t pending,N requires N to be a non-negative integer\n");
830 badarg = true;
831 } else if (i<0 || i>65535) {
832 snprintf(extraerror, sizeof(extraerror), "Option -t pending,N (N=%d) must have 0 <= N <= 65535\n", i);
833 badarg = true;
834 } else {
836 }
837 } else if (!strncmp(optarg,"select",strlen("select"))) {
838 if (ataopts.smart_selective_args.num_spans == 0)
839 testcnt++;
840 // parse range of LBAs to test
841 uint64_t start, stop; int mode;
842 if (split_selective_arg(optarg, &start, &stop, &mode)) {
843 snprintf(extraerror, sizeof(extraerror), "Option -t select,M-N must have non-negative integer M and N\n");
844 badarg = true;
845 } else {
846 if (ataopts.smart_selective_args.num_spans >= 5 || start > stop) {
847 if (start > stop) {
848 snprintf(extraerror, sizeof(extraerror), "ERROR: Start LBA (%" PRIu64 ") > ending LBA (%" PRId64 ") in argument \"%s\"\n",
849 start, stop, optarg);
850 } else {
851 snprintf(extraerror, sizeof(extraerror),"ERROR: No more than five selective self-test spans may be"
852 " defined\n");
853 }
854 badarg = true;
855 }
861 }
862 } else if (!strncmp(optarg, "scttempint", sizeof("scstempint")-1)) {
863 snprintf(extraerror, sizeof(extraerror), "-t scttempint is no longer supported, use -l scttempint instead\n");
864 badarg = true;
865 } else if (!strncmp(optarg, "vendor,", sizeof("vendor,")-1)) {
866 unsigned subcmd = ~0U; int n = -1;
867 if (!( sscanf(optarg, "%*[a-z],0x%x%n", &subcmd, &n) == 1
868 && subcmd <= 0xff && n == (int)strlen(optarg))) {
869 snprintf(extraerror, sizeof(extraerror), "Option -t vendor,0xNN syntax error\n");
870 badarg = true;
871 }
872 else
873 ataopts.smart_selftest_type = subcmd;
874 } else {
875 badarg = true;
876 }
877 break;
878 case 'C':
879 captive = true;
880 break;
881 case 'X':
882 testcnt++;
884 scsiopts.smart_selftest_abort = true;
885 nvmeopts.smart_selftest_type = 0xf;
886 break;
887 case 'n':
888 // skip disk check if in low-power mode
889 if (!strcmp(optarg, "never")) {
890 ataopts.powermode = 1; // do not skip, but print mode
891 scsiopts.powermode = 1;
892 }
893 else {
894 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
895 char s[7+1]; unsigned i = FAILPOWER, j = 0;
896 sscanf(optarg, "%7[a-z]%n,%u%n,%u%n", s, &n1, &i, &n2, &j, &n3);
897 if (!((n1 == len || n2 == len || n3 == len) && i <= 255 && j <= 255))
898 badarg = true;
899 else if (!strcmp(s, "sleep")) {
900 ataopts.powermode = 2;
901 scsiopts.powermode = 2;
902 } else if (!strcmp(s, "standby")) {
903 ataopts.powermode = 3;
904 scsiopts.powermode = 3;
905 } else if (!strcmp(s, "idle")) {
906 ataopts.powermode = 4;
907 scsiopts.powermode = 4;
908 } else
909 badarg = true;
910
911 ataopts.powerexit = i;
912 ataopts.powerexit_unsup = (n3 == len ? j : -1);
913 scsiopts.powerexit = i;
914 }
915 break;
916 case 'f':
917 if (!strcmp(optarg, "old")) {
918 ataopts.output_format &= ~ata_print_options::FMT_BRIEF;
919 output_format_set = true;
920 }
921 else if (!strcmp(optarg, "brief")) {
923 output_format_set = true;
924 }
925 else if (!strcmp(optarg, "hex"))
928 else if (!strcmp(optarg, "hex,id"))
930 else if (!strcmp(optarg, "hex,val"))
932 else
933 badarg = true;
934 break;
935 case 'B':
936 {
937 const char * path = optarg;
938 if (*path == '+' && path[1])
939 path++;
940 else
941 use_default_db = false;
942 if (!read_drive_database(path))
943 return FAILCMD;
944 }
945 break;
946 case 'h':
947 printing_is_off = false;
948 printslogan();
949 Usage();
950 return 0;
951
952 case 'g':
953 case_s_continued: // -s, see above
954 case opt_set: // --set
955 {
956 ataopts.get_set_used = true;
957 bool get = (optchar == 'g');
958 char name[16+1]; unsigned val;
959 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
960 if (sscanf(optarg, "%16[^,=]%n%*[,=]%n%u%n", name, &n1, &n2, &val, &n3) >= 1
961 && (n1 == len || (!get && n2 > 0))) {
962 bool on = false;
963 bool off = false;
964 bool ata = false;
965 bool persistent = false;
966
967 if (n2 > 0) {
968 int len2 = strlen(optarg + n2);
969 char * tmp = strstr(optarg+n2, ",p");
970 // handle ",p" in persistent options like: wcache-sct,[ata|on|off],p
971 if (tmp && (strlen(tmp) == 2)) {
972 persistent = true;
973 len2 = strlen(optarg+n2) - 2;
974
975 // the ,p option only works for set of SCT Feature Control command
976 if (strcmp(name, "wcache-sct") != 0 &&
977 strcmp(name, "wcreorder") != 0)
978 badarg = true;
979 }
980 on = !strncmp(optarg+n2, "on", len2);
981 off = !strncmp(optarg+n2, "off", len2);
982 ata = !strncmp(optarg+n2, "ata", len2);
983 }
984 if (n3 != len)
985 val = ~0U;
986
987 if (get && !strcmp(name, "all")) {
988 ataopts.get_aam = ataopts.get_apm = true;
989 ataopts.get_security = true;
990 ataopts.get_lookahead = ataopts.get_wcache = true;
991 ataopts.get_dsn = true;
992 scsiopts.get_rcd = scsiopts.get_wce = true;
993 }
994 else if (!strcmp(name, "aam")) {
995 if (get)
996 ataopts.get_aam = true;
997 else if (off)
998 ataopts.set_aam = -1;
999 else if (val <= 254)
1000 ataopts.set_aam = val + 1;
1001 else {
1002 snprintf(extraerror, sizeof(extraerror), "Option -s aam,N must have 0 <= N <= 254\n");
1003 badarg = true;
1004 }
1005 }
1006 else if (!strcmp(name, "apm")) {
1007 if (get)
1008 ataopts.get_apm = true;
1009 else if (off)
1010 ataopts.set_apm = -1;
1011 else if (1 <= val && val <= 254)
1012 ataopts.set_apm = val + 1;
1013 else {
1014 snprintf(extraerror, sizeof(extraerror), "Option -s apm,N must have 1 <= N <= 254\n");
1015 badarg = true;
1016 }
1017 }
1018 else if (!strcmp(name, "lookahead")) {
1019 if (get) {
1020 ataopts.get_lookahead = true;
1021 }
1022 else if (off)
1023 ataopts.set_lookahead = -1;
1024 else if (on)
1025 ataopts.set_lookahead = 1;
1026 else
1027 badarg = true;
1028 }
1029 else if (!strcmp(name, "wcreorder")) {
1030 ataopts.sct_wcache_reorder_set_pers = persistent;
1031 if (get) {
1032 ataopts.sct_wcache_reorder_get = true;
1033 }
1034 else if (off)
1035 ataopts.sct_wcache_reorder_set = -1;
1036 else if (on)
1037 ataopts.sct_wcache_reorder_set = 1;
1038 else
1039 badarg = true;
1040 }
1041 else if (!strcmp(name, "wcache-sct")) {
1042 ataopts.sct_wcache_sct_set_pers = persistent;
1043 if (get) {
1044 ataopts.sct_wcache_sct_get = true;
1045 }
1046 else if (off)
1047 ataopts.sct_wcache_sct_set = 3;
1048 else if (on)
1049 ataopts.sct_wcache_sct_set = 2;
1050 else if (ata)
1051 ataopts.sct_wcache_sct_set = 1;
1052 else
1053 badarg = true;
1054 }
1055 else if (!strcmp(name, "rcache")) {
1056 if (get)
1057 scsiopts.get_rcd = true;
1058 else if (off)
1059 scsiopts.set_rcd = -1;
1060 else if (on)
1061 scsiopts.set_rcd = 1;
1062 else
1063 badarg = true;
1064 }
1065 else if (get && !strcmp(name, "security")) {
1066 ataopts.get_security = true;
1067 }
1068 else if (!get && !strcmp(optarg, "security-freeze")) {
1069 ataopts.set_security_freeze = true;
1070 }
1071 else if (!get && !strcmp(optarg, "standby,now")) {
1072 ataopts.set_standby_now = true;
1073 scsiopts.set_standby_now = true;
1074 }
1075 else if (!get && !strcmp(name, "standby")) {
1076 if (off) {
1077 ataopts.set_standby = 0 + 1;
1078 scsiopts.set_standby = 0 + 1;
1079 } else if (val <= 255) {
1080 ataopts.set_standby = val + 1;
1081 scsiopts.set_standby = val + 1;
1082 } else {
1083 snprintf(extraerror, sizeof(extraerror), "Option -s standby,N must have 0 <= N <= 255\n");
1084 badarg = true;
1085 }
1086 }
1087 else if (!strcmp(name, "wcache")) {
1088 if (get) {
1089 ataopts.get_wcache = true;
1090 scsiopts.get_wce = true;
1091 }
1092 else if (off) {
1093 ataopts.set_wcache = -1;
1094 scsiopts.set_wce = -1;
1095 }
1096 else if (on) {
1097 ataopts.set_wcache = 1;
1098 scsiopts.set_wce = 1;
1099 }
1100 else
1101 badarg = true;
1102 }
1103 else if (!strcmp(name, "dsn")) {
1104 if (get) {
1105 ataopts.get_dsn = true;
1106 }
1107 else if (off) {
1108 ataopts.set_dsn = -1;
1109 }
1110 else if (on) {
1111 ataopts.set_dsn = 1;
1112 }
1113 else
1114 badarg = true;
1115 }
1116 else
1117 badarg = true;
1118 }
1119 else
1120 badarg = true;
1121 }
1122 break;
1123
1124 case opt_scan:
1125 case opt_scan_open:
1126 scan = optchar;
1127 break;
1128
1129 case 'j':
1130 {
1131 print_as_json = true;
1135 print_as_json_output = false;
1137 bool json_verbose = false;
1138 if (optarg_is_set) {
1139 for (int i = 0; optarg[i]; i++) {
1140 switch (optarg[i]) {
1141 case 'c': print_as_json_options.pretty = false; break;
1142 case 'g': print_as_json_options.format = 'g'; break;
1143 case 'i': print_as_json_impl = true; break;
1144 case 'o': print_as_json_output = true; break;
1145 case 's': print_as_json_options.sorted = true; break;
1146 case 'u': print_as_json_unimpl = true; break;
1147 case 'v': json_verbose = true; break;
1148 case 'y': print_as_json_options.format = 'y'; break;
1149 default: badarg = true;
1150 }
1151 }
1152 }
1153 js_initialize(argc, argv, json_verbose);
1154 }
1155 break;
1156
1157 case '?':
1158 default:
1159 printing_is_off = false;
1160 printslogan();
1161 // Point arg to the argument in which this option was found.
1162 arg = argv[optind-1];
1163 // Check whether the option is a long option that doesn't map to -h.
1164 if (arg[1] == '-' && optchar != 'h') {
1165 // Iff optopt holds a valid option then argument must be missing.
1166 if (optopt && (optopt > '~' || strchr(shortopts, optopt))) {
1167 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %s\n", arg+2);
1169 } else
1170 jerr("=======> UNRECOGNIZED OPTION: %s\n",arg+2);
1171 if (extraerror[0])
1172 pout("=======> %s", extraerror);
1173 UsageSummary();
1174 return FAILCMD;
1175 }
1176 if (0 < optopt && optopt < '~') {
1177 // Iff optopt holds a valid option then argument must be
1178 // missing. Note (BA) this logic seems to fail using Solaris
1179 // getopt!
1180 if (strchr(shortopts, optopt) != NULL) {
1181 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %c\n", optopt);
1183 } else
1184 jerr("=======> UNRECOGNIZED OPTION: %c\n",optopt);
1185 if (extraerror[0])
1186 pout("=======> %s", extraerror);
1187 UsageSummary();
1188 return FAILCMD;
1189 }
1190 Usage();
1191 return 0;
1192 } // closes switch statement to process command-line options
1193
1194 // Check to see if option had an unrecognized or incorrect argument.
1195 if (badarg) {
1196 printslogan();
1197 // It would be nice to print the actual option name given by the user
1198 // here, but we just print the short form. Please fix this if you know
1199 // a clean way to do it.
1200 char optstr[] = { (char)optchar, 0 };
1201 jerr("=======> INVALID ARGUMENT TO -%s: %s\n",
1202 (optchar == opt_identify ? "-identify" :
1203 optchar == opt_set ? "-set" :
1204 optchar == opt_smart ? "-smart" :
1205 optchar == 'j' ? "-json" : optstr), optarg);
1206 printvalidarglistmessage(optchar);
1207 if (extraerror[0])
1208 pout("=======> %s", extraerror);
1209 UsageSummary();
1210 return FAILCMD;
1211 }
1212 }
1213
1214 // Special handling of --scan, --scanopen
1215 if (scan) {
1216 // Read or init drive database to allow USB ID check.
1217 if (!init_drive_database(use_default_db))
1218 return FAILCMD;
1219 scan_devices(scan_types, (scan == opt_scan_open), argv + optind);
1220 return 0;
1221 }
1222
1223 // At this point we have processed all command-line options. If the
1224 // print output is switchable, then start with the print output
1225 // turned off
1227 printing_is_off = true;
1228
1229 // Check for multiple -d TYPE options
1230 if (scan_types.size() > 1) {
1231 printing_is_off = false;
1232 printslogan();
1233 jerr("ERROR: multiple -d TYPE options are only allowed with --scan\n");
1234 UsageSummary();
1235 return FAILCMD;
1236 }
1237
1238 // error message if user has asked for more than one test
1239 if (testcnt > 1) {
1240 printing_is_off = false;
1241 printslogan();
1242 jerr("\nERROR: smartctl can only run a single test type (or abort) at a time.\n");
1243 UsageSummary();
1244 return FAILCMD;
1245 }
1246
1247 // error message if user has set selective self-test options without
1248 // asking for a selective self-test
1249 if ( (ataopts.smart_selective_args.pending_time || ataopts.smart_selective_args.scan_after_select)
1250 && !ataopts.smart_selective_args.num_spans) {
1251 printing_is_off = false;
1252 printslogan();
1253 if (ataopts.smart_selective_args.pending_time)
1254 jerr("\nERROR: smartctl -t pending,N must be used with -t select,N-M.\n");
1255 else
1256 jerr("\nERROR: smartctl -t afterselect,(on|off) must be used with -t select,N-M.\n");
1257 UsageSummary();
1258 return FAILCMD;
1259 }
1260
1261 // If captive option was used, change test type if appropriate.
1262 if (captive)
1263 switch (ataopts.smart_selftest_type) {
1264 case SHORT_SELF_TEST:
1265 ataopts.smart_selftest_type = SHORT_CAPTIVE_SELF_TEST;
1266 scsiopts.smart_short_selftest = false;
1267 scsiopts.smart_short_cap_selftest = true;
1268 break;
1269 case EXTEND_SELF_TEST:
1270 ataopts.smart_selftest_type = EXTEND_CAPTIVE_SELF_TEST;
1271 scsiopts.smart_extend_selftest = false;
1272 scsiopts.smart_extend_cap_selftest = true;
1273 break;
1275 ataopts.smart_selftest_type = CONVEYANCE_CAPTIVE_SELF_TEST;
1276 break;
1278 ataopts.smart_selftest_type = SELECTIVE_CAPTIVE_SELF_TEST;
1279 break;
1280 }
1281
1282 // From here on, normal operations...
1283 printslogan();
1284
1285 // Warn if the user has provided no device name
1286 if (argc-optind<1){
1287 jerr("ERROR: smartctl requires a device name as the final command-line argument.\n\n");
1288 UsageSummary();
1289 return FAILCMD;
1290 }
1291
1292 // Warn if the user has provided more than one device name
1293 if (argc-optind>1){
1294 int i;
1295 jerr("ERROR: smartctl takes ONE device name as the final command-line argument.\n");
1296 pout("You have provided %d device names:\n",argc-optind);
1297 for (i=0; i<argc-optind; i++)
1298 pout("%s\n",argv[optind+i]);
1299 UsageSummary();
1300 return FAILCMD;
1301 }
1302
1303 // Read or init drive database
1304 if (!init_drive_database(use_default_db))
1305 return FAILCMD;
1306
1307 // No error, continue in main_worker()
1308 return -1;
1309}
1310
1311// Printing functions
1312
1314static void vjpout(bool is_js_impl, const char * msg_severity,
1315 const char *fmt, va_list ap)
1316{
1317 if (!print_as_json) {
1318 // Print out directly
1319 vprintf(fmt, ap);
1320 fflush(stdout);
1321 }
1322 else {
1323 // Add lines to JSON output
1324 static char buf[1024];
1325 static char * bufnext = buf;
1326 vsnprintf(bufnext, sizeof(buf) - (bufnext - buf), fmt, ap);
1327 for (char * p = buf, *q; ; p = q) {
1328 if (!(q = strchr(p, '\n'))) {
1329 // Keep remaining line for next call
1330 for (bufnext = buf; *p; bufnext++, p++)
1331 *bufnext = *p;
1332 break;
1333 }
1334 *q++ = 0; // '\n' -> '\0'
1335
1336 static int lineno = 0;
1337 lineno++;
1339 // Collect full output in array
1340 static int outindex = 0;
1341 jglb["smartctl"]["output"][outindex++] = p;
1342 }
1343 if (!*p)
1344 continue; // Skip empty line
1345
1346 if (msg_severity) {
1347 // Collect non-empty messages in array
1348 static int errindex = 0;
1349 json::ref jref = jglb["smartctl"]["messages"][errindex++];
1350 jref["string"] = p;
1351 jref["severity"] = msg_severity;
1352 }
1353
1354 if ( ( is_js_impl && print_as_json_impl )
1355 || (!is_js_impl && print_as_json_unimpl)) {
1356 // Add (un)implemented non-empty lines to global object
1357 jglb[strprintf("smartctl_%04d_%c", lineno,
1358 (is_js_impl ? 'i' : 'u')).c_str()] = p;
1359 }
1360 }
1361 }
1362}
1363
1364// Default: print to stdout
1365// --json: ignore
1366// --json=o: append to "output" array
1367// --json=u: add "smartctl_NNNN_u" element(s)
1368void pout(const char *fmt, ...)
1369{
1370 if (printing_is_off)
1371 return;
1374 return;
1375
1376 va_list ap;
1377 va_start(ap, fmt);
1378 vjpout(false, 0, fmt, ap);
1379 va_end(ap);
1380}
1381
1382// Default: Print to stdout
1383// --json: ignore
1384// --json=o: append to "output" array
1385// --json=i: add "smartctl_NNNN_i" element(s)
1386void jout(const char *fmt, ...)
1387{
1388 if (printing_is_off)
1389 return;
1392 return;
1393
1394 va_list ap;
1395 va_start(ap, fmt);
1396 vjpout(true, 0, fmt, ap);
1397 va_end(ap);
1398}
1399
1400// Default: print to stdout
1401// --json: append to "messages"
1402// --json=o: append to "output" array
1403// --json=i: add "smartctl_NNNN_i" element(s)
1404void jinf(const char *fmt, ...)
1405{
1406 if (printing_is_off)
1407 return;
1408
1409 va_list ap;
1410 va_start(ap, fmt);
1411 vjpout(true, "information", fmt, ap);
1412 va_end(ap);
1413}
1414
1415void jwrn(const char *fmt, ...)
1416{
1417 if (printing_is_off)
1418 return;
1419
1420 va_list ap;
1421 va_start(ap, fmt);
1422 vjpout(true, "warning", fmt, ap);
1423 va_end(ap);
1424}
1425
1426void jerr(const char *fmt, ...)
1427{
1428 if (printing_is_off)
1429 return;
1430
1431 va_list ap;
1432 va_start(ap, fmt);
1433 vjpout(true, "error", fmt, ap);
1434 va_end(ap);
1435}
1436
1437static char startup_datetime_buf[DATEANDEPOCHLEN];
1438
1439// Print smartctl start-up date and time and timezone
1440void jout_startup_datetime(const char *prefix)
1441{
1442 jout("%s%s\n", prefix, startup_datetime_buf);
1443}
1444
1445// Globals to set failuretest() policy
1447unsigned char failuretest_permissive = 0;
1448
1449// Compares failure type to policy in effect, and either exits or
1450// simply returns to the calling routine.
1451// Used in ataprint.cpp and scsiprint.cpp.
1452void failuretest(failure_type type, int returnvalue)
1453{
1454 // If this is an error in an "optional" SMART command
1455 if (type == OPTIONAL_CMD) {
1457 return;
1458 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1459 throw int(returnvalue);
1460 }
1461
1462 // If this is an error in a "mandatory" SMART command
1463 if (type == MANDATORY_CMD) {
1465 return;
1466 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1467 throw int(returnvalue);
1468 }
1469
1470 throw std::logic_error("failuretest: Unknown type");
1471}
1472
1473// Used to warn users about invalid checksums. Called from atacmds.cpp.
1474// Action to be taken may be altered by the user.
1475void checksumwarning(const char * string)
1476{
1477 // user has asked us to ignore checksum errors
1479 return;
1480
1481 pout("Warning! %s error: invalid SMART checksum.\n", string);
1482
1483 // user has asked us to fail on checksum errors
1485 throw int(FAILSMART);
1486}
1487
1488// Return info string about device protocol
1489static const char * get_protocol_info(const smart_device * dev)
1490{
1491 switch ( (int)dev->is_ata()
1492 | ((int)dev->is_scsi() << 1)
1493 | ((int)dev->is_nvme() << 2)) {
1494 case 0x1: return "ATA";
1495 case 0x2: return "SCSI";
1496 case 0x3: return "ATA+SCSI";
1497 case 0x4: return "NVMe";
1498 default: return "Unknown";
1499 }
1500}
1501
1502// Add JSON device info
1503static void js_device_info(const json::ref & jref, const smart_device * dev)
1504{
1505 jref["name"] = dev->get_dev_name();
1506 jref["info_name"] = dev->get_info_name();
1507 jref["type"] = dev->get_dev_type();
1508 jref["protocol"] = get_protocol_info(dev);
1509}
1510
1511// Device scan
1512// smartctl [-d type] --scan[-open] -- [PATTERN] [smartd directive ...]
1513void scan_devices(const smart_devtype_list & types, bool with_open, char ** argv)
1514{
1515 bool dont_print = !(ata_debugmode || scsi_debugmode || nvme_debugmode);
1516
1517 const char * pattern = 0;
1518 int ai = 0;
1519 if (argv[ai] && argv[ai][0] != '-')
1520 pattern = argv[ai++];
1521
1522 smart_device_list devlist;
1523 printing_is_off = dont_print;
1524 bool ok = smi()->scan_smart_devices(devlist, types, pattern);
1525 printing_is_off = false;
1526
1527 if (!ok) {
1528 pout("# scan_smart_devices: %s\n", smi()->get_errmsg());
1529 return;
1530 }
1531
1532 for (unsigned i = 0; i < devlist.size(); i++) {
1533 smart_device_auto_ptr dev( devlist.release(i) );
1534 json::ref jref = jglb["devices"][i];
1535
1536 if (with_open) {
1537 printing_is_off = dont_print;
1538 dev.replace ( dev->autodetect_open() );
1539 printing_is_off = false;
1540 }
1541
1542 js_device_info(jref, dev.get());
1543
1544 if (with_open && !dev->is_open()) {
1545 jout("# %s -d %s # %s, %s device open failed: %s\n", dev->get_dev_name(),
1546 dev->get_dev_type(), dev->get_info_name(),
1547 get_protocol_info(dev.get()), dev->get_errmsg());
1548 jref["open_error"] = dev->get_errmsg();
1549 continue;
1550 }
1551
1552 jout("%s -d %s", dev->get_dev_name(), dev->get_dev_type());
1553 if (!argv[ai])
1554 jout(" # %s, %s device\n", dev->get_info_name(), get_protocol_info(dev.get()));
1555 else {
1556 for (int j = ai; argv[j]; j++)
1557 jout(" %s", argv[j]);
1558 jout("\n");
1559 }
1560
1561 if (dev->is_open())
1562 dev->close();
1563 }
1564}
1565
1566// Main program without exception handling
1567static int main_worker(int argc, char **argv)
1568{
1569 // Throw if runtime environment does not match compile time test.
1570 check_config();
1571
1572 // Initialize interface
1574 if (!smi())
1575 return 1;
1576
1577 // Parse input arguments
1578 const char * type = 0;
1579 ata_print_options ataopts;
1580 scsi_print_options scsiopts;
1581 nvme_print_options nvmeopts;
1582 bool print_type_only = false;
1583 {
1584 int status = parse_options(argc, argv, type, ataopts, scsiopts, nvmeopts, print_type_only);
1585 if (status >= 0)
1586 return status;
1587 }
1588
1589 // Store formatted current time for jout_startup_datetime()
1590 // Output as JSON regardless of '-i' option
1591 {
1592 time_t now = time(nullptr);
1593 dateandtimezoneepoch(startup_datetime_buf, now);
1594 jglb["local_time"] += { {"time_t", now}, {"asctime", startup_datetime_buf} };
1595 }
1596
1597 const char * name = argv[argc-1];
1598
1600 if (!strcmp(name,"-")) {
1601 // Parse "smartctl -r ataioctl,2 ..." output from stdin
1602 if (type || print_type_only) {
1603 pout("-d option is not allowed in conjunction with device name \"-\".\n");
1604 UsageSummary();
1605 return FAILCMD;
1606 }
1607 dev = get_parsed_ata_device(smi(), name);
1608 }
1609 else
1610 // get device of appropriate type
1611 dev = smi()->get_smart_device(name, type);
1612
1613 if (!dev) {
1614 jerr("%s: %s\n", name, smi()->get_errmsg());
1615 if (type)
1617 else
1618 pout("Please specify device type with the -d option.\n");
1619 UsageSummary();
1620 return FAILCMD;
1621 }
1622
1623 if (print_type_only)
1624 // Report result of first autodetection
1625 pout("%s: Device of type '%s' [%s] detected\n",
1626 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1627
1628 if (dev->is_ata() && ataopts.powermode>=2 && dev->is_powered_down()) {
1629 jinf("Device is in STANDBY (OS) mode, exit(%d)\n", ataopts.powerexit);
1630 return ataopts.powerexit;
1631 }
1632
1633 // Open device
1634 {
1635 // Save old info
1636 smart_device::device_info oldinfo = dev->get_info();
1637
1638 // Open with autodetect support, may return 'better' device
1639 dev.replace( dev->autodetect_open() );
1640
1641 // Report if type has changed
1642 if ( (ata_debugmode || scsi_debugmode || nvme_debugmode || print_type_only)
1643 && oldinfo.dev_type != dev->get_dev_type() )
1644 pout("%s: Device open changed type from '%s' to '%s'\n",
1645 dev->get_info_name(), oldinfo.dev_type.c_str(), dev->get_dev_type());
1646 }
1647 if (!dev->is_open()) {
1648 jerr("Smartctl open device: %s failed: %s\n", dev->get_info_name(), dev->get_errmsg());
1649 return FAILDEV;
1650 }
1651
1652 // Add JSON info similar to --scan output
1653 js_device_info(jglb["device"], dev.get());
1654
1655 // now call appropriate ATA or SCSI routine
1656 int retval = 0;
1657 if (print_type_only)
1658 jout("%s: Device of type '%s' [%s] opened\n",
1659 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1660 else if (dev->is_ata())
1661 retval = ataPrintMain(dev->to_ata(), ataopts);
1662 else if (dev->is_scsi())
1663 retval = scsiPrintMain(dev->to_scsi(), scsiopts);
1664 else if (dev->is_nvme())
1665 retval = nvmePrintMain(dev->to_nvme(), nvmeopts);
1666 else
1667 // we should never fall into this branch!
1668 pout("%s: Neither ATA, SCSI nor NVMe device\n", dev->get_info_name());
1669
1670 dev->close();
1671 return retval;
1672}
1673
1674
1675// Main program
1676int main(int argc, char **argv)
1677{
1678 int status;
1679 bool badcode = false;
1680
1681 try {
1682 try {
1683 // Do the real work ...
1684 status = main_worker(argc, argv);
1685 }
1686 catch (int ex) {
1687 // Exit status from checksumwarning() and failuretest() arrives here
1688 status = ex;
1689 }
1690 // Print JSON if enabled
1692 jglb["smartctl"]["uint128_precision_bits"] = uint128_to_str_precision_bits();
1693 jglb["smartctl"]["exit_status"] = status;
1695 }
1696 catch (const std::bad_alloc & /*ex*/) {
1697 // Memory allocation failed (also thrown by std::operator new)
1698 printf("Smartctl: Out of memory\n");
1699 status = FAILCMD;
1700 }
1701 catch (const std::exception & ex) {
1702 // Other fatal errors
1703 printf("Smartctl: Exception: %s\n", ex.what());
1704 badcode = true;
1705 status = FAILCMD;
1706 }
1707
1708 // Check for remaining device objects
1709 if (smart_device::get_num_objects() != 0) {
1710 printf("Smartctl: Internal Error: %d device object(s) left at exit.\n",
1712 badcode = true;
1713 status = FAILCMD;
1714 }
1715
1716 if (badcode)
1717 printf("Please inform " PACKAGE_BUGREPORT ", including output of smartctl -V.\n");
1718
1719 return status;
1720}
1721
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:3338
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:568
unsigned char scsi_debugmode
Definition: scsicmds.cpp:45
int scsiPrintMain(scsi_device *device, const scsi_print_options &options)
Definition: scsiprint.cpp:3128
bool failuretest_conservative
Definition: smartctl.cpp:1446
static std::string getvalidarglist(int opt)
Definition: smartctl.cpp:228
void jout_startup_datetime(const char *prefix)
Definition: smartctl.cpp:1440
unsigned char failuretest_permissive
Definition: smartctl.cpp:1447
bool printing_is_off
Definition: smartctl.cpp:50
@ 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
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
int main(int argc, char **argv)
Definition: smartctl.cpp:1676
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:1503
__attribute_format_printf(3, 0) static void vjpout(bool is_js_impl
void checksumwarning(const char *string)
Definition: smartctl.cpp:1475
static const char * get_protocol_info(const smart_device *dev)
Definition: smartctl.cpp:1489
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:1452
static int main_worker(int argc, char **argv)
Definition: smartctl.cpp:1567
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:1315
static void Usage()
Definition: smartctl.cpp:113
bool printing_is_switchable
Definition: smartctl.cpp:49
const char * msg_severity
Definition: smartctl.cpp:1314
static void scan_devices(const smart_devtype_list &types, bool with_open, char **argv)
Definition: smartctl.cpp:1513
const char const char va_list ap
Definition: smartctl.cpp:1316
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:1326
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
bool smart_selftest_log
Definition: nvmeprint.h:25
unsigned char smart_selftest_type
Definition: nvmeprint.h:26
unsigned char log_page
Definition: nvmeprint.h:28
unsigned log_page_size
Definition: nvmeprint.h:29
bool smart_vendor_attrib
Definition: nvmeprint.h:24
unsigned error_log_entries
Definition: nvmeprint.h:27
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