summaryrefslogtreecommitdiffstats
path: root/perl-install/resize_fat
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/resize_fat')
-rw-r--r--perl-install/resize_fat/.cvsignore5
-rwxr-xr-x[-rw-r--r--]perl-install/resize_fat/Makefile.PL0
-rw-r--r--perl-install/resize_fat/README2
-rw-r--r--perl-install/resize_fat/any.pm17
-rw-r--r--perl-install/resize_fat/boot_sector.pm10
-rw-r--r--perl-install/resize_fat/c_rewritten.pm10
-rw-r--r--perl-install/resize_fat/c_rewritten.xs10
-rw-r--r--perl-install/resize_fat/dir_entry.pm8
-rw-r--r--perl-install/resize_fat/directory.pm12
-rw-r--r--perl-install/resize_fat/fat.pm25
-rw-r--r--perl-install/resize_fat/info_sector.pm2
-rw-r--r--perl-install/resize_fat/io.pm25
-rw-r--r--perl-install/resize_fat/main.pm15
13 files changed, 66 insertions, 75 deletions
diff --git a/perl-install/resize_fat/.cvsignore b/perl-install/resize_fat/.cvsignore
deleted file mode 100644
index 3001c7424..000000000
--- a/perl-install/resize_fat/.cvsignore
+++ /dev/null
@@ -1,5 +0,0 @@
-blib
-pm_to_blib
-Makefile_c
-c_rewritten.c
-c_rewritten.bs
diff --git a/perl-install/resize_fat/Makefile.PL b/perl-install/resize_fat/Makefile.PL
index 712f4e395..712f4e395 100644..100755
--- a/perl-install/resize_fat/Makefile.PL
+++ b/perl-install/resize_fat/Makefile.PL
diff --git a/perl-install/resize_fat/README b/perl-install/resize_fat/README
index 12b64dea9..ad5656f0b 100644
--- a/perl-install/resize_fat/README
+++ b/perl-install/resize_fat/README
@@ -5,4 +5,4 @@ resize_fat::fat::update($fs) should be called before doing undoable things
BUGS:
no known bugs :)
-if you found one, please mail pixel@mandrakesoft.com !!
+if you found one, please mail pixel !!
diff --git a/perl-install/resize_fat/any.pm b/perl-install/resize_fat/any.pm
index f811e7159..fc3c438eb 100644
--- a/perl-install/resize_fat/any.pm
+++ b/perl-install/resize_fat/any.pm
@@ -1,4 +1,4 @@
-package resize_fat::any; # $Id$
+package resize_fat::any;
use diagnostics;
use strict;
@@ -23,11 +23,11 @@ $UNMOVEABLE = 8;
#- returns the number of clusters for a given filesystem type
sub min_cluster_count($) {
my ($fs) = @_;
- (1 << $ {{ FAT16 => 12, FAT32 => 12 }}{$fs->{fs_type}}) - 12;
+ (1 << ${{ FAT16 => 12, FAT32 => 12 }}{$fs->{fs_type}}) - 12;
}
sub max_cluster_count($) {
my ($fs) = @_;
- (1 << $ {{ FAT16 => 16, FAT32 => 28 }}{$fs->{fs_type}}) - 11;
+ (1 << ${{ FAT16 => 16, FAT32 => 28 }}{$fs->{fs_type}}) - 11;
}
@@ -86,7 +86,15 @@ sub max_size($) {
sub used_size($) {
my ($fs) = @_;
- my $used_cluster_count = max(last_used($fs), min_cluster_count($fs));
+ my $last_used;
+ my $used_cluster_count;
+
+ eval { $last_used = last_used($fs) };
+ if ($@) {
+ # Empty FAT
+ $last_used = 0;
+ }
+ $used_cluster_count = max($last_used, min_cluster_count($fs));
$used_cluster_count * divide($fs->{cluster_size}, $SECTORSIZE) +
divide($fs->{cluster_offset}, $SECTORSIZE);
@@ -110,7 +118,6 @@ sub flag_clusters {
} else { return }
my $nb = resize_fat::c_rewritten::checkFat($cluster, $type, "$curr_dir_name/$entry->{name}");
- print "resize_fat:flag_clusters: check fat returned $nb of type $type for $curr_dir_name/$entry->{name}\n";
$nb_dirs += $nb if $type == $DIRECTORY;
0;
};
diff --git a/perl-install/resize_fat/boot_sector.pm b/perl-install/resize_fat/boot_sector.pm
index c87328637..f93647579 100644
--- a/perl-install/resize_fat/boot_sector.pm
+++ b/perl-install/resize_fat/boot_sector.pm
@@ -1,4 +1,4 @@
-package resize_fat::boot_sector; # $Id$
+package resize_fat::boot_sector;
use diagnostics;
use strict;
@@ -51,13 +51,13 @@ sub read($) {
my ($fs) = @_;
my $boot = eval { resize_fat::io::read($fs, 0, $SECTORSIZE) }; $@ and die "reading boot sector failed on device $fs->{fs_name}";
- @{$fs}{@fields} = unpack $format, $boot;
+ @$fs{@fields} = unpack $format, $boot;
$fs->{nb_sectors} = $fs->{small_nb_sectors} || $fs->{big_nb_sectors};
$fs->{cluster_size} = $fs->{cluster_size_in_sectors} * $fs->{sector_size};
$fs->{boot_sign} == 0xAA55 or die "Invalid signature for a MS-based filesystem.\n";
- $fs->{nb_sectors} < 32 and die "Too few sectors for viable file system\n";
+ $fs->{nb_sectors} < 32 and die "Too few sectors for viable filesystem\n";
$fs->{nb_fats} == 2 or cdie "Weird number of FATs: $fs->{nb_fats}, not 2.\n";
$fs->{sector_size} == 512 or cdie "Strange sector_size != 512\n";
@@ -87,7 +87,7 @@ sub read($) {
$fs->{nb_fat_entries} = divide($fs->{fat_size}, $fs->{fs_type_size} / 8);
- #- - 2 because clusters 0 & 1 doesn't exist
+ #- - 2 because clusters 0 & 1 does not exist
$fs->{nb_clusters} = divide($fs->{nb_sectors} * $fs->{sector_size} - $fs->{cluster_offset}, $fs->{cluster_size}) - 2;
$fs->{dir_entries_per_cluster} = divide($fs->{cluster_size}, psizeof($format));
@@ -98,7 +98,7 @@ sub read($) {
sub write($) {
my ($fs) = @_;
- my $boot = pack($format, @{$fs}{@fields});
+ my $boot = pack($format, @$fs{@fields});
eval { resize_fat::io::write($fs, 0, $SECTORSIZE, $boot) }; $@ and die "writing the boot sector failed on device $fs->{fs_name}";
diff --git a/perl-install/resize_fat/c_rewritten.pm b/perl-install/resize_fat/c_rewritten.pm
index d74ecb5d3..39ba9253f 100644
--- a/perl-install/resize_fat/c_rewritten.pm
+++ b/perl-install/resize_fat/c_rewritten.pm
@@ -1,14 +1,14 @@
-package resize_fat::c_rewritten; # $Id$
+package resize_fat::c_rewritten;
use strict;
-use vars qw($VERSION @ISA);
require DynaLoader;
-@ISA = qw(DynaLoader);
-$VERSION = '0.01';
+our @ISA = qw(DynaLoader Exporter);
+our $VERSION = '0.01';
+our @EXPORT_OK = qw(next set_next);
-bootstrap resize_fat::c_rewritten $VERSION;
+resize_fat::c_rewritten->bootstrap($VERSION);
1;
diff --git a/perl-install/resize_fat/c_rewritten.xs b/perl-install/resize_fat/c_rewritten.xs
index 92361097d..2bca483c0 100644
--- a/perl-install/resize_fat/c_rewritten.xs
+++ b/perl-install/resize_fat/c_rewritten.xs
@@ -40,12 +40,18 @@ void set_next(unsigned int cluster, unsigned int val) {
free_all();
croak("fat::set_next: cluster %d outside filesystem", cluster);
}
- type_size == 1 ? *p : *((unsigned int *) p) = val;
+ if (type_size == 1)
+ *p = val;
+ else
+ *((unsigned int *) p) = val;
}
MODULE = resize_fat::c_rewritten PACKAGE = resize_fat::c_rewritten
-void
+PROTOTYPES: DISABLE
+
+
+void
read_fat(fd, offset, size, magic)
int fd
int offset
diff --git a/perl-install/resize_fat/dir_entry.pm b/perl-install/resize_fat/dir_entry.pm
index b39c72094..27d2ea33f 100644
--- a/perl-install/resize_fat/dir_entry.pm
+++ b/perl-install/resize_fat/dir_entry.pm
@@ -1,4 +1,4 @@
-package resize_fat::dir_entry; # $Id$
+package resize_fat::dir_entry;
use diagnostics;
use strict;
@@ -6,7 +6,7 @@ use strict;
my $DELETED_FLAG = 0xe5;
-my $READ_ONLY_ATTR = 0x01;
+my $_READ_ONLY_ATTR = 0x01;
my $HIDDEN_ATTR = 0x02;
my $SYSTEM_ATTR = 0x04;
my $VOLUME_LABEL_ATTR = 0x08;
@@ -21,7 +21,7 @@ sub get_cluster($) {
}
sub set_cluster($$) {
my ($entry, $val) = @_;
- $entry->{first_cluster} = $val & (1 << 16) - 1;
+ $entry->{first_cluster} = $val & ((1 << 16) - 1);
$entry->{first_cluster_high} = $val >> 16 if $resize_fat::isFAT32;
}
@@ -61,7 +61,7 @@ sub is_special_entry($) {
#- return true if entry has been modified
#- curr_dir_name is added to contains current directory name, "" for root.
sub remap {
- my ($curr_dir_name, $entry) = @_;
+ my ($_curr_dir_name, $entry) = @_;
is_special_entry($entry) and return;
diff --git a/perl-install/resize_fat/directory.pm b/perl-install/resize_fat/directory.pm
index 455f579a2..9c04fb62b 100644
--- a/perl-install/resize_fat/directory.pm
+++ b/perl-install/resize_fat/directory.pm
@@ -1,4 +1,4 @@
-package resize_fat::directory; # $Id$
+package resize_fat::directory;
use diagnostics;
use strict;
@@ -28,23 +28,23 @@ my $psizeof_format = psizeof($format);
1;
-sub entry_size { $psizeof_format }
+sub entry_size() { $psizeof_format }
#- call `f' for each entry of the directory
#- if f return true, then modification in the entry are taken back
sub traverse($$$) {
my ($directory, $curr_dir_name, $f) = @_;
- for (my $i = 0; ; $i++) {
+ for (my $i = 0;; $i++) {
my $raw = \substr($directory, $i * $psizeof_format, $psizeof_format);
#- empty entry means end of directory
$$raw =~ /^\0*$/ and return $directory;
- my $entry; @{$entry}{@fields} = unpack $format, $$raw;
+ my $entry; @$entry{@fields} = unpack $format, $$raw;
&$f($curr_dir_name, $entry)
- and $$raw = pack $format, @{$entry}{@fields};
+ and $$raw = pack $format, @$entry{@fields};
}
$directory;
}
@@ -74,6 +74,6 @@ sub traverse_all($$) {
#- function used by construct_dir_tree to translate the `cluster' fields in each
#- directory entry
sub remap($$) {
- my ($fs, $directory) = @_;
+ my ($_fs, $directory) = @_;
traverse($directory, "", \&resize_fat::dir_entry::remap);
}
diff --git a/perl-install/resize_fat/fat.pm b/perl-install/resize_fat/fat.pm
index fdf0c2ac8..20145982b 100644
--- a/perl-install/resize_fat/fat.pm
+++ b/perl-install/resize_fat/fat.pm
@@ -1,13 +1,11 @@
-package resize_fat::fat; # $Id$
+package resize_fat::fat;
use diagnostics;
use strict;
use resize_fat::any;
use resize_fat::io;
-use resize_fat::c_rewritten;
-
-1;
+use resize_fat::c_rewritten qw(next set_next);
sub read($) {
my ($fs) = @_;
@@ -32,7 +30,7 @@ sub write($) {
#- allocates where all the clusters will be moved to. Clusters before cut_point
#- remain in the same position, however cluster that are part of a directory are
#- moved regardless (this is a mechanism to prevent data loss) (cut_point is the
-#- first cluster that won't occur in the new fs)
+#- first cluster that will not occur in the new fs)
sub allocate_remap {
my ($fs, $cut_point) = @_;
my ($cluster, $new_cluster);
@@ -78,7 +76,7 @@ sub update {
is_eof($old_next) ?
set_eof($fs, $new) :
- set_next ($fs, $new, $new_next);
+ set_next($fs, $new, $new_next);
}
}
}
@@ -89,22 +87,19 @@ sub endianness($$) {
my ($val, $nb_bits) = @_;
my $r = 0;
for (; $nb_bits > 0; $nb_bits -= 8) {
- $r <<= 8;
+ $r = $r << 8;
$r += $val & 0xff;
- $val >>= 8;
+ $val = $val >> 8;
}
$nb_bits < 0 and die "error: endianness only handle numbers divisible by 8";
$r;
}
-*next = \&resize_fat::c_rewritten::next;
-*set_next = \&resize_fat::c_rewritten::set_next;
-
sub get_free($) {
my ($fs) = @_;
- foreach (my $i = 0; $i < $fs->{nb_clusters}; $i++) {
+ for (my $i = 0; $i < $fs->{nb_clusters}; $i++) {
my $cluster = ($i + $fs->{last_free_cluster} - 2) % $fs->{nb_clusters} + 2;
is_available(&next($fs, $cluster)) and return $fs->{last_free_cluster} = $cluster;
}
@@ -118,7 +113,7 @@ sub is_eof($) {
}
sub set_eof($$) {
my ($fs, $cluster) = @_;
- set_next ($fs, $cluster, $resize_fat::bad_cluster_value + 1);
+ set_next($fs, $cluster, $resize_fat::bad_cluster_value + 1);
}
#- returns true if <cluster> is empty. Note that this includes bad clusters.
@@ -134,5 +129,7 @@ sub is_available($) {
}
sub set_available($$) {
my ($fs, $cluster) = @_;
- set_next ($fs, $cluster, 0);
+ set_next($fs, $cluster, 0);
}
+
+1;
diff --git a/perl-install/resize_fat/info_sector.pm b/perl-install/resize_fat/info_sector.pm
index 11aa7f153..47de2db1c 100644
--- a/perl-install/resize_fat/info_sector.pm
+++ b/perl-install/resize_fat/info_sector.pm
@@ -1,4 +1,4 @@
-package resize_fat::info_sector; # $Id$
+package resize_fat::info_sector;
use diagnostics;
use strict;
diff --git a/perl-install/resize_fat/io.pm b/perl-install/resize_fat/io.pm
index 7643a0953..78e3a3724 100644
--- a/perl-install/resize_fat/io.pm
+++ b/perl-install/resize_fat/io.pm
@@ -1,4 +1,4 @@
-package resize_fat::io; # $Id$
+package resize_fat::io;
use diagnostics;
use strict;
@@ -11,14 +11,13 @@ use c;
sub read($$$) {
my ($fs, $pos, $size) = @_;
- print "reading $size bytes at $pos\n";
my $buf = "\0" x $size;
sysseek $fs->{fd}, $pos, 0 or die "seeking to byte #$pos failed on device $fs->{fs_name}";
sysread $fs->{fd}, $buf, $size or die "reading at byte #$pos failed on device $fs->{fs_name}";
$buf;
}
sub write($$$$) {
- my ($fs, $pos, $size, $buf) = @_;
+ my ($fs, $pos, $_size, $buf) = @_;
sysseek $fs->{fd}, $pos, 0 or die "seeking to byte #$pos failed on device $fs->{fs_name}";
syswrite $fs->{fd}, $buf or die "writing at byte #$pos failed on device $fs->{fs_name}";
}
@@ -44,28 +43,16 @@ sub read_file($$) {
my ($fs, $cluster) = @_;
my $buf = '';
- for (; !resize_fat::fat::is_eof($cluster); $cluster = resize_fat::fat::next ($fs, $cluster)) {
+ for (; !resize_fat::fat::is_eof($cluster); $cluster = resize_fat::fat::next($fs, $cluster)) {
$cluster == 0 and die "Bad FAT: unterminated chain\n";
$buf .= read_cluster($fs, $cluster);
}
$buf;
}
-sub check_mounted($) {
- my ($f) = @_;
-
- local *F;
- open F, "/proc/mounts" or die "error opening /proc/mounts\n";
- foreach (<F>) {
- /^$f\s/ and die "device is mounted";
- }
-}
-
-sub open($) {
+sub open {
my ($fs) = @_;
- check_mounted($fs->{device});
-
- sysopen F, $fs->{fs_name}, 2 or sysopen F, $fs->{fs_name}, 0 or die "error opening device $fs->{fs_name} for writing\n";
- $fs->{fd} = *F;
+ sysopen $fs->{fd}, $fs->{fs_name}, 2 or
+ sysopen $fs->{fd}, $fs->{fs_name}, 0 or die "error opening device $fs->{fs_name} for writing\n";
}
diff --git a/perl-install/resize_fat/main.pm b/perl-install/resize_fat/main.pm
index dd3e720e5..681aec756 100644
--- a/perl-install/resize_fat/main.pm
+++ b/perl-install/resize_fat/main.pm
@@ -1,4 +1,4 @@
-package resize_fat::main; # $Id$
+package resize_fat::main;
# This is mainly a perl rewrite of the work of Andrew Clausen (libresize)
@@ -7,7 +7,6 @@ use strict;
use log;
use common;
-use MDK::Common::System;
use resize_fat::boot_sector;
use resize_fat::info_sector;
use resize_fat::directory;
@@ -21,7 +20,7 @@ use resize_fat::any;
#- - reads in the boot sector/partition info., and tries to make some sense of it
sub new($$$) {
my ($type, $device, $fs_name) = @_;
- my $fs = { device => $device, fs_name => $fs_name } ;
+ my $fs = { device => $device, fs_name => $fs_name };
eval {
resize_fat::io::open($fs);
@@ -45,7 +44,7 @@ sub DESTROY {
#- copy all clusters >= <start_cluster> to a new place on the partition, less
#- than <start_cluster>. Only copies files, not directories.
-#- (use of buffer needed because the seeks slow like hell the hard drive)
+#- (use of buffer needed because the seeks slow like hell the hard disk drive)
sub copy_clusters {
my ($fs, $cluster) = @_;
my @buffer;
@@ -71,7 +70,7 @@ sub construct_dir_tree {
if ($resize_fat::isFAT32) {
#- fat32's root must remain in the first 64k clusters
- #- so don't set it as DIRECTORY, it will be specially handled
+ #- so do not set it as DIRECTORY, it will be specially handled
resize_fat::c_rewritten::set_flag($fs->{fat32_root_dir_cluster}, $resize_fat::any::FREE);
}
@@ -121,13 +120,13 @@ sub resize {
$size >= $min or die "Minimum filesystem size is $min sectors";
$size <= $max or die "Maximum filesystem size is $max sectors";
- log::l("resize_fat: Partition size will be ". ($size * $SECTORSIZE >> 20) ."Mb (well exactly ${size} sectors)");
+ log::l("resize_fat: Partition size will be " . (($size * $SECTORSIZE) >> 20) . "Mb (well exactly ${size} sectors)");
my $new_data_size = $size * $SECTORSIZE - $fs->{cluster_offset};
my $new_nb_clusters = divide($new_data_size, $fs->{cluster_size});
my $used_size = used_size($fs);
- log::l("resize_fat: Break point for moving files is ". ($used_size * $SECTORSIZE >> 20) ." Mb ($used_size sectors)");
+ log::l("resize_fat: Break point for moving files is " . (($used_size * $SECTORSIZE) >> 20) . " Mb ($used_size sectors)");
if ($size < $used_size) {
log::l("resize_fat: Allocating new clusters");
resize_fat::fat::allocate_remap($fs, $new_nb_clusters);
@@ -158,7 +157,7 @@ sub resize {
resize_fat::boot_sector::write($fs);
- $resize_fat::isFAT32 and eval { resize_fat::info_sector::write($fs) }; #- doesn't matter if this fails - its pretty useless!
+ $resize_fat::isFAT32 and eval { resize_fat::info_sector::write($fs) }; #- does not matter if this fails - its pretty useless!
MDK::Common::System::sync();
close $fs->{fd};