mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-12-27 23:32:06 +00:00
Added --shred command line arg to fill free sectors with zero
This commit is contained in:
parent
91dc32e430
commit
151cf06115
@ -174,6 +174,12 @@ def assemble(image, source_files, data_files):
|
||||
if changed:
|
||||
image.save()
|
||||
|
||||
def shred_image(image, value=0):
|
||||
print "shredding: free sectors from %s filled with %d" % (image, value)
|
||||
if not options.dry_run:
|
||||
image.shred()
|
||||
image.save()
|
||||
|
||||
|
||||
def run():
|
||||
import sys
|
||||
@ -199,6 +205,7 @@ def run():
|
||||
parser.add_argument("-s", "--asm", nargs="+", action="append", help="source file(s) to assemble using pyatasm (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("--shred", action="store_true", default=False, help="fill empty sectors with 0")
|
||||
options, extra_args = parser.parse_known_args()
|
||||
print options, extra_args
|
||||
|
||||
@ -235,3 +242,6 @@ def run():
|
||||
assemble(parser.image, asm, datafiles)
|
||||
else:
|
||||
list_files(parser.image, file_list)
|
||||
|
||||
if options.shred:
|
||||
shred_image(parser.image)
|
||||
|
@ -48,6 +48,13 @@ class BaseHeader(object):
|
||||
|
||||
def sector_is_valid(self, sector):
|
||||
return (self.max_sectors < 0) | (sector >= self.starting_sector_label and sector < (self.max_sectors + self.starting_sector_label))
|
||||
|
||||
def iter_sectors(self):
|
||||
i = self.starting_sector_label
|
||||
while self.sector_is_valid(i):
|
||||
pos, size = self.get_pos(i)
|
||||
yield i, pos, size
|
||||
i += 1
|
||||
|
||||
def get_pos(self, sector):
|
||||
"""Get index (into the raw data of the disk image) of start of sector
|
||||
@ -374,3 +381,17 @@ class DiskImageBase(object):
|
||||
raise
|
||||
finally:
|
||||
self.get_metadata()
|
||||
|
||||
def shred(self, fill_value=0):
|
||||
state = self.begin_transaction()
|
||||
try:
|
||||
vtoc_segments = self.get_vtoc_segments()
|
||||
vtoc = self.vtoc_class(self.header, vtoc_segments)
|
||||
for sector_num, pos, size in vtoc.iter_free_sectors(self.header):
|
||||
log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value))
|
||||
self.bytes[pos:pos + size] = fill_value
|
||||
except AtrError:
|
||||
self.rollback_transaction(state)
|
||||
raise
|
||||
finally:
|
||||
self.get_metadata()
|
||||
|
@ -248,6 +248,11 @@ class VTOC(BaseSectorList):
|
||||
free = np.where(self.sector_map == 1)[0]
|
||||
return len(free)
|
||||
|
||||
def iter_free_sectors(self, header):
|
||||
for i, pos, size in header.iter_sectors():
|
||||
if self.sector_map[i] == 1:
|
||||
yield i, pos, size
|
||||
|
||||
def parse_segments(self, segments):
|
||||
raise NotImplementedError
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user