* Home page of code is: http://smartmontools.sourceforge.net
* Address of support mailing list: smartmontools-support@lists.sourceforge.net
*
- * Copyright (C) 2003-10 Philip Williams, Bruce Allen
- * Copyright (C) 2008-10 Christian Franke <smartmontools-support@lists.sourceforge.net>
+ * Copyright (C) 2003-11 Philip Williams, Bruce Allen
+ * Copyright (C) 2008-11 Christian Franke <smartmontools-support@lists.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "int64.h"
#include <stdio.h>
#include "atacmds.h"
-#include "extern.h"
#include "knowndrives.h"
#include "utility.h"
#include <stdexcept>
-const char * knowndrives_cpp_cvsid = "$Id: knowndrives.cpp 3093 2010-04-30 09:57:36Z chrfranke $"
+const char * knowndrives_cpp_cvsid = "$Id: knowndrives.cpp 3447 2011-10-14 20:32:00Z chrfranke $"
KNOWNDRIVES_H_CVSID;
#define MODEL_STRING_LENGTH 40
// string. If either the drive's model or firmware strings are not set by the
// manufacturer then values of NULL may be used. Returns the entry of the
// first match in knowndrives[] or 0 if no match if found.
-const drive_settings * lookup_drive(const char * model, const char * firmware)
+static const drive_settings * lookup_drive(const char * model, const char * firmware)
{
if (!model)
model = "";
i += strspn(presets+i, " \t");
if (!presets[i])
break;
- char opt, arg[40+1+13]; int len = -1;
- if (!(sscanf(presets+i, "-%c %40[^ ]%n", &opt, arg, &len) >= 2 && len > 0))
+ char opt, arg[80+1+13]; int len = -1;
+ if (!(sscanf(presets+i, "-%c %80[^ ]%n", &opt, arg, &len) >= 2 && len > 0))
return false;
if (opt == 'v' && defs) {
// Parse "-v N,format[,name]"
bcd_dev_str[0] = 0;
int found = 0;
- bool bcd_match = false;
for (unsigned i = 0; i < knowndrives.size(); i++) {
const drive_settings & dbentry = knowndrives[i];
// If two entries with same vendor:product ID have different
// types, use bcd_device (if provided by OS) to select entry.
- bool bm = ( *bcd_dev_str && *dbentry.firmwareregexp
- && match(dbentry.firmwareregexp, bcd_dev_str));
-
- if (found == 0 || bm > bcd_match) {
+ if ( *dbentry.firmwareregexp && *bcd_dev_str
+ && match(dbentry.firmwareregexp, bcd_dev_str)) {
+ // Exact match including bcd_device
+ info = d; found = 1;
+ break;
+ }
+ else if (!found) {
+ // First match without bcd_device
info = d; found = 1;
- bcd_match = bm;
}
- else if (info.usb_type != d.usb_type && bm == bcd_match) {
- // two different entries found
+ else if (info.usb_type != d.usb_type) {
+ // Another possible match with different type
info2 = d; found = 2;
break;
}
+
+ // Stop search at first matching entry with empty bcd_device
+ if (!*dbentry.firmwareregexp)
+ break;
}
return found;
}
for (int i = 0; i < MAX_ATTRIBUTE_NUM; i++) {
if (defs[i].priority != PRIOR_DEFAULT) {
+ std::string name = ata_get_smart_attr_name(i, defs);
// Use leading zeros instead of spaces so that everything lines up.
pout("%-*s %03d %s\n", TABLEPRINTWIDTH, first_preset ? "ATTRIBUTE OPTIONS:" : "",
- i, ata_get_smart_attr_name(i, defs).c_str());
+ i, name.c_str());
+ // Check max name length suitable for smartctl -A output
+ const unsigned maxlen = 23;
+ if (name.size() > maxlen) {
+ pout("%*s\n", TABLEPRINTWIDTH+6+maxlen, "Error: Attribute name too long ------^");
+ errcnt++;
+ }
first_preset = false;
}
}
}
// Shows the presets (if any) that are available for the given drive.
-void show_presets(const ata_identify_device * drive, bool fix_swapped_id)
+void show_presets(const ata_identify_device * drive)
{
char model[MODEL_STRING_LENGTH+1], firmware[FIRMWARE_STRING_LENGTH+1];
// get the drive's model/firmware strings
- format_ata_string(model, drive->model, MODEL_STRING_LENGTH, fix_swapped_id);
- format_ata_string(firmware, drive->fw_rev, FIRMWARE_STRING_LENGTH, fix_swapped_id);
-
+ ata_format_id_string(model, drive->model, sizeof(model)-1);
+ ata_format_id_string(firmware, drive->fw_rev, sizeof(firmware)-1);
+
// and search to see if they match values in the table
const drive_settings * dbentry = lookup_drive(model, firmware);
if (!dbentry) {
showonepreset(dbentry);
}
-// Sets preset vendor attribute options in opts by finding the entry
-// (if any) for the given drive in knowndrives[]. Values that have
-// already been set in opts will not be changed. Returns false if drive
-// not recognized.
-bool apply_presets(const ata_identify_device *drive, ata_vendor_attr_defs & defs,
- unsigned char & fix_firmwarebug, bool fix_swapped_id)
+// Searches drive database and sets preset vendor attribute
+// options in defs and fix_firmwarebug.
+// Values that have already been set will not be changed.
+// Returns pointer to database entry or nullptr if none found
+const drive_settings * lookup_drive_apply_presets(
+ const ata_identify_device * drive, ata_vendor_attr_defs & defs,
+ unsigned char & fix_firmwarebug)
{
// get the drive's model/firmware strings
char model[MODEL_STRING_LENGTH+1], firmware[FIRMWARE_STRING_LENGTH+1];
- format_ata_string(model, drive->model, MODEL_STRING_LENGTH, fix_swapped_id);
- format_ata_string(firmware, drive->fw_rev, FIRMWARE_STRING_LENGTH, fix_swapped_id);
-
+ ata_format_id_string(model, drive->model, sizeof(model)-1);
+ ata_format_id_string(firmware, drive->fw_rev, sizeof(firmware)-1);
+
// Look up the drive in knowndrives[].
const drive_settings * dbentry = lookup_drive(model, firmware);
if (!dbentry)
- return false;
+ return 0;
if (*dbentry->presets) {
// Apply presets
if (!parse_presets(dbentry->presets, defs, fix_firmwarebug))
pout("Syntax error in preset option string \"%s\"\n", dbentry->presets);
}
- return true;
+ return dbentry;
}