FileSystem-LL-FAT
view release on metacpan or search on metacpan
lib/FileSystem/LL/FAT.pm view on Meta::CPAN
while (1) {
last unless sysread $ifh, $F, 4*1e4;
for my $n (unpack 'V*', $F) {
my $n1 = $f[$n >> 28];
if ($n1) { # Special
my $cc = $n & 0xFFFFFFF;
while ($cc) {
my ($ccc, @rest) = $cc;
$ccc = 1e4 if $ccc > 1e4;
if ($n1 == 0x2) { # A run
push @out, $c + 1 .. $c + $ccc;
} else { # 0s
push @out, (0) x $ccc;
}
$cc -= $ccc, $c += $ccc;
__emit($ofh, \@out, $w) if @out >= 1e4;
}
} else {
$c++;
push @out, $n;
}
}
__emit($ofh, \@out, $w) if @out >= 1e4;
}
__emit($ofh, \@out, $w);
die "Odd number of uncompressed items, w=$w" if @out;
}
1;
__END__
=head1 NAME
FileSystem::LL::FAT - Perl extension for low-level access to FAT partitions
=head1 SYNOPSIS
use FileSystem::LL::FAT;
blah blah blah
=head1 DESCRIPTION
=head2 MBR_2_partitions($sector)
($fields, @partitions) = MBR_2_partitions($sector) or die "Not an MBR";
Takes the first sector as a string, extracts the partition info and
other information. Currently the only fields in the hash referenced by
$fields is C<bootcode> (string of length 446) and C<signature> (0xAA55).
Each element of @partitions is a hash reference with fields
raw is_active start_head start_sec_trac type end_head end_sec_track
start_lba sectors start_sec end_sec start_trac end_track
Returns an empty list unless signature is correct.
=head2 interpret_bootsector($bootsector)
Takes a string containing 512Byte bootsector; returns a hash reference
with decoded fields. The keys include
jump oem sector_size sectors_in_cluster FAT_table_off num_FAT_tables
root_dir_entries total_sectors1 media_type sectors_per_FAT16
sectors_per_track heads hidden_sectors total_sectors2
machine_code FS_type boot_signature volume_label physical_drive
ext_boot_signature serial_number raw
bpb_ext_boot_signature guessed_FAT_flavor
total_sectors sectors_per_FAT pre_sectors last_cluster sector_of_cluster0
(the last line contains info calculated based on other entries;
C<guessed_FAT_flavor> is one of 12,16,32, and
C<bpb_ext_boot_signature> is the C<ext_boot_signature> calculated
assuming FAT12 or FAT16 layout of bootsector).
Additional flavor-dependent keys: in FAT32 case
sectors_per_FAT32 FAT_flags version rootdir_start_cluster
fsi_sector_sector bootcopy_sector_sector reserved1 reserved2
otherwise
extended_bpb head___dirty_flags
=head2 check_bootsector($fields)
Takes a hash reference with decoded fields of a bootsector; returns
TRUE if minimal sanity checks hold; die()s otherwise.
=head2 interpret_directory($dir, $is_fat32, [$keep_del, [$keep_dots, [$keep_labels]]])
($res, $files) = interpret_directory($dir, $is_FAT32);
$files = interpret_directory($dir, $is_FAT32);
Takes catenation of directory cluster(s) as a string, extracts
information about the files in the directory. Each element of array
referenced by $files is a hash reference with keys
raw basename ext attrib name_ext_case creation_01sec time_create
date_create date_access cluster_high time_write date_write cluster_low
size cluster name dos_name time_creation
is_readonly is_hidden is_system is_volume_label is_subdir is_archive is_device
and possibly C<lfn_name>, C<lfn_name_UTF16>, C<lfn_raw> (if
applicable). (The last row lists flags extracted from C<attrib>.)
C<basename> and $<ext> are parts of the "DOS name" (lowercased if
indicated by the flags), C<time_create> has 0.01sec granularity (while
C<time_creation> has 2sec granularity). Entries for deleted files are
filtered out unless $keep_del is TRUE; F<.> and F<..> are also
filtered out unless $keep_dots is TRUE; records representing volume
labels are also deleted unless $keep_labels is TRUE. If not filtered
out, hashes for deleted files have an extra key C<deleted> with a true
value.
C<lfn_raw> contains an array reference with all the fractional entries
which contain the Long File Name. Each of them is a hash reference
with keys
raw seq_number name_chars_1 attrib nt_reserved checksum_dosname
name_chars_2 cluster_low name_chars_3 name_chars
$res is C<'end'> if end-of-directory entry is encountered; it is
C<'mid'> if directory ends in middle of LFN info. Otherwise $res is
not defined.
=head2 FAT_2array($fat, $s, $w [, $offset [, $lim ] ] )
Takes a reference $s to a string, at offset $offset of which is the
string representation of the FAT table; the length of FAT table in
bytes is assumed to be $lim. $offset defaults to 0, $lim defaults to
go to the end of string.
Appends to the array referenced by $fat a numeric array representating
FAT. $w is the bitwidth of the field (in 12,16,32).
=head2 check_FAT_array($fat, $b [, $offset ])
$fat is a reference to a numeric array, or to the string containing
the representation of FAT at $offset (which defaults to 0). $b is a
hash reference with keys C<guessed_FAT_flavor>, C<media_type> (e.g.,
the result of interpret_bootsector()).
Returns TRUE if the first two clusters satisfy the FAT conventions;
otherwise die()s.
=head2 cluster_chain($cluster, $maxc, $fat, $b [, $compress [, $offset ] ])
( run in 0.703 second using v1.01-cache-2.11-cpan-e1769b4cff6 )