Skip to content

Commit

Permalink
Add missing opcode, replace vectors by arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 29, 2025
1 parent c2a7c1e commit 2713338
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 86 deletions.
28 changes: 14 additions & 14 deletions cpp/s2pdump/board_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@

using namespace memory_util;

void BoardExecutor::TestUnitReady(vector<uint8_t> &cdb) const
void BoardExecutor::TestUnitReady(span<uint8_t> cdb) const
{
Execute(ScsiCommand::TEST_UNIT_READY, cdb, { }, 0, 1, false);
}

int BoardExecutor::RequestSense(vector<uint8_t> &cdb, span<uint8_t> buf) const
int BoardExecutor::RequestSense(span<uint8_t> cdb, span<uint8_t> buf) const
{
return Execute(ScsiCommand::REQUEST_SENSE, cdb, buf, static_cast<int>(buf.size()), 1, false);
}

bool BoardExecutor::Inquiry(vector<uint8_t> &cdb, span<uint8_t> buf) const
bool BoardExecutor::Inquiry(span<uint8_t> cdb, span<uint8_t> buf) const
{
return !Execute(ScsiCommand::INQUIRY, cdb, buf, static_cast<int>(buf.size()), 1, false);
}

bool BoardExecutor::ModeSense6(vector<uint8_t> &cdb, span<uint8_t> buf) const
bool BoardExecutor::ModeSense6(span<uint8_t> cdb, span<uint8_t> buf) const
{
return !Execute(ScsiCommand::MODE_SENSE_6, cdb, buf, static_cast<int>(buf.size()), 1, false);
}

set<int> BoardExecutor::ReportLuns(vector<uint8_t> &cdb, span<uint8_t> buf)
set<int> BoardExecutor::ReportLuns(span<uint8_t> cdb, span<uint8_t> buf)
{
// Assume 8 LUNs in case REPORT LUNS is not available
if (Execute(ScsiCommand::REPORT_LUNS, cdb, buf, static_cast<int>(buf.size()), 1, false)) {
Expand All @@ -58,49 +58,49 @@ set<int> BoardExecutor::ReportLuns(vector<uint8_t> &cdb, span<uint8_t> buf)
return luns;
}

int BoardExecutor::ReadCapacity10(vector<uint8_t> &cdb, span<uint8_t> buf) const
int BoardExecutor::ReadCapacity10(span<uint8_t> cdb, span<uint8_t> buf) const
{
return Execute(ScsiCommand::READ_CAPACITY_10, cdb, buf, 8, 1, true);
}

int BoardExecutor::ReadCapacity16(vector<uint8_t> &cdb, span<uint8_t> buf) const
int BoardExecutor::ReadCapacity16(span<uint8_t> cdb, span<uint8_t> buf) const
{
return Execute(ScsiCommand::READ_CAPACITY_READ_LONG_16, cdb, buf, 14, 1, true);
}

bool BoardExecutor::ReadWrite(vector<uint8_t> &cdb, span<uint8_t> buf, int length)
bool BoardExecutor::ReadWrite(span<uint8_t> cdb, span<uint8_t> buf, int length)
{
return !Execute(static_cast<ScsiCommand>(cdb[0]), cdb, buf, length, 10, true);
}

void BoardExecutor::SynchronizeCache(vector<uint8_t> &cdb) const
void BoardExecutor::SynchronizeCache(span<uint8_t> cdb) const
{
Execute(ScsiCommand::SYNCHRONIZE_CACHE_10, cdb, { }, 0, 3, true);
}

int BoardExecutor::Rewind(vector<uint8_t> &cdb) const
int BoardExecutor::Rewind(span<uint8_t> cdb) const
{
return Execute(ScsiCommand::REWIND, cdb, { }, 0, LONG_TIMEOUT, true);
}

void BoardExecutor::SpaceBack(vector<uint8_t> &cdb) const
void BoardExecutor::SpaceBack(span<uint8_t> cdb) const
{
if (Execute(ScsiCommand::SPACE_6, cdb, { }, 0, LONG_TIMEOUT, false)) {
throw IoException("Can't space back one block");
}
}

int BoardExecutor::WriteFilemark(vector<uint8_t> &cdb) const
int BoardExecutor::WriteFilemark(span<uint8_t> cdb) const
{
return Execute(ScsiCommand::WRITE_FILEMARKS_6, cdb, { }, 0, LONG_TIMEOUT, true);
}

bool BoardExecutor::Read(vector<uint8_t> &cdb, span<uint8_t> buf, int length)
bool BoardExecutor::Read(span<uint8_t> cdb, span<uint8_t> buf, int length)
{
return Execute(ScsiCommand::READ_6, cdb, buf, length, LONG_TIMEOUT, false);
}

bool BoardExecutor::Write(vector<uint8_t> &cdb, span<uint8_t> buf, int length)
bool BoardExecutor::Write(span<uint8_t> cdb, span<uint8_t> buf, int length)
{
return Execute(ScsiCommand::WRITE_6, cdb, buf, length, LONG_TIMEOUT, false);
}
Expand Down
28 changes: 14 additions & 14 deletions cpp/s2pdump/board_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ class BoardExecutor : public S2pDumpExecutor
}

// Disk and tape support
void TestUnitReady(vector<uint8_t>&) const override;
int RequestSense(vector<uint8_t>&, span<uint8_t>) const override;
bool Inquiry(vector<uint8_t>&, span<uint8_t>) const override;
bool ModeSense6(vector<uint8_t>&, span<uint8_t>) const override;
set<int> ReportLuns(vector<uint8_t>&, span<uint8_t>) override;
void TestUnitReady(span<uint8_t>) const override;
int RequestSense(span<uint8_t>, span<uint8_t>) const override;
bool Inquiry(span<uint8_t>, span<uint8_t>) const override;
bool ModeSense6(span<uint8_t>, span<uint8_t>) const override;
set<int> ReportLuns(span<uint8_t>, span<uint8_t>) override;

// Disk support
int ReadCapacity10(vector<uint8_t>&, span<uint8_t>) const override;
int ReadCapacity16(vector<uint8_t>&, span<uint8_t>) const override;
bool ReadWrite(vector<uint8_t>&, span<uint8_t>, int) override;
void SynchronizeCache(vector<uint8_t>&) const override;
int ReadCapacity10(span<uint8_t>, span<uint8_t>) const override;
int ReadCapacity16(span<uint8_t>, span<uint8_t>) const override;
bool ReadWrite(span<uint8_t>, span<uint8_t>, int) override;
void SynchronizeCache(span<uint8_t>) const override;

// Tape support
int Rewind(vector<uint8_t>&) const override;
int WriteFilemark(vector<uint8_t>&) const override;
bool Read(vector<uint8_t>&, span<uint8_t>, int) override;
bool Write(vector<uint8_t>&, span<uint8_t>, int) override;
int Rewind(span<uint8_t>) const override;
int WriteFilemark(span<uint8_t>) const override;
bool Read(span<uint8_t>, span<uint8_t>, int) override;
bool Write(span<uint8_t>, span<uint8_t>, int) override;

void SetTarget(int id, int lun, bool sasi)
{
Expand All @@ -54,7 +54,7 @@ class BoardExecutor : public S2pDumpExecutor

protected:

void SpaceBack(vector<uint8_t>&) const override;
void SpaceBack(span<uint8_t>) const override;

private:

Expand Down
31 changes: 15 additions & 16 deletions cpp/s2pdump/s2pdump_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ using namespace memory_util;

void S2pDumpExecutor::TestUnitReady() const
{
vector<uint8_t> cdb(6);

array<uint8_t, 6> cdb = { };
TestUnitReady(cdb);
}

void S2pDumpExecutor::RequestSense(span<uint8_t> buf) const
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::REQUEST_SENSE);
cdb[4] = static_cast<uint8_t>(buf.size());

Expand All @@ -31,7 +30,7 @@ void S2pDumpExecutor::RequestSense(span<uint8_t> buf) const

bool S2pDumpExecutor::Inquiry(span<uint8_t> buf) const
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::INQUIRY);
cdb[4] = static_cast<uint8_t>(buf.size());

Expand All @@ -40,7 +39,7 @@ bool S2pDumpExecutor::Inquiry(span<uint8_t> buf) const

bool S2pDumpExecutor::ModeSense6(span<uint8_t> buf) const
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::MODE_SENSE_6);
cdb[1] = 0x08;
cdb[2] = 0x3f;
Expand All @@ -51,16 +50,17 @@ bool S2pDumpExecutor::ModeSense6(span<uint8_t> buf) const

set<int> S2pDumpExecutor::ReportLuns()
{
vector<uint8_t> buf(512);
vector<uint8_t> cdb(12);
array<uint8_t, 512> buf = { };
array<uint8_t, 12> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::REPORT_LUNS);
SetInt16(cdb, 8, buf.size());

return ReportLuns(cdb, buf);
}

pair<uint64_t, uint32_t> S2pDumpExecutor::ReadCapacity() const
{
vector<uint8_t> buf(14);
array<uint8_t, 14> buf = { };
vector<uint8_t> cdb(10);
cdb[0] = static_cast<uint8_t>(ScsiCommand::READ_CAPACITY_10);

Expand Down Expand Up @@ -92,7 +92,7 @@ pair<uint64_t, uint32_t> S2pDumpExecutor::ReadCapacity() const

bool S2pDumpExecutor::ReadWrite(span<uint8_t> buf, uint32_t bstart, uint32_t blength, int length, bool is_write)
{
vector<uint8_t> cdb(10);
array<uint8_t, 10> cdb = { };
cdb[0] = static_cast<uint8_t>(is_write ? ScsiCommand::WRITE_10 : ScsiCommand::READ_10);
SetInt32(cdb, 2, bstart);
SetInt16(cdb, 7, blength);
Expand All @@ -102,33 +102,32 @@ bool S2pDumpExecutor::ReadWrite(span<uint8_t> buf, uint32_t bstart, uint32_t ble

void S2pDumpExecutor::SynchronizeCache() const
{
vector<uint8_t> cdb(10);
array<uint8_t, 10> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::SYNCHRONIZE_CACHE_10);

SynchronizeCache(cdb);
}

void S2pDumpExecutor::SpaceBack() const
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::SPACE_6);
cdb[1] = 0b000;
SetInt24(cdb, 2, -1);

SpaceBack(cdb);
}

int S2pDumpExecutor::Rewind()
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::REWIND);

return Rewind(cdb);
}

int S2pDumpExecutor::WriteFilemark() const
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };
cdb[0] = static_cast<uint8_t>(ScsiCommand::WRITE_FILEMARKS_6);
SetInt24(cdb, 2, 1);

Expand All @@ -137,7 +136,7 @@ int S2pDumpExecutor::WriteFilemark() const

int S2pDumpExecutor::ReadWrite(span<uint8_t> buf, int length)
{
vector<uint8_t> cdb(6);
array<uint8_t, 6> cdb = { };

// Restore
if (length) {
Expand All @@ -160,7 +159,7 @@ int S2pDumpExecutor::ReadWrite(span<uint8_t> buf, int length)
return default_length;
}

vector<uint8_t> sense_data(14);
array<uint8_t, 14> sense_data = { };
fill_n(cdb.begin(), cdb.size(), 0);
cdb[4] = static_cast<uint8_t>(sense_data.size());
const int status = RequestSense(cdb, sense_data);
Expand Down
28 changes: 14 additions & 14 deletions cpp/s2pdump/s2pdump_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ class S2pDumpExecutor
virtual ~S2pDumpExecutor() = default;

// Disk and tape support
virtual void TestUnitReady(vector<uint8_t>&) const = 0;
virtual int RequestSense(vector<uint8_t>&, span<uint8_t>) const = 0;
virtual bool Inquiry(vector<uint8_t>&, span<uint8_t>) const = 0;
virtual bool ModeSense6(vector<uint8_t>&, span<uint8_t>) const = 0;
virtual set<int> ReportLuns(vector<uint8_t>&, span<uint8_t>) = 0;
virtual void TestUnitReady(span<uint8_t>) const = 0;
virtual int RequestSense(span<uint8_t>, span<uint8_t>) const = 0;
virtual bool Inquiry(span<uint8_t>, span<uint8_t>) const = 0;
virtual bool ModeSense6(span<uint8_t>, span<uint8_t>) const = 0;
virtual set<int> ReportLuns(span<uint8_t>, span<uint8_t>) = 0;

// Disk support
virtual int ReadCapacity10(vector<uint8_t>&, span<uint8_t>) const = 0;
virtual int ReadCapacity16(vector<uint8_t>&, span<uint8_t>) const = 0;
virtual bool ReadWrite(vector<uint8_t>&, span<uint8_t>, int) = 0;
virtual void SynchronizeCache(vector<uint8_t>&) const = 0;
virtual int ReadCapacity10(span<uint8_t>, span<uint8_t>) const = 0;
virtual int ReadCapacity16(span<uint8_t>, span<uint8_t>) const = 0;
virtual bool ReadWrite(span<uint8_t>, span<uint8_t>, int) = 0;
virtual void SynchronizeCache(span<uint8_t>) const = 0;

// Tape support
virtual int Rewind(vector<uint8_t>&) const = 0;
virtual int WriteFilemark(vector<uint8_t>&) const = 0;
virtual bool Read(vector<uint8_t>&, span<uint8_t>, int) = 0;
virtual bool Write(vector<uint8_t>&, span<uint8_t>, int) = 0;
virtual int Rewind(span<uint8_t>) const = 0;
virtual int WriteFilemark(span<uint8_t>) const = 0;
virtual bool Read(span<uint8_t>, span<uint8_t>, int) = 0;
virtual bool Write(span<uint8_t>, span<uint8_t>, int) = 0;

void SpaceBack() const;
virtual void SpaceBack(vector<uint8_t>&) const = 0;
virtual void SpaceBack(span<uint8_t>) const = 0;

static void SetInt24(span<uint8_t>, int, int);

Expand Down
28 changes: 14 additions & 14 deletions cpp/s2pdump/sg_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,74 @@

using namespace memory_util;

void SgExecutor::TestUnitReady(vector<uint8_t> &cdb) const
void SgExecutor::TestUnitReady(span<uint8_t> cdb) const
{
sg_adapter.SendCommand(cdb, { }, 0, 1);
}

int SgExecutor::RequestSense(vector<uint8_t> &cdb, span<uint8_t> buf) const
int SgExecutor::RequestSense(span<uint8_t> cdb, span<uint8_t> buf) const
{
return sg_adapter.SendCommand(cdb, buf, static_cast<int>(buf.size()), 1).status;
}

bool SgExecutor::Inquiry(vector<uint8_t> &cdb, span<uint8_t> buf) const
bool SgExecutor::Inquiry(span<uint8_t> cdb, span<uint8_t> buf) const
{
return !sg_adapter.SendCommand(cdb, buf, static_cast<int>(buf.size()), 1).status;
}

bool SgExecutor::ModeSense6(vector<uint8_t> &cdb, span<uint8_t> buf) const
bool SgExecutor::ModeSense6(span<uint8_t> cdb, span<uint8_t> buf) const
{
return !sg_adapter.SendCommand(cdb, buf, static_cast<int>(buf.size()), 1).status;
}

set<int> SgExecutor::ReportLuns(vector<uint8_t>&, span<uint8_t>)
set<int> SgExecutor::ReportLuns(span<uint8_t>, span<uint8_t>)
{
return {0};
}

int SgExecutor::ReadCapacity10(vector<uint8_t> &cdb, span<uint8_t> buf) const
int SgExecutor::ReadCapacity10(span<uint8_t> cdb, span<uint8_t> buf) const
{
return sg_adapter.SendCommand(cdb, buf, 8, 1).status;
}

int SgExecutor::ReadCapacity16(vector<uint8_t> &cdb, span<uint8_t> buf) const
int SgExecutor::ReadCapacity16(span<uint8_t> cdb, span<uint8_t> buf) const
{
return sg_adapter.SendCommand(cdb, buf, 14, 1).status;
}

bool SgExecutor::ReadWrite(vector<uint8_t> &cdb, span<uint8_t> buf, int length)
bool SgExecutor::ReadWrite(span<uint8_t> cdb, span<uint8_t> buf, int length)
{
return !sg_adapter.SendCommand(cdb, buf, length, LONG_TIMEOUT).status;
}

void SgExecutor::SynchronizeCache(vector<uint8_t> &cdb) const
void SgExecutor::SynchronizeCache(span<uint8_t> cdb) const
{
sg_adapter.SendCommand(cdb, { }, 0, 3);
}

int SgExecutor::Rewind(vector<uint8_t> &cdb) const
int SgExecutor::Rewind(span<uint8_t> cdb) const
{
return !sg_adapter.SendCommand(cdb, { }, 0, LONG_TIMEOUT).status;
}

void SgExecutor::SpaceBack(vector<uint8_t> &cdb) const
void SgExecutor::SpaceBack(span<uint8_t> cdb) const
{
if (sg_adapter.SendCommand(cdb, { }, 0, LONG_TIMEOUT).status) {
throw IoException("Can't space back one block");
}
}

int SgExecutor::WriteFilemark(vector<uint8_t> &cdb) const
int SgExecutor::WriteFilemark(span<uint8_t> cdb) const
{
return sg_adapter.SendCommand(cdb, { }, 0, LONG_TIMEOUT).status;
}

bool SgExecutor::Read(vector<uint8_t> &cdb, span<uint8_t> buf, int length)
bool SgExecutor::Read(span<uint8_t> cdb, span<uint8_t> buf, int length)
{
return sg_adapter.SendCommand(cdb, buf, length, LONG_TIMEOUT).status;
}

bool SgExecutor::Write(vector<uint8_t> &cdb, span<uint8_t> buf, int length)
bool SgExecutor::Write(span<uint8_t> cdb, span<uint8_t> buf, int length)
{
return sg_adapter.SendCommand(cdb, buf, length, LONG_TIMEOUT).status;
}
Loading

0 comments on commit 2713338

Please sign in to comment.