diff --git a/cpp/devices/disk_track.cpp b/cpp/devices/disk_track.cpp index f3858e06..9b42fe16 100644 --- a/cpp/devices/disk_track.cpp +++ b/cpp/devices/disk_track.cpp @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/cpp/devices/linux_cache.cpp b/cpp/devices/linux_cache.cpp index d532dd59..9a85d856 100644 --- a/cpp/devices/linux_cache.cpp +++ b/cpp/devices/linux_cache.cpp @@ -45,6 +45,7 @@ int LinuxCache::Read(span 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; } @@ -59,6 +60,7 @@ int LinuxCache::Write(span 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; } @@ -74,6 +76,7 @@ bool LinuxCache::Flush() { file.flush(); if (file.fail()) { + file.clear(); ++write_error_count; return false; } diff --git a/cpp/devices/printer.cpp b/cpp/devices/printer.cpp index 4b8129b0..516336f3 100644 --- a/cpp/devices/printer.cpp +++ b/cpp/devices/printer.cpp @@ -197,6 +197,7 @@ int Printer::WriteData(span 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); } @@ -208,6 +209,7 @@ int Printer::WriteData(span 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); }