Skip to content

Commit

Permalink
Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 26, 2025
1 parent 6bd9bd3 commit 0e60f75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
44 changes: 21 additions & 23 deletions cpp/s2pdump/s2pdump_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ string S2pDump::DumpRestoreDisk(fstream &file)
s2pdump_logger->info("Data transfer size: {}", sector_count * sector_size);
s2pdump_logger->info("Image file chunk size: {}", current_count);

if (const string &error = ReadWriteWithRetry(file, sector_offset, sector_count, sector_size, current_count); !error.empty()) {
if (const string &error = ReadWrite(file, sector_offset, sector_count, sector_size, current_count); !error.empty()) {
return error;
}

Expand All @@ -641,24 +641,6 @@ string S2pDump::DumpRestoreDisk(fstream &file)
return "";
}

string S2pDump::ReadWriteWithRetry(fstream &file, int sector_offset, int sector_count, int sector_size,
int current_count)
{
int r = 0;
while (true) {
const string &error = ReadWrite(file, sector_offset, sector_count, sector_size, current_count);
if (error.empty()) {
return "";
}

if (r == retries) {
return error;
}

++r;
}
}

string S2pDump::DumpRestoreTape(fstream &file)
{
cout << "Rewinding tape\n";
Expand Down Expand Up @@ -690,12 +672,28 @@ string S2pDump::ReadWrite(fstream &file, int sector_offset, uint32_t sector_coun
return "Can't read from file '" + filename + "': " + strerror(errno);
}

if (!s2pdump_executor->ReadWrite(buffer, sector_offset, sector_count, sector_count * sector_size, true)) {
return "Can't write to device: " + string(strerror(errno));
int r = 0;
while (r <= retries) {
if (s2pdump_executor->ReadWrite(buffer, sector_offset, sector_count, sector_count * sector_size, true)) {
break;
}

++r;
}

return "Can't write to device";
} else {
if (!s2pdump_executor->ReadWrite(buffer, sector_offset, sector_count, sector_count * sector_size, false)) {
return "Can't read from device: " + string(strerror(errno));
int r = 0;
while (r <= retries) {
if (s2pdump_executor->ReadWrite(buffer, sector_offset, sector_count, sector_count * sector_size, false)) {
break;
}

++r;
}

if (r > retries) {
return "Can't read from device";
}

file.write((const char*)buffer.data(), byte_count);
Expand Down
1 change: 0 additions & 1 deletion cpp/s2pdump/s2pdump_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class S2pDump
void DisplayProperties(int, int) const;
string DumpRestore();
string DumpRestoreDisk(fstream&);
string ReadWriteWithRetry(fstream&, int, int, int, int);
string DumpRestoreTape(fstream&);
bool GetDeviceInfo();

Expand Down

0 comments on commit 0e60f75

Please sign in to comment.