source: MondoRescue/branches/3.2/mindi/mr-parted2fdisk@ 3586

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