diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG index 46dcf74ecab8cdc685f62cac4e7d5ee3b2d027ca..0bfb526a15fbce8dc19c871d761fe7e36e51359d 100644 --- a/smartmontools/CHANGELOG +++ b/smartmontools/CHANGELOG @@ -43,7 +43,9 @@ NOTES FOR FUTURE RELEASES: see TODO file. <DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE> - [CF] Add '-v ID,raw64[,...]' print format based on an patch provided + [CF] Add '-v ID,hex*' print formats. Fix '-v N,FORMAT,NAME' parsing. + + [CF] Add '-v ID,raw64[,...]' print format based on a patch provided by Marcin Marszalek. [CF] Add '-v ID,RAW_FORMAT[,ATTR_NAME]' option. This allows to add new diff --git a/smartmontools/atacmds.cpp b/smartmontools/atacmds.cpp index b567f3f999745f0bf0c3e8b3366cf74396f49445..ff4703dec68d8689782cfbeff1fc2c8b0e91ee04 100644 --- a/smartmontools/atacmds.cpp +++ b/smartmontools/atacmds.cpp @@ -196,7 +196,9 @@ const format_name_entry format_names[] = { {"raw8" , RAWFMT_RAW8}, {"raw16" , RAWFMT_RAW16}, {"raw48" , RAWFMT_RAW48}, + {"hex48" , RAWFMT_HEX48}, {"raw64" , RAWFMT_RAW64}, + {"hex64" , RAWFMT_HEX64}, {"raw16(raw16)" , RAWFMT_RAW16_OPT_RAW16}, {"raw16(avg16)" , RAWFMT_RAW16_OPT_AVG16}, {"raw24/raw24" , RAWFMT_RAW24_RAW24}, @@ -249,7 +251,8 @@ bool parse_attribute_def(const char * opt, ata_vendor_attr_defs & defs, char fmtname[32+1], attrname[32+1]; if (opt[0] == 'N') { // "N,format" - if (!(sscanf(opt, "N,%32[^,]%n", fmtname, &n1) == 1 && n1 == len)) + if (!( sscanf(opt, "N,%32[^,]%n,%32[^,]%n", fmtname, &n1, attrname, &n2) >= 1 + && (n1 == len || n2 == len))) return false; } else { @@ -257,9 +260,9 @@ bool parse_attribute_def(const char * opt, ata_vendor_attr_defs & defs, if (!( sscanf(opt, "%d,%32[^,]%n,%32[^,]%n", &id, fmtname, &n1, attrname, &n2) >= 2 && 1 <= id && id <= 255 && (n1 == len || n2 == len))) return false; - if (n1 == len) - attrname[0] = 0; } + if (n1 == len) + attrname[0] = 0; unsigned flags = 0; // For "-v 19[78],increasing" above @@ -282,6 +285,8 @@ bool parse_attribute_def(const char * opt, ata_vendor_attr_defs & defs, for (int j = 0; j < MAX_ATTRIBUTE_NUM; j++) { if (defs[j].priority >= priority) continue; + if (attrname[0]) + defs[j].name = attrname; defs[j].priority = priority; defs[j].raw_format = format; } @@ -1833,14 +1838,23 @@ std::string ata_format_attr_raw_value(const ata_smart_attribute & attribute, s = strprintf("%"PRIu64, rawvalue); break; + case RAWFMT_HEX48: + s = strprintf("0x%012"PRIx64, rawvalue); + break; + case RAWFMT_RAW64: + case RAWFMT_HEX64: // Some SSD vendors use bytes 3-10 from the Attribute // Data Structure to store a 64-bit raw value. + // TODO: Do not print VALUE/WORST/THRESH in attribute table. rawvalue <<= 8; rawvalue |= attribute.worst; rawvalue <<= 8; rawvalue |= attribute.current; - s = strprintf("%"PRIu64, rawvalue); + if (format == RAWFMT_RAW64) + s = strprintf("%"PRIu64, rawvalue); + else + s = strprintf("0x%016"PRIx64, rawvalue); break; case RAWFMT_RAW16_OPT_RAW16: diff --git a/smartmontools/atacmds.h b/smartmontools/atacmds.h index 746b66cbd75bb3cb4debc7e475a16812a2d6b39b..791c01470c96ebda86842a09c5e5fed4515b0756 100644 --- a/smartmontools/atacmds.h +++ b/smartmontools/atacmds.h @@ -641,7 +641,9 @@ enum ata_attr_raw_format RAWFMT_RAW8, RAWFMT_RAW16, RAWFMT_RAW48, + RAWFMT_HEX48, RAWFMT_RAW64, + RAWFMT_HEX64, RAWFMT_RAW16_OPT_RAW16, RAWFMT_RAW16_OPT_AVG16, RAWFMT_RAW24_RAW24, diff --git a/smartmontools/smartctl.8.in b/smartmontools/smartctl.8.in index 844328d88afdf7c69c82f21efc0f2af143bf6b25..769217f649eb25d614038118e0ca0f57993fb82b 100644 --- a/smartmontools/smartctl.8.in +++ b/smartmontools/smartctl.8.in @@ -1044,11 +1044,20 @@ This may be useful for decoding the meaning of the Raw value. \- Print the Raw value as a 48\-bit unsigned base\-10 integer. This is the default for most attributes. +.I hex48 +\- Print the Raw value as a 12 digit hexadecimal number. +This may be useful for decoding the meaning of the Raw value. + .I raw64 \- Print the Raw value as a 64\-bit unsigned base\-10 integer. This includes two bytes from the normalized and worst attribute value. This new raw format is used by some recent SSD devices. +.I hex64 +\- Print the Raw value as a 16 digit hexadecimal number. +This includes two bytes from the normalized and worst attribute value. +This new raw format is used by some recent SSD devices. + .I min2hour \- Raw Attribute is power\-on time in minutes. Its raw value will be displayed in the form "Xh+Ym". Here X is hours, and Y is