Support the case of device not in smartctl database

This commit is contained in:
Andrea Mazzoleni 2015-01-29 22:52:17 +01:00
parent a02ea3da76
commit cd1186e434
4 changed files with 4 additions and 17 deletions

View file

@ -395,8 +395,8 @@ static void state_smart(int verbose, unsigned n, tommy_list* low)
printf("%8" PRIu64, devinfo->smart[SMART_ERROR]);
else if (flag & (SMARTCTL_FLAG_ERROR | SMARTCTL_FLAG_ERROR_LOGGED))
printf(" ERROR");
else if (flag & (SMARTCTL_FLAG_OPEN | SMARTCTL_FLAG_COMMAND))
printf(" n/a");
else if (flag & (SMARTCTL_FLAG_UNSUPPORTED | SMARTCTL_FLAG_OPEN | SMARTCTL_FLAG_COMMAND))
printf(" -");
else if (devinfo->smart[SMART_ERROR] == 0)
printf(" 0");
else
@ -406,7 +406,7 @@ static void state_smart(int verbose, unsigned n, tommy_list* low)
if (flag & (SMARTCTL_FLAG_FAIL | SMARTCTL_FLAG_PREFAIL | SMARTCTL_FLAG_PREFAIL_LOGGED))
make_it_fail = 1;
if (flag & (SMARTCTL_FLAG_OPEN | SMARTCTL_FLAG_COMMAND)) {
if (flag & (SMARTCTL_FLAG_UNSUPPORTED | SMARTCTL_FLAG_OPEN | SMARTCTL_FLAG_COMMAND)) {
/* if error running smartctl, skip AFR estimation */
afr = 0;
printf(" -");

View file

@ -1849,13 +1849,6 @@ static int devsmart(const char* file, uint64_t* smart, char* serial)
return -1;
/* LCOV_EXCL_STOP */
}
/* check only first bit, as other bits are used to report other conditions */
if ((ret & 1) != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctl -a on device '%s' with return code %xh.\n", file, ret);
return -1;
/* LCOV_EXCL_STOP */
}
/* store the return smartctl return value */
smart[SMART_FLAGS] = ret;

View file

@ -328,6 +328,7 @@ int randomize(void* ptr, size_t size);
/**
* Flags returned by smartctl.
*/
#define SMARTCTL_FLAG_UNSUPPORTED (1 << 0) /**< Device not recognized, requiring the -d option. */
#define SMARTCTL_FLAG_OPEN (1 << 1) /**< Device open failed. */
#define SMARTCTL_FLAG_COMMAND (1 << 2) /**< Some SMART or other ATA command to the disk failed. */
#define SMARTCTL_FLAG_FAIL (1 << 3) /**< SMART status check returned "DISK FAILING". */

View file

@ -655,13 +655,6 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
return -1;
/* LCOV_EXCL_STOP */
}
/* check only first bit, as other bits are used to report other conditions */
if ((WEXITSTATUS(ret) & 1) != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctl -a on device '%u:%u' with return code %xh.\n", major(device), minor(device), WEXITSTATUS(ret));
return -1;
/* LCOV_EXCL_STOP */
}
/* store the return smartctl return value */
smart[SMART_FLAGS] = WEXITSTATUS(ret);