smartmontools SVN Rev 5612
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-23 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 5519 2023-07-24 15:57:54Z 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, farm\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, farm";
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", 3 /*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, "genstats")) {
538 scsiopts.general_stats_and_perf = true;
539 } else if (!strcmp(optarg,"sasphy")) {
540 scsiopts.sasphy = true;
541 } else if (!strcmp(optarg,"sasphy,reset")) {
542 scsiopts.sasphy = scsiopts.sasphy_reset = true;
543 } else if (!strcmp(optarg,"sataphy")) {
544 ataopts.sataphy = true;
545 } else if (!strcmp(optarg,"sataphy,reset")) {
546 ataopts.sataphy = ataopts.sataphy_reset = true;
547 } else if (!strcmp(optarg,"background")) {
548 scsiopts.smart_background_log = true;
549 } else if (!strcmp(optarg,"ssd")) {
550 ataopts.devstat_ssd_page = true;
551 scsiopts.smart_ss_media_log = true;
552 } else if (!strcmp(optarg,"scterc")) {
553 ataopts.sct_erc_get = 1;
554 } else if (!strcmp(optarg,"scttemp")) {
555 ataopts.sct_temp_sts = ataopts.sct_temp_hist = true;
556 } else if (!strcmp(optarg,"envrep")) {
557 scsiopts.smart_env_rep = true;
558 } else if (!strcmp(optarg,"scttempsts")) {
559 ataopts.sct_temp_sts = true;
560 } else if (!strcmp(optarg,"scttemphist")) {
561 ataopts.sct_temp_hist = true;
562 } else if (!strcmp(optarg,"farm")) {
563 ataopts.farm_log = scsiopts.farm_log = true; // Seagate Field Access Reliability Metrics (FARM) log
564 } else if (!strcmp(optarg,"tapealert")) {
565 scsiopts.tape_alert = true;
566 } else if (!strcmp(optarg,"tapedevstat")) {
567 scsiopts.tape_device_stats = true;
568 } else if (!strcmp(optarg,"zdevstat")) {
569 scsiopts.zoned_device_stats = true;
570 } else if (!strncmp(optarg, "scttempint,", sizeof("scstempint,")-1)) {
571 unsigned interval = 0; int n1 = -1, n2 = -1, len = strlen(optarg);
572 if (!( sscanf(optarg,"scttempint,%u%n,p%n", &interval, &n1, &n2) == 1
573 && 0 < interval && interval <= 0xffff && (n1 == len || n2 == len))) {
574 snprintf(extraerror, sizeof(extraerror), "Option -l scttempint,N[,p] must have positive integer N\n");
575 badarg = true;
576 }
577 ataopts.sct_temp_int = interval;
578 ataopts.sct_temp_int_pers = (n2 == len);
579
580 } else if (!strncmp(optarg, "devstat", sizeof("devstat")-1)) {
581 int n1 = -1, n2 = -1, len = strlen(optarg);
582 unsigned val = ~0;
583 sscanf(optarg, "devstat%n,%u%n", &n1, &val, &n2);
584 if (n1 == len)
585 ataopts.devstat_all_pages = true;
586 else {
587 if (n2 != len) // retry with hex
588 sscanf(optarg, "devstat,0x%x%n", &val, &n2);
589 if (n2 == len && val <= 0xff)
590 ataopts.devstat_pages.push_back(val);
591 else
592 badarg = true;
593 }
594
595 } else if (str_starts_with(optarg, "defects")) {
596 int n1 = -1, n2 = -1, len = strlen(optarg);
597 unsigned val = ~0;
598 sscanf(optarg, "defects%n,%u%n", &n1, &val, &n2);
599 scsiopts.scsi_pending_defects = true;
600 if (n1 == len)
601 ataopts.pending_defects_log = 31; // Entries of first page
602 else if (n2 == len && val <= 0xffff * 32 - 1)
603 ataopts.pending_defects_log = val;
604 else
605 badarg = true;
606
607 } else if (!strncmp(optarg, "xerror", sizeof("xerror")-1)) {
608 int n1 = -1, n2 = -1, len = strlen(optarg);
609 unsigned val = 8;
610 sscanf(optarg, "xerror%n,error%n", &n1, &n2);
611 if (!(n1 == len || n2 == len)) {
612 n1 = n2 = -1;
613 sscanf(optarg, "xerror,%u%n,error%n", &val, &n1, &n2);
614 }
615 if ((n1 == len || n2 == len) && val > 0) {
616 ataopts.smart_ext_error_log = val;
617 ataopts.retry_error_log = (n2 == len);
618 }
619 else
620 badarg = true;
621
622 } else if (!strncmp(optarg, "xselftest", sizeof("xselftest")-1)) {
623 int n1 = -1, n2 = -1, len = strlen(optarg);
624 unsigned val = 25;
625 sscanf(optarg, "xselftest%n,selftest%n", &n1, &n2);
626 if (!(n1 == len || n2 == len)) {
627 n1 = n2 = -1;
628 sscanf(optarg, "xselftest,%u%n,selftest%n", &val, &n1, &n2);
629 }
630 if ((n1 == len || n2 == len) && val > 0) {
631 ataopts.smart_ext_selftest_log = val;
632 ataopts.retry_selftest_log = (n2 == len);
633 }
634 else
635 badarg = true;
636
637 } else if (!strncmp(optarg, "scterc,", sizeof("scterc,")-1)) {
638 int n1 = -1, n2 = -1, len = strlen(optarg);
639 unsigned rt = ~0, wt = ~0;
640 sscanf(optarg, "scterc,%u,%u%n,p%n", &rt, &wt, &n1, &n2);
641 if ((n1 == len || n2 == len) && rt <= 999 && wt <= 999) {
642 ataopts.sct_erc_set = (n2 == len ? 2 : 1);
643 ataopts.sct_erc_readtime = rt;
644 ataopts.sct_erc_writetime = wt;
645 } else if (!strcmp(optarg, "scterc,p")) {
646 ataopts.sct_erc_get = 2;
647 } else if (!strcmp(optarg, "scterc,reset")) {
648 ataopts.sct_erc_set = 3;
649 ataopts.sct_erc_readtime = ataopts.sct_erc_writetime = 0;
650 } else {
651 snprintf(extraerror, sizeof(extraerror), "Option -l scterc[,READTIME,WRITETIME][,p|reset] syntax error\n");
652 badarg = true;
653 }
654 } else if ( !strncmp(optarg, "gplog," , sizeof("gplog," )-1)
655 || !strncmp(optarg, "smartlog,", sizeof("smartlog,")-1)) {
656 unsigned logaddr = ~0U; unsigned page = 0, nsectors = 1; char sign = 0;
657 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
658 sscanf(optarg, "%*[a-z],0x%x%n,%u%n%c%u%n",
659 &logaddr, &n1, &page, &n2, &sign, &nsectors, &n3);
660 if (len > n2 && n3 == -1 && !strcmp(optarg+n2, "-max")) {
661 nsectors = ~0U; sign = '+'; n3 = len;
662 }
663 bool gpl = (optarg[0] == 'g');
664 const char * erropt = (gpl ? "gplog" : "smartlog");
665 if (!( n1 == len || n2 == len
666 || (n3 == len && (sign == '+' || sign == '-')))) {
667 snprintf(extraerror, sizeof(extraerror), "Option -l %s,ADDR[,FIRST[-LAST|+SIZE]] syntax error\n", erropt);
668 badarg = true;
669 }
670 else if (!( logaddr <= 0xff && page <= (gpl ? 0xffffU : 0x00ffU)
671 && 0 < nsectors
672 && (nsectors <= (gpl ? 0xffffU : 0xffU) || nsectors == ~0U)
673 && (sign != '-' || page <= nsectors) )) {
674 snprintf(extraerror, sizeof(extraerror), "Option -l %s,ADDR[,FIRST[-LAST|+SIZE]] parameter out of range\n", erropt);
675 badarg = true;
676 }
677 else {
678 ata_log_request req;
679 req.gpl = gpl; req.logaddr = logaddr; req.page = page;
680 req.nsectors = (sign == '-' ? nsectors-page+1 : nsectors);
681 ataopts.log_requests.push_back(req);
682 }
683 }
684
685 else if (str_starts_with(optarg, "nvmelog,")) {
686 int n = -1, len = strlen(optarg);
687 unsigned page = 0, size = 0;
688 sscanf(optarg, "nvmelog,0x%x,0x%x%n", &page, &size, &n);
689 if (n == len && page <= 0xff && 0 < size && size <= 0x4000) {
690 nvmeopts.log_page = page; nvmeopts.log_page_size = size;
691 }
692 else
693 badarg = true;
694 }
695
696 else {
697 badarg = true;
698 }
699 break;
700 case 'i':
701 ataopts.drive_info = scsiopts.drive_info = nvmeopts.drive_info = true;
702 break;
703
704 case opt_identify:
705 ataopts.identify_word_level = ataopts.identify_bit_level = 0;
706 if (optarg_is_set) {
707 for (int i = 0; optarg[i]; i++) {
708 switch (optarg[i]) {
709 case 'w': ataopts.identify_word_level = 1; break;
710 case 'n': ataopts.identify_bit_level = -1; break;
711 case 'v': ataopts.identify_bit_level = 1; break;
712 case 'b': ataopts.identify_bit_level = 2; break;
713 default: badarg = true;
714 }
715 }
716 }
717 break;
718
719 case 'a':
720 ataopts.a_option = true;
721 ataopts.drive_info = scsiopts.drive_info = nvmeopts.drive_info = true;
722 ataopts.smart_check_status = scsiopts.smart_check_status = nvmeopts.smart_check_status = true;
723 ataopts.smart_general_values = nvmeopts.drive_capabilities = true;
724 ataopts.smart_vendor_attrib = scsiopts.smart_vendor_attrib = nvmeopts.smart_vendor_attrib = true;
725 ataopts.smart_error_log = scsiopts.smart_error_log = true;
726 nvmeopts.error_log_entries = 16;
727 ataopts.smart_selftest_log = scsiopts.smart_selftest_log = nvmeopts.smart_selftest_log = true;
728 ataopts.smart_selective_selftest_log = true;
729 /* scsiopts.smart_background_log = true; */
730 scsiopts.smart_ss_media_log = true;
731 // ataopts.farm_log_suggest = true; // has no effect because Log Directory is not read
732 scsiopts.farm_log_suggest = true;
733 break;
734 case 'x':
735 ataopts.drive_info = scsiopts.drive_info = nvmeopts.drive_info = true;
736 ataopts.smart_check_status = scsiopts.smart_check_status = nvmeopts.smart_check_status = true;
737 ataopts.smart_general_values = nvmeopts.drive_capabilities = true;
738 ataopts.smart_vendor_attrib = scsiopts.smart_vendor_attrib = nvmeopts.smart_vendor_attrib = true;
739 ataopts.smart_ext_error_log = 8;
740 ataopts.retry_error_log = true;
741 nvmeopts.error_log_entries = 16;
742 ataopts.smart_ext_selftest_log = 25;
743 ataopts.retry_selftest_log = true;
744 scsiopts.smart_error_log = scsiopts.smart_selftest_log = nvmeopts.smart_selftest_log = true;
745 ataopts.smart_selective_selftest_log = true;
746 ataopts.smart_logdir = ataopts.gp_logdir = true;
747 ataopts.sct_temp_sts = ataopts.sct_temp_hist = true;
748 ataopts.sct_erc_get = 1;
749 ataopts.sct_wcache_reorder_get = true;
750 ataopts.devstat_all_pages = true;
751 ataopts.pending_defects_log = 31;
752 ataopts.sataphy = true;
753 ataopts.get_set_used = true;
754 ataopts.get_aam = ataopts.get_apm = true;
755 ataopts.get_security = true;
756 ataopts.get_lookahead = ataopts.get_wcache = true;
757 ataopts.get_dsn = true;
758 scsiopts.get_rcd = scsiopts.get_wce = true;
759 scsiopts.smart_background_log = true;
760 scsiopts.smart_ss_media_log = true;
761 scsiopts.sasphy = true;
762 scsiopts.smart_env_rep = true;
763 scsiopts.scsi_pending_defects = true;
764 scsiopts.tape_device_stats = true;
765 scsiopts.zoned_device_stats = true;
766 scsiopts.general_stats_and_perf = true;
767 ataopts.farm_log_suggest = scsiopts.farm_log_suggest = true;
768 if (!output_format_set)
770 break;
771 case 'v':
772 // parse vendor-specific definitions of attributes
773 if (!strcmp(optarg,"help")) {
774 printing_is_off = false;
775 printslogan();
776 pout("The valid arguments to -v are:\n\thelp\n%s\n",
778 return 0;
779 }
780 if (!parse_attribute_def(optarg, ataopts.attribute_defs, PRIOR_USER))
781 badarg = true;
782 break;
783 case 'P':
784 if (!strcmp(optarg, "use")) {
785 ataopts.ignore_presets = false;
786 } else if (!strcmp(optarg, "ignore")) {
787 ataopts.ignore_presets = true;
788 } else if (!strcmp(optarg, "show")) {
789 ataopts.show_presets = true;
790 } else if (!strcmp(optarg, "showall")) {
791 if (!init_drive_database(use_default_db))
792 return FAILCMD;
793 if (optind < argc) { // -P showall MODEL [FIRMWARE]
794 int cnt = showmatchingpresets(argv[optind], (optind+1<argc ? argv[optind+1] : NULL));
795 return (cnt >= 0 ? cnt : 0);
796 }
797 if (showallpresets())
798 return FAILCMD; // report regexp syntax error
799 return 0;
800 } else {
801 badarg = true;
802 }
803 break;
804 case 't':
805 if (!strcmp(optarg,"offline")) {
806 testcnt++;
808 scsiopts.smart_default_selftest = true;
809 } else if (!strcmp(optarg,"short")) {
810 testcnt++;
812 scsiopts.smart_short_selftest = true;
813 nvmeopts.smart_selftest_type = 0x1; // TODO: enum
814 } else if (!strcmp(optarg,"long")) {
815 testcnt++;
817 scsiopts.smart_extend_selftest = true;
818 nvmeopts.smart_selftest_type = 0x2;
819 } else if (!strcmp(optarg,"conveyance")) {
820 testcnt++;
822 } else if (!strcmp(optarg,"force")) {
823 ataopts.smart_selftest_force = true;
824 scsiopts.smart_selftest_force = true;
825 } else if (!strcmp(optarg,"afterselect,on")) {
826 // scan remainder of disk after doing selected segment
828 } else if (!strcmp(optarg,"afterselect,off")) {
829 // don't scan remainder of disk after doing selected segments
831 } else if (!strncmp(optarg,"pending,",strlen("pending,"))) {
832 // parse number of minutes that test should be pending
833 int i;
834 char *tailptr=NULL;
835 errno=0;
836 i=(int)strtol(optarg+strlen("pending,"), &tailptr, 10);
837 if (errno || *tailptr != '\0') {
838 snprintf(extraerror, sizeof(extraerror), "Option -t pending,N requires N to be a non-negative integer\n");
839 badarg = true;
840 } else if (i<0 || i>65535) {
841 snprintf(extraerror, sizeof(extraerror), "Option -t pending,N (N=%d) must have 0 <= N <= 65535\n", i);
842 badarg = true;
843 } else {
845 }
846 } else if (!strncmp(optarg,"select",strlen("select"))) {
847 if (ataopts.smart_selective_args.num_spans == 0)
848 testcnt++;
849 // parse range of LBAs to test
850 uint64_t start, stop; int mode;
851 if (split_selective_arg(optarg, &start, &stop, &mode)) {
852 snprintf(extraerror, sizeof(extraerror), "Option -t select,M-N must have non-negative integer M and N\n");
853 badarg = true;
854 } else {
855 if (ataopts.smart_selective_args.num_spans >= 5 || start > stop) {
856 if (start > stop) {
857 snprintf(extraerror, sizeof(extraerror), "ERROR: Start LBA (%" PRIu64 ") > ending LBA (%" PRId64 ") in argument \"%s\"\n",
858 start, stop, optarg);
859 } else {
860 snprintf(extraerror, sizeof(extraerror),"ERROR: No more than five selective self-test spans may be"
861 " defined\n");
862 }
863 badarg = true;
864 }
870 }
871 } else if (!strncmp(optarg, "scttempint", sizeof("scstempint")-1)) {
872 snprintf(extraerror, sizeof(extraerror), "-t scttempint is no longer supported, use -l scttempint instead\n");
873 badarg = true;
874 } else if (!strncmp(optarg, "vendor,", sizeof("vendor,")-1)) {
875 unsigned subcmd = ~0U; int n = -1;
876 if (!( sscanf(optarg, "%*[a-z],0x%x%n", &subcmd, &n) == 1
877 && subcmd <= 0xff && n == (int)strlen(optarg))) {
878 snprintf(extraerror, sizeof(extraerror), "Option -t vendor,0xNN syntax error\n");
879 badarg = true;
880 }
881 else
882 ataopts.smart_selftest_type = subcmd;
883 } else {
884 badarg = true;
885 }
886 break;
887 case 'C':
888 captive = true;
889 break;
890 case 'X':
891 testcnt++;
893 scsiopts.smart_selftest_abort = true;
894 nvmeopts.smart_selftest_type = 0xf;
895 break;
896 case 'n':
897 // skip disk check if in low-power mode
898 if (!strcmp(optarg, "never")) {
899 ataopts.powermode = 1; // do not skip, but print mode
900 scsiopts.powermode = 1;
901 }
902 else {
903 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
904 char s[7+1]; unsigned i = FAILPOWER, j = 0;
905 sscanf(optarg, "%7[a-z]%n,%u%n,%u%n", s, &n1, &i, &n2, &j, &n3);
906 if (!((n1 == len || n2 == len || n3 == len) && i <= 255 && j <= 255))
907 badarg = true;
908 else if (!strcmp(s, "sleep")) {
909 ataopts.powermode = 2;
910 scsiopts.powermode = 2;
911 } else if (!strcmp(s, "standby")) {
912 ataopts.powermode = 3;
913 scsiopts.powermode = 3;
914 } else if (!strcmp(s, "idle")) {
915 ataopts.powermode = 4;
916 scsiopts.powermode = 4;
917 } else
918 badarg = true;
919
920 ataopts.powerexit = i;
921 ataopts.powerexit_unsup = (n3 == len ? j : -1);
922 scsiopts.powerexit = i;
923 }
924 break;
925 case 'f':
926 if (!strcmp(optarg, "old")) {
927 ataopts.output_format &= ~ata_print_options::FMT_BRIEF;
928 output_format_set = true;
929 }
930 else if (!strcmp(optarg, "brief")) {
932 output_format_set = true;
933 }
934 else if (!strcmp(optarg, "hex"))
937 else if (!strcmp(optarg, "hex,id"))
939 else if (!strcmp(optarg, "hex,val"))
941 else
942 badarg = true;
943 break;
944 case 'B':
945 {
946 const char * path = optarg;
947 if (*path == '+' && path[1])
948 path++;
949 else
950 use_default_db = false;
951 if (!read_drive_database(path))
952 return FAILCMD;
953 }
954 break;
955 case 'h':
956 printing_is_off = false;
957 printslogan();
958 Usage();
959 return 0;
960
961 case 'g':
962 case_s_continued: // -s, see above
963 case opt_set: // --set
964 {
965 ataopts.get_set_used = true;
966 bool get = (optchar == 'g');
967 char name[16+1]; unsigned val;
968 int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
969 if (sscanf(optarg, "%16[^,=]%n%*[,=]%n%u%n", name, &n1, &n2, &val, &n3) >= 1
970 && (n1 == len || (!get && n2 > 0))) {
971 bool on = false;
972 bool off = false;
973 bool ata = false;
974 bool persistent = false;
975
976 if (n2 > 0) {
977 int len2 = strlen(optarg + n2);
978 char * tmp = strstr(optarg+n2, ",p");
979 // handle ",p" in persistent options like: wcache-sct,[ata|on|off],p
980 if (tmp && (strlen(tmp) == 2)) {
981 persistent = true;
982 len2 = strlen(optarg+n2) - 2;
983
984 // the ,p option only works for set of SCT Feature Control command
985 if (strcmp(name, "wcache-sct") != 0 &&
986 strcmp(name, "wcreorder") != 0)
987 badarg = true;
988 }
989 on = !strncmp(optarg+n2, "on", len2);
990 off = !strncmp(optarg+n2, "off", len2);
991 ata = !strncmp(optarg+n2, "ata", len2);
992 }
993 if (n3 != len)
994 val = ~0U;
995
996 if (get && !strcmp(name, "all")) {
997 ataopts.get_aam = ataopts.get_apm = true;
998 ataopts.get_security = true;
999 ataopts.get_lookahead = ataopts.get_wcache = true;
1000 ataopts.get_dsn = true;
1001 scsiopts.get_rcd = scsiopts.get_wce = true;
1002 }
1003 else if (!strcmp(name, "aam")) {
1004 if (get)
1005 ataopts.get_aam = true;
1006 else if (off)
1007 ataopts.set_aam = -1;
1008 else if (val <= 254)
1009 ataopts.set_aam = val + 1;
1010 else {
1011 snprintf(extraerror, sizeof(extraerror), "Option -s aam,N must have 0 <= N <= 254\n");
1012 badarg = true;
1013 }
1014 }
1015 else if (!strcmp(name, "apm")) {
1016 if (get)
1017 ataopts.get_apm = true;
1018 else if (off)
1019 ataopts.set_apm = -1;
1020 else if (1 <= val && val <= 254)
1021 ataopts.set_apm = val + 1;
1022 else {
1023 snprintf(extraerror, sizeof(extraerror), "Option -s apm,N must have 1 <= N <= 254\n");
1024 badarg = true;
1025 }
1026 }
1027 else if (!strcmp(name, "lookahead")) {
1028 if (get) {
1029 ataopts.get_lookahead = true;
1030 }
1031 else if (off)
1032 ataopts.set_lookahead = -1;
1033 else if (on)
1034 ataopts.set_lookahead = 1;
1035 else
1036 badarg = true;
1037 }
1038 else if (!strcmp(name, "wcreorder")) {
1039 ataopts.sct_wcache_reorder_set_pers = persistent;
1040 if (get) {
1041 ataopts.sct_wcache_reorder_get = true;
1042 }
1043 else if (off)
1044 ataopts.sct_wcache_reorder_set = -1;
1045 else if (on)
1046 ataopts.sct_wcache_reorder_set = 1;
1047 else
1048 badarg = true;
1049 }
1050 else if (!strcmp(name, "wcache-sct")) {
1051 ataopts.sct_wcache_sct_set_pers = persistent;
1052 if (get) {
1053 ataopts.sct_wcache_sct_get = true;
1054 }
1055 else if (off)
1056 ataopts.sct_wcache_sct_set = 3;
1057 else if (on)
1058 ataopts.sct_wcache_sct_set = 2;
1059 else if (ata)
1060 ataopts.sct_wcache_sct_set = 1;
1061 else
1062 badarg = true;
1063 }
1064 else if (!strcmp(name, "rcache")) {
1065 if (get)
1066 scsiopts.get_rcd = true;
1067 else if (off)
1068 scsiopts.set_rcd = -1;
1069 else if (on)
1070 scsiopts.set_rcd = 1;
1071 else
1072 badarg = true;
1073 }
1074 else if (get && !strcmp(name, "security")) {
1075 ataopts.get_security = true;
1076 }
1077 else if (!get && !strcmp(optarg, "security-freeze")) {
1078 ataopts.set_security_freeze = true;
1079 }
1080 else if (!get && !strcmp(optarg, "standby,now")) {
1081 ataopts.set_standby_now = true;
1082 scsiopts.set_standby_now = true;
1083 }
1084 else if (!get && !strcmp(name, "standby")) {
1085 if (off) {
1086 ataopts.set_standby = 0 + 1;
1087 scsiopts.set_standby = 0 + 1;
1088 } else if (val <= 255) {
1089 ataopts.set_standby = val + 1;
1090 scsiopts.set_standby = val + 1;
1091 } else {
1092 snprintf(extraerror, sizeof(extraerror), "Option -s standby,N must have 0 <= N <= 255\n");
1093 badarg = true;
1094 }
1095 }
1096 else if (!strcmp(name, "wcache")) {
1097 if (get) {
1098 ataopts.get_wcache = true;
1099 scsiopts.get_wce = true;
1100 }
1101 else if (off) {
1102 ataopts.set_wcache = -1;
1103 scsiopts.set_wce = -1;
1104 }
1105 else if (on) {
1106 ataopts.set_wcache = 1;
1107 scsiopts.set_wce = 1;
1108 }
1109 else
1110 badarg = true;
1111 }
1112 else if (!strcmp(name, "dsn")) {
1113 if (get) {
1114 ataopts.get_dsn = true;
1115 }
1116 else if (off) {
1117 ataopts.set_dsn = -1;
1118 }
1119 else if (on) {
1120 ataopts.set_dsn = 1;
1121 }
1122 else
1123 badarg = true;
1124 }
1125 else
1126 badarg = true;
1127 }
1128 else
1129 badarg = true;
1130 }
1131 break;
1132
1133 case opt_scan:
1134 case opt_scan_open:
1135 scan = optchar;
1136 break;
1137
1138 case 'j':
1139 {
1140 print_as_json = true;
1144 print_as_json_output = false;
1146 bool json_verbose = false;
1147 if (optarg_is_set) {
1148 for (int i = 0; optarg[i]; i++) {
1149 switch (optarg[i]) {
1150 case 'c': print_as_json_options.pretty = false; break;
1151 case 'g': print_as_json_options.format = 'g'; break;
1152 case 'i': print_as_json_impl = true; break;
1153 case 'o': print_as_json_output = true; break;
1154 case 's': print_as_json_options.sorted = true; break;
1155 case 'u': print_as_json_unimpl = true; break;
1156 case 'v': json_verbose = true; break;
1157 case 'y': print_as_json_options.format = 'y'; break;
1158 default: badarg = true;
1159 }
1160 }
1161 }
1162 js_initialize(argc, argv, json_verbose);
1163 }
1164 break;
1165
1166 case '?':
1167 default:
1168 printing_is_off = false;
1169 printslogan();
1170 // Point arg to the argument in which this option was found.
1171 arg = argv[optind-1];
1172 // Check whether the option is a long option that doesn't map to -h.
1173 if (arg[1] == '-' && optchar != 'h') {
1174 // Iff optopt holds a valid option then argument must be missing.
1175 if (optopt && (optopt > '~' || strchr(shortopts, optopt))) {
1176 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %s\n", arg+2);
1178 } else
1179 jerr("=======> UNRECOGNIZED OPTION: %s\n",arg+2);
1180 if (extraerror[0])
1181 pout("=======> %s", extraerror);
1182 UsageSummary();
1183 return FAILCMD;
1184 }
1185 if (0 < optopt && optopt < '~') {
1186 // Iff optopt holds a valid option then argument must be
1187 // missing. Note (BA) this logic seems to fail using Solaris
1188 // getopt!
1189 if (strchr(shortopts, optopt) != NULL) {
1190 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %c\n", optopt);
1192 } else
1193 jerr("=======> UNRECOGNIZED OPTION: %c\n",optopt);
1194 if (extraerror[0])
1195 pout("=======> %s", extraerror);
1196 UsageSummary();
1197 return FAILCMD;
1198 }
1199 Usage();
1200 return 0;
1201 } // closes switch statement to process command-line options
1202
1203 // Check to see if option had an unrecognized or incorrect argument.
1204 if (badarg) {
1205 printslogan();
1206 // It would be nice to print the actual option name given by the user
1207 // here, but we just print the short form. Please fix this if you know
1208 // a clean way to do it.
1209 char optstr[] = { (char)optchar, 0 };
1210 jerr("=======> INVALID ARGUMENT TO -%s: %s\n",
1211 (optchar == opt_identify ? "-identify" :
1212 optchar == opt_set ? "-set" :
1213 optchar == opt_smart ? "-smart" :
1214 optchar == 'j' ? "-json" : optstr), optarg);
1215 printvalidarglistmessage(optchar);
1216 if (extraerror[0])
1217 pout("=======> %s", extraerror);
1218 UsageSummary();
1219 return FAILCMD;
1220 }
1221 }
1222
1223 // Special handling of --scan, --scanopen
1224 if (scan) {
1225 // Read or init drive database to allow USB ID check.
1226 if (!init_drive_database(use_default_db))
1227 return FAILCMD;
1228 scan_devices(scan_types, (scan == opt_scan_open), argv + optind);
1229 return 0;
1230 }
1231
1232 // At this point we have processed all command-line options. If the
1233 // print output is switchable, then start with the print output
1234 // turned off
1236 printing_is_off = true;
1237
1238 // Check for multiple -d TYPE options
1239 if (scan_types.size() > 1) {
1240 printing_is_off = false;
1241 printslogan();
1242 jerr("ERROR: multiple -d TYPE options are only allowed with --scan\n");
1243 UsageSummary();
1244 return FAILCMD;
1245 }
1246
1247 // error message if user has asked for more than one test
1248 if (testcnt > 1) {
1249 printing_is_off = false;
1250 printslogan();
1251 jerr("\nERROR: smartctl can only run a single test type (or abort) at a time.\n");
1252 UsageSummary();
1253 return FAILCMD;
1254 }
1255
1256 // error message if user has set selective self-test options without
1257 // asking for a selective self-test
1258 if ( (ataopts.smart_selective_args.pending_time || ataopts.smart_selective_args.scan_after_select)
1259 && !ataopts.smart_selective_args.num_spans) {
1260 printing_is_off = false;
1261 printslogan();
1262 if (ataopts.smart_selective_args.pending_time)
1263 jerr("\nERROR: smartctl -t pending,N must be used with -t select,N-M.\n");
1264 else
1265 jerr("\nERROR: smartctl -t afterselect,(on|off) must be used with -t select,N-M.\n");
1266 UsageSummary();
1267 return FAILCMD;
1268 }
1269
1270 // If captive option was used, change test type if appropriate.
1271 if (captive)
1272 switch (ataopts.smart_selftest_type) {
1273 case SHORT_SELF_TEST:
1274 ataopts.smart_selftest_type = SHORT_CAPTIVE_SELF_TEST;
1275 scsiopts.smart_short_selftest = false;
1276 scsiopts.smart_short_cap_selftest = true;
1277 break;
1278 case EXTEND_SELF_TEST:
1279 ataopts.smart_selftest_type = EXTEND_CAPTIVE_SELF_TEST;
1280 scsiopts.smart_extend_selftest = false;
1281 scsiopts.smart_extend_cap_selftest = true;
1282 break;
1284 ataopts.smart_selftest_type = CONVEYANCE_CAPTIVE_SELF_TEST;
1285 break;
1287 ataopts.smart_selftest_type = SELECTIVE_CAPTIVE_SELF_TEST;
1288 break;
1289 }
1290
1291 // From here on, normal operations...
1292 printslogan();
1293
1294 // Warn if the user has provided no device name
1295 if (argc-optind<1){
1296 jerr("ERROR: smartctl requires a device name as the final command-line argument.\n\n");
1297 UsageSummary();
1298 return FAILCMD;
1299 }
1300
1301 // Warn if the user has provided more than one device name
1302 if (argc-optind>1){
1303 int i;
1304 jerr("ERROR: smartctl takes ONE device name as the final command-line argument.\n");
1305 pout("You have provided %d device names:\n",argc-optind);
1306 for (i=0; i<argc-optind; i++)
1307 pout("%s\n",argv[optind+i]);
1308 UsageSummary();
1309 return FAILCMD;
1310 }
1311
1312 // Read or init drive database
1313 if (!init_drive_database(use_default_db))
1314 return FAILCMD;
1315
1316 // No error, continue in main_worker()
1317 return -1;
1318}
1319
1320// Printing functions
1321
1323static void vjpout(bool is_js_impl, const char * msg_severity,
1324 const char *fmt, va_list ap)
1325{
1326 if (!print_as_json) {
1327 // Print out directly
1328 vprintf(fmt, ap);
1329 fflush(stdout);
1330 }
1331 else {
1332 // Add lines to JSON output
1333 static char buf[1024];
1334 static char * bufnext = buf;
1335 vsnprintf(bufnext, sizeof(buf) - (bufnext - buf), fmt, ap);
1336 for (char * p = buf, *q; ; p = q) {
1337 if (!(q = strchr(p, '\n'))) {
1338 // Keep remaining line for next call
1339 for (bufnext = buf; *p; bufnext++, p++)
1340 *bufnext = *p;
1341 break;
1342 }
1343 *q++ = 0; // '\n' -> '\0'
1344
1345 static int lineno = 0;
1346 lineno++;
1348 // Collect full output in array
1349 static int outindex = 0;
1350 jglb["smartctl"]["output"][outindex++] = p;
1351 }
1352 if (!*p)
1353 continue; // Skip empty line
1354
1355 if (msg_severity) {
1356 // Collect non-empty messages in array
1357 static int errindex = 0;
1358 json::ref jref = jglb["smartctl"]["messages"][errindex++];
1359 jref["string"] = p;
1360 jref["severity"] = msg_severity;
1361 }
1362
1363 if ( ( is_js_impl && print_as_json_impl )
1364 || (!is_js_impl && print_as_json_unimpl)) {
1365 // Add (un)implemented non-empty lines to global object
1366 jglb[strprintf("smartctl_%04d_%c", lineno,
1367 (is_js_impl ? 'i' : 'u')).c_str()] = p;
1368 }
1369 }
1370 }
1371}
1372
1373// Default: print to stdout
1374// --json: ignore
1375// --json=o: append to "output" array
1376// --json=u: add "smartctl_NNNN_u" element(s)
1377void pout(const char *fmt, ...)
1378{
1379 if (printing_is_off)
1380 return;
1383 return;
1384
1385 va_list ap;
1386 va_start(ap, fmt);
1387 vjpout(false, 0, fmt, ap);
1388 va_end(ap);
1389}
1390
1391// Default: Print to stdout
1392// --json: ignore
1393// --json=o: append to "output" array
1394// --json=i: add "smartctl_NNNN_i" element(s)
1395void jout(const char *fmt, ...)
1396{
1397 if (printing_is_off)
1398 return;
1401 return;
1402
1403 va_list ap;
1404 va_start(ap, fmt);
1405 vjpout(true, 0, fmt, ap);
1406 va_end(ap);
1407}
1408
1409// Default: print to stdout
1410// --json: append to "messages"
1411// --json=o: append to "output" array
1412// --json=i: add "smartctl_NNNN_i" element(s)
1413void jinf(const char *fmt, ...)
1414{
1415 if (printing_is_off)
1416 return;
1417
1418 va_list ap;
1419 va_start(ap, fmt);
1420 vjpout(true, "information", fmt, ap);
1421 va_end(ap);
1422}
1423
1424void jwrn(const char *fmt, ...)
1425{
1426 if (printing_is_off)
1427 return;
1428
1429 va_list ap;
1430 va_start(ap, fmt);
1431 vjpout(true, "warning", fmt, ap);
1432 va_end(ap);
1433}
1434
1435void jerr(const char *fmt, ...)
1436{
1437 if (printing_is_off)
1438 return;
1439
1440 va_list ap;
1441 va_start(ap, fmt);
1442 vjpout(true, "error", fmt, ap);
1443 va_end(ap);
1444}
1445
1446static char startup_datetime_buf[DATEANDEPOCHLEN];
1447
1448// Print smartctl start-up date and time and timezone
1449void jout_startup_datetime(const char *prefix)
1450{
1451 jout("%s%s\n", prefix, startup_datetime_buf);
1452}
1453
1454// Globals to set failuretest() policy
1456unsigned char failuretest_permissive = 0;
1457
1458// Compares failure type to policy in effect, and either exits or
1459// simply returns to the calling routine.
1460// Used in ataprint.cpp and scsiprint.cpp.
1461void failuretest(failure_type type, int returnvalue)
1462{
1463 // If this is an error in an "optional" SMART command
1464 if (type == OPTIONAL_CMD) {
1466 return;
1467 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1468 throw int(returnvalue);
1469 }
1470
1471 // If this is an error in a "mandatory" SMART command
1472 if (type == MANDATORY_CMD) {
1474 return;
1475 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1476 throw int(returnvalue);
1477 }
1478
1479 throw std::logic_error("failuretest: Unknown type");
1480}
1481
1482// Used to warn users about invalid checksums. Called from atacmds.cpp.
1483// Action to be taken may be altered by the user.
1484void checksumwarning(const char * string)
1485{
1486 // user has asked us to ignore checksum errors
1488 return;
1489
1490 pout("Warning! %s error: invalid SMART checksum.\n", string);
1491
1492 // user has asked us to fail on checksum errors
1494 throw int(FAILSMART);
1495}
1496
1497// Return info string about device protocol
1498static const char * get_protocol_info(const smart_device * dev)
1499{
1500 switch ( (int)dev->is_ata()
1501 | ((int)dev->is_scsi() << 1)
1502 | ((int)dev->is_nvme() << 2)) {
1503 case 0x1: return "ATA";
1504 case 0x2: return "SCSI";
1505 case 0x3: return "ATA+SCSI";
1506 case 0x4: return "NVMe";
1507 default: return "Unknown";
1508 }
1509}
1510
1511// Add JSON device info
1512static void js_device_info(const json::ref & jref, const smart_device * dev)
1513{
1514 jref["name"] = dev->get_dev_name();
1515 jref["info_name"] = dev->get_info_name();
1516 jref["type"] = dev->get_dev_type();
1517 jref["protocol"] = get_protocol_info(dev);
1518}
1519
1520// Device scan
1521// smartctl [-d type] --scan[-open] -- [PATTERN] [smartd directive ...]
1522void scan_devices(const smart_devtype_list & types, bool with_open, char ** argv)
1523{
1524 bool dont_print = !(ata_debugmode || scsi_debugmode || nvme_debugmode);
1525
1526 const char * pattern = 0;
1527 int ai = 0;
1528 if (argv[ai] && argv[ai][0] != '-')
1529 pattern = argv[ai++];
1530
1531 smart_device_list devlist;
1532 printing_is_off = dont_print;
1533 bool ok = smi()->scan_smart_devices(devlist, types, pattern);
1534 printing_is_off = false;
1535
1536 if (!ok) {
1537 pout("# scan_smart_devices: %s\n", smi()->get_errmsg());
1538 return;
1539 }
1540
1541 for (unsigned i = 0; i < devlist.size(); i++) {
1542 smart_device_auto_ptr dev( devlist.release(i) );
1543 json::ref jref = jglb["devices"][i];
1544
1545 if (with_open) {
1546 printing_is_off = dont_print;
1547 dev.replace ( dev->autodetect_open() );
1548 printing_is_off = false;
1549 }
1550
1551 js_device_info(jref, dev.get());
1552
1553 if (with_open && !dev->is_open()) {
1554 jout("# %s -d %s # %s, %s device open failed: %s\n", dev->get_dev_name(),
1555 dev->get_dev_type(), dev->get_info_name(),
1556 get_protocol_info(dev.get()), dev->get_errmsg());
1557 jref["open_error"] = dev->get_errmsg();
1558 continue;
1559 }
1560
1561 jout("%s -d %s", dev->get_dev_name(), dev->get_dev_type());
1562 if (!argv[ai])
1563 jout(" # %s, %s device\n", dev->get_info_name(), get_protocol_info(dev.get()));
1564 else {
1565 for (int j = ai; argv[j]; j++)
1566 jout(" %s", argv[j]);
1567 jout("\n");
1568 }
1569
1570 if (dev->is_open())
1571 dev->close();
1572 }
1573}
1574
1575// Main program without exception handling
1576static int main_worker(int argc, char **argv)
1577{
1578 // Throw if runtime environment does not match compile time test.
1579 check_config();
1580
1581 // Initialize interface
1583 if (!smi())
1584 return 1;
1585
1586 // Parse input arguments
1587 const char * type = 0;
1588 ata_print_options ataopts;
1589 scsi_print_options scsiopts;
1590 nvme_print_options nvmeopts;
1591 bool print_type_only = false;
1592 {
1593 int status = parse_options(argc, argv, type, ataopts, scsiopts, nvmeopts, print_type_only);
1594 if (status >= 0)
1595 return status;
1596 }
1597
1598 // Store formatted current time for jout_startup_datetime()
1599 // Output as JSON regardless of '-i' option
1600 {
1601 time_t now = time(nullptr);
1602 dateandtimezoneepoch(startup_datetime_buf, now);
1603 jglb["local_time"] += { {"time_t", now}, {"asctime", startup_datetime_buf} };
1604 }
1605
1606 const char * name = argv[argc-1];
1607
1609 if (!strcmp(name,"-")) {
1610 // Parse "smartctl -r ataioctl,2 ..." output from stdin
1611 if (type || print_type_only) {
1612 pout("-d option is not allowed in conjunction with device name \"-\".\n");
1613 UsageSummary();
1614 return FAILCMD;
1615 }
1616 dev = get_parsed_ata_device(smi(), name);
1617 }
1618 else
1619 // get device of appropriate type
1620 dev = smi()->get_smart_device(name, type);
1621
1622 if (!dev) {
1623 jerr("%s: %s\n", name, smi()->get_errmsg());
1624 if (type)
1626 else
1627 pout("Please specify device type with the -d option.\n");
1628 UsageSummary();
1629 return FAILCMD;
1630 }
1631
1632 if (print_type_only)
1633 // Report result of first autodetection
1634 pout("%s: Device of type '%s' [%s] detected\n",
1635 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1636
1637 if (dev->is_ata() && ataopts.powermode>=2 && dev->is_powered_down()) {
1638 jinf("Device is in STANDBY (OS) mode, exit(%d)\n", ataopts.powerexit);
1639 return ataopts.powerexit;
1640 }
1641
1642 // Open device
1643 {
1644 // Save old info
1645 smart_device::device_info oldinfo = dev->get_info();
1646
1647 // Open with autodetect support, may return 'better' device
1648 dev.replace( dev->autodetect_open() );
1649
1650 // Report if type has changed
1651 if ( (ata_debugmode || scsi_debugmode || nvme_debugmode || print_type_only)
1652 && oldinfo.dev_type != dev->get_dev_type() )
1653 pout("%s: Device open changed type from '%s' to '%s'\n",
1654 dev->get_info_name(), oldinfo.dev_type.c_str(), dev->get_dev_type());
1655 }
1656 if (!dev->is_open()) {
1657 jerr("Smartctl open device: %s failed: %s\n", dev->get_info_name(), dev->get_errmsg());
1658 return FAILDEV;
1659 }
1660
1661 // Add JSON info similar to --scan output
1662 js_device_info(jglb["device"], dev.get());
1663
1664 // now call appropriate ATA or SCSI routine
1665 int retval = 0;
1666 if (print_type_only)
1667 jout("%s: Device of type '%s' [%s] opened\n",
1668 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1669 else if (dev->is_ata())
1670 retval = ataPrintMain(dev->to_ata(), ataopts);
1671 else if (dev->is_scsi())
1672 retval = scsiPrintMain(dev->to_scsi(), scsiopts);
1673 else if (dev->is_nvme())
1674 retval = nvmePrintMain(dev->to_nvme(), nvmeopts);
1675 else
1676 // we should never fall into this branch!
1677 pout("%s: Neither ATA, SCSI nor NVMe device\n", dev->get_info_name());
1678
1679 dev->close();
1680 return retval;
1681}
1682
1683
1684// Main program
1685int main(int argc, char **argv)
1686{
1687 int status;
1688 bool badcode = false;
1689
1690 try {
1691 try {
1692 // Do the real work ...
1693 status = main_worker(argc, argv);
1694 }
1695 catch (int ex) {
1696 // Exit status from checksumwarning() and failuretest() arrives here
1697 status = ex;
1698 }
1699 // Print JSON if enabled
1701 jglb["smartctl"]["uint128_precision_bits"] = uint128_to_str_precision_bits();
1702 jglb["smartctl"]["exit_status"] = status;
1704 }
1705 catch (const std::bad_alloc & /*ex*/) {
1706 // Memory allocation failed (also thrown by std::operator new)
1707 printf("Smartctl: Out of memory\n");
1708 status = FAILCMD;
1709 }
1710 catch (const std::exception & ex) {
1711 // Other fatal errors
1712 printf("Smartctl: Exception: %s\n", ex.what());
1713 badcode = true;
1714 status = FAILCMD;
1715 }
1716
1717 // Check for remaining device objects
1718 if (smart_device::get_num_objects() != 0) {
1719 printf("Smartctl: Internal Error: %d device object(s) left at exit.\n",
1721 badcode = true;
1722 status = FAILCMD;
1723 }
1724
1725 if (badcode)
1726 printf("Please inform " PACKAGE_BUGREPORT ", including output of smartctl -V.\n");
1727
1728 return status;
1729}
1730
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:3357
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:710
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:652
unsigned char scsi_debugmode
Definition: scsicmds.cpp:45
int scsiPrintMain(scsi_device *device, const scsi_print_options &options)
Definition: scsiprint.cpp:3494
bool failuretest_conservative
Definition: smartctl.cpp:1455
static std::string getvalidarglist(int opt)
Definition: smartctl.cpp:228
void jout_startup_datetime(const char *prefix)
Definition: smartctl.cpp:1449
unsigned char failuretest_permissive
Definition: smartctl.cpp:1456
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:1685
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:1512
void checksumwarning(const char *string)
Definition: smartctl.cpp:1484
static const char * get_protocol_info(const smart_device *dev)
Definition: smartctl.cpp:1498
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:1461
static int main_worker(int argc, char **argv)
Definition: smartctl.cpp:1576
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:1324
static void Usage()
Definition: smartctl.cpp:113
bool printing_is_switchable
Definition: smartctl.cpp:49
const char * msg_severity
Definition: smartctl.cpp:1323
static void scan_devices(const smart_devtype_list &types, bool with_open, char **argv)
Definition: smartctl.cpp:1522
const char const char va_list ap
Definition: smartctl.cpp:1325
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:1338
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:101
bool sct_temp_hist
Definition: ataprint.h:54
bool smart_auto_offl_disable
Definition: ataprint.h:61
bool sct_wcache_reorder_get
Definition: ataprint.h:98
bool smart_auto_save_enable
Definition: ataprint.h:62
bool smart_general_values
Definition: ataprint.h:36
unsigned sct_erc_writetime
Definition: ataprint.h:57
bool devstat_all_pages
Definition: ataprint.h:49
bool set_security_freeze
Definition: ataprint.h:95
unsigned pending_defects_log
Definition: ataprint.h:52
bool set_standby_now
Definition: ataprint.h:93
int identify_word_level
Definition: ataprint.h:34
int smart_selftest_type
Definition: ataprint.h:64
bool smart_selftest_log
Definition: ataprint.h:39
int identify_bit_level
Definition: ataprint.h:34
bool smart_disable
Definition: ataprint.h:60
ata_selective_selftest_args smart_selective_args
Definition: ataprint.h:66
unsigned char powerexit
Definition: ataprint.h:82
std::vector< int > devstat_pages
Definition: ataprint.h:50
bool smart_check_status
Definition: ataprint.h:35
bool farm_log_suggest
Definition: ataprint.h:108
unsigned smart_ext_error_log
Definition: ataprint.h:43
bool fix_swapped_id
Definition: ataprint.h:75
unsigned smart_ext_selftest_log
Definition: ataprint.h:44
firmwarebug_defs firmwarebugs
Definition: ataprint.h:74
bool ignore_presets
Definition: ataprint.h:79
unsigned char powermode
Definition: ataprint.h:81
bool get_lookahead
Definition: ataprint.h:90
bool sataphy_reset
Definition: ataprint.h:58
unsigned char output_format
Definition: ataprint.h:72
int sct_wcache_reorder_set
Definition: ataprint.h:99
bool sct_temp_int_pers
Definition: ataprint.h:69
bool smart_selftest_force
Definition: ataprint.h:65
bool smart_selective_selftest_log
Definition: ataprint.h:40
bool devstat_ssd_page
Definition: ataprint.h:49
ata_vendor_attr_defs attribute_defs
Definition: ataprint.h:77
unsigned sct_temp_int
Definition: ataprint.h:68
unsigned sct_erc_readtime
Definition: ataprint.h:57
bool smart_vendor_attrib
Definition: ataprint.h:37
std::vector< ata_log_request > log_requests
Definition: ataprint.h:47
bool sct_wcache_sct_set_pers
Definition: ataprint.h:103
bool retry_error_log
Definition: ataprint.h:45
bool sct_wcache_reorder_set_pers
Definition: ataprint.h:100
bool smart_auto_offl_enable
Definition: ataprint.h:61
bool retry_selftest_log
Definition: ataprint.h:45
bool smart_error_log
Definition: ataprint.h:38
bool smart_auto_save_disable
Definition: ataprint.h:62
int sct_wcache_sct_set
Definition: ataprint.h:102
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:53
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:53
unsigned char powerexit
Definition: scsiprint.h:56
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:47
bool smart_auto_save_enable
Definition: scsiprint.h:33
bool smart_ss_media_log
Definition: scsiprint.h:30
unsigned char powermode
Definition: scsiprint.h:55
bool scsi_pending_defects
Definition: scsiprint.h:40
bool general_stats_and_perf
Definition: scsiprint.h:41
bool zoned_device_stats
Definition: scsiprint.h:50
Device info strings.
Definition: dev_interface.h:37
std::string dev_type
Actual device type.
Definition: dev_interface.h:47
std::string format_version_info(const char *prog_name, int lines)
Definition: utility.cpp:87
void dateandtimezoneepoch(char(&buffer)[DATEANDEPOCHLEN], time_t tval)
Definition: utility.cpp:349
std::string strprintf(const char *fmt,...)
Definition: utility.cpp:799
int split_selective_arg(char *s, uint64_t *start, uint64_t *stop, int *mode)
Definition: utility.cpp:630
void check_config()
Definition: utility.cpp:919
#define BUILD_INFO
Definition: utility.cpp:82
#define DATEANDEPOCHLEN
Definition: utility.h:64
#define __attribute_format_printf(x, y)
Definition: utility.h:34
int uint128_to_str_precision_bits()
Definition: utility.h:296
bool str_starts_with(const char *str, const char *prefix)
Definition: utility.h:52