ataprint.cpp, ataprint.h, smartctl.cpp: Optionally exit immediately

if '-n POWERMODE' option is not supported (#1381).
smartctl.8.in: Document new STATUS2 Parameter for '-n POWERMODE'.

git-svn-id: http://svn.code.sf.net/p/smartmontools/code/trunk@5192 4ea69e1a-61f1-4043-bf83-b5c94c648137
pull/89/head
chrfranke 2 years ago
parent 0318e46d9f
commit 2535f754ee
  1. 6
      smartmontools/ChangeLog
  2. 13
      smartmontools/ataprint.cpp
  3. 1
      smartmontools/ataprint.h
  4. 16
      smartmontools/smartctl.8.in
  5. 14
      smartmontools/smartctl.cpp

@ -1,5 +1,11 @@
$Id$
2021-02-01 Christian Franke <franke@computer.org>
ataprint.cpp, ataprint.h, smartctl.cpp: Optionally exit immediately
if '-n POWERMODE' option is not supported (#1381).
smartctl.8.in: Document new STATUS2 Parameter for '-n POWERMODE'.
2021-01-27 Christian Franke <franke@computer.org>
json.cpp, json.h: Add support for nested braced-init-lists.

@ -3316,7 +3316,11 @@ int ataPrintMain (ata_device * device, const ata_print_options & options)
switch (powermode) {
case -1:
if (device->is_syscall_unsup()) {
pout("CHECK POWER MODE not implemented, ignoring -n option\n"); break;
if (options.powerexit_unsup >= 0) {
jinf("CHECK POWER MODE not implemented, exit(%d)\n", options.powerexit_unsup);
return options.powerexit_unsup;
}
jinf("CHECK POWER MODE not implemented, ignoring -n option\n"); break;
}
powername = "SLEEP"; powerlimit = 2;
break;
@ -3343,7 +3347,12 @@ int ataPrintMain (ata_device * device, const ata_print_options & options)
powername = "ACTIVE or IDLE"; break;
default:
pout("CHECK POWER MODE returned unknown value 0x%02x, ignoring -n option\n", powermode);
if (options.powerexit_unsup >= 0) {
jinf("CHECK POWER MODE returned unknown value 0x%02x, exit(%d)\n", powermode,
options.powerexit_unsup);
return options.powerexit_unsup;
}
jinf("CHECK POWER MODE returned unknown value 0x%02x, ignoring -n option\n", powermode);
break;
}
if (powername) {

@ -79,6 +79,7 @@ struct ata_print_options
bool show_presets = false; // Show presets and exit
unsigned char powermode = 0; // Skip check, if disk in idle or standby mode
unsigned char powerexit = 0; // exit() code for low power mode
int powerexit_unsup = -1; // exit() code for unsupported power mode or -1 to ignore
bool get_set_used = false; // true if any get/set command is used
bool get_aam = false; // print Automatic Acoustic Management status

@ -829,7 +829,7 @@ Then \fBsmartctl\fP internally simulates an ATA device with the same
behaviour.
This is does not work for SCSI devices yet.
.TP
.B \-n POWERMODE[,STATUS], \-\-nocheck=POWERMODE[,STATUS]
.B \-n POWERMODE[,STATUS[,STATUS2]], \-\-nocheck=POWERMODE[,STATUS[,STATUS2]]
[ATA]
[SCSI: NEW EXPERIMENTAL SMARTCTL FEATURE]
Specifies if \fBsmartctl\fP should exit before performing any
@ -857,19 +857,27 @@ The valid arguments to this option are:
\- check the device always, but print the power mode if \*(Aq\-i\*(Aq is
specified.
.Sp
.I sleep[,STATUS]
.I sleep[,STATUS[,STATUS2]]
\- check the device unless it is in SLEEP mode.
.Sp
.I standby[,STATUS]
.I standby[,STATUS[,STATUS2]]
\- check the device unless it is in SLEEP or STANDBY mode. In
these modes most disks are not spinning, so if you want to prevent
a disk from spinning up, this is probably what you want.
.Sp
.I idle[,STATUS]
.I idle[,STATUS[,STATUS2]]
\- check the device unless it is in SLEEP, STANDBY or IDLE mode.
In the IDLE state, most disks are still spinning, so this is probably
not what you want.
.Sp
The \*(Aq\-n\*(Aq option is ignored if the power mode check is not supported
or returns an unknown value.
.br
[ATA only][NEW EXPERIMENTAL SMARTCTL FEATURE]
If the optional STATUS2 parameter is specified, \fBsmartctl\fP exits
immediately with STATUS2 in this case.
For example use \*(Aq\-n standby,3,5\*(Aq to return unique exit statuses in
the STANDBY and UNSUPPORTED cases.
.TP
.B SMART FEATURE ENABLE/DISABLE COMMANDS:
.IP

@ -145,7 +145,7 @@ static void Usage()
" Set action on bad checksum to one of: warn, exit, ignore\n\n"
" -r TYPE, --report=TYPE\n"
" Report transactions (see man page)\n\n"
" -n MODE[,STATUS], --nocheck=MODE[,STATUS] (ATA, SCSI)\n"
" -n MODE[,STATUS[,STATUS2]], --nocheck=MODE[,STATUS[,STATUS2]] (ATA, SCSI)\n"
" No check if: never, sleep, standby, idle (see man page)\n\n",
getvalidarglist('d').c_str()); // TODO: Use this function also for other options ?
pout(
@ -254,7 +254,8 @@ static std::string getvalidarglist(int opt)
case 'F':
return std::string(get_valid_firmwarebug_args()) + ", swapid";
case 'n':
return "never, sleep[,STATUS], standby[,STATUS], idle[,STATUS]";
return "never, sleep[,STATUS[,STATUS2]], standby[,STATUS[,STATUS2]], "
"idle[,STATUS[,STATUS2]]";
case 'f':
return "old, brief, hex[,id|val]";
case 'g':
@ -868,10 +869,10 @@ static int parse_options(int argc, char** argv, const char * & type,
scsiopts.powermode = 1;
}
else {
int n1 = -1, n2 = -1, len = strlen(optarg);
char s[7+1]; unsigned i = FAILPOWER;
sscanf(optarg, "%9[a-z]%n,%u%n", s, &n1, &i, &n2);
if (!((n1 == len || n2 == len) && i <= 255))
int n1 = -1, n2 = -1, n3 = -1, len = strlen(optarg);
char s[7+1]; unsigned i = FAILPOWER, j = 0;
sscanf(optarg, "%9[a-z]%n,%u%n,%u%n", s, &n1, &i, &n2, &j, &n3);
if (!((n1 == len || n2 == len || n3 == len) && i <= 255 && j <= 255))
badarg = true;
else if (!strcmp(s, "sleep")) {
ataopts.powermode = 2;
@ -886,6 +887,7 @@ static int parse_options(int argc, char** argv, const char * & type,
badarg = true;
ataopts.powerexit = i;
ataopts.powerexit_unsup = (n3 == len ? j : -1);
scsiopts.powerexit = i;
}
break;

Loading…
Cancel
Save