From 5b1fbef973500af242522fb336c3456fb88042fd Mon Sep 17 00:00:00 2001 From: Leeland Heins Date: Mon, 4 Mar 2019 10:50:49 -0600 Subject: [PATCH] Added sub to mark blocks used. --- ProDOS.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ProDOS.pm b/ProDOS.pm index 7b3c7b1..6b268b1 100644 --- a/ProDOS.pm +++ b/ProDOS.pm @@ -1554,6 +1554,28 @@ sub rename_file { return 1; } +# +# Reserve a list of used blocks. +# +sub reserve_blocks { + my ($pofile, $used_blocks, $dbg) = @_; + + $debug = 1 if defined $dbg && $dbg; + + # Get the volume bit map (blocks used/free). + my (@bitmaps) = get_vol_bit_map($pofile, $debug); + + # Mark blocks in list as used in the bit map. + foreach my $cur_blk (@{$used_blocks}) { + #printf("cur_blk=%d byte=%d bit=%d\n", $cur_blk, $cur_blk / 8, $cur_blk % 8); + $bitmaps[$cur_blk / 8] &= ~(1 << ($cur_blk % 8)); + last if $cur_blk == 0; + } + + # Now write the volume bit map back out. + return write_vol_bit_map($pofile, \@bitmaps, $debug); +} + # # Free a list of blocks. #