Author: glen
Date: Mon Apr 16 14:45:01 2012
New Revision: 12546

Modified:
   geninitrd/trunk/geninitrd
   geninitrd/trunk/tests/initramfs_switchroot.sh
Log:
initramfs switchroot: fix parsing `root=fe00`


Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Mon Apr 16 14:45:01 2012
@@ -786,7 +786,7 @@
        # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
        add_linuxrc <<-'EOF'
                device=
-               eval "$(busybox awk -v c="$ROOT" '
+               eval "$(busybox awk -v root="$ROOT" '
                        BEGIN {
                                num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
                                num_pattern = "[0-9a-f]" num_pattern_short;
@@ -794,14 +794,24 @@
                                partition = "";
                                min = -1; maj = -1;
 
-                               sub("^0x", "", c);
-                               if (c ~ "^" num_pattern_short "$") sub("^", 
"0", c);
-                               if (c ~ "^" num_pattern  "$") {
-                                       maj = sprintf("%d",substr(c,1,2));
-                                       min = sprintf("%d",substr(c,3));
+                               # see if we have /dev/hdX or hdX, we can just 
take partition name
+                               if (root ~ "^\/dev\/" dev_pattern "$" || root ~ 
"^" dev_pattern "$") {
+                                       partition = root
+                                       sub("^/dev/", "", partition);
+
+                               } else {
+                                       # unify values first
+                                       if (root ~ "^" num_pattern_short "$")  {
+                                               # change "303" => "0x0303"
+                                               root = "0x0" root
+                                       } else if (root ~ "^" num_pattern "$")  
{
+                                               # change "0303" => "0x0303"
+                                               root = "0x" root
+                                       }
+
+                                       maj = sprintf("%d", "0x" substr(root, 
3, 2));
+                                       min = sprintf("%d", "0x" substr(root, 
5, 2));
                                }
-                               if (c ~ "^\/dev\/" dev_pattern "$") 
sub("^/dev/","", c);
-                               if (c ~ "^" dev_pattern "$") partition = c;
                        }
 
                        partition && $4 == partition { maj = $1; min = $2; }

Modified: geninitrd/trunk/tests/initramfs_switchroot.sh
==============================================================================
--- geninitrd/trunk/tests/initramfs_switchroot.sh       (original)
+++ geninitrd/trunk/tests/initramfs_switchroot.sh       Mon Apr 16 14:45:01 2012
@@ -22,7 +22,7 @@
 
                device=
                eval "$(
-               busybox awk -v c="$ROOT" '
+               busybox awk -v root="$ROOT" '
                        BEGIN {
                                num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
                                num_pattern = "[0-9a-f]" num_pattern_short;
@@ -30,15 +30,26 @@
                                partition = "";
                                min = -1; maj = -1;
 
-                               sub("^0x", "", c);
-                               if (c ~ "^" num_pattern_short "$") sub("^", 
"0", c);
-                               if (c ~ "^" num_pattern  "$") {
-                                       maj = sprintf("%d",substr(c,1,2));
-                                       min = sprintf("%d",substr(c,3));
+                               # see if we have /dev/hdX or hdX, we can just 
take partition name
+                               if (root ~ "^\/dev\/" dev_pattern "$" || root ~ 
"^" dev_pattern "$") {
+                                       partition = root
+                                       sub("^/dev/", "", partition);
+                                       printf("# partition regexp=%s;\n", 
partition);
+
+                               } else {
+                                       # unify values first
+                                       if (root ~ "^" num_pattern_short "$")  {
+                                               # change "303" => "0x0303"
+                                               root = "0x0" root
+                                       } else if (root ~ "^" num_pattern "$")  
{
+                                               # change "0303" => "0x0303"
+                                               root = "0x" root
+                                       }
+
+                                       maj = sprintf("%d", "0x" substr(root, 
3, 2));
+                                       min = sprintf("%d", "0x" substr(root, 
5, 2));
+                                       printf("# BEGIN: maj=%s, min=%s\n", 
maj, min);
                                }
-                               if (c ~ "^\/dev\/" dev_pattern "$") 
sub("^/dev/","", c);
-                               if (c ~ "^" dev_pattern "$") partition = c;
-                               printf("# BEGIN: partition=%s; maj=%s, 
min=%s\n", partition, maj, min);
                        }
                        { printf("# maj:[%s], min:[%s], part:[%s]\n", $1, $2, 
$4) }
 
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to