Begin cleaning up the Layout stuff.

This commit is contained in:
David Given
2022-09-15 21:45:12 +02:00
parent 8eb17bf104
commit 88fc7ff9c3
13 changed files with 42 additions and 42 deletions

View File

@@ -114,7 +114,7 @@ public:
IbmEncoderProto::TrackdataProto trackdata;
getEncoderTrackData(trackdata, location.logicalTrack, location.logicalSide);
auto& trackLayout =
auto trackLayout =
Layout::getLayoutOfTrack(location.logicalTrack, location.logicalSide);
auto writeBytes = [&](const Bytes& bytes)
@@ -151,7 +151,7 @@ public:
uint8_t sectorSize = 0;
{
int s = trackLayout.sectorSize >> 7;
int s = trackLayout->sectorSize >> 7;
while (s > 1)
{
s >>= 1;
@@ -237,7 +237,7 @@ public:
bw.write_8(damUnencoded);
Bytes truncatedData =
sectorData->data.slice(0, trackLayout.sectorSize);
sectorData->data.slice(0, trackLayout->sectorSize);
bw += truncatedData;
uint16_t crc = crc16(CCITT_POLY, data);
bw.write_be16(crc);

View File

@@ -133,7 +133,7 @@ std::shared_ptr<const TrackDataFlux> Decoder::decodeToSectors(
if (_sector->status != Sector::MISSING)
{
auto& trackLayout = Layout::getLayoutOfTrack(
auto trackLayout = Layout::getLayoutOfTrack(
_sector->logicalTrack, _sector->logicalSide);
_trackdata->sectors.push_back(_sector);
}
@@ -224,12 +224,12 @@ uint64_t Decoder::readRaw64()
std::set<LogicalLocation> Decoder::requiredSectors(
const Location& location) const
{
const auto& trackLayout =
const auto trackLayout =
Layout::getLayoutOfTrackPhysical(location.physicalTrack, location.physicalSide);
std::set<LogicalLocation> results;
for (unsigned sectorId : trackLayout.logicalSectorOrder)
for (unsigned sectorId : trackLayout->logicalSectorOrder)
results.insert(LogicalLocation{
trackLayout.logicalTrack, trackLayout.logicalSide, sectorId});
trackLayout->logicalTrack, trackLayout->logicalSide, sectorId});
return results;
}

View File

@@ -67,9 +67,9 @@ std::vector<std::shared_ptr<const Sector>> Encoder::collectSectors(
{
std::vector<std::shared_ptr<const Sector>> sectors;
const auto& trackLayout =
const auto trackLayout =
Layout::getLayoutOfTrack(location.logicalTrack, location.logicalSide);
for (unsigned sectorId : trackLayout.diskSectorOrder)
for (unsigned sectorId : trackLayout->diskSectorOrder)
{
const auto& sector = getSector(location, image, sectorId);
if (!sector)

View File

@@ -29,9 +29,9 @@ void Image::createBlankImage()
{
unsigned track = trackAndHead.first;
unsigned side = trackAndHead.second;
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
Bytes blank(trackLayout.sectorSize);
for (unsigned sectorId : trackLayout.logicalSectorOrder)
auto trackLayout = Layout::getLayoutOfTrack(track, side);
Bytes blank(trackLayout->sectorSize);
for (unsigned sectorId : trackLayout->logicalSectorOrder)
put(track, side, sectorId)->data = blank;
}
}
@@ -62,7 +62,7 @@ std::shared_ptr<const Sector> Image::get(
std::shared_ptr<Sector> Image::put(
unsigned track, unsigned side, unsigned sectorid)
{
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
auto trackLayout = Layout::getLayoutOfTrack(track, side);
key_t key = std::make_tuple(track, side, sectorid);
std::shared_ptr<Sector> sector = std::make_shared<Sector>();
sector->logicalTrack = track;

View File

@@ -107,12 +107,12 @@ std::unique_ptr<Image> ImageReader::readMappedImage()
std::set<std::shared_ptr<const Sector>> sectors;
for (const auto& e : *rawImage)
{
auto& trackLayout =
auto trackLayout =
Layout::getLayoutOfTrack(e->logicalTrack, e->logicalSide);
auto newSector = std::make_shared<Sector>();
*newSector = *e;
newSector->logicalSector =
trackLayout.filesystemToLogicalSectorMap.at(e->logicalSector);
trackLayout->filesystemToLogicalSectorMap.at(e->logicalSector);
sectors.insert(newSector);
}

View File

@@ -39,10 +39,10 @@ public:
if (inputFile.eof())
break;
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
for (int sectorId : trackLayout.logicalSectorOrder)
auto trackLayout = Layout::getLayoutOfTrack(track, side);
for (int sectorId : trackLayout->logicalSectorOrder)
{
Bytes data(trackLayout.sectorSize);
Bytes data(trackLayout->sectorSize);
inputFile.read((char*)data.begin(), data.size());
const auto& sector = image->put(track, side, sectorId);

View File

@@ -213,12 +213,12 @@ void ImageWriter::writeMappedImage(const Image& image)
std::set<std::shared_ptr<const Sector>> sectors;
for (const auto& e : image)
{
auto& trackLayout =
auto trackLayout =
Layout::getLayoutOfTrack(e->logicalTrack, e->logicalSide);
auto newSector = std::make_shared<Sector>();
*newSector = *e;
newSector->logicalSector =
trackLayout.logicalToFilesystemSectorMap.at(e->logicalSector);
trackLayout->logicalToFilesystemSectorMap.at(e->logicalSector);
sectors.insert(newSector);
}

View File

@@ -36,14 +36,14 @@ public:
int track = p.first;
int side = p.second;
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
for (int sectorId : trackLayout.logicalSectorOrder)
auto trackLayout = Layout::getLayoutOfTrack(track, side);
for (int sectorId : trackLayout->logicalSectorOrder)
{
const auto& sector = image.get(track, side, sectorId);
if (sector)
sector->data.slice(0, trackLayout.sectorSize).writeTo(outputFile);
sector->data.slice(0, trackLayout->sectorSize).writeTo(outputFile);
else
outputFile.seekp(trackLayout.sectorSize, std::ios::cur);
outputFile.seekp(trackLayout->sectorSize, std::ios::cur);
}
}

View File

@@ -4,7 +4,7 @@
#include "lib/environment.h"
#include <fmt/format.h>
static Local<std::map<std::pair<int, int>, std::unique_ptr<Layout>>>
static Local<std::map<std::pair<int, int>, std::shared_ptr<Layout>>>
layoutCache;
static unsigned getTrackStep()
@@ -141,13 +141,13 @@ std::vector<unsigned> Layout::expandSectorList(
return sectors;
}
const Layout& Layout::getLayoutOfTrack(
std::shared_ptr<const Layout> Layout::getLayoutOfTrack(
unsigned logicalTrack, unsigned logicalSide)
{
auto& layout = (*layoutCache)[std::make_pair(logicalTrack, logicalSide)];
if (!layout)
{
layout.reset(new Layout());
layout = std::make_shared<Layout>();
LayoutProto::LayoutdataProto layoutdata;
for (const auto& f : config.layout().layoutdata())
@@ -203,10 +203,10 @@ const Layout& Layout::getLayoutOfTrack(
}
}
return *layout;
return layout;
}
const Layout& Layout::getLayoutOfTrackPhysical(
std::shared_ptr<const Layout> Layout::getLayoutOfTrackPhysical(
unsigned physicalTrack, unsigned physicalSide)
{
return getLayoutOfTrack(remapTrackPhysicalToLogical(physicalTrack),

View File

@@ -45,11 +45,11 @@ public:
unsigned guessedTracks = 0, unsigned guessedSides = 0);
/* Returns the layout of a given track. */
static const Layout& getLayoutOfTrack(
static std::shared_ptr<const Layout> getLayoutOfTrack(
unsigned logicalTrack, unsigned logicalHead);
/* Returns the layout of a given track via physical location. */
static const Layout& getLayoutOfTrackPhysical(
static std::shared_ptr<const Layout> getLayoutOfTrackPhysical(
unsigned physicalTrack, unsigned physicalSide);
/* Expand a SectorList into the actual sector IDs. */

View File

@@ -91,7 +91,7 @@ public:
dev.devType = DEVTYPE_FLOPDD;
dev.cylinders = config.layout().tracks();
dev.heads = config.layout().sides();
dev.sectors = Layout::getLayoutOfTrack(0, 0).numSectors;
dev.sectors = Layout::getLayoutOfTrack(0, 0)->numSectors;
adfInitDevice(&dev, nullptr, false);
int res = adfCreateFlop(&dev, (char*)volumeName.c_str(), 0);
if (res != RC_OK)

View File

@@ -62,7 +62,7 @@ public:
{
unsigned track = trackid.first;
unsigned side = trackid.second;
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
auto trackLayout = Layout::getLayoutOfTrack(track, side);
locations.insert(Layout::computeLocationFor(track, side));
/* If we don't have all the sectors of this track, we may need to
@@ -72,7 +72,7 @@ public:
if (!imageContainsAllSectorsOf(_changedSectors,
track,
side,
trackLayout.logicalSectorOrder))
trackLayout->logicalSectorOrder))
{
/* If we don't have any loaded sectors for this track, pre-read
* it. */
@@ -83,7 +83,7 @@ public:
/* Now merge the loaded track with the changed one, and write
* the result back. */
for (unsigned sectorId : trackLayout.logicalSectorOrder)
for (unsigned sectorId : trackLayout->logicalSectorOrder)
{
if (!_changedSectors.contains(track, side, sectorId))
_changedSectors.put(track, side, sectorId)->data =

View File

@@ -164,12 +164,12 @@ Filesystem::Filesystem(std::shared_ptr<SectorInterface> sectors):
int track = p.first;
int side = p.second;
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
if (trackLayout.numSectors == 0)
auto trackLayout = Layout::getLayoutOfTrack(track, side);
if (trackLayout->numSectors == 0)
Error() << "FS: filesystem support cannot be used without concrete "
"layout information";
for (int sectorId : trackLayout.filesystemSectorOrder)
for (int sectorId : trackLayout->filesystemSectorOrder)
_locations.push_back(std::make_tuple(track, side, sectorId));
}
}
@@ -273,9 +273,9 @@ Bytes Filesystem::getLogicalSector(uint32_t number, uint32_t count)
int track = std::get<0>(it);
int side = std::get<1>(it);
int sector = std::get<2>(it);
auto& trackLayout = Layout::getLayoutOfTrack(track, side);
auto trackLayout = Layout::getLayoutOfTrack(track, side);
bw += _sectors->get(track, side, sector)
->data.slice(0, trackLayout.sectorSize);
->data.slice(0, trackLayout->sectorSize);
}
return data;
}
@@ -293,7 +293,7 @@ void Filesystem::putLogicalSector(uint32_t number, const Bytes& data)
int track = std::get<0>(it);
int side = std::get<1>(it);
int sector = std::get<2>(it);
int sectorSize = Layout::getLayoutOfTrack(track, side).sectorSize;
int sectorSize = Layout::getLayoutOfTrack(track, side)->sectorSize;
_sectors->put(track, side, sector)->data = data.slice(pos, sectorSize);
pos += sectorSize;
@@ -322,7 +322,7 @@ unsigned Filesystem::getLogicalSectorCount()
unsigned Filesystem::getLogicalSectorSize(unsigned track, unsigned side)
{
return Layout::getLayoutOfTrack(track, side).sectorSize;
return Layout::getLayoutOfTrack(track, side)->sectorSize;
}
void Filesystem::eraseEverythingOnDisk()