diff options
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/resize_fat/any.pm | 25 | ||||
-rw-r--r-- | perl-install/resize_fat/boot_sector.pm | 1 | ||||
-rw-r--r-- | perl-install/resize_fat/c_rewritten.xs | 18 | ||||
-rw-r--r-- | perl-install/resize_fat/fat.pm | 7 | ||||
-rw-r--r-- | perl-install/resize_fat/info_sector.pm | 1 |
5 files changed, 29 insertions, 23 deletions
diff --git a/perl-install/resize_fat/any.pm b/perl-install/resize_fat/any.pm index 47f15558b..63f154008 100644 --- a/perl-install/resize_fat/any.pm +++ b/perl-install/resize_fat/any.pm @@ -38,7 +38,7 @@ sub last_used($) { #- count in negative so absolute value count back to 2. foreach (-($fs->{nb_clusters}+1)..-2) { return -$_ if resize_fat::c_rewritten::flag(-$_) } - return 2; + die "any: empty FAT table"; } #- patch to get the function last_unmoveable that return the last unmoveable cluster of a fs. sub last_unmoveable($) { @@ -46,7 +46,7 @@ sub last_unmoveable($) { #- count in negative so absolute value count back to 2. foreach (-($fs->{nb_clusters}+1)..-2) { return -$_ if 0x8 & resize_fat::c_rewritten::flag(-$_) } - return 2; + die "any: empty FAT table"; } #- calculates the minimum size of a partition, in physical sectors @@ -58,10 +58,18 @@ sub min_size($) { #- It's done on purpose since we're moving all directories. So at the worse #- moment, 2 directories are there, but that way nothing wrong can happen :) my $min_cluster_count = max(2 + $count->{used} + $count->{bad} + $count->{dirs}, min_cluster_count($fs)); - $min_cluster_count = max($min_cluster_count, 2 + last_unmoveable($fs)); + $min_cluster_count = max($min_cluster_count, last_unmoveable($fs)); + + my $size = $min_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + + divide($fs->{cluster_offset}, $SECTORSIZE) + + 64*1024*1024 / $SECTORSIZE; #- help with such more sectors (ie 64Mb). + + #- help zindozs again with 512Mb+ at least else partition is ignored. + if ($resize_fat::isFAT32) { + $size = max($size, 524*1024*1024 / $SECTORSIZE); + } + $size; - $min_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + - divide($fs->{cluster_offset}, $SECTORSIZE); } #- calculates the maximum size of a partition, in physical sectors sub max_size($) { @@ -76,7 +84,7 @@ sub max_size($) { sub used_size($) { my ($fs) = @_; - my $used_cluster_count = max(2 + last_used($fs), min_cluster_count($fs)); + my $used_cluster_count = max(last_used($fs), min_cluster_count($fs)); $used_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) + divide($fs->{cluster_offset}, $SECTORSIZE); @@ -103,10 +111,9 @@ sub flag_clusters { $nb_dirs += $nb if $type == $DIRECTORY; 0; }; - resize_fat::c_rewritten::allocate_fat_flag($fs->{nb_clusters} + 2); - #- patch to reset contents of memory allocated by allocate_fat_flag - foreach (0..$fs->{nb_clusters} + 1) { resize_fat::c_rewritten::set_flag($_, 0) } + #- this must call allocate_fat_flag that zeroes the buffer allocated. + resize_fat::c_rewritten::allocate_fat_flag($fs->{nb_clusters} + 2); resize_fat::directory::traverse_all($fs, $f); $fs->{clusters}{count}{dirs} = $nb_dirs; diff --git a/perl-install/resize_fat/boot_sector.pm b/perl-install/resize_fat/boot_sector.pm index 48e2a8d4e..0ca110af8 100644 --- a/perl-install/resize_fat/boot_sector.pm +++ b/perl-install/resize_fat/boot_sector.pm @@ -9,6 +9,7 @@ use resize_fat::any; use resize_fat::directory; +#- Oops, this will be unresizable on big-endian machine. trapped by signature. my $format = "a3 a8 S C S C S S C S S S I I I S S I S S a458 S"; my @fields = ( 'boot_jump', #- boot strap short or near jump diff --git a/perl-install/resize_fat/c_rewritten.xs b/perl-install/resize_fat/c_rewritten.xs index 5aebb1ffb..eb3e314dd 100644 --- a/perl-install/resize_fat/c_rewritten.xs +++ b/perl-install/resize_fat/c_rewritten.xs @@ -35,11 +35,11 @@ read_fat(fd, offset, size, magic) if (lseek(fd, offset, SEEK_SET) != offset || read(fd, fat, size) != size) { free(fat); fat = NULL; - croak("reading FAT failed"); + croak("read_fat: reading FAT failed"); } if (magic != *(unsigned char *) fat) { free(fat); fat = NULL; - croak("FAT has invalid signature"); + croak("read_fat: FAT has invalid signature"); } } @@ -72,9 +72,9 @@ scan_fat(nb_clusters_, type_size_) short *p; type_size = type_size_; nb_clusters = nb_clusters_; - bad_cluster_value = type_size ? 0xffffff7 : 0xfff7; + bad_cluster_value = type_size == 32 ? 0xffffff7 : 0xfff7; - if (type_size % 16) fprintf(stderr, "unable to handle type_size"), exit(1); + if (type_size % 16) croak("scan_fat: unable to handle FAT%d", type_size); type_size /= 16; for (p = fat + 2 * type_size; p < fat + type_size * (nb_clusters + 2); p += type_size) { @@ -111,7 +111,7 @@ void allocate_fat_flag(size) int size CODE: - fat_flag_map = malloc(size); + fat_flag_map = calloc(size, 1); int checkFat(cluster, type, name) @@ -151,8 +151,8 @@ void allocate_fat_remap(size) int size CODE: - fat_remap_size = size / 4; - fat_remap = (unsigned int *) malloc(size); + fat_remap_size = size; + fat_remap = (unsigned int *) calloc(size, sizeof(unsigned int *)); unsigned int fat_remap(cluster) @@ -161,8 +161,8 @@ fat_remap(cluster) if (cluster >= bad_cluster_value) { RETVAL = cluster; /* special cases */ } else { - if (fat_remap == NULL) croak("fat_remap NULL in fat_remap"); - if (cluster >= fat_remap_size) croak("cluster %d >= %d in fat_remap", cluster, fat_remap_size); + if (fat_remap == NULL) croak("fat_remap: NULL in fat_remap"); + if (cluster >= fat_remap_size) croak("fat_remap: cluster %d >= %d in fat_remap", cluster, fat_remap_size); RETVAL = fat_remap[cluster]; } OUTPUT: diff --git a/perl-install/resize_fat/fat.pm b/perl-install/resize_fat/fat.pm index 33572624a..0d8a32dfa 100644 --- a/perl-install/resize_fat/fat.pm +++ b/perl-install/resize_fat/fat.pm @@ -44,11 +44,8 @@ sub allocate_remap { #-log::ld("resize_fat: [$cluster,", &next($fs, $cluster), "...]->$new_cluster..."); }; - resize_fat::c_rewritten::allocate_fat_remap($fs->{fat_size}); - - #- patch to reset contents of memory allocated by allocate_fat_remap - #- divide by 4 because fat_size is in bytes. - foreach (0..$fs->{fat_size}/4 - 1) { resize_fat::c_rewritten::set_fat_remap($_, 0) } + #- this must call allocate_fat_remap that zeroes the buffer allocated. + resize_fat::c_rewritten::allocate_fat_remap($fs->{nb_clusters} + 2); $fs->{last_free_cluster} = 2; for ($cluster = 2; $cluster < $fs->{nb_clusters} + 2; $cluster++) { diff --git a/perl-install/resize_fat/info_sector.pm b/perl-install/resize_fat/info_sector.pm index 3a6f7cfed..dc459ef6c 100644 --- a/perl-install/resize_fat/info_sector.pm +++ b/perl-install/resize_fat/info_sector.pm @@ -6,6 +6,7 @@ use strict; use common qw(:system); use resize_fat::io; +#- Oops, this will be unresizable on big-endian machine. trapped by signature. my $format = "a484 I I I a16"; my @fields = ( 'unused', |