Description: Add machine-readable output format
old
|
new
|
static void PrintSmartAttribWithThres(co
|
1014 | 1014 | bool brief = !!(format & ata_print_options::FMT_BRIEF); |
1015 | 1015 | bool hexid = !!(format & ata_print_options::FMT_HEX_ID); |
1016 | 1016 | bool hexval = !!(format & ata_print_options::FMT_HEX_VAL); |
| 1017 | bool machine = !!(format & ata_print_options::FMT_MACHINE); |
1017 | 1018 | bool needheader = true; |
1018 | 1019 | |
| 1020 | if (machine) |
| 1021 | needheader = false; |
| 1022 | |
1019 | 1023 | // step through all vendor attributes |
1020 | 1024 | for (int i = 0; i < NUMBER_ATA_SMART_ATTRIBUTES; i++) { |
1021 | 1025 | const ata_smart_attribute & attr = data->vendor_attributes[i]; |
… |
… |
static void PrintSmartAttribWithThres(co
|
1049 | 1053 | } |
1050 | 1054 | |
1051 | 1055 | // Format value, worst, threshold |
1052 | | std::string valstr, worstr, threstr; |
1053 | | if (state > ATTRSTATE_NO_NORMVAL) |
1054 | | valstr = (!hexval ? strprintf("%.3d", attr.current) |
| 1056 | std::string idstr, valstr, worstr, threstr; |
| 1057 | if (!machine) { |
| 1058 | if (state > ATTRSTATE_NO_NORMVAL) |
| 1059 | valstr = (!hexval ? strprintf("%.3d", attr.current) |
1055 | 1060 | : strprintf("0x%02x", attr.current)); |
1056 | | else |
1057 | | valstr = (!hexval ? "---" : "----"); |
1058 | | if (!(defs[attr.id].flags & ATTRFLAG_NO_WORSTVAL)) |
1059 | | worstr = (!hexval ? strprintf("%.3d", attr.worst) |
| 1061 | else |
| 1062 | valstr = (!hexval ? "---" : "----"); |
| 1063 | if (!(defs[attr.id].flags & ATTRFLAG_NO_WORSTVAL)) |
| 1064 | worstr = (!hexval ? strprintf("%.3d", attr.worst) |
1060 | 1065 | : strprintf("0x%02x", attr.worst)); |
1061 | | else |
1062 | | worstr = (!hexval ? "---" : "----"); |
1063 | | if (state > ATTRSTATE_NO_THRESHOLD) |
1064 | | threstr = (!hexval ? strprintf("%.3d", threshold) |
| 1066 | else |
| 1067 | worstr = (!hexval ? "---" : "----"); |
| 1068 | if (state > ATTRSTATE_NO_THRESHOLD) |
| 1069 | threstr = (!hexval ? strprintf("%.3d", threshold) |
1065 | 1070 | : strprintf("0x%02x", threshold)); |
1066 | | else |
1067 | | threstr = (!hexval ? "---" : "----"); |
1068 | | |
1069 | | // Print line for each valid attribute |
1070 | | std::string idstr = (!hexid ? strprintf("%3d", attr.id) |
1071 | | : strprintf("0x%02x", attr.id)); |
| 1071 | else |
| 1072 | threstr = (!hexval ? "---" : "----"); |
| 1073 | // Print line for each valid attribute |
| 1074 | idstr = (!hexid ? strprintf("%3d", attr.id) |
| 1075 | : strprintf("0x%02x", attr.id)); |
| 1076 | } else { |
| 1077 | valstr = strprintf("%d", attr.current); |
| 1078 | worstr = strprintf("%d", attr.worst); |
| 1079 | threstr = strprintf("%d", threshold); |
| 1080 | idstr = strprintf("%d", attr.id); |
| 1081 | } |
1072 | 1082 | std::string attrname = ata_get_smart_attr_name(attr.id, defs, rpm); |
1073 | 1083 | std::string rawstr = ata_format_attr_raw_value(attr, defs); |
1074 | 1084 | |
1075 | | if (!brief) |
| 1085 | if (machine) |
| 1086 | pout("%s,%s,0x%04x,%s,%s,%s,%s,%s,%s,%s\n", |
| 1087 | idstr.c_str(), attrname.c_str(), attr.flags, |
| 1088 | valstr.c_str(), worstr.c_str(), threstr.c_str(), |
| 1089 | (ATTRIBUTE_FLAGS_PREFAILURE(attr.flags) ? "Pre-fail" : "Old_age"), |
| 1090 | (ATTRIBUTE_FLAGS_ONLINE(attr.flags) ? "Always" : "Offline"), |
| 1091 | (state == ATTRSTATE_FAILED_NOW ? "FAILING_NOW" : |
| 1092 | state == ATTRSTATE_FAILED_PAST ? "In_the_past" |
| 1093 | : "-") , |
| 1094 | rawstr.c_str()); |
| 1095 | else if (!brief) |
1076 | 1096 | pout("%s %-24s0x%04x %-4s %-4s %-4s %-10s%-9s%-12s%s\n", |
1077 | 1097 | idstr.c_str(), attrname.c_str(), attr.flags, |
1078 | 1098 | valstr.c_str(), worstr.c_str(), threstr.c_str(), |
… |
… |
int ataPrintMain (ata_device * device, c
|
3049 | 3069 | smart_val_ok = false; |
3050 | 3070 | } |
3051 | 3071 | |
3052 | | // all this for a newline! |
3053 | | if ( options.smart_disable || options.smart_enable |
| 3072 | if (!(options.output_format & ata_print_options::FMT_MACHINE)) { |
| 3073 | // all this for a newline! |
| 3074 | if ( options.smart_disable || options.smart_enable |
3054 | 3075 | || options.smart_auto_save_disable || options.smart_auto_save_enable |
3055 | 3076 | || options.smart_auto_offl_disable || options.smart_auto_offl_enable |
3056 | 3077 | || options.set_aam || options.set_apm || options.set_lookahead |
… |
… |
int ataPrintMain (ata_device * device, c
|
3058 | 3079 | || options.sct_wcache_reorder_set) |
3059 | 3080 | pout("\n"); |
3060 | 3081 | |
3061 | | // START OF READ-ONLY OPTIONS APART FROM -V and -i |
3062 | | if ( options.smart_check_status || options.smart_general_values |
| 3082 | // START OF READ-ONLY OPTIONS APART FROM -V and -i |
| 3083 | if ( options.smart_check_status || options.smart_general_values |
3063 | 3084 | || options.smart_vendor_attrib || options.smart_error_log |
3064 | 3085 | || options.smart_selftest_log || options.smart_selective_selftest_log |
3065 | 3086 | || options.smart_ext_error_log || options.smart_ext_selftest_log |
3066 | 3087 | || options.sct_temp_sts || options.sct_temp_hist ) |
3067 | | pout("=== START OF READ SMART DATA SECTION ===\n"); |
3068 | | |
| 3088 | pout("=== START OF READ SMART DATA SECTION ===\n"); |
| 3089 | } |
| 3090 | |
3069 | 3091 | // Check SMART status |
3070 | 3092 | if (options.smart_check_status) { |
3071 | 3093 | |