#!/usr/bin/env python # Verify that a mkisofs image has been burnt correctly to CD, automatically # ignoring errors within the padding at the end of the image. # Adam Sampson import sys, os, progress if len(sys.argv) != 3: print >>sys.stderr, "Usage: verify-iso ISO DEVICE" sys.exit(1) block = 4096 fi = open(sys.argv[1]) size = os.fstat(fi.fileno()).st_size prog = progress.Progress(size, sys.argv[1]) fo = open(sys.argv[2]) start = 0 fi.seek(start) fo.seek(start) done = start while done < size: n = block if n > (size - done): n = size - done di = fi.read(n) fault = "end of disc" try: do = fo.read(n) except IOError: do = "" fault = "read error" if len(do) < n: prog.close() pos = size + len(do) if (size - pos) < (300 * 1024): # It appears Linux's CD devices won't read the end of # the disc correctly -- so mkisofs pads its images by # 300KiB to get around it. Ignore read errors within # that pad. print >>sys.stderr, "Ignored %s within 300KiB pad" % (fault,) break else: print >>sys.stderr, "Unexpected %s at %d of %d" % (fault, pos, size) sys.exit(1) if di != do: prog.close() print >>sys.stderr, "Files differ between %d and %d" % (done, done + n) i = 0 while i < n: b = 16 if (n - i) < b: b = n - i def fmt(d): s = "%10d: " % (size + i,) for j in range(b): s += " %02d" % (ord(d[i + j]),) return s print >>sys.stderr, "ISO: " + fmt(di) print >>sys.stderr, "Disc: " + fmt(do) i += b sys.exit(1) done += len(di) prog.update(done) fi.close() fo.close() prog.close() sys.exit(0)