Ticket #815: 0001-smartcl-Add-options-g-s-dsn-to-get-set-DSN-feature.patch

File 0001-smartcl-Add-options-g-s-dsn-to-get-set-DSN-feature.patch, 9.9 KB (added by JonghwanChoi, 7 years ago)
  • atacmds.h

    From 8b1a0b1320cf178ce09dc90aa4b1c07b82d2d4a3 Mon Sep 17 00:00:00 2001
    From: Jonghwan Choi <jhbird.choi@gmail.com>
    Date: Tue, 7 Mar 2017 14:31:02 +0900
    Subject: [PATCH] smartcl: Add options '-g/s dsn' to get/set DSN feature
    
    Signed-off-by: Jonghwan Choi <jhbird.choi@gmail.com>
    ---
     atacmds.h    |  1 +
     ataprint.cpp | 27 +++++++++++++++++++++++++--
     ataprint.h   |  5 ++++-
     smartctl.cpp | 23 ++++++++++++++++++-----
     smartd.cpp   | 21 +++++++++++++++++----
     5 files changed, 65 insertions(+), 12 deletions(-)
    
    diff --git a/atacmds.h b/atacmds.h
    index 7a32676..23b62cf 100644
    a b typedef enum {  
    8888#define ATA_ENABLE_APM                  0x05
    8989#define ATA_ENABLE_WRITE_CACHE          0x02
    9090#define ATA_ENABLE_READ_LOOK_AHEAD      0xaa
     91#define ATA_ENABLE_DISABLE_DSN          0x63
    9192
    9293// 48-bit commands
    9394#define ATA_READ_LOG_EXT                0x2F
  • ataprint.cpp

    diff --git a/ataprint.cpp b/ataprint.cpp
    index 9e9cbbb..daebc93 100644
    a b int ataPrintMain (ata_device * device, const ata_print_options & options)  
    27952795       !(drive.cfs_enable_1 & 0x0020) ? "Disabled" : "Enabled"); // word085
    27962796  }
    27972797
     2798  // Print DSN status
     2799  unsigned short word120 = drive.words088_255[120-88];
     2800  if (options.get_dsn) {
     2801    if (!(drive.word086 & 0x8000) // word086
     2802       || ((word120 & 0xc000) != 0x4000)) // word120
     2803      pout("DSN feature is:   Unavailable\n");
     2804    else if (word120 & 0x200) // word120
     2805      pout("DSN feature is:   Enabled\n");
     2806    else
     2807      pout("DSN feature is:   Disabled\n");
     2808  }
     2809
    27982810  // Check for ATA Security LOCK
    27992811  unsigned short word128 = drive.words088_255[128-88];
    28002812  bool locked = ((word128 & 0x0007) == 0x0007); // LOCKED|ENABLED|SUPPORTED
    int ataPrintMain (ata_device * device, const ata_print_options & options)  
    28662878      || options.smart_auto_offl_disable || options.smart_auto_offl_enable
    28672879      || options.set_aam || options.set_apm || options.set_lookahead
    28682880      || options.set_wcache || options.set_security_freeze || options.set_standby
    2869       || options.sct_wcache_reorder_set || options.sct_wcache_sct_set)
     2881      || options.sct_wcache_reorder_set || options.sct_wcache_sct_set || options.set_dsn)
    28702882    pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
    28712883 
    28722884  // Enable/Disable AAM
    int ataPrintMain (ata_device * device, const ata_print_options & options)  
    29312943      pout("Write cache %sabled\n", (enable ? "en" : "dis"));
    29322944  }
    29332945
     2946  // Enable/Disable DSN
     2947  if (options.set_dsn) {
     2948    bool enable = (options.set_dsn > 0);
     2949    if (!ata_set_features(device, ATA_ENABLE_DISABLE_DSN, (enable ? 0x1 : 0x2))) {
     2950        pout("DSN %sable failed: %s\n", (enable ? "en" : "dis"), device->get_errmsg());
     2951        returnval |= FAILSMART;
     2952    }
     2953    else
     2954      pout("DSN %sabled\n", (enable ? "en" : "dis"));
     2955  }
     2956
    29342957  // Enable/Disable write cache reordering
    29352958  if (options.sct_wcache_reorder_set) {
    29362959    bool enable = (options.sct_wcache_reorder_set > 0);
    int ataPrintMain (ata_device * device, const ata_print_options & options)  
    31003123      || options.smart_auto_offl_disable || options.smart_auto_offl_enable
    31013124      || options.set_aam || options.set_apm || options.set_lookahead
    31023125      || options.set_wcache || options.set_security_freeze || options.set_standby
    3103       || options.sct_wcache_reorder_set)
     3126      || options.sct_wcache_reorder_set || options.set_dsn)
    31043127    pout("\n");
    31053128
    31063129  // START OF READ-ONLY OPTIONS APART FROM -V and -i
  • ataprint.h

    diff --git a/ataprint.h b/ataprint.h
    index 1da201c..b8ccf1f 100644
    a b struct ata_print_options  
    113113  bool sct_wcache_sct_get; // print SCT Feature Control of write cache status
    114114  int sct_wcache_sct_set; // determined by ata set features command(1), force enable(2), force disable(3)
    115115  bool sct_wcache_sct_set_pers; // persistent or volatile
     116  bool get_dsn; // print DSN status
     117  int set_dsn; // disable(02h), enable(01h) DSN
    116118
    117119  ata_print_options()
    118120    : drive_info(false),
    struct ata_print_options  
    153155      sct_wcache_reorder_get(false), sct_wcache_reorder_set(0),
    154156      sct_wcache_reorder_set_pers(false),
    155157      sct_wcache_sct_get(false), sct_wcache_sct_set(0),
    156       sct_wcache_sct_set_pers(false)
     158      sct_wcache_sct_set_pers(false),
     159      get_dsn(false), set_dsn(0)
    157160    { }
    158161};
    159162
  • smartctl.cpp

    diff --git a/smartctl.cpp b/smartctl.cpp
    index 233220a..d05b2b3 100644
    a b static void Usage()  
    8787"  --identify[=[w][nvb]]\n"
    8888"         Show words and bits from IDENTIFY DEVICE data                (ATA)\n\n"
    8989"  -g NAME, --get=NAME\n"
    90 "        Get device setting: all, aam, apm, lookahead, security, wcache, rcache, wcreorder, wcache-sct\n\n"
     90"        Get device setting: all, aam, apm, dsn, lookahead, security, wcache, rcache, wcreorder, wcache-sct\n\n"
    9191"  -a, --all\n"
    9292"         Show all SMART information for device\n\n"
    9393"  -x, --xall\n"
    static void Usage()  
    122122"        Enable/disable Attribute autosave on device (on/off)\n\n"
    123123"  -s NAME[,VALUE], --set=NAME[,VALUE]\n"
    124124"        Enable/disable/change device setting: aam,[N|off], apm,[N|off],\n"
    125 "        lookahead,[on|off], security-freeze, standby,[N|off|now],\n"
     125"        dsn,[on|off], lookahead,[on|off], security-freeze, standby,[N|off|now],\n"
    126126"        wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]]\n"
    127127"        wcache-sct,[ata|on|off[,p]]\n\n"
    128128  );
    static std::string getvalidarglist(int opt)  
    224224  case 'f':
    225225    return "old, brief, hex[,id|val]";
    226226  case 'g':
    227     return "aam, apm, lookahead, security, wcache, rcache, wcreorder, wcache-sct";
     227    return "aam, apm, dsn, lookahead, security, wcache, rcache, wcreorder, wcache-sct";
    228228  case opt_set:
    229     return "aam,[N|off], apm,[N|off], lookahead,[on|off], security-freeze, "
     229    return "aam,[N|off], apm,[N|off], dsn,[on|off], lookahead,[on|off], security-freeze, "
    230230           "standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]], "
    231231           "wcache-sct,[ata|on|off[,p]]";
    232232  case 's':
    static const char * parse_options(int argc, char** argv,  
    897897          if (get && !strcmp(name, "all")) {
    898898            ataopts.get_aam = ataopts.get_apm = true;
    899899            ataopts.get_security = true;
    900             ataopts.get_lookahead = ataopts.get_wcache = true;
     900            ataopts.get_lookahead = ataopts.get_wcache = ataopts.get_dsn = true;
    901901            scsiopts.get_rcd = scsiopts.get_wce = true;
    902902          }
    903903          else if (!strcmp(name, "aam")) {
    static const char * parse_options(int argc, char** argv,  
    10061006            else
    10071007              badarg = true;
    10081008          }
     1009          else if (!strcmp(name, "dsn")) {
     1010            if (get) {
     1011              ataopts.get_dsn = true;
     1012            }
     1013            else if (off) {
     1014              ataopts.set_dsn = -1;
     1015            }
     1016            else if (on) {
     1017              ataopts.set_dsn = 1;
     1018            }
     1019            else
     1020              badarg = true;
     1021          }
    10091022          else
    10101023            badarg = true;
    10111024        }
  • smartd.cpp

    diff --git a/smartd.cpp b/smartd.cpp
    index 8385cde..04dabdc 100644
    a b struct dev_config  
    281281  int set_standby; // set(1..255->0..254) standby timer
    282282  bool set_security_freeze; // Freeze ATA security
    283283  int set_wcache; // disable(-1), enable(1) write cache
     284  int set_dsn; // disable(0x2), enable(0x1) DSN
    284285
    285286  bool sct_erc_set;                       // set SCT ERC to:
    286287  unsigned short sct_erc_readtime;        // ERC read time (deciseconds)
    dev_config::dev_config()  
    328329  set_lookahead(0),
    329330  set_standby(0),
    330331  set_security_freeze(false),
    331   set_wcache(0),
     332  set_wcache(0), set_dsn(0),
    332333  sct_erc_set(false),
    333334  sct_erc_readtime(0), sct_erc_writetime(0),
    334335  curr_pending_id(0), offl_pending_id(0),
    static void Directives()  
    14381439           "  -l TYPE Monitor SMART log or self-test status:\n"
    14391440           "          error, selftest, xerror, offlinests[,ns], selfteststs[,ns]\n"
    14401441           "  -l scterc,R,W  Set SCT Error Recovery Control\n"
    1441            "  -e      Change device setting: aam,[N|off], apm,[N|off], lookahead,[on|off],\n"
    1442            "          security-freeze, standby,[N|off], wcache,[on|off]\n"
     1442           "  -e      Change device setting: aam,[N|off], apm,[N|off], dsn,[on|off],\n"
     1443           "          lookahead,[on|off], security-freeze, standby,[N|off], wcache,[on|off]\n"
    14431444           "  -f      Monitor 'Usage' Attributes, report failures\n"
    14441445           "  -m ADD  Send email warning to address ADD\n"
    14451446           "  -M TYPE Modify email warning behavior (see man page)\n"
    static int ATADeviceScan(dev_config & cfg, dev_state & state, ata_device * atade  
    21142115    format_set_result_msg(msg, "Wr-cache", ata_set_features(atadev,
    21152116      (cfg.set_wcache > 0? ATA_ENABLE_WRITE_CACHE : ATA_DISABLE_WRITE_CACHE)), cfg.set_wcache);
    21162117
     2118  if (cfg.set_dsn)
     2119    format_set_result_msg(msg, "DSN", ata_set_features(atadev,
     2120      ATA_ENABLE_DISABLE_DSN, (cfg.set_dsn > 0 ? 0x1 : 0x2)));
     2121
    21172122  if (cfg.set_security_freeze)
    21182123    format_set_result_msg(msg, "Security freeze",
    21192124      ata_nodata_command(atadev, ATA_SECURITY_FREEZE_LOCK));
    static void printoutvaliddirectiveargs(int priority, char d)  
    38433848    PrintOut(priority, "%s", get_valid_firmwarebug_args());
    38443849    break;
    38453850  case 'e':
    3846     PrintOut(priority, "aam,[N|off], apm,[N|off], lookahead,[on|off], "
     3851    PrintOut(priority, "aam,[N|off], apm,[N|off], lookahead,[on|off], dsn,[on|off] "
    38473852                       "security-freeze, standby,[N|off], wcache,[on|off]");
    38483853    break;
    38493854  }
    static int ParseToken(char * token, dev_config & cfg, smart_devtype_list & scan_  
    43654370          else
    43664371            badarg = true;
    43674372        }
     4373        else if (!strcmp(arg2, "dsn")) {
     4374          if (off)
     4375            cfg.set_dsn = -1;
     4376          else if (on)
     4377            cfg.set_dsn = 1;
     4378          else
     4379            badarg = true;
     4380        }
    43684381        else
    43694382          badarg = true;
    43704383      }