- Changing SmartQuirkDatabase to store QString instead of char*.

- Changing quirkDatabase function to return QVector<SmartQuirkDatabase> instead of SmartQuirkDatabase*.
This commit is contained in:
Caio Carvalho 2018-03-24 15:17:30 -03:00
parent a4be3fd2ea
commit f8f25dc82a
2 changed files with 158 additions and 164 deletions

View File

@ -22,6 +22,7 @@
#include <QMap>
#include <QRegularExpression>
#include <QVariant>
#include <QVector>
#define MKELVIN_VALID_MIN ((qint64) ((-15LL*1000LL) + 273150LL))
#define MKELVIN_VALID_MAX ((qint64) ((100LL*1000LL) + 273150LL))
@ -477,33 +478,29 @@ static const QMap<qint32, SmartAttributeParsedData::SmartAttributeUnit> tableUni
return table;
}
static const SmartAttributeParsedData::SmartQuirkDataBase *quirkDatabase()
static const QVector<SmartAttributeParsedData::SmartQuirkDataBase> quirkDatabase()
{
static const SmartAttributeParsedData::SmartQuirkDataBase quirkDb[] = {
{
"^(FUJITSU MHY2120BH|FUJITSU MHY2250BH)$",
"^0085000B$",
typedef SmartAttributeParsedData::SmartQuirkDataBase QuirkDatabase;
QVector<QuirkDatabase> quirkDb;
quirkDb << QuirkDatabase(QStringLiteral("^(FUJITSU MHY2120BH|FUJITSU MHY2250BH)$"), QStringLiteral("^0085000B$"),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES |
SmartAttributeParsedData::SMART_QUIRK_197_UNKNOWN |
SmartAttributeParsedData::SMART_QUIRK_198_UNKNOWN)
},
{
"^FUJITSU MHR2040AT$",
NULL,
SmartAttributeParsedData::SMART_QUIRK_198_UNKNOWN));
quirkDb << QuirkDatabase(QStringLiteral("^FUJITSU MHR2040AT$"), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS |
SmartAttributeParsedData::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT |
SmartAttributeParsedData::SMART_QUIRK_200_WRITEERRORCOUNT)
},
{
"^FUJITSU MHS20[6432]0AT( .)?$",
NULL,
SmartAttributeParsedData::SMART_QUIRK_200_WRITEERRORCOUNT));
quirkDb << QuirkDatabase(QStringLiteral("^FUJITSU MHS20[6432]0AT( .)?$"), QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS |
SmartAttributeParsedData::SMART_QUIRK_192_EMERGENCYRETRACTCYCLECT |
SmartAttributeParsedData::SMART_QUIRK_200_WRITEERRORCOUNT |
SmartAttributeParsedData::SMART_QUIRK_201_DETECTEDTACOUNT)
},
{
"^("
SmartAttributeParsedData::SMART_QUIRK_201_DETECTEDTACOUNT));
quirkDb << QuirkDatabase(QStringLiteral("^("
"FUJITSU M1623TAU|"
"FUJITSU MHG2...ATU?.*|"
"FUJITSU MHH2...ATU?.*|"
@ -517,54 +514,47 @@ static const SmartAttributeParsedData::SmartQuirkDataBase *quirkDatabase()
"FUJITSU MHU2...ATU?.*|"
"FUJITSU MHV2...(AH|AS|AT|BH|BS|BT).*|"
"FUJITSU MP[A-G]3...A[HTEV]U?.*"
")$",
NULL,
SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS
},
{
"^("
")$"),
QStringLiteral(),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONSECONDS);
quirkDb << QuirkDatabase(QStringLiteral("^("
"SAMSUNG SV4012H|"
"SAMSUNG SP(0451|08[0124]2|12[0145]3|16[0145]4)[CN]"
")$",
NULL,
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES
},
{
"^("
")$"),
QStringLiteral(),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^("
"SAMSUNG SV0412H|"
"SAMSUNG SV1204H"
")$",
NULL,
")$"),
QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES |
SmartAttributeParsedData::SMART_QUIRK_194_10XCELSIUS)
},
{
"^SAMSUNG SP40A2H$",
"^RR100-07$",
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES
},
{
"^SAMSUNG SP80A4H$",
"^RT100-06$",
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES
},
{
"^SAMSUNG SP8004H$",
"^QW100-61$",
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES
},
{
"^("
SmartAttributeParsedData::SMART_QUIRK_194_10XCELSIUS));
quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP40A2H$"),
QStringLiteral("^RR100-07$"),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP80A4H$"),
QStringLiteral("^RT100-06$"),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^SAMSUNG SP8004H$"),
QStringLiteral("^QW100-61$"),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONHALFMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^("
"Maxtor 2B0(0[468]|1[05]|20)H1|"
"Maxtor 4G(120J6|160J[68])|"
"Maxtor 4D0(20H1|40H2|60H3|80H4)"
")$",
NULL,
")$"),
QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES |
SmartAttributeParsedData::SMART_QUIRK_194_UNKNOWN)
},
{
"^("
SmartAttributeParsedData::SMART_QUIRK_194_UNKNOWN));
quirkDb << QuirkDatabase(QStringLiteral("^("
"Maxtor 2F0[234]0[JL]0|"
"Maxtor 8(1280A2|2160A4|2560A4|3840A6|4000A6|5120A8)|"
"Maxtor 8(2160D2|3228D3|3240D3|4320D4|6480D6|8400D8|8455D8)|"
@ -593,71 +583,66 @@ static const SmartAttributeParsedData::SmartQuirkDataBase *quirkDatabase()
"Maxtor 7Y250[PM]0|"
"Maxtor [45]A(25|30|32)0[JN]0|"
"Maxtor 7L(25|30)0[SR]0"
")$",
NULL,
SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES
},
{
"^("
")$"),
QStringLiteral(),
SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES);
quirkDb << QuirkDatabase(QStringLiteral("^("
"HITACHI_DK14FA-20B|"
"HITACHI_DK23..-..B?|"
"HITACHI_DK23FA-20J|HTA422020F9AT[JN]0|"
"HE[JN]4230[23]0F9AT00|"
"HTC4260[23]0G5CE00|HTC4260[56]0G8CE00"
")$",
NULL,
")$"),
QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_9_POWERONMINUTES |
SmartAttributeParsedData::SMART_QUIRK_193_LOADUNLOAD)
},
{
"^HTS541010G9SA00$",
"^MBZOC60P$",
SmartAttributeParsedData::SMART_QUIRK_5_UNKNOWN
},
{
"^MCCOE64GEMPP$",
"^2.9.0[3-9]$",
SmartAttributeParsedData::SMART_QUIRK_193_LOADUNLOAD));
quirkDb << QuirkDatabase(QStringLiteral("^HTS541010G9SA00$"),
QStringLiteral("^MBZOC60P$"),
SmartAttributeParsedData::SMART_QUIRK_5_UNKNOWN);
quirkDb << QuirkDatabase(QStringLiteral("^MCCOE64GEMPP$"),
QStringLiteral("^2.9.0[3-9]$"),
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_5_UNKNOWN |
SmartAttributeParsedData::SMART_QUIRK_190_UNKNOWN)
},
{
"^INTEL SSDSA2(CT|BT|CW|BW)[0-9]{3}G3.*$",
NULL,
(SmartAttributeParsedData::SmartQuirk) (SmartAttributeParsedData::SMART_QUIRK_3_UNUSED |
SmartAttributeParsedData::SMART_QUIRK_190_UNKNOWN));
quirkDb << QuirkDatabase(QStringLiteral("^INTEL SSDSA2(CT|BT|CW|BW)[0-9]{3}G3.*$"),
QStringLiteral(),
(SmartAttributeParsedData::SmartQuirk)
(SmartAttributeParsedData::SMART_QUIRK_3_UNUSED |
SmartAttributeParsedData::SMART_QUIRK_4_UNUSED |
SmartAttributeParsedData::SMART_QUIRK_225_TOTALLBASWRITTEN |
SmartAttributeParsedData::SMART_QUIRK_226_TIMEWORKLOADMEDIAWEAR |
SmartAttributeParsedData::SMART_QUIRK_227_TIMEWORKLOADHOSTREADS |
SmartAttributeParsedData::SMART_QUIRK_228_WORKLOADTIMER |
SmartAttributeParsedData::SMART_QUIRK_232_AVAILABLERESERVEDSPACE |
SmartAttributeParsedData::SMART_QUIRK_233_MEDIAWEAROUTINDICATOR)
}
};
SmartAttributeParsedData::SMART_QUIRK_233_MEDIAWEAROUTINDICATOR));
return quirkDb;
}
static SmartAttributeParsedData::SmartQuirk getQuirk(QString model, QString firmware)
{
const SmartAttributeParsedData::SmartQuirkDataBase *db;
const QVector<SmartAttributeParsedData::SmartQuirkDataBase> db = quirkDatabase();
QRegularExpression modelRegex;
QRegularExpression firmwareRegex;
for (db = quirkDatabase(); db->model || db->firmware; db++) {
if (db->model) {
modelRegex.setPattern(QString::fromLocal8Bit(db->model));
for (const SmartAttributeParsedData::SmartQuirkDataBase &item : qAsConst(db)) {
if (!item.model.isEmpty()) {
modelRegex.setPattern(item.model);
QRegularExpressionMatch match = modelRegex.match(model);
if (!match.hasMatch())
continue;
}
if (db->firmware) {
firmwareRegex.setPattern(QString::fromLocal8Bit(db->firmware));
if (!item.firmware.isEmpty()) {
firmwareRegex.setPattern(item.firmware);
QRegularExpressionMatch match = firmwareRegex.match(firmware);
if (!match.hasMatch())
continue;
}
return db->quirk;
return item.quirk;
}
return (SmartAttributeParsedData::SmartQuirk) 0;

View File

@ -74,9 +74,18 @@ public:
/** SMART Quirk to some particular model and firmware */
struct SmartQuirkDataBase {
const char *model;
const char *firmware;
QString model;
QString firmware;
SmartAttributeParsedData::SmartQuirk quirk;
SmartQuirkDataBase(const QString &m = QString(),
const QString &f = QString(),
SmartAttributeParsedData::SmartQuirk q = (SmartAttributeParsedData::SmartQuirk) 0) :
model(m),
firmware(f),
quirk(q)
{
};
};
public: