mirror of
https://github.com/softwarejanitor/ProDOS.git
synced 2024-09-27 03:54:36 +00:00
Work on undelete
This commit is contained in:
parent
2720c2ef37
commit
44e0ce0cb9
76
ProDOS.pm
76
ProDOS.pm
@ -1797,10 +1797,10 @@ $debug = 0;
|
|||||||
last if $blk == 0;
|
last if $blk == 0;
|
||||||
my @subblks = get_sub_ind_blk($pofile, $blk, $debug);
|
my @subblks = get_sub_ind_blk($pofile, $blk, $debug);
|
||||||
|
|
||||||
foreach my $sblk (@subblks) {
|
#foreach my $sblk (@subblks) {
|
||||||
#print "sblk=$sblk\n";
|
# #print "sblk=$sblk\n";
|
||||||
last if $sblk == 0;
|
# last if $sblk == 0;
|
||||||
}
|
#}
|
||||||
#die "ACK!\n";
|
#die "ACK!\n";
|
||||||
|
|
||||||
foreach my $subblk (@subblks) {
|
foreach my $subblk (@subblks) {
|
||||||
@ -3024,29 +3024,93 @@ sub undelete_file {
|
|||||||
|
|
||||||
print "storage_type=$storage_type file_type=$file_type key_pointer=$key_pointer blocks_used=$blocks_used eof=$eof header_pointer=$header_pointer i=$i\n";
|
print "storage_type=$storage_type file_type=$file_type key_pointer=$key_pointer blocks_used=$blocks_used eof=$eof header_pointer=$header_pointer i=$i\n";
|
||||||
|
|
||||||
|
my @used_blocks = ();
|
||||||
# Re-set the STORAGE_TYPE/NAME_LENGTH byte.
|
# Re-set the STORAGE_TYPE/NAME_LENGTH byte.
|
||||||
if ($file_type eq 'DIR') {
|
if ($file_type eq 'DIR') {
|
||||||
# Directory
|
# Directory
|
||||||
$storage_type = 0x0d;
|
$storage_type = 0x0d;
|
||||||
|
|
||||||
|
# Read directory blocks, add them to reserve list.
|
||||||
|
my $buf2;
|
||||||
|
my $blk = $key_pointer;
|
||||||
|
my $done = 0;
|
||||||
|
while (!$done) {
|
||||||
|
push @used_blocks, $blk;
|
||||||
|
clear_buf(\$buf2);
|
||||||
|
if (read_blk($pofile, $blk, \$buf2)) {
|
||||||
|
my @subdirbytes = unpack "C*", $buf2;
|
||||||
|
if ($subdirbytes[2] == 0x00 && $subdirbytes[3] == 0x00) {
|
||||||
|
$done = 1;
|
||||||
|
} else {
|
||||||
|
$blk = ($subdirbytes[2] | ($subdirbytes[3] >> 8));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print "I/O Error reading block $blk\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
# Guess on whether it is a seedling, sapling or tree based on EOF.
|
# Guess on whether it is a seedling, sapling or tree based on EOF.
|
||||||
} elsif ($eof <= 512) {
|
} elsif ($eof <= 512) {
|
||||||
# Seedling;
|
# Seedling;
|
||||||
$storage_type = 0x10;
|
$storage_type = 0x10;
|
||||||
|
push @used_blocks, $key_pointer;
|
||||||
} elsif ($eof <= (256 * 512)) {
|
} elsif ($eof <= (256 * 512)) {
|
||||||
# Saplingg;
|
# Saplingg;
|
||||||
$storage_type = 0x20;
|
$storage_type = 0x20;
|
||||||
|
|
||||||
|
push @used_blocks, $key_pointer;
|
||||||
|
# Read index block, add blocks to reserve list.
|
||||||
|
my @blks = get_ind_blk($pofile, $key_pointer, $debug);
|
||||||
|
foreach my $blk (@blks) {
|
||||||
|
push @used_blocks, $blk;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
# Tree
|
# Tree
|
||||||
$storage_type = 0x30;
|
$storage_type = 0x30;
|
||||||
|
|
||||||
|
push @used_blocks, $key_pointer;
|
||||||
|
# Read master index block and index blocks, add blocks to reserve list.
|
||||||
|
my @blks = get_master_ind_blk($pofile, $key_pointer, $debug);
|
||||||
|
|
||||||
|
my $blkno = 1;
|
||||||
|
foreach my $blk (@blks) {
|
||||||
|
push @used_blocks, $blk;
|
||||||
|
|
||||||
|
my @subblks = get_sub_ind_blk($pofile, $blk, $debug);
|
||||||
|
|
||||||
|
foreach my $subblk (@subblks) {
|
||||||
|
push @used_blocks, $subblk;
|
||||||
|
}
|
||||||
|
|
||||||
|
last if $blkno++ == $blocks_used - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$storage_type |= length($filename);
|
$storage_type |= length($filename);
|
||||||
|
|
||||||
printf("storage_type=\$%02x\n", $storage_type);
|
printf("storage_type=\$%02x\n", $storage_type);
|
||||||
|
|
||||||
# Re-write file descriptive entry.
|
# Re-write file descriptive entry.
|
||||||
##FIXME
|
my $buf;
|
||||||
|
if (read_blk($pofile, $header_pointer, \$buf)) {
|
||||||
|
dump_blk($buf) if $debug;
|
||||||
|
|
||||||
|
my @bytes = unpack "C*", $buf;
|
||||||
|
|
||||||
|
# Set file storage type to hopefully original value.
|
||||||
|
$bytes[0x2b + ($i * 0x27)] = $storage_type;
|
||||||
|
|
||||||
|
$buf = pack "C*", @bytes;
|
||||||
|
|
||||||
|
if (!write_blk($pofile, $header_pointer, \$buf)) {
|
||||||
|
print "I/O Error writing block $header_pointer\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print "I/O Error reading block $header_pointer\n";
|
||||||
|
}
|
||||||
|
|
||||||
# Re-mark all the blocks for the file as used.
|
# Re-mark all the blocks for the file as used.
|
||||||
##FIXME
|
$rv = reserve_blocks($pofile, \@used_blocks, $debug);
|
||||||
|
|
||||||
return $rv;
|
return $rv;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user