]> git.proxmox.com Git - mirror_smartmontools-debian.git/blobdiff - smartctl.cpp
Change second dh_systemd_enable to _start
[mirror_smartmontools-debian.git] / smartctl.cpp
index 190f9f3af6ded2e07b89ab0066e8b5746cd4404e..e2116398153bf3eca0e6239fbf70987c1b53eaac 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * smartctl.cpp
  *
- * Home page of code is: http://smartmontools.sourceforge.net
+ * Home page of code is: http://www.smartmontools.org
  *
- * Copyright (C) 2002-11 Bruce Allen <smartmontools-support@lists.sourceforge.net>
- * Copyright (C) 2008-12 Christian Franke <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2002-11 Bruce Allen
+ * Copyright (C) 2008-15 Christian Franke
  * Copyright (C) 2000 Michael Cornwell <cornwell@acm.org>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <string.h>
+#include <stdlib.h>
 #include <stdarg.h>
 #include <stdexcept>
 #include <getopt.h>
@@ -50,7 +51,7 @@
 #include "smartctl.h"
 #include "utility.h"
 
-const char * smartctl_cpp_cvsid = "$Id: smartctl.cpp 3726 2012-12-12 20:02:48Z chrfranke $"
+const char * smartctl_cpp_cvsid = "$Id: smartctl.cpp 4162 2015-10-31 16:36:16Z chrfranke $"
   CONFIG_H_CVSID SMARTCTL_H_CVSID;
 
 // Globals to control printing
@@ -85,7 +86,7 @@ static void Usage()
 "  --identify[=[w][nvb]]\n"
 "         Show words and bits from IDENTIFY DEVICE data                (ATA)\n\n"
 "  -g NAME, --get=NAME\n"
-"        Get device setting: all, aam, apm, lookahead, security, wcache, rcache\n\n"
+"        Get device setting: all, aam, apm, lookahead, security, wcache, rcache, wcreorder\n\n"
 "  -a, --all\n"
 "         Show all SMART information for device\n\n"
 "  -x, --xall\n"
@@ -121,7 +122,7 @@ static void Usage()
 "  -s NAME[,VALUE], --set=NAME[,VALUE]\n"
 "        Enable/disable/change device setting: aam,[N|off], apm,[N|off],\n"
 "        lookahead,[on|off], security-freeze, standby,[N|off|now],\n"
-"        wcache,[on|off], rcache,[on|off]\n\n"
+"        wcache,[on|off], rcache,[on|off], wcreorder,[on|off]\n\n"
   );
   printf(
 "======================================= READ AND DISPLAY DATA OPTIONS =====\n\n"
@@ -218,10 +219,10 @@ static std::string getvalidarglist(int opt)
   case 'f':
     return "old, brief, hex[,id|val]";
   case 'g':
-    return "aam, apm, lookahead, security, wcache, rcache";
+    return "aam, apm, lookahead, security, wcache, rcache, wcreorder";
   case opt_set:
     return "aam,[N|off], apm,[N|off], lookahead,[on|off], security-freeze, "
-           "standby,[N|off|now], wcache,[on|off], rcache,[on|off]";
+           "standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off]";
   case 's':
     return getvalidarglist(opt_smart)+", "+getvalidarglist(opt_set);
   case opt_identify:
@@ -312,7 +313,7 @@ static const char * parse_options(int argc, char** argv,
   opterr=optopt=0;
 
   const char * type = 0; // set to -d optarg
-  bool no_defaultdb = false; // set true on '-B FILE'
+  bool use_default_db = true; // set false on '-B FILE'
   bool output_format_set = false; // set true on '-f FORMAT'
   int scan = 0; // set by --scan, --scan-open
   bool badarg = false, captive = false;
@@ -502,10 +503,14 @@ static const char * parse_options(int argc, char** argv,
         sscanf(optarg, "devstat%n,%u%n", &n1, &val, &n2);
         if (n1 == len)
           ataopts.devstat_all_pages = true;
-        else if (n2 == len && val <= 255)
-          ataopts.devstat_pages.push_back(val);
-        else
-          badarg = true;
+        else {
+            if (n2 != len) // retry with hex
+              sscanf(optarg, "devstat,0x%x%n", &val, &n2);
+            if (n2 == len && val <= 0xff)
+              ataopts.devstat_pages.push_back(val);
+            else
+              badarg = true;
+        }
 
       } else if (!strncmp(optarg, "xerror", sizeof("xerror")-1)) {
         int n1 = -1, n2 = -1, len = strlen(optarg);
@@ -626,6 +631,7 @@ static const char * parse_options(int argc, char** argv,
       ataopts.smart_logdir = ataopts.gp_logdir = true;
       ataopts.sct_temp_sts = ataopts.sct_temp_hist = true;
       ataopts.sct_erc_get = true;
+      ataopts.sct_wcache_reorder_get = true;
       ataopts.devstat_all_pages = true;
       ataopts.sataphy = true;
       ataopts.get_set_used = true;
@@ -659,7 +665,7 @@ static const char * parse_options(int argc, char** argv,
       } else if (!strcmp(optarg, "show")) {
         ataopts.show_presets = true;
       } else if (!strcmp(optarg, "showall")) {
-        if (!no_defaultdb && !read_default_drive_databases())
+        if (!init_drive_database(use_default_db))
           EXIT(FAILCMD);
         if (optind < argc) { // -P showall MODEL [FIRMWARE]
           int cnt = showmatchingpresets(argv[optind], (optind+1<argc ? argv[optind+1] : NULL));
@@ -723,7 +729,7 @@ static const char * parse_options(int argc, char** argv,
         } else {
           if (ataopts.smart_selective_args.num_spans >= 5 || start > stop) {
             if (start > stop) {
-              snprintf(extraerror, sizeof(extraerror), "ERROR: Start LBA (%"PRIu64") > ending LBA (%"PRId64") in argument \"%s\"\n",
+              snprintf(extraerror, sizeof(extraerror), "ERROR: Start LBA (%" PRIu64 ") > ending LBA (%" PRId64 ") in argument \"%s\"\n",
                 start, stop, optarg);
             } else {
               snprintf(extraerror, sizeof(extraerror),"ERROR: No more than five selective self-test spans may be"
@@ -799,7 +805,7 @@ static const char * parse_options(int argc, char** argv,
         if (*path == '+' && path[1])
           path++;
         else
-          no_defaultdb = true;
+          use_default_db = false;
         if (!read_drive_database(path))
           EXIT(FAILCMD);
       }
@@ -867,6 +873,17 @@ static const char * parse_options(int argc, char** argv,
             else
               badarg = true;
           }
+          else if (!strcmp(name, "wcreorder")) {
+            if (get) {
+              ataopts.sct_wcache_reorder_get = true;
+            }
+            else if (off)
+              ataopts.sct_wcache_reorder_set = -1;
+            else if (on)
+              ataopts.sct_wcache_reorder_set = 1;
+            else
+              badarg = true;
+          }
           else if (!strcmp(name, "rcache")) {
             if (get)
               scsiopts.get_rcd = true;
@@ -984,7 +1001,7 @@ static const char * parse_options(int argc, char** argv,
   // Special handling of --scan, --scanopen
   if (scan) {
     // Read or init drive database to allow USB ID check.
-    if (!no_defaultdb && !read_default_drive_databases())
+    if (!init_drive_database(use_default_db))
       EXIT(FAILCMD);
     scan_devices(type, (scan == opt_scan_open), argv + optind);
     EXIT(0);
@@ -1062,7 +1079,7 @@ static const char * parse_options(int argc, char** argv,
   }
 
   // Read or init drive database
-  if (!no_defaultdb && !read_default_drive_databases())
+  if (!init_drive_database(use_default_db))
     EXIT(FAILCMD);
 
   return type;
@@ -1200,8 +1217,8 @@ void scan_devices(const char * type, bool with_open, char ** argv)
 // Main program without exception handling
 static int main_worker(int argc, char **argv)
 {
-  // Throw if CPU endianess does not match compile time test.
-  check_endianness();
+  // Throw if runtime environment does not match compile time test.
+  check_config();
 
   // Initialize interface
   smart_interface::init();