Skip to content

Commit

Permalink
Fix handling of tracks out-of-range for format specified.
Browse files Browse the repository at this point in the history
Fixes #279
  • Loading branch information
keirf committed Feb 6, 2023
1 parent 7515b00 commit b0b6592
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/greaseweazle/codec/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/greaseweazle/tools/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/greaseweazle/tools/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 6 additions & 2 deletions src/greaseweazle/tools/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b0b6592

Please sign in to comment.