1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Ensured that FileHolder gets a writeable file reference if one is possible, and records whether the file in hand is read-only. So now the SSD class can answer honestly.

This commit is contained in:
Thomas Harte 2016-12-28 20:09:14 -05:00
parent 4adcb46665
commit bfe6c0a0c1
3 changed files with 15 additions and 5 deletions

View File

@ -65,7 +65,7 @@ unsigned int SSD::get_head_count()
bool SSD::get_is_read_only()
{
return false;
return is_read_only_;
}
std::shared_ptr<Track> SSD::get_uncached_track_at_position(unsigned int head, unsigned int position)
@ -85,9 +85,12 @@ std::shared_ptr<Track> SSD::get_uncached_track_at_position(unsigned int head, un
new_sector.sector = (uint8_t)sector;
new_sector.data.resize(256);
fread(&new_sector.data[0], 1, 256, file_);
// if(feof(file_))
// new_sector.data[0];
fread(new_sector.data.data(), 1, 256, file_);
// zero out if this wasn't present in the disk image; it's still appropriate to put a sector
// on disk because one will have been placed during formatting, but there's no reason to leak
// information from outside the emulated machine's world
if(feof(file_)) memset(new_sector.data.data(), 0, 256);
sectors.push_back(std::move(new_sector));
}

View File

@ -20,7 +20,13 @@ FileHolder::~FileHolder()
FileHolder::FileHolder(const char *file_name) : file_(nullptr)
{
stat(file_name, &file_stats_);
is_read_only_ = false;
file_ = fopen(file_name, "rb+");
if(!file_)
{
is_read_only_ = true;
file_ = fopen(file_name, "rb");
}
if(!file_) throw ErrorCantOpen;
}

View File

@ -67,6 +67,7 @@ class FileHolder {
FILE *file_;
struct stat file_stats_;
bool is_read_only_;
};
}