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

glen glen at pld-linux.org
Fri Mar 30 16:30:08 CEST 2012


Author: glen
Date: Fri Mar 30 16:30:08 2012
New Revision: 12529

Modified:
   geninitrd/trunk/geninitrd
   geninitrd/trunk/tests/initramfs_switchroot.sh
Log:
fix /proc/partitions parsing: expect "3" not "03" as device minor/major

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Fri Mar 30 16:30:08 2012
@@ -796,8 +796,8 @@
 				sub("^0x", "", c);
 				if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
 				if (c ~ "^" num_pattern  "$") {
-					maj = sprintf("%s",substr(c,1,2));
-					min = sprintf("%s",substr(c,3));
+					maj = sprintf("%d",substr(c,1,2));
+					min = sprintf("%d",substr(c,3));
 				}
 				if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
 				if (c ~ "^" dev_pattern "$") partition = c;

Modified: geninitrd/trunk/tests/initramfs_switchroot.sh
==============================================================================
--- geninitrd/trunk/tests/initramfs_switchroot.sh	(original)
+++ geninitrd/trunk/tests/initramfs_switchroot.sh	Fri Mar 30 16:30:08 2012
@@ -9,49 +9,60 @@
 	echo "mount $@"
 }
 
+mknod() {
+	echo "mknod $@"
+}
 
 	# parse 'root=xxx' kernel commandline
 	# We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
 #	add_linuxrc <<-'EOF'
 runtest_run() {
-		device=/dev/no_partition_found
+	set -$flags
+
+		device=
 		eval "$(
 		busybox awk -v c="$ROOT" '
 			BEGIN {
 				num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
 				num_pattern = "[0-9a-f]" num_pattern_short;
 				dev_pattern = "[hms][a-z][a-z]([0-9])+";
-				partition = "no_partition_found";
+				partition = "";
 				min = -1; maj = -1;
 
 				sub("^0x", "", c);
 				if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
 				if (c ~ "^" num_pattern  "$") {
-					maj = sprintf("%s",substr(c,1,2));
-					min = sprintf("%s",substr(c,3));
+					maj = sprintf("%d",substr(c,1,2));
+					min = sprintf("%d",substr(c,3));
 				}
 				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) }
 
-			$4 == partition { maj = $1; min = $2; }
-			$1 == maj && $2 == min { partition = $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)}
 
 			END {
 				if (maj >= 0 && min >= 0) {
-					printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
+					printf("maj=%s; min=%s;\n", maj, min);
+				}
+				if (partition) {
+					printf("device=/dev/%s;\n", partition);
 				}
 			}
 			' $proc/partitions
 		)"
-		if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
-			mknod $device b $maj $min
-		fi
 
-		if [ "$device" = '/dev/no_partition_found' ]; then
+		if [ -z "$device" ]; then
 			device=$ROOT
 		fi
 
+		if [ "$device" -a ! -b $device ]; then
+			mknod $device b $maj $min
+		fi
+
 		[ -n "$ROOTFSFLAGS" ] && ROOTFSFLAGS="-o $ROOTFSFLAGS"
 
 		mount -t $ROOTFS -r $device $ROOTFSFLAGS /newroot || echo "Mount of rootfs failed."
@@ -64,29 +75,30 @@
 }
 
 proc=.
+ROOTFS=xfs
 
 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
 ROOT=sda3
 runtest <<'EOF'
-mount -t -r /dev/sda3 /newroot
+mount -t xfs -r /dev/sda3 /newroot
 EOF
 
 ROOT=/dev/sda3
 runtest <<'EOF'
-mount -t -r /dev/sda3 /newroot
+mount -t xfs -r /dev/sda3 /newroot
 EOF
 
 ROOT=0803
 runtest <<'EOF'
-mount -t -r /dev/sda3 /newroot
+mount -t xfs -r /dev/sda3 /newroot
 EOF
 
 ROOT=0x0803
 runtest <<'EOF'
-mount -t -r /dev/sda3 /newroot
+mount -t xfs -r /dev/sda3 /newroot
 EOF
 
 ROOT=803
 runtest <<'EOF'
-mount -t -r /dev/sda3 /newroot
+mount -t xfs -r /dev/sda3 /newroot
 EOF


More information about the pld-cvs-commit mailing list