mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-20 10:17:05 +00:00
Extended Storage::Disk::Disk to permit write-back of modified tracks, exposed some interface via Storage::Disk::Drive.
This commit is contained in:
+29
-1
@@ -10,9 +10,23 @@
|
||||
|
||||
using namespace Storage::Disk;
|
||||
|
||||
int Disk::get_id_for_track_at_position(unsigned int head, unsigned int position)
|
||||
{
|
||||
return (int)(position * get_head_count() + head);
|
||||
}
|
||||
|
||||
void Disk::set_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track)
|
||||
{
|
||||
if(!get_is_read_only()) return;
|
||||
|
||||
int address = get_id_for_track_at_position(head, position);
|
||||
cached_tracks_[address] = track;
|
||||
modified_tracks_.insert(address);
|
||||
}
|
||||
|
||||
std::shared_ptr<Track> Disk::get_track_at_position(unsigned int head, unsigned int position)
|
||||
{
|
||||
int address = (int)(position * get_head_count() + head);
|
||||
int address = get_id_for_track_at_position(head, position);
|
||||
std::map<int, std::shared_ptr<Track>>::iterator cached_track = cached_tracks_.find(address);
|
||||
if(cached_track != cached_tracks_.end()) return cached_track->second;
|
||||
|
||||
@@ -20,3 +34,17 @@ std::shared_ptr<Track> Disk::get_track_at_position(unsigned int head, unsigned i
|
||||
cached_tracks_[address] = track;
|
||||
return track;
|
||||
}
|
||||
|
||||
std::shared_ptr<Track> Disk::get_modified_track_at_position(unsigned int head, unsigned int position)
|
||||
{
|
||||
int address = get_id_for_track_at_position(head, position);
|
||||
if(modified_tracks_.find(address) == modified_tracks_.end()) return nullptr;
|
||||
std::map<int, std::shared_ptr<Track>>::iterator cached_track = cached_tracks_.find(address);
|
||||
if(cached_track == cached_tracks_.end()) return nullptr;
|
||||
return cached_track->second;
|
||||
}
|
||||
|
||||
bool Disk::get_is_modified()
|
||||
{
|
||||
return !modified_tracks_.empty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user