diff -u libatasmart-0.17/debian/patches/series libatasmart-0.17/debian/patches/series --- libatasmart-0.17/debian/patches/series +++ libatasmart-0.17/debian/patches/series @@ -3,0 +4,3 @@ +02-fix-return-value.patch +03-improve-granularity-of-errors.patch +04-strip-off-unlucky-heuristic-code.patch only in patch2: unchanged: --- libatasmart-0.17.orig/debian/patches/03-improve-granularity-of-errors.patch +++ libatasmart-0.17/debian/patches/03-improve-granularity-of-errors.patch @@ -0,0 +1,166 @@ +Subject: Improve granularity of errors with a "caution" flag. +Author: Roberto Mariani + + - Added caution flag to struct SkSmartAttributeParsedData. + This permits to have also a caution flag for minimal or supposed + problems, without boring with an excessive warning. + - Implements use of caution flag in skdump, for coloring the different errors + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/lucid/+source/libatasmart/+bug/438136 +Index: libatasmart-0.17/atasmart.c +=================================================================== +--- libatasmart-0.17.orig/atasmart.c 2009-12-14 13:04:10.345788920 +0100 ++++ libatasmart-0.17/atasmart.c 2009-12-14 13:36:36.233791003 +0100 +@@ -1275,10 +1275,8 @@ + a->pretty_value = SK_SMART_ATTRIBUTE_UNIT_UNKNOWN; + d->attribute_verification_bad = TRUE; + } else { +- if ((!strcmp(a->name, "reallocated-sector-count") || +- !strcmp(a->name, "current-pending-sector")) && +- a->pretty_value > 0) +- a->warn = TRUE; ++ if (a->pretty_value > 0) ++ a->caution = TRUE; + } + } + +@@ -1855,6 +1853,7 @@ + a.flags = ((uint16_t) p[2] << 8) | p[1]; + a.prefailure = !!(p[1] & 1); + a.online = !!(p[1] & 2); ++ a.caution = FALSE; + + memcpy(a.raw, p+5, 6); + +@@ -2251,14 +2250,38 @@ + return s; + } + +-#define HIGHLIGHT "\x1B[1m" +-#define ENDHIGHLIGHT "\x1B[0m" ++typedef enum SkColors { ++ SK_COLOR_BRIGHT_RED, ++ SK_COLOR_RED, ++ SK_COLOR_YELLOW, ++ SK_COLOR_END, ++ _SK_COLOR_MAX ++} SkColors; ++ ++static const char* highlight(SkColors color) { ++ ++ /* %STRINGPOOLSTART% */ ++ const char * const map[] = { ++ [SK_COLOR_BRIGHT_RED] = "\x1B[1;31m", ++ [SK_COLOR_RED] = "\x1B[0;31m", ++ [SK_COLOR_YELLOW] = "\x1B[0;33m", ++ [SK_COLOR_END] = "\x1B[0m" ++ }; ++ /* %STRINGPOOLSTOP% */ ++ ++ if (!isatty(STDOUT_FILENO)) ++ return ""; ++ ++ if (color >= _SK_COLOR_MAX) ++ return ""; ++ ++ return _P(map[color]); ++} + + static void disk_dump_attributes(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata) { + char name[32]; + char pretty[32]; + char tt[32], tw[32], tc[32]; +- SkBool highlight; + + snprintf(tt, sizeof(tt), "%3u", a->threshold); + tt[sizeof(tt)-1] = 0; +@@ -2267,10 +2290,13 @@ + snprintf(tc, sizeof(tc), "%3u", a->current_value); + tc[sizeof(tc)-1] = 0; + +- highlight = a->warn && isatty(1); +- +- if (highlight) +- fprintf(stderr, HIGHLIGHT); ++ if (a->warn) { ++ if (a->good_now_valid && !a->good_now) ++ printf("%s", highlight(SK_COLOR_BRIGHT_RED)); ++ else if (a->good_in_the_past_valid && !a->good_in_the_past) ++ printf("%s", highlight(SK_COLOR_RED)); ++ } else if (a->caution) ++ printf("%s", highlight(SK_COLOR_YELLOW)); + + printf("%3u %-27s %-3s %-3s %-3s %-11s 0x%02x%02x%02x%02x%02x%02x %-7s %-7s %-4s %-4s\n", + a->id, +@@ -2285,8 +2311,8 @@ + a->good_now_valid ? yes_no(a->good_now) : "n/a", + a->good_in_the_past_valid ? yes_no(a->good_in_the_past) : "n/a"); + +- if (highlight) +- fprintf(stderr, ENDHIGHLIGHT); ++ if (a->warn || a->caution) ++ printf("%s", highlight(SK_COLOR_END)); + } + + int sk_disk_dump(SkDisk *d) { +@@ -2351,9 +2377,9 @@ + + ret = sk_disk_smart_status(d, &good); + printf("%sSMART Disk Health Good: %s%s\n", +- ret >= 0 && !good ? HIGHLIGHT : "", ++ ret >= 0 && !good ? highlight(SK_COLOR_BRIGHT_RED) : "", + ret >= 0 ? yes_no(good) : strerror(errno), +- ret >= 0 && !good ? ENDHIGHLIGHT : ""); ++ ret >= 0 && !good ? highlight(SK_COLOR_END) : ""); + if ((ret = sk_disk_smart_read_data(d)) < 0) + return ret; + +@@ -2387,9 +2413,9 @@ + printf("Bad Sectors: %s\n", strerror(errno)); + else + printf("%sBad Sectors: %s%s\n", +- value > 0 ? HIGHLIGHT : "", ++ value > 0 ? highlight(SK_COLOR_YELLOW) : "", + print_value(pretty, sizeof(pretty), value, SK_SMART_ATTRIBUTE_UNIT_SECTORS), +- value > 0 ? ENDHIGHLIGHT : ""); ++ value > 0 ? highlight(SK_COLOR_END) : ""); + + if (sk_disk_smart_get_power_on(d, &power_on) < 0) { + printf("Powered On: %s\n", strerror(errno)); +@@ -2418,9 +2444,9 @@ + printf("Overall Status: %s\n", strerror(errno)); + else + printf("%sOverall Status: %s%s\n", +- overall != SK_SMART_OVERALL_GOOD ? HIGHLIGHT : "", ++ overall != SK_SMART_OVERALL_GOOD ? highlight(SK_COLOR_RED) : "", + sk_smart_overall_to_string(overall), +- overall != SK_SMART_OVERALL_GOOD ? ENDHIGHLIGHT : ""); ++ overall != SK_SMART_OVERALL_GOOD ? highlight(SK_COLOR_END) : ""); + + printf("%3s %-27s %5s %5s %5s %-11s %-14s %-7s %-7s %-4s %-4s\n", + "ID#", +Index: libatasmart-0.17/atasmart.h +=================================================================== +--- libatasmart-0.17.orig/atasmart.h 2009-08-06 20:12:49.000000000 +0200 ++++ libatasmart-0.17/atasmart.h 2009-12-14 13:13:44.545793973 +0100 +@@ -160,7 +160,7 @@ + SkBool good_now:1, good_now_valid:1; + SkBool good_in_the_past:1, good_in_the_past_valid:1; + SkBool current_value_valid:1, worst_value_valid:1; +- SkBool warn:1; ++ SkBool warn:1, caution:1; + uint8_t current_value, worst_value; + uint64_t pretty_value; + uint8_t raw[6]; +Index: libatasmart-0.17/vala/atasmart.vapi +=================================================================== +--- libatasmart-0.17.orig/vala/atasmart.vapi 2009-09-18 05:03:58.000000000 +0200 ++++ libatasmart-0.17/vala/atasmart.vapi 2009-12-14 13:13:44.545793973 +0100 +@@ -107,6 +107,7 @@ + public bool current_value_valid; + public bool worst_value_valid; + public bool warn; ++ public bool caution; + public uint8 current_value; + public uint8 worst_value; + public uint64 pretty_value; only in patch2: unchanged: --- libatasmart-0.17.orig/debian/patches/02-fix-return-value.patch +++ libatasmart-0.17/debian/patches/02-fix-return-value.patch @@ -0,0 +1,60 @@ +Date: Mon, 14 Dec 2009 13:07:55 +0100 +Subject: Fix some return values. +Author: Roberto Mariani + + - Fix some return value. + - Call disk_smart_read_thresholds inside sk_disk_smart_read_data + instead of init_smart function. +Index: libatasmart-0.17/atasmart.c +=================================================================== +--- libatasmart-0.17.orig/atasmart.c 2009-10-24 00:37:59.000000000 +0200 ++++ libatasmart-0.17/atasmart.c 2009-12-14 13:04:10.345788920 +0100 +@@ -152,6 +152,7 @@ + #define SK_MSECOND_VALID_LONG_MAX (30ULL * 365ULL * 24ULL * 60ULL * 60ULL * 1000ULL) + + int init_smart(SkDisk *d); ++static int disk_smart_read_thresholds(SkDisk *d); + + static const char *disk_type_to_human_string(SkDiskType type) { + +@@ -841,12 +842,20 @@ + cmd[3] = htons(0x00C2U); + cmd[4] = htons(0x4F00U); + +- if ((ret = disk_command(d, SK_ATA_COMMAND_SMART, SK_DIRECTION_IN, cmd, d->smart_data, &len)) < 0) ++ if ((ret = disk_command(d, SK_ATA_COMMAND_SMART, SK_DIRECTION_IN, cmd, d->smart_data, &len)) < 0) { ++ d->smart_data_valid = FALSE; + return ret; ++ } + + d->smart_data_valid = TRUE; + +- return ret; ++ if ((ret = disk_smart_read_thresholds(d)) < 0) { ++ /* Command D1h is obsolete. If it fail don't bother user, ++ * but set thresholds as invalid */ ++ d->smart_thresholds_valid = FALSE; ++ } ++ ++ return 0; + } + + static int disk_smart_read_thresholds(SkDisk *d) { +@@ -875,7 +884,7 @@ + + d->smart_thresholds_valid = TRUE; + +- return ret; ++ return 0; + } + + int sk_disk_smart_status(SkDisk *d, SkBool *good) { +@@ -2577,7 +2586,7 @@ + } + } + +- disk_smart_read_thresholds(d); ++ return 0; + + fail: + return ret; only in patch2: unchanged: --- libatasmart-0.17.orig/debian/patches/04-strip-off-unlucky-heuristic-code.patch +++ libatasmart-0.17/debian/patches/04-strip-off-unlucky-heuristic-code.patch @@ -0,0 +1,39 @@ +Subject: Added #if 0 for unlucky heuristic for find BAD SECTORS MANY. +Author: Roberto Mariani + + - A comment in the code say: + + /* We use log2(n_sectors) as a threshold here. We had to pick + * something, and this makes a bit of sense, or doesn't it? */ + + this means: + + 128GB = 2^37 Bytes -> log2(2^28) = 28 sectors + 1TB = 2^40 Bytes -> log2(2^31) = 31 sectors + 8TB = 2^43 Bytes -> log2(2^34) = 34 sectors + + This is a unlucky heuristic. + +Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/lucid/+source/libatasmart/+bug/438136 +Index: libatasmart-0.17/atasmart.c +=================================================================== +--- libatasmart-0.17.orig/atasmart.c 2009-12-14 13:36:36.233791003 +0100 ++++ libatasmart-0.17/atasmart.c 2009-12-14 13:39:03.001788183 +0100 +@@ -2153,11 +2153,17 @@ + /* We use log2(n_sectors) as a threshold here. We had to pick + * something, and this makes a bit of sense, or doesn't it? */ + sector_threshold = u64log2(d->size/512); ++#if 0 ++ /* 128GB = 2^37 -> sector_threshold = 28 ++ * 1TB = 2^40 -> sector_threshold = 31 ++ * 8TB = 2^43 -> sector_threshold = 34 ++ * This is a unlucky heuristic */ + + if (sectors >= sector_threshold) { + *overall = SK_SMART_OVERALL_BAD_SECTOR_MANY; + return 0; + } ++#endif + } + + /* Third, check if any of the SMART attributes is bad */