source: MondoRescue/branches/3.2/mindi/mr_parted2fdisk@ 3371

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