[Fai-commit] r4615 - people/michael/features/setup_harddisks_2/implementation

andreas at alioth.debian.org andreas at alioth.debian.org
Tue Oct 9 18:41:48 UTC 2007


Author: andreas
Date: 2007-10-09 18:41:48 +0000 (Tue, 09 Oct 2007)
New Revision: 4615

Modified:
   people/michael/features/setup_harddisks_2/implementation/shdd2-parser
Log:
enable parser to handle size values in kilo, mega, giga, tera and petabytes

Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-parser
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-parser	2007-10-09 18:36:33 UTC (rev 4614)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-parser	2007-10-09 18:41:48 UTC (rev 4615)
@@ -84,9 +84,10 @@
 # name ::= [^/[:space:]]+
 #          /* lvm volume group name */
 #
-# size ::= [[:digit:]]+%?(-([[:digit:]]+%?)?)?(:resize)?
-#          /* size in megabytes or %, possibly given as a range; physical
-#           * partitions or lvm logical volumes only */
+# size ::= [[:digit:]]+[kMGTP%]?(-([[:digit:]]+[kMGTP%]?)?)?(:resize)?
+#          /* size in kilo, mega (default), giga, tera or petabytes or %,
+#           * possibly given as a range; physical
+#           * partitions or lvm logical volumes only; */
 #          | -[[:digit:]]+%?(:resize)?
 #          /* size in megabytes or % given as upper limit; physical partitions
 #           * or lvm logical volumes only */
@@ -343,6 +344,43 @@
     or $FAI::partition_pointer->{"size"}->{"resize"} = 0;
 }
 
+################################################################################
+#
+# @brief This function converts different sizes to Mbyte
+#
+# @param $val is the number with its unit
+#
+################################################################################
+sub convert_units
+{
+  my ($val) = @_;
+  $val =~ /(\d+)([kMGTP%]?)/;
+  unless ( $2 eq "%" )
+  {
+    if ( $2 eq "k" )
+    {
+      $val *= ( 1 / 1024 );
+    }
+    elsif ( $2 eq "M" )
+    {
+      $val *= 1;
+    }
+    elsif ( $2 eq "G" )
+    {
+      $val *= 1024;
+    }
+    elsif ( $2 eq "T" )
+    {
+      $val *= ( 1024 * 1024 );
+    }
+    elsif ( $2 eq "P" )
+    {
+      $val *= ( 1024 * 1024 * 1024 );
+    }
+  }
+  return $val;
+}
+
 # have RecDescent do proper error reporting
 $::RD_HINT = 1;
 
@@ -544,7 +582,7 @@
           1;
         }
 
-    size: /^(\d+%?(-(\d+%?)?)?)(:resize)?\s+/
+    size: /^(\d+[kMGTP%]?(-(\d+[kMGTP%]?)?)?)(:resize)?\s+/
         {
           # complete the size specification to be a range in all cases
           my $range = $1;
@@ -558,7 +596,12 @@
           {
             # range has no upper limit, assume the whole disk
             $range = $range . "100%";
-          }
+	  } 
+	  
+	  my ($min, $max) = split(/-/, $range);
+	  $min   = convert_unit($min);
+	  $max   = convert_unit($max);
+	  $range = "$min-$max";
           # enter the range into the hash
           $FAI::partition_pointer->{ "size" }->{ "range" } = $range;
           # set the resize flag, if required




More information about the Fai-commit mailing list