Commit cc49f49d authored by Eric Cano's avatar Eric Cano
Browse files

Added ASC/ASCQ sense constants (from Linux kernel) and added a function to

pretty print the meaning of the ACS/ACSQ couple.
parent 19142144
This diff is collapsed.
......@@ -293,5 +293,24 @@ namespace SCSI {
bytesWrittenToTape = 0x0009 // a signed number and may be negative
};
};
class senseConstants {
public:
/* Structures from the Linux Kernel. It holds ASC/ASCQ to string
* translations (from http://www.t10.org/lists/asc-num.txt) */
struct error_info {
uint16_t code12; /* 0x0302 looks better than 0x03,0x02 */
const char * text;
};
static const struct error_info ascStrings[];
struct error_range_info {
uint8_t asc;
uint8_t ascq_min;
uint8_t ascq_max;
const char * text;
};
static const struct error_range_info ascRangesStrings[];
};
}; // namespace SCSI
......@@ -24,6 +24,7 @@
#include "Structures.hh"
#include <sstream>
#include <cstdio>
std::string SCSI::Structures::toString(const inquiryData_t& inq) {
std::stringstream inqDump;
......@@ -60,4 +61,3 @@ std::string SCSI::Structures::toString(const inquiryData_t& inq) {
inqDump << "inq.versionDescriptor[" << i << "]=" << SCSI::Structures::toU16(inq.versionDescriptor[i]) << std::endl;
return inqDump.str();
}
......@@ -608,7 +608,33 @@ namespace SCSI {
} else {
throw Tape::Exception("In senseData_t::getASCQ: no ACSQ with this response code or response code not supported");
}
};
}
/**
* Function turning the ACS/ACSQ contents into a string.
* This function is taken from the Linux kernel sources.
* see scsi_extd_sense_format.
* @return the error string as defined by SCSI specifications.
*/
std::string getACSString() {
SCSI::senseConstants sc;
uint8_t asc = getASC();
uint8_t ascq = getASCQ();
uint16_t code = (asc << 8) | ascq;
for (int i = 0; sc.ascStrings[i].text; i++)
if (sc.ascStrings[i].code12 == code)
return std::string(sc.ascStrings[i].text);
for (int i = 0; sc.ascRangesStrings[i].text; i++)
if (sc.ascRangesStrings[i].asc == asc &&
sc.ascRangesStrings[i].ascq_min <= ascq &&
sc.ascRangesStrings[i].ascq_max >= ascq) {
char buff[100];
snprintf(buff, sizeof (buff), sc.ascRangesStrings[i].text, ascq);
return std::string(buff);
}
char buff[100];
snprintf(buff, sizeof (buff), "Unknown ASC/ASCQ:%02x/%02x", asc, ascq);
return std::string(buff);
}
};
template <size_t n>
......@@ -649,6 +675,5 @@ namespace SCSI {
return hex.str();
}
};
};
......@@ -412,17 +412,28 @@ namespace UnitTests {
ASSERT_EQ(0x78, sense.getASCQ());
buff[0] = 0x73;
buff[2] = 0x56;
buff[3] = 0x78;
buff[2] = 0x0b;
buff[3] = 0x08;
ASSERT_EQ(false, sense.isCurrent());
ASSERT_EQ(true, sense.isDeffered());
ASSERT_EQ(false, sense.isFixedFormat());
ASSERT_EQ(true, sense.isDescriptorFormat());
ASSERT_EQ(0x56, sense.getASC());
ASSERT_EQ(0x78, sense.getASCQ());
ASSERT_EQ(0x0b, sense.getASC());
ASSERT_EQ(0x08, sense.getASCQ());
ASSERT_EQ("Warning - power loss expected", sense.getACSString());
buff[2] = 0x40;
buff[3] = 0xab;
ASSERT_EQ("Diagnostic failure on component (ab)", sense.getACSString());
buff[2] = 0x00;
buff[3] = 0x1F;
ASSERT_EQ("Unknown ASC/ASCQ:00/1f", sense.getACSString());
buff[0] = 0x74;
ASSERT_THROW(sense.getASC(), Tape::Exception);
ASSERT_THROW(sense.getACSString(), Tape::Exception);
}
TEST(SCSI_Structures, toU16) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment