home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-2 / Inter.Net 55-2.iso / Mandrake / mdkinst / usr / bin / perl-install / resize_fat / dir_entry.pm < prev    next >
Encoding:
Perl POD Document  |  2000-01-12  |  1.4 KB  |  68 lines

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