smartmontools SVN Rev 5618
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 5613 2024-05-08 13:46:51Z 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 // Note: getopt_long() may set optind > argc (e.g. musl libc)
1172 arg = argv[optind <= argc ? optind - 1 : argc - 1];
1173 // Check whether the option is a long option that doesn't map to -h.
1174 if (arg[1] == '-' && optchar != 'h') {
1175 // Iff optopt holds a valid option then argument must be missing.
1176 if (optopt && (optopt > '~' || strchr(shortopts, optopt))) {
1177 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %s\n", arg+2);
1179 } else
1180 jerr("=======> UNRECOGNIZED OPTION: %s\n",arg+2);
1181 if (extraerror[0])
1182 pout("=======> %s", extraerror);
1183 UsageSummary();
1184 return FAILCMD;
1185 }
1186 if (0 < optopt && optopt < '~') {
1187 // Iff optopt holds a valid option then argument must be
1188 // missing. Note (BA) this logic seems to fail using Solaris
1189 // getopt!
1190 if (strchr(shortopts, optopt) != NULL) {
1191 jerr("=======> ARGUMENT REQUIRED FOR OPTION: %c\n", optopt);
1193 } else
1194 jerr("=======> UNRECOGNIZED OPTION: %c\n",optopt);
1195 if (extraerror[0])
1196 pout("=======> %s", extraerror);
1197 UsageSummary();
1198 return FAILCMD;
1199 }
1200 Usage();
1201 return 0;
1202 } // closes switch statement to process command-line options
1203
1204 // Check to see if option had an unrecognized or incorrect argument.
1205 if (badarg) {
1206 printslogan();
1207 // It would be nice to print the actual option name given by the user
1208 // here, but we just print the short form. Please fix this if you know
1209 // a clean way to do it.
1210 char optstr[] = { (char)optchar, 0 };
1211 jerr("=======> INVALID ARGUMENT TO -%s: %s\n",
1212 (optchar == opt_identify ? "-identify" :
1213 optchar == opt_set ? "-set" :
1214 optchar == opt_smart ? "-smart" :
1215 optchar == 'j' ? "-json" : optstr), optarg);
1216 printvalidarglistmessage(optchar);
1217 if (extraerror[0])
1218 pout("=======> %s", extraerror);
1219 UsageSummary();
1220 return FAILCMD;
1221 }
1222 }
1223
1224 // Special handling of --scan, --scanopen
1225 if (scan) {
1226 // Read or init drive database to allow USB ID check.
1227 if (!init_drive_database(use_default_db))
1228 return FAILCMD;
1229 scan_devices(scan_types, (scan == opt_scan_open), argv + optind);
1230 return 0;
1231 }
1232
1233 // At this point we have processed all command-line options. If the
1234 // print output is switchable, then start with the print output
1235 // turned off
1237 printing_is_off = true;
1238
1239 // Check for multiple -d TYPE options
1240 if (scan_types.size() > 1) {
1241 printing_is_off = false;
1242 printslogan();
1243 jerr("ERROR: multiple -d TYPE options are only allowed with --scan\n");
1244 UsageSummary();
1245 return FAILCMD;
1246 }
1247
1248 // error message if user has asked for more than one test
1249 if (testcnt > 1) {
1250 printing_is_off = false;
1251 printslogan();
1252 jerr("\nERROR: smartctl can only run a single test type (or abort) at a time.\n");
1253 UsageSummary();
1254 return FAILCMD;
1255 }
1256
1257 // error message if user has set selective self-test options without
1258 // asking for a selective self-test
1259 if ( (ataopts.smart_selective_args.pending_time || ataopts.smart_selective_args.scan_after_select)
1260 && !ataopts.smart_selective_args.num_spans) {
1261 printing_is_off = false;
1262 printslogan();
1263 if (ataopts.smart_selective_args.pending_time)
1264 jerr("\nERROR: smartctl -t pending,N must be used with -t select,N-M.\n");
1265 else
1266 jerr("\nERROR: smartctl -t afterselect,(on|off) must be used with -t select,N-M.\n");
1267 UsageSummary();
1268 return FAILCMD;
1269 }
1270
1271 // If captive option was used, change test type if appropriate.
1272 if (captive)
1273 switch (ataopts.smart_selftest_type) {
1274 case SHORT_SELF_TEST:
1275 ataopts.smart_selftest_type = SHORT_CAPTIVE_SELF_TEST;
1276 scsiopts.smart_short_selftest = false;
1277 scsiopts.smart_short_cap_selftest = true;
1278 break;
1279 case EXTEND_SELF_TEST:
1280 ataopts.smart_selftest_type = EXTEND_CAPTIVE_SELF_TEST;
1281 scsiopts.smart_extend_selftest = false;
1282 scsiopts.smart_extend_cap_selftest = true;
1283 break;
1285 ataopts.smart_selftest_type = CONVEYANCE_CAPTIVE_SELF_TEST;
1286 break;
1288 ataopts.smart_selftest_type = SELECTIVE_CAPTIVE_SELF_TEST;
1289 break;
1290 }
1291
1292 // From here on, normal operations...
1293 printslogan();
1294
1295 // Warn if the user has provided no device name
1296 if (argc-optind<1){
1297 jerr("ERROR: smartctl requires a device name as the final command-line argument.\n\n");
1298 UsageSummary();
1299 return FAILCMD;
1300 }
1301
1302 // Warn if the user has provided more than one device name
1303 if (argc-optind>1){
1304 int i;
1305 jerr("ERROR: smartctl takes ONE device name as the final command-line argument.\n");
1306 pout("You have provided %d device names:\n",argc-optind);
1307 for (i=0; i<argc-optind; i++)
1308 pout("%s\n",argv[optind+i]);
1309 UsageSummary();
1310 return FAILCMD;
1311 }
1312
1313 // Read or init drive database
1314 if (!init_drive_database(use_default_db))
1315 return FAILCMD;
1316
1317 // No error, continue in main_worker()
1318 return -1;
1319}
1320
1321// Printing functions
1322
1324static void vjpout(bool is_js_impl, const char * msg_severity,
1325 const char *fmt, va_list ap)
1326{
1327 if (!print_as_json) {
1328 // Print out directly
1329 vprintf(fmt, ap);
1330 fflush(stdout);
1331 }
1332 else {
1333 // Add lines to JSON output
1334 static char buf[1024];
1335 static char * bufnext = buf;
1336 vsnprintf(bufnext, sizeof(buf) - (bufnext - buf), fmt, ap);
1337 for (char * p = buf, *q; ; p = q) {
1338 if (!(q = strchr(p, '\n'))) {
1339 // Keep remaining line for next call
1340 for (bufnext = buf; *p; bufnext++, p++)
1341 *bufnext = *p;
1342 break;
1343 }
1344 *q++ = 0; // '\n' -> '\0'
1345
1346 static int lineno = 0;
1347 lineno++;
1349 // Collect full output in array
1350 static int outindex = 0;
1351 jglb["smartctl"]["output"][outindex++] = p;
1352 }
1353 if (!*p)
1354 continue; // Skip empty line
1355
1356 if (msg_severity) {
1357 // Collect non-empty messages in array
1358 static int errindex = 0;
1359 json::ref jref = jglb["smartctl"]["messages"][errindex++];
1360 jref["string"] = p;
1361 jref["severity"] = msg_severity;
1362 }
1363
1364 if ( ( is_js_impl && print_as_json_impl )
1365 || (!is_js_impl && print_as_json_unimpl)) {
1366 // Add (un)implemented non-empty lines to global object
1367 jglb[strprintf("smartctl_%04d_%c", lineno,
1368 (is_js_impl ? 'i' : 'u')).c_str()] = p;
1369 }
1370 }
1371 }
1372}
1373
1374// Default: print to stdout
1375// --json: ignore
1376// --json=o: append to "output" array
1377// --json=u: add "smartctl_NNNN_u" element(s)
1378void pout(const char *fmt, ...)
1379{
1380 if (printing_is_off)
1381 return;
1384 return;
1385
1386 va_list ap;
1387 va_start(ap, fmt);
1388 vjpout(false, 0, fmt, ap);
1389 va_end(ap);
1390}
1391
1392// Default: Print to stdout
1393// --json: ignore
1394// --json=o: append to "output" array
1395// --json=i: add "smartctl_NNNN_i" element(s)
1396void jout(const char *fmt, ...)
1397{
1398 if (printing_is_off)
1399 return;
1402 return;
1403
1404 va_list ap;
1405 va_start(ap, fmt);
1406 vjpout(true, 0, fmt, ap);
1407 va_end(ap);
1408}
1409
1410// Default: print to stdout
1411// --json: append to "messages"
1412// --json=o: append to "output" array
1413// --json=i: add "smartctl_NNNN_i" element(s)
1414void jinf(const char *fmt, ...)
1415{
1416 if (printing_is_off)
1417 return;
1418
1419 va_list ap;
1420 va_start(ap, fmt);
1421 vjpout(true, "information", fmt, ap);
1422 va_end(ap);
1423}
1424
1425void jwrn(const char *fmt, ...)
1426{
1427 if (printing_is_off)
1428 return;
1429
1430 va_list ap;
1431 va_start(ap, fmt);
1432 vjpout(true, "warning", fmt, ap);
1433 va_end(ap);
1434}
1435
1436void jerr(const char *fmt, ...)
1437{
1438 if (printing_is_off)
1439 return;
1440
1441 va_list ap;
1442 va_start(ap, fmt);
1443 vjpout(true, "error", fmt, ap);
1444 va_end(ap);
1445}
1446
1447static char startup_datetime_buf[DATEANDEPOCHLEN];
1448
1449// Print smartctl start-up date and time and timezone
1450void jout_startup_datetime(const char *prefix)
1451{
1452 jout("%s%s\n", prefix, startup_datetime_buf);
1453}
1454
1455// Globals to set failuretest() policy
1457unsigned char failuretest_permissive = 0;
1458
1459// Compares failure type to policy in effect, and either exits or
1460// simply returns to the calling routine.
1461// Used in ataprint.cpp and scsiprint.cpp.
1462void failuretest(failure_type type, int returnvalue)
1463{
1464 // If this is an error in an "optional" SMART command
1465 if (type == OPTIONAL_CMD) {
1467 return;
1468 pout("An optional SMART command failed: exiting. Remove '-T conservative' option to continue.\n");
1469 throw int(returnvalue);
1470 }
1471
1472 // If this is an error in a "mandatory" SMART command
1473 if (type == MANDATORY_CMD) {
1475 return;
1476 pout("A mandatory SMART command failed: exiting. To continue, add one or more '-T permissive' options.\n");
1477 throw int(returnvalue);
1478 }
1479
1480 throw std::logic_error("failuretest: Unknown type");
1481}
1482
1483// Used to warn users about invalid checksums. Called from atacmds.cpp.
1484// Action to be taken may be altered by the user.
1485void checksumwarning(const char * string)
1486{
1487 // user has asked us to ignore checksum errors
1489 return;
1490
1491 pout("Warning! %s error: invalid SMART checksum.\n", string);
1492
1493 // user has asked us to fail on checksum errors
1495 throw int(FAILSMART);
1496}
1497
1498// Return info string about device protocol
1499static const char * get_protocol_info(const smart_device * dev)
1500{
1501 switch ( (int)dev->is_ata()
1502 | ((int)dev->is_scsi() << 1)
1503 | ((int)dev->is_nvme() << 2)) {
1504 case 0x1: return "ATA";
1505 case 0x2: return "SCSI";
1506 case 0x3: return "ATA+SCSI";
1507 case 0x4: return "NVMe";
1508 default: return "Unknown";
1509 }
1510}
1511
1512// Add JSON device info
1513static void js_device_info(const json::ref & jref, const smart_device * dev)
1514{
1515 jref["name"] = dev->get_dev_name();
1516 jref["info_name"] = dev->get_info_name();
1517 jref["type"] = dev->get_dev_type();
1518 jref["protocol"] = get_protocol_info(dev);
1519}
1520
1521// Device scan
1522// smartctl [-d type] --scan[-open] -- [PATTERN] [smartd directive ...]
1523void scan_devices(const smart_devtype_list & types, bool with_open, char ** argv)
1524{
1525 bool dont_print = !(ata_debugmode || scsi_debugmode || nvme_debugmode);
1526
1527 const char * pattern = 0;
1528 int ai = 0;
1529 if (argv[ai] && argv[ai][0] != '-')
1530 pattern = argv[ai++];
1531
1532 smart_device_list devlist;
1533 printing_is_off = dont_print;
1534 bool ok = smi()->scan_smart_devices(devlist, types, pattern);
1535 printing_is_off = false;
1536
1537 if (!ok) {
1538 pout("# scan_smart_devices: %s\n", smi()->get_errmsg());
1539 return;
1540 }
1541
1542 for (unsigned i = 0; i < devlist.size(); i++) {
1543 smart_device_auto_ptr dev( devlist.release(i) );
1544 json::ref jref = jglb["devices"][i];
1545
1546 if (with_open) {
1547 printing_is_off = dont_print;
1548 dev.replace ( dev->autodetect_open() );
1549 printing_is_off = false;
1550 }
1551
1552 js_device_info(jref, dev.get());
1553
1554 if (with_open && !dev->is_open()) {
1555 jout("# %s -d %s # %s, %s device open failed: %s\n", dev->get_dev_name(),
1556 dev->get_dev_type(), dev->get_info_name(),
1557 get_protocol_info(dev.get()), dev->get_errmsg());
1558 jref["open_error"] = dev->get_errmsg();
1559 continue;
1560 }
1561
1562 jout("%s -d %s", dev->get_dev_name(), dev->get_dev_type());
1563 if (!argv[ai])
1564 jout(" # %s, %s device\n", dev->get_info_name(), get_protocol_info(dev.get()));
1565 else {
1566 for (int j = ai; argv[j]; j++)
1567 jout(" %s", argv[j]);
1568 jout("\n");
1569 }
1570
1571 if (dev->is_open())
1572 dev->close();
1573 }
1574}
1575
1576// Main program without exception handling
1577static int main_worker(int argc, char **argv)
1578{
1579 // Throw if runtime environment does not match compile time test.
1580 check_config();
1581
1582 // Initialize interface
1584 if (!smi())
1585 return 1;
1586
1587 // Parse input arguments
1588 const char * type = 0;
1589 ata_print_options ataopts;
1590 scsi_print_options scsiopts;
1591 nvme_print_options nvmeopts;
1592 bool print_type_only = false;
1593 {
1594 int status = parse_options(argc, argv, type, ataopts, scsiopts, nvmeopts, print_type_only);
1595 if (status >= 0)
1596 return status;
1597 }
1598
1599 // Store formatted current time for jout_startup_datetime()
1600 // Output as JSON regardless of '-i' option
1601 {
1602 time_t now = time(nullptr);
1603 dateandtimezoneepoch(startup_datetime_buf, now);
1604 jglb["local_time"] += { {"time_t", now}, {"asctime", startup_datetime_buf} };
1605 }
1606
1607 const char * name = argv[argc-1];
1608
1610 if (!strcmp(name,"-")) {
1611 // Parse "smartctl -r ataioctl,2 ..." output from stdin
1612 if (type || print_type_only) {
1613 pout("-d option is not allowed in conjunction with device name \"-\".\n");
1614 UsageSummary();
1615 return FAILCMD;
1616 }
1617 dev = get_parsed_ata_device(smi(), name);
1618 }
1619 else
1620 // get device of appropriate type
1621 dev = smi()->get_smart_device(name, type);
1622
1623 if (!dev) {
1624 jerr("%s: %s\n", name, smi()->get_errmsg());
1625 if (type)
1627 else
1628 pout("Please specify device type with the -d option.\n");
1629 UsageSummary();
1630 return FAILCMD;
1631 }
1632
1633 if (print_type_only)
1634 // Report result of first autodetection
1635 pout("%s: Device of type '%s' [%s] detected\n",
1636 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1637
1638 if (dev->is_ata() && ataopts.powermode>=2 && dev->is_powered_down()) {
1639 jinf("Device is in STANDBY (OS) mode, exit(%d)\n", ataopts.powerexit);
1640 return ataopts.powerexit;
1641 }
1642
1643 // Open device
1644 {
1645 // Save old info
1646 smart_device::device_info oldinfo = dev->get_info();
1647
1648 // Open with autodetect support, may return 'better' device
1649 dev.replace( dev->autodetect_open() );
1650
1651 // Report if type has changed
1652 if ( (ata_debugmode || scsi_debugmode || nvme_debugmode || print_type_only)
1653 && oldinfo.dev_type != dev->get_dev_type() )
1654 pout("%s: Device open changed type from '%s' to '%s'\n",
1655 dev->get_info_name(), oldinfo.dev_type.c_str(), dev->get_dev_type());
1656 }
1657 if (!dev->is_open()) {
1658 jerr("Smartctl open device: %s failed: %s\n", dev->get_info_name(), dev->get_errmsg());
1659 return FAILDEV;
1660 }
1661
1662 // Add JSON info similar to --scan output
1663 js_device_info(jglb["device"], dev.get());
1664
1665 // now call appropriate ATA or SCSI routine
1666 int retval = 0;
1667 if (print_type_only)
1668 jout("%s: Device of type '%s' [%s] opened\n",
1669 dev->get_info_name(), dev->get_dev_type(), get_protocol_info(dev.get()));
1670 else if (dev->is_ata())
1671 retval = ataPrintMain(dev->to_ata(), ataopts);
1672 else if (dev->is_scsi())
1673 retval = scsiPrintMain(dev->to_scsi(), scsiopts);
1674 else if (dev->is_nvme())
1675 retval = nvmePrintMain(dev->to_nvme(), nvmeopts);
1676 else
1677 // we should never fall into this branch!
1678 pout("%s: Neither ATA, SCSI nor NVMe device\n", dev->get_info_name());
1679
1680 dev->close();
1681 return retval;
1682}
1683
1684
1685// Main program
1686int main(int argc, char **argv)
1687{
1688 int status;
1689 bool badcode = false;
1690
1691 try {
1692 try {
1693 // Do the real work ...
1694 status = main_worker(argc, argv);
1695 }
1696 catch (int ex) {
1697 // Exit status from checksumwarning() and failuretest() arrives here
1698 status = ex;
1699 }
1700 // Print JSON if enabled
1702 jglb["smartctl"]["uint128_precision_bits"] = uint128_to_str_precision_bits();
1703 jglb["smartctl"]["exit_status"] = status;
1705 }
1706 catch (const std::bad_alloc & /*ex*/) {
1707 // Memory allocation failed (also thrown by std::operator new)
1708 printf("Smartctl: Out of memory\n");
1709 status = FAILCMD;
1710 }
1711 catch (const std::exception & ex) {
1712 // Other fatal errors
1713 printf("Smartctl: Exception: %s\n", ex.what());
1714 badcode = true;
1715 status = FAILCMD;
1716 }
1717
1718 // Check for remaining device objects
1719 if (smart_device::get_num_objects() != 0) {
1720 printf("Smartctl: Internal Error: %d device object(s) left at exit.\n",
1722 badcode = true;
1723 status = FAILCMD;
1724 }
1725
1726 if (badcode)
1727 printf("Please inform " PACKAGE_BUGREPORT ", including output of smartctl -V.\n");
1728
1729 return status;
1730}
1731
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:1456
static std::string getvalidarglist(int opt)
Definition: smartctl.cpp:228
void jout_startup_datetime(const char *prefix)
Definition: smartctl.cpp:1450
unsigned char failuretest_permissive
Definition: smartctl.cpp:1457
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:1686
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:1513
void checksumwarning(const char *string)
Definition: smartctl.cpp:1485
static const char * get_protocol_info(const smart_device *dev)
Definition: smartctl.cpp:1499
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:1462
static int main_worker(int argc, char **argv)
Definition: smartctl.cpp:1577
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:1325
static void Usage()
Definition: smartctl.cpp:113
bool printing_is_switchable
Definition: smartctl.cpp:49
const char * msg_severity
Definition: smartctl.cpp:1324
static void scan_devices(const smart_devtype_list &types, bool with_open, char **argv)
Definition: smartctl.cpp:1523
const char const char va_list ap
Definition: smartctl.cpp:1326
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