Changeset 91 in MondoRescue


Ignore:
Timestamp:
Oct 28, 2005, 12:12:48 AM (18 years ago)
Author:
bcornec
Message:

merge r88:90 of branch 2.04_berlios

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mindi/parted2fdisk.pl

    r89 r91  
    3131my $start = "";
    3232my $end = "";
     33my $cylstart;
     34my $cylend;
    3335my %start;
    3436my %end;
     
    123125        print FLOG "Not an msdos type of disk label\n";
    124126        if ($args =~ /-l/) {
    125             fdisk_list($device,undef,\%start,\%end);
     127            fdisk_list($device,undef,\%start,\%end, 1);
    126128        } elsif ($args =~ /-s/) {
    127             fdisk_list($device,$wpart,\%start,\%end);
     129            fdisk_list($device,$wpart,\%start,\%end, 1);
    128130        } elsif (($args =~ /-/) and ($fake == 0)) {
    129131            printf FLOG "Option not supported ($args) ...\n";
     
    136138            while ($i = <STDIN>) {
    137139                if ($i =~ /^p$/) {
    138                     fdisk_list($device,undef,\%start,\%end);
     140                    fdisk_list($device,undef,\%start,\%end, 1);
    139141                }
    140142                elsif ($i =~ /^n$/) {
    141                     fdisk_list($device,undef,\%start,\%end);
     143                    fdisk_list($device,undef,\%start,\%end, 0);
    142144                    if ($type ne "gpt") {
    143145                        print FLOG "Forcing GPT type of disk label\n";
    144146                        print FLOG "mklabel gpt\n";
    145                         system "$parted -s $device mklabel gpt\n" if ($fake != 0);
     147                        system "$parted -s $device mklabel gpt\n" if ($fake == 0);
    146148                        $type = "gpt";
    147149                    }
     
    158160                    }
    159161                    chomp($part);
    160                     $start = <STDIN>;
    161                     chomp($start);
    162                     if ((not (defined $start)) || ($start eq "")) {
     162                    $cylstart = <STDIN>;
     163                    chomp($cylstart);
     164                    if ((not (defined $cylstart)) || ($cylstart eq "")) {
    163165                        if (defined $start{$part-1}) {
    164                             $start = scalar $end{$part-1} + 0.001;
    165                             print FLOG "no start cyl given for creation... assuming the following $start\n";
     166                            # in MB => cyl
     167                            $cylstart = sprintf("%d",$end{$part-1}*1048576/$un + 1);
     168                            print FLOG "no start cyl given for creation... assuming the following $cylstart\n";
    166169                        } else {
    167170                            print FLOG "no start cyl given for creation... assuming the following 1\n";
    168                             $start = 1;
     171                            $cylstart = 1;
    169172                        }
    170173                    }
    171                     $start = 1 if ($start < 1);
    172                     print FLOG "start cyl : $start\n";
    173                     $un = get_un($device);
     174                    $cylstart = 1 if ($cylstart < 1);
     175                    print FLOG "start cyl : $cylstart\n";
     176                    $un = get_un($device, "", 0);
    174177                    # parted needs MB
    175                     $start = $start * $un / 1048576;
     178                    if ($cylstart == 1) {
     179                        $start = 0.01;
     180                    } else {
     181                        $start = $cylstart* $un / 1048576 +0.001;
     182                    }
    176183                    # this is a size in B/KB/MB/GB
     184
    177185                    $endmax = get_max($device);
    178                     $end = <STDIN>;
    179                     chomp($end);
    180                     if ((not (defined $end)) || ($end eq "")) {
     186                    $cylend = <STDIN>;
     187                    chomp($cylend);
     188                    if ((not (defined $cylend)) || ($cylend eq "")) {
    181189                        print FLOG "no end cyl given for creation... assuming full disk)\n";
    182                         $end = $endmax;
     190                        $cylend = $endmax;
    183191                    }
    184192                    # Handles end syntaxes (+, K, M, ...)
    185193                    # to give cylinders
    186                     if ($end =~ /^\+/) {
    187                         $end =~ s/^\+//;
    188                         if ($end =~ /K$/) {
    189                             $end =~ s/K$//;
    190                             $end *= 1000;
    191                         } elsif ($end =~ /M$/) {
    192                             $end =~ s/M$//;
    193                             $end *= 1000000;
    194                         } elsif ($end =~ /G$/) {
    195                             $end =~ s/G$//;
    196                             $end *= 1000000000;
     194                    if ($cylend =~ /^\+/) {
     195                        $cylend =~ s/^\+//;
     196                        if ($cylend =~ /K$/) {
     197                            $cylend =~ s/K$//;
     198                            $cylend *= 1024;
     199                        } elsif ($cylend =~ /M$/) {
     200                            $cylend =~ s/M$//;
     201                            $cylend *= 1048576;
     202                        } elsif ($cylend =~ /G$/) {
     203                            $cylend =~ s/G$//;
     204                            $cylend *= 1073741824;
    197205                        }
    198206                        # This gives the number of cyl
    199                         $end /= $un;
    200                         $end = sprintf("%d",$end);
    201                         $end += $start - 0.001;
     207                        $cylend /= $un;
     208                        $cylend = sprintf("%d",$cylend);
     209                        $cylend += $cylstart - 0.001;
    202210                        # We now have the end cyl
    203211                    }
    204                     print FLOG "end cyl : $end\n";
     212                    $cylend = $endmax if ($cylend > $endmax);
     213                    print FLOG "end cyl : $cylend\n";
    205214                    # parted needs MB
    206                     $end = $end * $un / 1048576;
    207                     $end = $endmax if ($end > $endmax);
    208                     print FLOG "n $l $part => mkpart primary $start $end\n";
    209                     system "$parted -s $device mkpart primary ext2 $start $end\n" if ($fake != 0);
     215                    $end = $cylend * $un / 1048576;
     216                    print FLOG "n $l $part $cylstart $cylend => mkpart primary $start $end\n";
     217                    system "$parted -s $device mkpart primary ext2 $start $end\n" if ($fake == 0);
    210218                }
    211219                elsif ($i =~ /^d$/) {
     
    217225                    chomp($part);
    218226                    print FLOG "d $part => rm $part\n";
    219                     system "$parted -s $device rm $part\n" if ($fake != 0);
    220                     get_parted($device,undef,\%start,\%end,undef,undef);
     227                    system "$parted -s $device rm $part\n" if ($fake == 0);
     228                    get_parted($device,undef,\%start,\%end,undef);
    221229                }
    222230                elsif ($i =~ /^w$/) {
     
    240248                        next;
    241249                    }
    242                     print FLOG "t $part => mkfs $part $pnum{$l}\n";
    243                     system "$parted -s $device mkfs $part $pnum{$l}\n" if ($fake != 0);
     250                    print FLOG "t $part $l => mkfs $part $pnum{$l}\n";
     251                    system "$parted -s $device mkfs $part $pnum{$l}\n" if ($fake == 0);
    244252                }
    245253                elsif ($i =~ /^a$/) {
     
    251259                    chomp($part);
    252260                    print FLOG "a $part => set $part boot on\n";
    253                     system "$parted -s $device set $part boot on\n" if ($fake != 0);
     261                    system "$parted -s $device set $part boot on\n" if ($fake == 0);
    254262                }
    255263                elsif ($i =~ /^q$/) {
     
    341349my $start = shift;
    342350my $end = shift;
     351my $verbose = shift;
    343352
    344353my $un;
     
    389398#
    390399# this will return bytes
    391 $un = get_un ($device,$wpart);
     400$un = get_un ($device,$wpart,$verbose);
     401
    392402$endmax = get_max($device);
     403
    393404# This will return MB
    394405get_parted ($device,$start,$end,\%type,\%flags);
     
    407418    $pid = $pid{$type{$n}};
    408419    $cmt = $cmt{$type{$n}};
    409     print FLOG "$part - $mstart - $mend - $length\n";
    410 
    411     if (not (defined $wpart)) {
    412         if (length($part) > 13) {
    413             open(STDOUT2,">&STDOUT") || die "Unable to open STDOUT2";
    414             select(STDOUT2);
    415             write;
    416             open(FLOG2,">&FLOG") || die "Unable to open FLOG2";
    417             select(FLOG2);
    418             write;
    419             select(STDOUT);
    420             close(FLOG2);
    421             close(STDOUT2);
     420    #print FLOG "$part - $mstart - $mend - $length\n";
     421
     422    if ($verbose == 1) {
     423        if (not (defined $wpart)) {
     424            if (length($part) > 13) {
     425                open(STDOUT2,">&STDOUT") || die "Unable to open STDOUT2";
     426                select(STDOUT2);
     427                write;
     428                open(FLOG2,">&FLOG") || die "Unable to open FLOG2";
     429                select(FLOG2);
     430                write;
     431                select(STDOUT);
     432                close(FLOG2);
     433                close(STDOUT2);
     434            } else {
     435                open(STDOUT1,">&STDOUT") || die "Unable to open STDOUT1";
     436                select(STDOUT1);
     437                write;
     438                open(FLOG1,">&FLOG") || die "Unable to open FLOG1";
     439                select(FLOG1);
     440                write;
     441                select(STDOUT);
     442                close(FLOG1);
     443                close(STDOUT1);
     444            }
    422445        } else {
    423             open(STDOUT1,">&STDOUT") || die "Unable to open STDOUT1";
    424             select(STDOUT1);
    425             write;
    426             open(FLOG1,">&FLOG") || die "Unable to open FLOG1";
    427             select(FLOG1);
    428             write;
    429             select(STDOUT);
    430             close(FLOG1);
    431             close(STDOUT1);
     446            # manage the -s option of fdisk here
     447            print "$length\n" if ($part eq $wpart);
     448            print FLOG "$part has $length KBytes\n" if ($part eq $wpart);
    432449        }
    433     } else {
    434         # manage the -s option of fdisk here
    435         print "$length\n" if ($part eq $wpart);
    436         print FLOG "$part has $length KBytes\n" if ($part eq $wpart);
    437450    }
    438451}
     
    470483my $device = shift;
    471484my $wpart = shift;
     485my $verbose = shift;
    472486my $un = 0;
    473487my $foo;
     
    475489open (FDISK, "$fdisk -l $device |") || die "Unable to read from $fdisk";
    476490while (<FDISK>) {
    477     print if (($_ !~ /^\/dev\//) and (not (defined $wpart)));
     491    print if (($_ !~ /^\/dev\//) and (not (defined $wpart)) and ($verbose == 1));
    478492    if ($_ =~ /^Units/) {
    479493        ($foo, $un , $foo) = split /=/;
Note: See TracChangeset for help on using the changeset viewer.