From b0b6592892fbf21716b4dec3e8235e89d9d83d26 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 6 Feb 2023 09:16:18 +0000 Subject: [PATCH] Fix handling of tracks out-of-range for format specified. Fixes #279 --- src/greaseweazle/codec/formats.py | 3 ++- src/greaseweazle/tools/convert.py | 4 ++++ src/greaseweazle/tools/read.py | 15 +++++++++++---- src/greaseweazle/tools/write.py | 8 ++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/greaseweazle/codec/formats.py b/src/greaseweazle/codec/formats.py index 8b977e20..d95d905f 100644 --- a/src/greaseweazle/codec/formats.py +++ b/src/greaseweazle/codec/formats.py @@ -60,7 +60,8 @@ def mk_track(self, cyl, head): def decode_track(self, cyl, head, track): t = self.mk_track(cyl, head) - t.decode_raw(track) + if t is not None: + t.decode_raw(track) return t @property diff --git a/src/greaseweazle/tools/convert.py b/src/greaseweazle/tools/convert.py index a9f64d78..eff5f076 100644 --- a/src/greaseweazle/tools/convert.py +++ b/src/greaseweazle/tools/convert.py @@ -57,6 +57,10 @@ def convert(args, in_image, out_image, decoder=None): print("T%u.%u: %s" % (cyl, head, track.summary_string())) else: dat = decoder(cyl, head, track) + if dat is None: + print("T%u.%u: WARNING: out of range for format '%s': Track " + "skipped" % (cyl, head, args.format)) + continue for pll in plls[1:]: if dat.nr_missing() == 0: break diff --git a/src/greaseweazle/tools/read.py b/src/greaseweazle/tools/read.py index a8a434ea..e2faaf71 100644 --- a/src/greaseweazle/tools/read.py +++ b/src/greaseweazle/tools/read.py @@ -9,7 +9,7 @@ description = "Read a disk to the specified image file." -import sys +import sys, copy from greaseweazle.tools import util from greaseweazle import error @@ -60,6 +60,10 @@ def read_with_retry(usb, args, t, decoder): return flux, flux dat = decoder(cyl, head, flux) + if dat is None: + print("T%u.%u: WARNING: Out of range for for format '%s': No format " + "conversion applied" % (cyl, head, args.format)) + return flux, None for pll in plls[1:]: if dat.nr_missing() == 0: break @@ -156,9 +160,12 @@ def read_to_image(usb, args, image, decoder=None): for t in args.tracks: cyl, head = t.cyl, t.head flux, dat = read_with_retry(usb, args, t, decoder) - if decoder is not None: + if decoder is not None and dat is not None: summary[cyl,head] = dat - image.emit_track(cyl, head, flux if args.raw else dat) + if args.raw: + image.emit_track(cyl, head, flux) + elif dat is not None: + image.emit_track(cyl, head, dat) if decoder is not None: print_summary(args, summary) @@ -220,7 +227,7 @@ def main(argv): % (args.format, formats.print_formats( args.diskdefs))) decoder = args.fmt_cls.decode_track - def_tracks = args.fmt_cls.tracks + def_tracks = copy.copy(args.fmt_cls.tracks) if args.revs is None: args.revs = args.fmt_cls.default_revs if def_tracks is None: def_tracks = util.TrackSet('c=0-81:h=0-1') diff --git a/src/greaseweazle/tools/write.py b/src/greaseweazle/tools/write.py index 7a3e0819..e02e1c33 100644 --- a/src/greaseweazle/tools/write.py +++ b/src/greaseweazle/tools/write.py @@ -9,7 +9,7 @@ description = "Write a disk from the specified image file." -import sys +import sys, copy from greaseweazle.tools import util from greaseweazle import error, track @@ -57,6 +57,10 @@ def write_from_image(usb, args, image): if args.raw_image_class and args.fmt_cls is not None: track = args.fmt_cls.decode_track(cyl, head, track) + if track is None: + print("T%u.%u: WARNING: out of range for format '%s': Track " + "skipped" % (cyl, head, args.format)) + continue error.check(track.nr_missing() == 0, 'T%u.%u: %u missing sectors in input image' % (cyl, head, track.nr_missing())) @@ -208,7 +212,7 @@ def main(argv): Known formats:\n%s""" % (args.format, formats.print_formats( args.diskdefs))) - def_tracks = args.fmt_cls.tracks + def_tracks = copy.copy(args.fmt_cls.tracks) if def_tracks is None: def_tracks = util.TrackSet('c=0-81:h=0-1') if args.tracks is not None: