Changeset 3355


Ignore:
Timestamp:
Mar 5, 2015, 1:25:41 PM (5 years ago)
Author:
Bruno Cornec
Message:
  • Fix parted2fdisk for RHEL5 support with regex for fdisk version adapted
  • parted2fdisk now supports being called with -l option without device. It then calls fdisk directly for this case to be fully compatible.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi/parted2fdisk.pl

    r3344 r3355  
    77#
    88# Aims to be architecture independant (i386/ia64)
    9 # Tested on ia64 with RHAS 2.1 - Mandrake 9.0 - RHEL 3.0 - SLES 10
     9# Tested on ia64 with RHAS 2.1 - Mandrake 9.0 - RHEL 3.0 - SLES 10 - RHEL 5 -
    1010#
    1111# Copyright B. Cornec 2000-2015
     
    2929
    3030parted2fdisk -s partition
    31 parted2fdisk -l device
     31parted2fdisk -l [device]
    3232parted2fdisk [-n] device
    3333
     
    4646=item B<-l>
    4747
    48 List the partition tables for the specified device and then exit.
     48List the partition tables for the specified device (or all if none specified) and then exit.
    4949
    5050=item B<no option>
     
    175175}
    176176
    177 if (($args ne "") and ($device eq "")) {
     177if (($args ne "") && ($args ne "-l") && ($device eq "")) {
    178178    mysyn();
    179179}
     
    191191
    192192print FLOG "Called with device $device and arg $args\n";
     193
     194if (($args =~ /-l/) && ($device eq "")) {
     195    # Pass to real fdisk directly
     196    local_fdisk($args,$device);
     197    myexit(0);
     198}
    193199
    194200# util-linux/fdisk version
     
    197203close(CMD);
    198204chomp($version);
    199 $version =~ s/[^0-9\.]*([0-9\.]+)[\)]*$/$1/;
     205# RHEL 5 has fdisk (util-linux 2.13-pre7)
     206# Mageia 4 has fdisk from util-linux 2.24.2
     207$version =~ s/[^0-9\.]*([0-9a-z\.-]+)[\)]*$/$1/;
    200208my ($v,$maj,$min) = split(/\./,$version);
     209
     210# Consider pre version the same as the following for formats
     211if ((defined $maj) && ($maj =~ /-pre/)) {
     212    $maj =~ s/-pre.*$//;
     213    $maj++;
     214}
     215if ((defined $min) && ($min =~ /-pre/)) {
     216    $min =~ s/-pre.*$//;
     217    $min++;
     218}
    201219
    202220if (($v == 1) || (($v == 2) && ($maj < 22))) {
     
    370388#
    371389# Print only mode
     390local_fdisk($args,$device);
     391myexit(0);
     392
     393sub local_fdisk {
     394
     395my $args=shift;
     396my $device=shift;
     397
    372398print FLOG "Passing everything to the real fdisk with $args $device\n";
    373399
     
    388414    close(STDIN);
    389415}
    390 myexit(0);
    391 
     416return;
     417}
    392418
    393419# Is your system LSB ?
     
    415441return($cmd);
    416442}
     443
     444# Unused for now - Kept for reference in case there is a need later on
     445sub fdisk_list_all {
     446my $device = shift;
     447my $wpart = shift;
     448my $start = shift;
     449my $end = shift;
     450my $verbose = shift;
     451
     452return fdisk_list($device,$wpart,$start,$end,$verbose) if ((defined $device) && ($device ne ""));
     453
     454# If no device given loop on the list of devices found in /proc/partitions
     455open(PART,"/proc/partitions") || die "Unable to open /proc/partitions";
     456while (<PART>) {
     457    my ($maj,$min,$blocks,$dev) = split(/\s+/);
     458    next if ($dev =~ /^fd|^sr/);
     459    next if ($min != 0);
     460    fdisk_list("/dev/$dev",$wpart,$start,$end,$verbose);
     461}
     462close(PART);
     463}
     464
    417465
    418466sub fdisk_list {
     
    482530
    483531# This will return MB
    484 get_parted ($device,$start,$end,\%type);
     532get_parted($device,$start,$end,\%type);
    485533
    486534while (($n,$d) = each %type) {
Note: See TracChangeset for help on using the changeset viewer.