Added option to show vtoc

This commit is contained in:
Rob McMullen 2017-02-26 14:14:25 -08:00
parent 74b0a63ef6
commit e9af557200
2 changed files with 13 additions and 6 deletions

View File

@ -196,6 +196,7 @@ def run():
parser.add_argument("-b", "--bytes", nargs="+", action="append", help="data file(s) to add to assembly, specify as file@addr (requires -o to specify filename stored on disk image)") parser.add_argument("-b", "--bytes", nargs="+", action="append", help="data file(s) to add to assembly, specify as file@addr (requires -o to specify filename stored on disk image)")
parser.add_argument("-o", "--output", action="store", default="", help="output file name for those commands that need it") parser.add_argument("-o", "--output", action="store", default="", help="output file name for those commands that need it")
parser.add_argument("--shred", action="store_true", default=False, help="fill empty sectors with 0") parser.add_argument("--shred", action="store_true", default=False, help="fill empty sectors with 0")
parser.add_argument("--vtoc", action="store_true", default=False, help="show the VTOC")
options, extra_args = parser.parse_known_args() options, extra_args = parser.parse_known_args()
print options, extra_args print options, extra_args
@ -240,3 +241,7 @@ def run():
if options.shred: if options.shred:
shred_image(parser.image) shred_image(parser.image)
if options.vtoc:
vtoc = parser.image.get_vtoc_object()
print vtoc

View File

@ -324,6 +324,11 @@ class DiskImageBase(object):
self.bytes[:], self.style[:] = state self.bytes[:], self.style[:] = state
return return
def get_vtoc_object(self):
vtoc_segments = self.get_vtoc_segments()
vtoc = self.vtoc_class(self.header, vtoc_segments)
return vtoc
def write_file(self, filename, filetype, data): def write_file(self, filename, filetype, data):
"""Write data to a file on disk """Write data to a file on disk
@ -338,8 +343,7 @@ class DiskImageBase(object):
dirent = directory.add_dirent(filename, filetype) dirent = directory.add_dirent(filename, filetype)
data = to_numpy(data) data = to_numpy(data)
sector_list = self.build_sectors(data) sector_list = self.build_sectors(data)
vtoc_segments = self.get_vtoc_segments() vtoc = self.get_vtoc_object()
vtoc = self.vtoc_class(self.header, vtoc_segments)
directory.save_dirent(self, dirent, vtoc, sector_list) directory.save_dirent(self, dirent, vtoc, sector_list)
self.write_sector_list(sector_list) self.write_sector_list(sector_list)
self.write_sector_list(vtoc) self.write_sector_list(vtoc)
@ -374,8 +378,7 @@ class DiskImageBase(object):
self.get_directory(directory) self.get_directory(directory)
dirent = directory.find_dirent(filename) dirent = directory.find_dirent(filename)
sector_list = dirent.get_sectors_in_vtoc(self) sector_list = dirent.get_sectors_in_vtoc(self)
vtoc_segments = self.get_vtoc_segments() vtoc = self.get_vtoc_object()
vtoc = self.vtoc_class(self.header, vtoc_segments)
directory.remove_dirent(self, dirent, vtoc, sector_list) directory.remove_dirent(self, dirent, vtoc, sector_list)
self.write_sector_list(vtoc) self.write_sector_list(vtoc)
self.write_sector_list(directory) self.write_sector_list(directory)
@ -388,8 +391,7 @@ class DiskImageBase(object):
def shred(self, fill_value=0): def shred(self, fill_value=0):
state = self.begin_transaction() state = self.begin_transaction()
try: try:
vtoc_segments = self.get_vtoc_segments() vtoc = self.get_vtoc_object()
vtoc = self.vtoc_class(self.header, vtoc_segments)
for sector_num, pos, size in vtoc.iter_free_sectors(): for sector_num, pos, size in vtoc.iter_free_sectors():
log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value)) log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value))
self.bytes[pos:pos + size] = fill_value self.bytes[pos:pos + size] = fill_value