Changeset 88 in MondoRescue for branches


Ignore:
Timestamp:
Oct 27, 2005, 10:35:13 PM (18 years ago)
Author:
bcornec
Message:

ia64:

  • corrects units issues in parted2fdisk.pl (cyl vs MB)
  • add -n option to parted2fdisk.pl
  • improve GPT support during partition restoration
Location:
branches/2.04_berlios
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.04_berlios/mindi/parted2fdisk.pl

    r30 r88  
    11#!/usr/bin/perl -w
    22#
     3# $Id$
     4#
    35# parted2fdisk: fdisk like interface for parted
    4 # [developped for mindi/mondo http://www.mondorescue.org]
     6# [developped for mindi/mondo http://mondorescue.berlios.de]
    57#
    68# Aims to be architecture independant (i386/ia64)
     
    3436my %flags;
    3537my $arch;
     38my $fake = 0;
    3639
    3740# Determine on which arch we're running
     
    5760my $args = "";
    5861my $device = "";
     62my $endmax = "";
    5963
    6064if ($#ARGV < 0) {
     
    104108}
    105109
     110if ($args =~ /-n/) {
     111    print FLOG "Fake mode. Nothing will be really done\n";
     112    $fake = 1;
     113}
     114
    106115print FLOG "Called with device $device and arg $args\n";
    107116
     
    117126        } elsif ($args =~ /-s/) {
    118127            fdisk_list($device,$wpart,\%start,\%end);
    119         } elsif ($args =~ /-/) {
     128        } elsif (($args =~ /-/) and ($fake == 0)) {
    120129            printf FLOG "Option not supported ($args) ...\n";
    121130            printf FLOG "Please report to the author\n";
     
    134143                        print FLOG "Forcing GPT type of disk label\n";
    135144                        print FLOG "mklabel gpt\n";
    136                         system "$parted -s $device mklabel gpt\n";
     145                        system "$parted -s $device mklabel gpt\n" if ($fake != 0);
    137146                        $type = "gpt";
    138147                    }
     
    160169                        }
    161170                    }
     171                    $start = 1 if ($start < 1);
    162172                    print FLOG "start cyl : $start\n";
     173                    $un = get_un($device);
     174                    # parted needs MB
     175                    $start = $start * $un / 1048576;
     176                    # this is a size in B/KB/MB/GB
     177                    $endmax = get_max($device);
    163178                    $end = <STDIN>;
    164179                    chomp($end);
    165180                    if ((not (defined $end)) || ($end eq "")) {
    166181                        print FLOG "no end cyl given for creation... assuming full disk)\n";
    167                         $end = get_max($device);
    168                     }
    169                     $un = get_un($device);
     182                        $end = $endmax;
     183                    }
    170184                    # Handles end syntaxes (+, K, M, ...)
     185                    # to give cylinders
    171186                    if ($end =~ /^\+/) {
    172187                        $end =~ s/^\+//;
     
    181196                            $end *= 1000000000;
    182197                        }
     198                        # This gives the number of cyl
    183199                        $end /= $un;
    184                         $end = int($end)+1;
     200                        $end = sprintf("%d",$end);
    185201                        $end += $start - 0.001;
     202                        # We now have the end cyl
    186203                    }
    187204                    print FLOG "end cyl : $end\n";
    188                     print FLOG "n $l $part $start $end => mkpart primary $start $end\n";
    189                     system "$parted -s $device mkpart primary ext2 $start $end\n";
     205                    # 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);
    190210                }
    191211                elsif ($i =~ /^d$/) {
     
    197217                    chomp($part);
    198218                    print FLOG "d $part => rm $part\n";
    199                     system "$parted -s $device rm $part\n";
     219                    system "$parted -s $device rm $part\n" if ($fake != 0);
    200220                    get_parted($device,undef,\%start,\%end,undef,undef);
    201221                }
     
    221241                    }
    222242                    print FLOG "t $part => mkfs $part $pnum{$l}\n";
    223                     system "$parted -s $device mkfs $part $pnum{$l}\n";
     243                    system "$parted -s $device mkfs $part $pnum{$l}\n" if ($fake != 0);
    224244                }
    225245                elsif ($i =~ /^a$/) {
     
    231251                    chomp($part);
    232252                    print FLOG "a $part => set $part boot on\n";
    233                     system "$parted -s $device set $part boot on\n";
     253                    system "$parted -s $device set $part boot on\n" if ($fake != 0);
    234254                }
    235255                elsif ($i =~ /^q$/) {
     
    323343
    324344my $un;
     345my $endmax;
    325346my $d;
    326347my $n;
     
    367388# Keep Fdisk headers
    368389#
     390# this will return bytes
    369391$un = get_un ($device,$wpart);
     392$endmax = get_max($device);
     393# This will return MB
    370394get_parted ($device,$start,$end,\%type,\%flags);
    371395
     
    373397    # Print infos fdisk like
    374398    $part = ${device}.$n;
    375     $mstart = sprintf("%d",int($$start{$n}));
    376     $mend = sprintf("%d",int($$end{$n}));
    377     $length = sprintf("%d",($mend-$mstart+1)*$un/1048576);
     399    # start and end are in cylinder in fdisk format
     400    # so return in MB * 1MB / what represents 1 cyl in B
     401    $mstart = sprintf("%d",$$start{$n}*1048576/$un);
     402    $mstart = 1 if ($mstart < 1);
     403    $mend = sprintf("%d",$$end{$n}*1048576/$un - 1);
     404    $mend = $endmax if ($mend > $endmax);
     405    # length is in 1K blocks
     406    $length = sprintf("%d",($mend-$mstart+1)*$un/1024);
    378407    $pid = $pid{$type{$n}};
    379408    $cmt = $cmt{$type{$n}};
     
    404433    } else {
    405434        # manage the -s option of fdisk here
    406         my $s = int(eval("$length/1048576*$un*1024"));
    407         print "$s\n" if ($part eq $wpart);
    408         print FLOG "$part has $s Bytes\n" if ($part eq $wpart);
     435        print "$length\n" if ($part eq $wpart);
     436        print FLOG "$part has $length KBytes\n" if ($part eq $wpart);
    409437    }
    410438}
     
    424452open (FDISK, "$fdisk -l $device |") || die "Unable to read from $fdisk";
    425453while (<FDISK>) {
    426     if ($_ =~ /^Disk/) {
    427         ($foo, $un , $foo) = split /=/;
    428         $max =~ s/.*sectors,([0-9]+) cylinders/$1/g;
    429         $max = eval($max);
     454    if ($_ =~ /heads/) {
     455        chomp;
     456        $max = $_;
     457        $max =~ s/.* ([0-9]+) cylinders/$1/;
    430458    }
    431459}
     
    436464
    437465#
    438 # Get units from fdisk
     466# Get units from fdisk (cylinder size)
    439467#
    440468sub get_un {
     
    459487}
    460488
     489#
     490# Parted gives info in MB
     491#
    461492sub get_parted {
    462493
  • branches/2.04_berlios/mondo/mondo/mondorestore/mondo-prep.c

    r85 r88  
    16811681    sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
    16821682
     1683    /* BERLIOS: shoould not be called each time */
     1684    part_table_fmt = which_partition_format(drive);
    16831685    output[0] = '\0';
    16841686    /* make it a primary/extended/logical */
     
    16861688        sprintf(output + strlen(output), "n\np\n%d\n", partno);
    16871689    } else {
    1688         if (partno == 5) {
    1689             part_table_fmt = which_partition_format(drive);
     1690        /* MBR needs an extended partition if more than 4 partitions */
     1691        if (strcmp(part_table_fmt,"MBR") == 0) {
     1692            if (partno == 5) {
     1693                if (prev_partno >= 4) {
     1694                    log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
     1695                    paranoid_free(program);
     1696                    paranoid_free(partition_name);
     1697                    paranoid_free(tmp);
     1698                    paranoid_free(logfile);
     1699                    paranoid_free(output);
     1700                    return (1);
     1701                } else {
     1702                    sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1);
     1703                }
     1704            }
     1705            strcat(output + strlen(output), "n\nl\n");
     1706        } else {
    16901707            /* GPT allows more than 4 primary partitions */
    1691             if ((prev_partno >= 4) && (strcmp(part_table_fmt,"MBR") == 0)) {
    1692                 log_to_screen("You need to leave at least one partition free, for 'extended/logical'");
    1693                 paranoid_free(program);
    1694                 paranoid_free(partition_name);
    1695                 paranoid_free(tmp);
    1696                 paranoid_free(logfile);
    1697                 paranoid_free(output);
    1698                 return (1);
    1699             } else {
    1700                 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1);
    1701             }
    1702         }
    1703         strcat(output + strlen(output), "n\nl\n");
     1708            sprintf(output + strlen(output), "n\np\n%d\n", partno);
     1709        }
    17041710    }
    17051711    strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
Note: See TracChangeset for help on using the changeset viewer.