summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table/dos.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/partition_table/dos.pm')
-rw-r--r--perl-install/partition_table/dos.pm35
1 files changed, 30 insertions, 5 deletions
diff --git a/perl-install/partition_table/dos.pm b/perl-install/partition_table/dos.pm
index 8d8109723..59439e1d4 100644
--- a/perl-install/partition_table/dos.pm
+++ b/perl-install/partition_table/dos.pm
@@ -1,4 +1,4 @@
-package partition_table::dos; # $Id$
+package partition_table::dos; # $Id: dos.pm 263707 2009-11-26 13:26:41Z pterjan $
use diagnostics;
use strict;
@@ -9,6 +9,7 @@ use vars qw(@ISA);
use common;
use partition_table::raw;
use partition_table;
+use fs::type;
use c;
my @fields = qw(active start_head start_sec start_cyl pt_type end_head end_sec end_cyl start size);
@@ -18,6 +19,7 @@ my $nb_primary = 4;
my $offset = $common::SECTORSIZE - length($magic) - $nb_primary * common::psizeof($format);
+sub use_pt_type { 1 }
sub hasExtended { 1 }
sub geometry_to_string {
@@ -31,6 +33,10 @@ sub last_usable_sector {
$hd->{geom}{sectors} * $hd->{geom}{heads} * $hd->{geom}{cylinders};
}
+my $two_TB = 2 * 1024 * 1024 * 2048;
+sub max_partition_start { $two_TB - 1 }
+sub max_partition_size { $two_TB - 1 }
+
sub get_rawCHS {
my ($part) = @_;
@@ -103,8 +109,8 @@ sub is_geometry_valid_for_the_partition_table {
my ($chs_start_v1, $chs_end_v1) = map { join(',', @$_) } CHS_from_part_rawCHS($_) or next;
my ($chs_start_v2, $chs_end_v2) = map { join(',', @$_) } map { [ min($_->[0], 1023), $_->[1], $_->[2] ] } CHS_from_part_linear($geom, $_);
if (!$no_log) {
- $chs_start_v1 eq $chs_start_v2 or log::l("check_geometry_using_the_partition_table failed for ($_->{device}, $_->{start}): $chs_start_v1 vs $chs_start_v2 with geometry " . geometry_to_string($geom));
- $chs_end_v1 eq $chs_end_v2 or log::l("check_geometry_using_the_partition_table failed for ($_->{device}, " . ($_->{start} + $_->{size} - 1) . "): $chs_end_v1 vs $chs_end_v2 with geometry " . geometry_to_string($geom));
+ $chs_start_v1 eq $chs_start_v2 or log::l("is_geometry_valid_for_the_partition_table failed for ($_->{device}, $_->{start}): $chs_start_v1 vs $chs_start_v2 with geometry " . geometry_to_string($geom));
+ $chs_end_v1 eq $chs_end_v2 or log::l("is_geometry_valid_for_the_partition_table failed for ($_->{device}, " . ($_->{start} + $_->{size} - 1) . "): $chs_end_v1 vs $chs_end_v2 with geometry " . geometry_to_string($geom));
}
$chs_start_v1 eq $chs_start_v2 && $chs_end_v1 eq $chs_end_v2;
} @{$hd->{primary}{normal} || []};
@@ -195,7 +201,7 @@ sub set_best_geometry_for_the_partition_table {
}
}
-sub read {
+sub read_one {
my ($hd, $sector) = @_;
my $tmp;
@@ -214,6 +220,19 @@ sub read {
sysread $F, $tmp, length $magic or die "error reading magic number on disk $hd->{device}";
$tmp eq $magic or die "bad magic number on disk $hd->{device}";
+ if (c::get_disk_type($hd->{file}) ne "msdos") {
+ # libparted may have ignored it because of overlapping partitions or other error
+ # while it is actually a partition table.
+ $hd->{fs_type_from_magic} and die "unpartitionned disk";
+ my $primary = partition_table::raw::pt_info_to_primary($hd, [ @pt ]);
+ foreach my $i (@{$primary->{normal}}) {
+ if ($i->{active} && $i->{active} != 0x80 ||
+ $hd->{totalsectors} && $i->{start} > $hd->{totalsectors}) {
+ die "Invalid DOS partition table";
+ }
+ }
+ }
+
[ @pt ];
}
@@ -245,6 +264,12 @@ sub write {
1;
}
-sub clear_raw { { raw => [ ({}) x $nb_primary ] } }
+sub empty_raw { { raw => [ ({}) x $nb_primary ] } }
+
+sub initialize {
+ my ($class, $hd) = @_;
+ $hd->{primary} = empty_raw();
+ bless $hd, $class;
+}
1;