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

  1. package resize_fat::any;
  2.  
  3.  
  4.  
  5.  
  6.  
  7. use common qw(:common :constant);
  8. use resize_fat::fat;
  9. use resize_fat::directory;
  10. use resize_fat::dir_entry;
  11. use resize_fat::c_rewritten;
  12.  
  13.  
  14. $FREE      = 0;
  15. $FILE      = 1;
  16. $DIRECTORY = 2;
  17.  
  18.  
  19. 1;
  20.  
  21.  
  22.  
  23. sub min_cluster_count($) {
  24.     my ($fs) = @_;
  25.     (1 << $ {{ FAT16 => 12, FAT32 => 12 }}{$fs->{fs_type}}) - 12;
  26. }
  27. sub max_cluster_count($) {
  28.     my ($fs) = @_;
  29.     2 ** $fs->{fs_type_size} - 11;
  30. }
  31.  
  32.  
  33.  
  34.  
  35. sub min_size($) {
  36.     my ($fs) = @_;
  37.     my $count = $fs->{clusters}{count};
  38.  
  39.     
  40.     
  41.     
  42.     my $min_cluster_count = max(2 + $count->{used} + $count->{bad} + $count->{dirs}, min_cluster_count($fs));
  43.  
  44.     $min_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) +
  45.     divide($fs->{cluster_offset}, $SECTORSIZE);
  46. }
  47.  
  48. sub max_size($) {
  49.     my ($fs) = @_;
  50.  
  51.     my $max_cluster_count = min($fs->{nb_fat_entries} - 2, max_cluster_count($fs));
  52.  
  53.     $max_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) +
  54.     divide($fs->{cluster_offset}, $SECTORSIZE);
  55. }
  56.  
  57.  
  58.  
  59. sub flag_clusters {
  60.     my ($fs) = @_;
  61.     my ($cluster, $entry, $type, $nb_dirs);
  62.  
  63.     my $f = sub {
  64.     ($entry) = @_;
  65.     $cluster = resize_fat::dir_entry::get_cluster($entry);
  66.  
  67.     if (resize_fat::dir_entry::is_file($entry)) {
  68.         $type = $FILE;
  69.     } elsif (resize_fat::dir_entry::is_directory($entry)) {
  70.         $type = $DIRECTORY;
  71.     } else { return }
  72.  
  73.     my $nb = resize_fat::c_rewritten::checkFat($cluster, $type, $entry->{name});
  74.     $nb_dirs += $nb if $type == $DIRECTORY;
  75.     0;
  76.     };
  77.     resize_fat::c_rewritten::allocate_fat_flag($fs->{nb_clusters} + 2);
  78.     resize_fat::directory::traverse_all($fs, $f);
  79.     $fs->{clusters}{count}{dirs} = $nb_dirs;
  80. }
  81.