Ticket #832: 0001-Enable-Disable-the-certain-device-features-by-specif.patch

File 0001-Enable-Disable-the-certain-device-features-by-specif.patch, 6.6 KB (added by JonghwanChoi, 7 years ago)
  • ataprint.cpp

    From 0469a4b4e7f384b3b72e1fc47839959804b2406f Mon Sep 17 00:00:00 2001
    From: Jonwhan Choi <jhbird.choi@gmail.com>
    Date: Tue, 21 Mar 2017 02:29:37 +0900
    Subject: [PATCH] Enable/Disable the certain device features by specifying
     feature value and sector count value.
    
    Signed-off-by: Jonwhan Choi <jhbird.choi@gmail.com>
    ---
     ataprint.cpp  | 12 +++++++++++-
     ataprint.h    |  5 ++++-
     smartctl.8.in |  5 +++++
     smartctl.cpp  | 34 +++++++++++++++++++++++++++-------
     4 files changed, 47 insertions(+), 9 deletions(-)
    
    diff --git a/ataprint.cpp b/ataprint.cpp
    index 8b27de4..28e6c02 100644
    a b int ataPrintMain (ata_device * device, const ata_print_options & options)  
    28982898  if (   options.smart_disable           || options.smart_enable
    28992899      || options.smart_auto_save_disable || options.smart_auto_save_enable
    29002900      || options.smart_auto_offl_disable || options.smart_auto_offl_enable
    2901       || options.set_aam || options.set_apm || options.set_lookahead
     2901      || options.set_aam || options.set_apm || options.set_features || options.set_lookahead
    29022902      || options.set_wcache || options.set_security_freeze || options.set_standby
    29032903      || options.sct_wcache_reorder_set || options.sct_wcache_sct_set || options.set_dsn)
    29042904    pout("=== START OF ENABLE/DISABLE COMMANDS SECTION ===\n");
    int ataPrintMain (ata_device * device, const ata_print_options & options)  
    29762976      pout("DSN %sabled\n", (enable ? "en" : "dis"));
    29772977  }
    29782978
     2979  // Enable/Disable Features
     2980  if (options.set_features) {
     2981    if (!ata_set_features(device, options.set_features_feature, options.set_features_scount)) {
     2982        pout("Features[0x%x] Sector Count[0x%x] failed: %s\n", options.set_features_feature, options.set_features_scount, device->get_errmsg());
     2983        returnval |= FAILSMART;
     2984    }
     2985    else
     2986      pout("Features[0x%x] Sector Count[0x%x]\n", options.set_features_feature, options.set_features_scount);
     2987  }
     2988
    29792989  // Enable/Disable write cache reordering
    29802990  if (options.sct_wcache_reorder_set) {
    29812991    bool enable = (options.sct_wcache_reorder_set > 0);
  • ataprint.h

    diff --git a/ataprint.h b/ataprint.h
    index b8ccf1f..7722613 100644
    a b struct ata_print_options  
    115115  bool sct_wcache_sct_set_pers; // persistent or volatile
    116116  bool get_dsn; // print DSN status
    117117  int set_dsn; // disable(02h), enable(01h) DSN
     118  int set_features; // Enable/Disable the SET FEATRUE command
     119  int set_features_feature; // feature value for the SET FEATURE command
     120  int set_features_scount; // sector count value for the SET FEATURE command
    118121
    119122  ata_print_options()
    120123    : drive_info(false),
    struct ata_print_options  
    156159      sct_wcache_reorder_set_pers(false),
    157160      sct_wcache_sct_get(false), sct_wcache_sct_set(0),
    158161      sct_wcache_sct_set_pers(false),
    159       get_dsn(false), set_dsn(0)
     162      get_dsn(false), set_dsn(0), set_features(0)
    160163    { }
    161164};
    162165
  • smartctl.8.in

    diff --git a/smartctl.8.in b/smartctl.8.in
    index 103fb71..4f755bb 100644
    a b The read cache is usually enabled by default.  
    10121012Gets/sets the DSN feature (if supported).
    10131013The dsn is usually disabled by default.
    10141014
     1015.I features,0xFEATURE[,0xCOUNT]
     1016\- [ATA only]
     1017Enable or disable the certain device features by specifying feature value
     1018and sector count value. Use with care.
     1019
    10151020.TP
    10161021.B SMART READ AND DISPLAY DATA OPTIONS:
    10171022.TP
  • smartctl.cpp

    diff --git a/smartctl.cpp b/smartctl.cpp
    index 5f663b5..988d1c0 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, dsn, lookahead, security, wcache, rcache, wcreorder, wcache-sct\n\n"
     90"        Get device setting: all, aam, apm, dsn, features, 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 "        dsn,[on|off], lookahead,[on|off], security-freeze, standby,[N|off|now],\n"
     125"        dsn,[on|off], features,0xFEATURE[,0xCOUNT], lookahead,[on|off], \n"
     126"        security-freeze, standby,[N|off|now],\n"
    126127"        wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]]\n"
    127128"        wcache-sct,[ata|on|off[,p]]\n\n"
    128129  );
    static std::string getvalidarglist(int opt)  
    226227  case 'g':
    227228    return "aam, apm, dsn, lookahead, security, wcache, rcache, wcreorder, wcache-sct";
    228229  case opt_set:
    229     return "aam,[N|off], apm,[N|off], dsn,[on|off], lookahead,[on|off], security-freeze, "
    230            "standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]], "
     230    return "aam,[N|off], apm,[N|off], dsn,[on|off], features,0xFEATURE[,0xCOUNT], lookahead,[on|off], "
     231           "security-freeze, standby,[N|off|now], wcache,[on|off], rcache,[on|off], wcreorder,[on|off[,p]], "
    231232           "wcache-sct,[ata|on|off[,p]]";
    232233  case 's':
    233234    return getvalidarglist(opt_smart)+", "+getvalidarglist(opt_set);
    static const char * parse_options(int argc, char** argv,  
    888889                  strcmp(name, "wcreorder") != 0)
    889890                badarg = true;
    890891            }
    891             on  = !strncmp(optarg+n2, "on", len2);
    892             off = !strncmp(optarg+n2, "off", len2);
    893             ata = !strncmp(optarg+n2, "ata", len2);
     892
     893            if (!strcmp(name, "features")) {
     894              int feature, scount;
     895              if (sscanf(optarg + n2, "%x,%x", &feature, &scount) == 2) {
     896                if ((feature < 0 || feature > 0xff) ||
     897                    (scount < 0 || scount > 0xff)) {
     898                  badarg = true;
     899                } else {
     900                   ataopts.set_features_feature = feature;
     901                   ataopts.set_features_scount = scount;
     902                }
     903              } else {
     904                badarg = true;
     905              }
     906            } else {
     907              on  = !strncmp(optarg+n2, "on", len2);
     908              off = !strncmp(optarg+n2, "off", len2);
     909              ata = !strncmp(optarg+n2, "ata", len2);
     910            }
    894911          }
    895912          if (n3 != len)
    896913            val = ~0U;
    static const char * parse_options(int argc, char** argv,  
    10211038            else
    10221039              badarg = true;
    10231040          }
     1041          else if (!strcmp(name, "features")) {
     1042              ataopts.set_features = 1;
     1043          }
    10241044          else
    10251045            badarg = true;
    10261046        }