Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 10, 2024
1 parent c79bad7 commit 0701d37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
16 changes: 12 additions & 4 deletions cpp/s2pdump/s2pdump_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ string S2pDump::DumpRestoreTape(fstream &fs)
{
cout << "Starting " << (restore ? "restore" : "dump") << "\n";

tape_executor->Rewind();
if (tape_executor->Rewind()) {
return "Can't rewind tape";
}

while (true) {
const int length = tape_executor->ReadWrite(buffer, restore);
Expand All @@ -597,13 +599,19 @@ string S2pDump::DumpRestoreTape(fstream &fs)
}
else {
if (length) {
WriteGoodData(fs, buffer, length);
if (!WriteGoodData(fs, buffer, length)) {
return "Can't write SIMH data";
}
}
else {
WriteFilemark(fs);
if (!WriteFilemark(fs)) {
return "Can't write SIMH type mark";
}

// Space over filemark
tape_executor->Space(true, false);
if (tape_executor->Space(true, false)) {
return "Can't space over filemark";
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions cpp/s2pdump/tape_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
using namespace spdlog;
using namespace memory_util;

void TapeExecutor::Rewind()
int TapeExecutor::Rewind()
{
vector<uint8_t> cdb(6);

initiator_executor->Execute(scsi_command::rewind, cdb, { }, 0, 300);
return initiator_executor->Execute(scsi_command::rewind, cdb, { }, 0, 300);
}

void TapeExecutor::Space(bool filemark, bool reverse)
int TapeExecutor::Space(bool filemark, bool reverse)
{
vector<uint8_t> cdb(6);
cdb[1] = filemark ? 0b001 : 0b000;
Expand All @@ -33,7 +33,7 @@ void TapeExecutor::Space(bool filemark, bool reverse)
cdb[4] = 0x01;
}

initiator_executor->Execute(scsi_command::space_6, cdb, { }, 0, 3);
return initiator_executor->Execute(scsi_command::space_6, cdb, { }, 0, 3);
}

int TapeExecutor::ReadWrite(span<uint8_t> buffer, bool is_write)
Expand Down
4 changes: 2 additions & 2 deletions cpp/s2pdump/tape_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TapeExecutor : public S2pDumpExecutor
{
}

void Rewind();
void Space(bool, bool);
int Rewind();
int Space(bool, bool);
int ReadWrite(span<uint8_t>, bool);

private:
Expand Down

0 comments on commit 0701d37

Please sign in to comment.