diff --git a/lib/decoders/decoders.proto b/lib/decoders/decoders.proto index a8a94007..74c3f928 100644 --- a/lib/decoders/decoders.proto +++ b/lib/decoders/decoders.proto @@ -19,7 +19,7 @@ import "arch/zilogmcz/zilogmcz.proto"; import "lib/fluxsink/fluxsink.proto"; import "lib/common.proto"; -//NEXT: 29 +//NEXT: 30 message DecoderProto { optional double pulse_debounce_threshold = 1 [default = 0.30, (help) = "ignore pulses with intervals shorter than this, in fractions of a clock"]; @@ -61,5 +61,7 @@ message DecoderProto { (help) = "how many times to retry each track in the event of a read failure"]; optional string write_csv_to = 23 [(help) = "if set, write a CSV report of the disk state"]; + optional bool skip_unnecessary_tracks = 29 [default = true, + (help) = "don't read tracks if we already have all necessary sectors"]; } diff --git a/lib/readerwriter.cc b/lib/readerwriter.cc index 3db6d015..ad469af7 100644 --- a/lib/readerwriter.cc +++ b/lib/readerwriter.cc @@ -27,6 +27,12 @@ enum ReadResult BAD_AND_CAN_NOT_RETRY }; +enum BadSectorsState +{ + HAS_NO_BAD_SECTORS, + HAS_BAD_SECTORS +}; + /* In order to allow rereads in file-based flux sources, we need to persist the * FluxSourceIterator (as that's where the state for which read to return is * held). This class handles that. */ @@ -108,8 +114,7 @@ static std::set> collectSectors( return sector_set; } -/* Returns true if the result contains bad sectors. */ -bool combineRecordAndSectors( +BadSectorsState combineRecordAndSectors( TrackFlux& trackFlux, AbstractDecoder& decoder, const Location& location) { std::set> track_sectors; @@ -128,12 +133,12 @@ bool combineRecordAndSectors( trackFlux.sectors = collectSectors(track_sectors); if (trackFlux.sectors.empty()) - return true; + return HAS_BAD_SECTORS; for (const auto& sector : trackFlux.sectors) if (sector->status != Sector::OK) - return true; + return HAS_BAD_SECTORS; - return false; + return HAS_NO_BAD_SECTORS; } ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder, @@ -163,9 +168,13 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder, auto trackdataflux = decoder.decodeToSectors(fluxmap, location); trackFlux.trackDatas.push_back(trackdataflux); - if (!combineRecordAndSectors(trackFlux, decoder, location)) - return GOOD_READ; - if (fluxSourceIterator.hasNext()) + if (combineRecordAndSectors(trackFlux, decoder, location) == HAS_NO_BAD_SECTORS) + { + result = GOOD_READ; + if (config.decoder().skip_unnecessary_tracks()) + return result; + } + else if (fluxSourceIterator.hasNext()) result = BAD_AND_CAN_RETRY; }