Ignore:
Timestamp:
Apr 7, 2016, 3:47:44 AM (4 years ago)
Author:
Bruno Cornec
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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.