summaryrefslogtreecommitdiffstats
path: root/perl-install/resize_fat/main.pm
diff options
context:
space:
mode:
authorMystery Man <unknown@mandriva.org>2000-11-08 00:01:16 +0000
committerMystery Man <unknown@mandriva.org>2000-11-08 00:01:16 +0000
commitd5c526273db473a7d87a26000585900fc10dda7d (patch)
tree0fdaabe7a00921b6cc556601b103d344fc7ac781 /perl-install/resize_fat/main.pm
parent9c164312d4bfff6d93e1c4529de6b992f2bebc44 (diff)
downloaddrakx-d5c526273db473a7d87a26000585900fc10dda7d.tar
drakx-d5c526273db473a7d87a26000585900fc10dda7d.tar.gz
drakx-d5c526273db473a7d87a26000585900fc10dda7d.tar.bz2
drakx-d5c526273db473a7d87a26000585900fc10dda7d.tar.xz
drakx-d5c526273db473a7d87a26000585900fc10dda7d.zip
This commit was manufactured by cvs2svn to create branch
'unlabeled-1.1.1'.
Diffstat (limited to 'perl-install/resize_fat/main.pm')
-rw-r--r--perl-install/resize_fat/main.pm139
1 files changed, 53 insertions, 86 deletions
diff --git a/perl-install/resize_fat/main.pm b/perl-install/resize_fat/main.pm
index 256031228..2d5f4f969 100644
--- a/perl-install/resize_fat/main.pm
+++ b/perl-install/resize_fat/main.pm
@@ -1,24 +1,5 @@
#!/usr/bin/perl
-# DiskDrake
-# Copyright (C) 1999 MandrakeSoft (pixel@linux-mandrake.com)
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
-# any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-# This is mainly a perl rewrite of the work of Andrew Clausen (libresize)
-
package resize_fat::main;
use diagnostics;
@@ -34,86 +15,79 @@ use resize_fat::fat;
use resize_fat::any;
+#@ARGV == 2 or die "usage: fatresize <device> <size>\n <size> = 100 means `resize to 100Mb'\n <size> = +10 means `keep 10Mb of free space'\n";
+#
+#my $fs = init($ARGV[0]);
+#resize($fs, $ARGV[1]);
+
1;
-#- - reads in the boot sector/partition info., and tries to make some sense of it
+# - 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 } ;
- eval {
- resize_fat::io::open($fs);
- resize_fat::boot_sector::read($fs);
- $resize_fat::isFAT32 and eval { resize_fat::info_sector::read($fs) };
- resize_fat::fat::read($fs);
- resize_fat::any::flag_clusters($fs);
- };
- if ($@) {
- close $fs->{fd};
- die;
- }
- bless $fs, $type;
-}
+ resize_fat::io::open($fs);
+ resize_fat::boot_sector::read($fs);
+ $resize_fat::isFAT32 and eval { resize_fat::info_sector::read($fs) };
+ resize_fat::fat::read($fs);
+ resize_fat::fat::check($fs);
+ resize_fat::any::flag_clusters($fs);
-sub DESTROY {
- my ($fs) = @_;
- close $fs->{fd};
- resize_fat::c_rewritten::free_all();
+ bless $fs, $type;
}
-#- 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)
+# 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)
sub copy_clusters {
my ($fs, $cluster) = @_;
my @buffer;
- my $flush = sub {
- while (@buffer) {
+ my $flush = sub {
+ while (@buffer) {
my $cluster = shift @buffer;
resize_fat::io::write_cluster($fs, $cluster, shift @buffer);
}
};
for (; $cluster < $fs->{nb_clusters} + 2; $cluster++) {
- resize_fat::c_rewritten::flag($cluster) == $resize_fat::any::FILE or next;
- push @buffer,
- resize_fat::c_rewritten::fat_remap($cluster),
- resize_fat::io::read_cluster($fs, $cluster);
+ $fs->{fat_flag_map}->[$cluster] == $resize_fat::any::FILE or next;
+ push @buffer, $fs->{fat_remap}->[$cluster], resize_fat::io::read_cluster($fs, $cluster);
@buffer > 50 and &$flush();
}
&$flush();
}
-#- Constructs the new directory tree to match the new file locations.
+# Constructs the new directory tree to match the new file locations.
sub construct_dir_tree {
my ($fs) = @_;
- 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
- resize_fat::c_rewritten::set_flag($fs->{fat32_root_dir_cluster}, $resize_fat::any::FREE);
+ 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
+ $fs->{fat_flag_map}->[$fs->{fat32_root_dir_cluster}] = $resize_fat::any::FREE;
}
for (my $cluster = 2; $cluster < $fs->{nb_clusters} + 2; $cluster++) {
- resize_fat::c_rewritten::flag($cluster) == $resize_fat::any::DIRECTORY or next;
+ $fs->{fat_flag_map}->[$cluster] == $resize_fat::any::DIRECTORY or next;
- resize_fat::io::write_cluster($fs,
- resize_fat::c_rewritten::fat_remap($cluster),
- resize_fat::directory::remap($fs, resize_fat::io::read_cluster($fs, $cluster)));
+ resize_fat::io::write_cluster($fs,
+ $fs->{fat_remap}->[$cluster],
+ resize_fat::directory::remap($fs, resize_fat::io::read_cluster($fs, $cluster)));
}
sync();
- #- until now, only free clusters have been written. it's a null operation if we stop here.
- #- it means no corruption :)
+ # until now, only free clusters have been written. it's a null operation if we stop here.
+ # it means no corruption :)
#
- #- now we must be as fast as possible!
+ # now we must be as fast as possible!
- #- remapping non movable root directory
+ # remapping non movable root directory
if ($resize_fat::isFAT32) {
my $cluster = $fs->{fat32_root_dir_cluster};
- resize_fat::io::write_cluster($fs,
- resize_fat::c_rewritten::fat_remap($cluster),
+ resize_fat::io::write_cluster($fs,
+ $fs->{fat_remap}->[$cluster],
resize_fat::directory::remap($fs, resize_fat::io::read_cluster($fs, $cluster)));
} else {
resize_fat::io::write($fs, $fs->{root_dir_offset}, $fs->{root_dir_size},
@@ -123,50 +97,44 @@ sub construct_dir_tree {
sub min_size($) { &resize_fat::any::min_size }
sub max_size($) { &resize_fat::any::max_size }
-sub used_size($) { &resize_fat::any::used_size }
-#- resize
-#- - size is in sectors
-#- - checks boundaries before starting
-#- - copies all data beyond new_cluster_count behind the frontier
+# resize
+# - size is in sectors
+# - checks boundaries before starting
+# - copies all data beyond new_cluster_count behind the frontier
sub resize {
my ($fs, $size) = @_;
my ($min, $max) = (min_size($fs), max_size($fs));
+
$size += $min if $size =~ /^\+/;
$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 fill 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)");
- if ($size < $used_size) {
- log::l("resize_fat: Allocating new clusters");
- resize_fat::fat::allocate_remap($fs, $new_nb_clusters);
+ log::l("resize_fat: Allocating new clusters");
+ resize_fat::fat::allocate_remap($fs, $new_nb_clusters);
- log::l("resize_fat: Copying files");
- copy_clusters($fs, $new_nb_clusters);
+ log::l("resize_fat: Copying files");
+ copy_clusters($fs, $new_nb_clusters);
- log::l("resize_fat: Copying directories");
- construct_dir_tree($fs);
+ log::l("resize_fat: Copying directories");
+ construct_dir_tree($fs);
- log::l("Writing new FAT...");
- resize_fat::fat::update($fs);
- resize_fat::fat::write($fs);
- } else {
- log::l("resize_fat: Nothing need to be moved");
- }
+ log::l("Writing new FAT...");
+ resize_fat::fat::update($fs);
+ resize_fat::fat::write($fs);
$fs->{nb_sectors} = $size;
$fs->{nb_clusters} = $new_nb_clusters;
- $fs->{clusters}{count}->{free} =
- $fs->{nb_clusters} - $fs->{clusters}{count}->{used} - $fs->{clusters}->{count}->{bad} - 2;
+ $fs->{clusters}->{count}->{free} =
+ $fs->{nb_clusters} - $fs->{clusters}->{count}->{used} - $fs->{clusters}->{count}->{bad};
$fs->{system_id} = 'was here!';
$fs->{small_nb_sectors} = 0;
@@ -176,10 +144,9 @@ 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) }; # doesn't matter if this fails - its pretty useless!
sync();
- close $fs->{fd};
log::l("resize_fat: done");
}