From f160047359748cdf93071e9c5aa0e5d80275a9f2 Mon Sep 17 00:00:00 2001 From: Leeland Heins Date: Thu, 17 Jan 2019 13:01:34 -0600 Subject: [PATCH] Bug fixes --- DOS33.pm | 77 ++++++++++++++++++++++++++++++++++++++++++++++++-- README | 2 +- catalog.pl | 2 ++ dos33copy.pl | 2 ++ dos33delete.pl | 2 ++ dos33lock.pl | 2 ++ dos33read.pl | 2 ++ dos33rename.pl | 2 ++ dos33unlock.pl | 2 ++ dos33write.pl | 2 ++ freemap.pl | 2 ++ procat.pl | 2 ++ profree.pl | 2 ++ proread.pl | 2 ++ prozap.pl | 2 ++ zap.pl | 2 ++ 16 files changed, 103 insertions(+), 4 deletions(-) diff --git a/DOS33.pm b/DOS33.pm index c3b473d..bf87de6 100644 --- a/DOS33.pm +++ b/DOS33.pm @@ -495,6 +495,7 @@ sub read_file { #print sprintf("%c", $byte & 0x7f); print sprintf("%c", $byte); } +##FIXME -- need to handle additional file types + handle incomplete last sectors properly here. } } } @@ -582,13 +583,85 @@ sub delete_file { my ($file, $cat_trk, $cat_sec, $cat_buf) = find_file($dskfile, $filename); if (defined $file && $file && $file->{'trk'}) { - ##FIXME + print "cat_trk=$cat_trk cat_sec=$cat_sec\n"; + dump_sec($cat_buf) if $debug; + my @bytes = unpack "C*", $cat_buf; # Mark file as deleted. + # 11 is first tslist sector track + my $first_tslist_sec_trk = $bytes[11 + (($file->{'cat_offset'} - 1) * 35)]; + print sprintf("first_tslist_sec_trk=%02x\n", $first_tslist_sec_trk); + $bytes[11 + (($file->{'cat_offset'} - 1) * 35)] = 0x00; + # Set last byte of filename to first tslist sector track + $bytes[43 + (($file->{'cat_offset'} - 1) * 35)] = $first_tslist_sec_trk; + # Re-pack the data in the sector. + $cat_buf = pack "C*", @bytes; + + dump_sec($cat_buf) if $debug; # Write back catalog sector. + #if (!wts($dskfile, $cat_trk, $cat_sec, $cat_buf)) { + # print "Failed to write catalog sector $cat_trk $cat_sec!\n"; + #} + + my ($trk_num_1st_cat_sec, $sec_num_1st_cat_sec, $rel_num_dos, $dsk_vol_num, $max_tslist_secs, $last_trk_secs_alloc, $dir_trk_alloc, $num_trks_dsk, $num_secs_dsk, $num_bytes_sec, $bit_map_free_secs) = get_vtoc_sec($dskfile); + + my $tmpl = ''; + for (my $t = $min_trk; $t <= $max_trk; $t++) { + $tmpl .= $bit_map_free_sec_tmpl; + } + + print "tmpl=$tmpl\n" if $debug; + my @flds = unpack $tmpl, $bit_map_free_secs; + + if ($debug) { + for (my $t = $min_trk; $t <= $max_trk; $t++) { + print sprintf("%2d %04x\n", $t, $flds[$t]) if $debug; + print sprintf("%2d %016b\n", $t, $flds[$t]) if $debug; + my $fr = sprintf("%016b", $flds[$t]); + print "fr=$fr\n" if $debug; + my $fm = reverse $fr; + print "fm=$fm\n" if $debug; + $fm =~ s/0/ /g; + $fm =~ s/1/*/g; + print "fm=$fm\n" if $debug; + print sprintf("%2d|%s\n", $t, $fm); + } + } # get the files t/s list and free those sectors + my @secs = get_tslist($dskfile, $file->{'trk'}, $file->{'sec'}); + foreach my $sec (@secs) { + next if $sec->{'trk'} == 0 && $sec->{'sec'} == 0; + #print "trl=$sec->{'trk'} sec=$sec->{'sec'}\n"; + my $fr = sprintf("%016b", $flds[$sec->{'trk'}]); + #print "fr=$fr\n"; + $flds[$sec->{'trk'}] |= (1 << $sec->{'sec'}); + my $fr2 = sprintf("%016b", $flds[$sec->{'trk'}]); + #print "fr=$fr2\n"; + } + ##FIXME -- may need to free additional tslist sectors. + $flds[$file->{'trk'}] |= (1 << $file->{'sec'}); + + if ($debug) { + for (my $t = $min_trk; $t <= $max_trk; $t++) { + print sprintf("%2d %04x\n", $t, $flds[$t]) if $debug; + print sprintf("%2d %016b\n", $t, $flds[$t]) if $debug; + my $fr = sprintf("%016b", $flds[$t]); + print "fr=$fr\n" if $debug; + my $fm = reverse $fr; + print "fm=$fm\n" if $debug; + $fm =~ s/0/ /g; + $fm =~ s/1/*/g; + print "fm=$fm\n" if $debug; + print sprintf("%2d|%s\n", $t, $fm); + } + } + + $bit_map_free_secs = pack $tmpl, @flds; + + # Write vtoc back +##FIXME } } @@ -628,7 +701,6 @@ sub rename_file { # Re-pack the data in the sector. $cat_buf = pack "C*", @bytes; - # Write back catalog sector. dump_sec($cat_buf) if $debug; # Write back catalog sector. if (!wts($dskfile, $cat_trk, $cat_sec, $cat_buf)) { @@ -663,6 +735,5 @@ sub write_file { ##FIXME } - 1; diff --git a/README b/README index d8ebced..6ec7d49 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ dos33write.pl -- started dos33umlock.pl -- mostly working dos33lock.pl -- mostly working dos33rename.pl -- mostly working -dos33delete.pl -- started +dos33delete.pl -- in progress dos33copy.pl -- started zap.pl -- partially working prozap.pl -- partially working diff --git a/catalog.pl b/catalog.pl index 9547186..ef52daf 100644 --- a/catalog.pl +++ b/catalog.pl @@ -18,6 +18,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33copy.pl b/dos33copy.pl index 4a24b15..dcf64b4 100644 --- a/dos33copy.pl +++ b/dos33copy.pl @@ -19,6 +19,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33delete.pl b/dos33delete.pl index 630b2d1..7969448 100644 --- a/dos33delete.pl +++ b/dos33delete.pl @@ -19,6 +19,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33lock.pl b/dos33lock.pl index 2244f99..618d684 100644 --- a/dos33lock.pl +++ b/dos33lock.pl @@ -19,6 +19,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33read.pl b/dos33read.pl index 5495382..570d420 100644 --- a/dos33read.pl +++ b/dos33read.pl @@ -52,6 +52,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { } elsif ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33rename.pl b/dos33rename.pl index 331efd0..1258b79 100644 --- a/dos33rename.pl +++ b/dos33rename.pl @@ -19,6 +19,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33unlock.pl b/dos33unlock.pl index c276fdb..4fe400a 100644 --- a/dos33unlock.pl +++ b/dos33unlock.pl @@ -19,6 +19,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/dos33write.pl b/dos33write.pl index 99c6ab0..749d95e 100644 --- a/dos33write.pl +++ b/dos33write.pl @@ -52,6 +52,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { } elsif ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/freemap.pl b/freemap.pl index 2968d9b..2e45f36 100644 --- a/freemap.pl +++ b/freemap.pl @@ -18,6 +18,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/procat.pl b/procat.pl index 6d62c4c..f5bb72c 100644 --- a/procat.pl +++ b/procat.pl @@ -24,6 +24,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { $blk = $ARGV[1]; shift; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/profree.pl b/profree.pl index 824a51c..f862799 100644 --- a/profree.pl +++ b/profree.pl @@ -18,6 +18,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { if ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/proread.pl b/proread.pl index 2923e71..28dba1c 100644 --- a/proread.pl +++ b/proread.pl @@ -52,6 +52,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { } elsif ($ARGV[0] eq '-d') { $debug = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/prozap.pl b/prozap.pl index af708a8..643d1f1 100644 --- a/prozap.pl +++ b/prozap.pl @@ -48,6 +48,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { } elsif ($ARGV[0] eq "-w") { $write = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } } diff --git a/zap.pl b/zap.pl index 5d85259..ea91b12 100644 --- a/zap.pl +++ b/zap.pl @@ -60,6 +60,8 @@ while (defined $ARGV[0] && $ARGV[0] =~ /^-/) { } elsif ($ARGV[0] eq "-w") { $write = 1; shift; + } else { + die "Unknown command line argument $ARGV[0]\n"; } }