summaryrefslogtreecommitdiffstats
path: root/perl-install/fs
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-08-03 05:41:59 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-08-03 05:41:59 +0000
commitf8d30c05a05c1c01b3f8a758c54f4af07d7b114e (patch)
tree195d64c8532c126b49c0e71f649d08fbfe8f330b /perl-install/fs
parent607de8e2fa2b83e8b9cefd4ced24d3b4e24fc007 (diff)
downloaddrakx-backup-do-not-use-f8d30c05a05c1c01b3f8a758c54f4af07d7b114e.tar
drakx-backup-do-not-use-f8d30c05a05c1c01b3f8a758c54f4af07d7b114e.tar.gz
drakx-backup-do-not-use-f8d30c05a05c1c01b3f8a758c54f4af07d7b114e.tar.bz2
drakx-backup-do-not-use-f8d30c05a05c1c01b3f8a758c54f4af07d7b114e.tar.xz
drakx-backup-do-not-use-f8d30c05a05c1c01b3f8a758c54f4af07d7b114e.zip
many functions in fsedit don't modify anything, they are simply accessors.
create fs::get and move them into it - device2part(), up_mount_point() moved from fs to fs::get - part2hd(), file2part(), has_mntpoint(), mntpoint2part(), empty_all_hds() moved from fsedit to fs::get - fsedit::get_root() -> fs::get::root() - fsedit::get_root_() -> fs::get::root_() - fsedit::get_really_all_fstab() -> fs::get::really_all_fstab() - fsedit::get_all_fstab_and_holes() -> fs::get::fstab_and_holes() - fsedit::get_all_fstab() -> fs::get::fstab() - fsedit::get_all_holes() -> fs::get::holes() - fsedit::all_free_space -> fs::get::free_space() - fsedit::get_really_all_fstab() -> fs::get::really_all_fstab() - fsedit::get_fstab_and_holes() -> fs::get::hds_fstab_and_holes() - fsedit::get_holes() -> fs::get::hds_holes() - fsedit::get_fstab() -> fs::get::hds_fstab() - fsedit::free_space() -> fs::get::hds_free_space() - fsedit::get_visible_fstab() unused, removed
Diffstat (limited to 'perl-install/fs')
-rw-r--r--perl-install/fs/format.pm1
-rw-r--r--perl-install/fs/get.pm128
2 files changed, 129 insertions, 0 deletions
diff --git a/perl-install/fs/format.pm b/perl-install/fs/format.pm
index ad4eebdd2..eb3f89be4 100644
--- a/perl-install/fs/format.pm
+++ b/perl-install/fs/format.pm
@@ -54,6 +54,7 @@ sub part_raw {
$part->{isFormatted} and return;
if ($part->{encrypt_key}) {
+ require fs;
fs::set_loop($part);
}
diff --git a/perl-install/fs/get.pm b/perl-install/fs/get.pm
new file mode 100644
index 000000000..5b5b75077
--- /dev/null
+++ b/perl-install/fs/get.pm
@@ -0,0 +1,128 @@
+package fs::get; # $Id$
+
+use diagnostics;
+use strict;
+
+use partition_table;
+use fs::type;
+use fs;
+use common;
+use log;
+
+sub empty_all_hds() {
+ { hds => [], lvms => [], raids => [], loopbacks => [], raw_hds => [], nfss => [], smbs => [], davs => [], special => [] };
+}
+sub fstab {
+ my ($all_hds) = @_;
+ my @parts = map { partition_table::get_normal_parts($_) } hds($all_hds);
+ my @raids = grep { $_ } @{$all_hds->{raids}};
+ @parts, @raids, @{$all_hds->{loopbacks}};
+}
+sub really_all_fstab {
+ my ($all_hds) = @_;
+ my @l = fstab($all_hds);
+ @l, @{$all_hds->{raw_hds}}, @{$all_hds->{nfss}}, @{$all_hds->{smbs}}, @{$all_hds->{davs}};
+}
+
+sub fstab_and_holes {
+ my ($all_hds) = @_;
+ my @raids = grep { $_ } @{$all_hds->{raids}};
+ hds_fstab_and_holes(hds($all_hds)), @raids, @{$all_hds->{loopbacks}};
+}
+
+sub holes {
+ my ($all_hds) = @_;
+ grep { $_->{pt_type} == 0 } fstab_and_holes($all_hds);
+}
+sub hds_holes {
+ grep { $_->{pt_type} == 0 } hds_fstab_and_holes(@_);
+}
+sub free_space {
+ my ($all_hds) = @_;
+ sum map { $_->{size} } holes($all_hds);
+}
+sub hds_free_space {
+ sum map { $_->{size} } hds_holes(@_);
+}
+
+sub hds {
+ my ($all_hds) = @_;
+ (@{$all_hds->{hds}}, @{$all_hds->{lvms}});
+}
+
+#- get all normal partition including special ones as found on sparc.
+sub hds_fstab {
+ map { partition_table::get_normal_parts($_) } @_;
+}
+
+sub hds_fstab_and_holes {
+ map {
+ if (isLVM($_)) {
+ my @parts = partition_table::get_normal_parts($_);
+ my $free = $_->{totalsectors} - sum map { $_->{size} } @parts;
+ my $free_part = { start => 0, size => $free, pt_type => 0, rootDevice => $_->{VG_name} };
+ @parts, if_($free >= $_->cylinder_size, $free_part);
+ } else {
+ partition_table::get_normal_parts_and_holes($_);
+ }
+ } @_;
+}
+
+
+sub device2part {
+ my ($dev, $fstab) = @_;
+ my $subpart = fs::subpart_from_wild_device_name($dev);
+ my $part = find { fsedit::is_same_hd($subpart, $_) } @$fstab;
+ log::l("fs::device2part: unknown device <<$dev>>") if !$part;
+ $part;
+}
+
+sub part2hd {
+ my ($part, $all_hds) = @_;
+ my $hd = find { $part->{rootDevice} eq ($_->{device} || $_->{VG_name}) } hds($all_hds);
+ $hd;
+}
+
+sub file2part {
+ my ($fstab, $file, $b_keep_simple_symlinks) = @_;
+ my $part;
+
+ $file = $b_keep_simple_symlinks ? common::expand_symlinks_but_simple("$::prefix$file") : expand_symlinks("$::prefix$file");
+ unless ($file =~ s/^$::prefix//) {
+ my $part = find { loopback::carryRootLoopback($_) } @$fstab or die;
+ log::l("found $part->{mntpoint}");
+ $file =~ s|/initrd/loopfs|$part->{mntpoint}|;
+ }
+ foreach (@$fstab) {
+ my $m = $_->{mntpoint};
+ $part = $_ if
+ $file =~ /^\Q$m/ &&
+ (!$part || length $part->{mntpoint} < length $m);
+ }
+ $part or die "file2part: not found $file";
+ $file =~ s|$part->{mntpoint}/?|/|;
+ ($part, $file);
+}
+
+sub mntpoint2part {
+ my ($mntpoint, $fstab) = @_;
+ find { $mntpoint eq $_->{mntpoint} } @$fstab;
+}
+sub has_mntpoint {
+ my ($mntpoint, $all_hds) = @_;
+ mntpoint2part($mntpoint, [ really_all_fstab($all_hds) ]);
+}
+sub root_ {
+ my ($fstab, $o_boot) = @_;
+ $o_boot && mntpoint2part("/boot", $fstab) || mntpoint2part("/", $fstab);
+}
+sub root { &root_ || {} }
+
+sub up_mount_point {
+ my ($mntpoint, $fstab) = @_;
+ while (1) {
+ $mntpoint = dirname($mntpoint);
+ $mntpoint ne "." or return;
+ $_->{mntpoint} eq $mntpoint and return $_ foreach @$fstab;
+ }
+}