| 431 | } |
| 432 | |
| 433 | void writeTracks(const DiskLayout& diskLayout, |
| 434 | |
| 435 | FluxSinkFactory& fluxSinkFactory, |
| 436 | std::function<std::unique_ptr<const Fluxmap>( |
| 437 | const std::shared_ptr<const LogicalTrackLayout>&)> producer, |
| 438 | std::function<bool(const std::shared_ptr<const LogicalTrackLayout>&)> |
| 439 | verifier, |
| 440 | const std::vector<CylinderHead>& logicalLocations) |
| 441 | { |
| 442 | log(BeginOperationLogMessage{"Encoding and writing to disk"}); |
| 443 | |
| 444 | if (fluxSinkFactory.isHardware()) |
| 445 | measureDiskRotation(); |
| 446 | { |
| 447 | auto fluxSink = fluxSinkFactory.create(); |
| 448 | int index = 0; |
| 449 | for (auto& ch : logicalLocations) |
| 450 | { |
| 451 | log(OperationProgressLogMessage{ |
| 452 | index * 100 / (unsigned)logicalLocations.size()}); |
| 453 | index++; |
| 454 | |
| 455 | testForEmergencyStop(); |
| 456 | |
| 457 | const auto& ltl = diskLayout.layoutByLogicalLocation.at(ch); |
| 458 | int retriesRemaining = globalConfig()->decoder().retries(); |
| 459 | for (;;) |
| 460 | { |
| 461 | for (int offset = 0; offset < ltl->groupSize; |
| 462 | offset += diskLayout.headWidth) |
| 463 | { |
| 464 | unsigned physicalCylinder = ltl->physicalCylinder + offset; |
| 465 | unsigned physicalHead = ltl->physicalHead; |
| 466 | |
| 467 | log(BeginWriteOperationLogMessage{ |
| 468 | physicalCylinder, ltl->physicalHead}); |
| 469 | |
| 470 | if (offset == globalConfig()->drive().group_offset()) |
| 471 | { |
| 472 | auto fluxmap = producer(ltl); |
| 473 | if (!fluxmap) |
| 474 | goto erase; |
| 475 | |
| 476 | fluxSink->addFlux( |
| 477 | physicalCylinder, physicalHead, *fluxmap); |
| 478 | log("writing {0} ms in {1} bytes", |
| 479 | int(fluxmap->duration() / 1e6), |
| 480 | fluxmap->bytes()); |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | erase: |
| 485 | /* Erase this track rather than writing. */ |
| 486 | |
| 487 | Fluxmap blank; |
| 488 | fluxSink->addFlux( |
| 489 | physicalCylinder, physicalHead, blank); |
| 490 | log("erased"); |
no test coverage detected