SVN: geninitrd/trunk: geninitrd tests/initramfs_switchroot.sh

glen glen at pld-linux.org
Mon Apr 23 17:14:11 CEST 2012


Author: glen
Date: Mon Apr 23 17:14:11 2012
New Revision: 12560

Modified:
   geninitrd/trunk/geninitrd
   geninitrd/trunk/tests/initramfs_switchroot.sh
Log:
initramfs switchroot: use awk own function to convert hex to dec (currently dietlibc built awk can't handle hex printf)

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Mon Apr 23 17:14:11 2012
@@ -804,9 +804,23 @@
 	add_linuxrc <<-'EOF'
 		device=
 		eval "$(busybox awk -v root="$ROOT" '
+			# http://9fans.net/archive/2006/09/261
+			function h2d(str, hstr, res, num, n, digit, i) {
+				hstr = "0123456789abdcef";
+				res = 0;
+				n = split(tolower(str), digit, "");
+
+				for (i = 1; i <= n; i++) {
+					num = index(hstr, digit[i]) - 1;
+					res = res + (num * 16 ^ (n - i));
+				}
+
+				return res;
+			}
 			BEGIN {
-				num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
-				num_pattern = "[0-9a-f]" num_pattern_short;
+
+				num_pattern_short = "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]";
+				num_pattern = "[0-9a-fA-F]" num_pattern_short;
 				dev_pattern = "[hms][a-z][a-z]([0-9])+";
 				partition = "";
 				min = -1; maj = -1;
@@ -826,8 +840,8 @@
 						root = "0x" root
 					}
 
-					maj = sprintf("%d", "0x" substr(root, 3, 2));
-					min = sprintf("%d", "0x" substr(root, 5, 2));
+					maj = h2d(substr(root, 3, 2));
+					min = h2d(substr(root, 5, 2));
 				}
 			}
 

Modified: geninitrd/trunk/tests/initramfs_switchroot.sh
==============================================================================
--- geninitrd/trunk/tests/initramfs_switchroot.sh	(original)
+++ geninitrd/trunk/tests/initramfs_switchroot.sh	Mon Apr 23 17:14:11 2012
@@ -23,9 +23,24 @@
 		device=
 		eval "$(
 		busybox awk -v root="$ROOT" '
+			# http://9fans.net/archive/2006/09/261
+			function h2d(str, hstr, res, num, n, digit, i) {
+				hstr = "0123456789abdcef";
+				res = 0;
+				n = split(tolower(str), digit, "");
+
+				for (i = 1; i <= n; i++) {
+					num = index(hstr, digit[i]) - 1;
+					res = res + (num * 16 ^ (n - i));
+				}
+printf("# h2d(%s) -> [%s]\n", str, res);
+
+				return res;
+			}
 			BEGIN {
-				num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
-				num_pattern = "[0-9a-f]" num_pattern_short;
+
+				num_pattern_short = "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]";
+				num_pattern = "[0-9a-fA-F]" num_pattern_short;
 				dev_pattern = "[hms][a-z][a-z]([0-9])+";
 				partition = "";
 				min = -1; maj = -1;
@@ -46,12 +61,12 @@
 						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);
+					maj = h2d(substr(root, 3, 2));
+					min = h2d(substr(root, 5, 2));
+printf("# BEGIN: root=[%s] maj=%s, min=%s\n", root, maj, min);
 				}
 			}
-			{ printf("# maj:[%s], min:[%s], part:[%s]\n", $1, $2, $4) }
+{ printf("# maj:[%s], min:[%s], part:[%s]\n", $1, $2, $4) }
 
 			partition && $4 == partition { maj = $1; min = $2; printf("# found partition: %s\n", partition) }
 			$1 == maj && $2 == min { partition = $4; printf("# found maj and min: %s, %s\n", maj, min)}
@@ -126,3 +141,10 @@
 runtest <<'EOF'
 mount -t xfs -r /dev/dm-0 /newroot
 EOF
+
+# lilo for dm-0
+partitions=./partitions2
+ROOT=FE00
+runtest <<'EOF'
+mount -t xfs -r /dev/dm-0 /newroot
+EOF


More information about the pld-cvs-commit mailing list