bc092b
From 37865c2c4ad26cd5e947b08abf1fde8145699919 Mon Sep 17 00:00:00 2001
bc092b
From: Vladimir Serbinenko <phcoder@gmail.com>
bc092b
Date: Mon, 23 Jan 2017 14:35:59 +0300
31cddd
Subject: [PATCH] fs-tester: make sh-compatible
bc092b
bc092b
---
bc092b
 tests/util/grub-fs-tester.in | 306 ++++++++++++++++++++++++-------------------
bc092b
 1 file changed, 169 insertions(+), 137 deletions(-)
bc092b
bc092b
diff --git a/tests/util/grub-fs-tester.in b/tests/util/grub-fs-tester.in
ec4acb
index 2337771a1b9..4515d165e6e 100644
bc092b
--- a/tests/util/grub-fs-tester.in
bc092b
+++ b/tests/util/grub-fs-tester.in
bc092b
@@ -1,4 +1,4 @@
bc092b
-#!/bin/bash
bc092b
+#!/bin/sh
bc092b
 
bc092b
 set -e
bc092b
 
bc092b
@@ -13,8 +13,29 @@ run_it () {
bc092b
     LC_ALL=C "$GRUBFSTEST" "$@"
bc092b
 }
bc092b
 
bc092b
+range() {
bc092b
+    range_counter="$1"
bc092b
+    while test "$range_counter" -le "$2"; do
bc092b
+	echo "$range_counter"
bc092b
+	range_counter="$((range_counter + $3))"
bc092b
+    done
bc092b
+}
bc092b
+
bc092b
+powrange() {
bc092b
+    range_counter="$1"
bc092b
+    while test "$range_counter" -le "$2"; do
bc092b
+	echo "$range_counter"
bc092b
+	range_counter="$((range_counter * 2))"
bc092b
+    done
bc092b
+}
bc092b
+
bc092b
 run_grubfstest () {
bc092b
-    run_it -c $NEED_IMAGES_N "${NEED_IMAGES[@]}"  "$@"
bc092b
+    need_images=
bc092b
+    for i in $(range 0 $((NEED_IMAGES_N-1)) 1); do
bc092b
+	need_images="$need_images $FSIMAGEP${i}.img";
bc092b
+    done
bc092b
+
bc092b
+    run_it -c $NEED_IMAGES_N $need_images  "$@"
bc092b
 }
bc092b
 
bc092b
 # OS LIMITATION: GNU/Linux has no AFS support, so we use a premade image and a reference tar file. I.a. no multiblocksize test
bc092b
@@ -51,7 +72,7 @@ case x"$fs" in
bc092b
 	# OS limitation: zfs-fuse always uses ashift=9 with loop devices
bc092b
 	MAXLOGSECSIZE=9;;
bc092b
 esac
bc092b
-for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE + 1)); do
bc092b
+for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
bc092b
     SECSIZE="$((1 << LOGSECSIZE))"
bc092b
     MINBLKSIZE=512
bc092b
     MAXBLKSIZE=512
bc092b
@@ -169,7 +190,12 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    MINBLKSIZE=1024
bc092b
 	    MAXBLKSIZE=4096;;
bc092b
     esac
bc092b
-    for ((BLKSIZE=MINBLKSIZE;BLKSIZE<=MAXBLKSIZE;BLKSIZE=BLKSTEP?BLKSIZE+BLKSTEP:2*BLKSIZE)); do
bc092b
+    if test "$BLKSTEP" -eq 0; then
bc092b
+	blksizes="$(powrange "$MINBLKSIZE" "$MAXBLKSIZE")"
bc092b
+    else
bc092b
+	blksizes="$(range "$MINBLKSIZE" "$MAXBLKSIZE" "$BLKSTEP")"
bc092b
+    fi
bc092b
+    for BLKSIZE in $blksizes; do
bc092b
 	MAXDEVICES=1
bc092b
 	MINDEVICES=1
bc092b
 	export fs
bc092b
@@ -199,13 +225,11 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		MAXDEVICES=7;;
bc092b
 	esac
bc092b
 
bc092b
-	for ((NDEVICES=MINDEVICES; NDEVICES <= MAXDEVICES; NDEVICES++)); do
bc092b
+	for NDEVICES in $(range "$MINDEVICES" "$MAXDEVICES" 1); do
bc092b
 	    export NDEVICES
bc092b
-	    unset FSIMAGES
bc092b
-	    for ((i=0; i < NDEVICES; i++)); do
bc092b
-		FSIMAGES[i]="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_$i.img"
bc092b
-	    done
bc092b
-	    export FSIMAGES
bc092b
+	    unset FSIMAGEP
bc092b
+	    FSIMAGEP="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_"
bc092b
+	    export FSIMAGEP
bc092b
 	    unset NEED_IMAGES;
bc092b
 
bc092b
 	    case x$fs in
bc092b
@@ -226,11 +250,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		*)
bc092b
 		    NEED_IMAGES_N=$NDEVICES;;
bc092b
 	    esac
bc092b
-	    for ((i=0;i < NEED_IMAGES_N; i++)); do
bc092b
-		NEED_IMAGES[i]="${FSIMAGES[i]}";
bc092b
-	    done
bc092b
 	    export NEED_IMAGES_N
bc092b
-	    export NEED_IMAGES
bc092b
 
bc092b
 	    MNTPOINTRO="${tempdir}/${fs}_ro"
bc092b
 	    MNTPOINTRW="${tempdir}/${fs}_rw"
bc092b
@@ -238,20 +258,25 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    MOUNTFS="$fs"
bc092b
 	    MASTER="${tempdir}/master"
bc092b
 	    FSLABEL="grub_;/testé莭莽茝😁киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfew"
bc092b
-	    CFILESN=1
bc092b
-	    if test -f /usr/share/dict/american-english; then
bc092b
-		CFILESSRC[0]="/usr/share/dict/american-english"
bc092b
-	    else
bc092b
-		CFILESSRC[0]="/usr/share/dict/linux.words"
bc092b
+	    CFILESRC=
bc092b
+	    for cand in /usr/share/dict/american-english /usr/share/dict/linux.words; do
bc092b
+		if test -f "$cand" ; then
bc092b
+		    CFILESRC="$cand"
bc092b
+		    break
bc092b
+		fi
bc092b
+	    done
bc092b
+	    if test "$CFILESRC" = "" ; then
bc092b
+		echo "Couldn't find compressible file" >&2
bc092b
+		exit 1
bc092b
 	    fi
bc092b
 	    case x"$fs" in
bc092b
 		    # FS LIMITATION: 8.3 names
bc092b
 		xmsdos*)
bc092b
-		    CFILES[0]="american.eng";;
bc092b
+		    CFILE="american.eng";;
bc092b
 		xiso9660)
bc092b
-		    CFILES[0]="american_english";;
bc092b
+		    CFILE="american_english";;
bc092b
 		*)
bc092b
-		    CFILES[0]="american-english";;
bc092b
+		    CFILE="american-english";;
bc092b
 	    esac
bc092b
         # OS LIMITATION: Limited by NAME_MAX (usually 255) in GNU/Linux
bc092b
 	    LONGNAME="qwertzuiopasdfghjklyxcvbnm1234567890qwertzuiopasdfghjklyxcvbnm1234567890oiewqfiewioqoiqoiurqruewqoiuwoieoiiuewqroreqiufieiuwrnureweriuvceoiroiewqoiricdsalkcndsakfirefoiwqeoircorejwoijfreoijojoiewjfwnfcoirenfoirefnreoifenoiwfnoi"
bc092b
@@ -388,8 +413,8 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    ;;
bc092b
 		x"vfat16" | xmsdos16)
bc092b
 		    BIGBLOCKCNT=$((25000 * BLKSIZE))
bc092b
-		    if [ $BIGBLOCKCNT -gt $((16#ffffffff)) ]; then
bc092b
-			BIGBLOCKCNT=$((16#ffffffff))
bc092b
+		    if [ $BIGBLOCKCNT -gt 4294967295 ]; then
bc092b
+			BIGBLOCKCNT=4294967295
bc092b
 		    fi
bc092b
 		    ;;
bc092b
 		x"minix")
bc092b
@@ -410,7 +435,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    BIGBLOCKCNT=$((4000 * 1048576));;
bc092b
 		    # FS LIMITATION: These FS have uint32 as file size field
bc092b
 		x"vfat"* | xmsdos* | x"cpio_crc" | x"cpio_newc" | x"cpio_bin" | x"cpio_hpbin" | xsfs*)
bc092b
-		    BIGBLOCKCNT=$((16#ffffffff));;
bc092b
+		    BIGBLOCKCNT=4294967295;;
bc092b
 		    # FS LIMITATION: These FS have int32 as file size field
bc092b
 		    # FIXME: not so sure about AFFS
bc092b
 		    # OS LIMITATION: minix2/minix3 could be formatted in a way to permit more.
bc092b
@@ -543,18 +568,18 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 
bc092b
 	    PDIR=""
bc092b
 		# OS LIMITATION: Limited by PATH_MAX (usually 1024)
bc092b
-	    for ((i=0;i
bc092b
+	    for i in $(range 0 $((PDIRCOMPNUM-1)) 1); do
bc092b
 		PDIR="$PDIR/$i";
bc092b
-		if [ $((i%3)) == 0 ]; then
bc092b
+		if test $((i%3)) = 0; then
bc092b
 		    PDIR="$PDIR/"
bc092b
 		fi
bc092b
 	    done
bc092b
 
bc092b
 	    PDIR2=""
bc092b
 		# OS LIMITATION: Limited by PATH_MAX (usually 1024)
bc092b
-	    for ((i=0;i
bc092b
+	    for i in $(range 0 $((PDIR2COMPNUM-1)) 1); do
bc092b
 		PDIR2="${PDIR2}/$i";
bc092b
-		if [ $((i%3)) == 0 ]; then
bc092b
+		if test $((i%3)) = 0; then
bc092b
 		    PDIR2="${PDIR2}/"
bc092b
 		fi
bc092b
 	    done
bc092b
@@ -563,7 +588,9 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 
bc092b
 	    unset LODEVICES
bc092b
 	    GENERATED=n
bc092b
-
bc092b
+	    LODEVICES=
bc092b
+	    MOUNTDEVICE=
bc092b
+	    
bc092b
 	    case x"$fs" in
bc092b
 		x"tarfs" | x"cpio_"*| x"ziso9660" | x"romfs" | x"squash4_"*\
bc092b
                     | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet \
bc092b
@@ -577,62 +604,65 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		*)
bc092b
 		    mkdir -p "$MNTPOINTRW"
bc092b
 		    mkdir -p "$MNTPOINTRO"
bc092b
-		    for ((i=0; i < NDEVICES; i++)); do
bc092b
-			dd if=/dev/zero of="${FSIMAGES[i]}" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null
bc092b
-			LODEVICES[i]=`losetup -f`
bc092b
-			losetup "${LODEVICES[i]}" "${FSIMAGES[i]}"
bc092b
+		    for i in $(range 0 $((NDEVICES-1)) 1); do
bc092b
+			dd if=/dev/zero of="$FSIMAGEP${i}.img" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null
bc092b
+			LODEVICE="$(losetup -f)"
bc092b
+			LODEVICES="$LODEVICES $LODEVICE"
bc092b
+			losetup "$LODEVICE" "$FSIMAGEP${i}.img"
bc092b
+			if test "$i" = 0; then
bc092b
+			    MOUNTDEVICE="$LODEVICE"
bc092b
+			fi
bc092b
 		    done ;;
bc092b
 	    esac
bc092b
 
bc092b
-	    MOUNTDEVICE="${LODEVICES[0]}"
bc092b
 	    case x"$fs" in
bc092b
 		x"afs")
bc092b
 		    ;;
bc092b
 		x"btrfs")
bc092b
-		    "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${LODEVICES[0]}" ;;
bc092b
+		    "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" ;;
bc092b
 		x"btrfs_zlib" | x"btrfs_lzo")
bc092b
-		    "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${LODEVICES[0]}"
bc092b
+		    "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="compress=${fs/btrfs_/},"
bc092b
 		    MOUNTFS="btrfs"
bc092b
 		    ;;
bc092b
 		x"btrfs_raid0")
bc092b
-		    "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" "${LODEVICES[@]}"
bc092b
+		    "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" $LODEVICES
bc092b
 		    MOUNTFS="btrfs"
bc092b
 		    ;;
bc092b
 		x"btrfs_raid1")
bc092b
-		    "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" "${LODEVICES[@]}"
bc092b
+		    "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" $LODEVICES
bc092b
 		    MOUNTFS="btrfs"
bc092b
 		    ;;
bc092b
 		x"btrfs_raid10")
bc092b
-		    "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" "${LODEVICES[@]}"
bc092b
+		    "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" $LODEVICES
bc092b
 		    MOUNTFS="btrfs"
bc092b
 		    ;;
bc092b
 		x"btrfs_single")
bc092b
-		    "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" "${LODEVICES[@]}"
bc092b
+		    "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" $LODEVICES
bc092b
 		    MOUNTFS="btrfs"
bc092b
 		    ;;
bc092b
 		x"exfat")
bc092b
-		    "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${LODEVICES[0]}"
bc092b
+		    "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="iocharset=utf8,"
bc092b
 		    MOUNTFS="exfat-fuse";;
bc092b
 		x"minix")
bc092b
-		    "mkfs.minix" "${LODEVICES[0]}"
bc092b
+		    "mkfs.minix" "${MOUNTDEVICE}"
bc092b
 		    ;;
bc092b
 	# mkfs.hfs and mkfs.hfsplus don't fill UUID.
bc092b
 		x"hfsplus")
bc092b
-		    "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${LODEVICES[0]}"
bc092b
-		    dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;;
bc092b
+		    "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
bc092b
+		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;;
bc092b
 		x"hfsplus_wrap")
bc092b
-		    "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${LODEVICES[0]}"
bc092b
-		    dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#468)) conv=notrunc count=8
bc092b
+		    "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
bc092b
+		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8
bc092b
 		    MOUNTFS="hfsplus";;
bc092b
 		x"hfsplus_casesens")
bc092b
-		    "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${LODEVICES[0]}"
bc092b
-		    dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#468)) conv=notrunc count=8
bc092b
+		    "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
bc092b
+		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8
bc092b
 		    MOUNTFS="hfsplus";;
bc092b
 		x"hfs")
bc092b
-		    "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${LODEVICES[0]}"
bc092b
-		    dd if=/dev/urandom of="${LODEVICES[0]}" bs=1 seek=$((16#474)) conv=notrunc count=8
bc092b
+		    "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${MOUNTDEVICE}"
bc092b
+		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#474)) conv=notrunc count=8
bc092b
 		    MOUNTOPTS="iocharset=utf8,codepage=macroman,"
bc092b
 		    ;;
bc092b
 		x"vfat"*|xmsdos*)
bc092b
@@ -643,98 +673,98 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    else
bc092b
 			A=
bc092b
 		    fi
bc092b
-		    "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${FSIMAGES[0]}"
bc092b
+		    "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="iocharset=utf8,codepage=437,"
bc092b
 		    MOUNTFS="$(echo "$fs"|sed 's,[0-9]*a\?$,,')";;
bc092b
 		x"minix2")
bc092b
-		    "mkfs.minix" -v "${LODEVICES[0]}"
bc092b
+		    "mkfs.minix" -v "${MOUNTDEVICE}"
bc092b
 		    MOUNTFS="minix";;
bc092b
 		x"minix3")
bc092b
-		    "mkfs.minix" -B $BLKSIZE -3 "${LODEVICES[0]}"
bc092b
+		    "mkfs.minix" -B $BLKSIZE -3 "${MOUNTDEVICE}"
bc092b
 		    MOUNTFS="minix";;
bc092b
 		x"ntfs"*)
bc092b
-		    "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${LODEVICES[0]}"
bc092b
+		    "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="iocharset=utf8,compression,"
bc092b
 		    MOUNTFS="ntfs-3g";;
bc092b
 		x"udf")
bc092b
-		    "mkudffs" --utf8 -b $BLKSIZE --lvid="$FSLABEL" "${LODEVICES[0]}"
bc092b
+		    "mkudffs" --utf8 -b $BLKSIZE --lvid="$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="iocharset=utf8,bs=$BLKSIZE,";;
bc092b
 		x"ufs2")
bc092b
-		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${LODEVICES[0]}"
bc092b
+		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="ufstype=ufs2,"
bc092b
 		    MOUNTFS="ufs";;
bc092b
 		x"ufs1")
bc092b
-		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${LODEVICES[0]}"
bc092b
+		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="ufstype=44bsd,"
bc092b
 		    MOUNTFS="ufs";;
bc092b
 		x"ufs1_sun")
bc092b
-		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${LODEVICES[0]}"
bc092b
+		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="ufstype=sun,"
bc092b
 		    MOUNTFS="ufs";;
bc092b
 		x"zfs")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[0]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    sleep 1
bc092b
 		    "zfs" create "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_caseins")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[0]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    sleep 1
bc092b
 		    "zfs" create -o casesensitivity=insensitive "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_lzjb" | xzfs_gzip | xzfs_zle)
bc092b
-		    "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[0]}"
bc092b
+		    "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
bc092b
 		    sleep 1
bc092b
 		    "zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_raidz")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 "${LODEVICES[@]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 $LODEVICES
bc092b
 		    sleep 1
bc092b
 		    "zfs" create "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_raidz2")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 "${LODEVICES[@]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 $LODEVICES
bc092b
 		    sleep 1
bc092b
 		    "zfs" create "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_raidz3")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 "${LODEVICES[@]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 $LODEVICES
bc092b
 		    sleep 1
bc092b
 		    "zfs" create "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_mirror")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror "${LODEVICES[@]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror $LODEVICES
bc092b
 		    sleep 1
bc092b
 		    "zfs" create "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"zfs_stripe")
bc092b
-		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${LODEVICES[@]}"
bc092b
+		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" $LODEVICES
bc092b
 		    sleep 1
bc092b
 		    "zfs" create "$FSLABEL"/"grub fs"
bc092b
 		    sleep 1;;
bc092b
 		x"tarfs" | x"cpio_"* | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 | xrockridge_joliet_1999 | x"ziso9660" | x"romfs" | x"squash4_"*)
bc092b
 		    INSTDEVICE=/dev/null;;
bc092b
 		x"reiserfs")
bc092b
-		    "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${LODEVICES[0]}" ;;
bc092b
+		    "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" ;;
bc092b
 		x"reiserfs_old")
bc092b
-		    "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${LODEVICES[0]}"
bc092b
+		    "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}"
bc092b
 		    MOUNTFS=reiserfs;;
bc092b
 		x"jfs")
bc092b
-		    "mkfs.jfs" -L "$FSLABEL" -q "${LODEVICES[0]}"
bc092b
+		    "mkfs.jfs" -L "$FSLABEL" -q "${MOUNTDEVICE}"
bc092b
 		    MOUNTOPTS="iocharset=utf8,";;
bc092b
 		x"jfs_caseins")
bc092b
-		    "mkfs.jfs" -O -L "$FSLABEL" -q "${LODEVICES[0]}"
bc092b
+		    "mkfs.jfs" -O -L "$FSLABEL" -q "${MOUNTDEVICE}"
bc092b
 		    MOUNTFS=jfs
bc092b
 		    MOUNTOPTS="iocharset=utf8,";;
bc092b
 		x"mdraid"*)
bc092b
-		    mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" "${LODEVICES[@]}"
bc092b
+		    mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" $LODEVICES
bc092b
 		    MOUNTDEVICE="/dev/md/${fs}_${NDEVICES}"
bc092b
 		    MOUNTFS=ext2
bc092b
 		    "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
bc092b
 		x"lvm"*)
bc092b
-		    for ((i=0;i
bc092b
-			pvcreate "${LODEVICES[i]}"
bc092b
+		    for lodev in $LODEVICES; do
bc092b
+			pvcreate "$lodev"
bc092b
 		    done
bc092b
-		    vgcreate -s $((BLKSIZE/1024))K grub_test "${LODEVICES[@]}"
bc092b
+		    vgcreate -s $((BLKSIZE/1024))K grub_test $LODEVICES
bc092b
 		    if [ x$fs = xlvm ] ; then
bc092b
 			lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -n testvol grub_test
bc092b
 		    elif [ x$fs = xlvm_stripe ] ; then
bc092b
@@ -757,22 +787,22 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    MOUNTFS=ext2
bc092b
 		    "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}"  ;;
bc092b
 		xnilfs2)
bc092b
-		    "mkfs.nilfs2" -L "$FSLABEL" -b $BLKSIZE  -q "${LODEVICES[0]}" ;;
bc092b
+		    "mkfs.nilfs2" -L "$FSLABEL" -b $BLKSIZE  -q "${MOUNTDEVICE}" ;;
bc092b
 		xext2_old)
bc092b
-		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext2" -r 0 -b $BLKSIZE -L "$FSLABEL" -q "${LODEVICES[0]}"
bc092b
+		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext2" -r 0 -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
bc092b
 		    MOUNTFS=ext2
bc092b
 		    ;;
bc092b
 		xext4_metabg)
bc092b
-		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O meta_bg,^resize_inode -b $BLKSIZE -L "$FSLABEL" -q "${LODEVICES[0]}"
bc092b
+		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O meta_bg,^resize_inode -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
bc092b
 		    MOUNTFS=ext4
bc092b
 		    ;;
bc092b
 		xext*)
bc092b
-		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.$fs" -b $BLKSIZE -L "$FSLABEL" -q "${LODEVICES[0]}" ;;
bc092b
+		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.$fs" -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
bc092b
 		xxfs)
bc092b
-		    "mkfs.xfs" -m crc=0 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${LODEVICES[0]}" ;;
bc092b
+		    "mkfs.xfs" -m crc=0 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
bc092b
 		xxfs_crc)
bc092b
 		    MOUNTFS="xfs"
bc092b
-		    "mkfs.xfs" -m crc=1 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${LODEVICES[0]}" ;;
bc092b
+		    "mkfs.xfs" -m crc=1 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
bc092b
 		*)
bc092b
 		    echo "Add appropriate mkfs command here"
bc092b
 		    exit 1
bc092b
@@ -873,11 +903,13 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		*)
bc092b
 		    if ! mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRW" -o ${MOUNTOPTS}${SELINUXOPTS}rw  ; then
bc092b
 			echo "MOUNT FAILED."
bc092b
-			for ((i=0; i < NDEVICES; i++)); do
bc092b
-			    while ! losetup -d "${LODEVICES[i]}"; do
bc092b
+			for lodev in $LODEVICES; do
bc092b
+			    while ! losetup -d "$lodev"; do
bc092b
 				sleep 1
bc092b
 			    done
bc092b
-			    rm "${FSIMAGES[i]}"
bc092b
+			done
bc092b
+			for i in $(range 0 $((NDEVICES-1)) 1); do
bc092b
+			    rm "$FSIMAGEP${i}.img"
bc092b
 			done
bc092b
 			exit 1;
bc092b
 		    fi
bc092b
@@ -939,11 +971,11 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    if (test x$fs = xvfat12a || test x$fs = xmsdos12a) && test x$BLKSIZE = x131072; then
bc092b
 		    # With this config there isn't enough space for full copy.
bc092b
 		    # Copy as much as we can
bc092b
-		cp "${CFILESSRC[0]}" "$MNTPOINTRW/$OSDIR/${CFILES[0]}" &> /dev/null;
bc092b
+		cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}" &> /dev/null;
bc092b
 	    else
bc092b
-		for ((i=0;i<$CFILESN;i++)); do
bc092b
-		    cp "${CFILESSRC[i]}" "$MNTPOINTRW/$OSDIR/${CFILES[i]}";
bc092b
-		done
bc092b
+
bc092b
+		cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}";
bc092b
+
bc092b
 	    fi
bc092b
 
bc092b
 	    if [ x$NOSYMLINK != xy ]; then
bc092b
@@ -968,48 +1000,48 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    sleep 2
bc092b
 		    ;;
bc092b
 		x"tarfs")
bc092b
-		    (cd "$MASTER"; tar cf "${FSIMAGES[0]}" .) ;;
bc092b
+		    (cd "$MASTER"; tar cf "${FSIMAGEP}0.img" .) ;;
bc092b
 		x"cpio_"*)
bc092b
-		    (cd "$MASTER"; find . | cpio -o -H "${fs/cpio_/}" > "${FSIMAGES[0]}" ) ;;
bc092b
+		    (cd "$MASTER"; find . | cpio -o -H "$(echo ${fs} | sed 's@^cpio_@@')" > "${FSIMAGEP}0.img" ) ;;
bc092b
 		x"ziso9660")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso -compliance rec_mtime -set_filter_r --zisofs -- -zisofs default -as mkisofs -iso-level 3 -graft-points -R -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}"  -- -set_filter_r --zisofs -- -zisofs default -add /="$MASTER" ;;
bc092b
+		    xorriso -compliance rec_mtime -set_filter_r --zisofs -- -zisofs default -as mkisofs -iso-level 3 -graft-points -R -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img"  -- -set_filter_r --zisofs -- -zisofs default -add /="$MASTER" ;;
bc092b
 		x"iso9660")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"joliet")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge off  -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge off  -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"rockridge")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"rockridge_joliet")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 3 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"iso9660_1999")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge off -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"joliet_1999")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge off  -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge off  -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"rockridge_1999")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"rockridge_joliet_1999")
bc092b
 		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
bc092b
-		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGES[0]}" /="$MASTER"  ;;
bc092b
+		    xorriso --rockridge on -compliance rec_mtime -as mkisofs -iso-level 4 -graft-points -J -joliet-long -V "$FSLABEL" --modification-date=$(echo ${FSUUID} | sed 's/-//g;') -o "${FSIMAGEP}0.img" /="$MASTER"  ;;
bc092b
 		x"romfs")
bc092b
-		    genromfs -V "$FSLABEL" -f "${FSIMAGES[0]}" -d "$MASTER" ;;
bc092b
+		    genromfs -V "$FSLABEL" -f "${FSIMAGEP}0.img" -d "$MASTER" ;;
bc092b
 		xsquash4_*)
bc092b
-		    echo mksquashfs "$MASTER" "${FSIMAGES[0]}" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE
bc092b
-		    mksquashfs "$MASTER" "${FSIMAGES[0]}" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;;
bc092b
+		    echo mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE
bc092b
+		    mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;;
bc092b
 		x"bfs")
bc092b
 		    sleep 1
bc092b
 		    fusermount -u "$MNTPOINTRW"
bc092b
 		    ;;
bc092b
 		xlvm*)
bc092b
 		    sleep 1
bc092b
-		    for ((try=0;try < 20; try++)); do
bc092b
+		    for try in $(range 0 20 1); do
bc092b
 			if umount "$MNTPOINTRW" ; then
bc092b
 			    break;
bc092b
 			fi
bc092b
@@ -1021,7 +1053,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    ;;
bc092b
 		xmdraid*)
bc092b
 		    sleep 1
bc092b
-		    for ((try=0;try < 20; try++)); do
bc092b
+		    for try in $(range 0 20 1); do
bc092b
 			if umount "$MNTPOINTRW" ; then
bc092b
 			    break;
bc092b
 			fi
bc092b
@@ -1033,7 +1065,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    ;;
bc092b
 		*)
bc092b
 		    sleep 1
bc092b
-		    for ((try=0;try < 20; try++)); do
bc092b
+		    for try in $(range 0 20 1); do
bc092b
 			if umount "$MNTPOINTRW" ; then
bc092b
 			    break;
bc092b
 			fi
bc092b
@@ -1066,7 +1098,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    sleep 1
bc092b
 		    mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
bc092b
 		xmdraid*)
bc092b
-		    mdadm --assemble /dev/md/"${fs}_$NDEVICES" "${LODEVICES[@]}"
bc092b
+		    mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES
bc092b
 		    sleep 1
bc092b
 		    mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
bc092b
 		*)
bc092b
@@ -1085,7 +1117,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo LIST FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1094,7 +1126,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo NLIST FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -lA "$MNTPOINTRO"
bc092b
+		TZ=UTC ls -lA "$MNTPOINTRO"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1103,7 +1135,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo ILIST FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1112,7 +1144,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo LONG LIST FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1123,7 +1155,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		else
bc092b
 		    echo TIME FAIL
bc092b
 		    echo "$LSROUT"
bc092b
-		    TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+		    TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 		    exit 1
bc092b
 		fi
bc092b
 
bc092b
@@ -1133,7 +1165,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		else
bc092b
 		    echo LONG TIME FAIL
bc092b
 		    echo "$LSROUT"
bc092b
-		    TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+		    TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 		    exit 1
bc092b
 		fi
bc092b
 	    fi
bc092b
@@ -1149,7 +1181,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo DOT IN ROOTDIR FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1163,7 +1195,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    else
bc092b
 			echo DOTDOT IN ROOTDIR FAIL
bc092b
 			echo "$LSROUT"
bc092b
-			TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO"
bc092b
+			TZ=UTC ls -l "$MNTPOINTRO"
bc092b
 			exit 1
bc092b
 		    fi
bc092b
 		    ;;
bc092b
@@ -1180,7 +1212,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo SLIST FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO/sdir"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO/sdir"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1195,7 +1227,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo PLIST FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO/$PDIR"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO/$PDIR"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1210,7 +1242,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo DOT IN SUBDIR FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO/$OSDIR/sdir"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/sdir"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1225,7 +1257,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    else
bc092b
 		echo DOTDOT IN SUBDIR FAIL
bc092b
 		echo "$LSROUT"
bc092b
-		TZ=UTC ls --time-style=+%Y%m%d%H%M%S.%N -l "$MNTPOINTRO/$OSDIR/ssdir"
bc092b
+		TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/ssdir"
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 
bc092b
@@ -1245,8 +1277,8 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 	    case x"$fs" in
bc092b
 		x"iso9660" | x"ziso9660" | xrockridge | xjoliet | xrockridge_joliet | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
bc092b
 		x"zfs"*)
bc092b
-		    for ((i=0;i
bc092b
-			FSUUID=$(printf "%016x\n" $(blkid -o export "${LODEVICES[i]}" |grep -F UUID=|sed s,UUID=,,g))
bc092b
+		    for lodev in $LODEVICES; do
bc092b
+			FSUUID=$(printf "%016x\n" $(blkid -o export "$lodev" |grep -F UUID=|sed s,UUID=,,g))
bc092b
 			if [ "$FSUUID" != 0000000000000000 ]; then
bc092b
 			    break;
bc092b
 			fi
bc092b
@@ -1264,8 +1296,8 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 			echo UUID FAIL
bc092b
 			echo "$LSOUT"
bc092b
 			echo "$GRUBUUID"
bc092b
-			for ((i=0;i
bc092b
-			    blkid "${LODEVICES[i]}"
bc092b
+			for lodev in $LODEVICES; do
bc092b
+			    blkid "$lodev"
bc092b
 			done
bc092b
 			exit 1
bc092b
 		    fi
bc092b
@@ -1290,7 +1322,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 			echo UUID FAIL
bc092b
 			echo "$FSUUID"
bc092b
 			echo "$LSOUT"
bc092b
-			blkid "${LODEVICES[0]}"
bc092b
+			blkid "${MOUNTDEVICE}"
bc092b
 			exit 1
bc092b
 		    fi
bc092b
 		    ;;
bc092b
@@ -1304,7 +1336,7 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    # may be delayed for a long time.
bc092b
 		    FSTIME="$UMOUNT_TIME";;
bc092b
 		*)
bc092b
-		    FSTIME="$(TZ=UTC ls --time-style="+%Y-%m-%d_%H:%M:%S" -l -d "${FSIMAGES[0]}"|awk '{print $6; }'|sed 's,_, ,g')";;
bc092b
+		    FSTIME="$(TZ=UTC ls --time-style="+%Y-%m-%d_%H:%M:%S" -l -d "${FSIMAGEP}0.img"|awk '{print $6; }'|sed 's,_, ,g')";;
bc092b
 	    esac
bc092b
 	    # With some abstractions like mdraid computing of UMOUNT_TIME
bc092b
 	    # is not precise. Account for small difference here.
bc092b
@@ -1410,11 +1442,9 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		exit 1
bc092b
 	    fi
bc092b
 	    ok=true
bc092b
-	    for ((i=0;i<$CFILESN;i++)); do
bc092b
-		if ! run_grubfstest cmp "$GRUBDIR/${CFILES[i]}" "$MNTPOINTRO/$OSDIR/${CFILES[i]}"  ; then
bc092b
-		    ok=false;
bc092b
-		fi
bc092b
-	    done
bc092b
+	    if ! run_grubfstest cmp "$GRUBDIR/${CFILE}" "$MNTPOINTRO/$OSDIR/${CFILE}"  ; then
bc092b
+		ok=false;
bc092b
+	    fi
bc092b
 	    if  test x$ok = xtrue; then
bc092b
 		:
bc092b
 	    else
bc092b
@@ -1503,15 +1533,17 @@ for ((LOGSECSIZE=MINLOGSECSIZE;LOGSECSIZE<=MAXLOGSECSIZE;LOGSECSIZE=LOGSECSIZE +
bc092b
 		    sleep 1
bc092b
 		    ;;
bc092b
 	    esac
bc092b
-	    for ((i=0; i < NDEVICES; i++)); do
bc092b
-		case x"$fs" in
bc092b
-		    x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
bc092b
-		    *)
bc092b
-			while ! losetup -d "${LODEVICES[i]}"; do
bc092b
+	    case x"$fs" in
bc092b
+		x"tarfs" | x"cpio_"* | x"iso9660" | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
bc092b
+		*)
bc092b
+		    for lodev in $LODEVICES; do
bc092b
+			while ! losetup -d "$lodev"; do
bc092b
 			    sleep 1
bc092b
-			done;;
bc092b
-		esac
bc092b
-		rm "${FSIMAGES[i]}"
bc092b
+			done
bc092b
+		    done;;
bc092b
+	    esac
bc092b
+	    for i in $(range 0 $((NDEVICES-1)) 1); do
bc092b
+		rm "$FSIMAGEP${i}.img"
bc092b
 	    done
bc092b
 	    if [ x"$fs" = x"zfs" ]; then
bc092b
 		rmdir "$MNTPOINTRW"/"grub fs"  || true