Changeset 3553 for branches


Ignore:
Timestamp:
Apr 7, 2016, 3:47:44 AM (4 years ago)
Author:
bruno
Message:

Help Fix #790

  • Fix perl functions to handle disk type (MBR vs GPT) on RHEL7 and unify output format
  • Adds perl function to list all disks on the system
  • Adds perl program to unit test these functions
  • which_partition_format now uses mr-disk-type
Location:
branches/3.2
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/MondoRescue/Makefile.PL

    r3487 r3553  
    1818    EXE_FILES    => [ qw( bin/mr-analyze-lvm
    1919                bin/mr-check-lvm
     20                bin/mr-disk-list
     21                bin/mr-disk-type
    2022                bin/mr-device-mounted
    2123                bin/mr-process-ldd
  • branches/3.2/MondoRescue/lib/MondoRescue/Disk.pm

    r3447 r3553  
    2323
    2424our @ISA = qw(Exporter);
    25 our @EXPORT = qw(mr_disk_type mr_device_mounted);
     25our @EXPORT = qw(mr_disk_list mr_disk_type mr_device_mounted);
    2626
    2727=pod
     
    3939=over 4
    4040
     41=item B<mr_disk_list>
     42
     43This function uses fdisk to determine the list of all the disks on the system
     44It returns an array of strings giving all the devices
     45
     46=cut
     47
     48sub mr_disk_list {
     49
     50my $fdisk = pb_check_req("fdisk",0);
     51my @disks;
     52
     53open(FDISK, "LANG=C $fdisk -l 2>/dev/null |") || die "Unable to read from $fdisk";
     54while (<FDISK>) {
     55    chomp($_);
     56    my $i = $_;
     57    if ($i =~ /^Disk \//) {
     58        pb_log(2,"Found disk line: $i\n");
     59        $i =~ s|^Disk /([A-z0-9/_-]+):.*|/$1|;
     60        pb_log(2,"Pushing $i\n");
     61        push @disks,$i;
     62    }
     63}
     64close(FDISK);
     65pb_log(2,"Found the following disks: @disks\n");
     66return (@disks);
     67}
     68
    4169=item B<mr_disk_type>
    4270
     
    5078my $device = shift;
    5179# MBR by default
    52 my $type = "msdos";
     80my $type = "MBR";
    5381
    5482my $fdisk = pb_check_req("fdisk",0);
    5583
    56 open(FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk";
     84open(FDISK, "LANG=C $fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk";
    5785while (<FDISK>) {
    58     if (($_ =~ /EFI GPT/) || ($_ =~ / GPT /)) {
    59         $type= "gpt";
     86    if (($_ =~ /EFI GPT/) || ($_ =~ / GPT /) || ($_ =~ /Disk[\s]*label type: gpt/)) {
     87        $type= "GPT";
    6088        last;
    6189    }
  • branches/3.2/mindi/mr-parted2fdisk

    r3383 r3553  
    241241$type = mr_disk_type($device);
    242242# Replacement code only for GPT disks
    243 if ((($v == 1) || (($v == 2) && ($maj < 22))) && ($type ne "msdos")) {
     243if ((($v == 1) || (($v == 2) && ($maj < 22))) && ($type ne "MBR")) {
    244244    pb_log(1,"This distribution uses an old fdisk, activating replacement code for GPT disk label...\n");
    245245    my $parted = pb_check_req("parted",0);
     
    258258            } elsif ($i =~ /^n$/) {
    259259                fdisk_list($device,undef,\%start,\%end, 0);
    260                 if ($type ne "gpt") {
     260                if ($type ne "GPT") {
    261261                    pb_log(1,"Forcing GPT type of disk label\n");
    262262                    pb_log(1,"mklabel gpt\n");
    263263                    pb_system("$parted -s $device mklabel gpt\n") if ($fake == 0);
    264                     $type = "gpt";
     264                    $type = "GPT";
    265265                }
    266266                $l = <STDIN>;
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3539 r3553  
    33163316{
    33173317    char *output = NULL;
    3318     char *tmp = NULL;
    33193318    char *command = NULL;
    3320     mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | grep 'EFI GPT'", drive);
    3321     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     3319    mr_asprintf(command, "mr-disk-type %s", drive);
     3320    mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command));
    33223321    mr_free(command);
    3323 
    3324     if (strstr(tmp, "GPT") == NULL) {
    3325         mr_asprintf(output, "%s", "MBR");
    3326     } else {
    3327         mr_asprintf(output, "%s", "GPT");
    3328     }
    3329     mr_free(tmp);
    33303322
    33313323    log_msg(0, "Found %s partition table format type on %s", output, drive);
Note: See TracChangeset for help on using the changeset viewer.