MCPcopy Create free account
hub / github.com/davidgiven/fluxengine / writeImage

Method writeImage

lib/imagewriter/imgimagewriter.cc:21–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 ImgImageWriter(const ImageWriterProto& config): ImageWriter(config) {}
20
21 void writeImage(const Image& image) override
22 {
23 const Geometry geometry = image.getGeometry();
24
25 auto& layout = globalConfig()->layout();
26 int tracks =
27 layout.has_tracks() ? layout.tracks() : geometry.numCylinders;
28 int sides = layout.has_sides() ? layout.sides() : geometry.numHeads;
29
30 std::ofstream outputFile(
31 _config.filename(), std::ios::out | std::ios::binary);
32 if (!outputFile.is_open())
33 error("cannot open output file");
34
35 const auto diskLayout = createDiskLayout();
36 bool in_filesystem_order = _config.img().filesystem_sector_order();
37
38 for (auto& logicalLocation :
39 in_filesystem_order ? diskLayout->logicalLocationsInFilesystemOrder
40 : diskLayout->logicalLocations)
41 {
42 auto& ltl = diskLayout->layoutByLogicalLocation.at(logicalLocation);
43
44 for (unsigned sectorId : in_filesystem_order
45 ? ltl->filesystemSectorOrder
46 : ltl->naturalSectorOrder)
47 {
48 const auto& sector = image.get(
49 logicalLocation.cylinder, logicalLocation.head, sectorId);
50 if (sector)
51 sector->data.slice(0, ltl->sectorSize).writeTo(outputFile);
52 else
53 outputFile.seekp(ltl->sectorSize, std::ios::cur);
54 }
55 }
56
57 log("IMG: wrote {} tracks, {} sides, {} kB total to {}",
58 tracks,
59 sides,
60 outputFile.tellp() / 1024,
61 _config.filename());
62 }
63};
64
65std::unique_ptr<ImageWriter> ImageWriter::createImgImageWriter(

Callers 2

flushChangesMethod · 0.45
readDiskCommandFunction · 0.45

Calls 6

errorFunction · 0.85
createDiskLayoutFunction · 0.85
writeToMethod · 0.80
sliceMethod · 0.80
logFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected