Changeset 91 in MondoRescue
- Timestamp:
- Oct 28, 2005, 12:12:48 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mindi/parted2fdisk.pl
r89 r91 31 31 my $start = ""; 32 32 my $end = ""; 33 my $cylstart; 34 my $cylend; 33 35 my %start; 34 36 my %end; … … 123 125 print FLOG "Not an msdos type of disk label\n"; 124 126 if ($args =~ /-l/) { 125 fdisk_list($device,undef,\%start,\%end );127 fdisk_list($device,undef,\%start,\%end, 1); 126 128 } elsif ($args =~ /-s/) { 127 fdisk_list($device,$wpart,\%start,\%end );129 fdisk_list($device,$wpart,\%start,\%end, 1); 128 130 } elsif (($args =~ /-/) and ($fake == 0)) { 129 131 printf FLOG "Option not supported ($args) ...\n"; … … 136 138 while ($i = <STDIN>) { 137 139 if ($i =~ /^p$/) { 138 fdisk_list($device,undef,\%start,\%end );140 fdisk_list($device,undef,\%start,\%end, 1); 139 141 } 140 142 elsif ($i =~ /^n$/) { 141 fdisk_list($device,undef,\%start,\%end );143 fdisk_list($device,undef,\%start,\%end, 0); 142 144 if ($type ne "gpt") { 143 145 print FLOG "Forcing GPT type of disk label\n"; 144 146 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); 146 148 $type = "gpt"; 147 149 } … … 158 160 } 159 161 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 "")) { 163 165 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"; 166 169 } else { 167 170 print FLOG "no start cyl given for creation... assuming the following 1\n"; 168 $ start = 1;171 $cylstart = 1; 169 172 } 170 173 } 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); 174 177 # 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 } 176 183 # this is a size in B/KB/MB/GB 184 177 185 $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 "")) { 181 189 print FLOG "no end cyl given for creation... assuming full disk)\n"; 182 $ end = $endmax;190 $cylend = $endmax; 183 191 } 184 192 # Handles end syntaxes (+, K, M, ...) 185 193 # 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; 197 205 } 198 206 # 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; 202 210 # We now have the end cyl 203 211 } 204 print FLOG "end cyl : $end\n"; 212 $cylend = $endmax if ($cylend > $endmax); 213 print FLOG "end cyl : $cylend\n"; 205 214 # 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); 210 218 } 211 219 elsif ($i =~ /^d$/) { … … 217 225 chomp($part); 218 226 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); 221 229 } 222 230 elsif ($i =~ /^w$/) { … … 240 248 next; 241 249 } 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); 244 252 } 245 253 elsif ($i =~ /^a$/) { … … 251 259 chomp($part); 252 260 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); 254 262 } 255 263 elsif ($i =~ /^q$/) { … … 341 349 my $start = shift; 342 350 my $end = shift; 351 my $verbose = shift; 343 352 344 353 my $un; … … 389 398 # 390 399 # this will return bytes 391 $un = get_un ($device,$wpart); 400 $un = get_un ($device,$wpart,$verbose); 401 392 402 $endmax = get_max($device); 403 393 404 # This will return MB 394 405 get_parted ($device,$start,$end,\%type,\%flags); … … 407 418 $pid = $pid{$type{$n}}; 408 419 $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 } 422 445 } 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); 432 449 } 433 } else {434 # manage the -s option of fdisk here435 print "$length\n" if ($part eq $wpart);436 print FLOG "$part has $length KBytes\n" if ($part eq $wpart);437 450 } 438 451 } … … 470 483 my $device = shift; 471 484 my $wpart = shift; 485 my $verbose = shift; 472 486 my $un = 0; 473 487 my $foo; … … 475 489 open (FDISK, "$fdisk -l $device |") || die "Unable to read from $fdisk"; 476 490 while (<FDISK>) { 477 print if (($_ !~ /^\/dev\//) and (not (defined $wpart)) );491 print if (($_ !~ /^\/dev\//) and (not (defined $wpart)) and ($verbose == 1)); 478 492 if ($_ =~ /^Units/) { 479 493 ($foo, $un , $foo) = split /=/;
Note:
See TracChangeset
for help on using the changeset viewer.