blob: 0739b0951f9135ac611f3b29be9893a087e637f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package resize_fat::dir_entry;
use diagnostics;
use strict;
my $DELETED_FLAG = 0xe5;
my $VOLUME_LABEL_ATTR = 0x08;
my $VFAT_ATTR = 0x0f;
my $DIRECTORY_ATTR = 0x10;
1;
sub get_cluster($) {
my ($entry) = @_;
$entry->{first_cluster} + ($resize_fat::isFAT32 ? $entry->{first_cluster_high} * 65536 : 0);
}
sub set_cluster($$) {
my ($entry, $val) = @_;
$entry->{first_cluster} = $val & (1 << 16) - 1;
$entry->{first_cluster_high} = $val >> 16 if $resize_fat::isFAT32;
}
sub is_directory($) {
my ($entry) = @_;
$entry->{attributes} & $DIRECTORY_ATTR && $entry->{name} !~ /^\.\.? / && !is_special_entry($entry);
}
sub is_volume($) {
my ($entry) = @_;
!is_special_entry($entry) && $entry->{attributes} & $VOLUME_LABEL_ATTR;
}
sub is_file($) {
my ($entry) = @_;
!is_special_entry($entry) && !is_directory($entry) && !is_volume($entry) && $entry->{length};
}
sub is_special_entry($) {
my ($entry) = @_;
my ($c) = unpack "C", $entry->{name};
#- skip empty slots, deleted files, and 0xF6?? (taken from kernel)
$c == 0 || $c == $DELETED_FLAG || $c == 0xF6 and return 1;
$entry->{attributes} == $VFAT_ATTR and return 1;
0;
}
#- return true if entry has been modified
sub remap {
my ($fat_remap, $entry) = @_;
is_special_entry($entry) and return;
my $cluster = get_cluster($entry);
my $new_cluster = $fat_remap->[$cluster];
#-print "remapping cluster ", get_first_cluster($fs, $entry), " to $new_cluster";
$new_cluster == $cluster and return; #- no need to modify
set_cluster($entry, $new_cluster);
1;
}
|