package partition_table; # $Id$
use diagnostics;
use strict;
use common;
use fs::type;
use partition_table::raw;
use detect_devices;
use log;
sub hd2minimal_part {
my ($hd) = @_;
{
rootDevice => $hd->{device},
if_($hd->{usb_media_type}, is_removable => 1),
};
}
#- works for both hard drives and partitions ;p
sub description {
my ($hd) = @_;
my $win = $hd->{device_windobe};
sprintf "%s%s (%s)",
$hd->{device},
$win && " [$win:]",
join(', ',
grep { $_ }
formatXiB($hd->{totalsectors} || $hd->{size}, 512),
$hd->{info}, $hd->{mntpoint}, $hd->{fs_type});
}
sub adjustStartAndEnd {
my ($hd, $part) = @_;
$hd->adjustStart($part);
$hd->adjustEnd($part);
}
sub verifyNotOverlap {
my ($a, $b) = @_;
$a->{start} + $a->{size} <= $b->{start} || $b->{start} + $b->{size} <= $a->{start};
}
sub verifyInside {
my ($a, $b) = @_;
$b->{start} <= $a->{start} && $a->{start} + $a->{size} <= $b->{start} + $b->{size};
}
sub verifyParts_ {
foreach my $i (@_) {
foreach (@_) {
next if !$i || !$_ || $i == $_ || isWholedisk($i) || isExtended($i); #- avoid testing twice for simplicity :-)
if (isWholedisk($_)) {
verifyInside($i, $_) or
cdie sprintf("partition sector #$i->{start} (%s) is not inside whole disk (%s)!",
formatXiB($i->{size}, 512), formatXiB($_->{size}, 512));
} elsif (isExtended($_)) {
verifyNotOverlap($i, $_) or
log::l(sprintf("warning partition sector #$i->{start} (%s) is overlapping with extended partition!",
formatXiB($i->{size}, 512))); #- only warning for this one is acceptable
} else {
verifyNotOverlap($i, $_) or
cdie sprintf("partitions sector #$i->{start} (%s) and sector #$_->{start} (%s) are overlapping!",
formatXiB($i->{size}, 512), formatXiB($_->{size}, 512));
}
}
}
}
sub verifyParts {
my ($hd) = @_;
verifyParts_(get_normal_parts($hd));
}
sub verifyPrimary {
my ($pt) = @_;
$_->{start} > 0 || arch() =~ /^sparc/ || die "partition must NOT start at sector 0" foreach @{$pt->{normal}};
verifyParts_(@{$pt->{normal}}, $pt->{extended});
}
sub compute_device_name {
my ($part, $hd) = @_;
$part->{device} = _compute_device_name($hd, $part->{part_number});
}
sub _compute_device_name {
my ($hd, $nb) = @_;
|