Skip to content

Commit

Permalink
Clear I/O error status after I/O failure
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Oct 11, 2024
1 parent b5951c5 commit 2170959
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cpp/devices/disk_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ bool DiskTrack::Load(const string &path, uint64_t &cache_miss_read_count)

ifstream in(path, ios::binary);
if (in.fail()) {
in.clear();
return false;
}

in.seekg(offset);
if (in.fail()) {
in.clear();
return false;
}
in.read((char*)dt.buffer, length);
if (in.fail()) {
in.clear();
return false;
}

Expand Down Expand Up @@ -118,6 +121,7 @@ bool DiskTrack::Save(const string &path, uint64_t &cache_miss_write_count)

ofstream out(path, ios::in | ios::out | ios::binary);
if (out.fail()) {
out.clear();
return false;
}

Expand All @@ -131,6 +135,7 @@ bool DiskTrack::Save(const string &path, uint64_t &cache_miss_write_count)

out.seekp(offset + (i << dt.size));
if (out.fail()) {
out.clear();
return false;
}

Expand All @@ -148,6 +153,7 @@ bool DiskTrack::Save(const string &path, uint64_t &cache_miss_write_count)

out.write((const char*)&dt.buffer[i << dt.size], total);
if (out.fail()) {
out.clear();
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions cpp/devices/linux_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int LinuxCache::Read(span<uint8_t> buf, uint64_t start, int length)
file.seekg(sector_size * start, ios::beg);
file.read((char*)buf.data(), length);
if (file.fail()) {
file.clear();
++read_error_count;
return 0;
}
Expand All @@ -59,6 +60,7 @@ int LinuxCache::Write(span<const uint8_t> buf, uint64_t start, int length)
file.seekp(sector_size * start, ios::beg);
file.write((const char*)buf.data(), length);
if (file.fail()) {
file.clear();
++write_error_count;
return 0;
}
Expand All @@ -74,6 +76,7 @@ bool LinuxCache::Flush()
{
file.flush();
if (file.fail()) {
file.clear();
++write_error_count;
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/devices/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ int Printer::WriteData(span<const uint8_t> buf, scsi_command command)

out.open(filename, ios::binary);
if (out.fail()) {
out.clear();
++print_error_count;
throw scsi_exception(sense_key::aborted_command, asc::printer_write_failed);
}
Expand All @@ -208,6 +209,7 @@ int Printer::WriteData(span<const uint8_t> buf, scsi_command command)

out.write((const char*)buf.data(), length);
if (out.fail()) {
out.clear();
++print_error_count;
throw scsi_exception(sense_key::aborted_command, asc::printer_write_failed);
}
Expand Down

0 comments on commit 2170959

Please sign in to comment.