source: MondoRescue/branches/3.3/mindi/mr-parted2fdisk@ 3631

Last change on this file since 3631 was 3631, checked in by Bruno Cornec, 7 years ago

Fix a missing dependency on FileHandle for the autoflush feature (missing at restore otherwise)

  • Property svn:keywords set to Id
File size: 18.4 KB
Line 
1#!/usr/bin/perl -w
2#
3# $Id: mr-parted2fdisk 3631 2016-12-21 16:50:11Z bruno $
4#
5# mr-parted2fdisk: fdisk like interface for parted
6# [developed for mindi/mondo http://www.mondorescue.org]
7#
8# Aims to be architecture independant (i386/ia64)
9# Tested on ia64 with RHAS 2.1 - Mandrake 9.0 - RHEL 3.0 - SLES 10 - RHEL 5 -
10#
11# Copyright B. Cornec 2000-2015
12# Provided under the GPL v2
13
14use strict;
15use File::Basename;
16use Getopt::Long qw(:config auto_abbrev no_ignore_case);
17use Carp qw/confess cluck/;
18use Data::Dumper;
19use English;
20use FileHandle;
21use MondoRescue::Version;
22use MondoRescue::Base;
23use MondoRescue::Disk;
24use ProjectBuilder::Base;
25
26=pod
27
28=head1 NAME
29
30mr-parted2fdisk is a fdisk like command using parted internally for analysing GPT labelled disks
31
32=head1 DESCRIPTION
33
34mr-parted2fdisk behaves like the fdisk command, but dialog internally with parted in order to manipulate partition tables, which allow it to support GPT partition format as well as MBR, contrary to fdisk. It aims at providing compatible external interface with fdisk. Developed initialy for ia64 Linux, it is also useful now on x86 systems using GPT partition format (for large HDDs).
35
36=head1 SYNOPSIS
37
38mr-parted2fdisk -s partition
39
40mr-parted2fdisk -l [device]
41
42mr-parted2fdisk [-n] device
43
44=head1 OPTIONS
45
46=over 4
47
48=item B<-s>
49
50Print the size (in blocks) of the given partition.
51
52=item B<-l>
53
54List the partition tables for the specified device (or all if none specified) and then exit.
55
56=item B<-n>
57
58Fake mode. Doesn't pass the commands just simulate.
59
60=item B<-v>
61
62Verbose mode. Used to help debugging issues.
63
64=item B<no option>
65
66Allow the creation and manipulation of partition tables.
67
68=back
69
70=head1 ARGUMENTS
71
72=over 4
73
74=item B<partition>
75
76partition device file (only used with -s option).
77
78=item B<device>
79
80device file to work on.
81
82=back
83
84=head1 WEB SITES
85
86The main Web site of the project is available at L<http://www.mondorescue.org>. Bug reports should be filled using the trac instance of the project at L<http://trac.mondorescue.org/>.
87
88=head1 USER MAILING LIST
89
90For community exchanges around MondoRescue please use the list L<http://sourceforge.net/mailarchive/forum.php?forum_name=mondo-devel>
91
92=head1 AUTHORS
93
94The MondoRescue team lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
95
96=head1 COPYRIGHT
97
98MondoRescue is distributed under the GPL v2.0 license or later,
99described in the file C<COPYING> included with the distribution.
100
101=cut
102
103
104$ENV{LANG} = "C";
105$ENV{LANGUAGE} = "C";
106$ENV{LC_ALL} = "C";
107
108# Log
109my $flog = "/var/log/mr-parted2fdisk.log";
110open(FLOG, "> $flog") || die "Unable to open $flog";
111
112my $i;
113my $l;
114my $part;
115my $wpart;
116my $start = "";
117my $end = "";
118my $cylstart;
119my $cylend;
120my %start;
121my %end;
122my %type;
123my $fake = 0;
124my $mega = 1048576;
125my %opts;
126
127# Immediate flushing to avoids read error from mondorestore in log files
128$| = 1;
129
130#
131# We always use fdisk except with GPT types of
132# partition tables where we need parted
133# All should return fdisk like format so that callers
134# think they have called fdisk directly
135#
136my $un;
137my $type;
138my $device;
139my $endmax = "";
140my $appname = "mr-parted2fdisk";
141my ($mrver,$mrrev) = mr_version_init();
142
143pb_syntax_init("$appname Version $mrver-$mrrev\n");
144
145if ($#ARGV < 0) {
146 pb_syntax(-1,0);
147}
148
149GetOptions("help|?|h+" => \$opts{'h'},
150 "device|d|s=s" => \$opts{'s'},
151 "list|l" => \$opts{'l'},
152 "Log-File|L=s" => \$opts{'L'},
153 "man" => \$opts{'man'},
154 "noop|n" => \$opts{'n'},
155 "quiet|q" => \$opts{'q'},
156 "version|V=s" => \$opts{'V'},
157 "verbose|v+" => \$opts{'v'},
158 "stop-on-error!" => \$Global::pb_stop_on_error,
159) || pb_syntax(-1,0);
160
161if (defined $opts{'L'}) {
162 open(pbLOG,"> $opts{'L'}") || die "Unable to log to $opts{'L'}: $!";
163 $pbLOG = \*pbLOG;
164 }
165pb_log_init($opts{'v'}, $pbLOG);
166
167# We support at most one option and one device
168if ((defined $opts{'l'}) && (defined $opts{'s'})) {
169 pb_syntax(-1,0);
170}
171
172# Create a device var which will be the devide or partition on which to work
173# whatever the option used.
174$device = $ARGV[0] if (defined $opts{'l'});
175$device = $opts{'s'} if (defined $opts{'s'});
176$device = $ARGV[0] if (defined $ARGV[0]);
177$device = "" if ((not defined $device) || ($device =~ /^-/));
178
179# -s takes a partition as arg
180# so create a correct device from that
181if (defined $opts{'s'}) {
182 $wpart = $device;
183 # To support dev like cciss/c0d0p1
184 if ($device =~ /([0-9]+)p[0-9]+$/) {
185 $device =~ s/([0-9]+)p[0-9]+$/$1/;
186 } else {
187 $device =~ s/[0-9]+$//;
188 }
189}
190
191if (defined $opts{'n'}) {
192 print FLOG "Fake mode. Nothing will be really done\n";
193 $fake = 1;
194}
195
196pb_log(1,"Called with device: $device\n");
197
198my %pid = ( "FAT" => "6",
199 "fat32" => "b",
200 "fat16" => "e",
201 "ext2" => "83",
202 "ext3" => "83",
203 "ext4" => "83",
204 "xfs" => "83",
205 "btrfs" => "83",
206 "reiserfs" => "83",
207 "linux-swap" => "82",
208 "lvm" => "8e",
209 "raid" => "fd",
210 "" => "",
211 );
212my %pnum;
213
214# Reverse table of pid
215while (($i,$l) = each %pid) {
216 next if ($i eq "ext2");
217 $pnum{$l} = $i;
218}
219
220# util-linux/fdisk version
221my $fdisk = pb_check_req("fdisk",0);
222open(CMD,"$fdisk -v |") || die "Unable to execute $fdisk";
223my $version = <CMD>;
224close(CMD);
225chomp($version);
226# RHEL 5 has fdisk from util-linux 2.13-pre7
227# Mageia 4 has fdisk from util-linux 2.24.2
228$version =~ s/[^0-9\.]*([0-9a-z\.-]+)[\)]*$/$1/;
229my ($v,$maj,$min) = split(/\./,$version);
230
231# Consider pre version the same as the following for formats
232if ((defined $maj) && ($maj =~ /-pre/)) {
233 $maj =~ s/-pre.*$//;
234 $maj++;
235}
236# Remove potential remaining letters
237$maj =~ s/[a-z]+//;
238
239if ((defined $min) && ($min =~ /-pre/)) {
240 $min =~ s/-pre.*$//;
241 $min++;
242}
243$min =~ s/[a-z]+// if (defined $min);
244
245# Check partition table type
246$type = mr_disk_type($device);
247# Replacement code only for GPT disks
248if ((($v == 1) || (($v == 2) && ($maj < 22))) && ($type ne "MBR")) {
249 pb_log(1,"This distribution uses an old fdisk, activating replacement code for GPT disk label...\n");
250 my $parted = pb_check_req("parted",0);
251 if (defined $opts{'l'}) {
252 fdisk_list($device,undef,\%start,\%end, 1);
253 } elsif (defined $opts{'s'}) {
254 fdisk_list($device,$wpart,\%start,\%end, 1);
255 } else {
256 # Read fdisk orders on stdin and pass them to parted
257 # on the command line as parted doesn't read on stdin
258 pb_log(1,"Translating fdisk command to parted\n");
259 while ($i = <STDIN>) {
260 if ($i =~ /^p$/) {
261 fdisk_list($device,undef,\%start,\%end, 1);
262 print "command (m for help) sent back to fake fdisk for mondorestore\n";
263 } elsif ($i =~ /^n$/) {
264 fdisk_list($device,undef,\%start,\%end, 0);
265 if ($type ne "GPT") {
266 pb_log(1,"Forcing GPT type of disk label\n");
267 pb_log(1,"mklabel gpt\n");
268 pb_system("$parted -s $device mklabel gpt\n") if ($fake == 0);
269 $type = "GPT";
270 }
271 $l = <STDIN>;
272 if (not defined $l) {
273 pb_log(1,"no primary/extended arg given for creation... assuming primary\n");
274 $l = "p";
275 }
276 chomp($l);
277 $part = <STDIN>;
278 if ((not defined $part) || ($part eq "")) {
279 pb_log(1,"no partition given for creation... skipping\n");
280 next;
281 }
282 chomp($part);
283 $cylstart = <STDIN>;
284 chomp($cylstart);
285 if ((not defined $cylstart) || ($cylstart eq "")) {
286 if (defined $start{$part-1}) {
287 # in MB => cyl
288 $cylstart = sprintf("%d",$end{$part-1}*$mega/$un + 1);
289 } else {
290 $cylstart = 1;
291 }
292 pb_log(1,"no start cyl given for creation... assuming the following: $cylstart\n");
293 } else {
294 pb_log(1,"start cyl: $cylstart\n");
295 }
296 $cylstart = 1 if ($cylstart < 1);
297 $un = get_un($device, "", 0);
298 # parted needs MB
299 if ($cylstart == 1) {
300 $start = 0.01;
301 } else {
302 $start = $cylstart* $un / $mega + 0.001;
303 }
304 # this is a size in B/KB/MB/GB
305
306 $endmax = get_max($device);
307 $cylend = <STDIN>;
308 chomp($cylend);
309 if ((not defined $cylend) || ($cylend eq "")) {
310 pb_log(1,"no end cyl given for creation... assuming full disk)\n");
311 $cylend = $endmax;
312 }
313 # Handles end syntaxes (+, K, M, ...)
314 # to give cylinders
315 if ($cylend =~ /^\+/) {
316 $cylend =~ s/^\+//;
317 # Handles suffixes; return bytes
318 $cylend = decode_Bsuf($cylend,1);
319 # This gives the number of cyl
320 $cylend /= $un;
321 $cylend = sprintf("%d",$cylend);
322 $cylend += $cylstart - 0.001;
323 # We now have the end cyl
324 }
325 $cylend = $endmax if ($cylend > $endmax);
326 pb_log(1,"end cyl: $cylend\n");
327 # parted needs MB
328 $end = $cylend * $un / $mega;
329 pb_log(1,"n $l $part $cylstart $cylend => mkpart primary $start $end\n");
330 pb_system("$parted -s $device mkpart primary ext2 $start $end\n") if ($fake == 0);
331 print "command (m for help) sent back to fake fdisk for mondorestore\n";
332 } elsif ($i =~ /^d$/) {
333 $part = <STDIN>;
334 if (not defined $part) {
335 pb_log(1,"no partition given for deletion... skipping\n");
336 next;
337 }
338 chomp($part);
339 pb_log(1,"d $part => rm $part\n");
340 pb_system("$parted -s $device rm $part\n") if ($fake == 0);
341 get_parted($device,undef,\%start,\%end,undef);
342 print "command (m for help) sent back to fake fdisk for mondorestore\n";
343 } elsif ($i =~ /^w$/) {
344 pb_log(1,"w => quit\n");
345 } elsif ($i =~ /^t$/) {
346 $part = <STDIN>;
347 if (not defined $part) {
348 pb_log(1,"no partition given for tagging... skipping\n");
349 next;
350 }
351 chomp($part);
352 # If no partition number given it's 1, and we received the type
353 if ($part !~ /\d+/) {
354 $l = $part;
355 $part = 1
356 } else {
357 $l = <STDIN>;
358 }
359 if (not defined $l) {
360 pb_log(1,"no type given for tagging partition $part... skipping\n");
361 next;
362 }
363 chomp($l);
364 if (not defined $pnum{$l}) {
365 pb_log(1,"no partition number given for $l... please report to the author\n");
366 next;
367 }
368
369 if ($pnum{$l} eq "lvm") {
370 # In that case this is a flag set, not a mkfs
371 pb_log(1,"t $part $l => set $part $pnum{$l} on\n");
372 pb_system("$parted -s $device set $part $pnum{$l} on\n") if ($fake == 0);
373 } else {
374 pb_log(1,"t $part $l => mkfs $part $pnum{$l}\n");
375 pb_system("$parted -s $device mkfs $part $pnum{$l}\n") if ($fake == 0);
376 }
377 print "command (m for help) sent back to fake fdisk for mondorestore\n";
378 } elsif ($i =~ /^a$/) {
379 $part = <STDIN>;
380 if (not defined $part) {
381 pb_log(1,"no partition given for tagging... skipping\n");
382 next;
383 }
384 chomp($part);
385
386 # Partition shouldn't be negative or null. Then take the first one.
387 $part = 1 if ($part le 0);
388
389 pb_log(1,"a $part => set $part boot on\n");
390 pb_system("$parted -s $device set $part boot on\n") if ($fake == 0);
391 print "command (m for help) sent back to fake fdisk for mondorestore\n";
392 } elsif ($i =~ /^q$/) {
393 pb_log(1,"q => quit\n");
394 } else {
395 pb_log(1,"Unknown command: $i\n");
396 print "command (m for help) sent back to fake fdisk for mondorestore\n";
397 next;
398 }
399
400 }
401 }
402 exit(0);
403}
404
405#
406# Else everything is for fdisk
407#
408# Print only mode
409local_fdisk(\%opts,$device);
410exit(0);
411
412# End of main
413
414
415sub local_fdisk {
416
417my $opts=shift;
418my $device=shift;
419
420pb_log(1,"Passing everything to the real fdisk with device: $device\n");
421pb_log(1,"and the -s $wpart option\n") if (defined $opts{'s'});
422
423if ((defined $opts->{'l'}) || (defined $opts->{'s'})) {
424 my $args = "-l $device" if (defined $opts->{'l'});
425 $args = "-s $wpart" if (defined $opts->{'s'});
426 open (FDISK, "$fdisk $args 2>/dev/null |") || die "Unable to read from $fdisk";
427 while (<FDISK>) {
428 print $_;
429 }
430 close(FDISK);
431} else {
432 # Modification mode
433 open (FDISK, "| $fdisk $device 2>/dev/null") || die "Unable to modify through $fdisk";
434 # disable fdisk output buffering
435 autoflush FDISK 1;
436 while (<STDIN>) {
437 print FDISK $_;
438 }
439 close(FDISK);
440 close(STDIN);
441}
442return;
443}
444
445# Unused for now - Kept for reference in case there is a need later on
446sub fdisk_list_all {
447
448my $device = shift;
449my $wpart = shift;
450my $start = shift;
451my $end = shift;
452my $verbose = shift;
453
454return fdisk_list($device,$wpart,$start,$end,$verbose) if ((defined $device) && ($device ne ""));
455
456# If no device given loop on the list of devices found in /proc/partitions
457open(PART,"/proc/partitions") || die "Unable to open /proc/partitions";
458while (<PART>) {
459 my ($maj,$min,$blocks,$dev) = split(/\s+/);
460 next if ($dev =~ /^fd|^sr/);
461 next if ($min != 0);
462 fdisk_list("/dev/$dev",$wpart,$start,$end,$verbose);
463}
464close(PART);
465}
466
467
468sub fdisk_list {
469
470my $device = shift;
471my $wpart = shift;
472my $start = shift;
473my $end = shift;
474my $verbose = shift;
475
476my $un;
477my $endmax;
478my $d;
479my $n;
480
481my %cmt = ( "FAT" => "FAT",
482 "ext2" => "Linux",
483 "ext3" => "Linux",
484 "ext4" => "Linux",
485 "xfs" => "Linux",
486 "reiserfs" => "Linux",
487 "linux-swap" => "Linux swap",
488 "lvm" => "Linux LVM",
489 "raid" => "RAID Linux auto",
490 "fat16" => "fat16",
491 "fat32" => "fat32",
492 "" => "Linux",
493);
494
495my $part;
496my $mstart;
497my $mend;
498my $length;
499my $pid;
500my $cmt;
501format FLOG1 =
502@<<<<<<<<<<<< @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>> @>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
503$part, $mstart, $mend, $length, $pid, $cmt
504.
505format FLOG2 =
506@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
507$part,
508 @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>> @>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
509 $mstart, $mend, $length, $pid, $cmt
510.
511format STDOUT1 =
512@<<<<<<<<<<<< @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>> @>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
513$part, $mstart, $mend, $length, $pid, $cmt
514.
515format STDOUT2 =
516@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
517$part,
518 @>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>>> @>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<
519 $mstart, $mend, $length, $pid, $cmt
520.
521# Device Boot Start End Blocks Id System
522#/dev/hda1 1 77579 39099374+ ee EFI GPT
523
524
525#
526# Keep Fdisk headers
527#
528# this will return bytes
529$un = get_un($device,$wpart,$verbose);
530
531$endmax = get_max($device);
532
533# This will return MB
534get_parted($device,$start,$end,\%type);
535
536while (($n,$d) = each %type) {
537 # Print infos fdisk like
538 $part = ${device}.$n;
539 # start and end are in cylinder in fdisk format
540 # so return in MB * 1MB / what represents 1 cyl in B
541 $mstart = sprintf("%d",$$start{$n}*$mega/$un);
542 $mstart = 1 if ($mstart < 1);
543 $mstart = $endmax if ($mstart > $endmax);
544 $mend = sprintf("%d",$$end{$n}*$mega/$un - 1);
545 $mend = $endmax if ($mend > $endmax);
546 $mend = 1 if ($mend < 1);
547 # length is in 1K blocks
548 $length = sprintf("%d",($mend-$mstart+1)*$un/1024);
549 $pid = $pid{$type{$n}};
550 $cmt = $cmt{$type{$n}};
551 #print FLOG "$part - $mstart - $mend - $length\n";
552
553 if ($verbose == 1) {
554 if (not defined $wpart) {
555 if (length($part) > 13) {
556 open(STDOUT2,">&STDOUT") || die "Unable to open STDOUT2";
557 select(STDOUT2);
558 write;
559 open(FLOG2,">&FLOG") || die "Unable to open FLOG2";
560 select(FLOG2);
561 write;
562 select(STDOUT);
563 close(FLOG2);
564 close(STDOUT2);
565 } else {
566 open(STDOUT1,">&STDOUT") || die "Unable to open STDOUT1";
567 select(STDOUT1);
568 write;
569 open(FLOG1,">&FLOG") || die "Unable to open FLOG1";
570 select(FLOG1);
571 write;
572 select(STDOUT);
573 close(FLOG1);
574 close(STDOUT1);
575 }
576 } else {
577 # manage the -s option of fdisk here
578 print "$length\n" if ($part eq $wpart);
579 pb_log(1,"$part has $length KBytes\n") if ($part eq $wpart);
580 }
581 }
582}
583close(FDISK);
584close(PARTED);
585}
586
587#
588# Get max size from fdisk
589#
590sub get_max {
591
592my $device = shift;
593my $max = 0;
594my $foo;
595
596open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk";
597while (<FDISK>) {
598 if ($_ =~ /heads/) {
599 chomp;
600 $max = $_;
601 $max =~ s/.* ([0-9]+) cylinders/$1/;
602 }
603}
604close(FDISK);
605pb_log(2,"get_max returns $max\n");
606return($max);
607}
608
609#
610# Get units from fdisk (cylinder size)
611#
612sub get_un {
613
614my $device = shift;
615my $wpart = shift;
616my $verbose = shift;
617my $un = 0;
618my $foo;
619
620open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk";
621while (<FDISK>) {
622 print if (($_ !~ /^\/dev\//) and (not (defined $wpart)) and ($verbose == 1));
623 if ($_ =~ /^Units/) {
624 ($foo, $un , $foo) = split /=/;
625 $un =~ s/[A-z\s=]//g;
626 $un = eval($un);
627 }
628}
629close(FDISK);
630pb_log(2,"get_un returns $un\n");
631return($un);
632}
633
634#
635# Parted gives info in MB
636# (depending on versions - 1.6.25.1 provides suffixes)
637#
638sub get_parted {
639
640my $device = shift;
641my $start = shift;
642my $end = shift;
643my $type = shift;
644my $void;
645my $d;
646my $n;
647my $ret;
648my $mode;
649my $size;
650my $unit;
651
652my $parted = pb_check_req("parted",0);
653open (PARTED, "$parted -v |") || die "Unable to read from $parted";
654$d = <PARTED>;
655pb_log(2,"$d");
656close(PARTED);
657chomp($d);
658# parted version
659$d =~ s/[^0-9\.]*([0-9\.]+)$/$1/;
660my ($v,$maj,$min) = split(/\./,$d);
661# depending on parted version, information given change:
662if ($v == 2) {
663 # RHEL 6 parted 2.1
664 $mode=2;
665} elsif ($v == 1) {
666 if (($maj <= 5) || (($maj == 6) && (defined $min) && ($min < 25))) {
667 # RHEL 3 parted 1.6.3
668 # RHEL 4 parted 1.6.19
669 $mode=0;
670 } else {
671 # SLES 10 parted >= 1.6.25
672 $mode=1;
673 }
674} else {
675 $mode=-1;
676}
677pb_log(2,"parted mode: $mode\n");
678
679open(PARTED, "$parted -s $device print |") || die "Unable to read from $parted";
680# Skip 3 first lines
681$d = <PARTED>;
682$d = <PARTED>;
683$d = <PARTED>;
684
685if ($mode == 2) {
686 $d = <PARTED>;
687 $d = <PARTED>;
688 $d = <PARTED>;
689}
690pb_log(2,"Got from parted: \n");
691pb_log(2,"Minor Start End Filesystem\n");
692# Get info from each partition line
693while (($n,$d) = split(/\s/, <PARTED>,2)) {
694 chomp($d);
695 # v2 of parted ends with empty line
696 next if (($mode == 2) && ($n eq "") && ($d eq ""));
697 # v2 of parted starts with space potentially
698 ($n,$d) = split(/\s/, $d,2) if (($mode == 2) && ($n eq ""));
699 next if ($n !~ /^[1-9]/);
700 $d =~ s/^\s*//;
701 $d =~ s/\s+/ /g;
702 if ($mode == 0) {
703 ($$start{$n},$$end{$n},$$type{$n},$void) = split(/ /,$d);
704 $unit = 1;
705 } elsif ($mode == 1) {
706 ($$start{$n},$$end{$n},$size,$$type{$n},$void) = split(/ /,$d);
707 $unit = $mega;
708 } elsif ($mode == 2) {
709 ($$start{$n},$$end{$n},$size,$$type{$n},$void) = split(/ /,$d);
710 $unit = $mega;
711 } else {
712 die "Undefined mode $mode";
713 }
714 $$start{$n} = "" if (not defined $$start{$n});
715 $$end{$n} = "" if (not defined $$end{$n});
716 $$type{$n} = "" if (not defined $$type{$n});
717 # Handles potential suffixes in latest parted version. Return MB
718 $ret = decode_Bsuf($$start{$n},$unit);
719 $$start{$n} = $ret;
720 $ret = decode_Bsuf($$end{$n},$unit);
721 $$end{$n} = $ret;
722 pb_log(2,"$n $$start{$n} $$end{$n} $$type{$n}\n");
723}
724close(PARTED);
725}
726
727sub decode_Bsuf {
728
729my $size = shift;
730my $unit = shift;
731my $ret = 0;
732
733pb_log(2,"decode_Bsuf input: $size / $unit ");
734if ($size =~ /K[B]*$/i) {
735 $size =~ s/K[B]*$//i;
736 $size *= 1024;
737} elsif ($size =~ /M[B]*$/i) {
738 $size =~ s/M[B]*$//i;
739 $size *= 1048576;
740} elsif ($size =~ /G[B]*$/i) {
741 $size =~ s/G[B]*$//i;
742 $size *= 1073741824;
743} elsif ($size =~ /T[B]*$/i) {
744 $size =~ s/T[B]*$//i;
745 $size *= 1099511627776;
746} else {
747 # Nothing to do
748}
749$ret = $size / $unit;
750pb_log(2," - output : $size => $ret\n");
751return($ret);
752}
Note: See TracBrowser for help on using the repository browser.