summaryrefslogtreecommitdiffstats
path: root/tests/util/grub-fs-tester.in
blob: bfc425e1fd7fc7b1b535c415ae4ee2efd9edcfc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
#!@BUILD_SHEBANG@

set -e

fs="$1"

GRUBFSTEST="@builddir@/grub-fstest"

tempdir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1

# This wrapper is to ease insertion of valgrind or time statistics
run_it () {
    LC_ALL=C "$GRUBFSTEST" "$@"
}

range() {
    range_counter="$1"
    while test "$range_counter" -le "$2"; do
	echo "$range_counter"
	range_counter="$((range_counter + $3))"
    done
}

powrange() {
    range_counter="$1"
    while test "$range_counter" -le "$2"; do
	echo "$range_counter"
	range_counter="$((range_counter * 2))"
    done
}

run_grubfstest () {
    need_images=
    for i in $(range 0 $((NEED_IMAGES_N-1)) 1); do
	need_images="$need_images $FSIMAGEP${i}.img";
    done

    run_it -c $NEED_IMAGES_N $need_images  "$@"
}

# OS LIMITATION: GNU/Linux has no AFS support, so we use a premade image and a reference tar file. I.a. no multiblocksize test

MINLOGSECSIZE=9
MAXLOGSECSIZE=9
case x"$fs" in
    xntfs*)
	MINLOGSECSIZE=8
	MAXLOGSECSIZE=12;;
    xvfat*|xmsdos*)
	MINLOGSECSIZE=9
	    #  OS LIMITATION: It could go up to 32768 but Linux rejects sector sizes > 4096
	MAXLOGSECSIZE=12;;
    xext*)
	MINLOGSECSIZE=8
	MAXLOGSECSIZE=12;;
    xbtrfs*)
	MINLOGSECSIZE=8
	    #  OS LIMITATION: It could go up to 32768 but Linux rejects sector sizes > 4096
	MAXLOGSECSIZE=12;;
    xxfs)
	MINLOGSECSIZE=9
  	    # OS LIMITATION: GNU/Linux doesn't accept > 4096
	MAXLOGSECSIZE=12;;
    xxfs_crc)
	MINLOGSECSIZE=9
  	    # OS LIMITATION: GNU/Linux doesn't accept > 1024
	MAXLOGSECSIZE=10;;
    xzfs*)
	    # OS LIMITATION: zfs-fuse hangs when creating zpool with sectors <=256B.
	MINLOGSECSIZE=9
	    # OS LIMITATION: zfs-fuse fails with >= 32K sectors.
	# OS limitation: zfs-fuse always uses ashift=9 with loop devices
	MAXLOGSECSIZE=9;;
esac
for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do
    SECSIZE="$((1 << LOGSECSIZE))"
    MINBLKSIZE=512
    MAXBLKSIZE=512
    BLKSTEP=0
    case x"$fs" in
	xntfs*)
	    MINBLKSIZE=$SECSIZE
	    MAXBLKSIZE=65536
	    if [ x"$SECSIZE" = x256 ]; then
		MINBLKSIZE=512
		MAXBLKSIZE=32768
	    fi
	    ;;
	xvfat* | xmsdos*)
	    MINBLKSIZE=$SECSIZE
	    MAXBLKSIZE=$((128*SECSIZE))
	    ;;
	xexfat*)
	    MINBLKSIZE=$SECSIZE
		# It could go further but it requires more and more space
	    MAXBLKSIZE=8286208
	    ;;
	xhfs)
	    MINBLKSIZE=512
	    # OS LIMITATION: should be 1048576 but linux hangs on unmnount with
	    # >= 524288
	    MAXBLKSIZE=262144
	    ;;
	xhfsplus | xhfsplus_casesens | xhfsplus_wrap)
	    MINBLKSIZE=512
	    MAXBLKSIZE=1048576
	    ;;
	xnilfs2)
	    # nilfs2 supports blocksizes from 1024 to 4096
	    # but non-4096 results in kernel oops in some cases,
	    # avoid it.
	    MINBLKSIZE=4096
	    MAXBLKSIZE=4096
	    ;;
	xsfs*)
	    MINBLKSIZE=512
	    MAXBLKSIZE=4096
	    ;;
	xaffs | xaffs_intl)
	    MINBLKSIZE=512
	    MAXBLKSIZE=4096
	    ;;
	xreiserfs*)
	    MINBLKSIZE=512
		# OS LIMITATION: 8192 isn't supported.
	    MAXBLKSIZE=4096
	    ;;
	x"mdraid"*)
	    MINBLKSIZE=4096
		# OS LIMITATION: Linux oopses with >=32768K
	    MAXBLKSIZE=$((16384*1024))
	    ;;
	x"lvm_raid1"* | x"lvm_raid4" | x"lvm_raid5" | x"lvm_raid6")
		# OS LIMITATION: Linux crashes with less than 16384
	    MINBLKSIZE=16384
		# Could go further but what's the point?
	    MAXBLKSIZE=$((65536*1024))
	    ;;
	x"lvm_mirrorall")
	    MINBLKSIZE=2048
		# Could go further but what's the point?
	    MAXBLKSIZE=$((65536*1024))
	    ;;
	x"lvm_mirror1")
	    MINBLKSIZE=4096
		# Could go further but what's the point?
	    MAXBLKSIZE=$((65536*1024))
	    ;;
	x"lvm_stripe")
	    MINBLKSIZE=4096
		# Could go further but what's the point?
	    MAXBLKSIZE=$((65536*1024))
	    ;;
	x"lvm"*)
	    MINBLKSIZE=1024
		# Could go further but what's the point?
	    MAXBLKSIZE=$((65536*1024))
	    ;;
       xext4_encrypt)
           # OS LIMITATION: Linux currently only allows the 'encrypt' feature
           # in combination with block_size = PAGE_SIZE (4096 bytes on x86).
           MINBLKSIZE=$(getconf PAGE_SIZE)
           MAXBLKSIZE=$MINBLKSIZE
           ;;
	xext*)
	    MINBLKSIZE=1024
	    if [ $MINBLKSIZE -lt $SECSIZE ]; then
		MINBLKSIZE=$SECSIZE
	    fi
	    MAXBLKSIZE=4096
	    ;;
	xsquash*)
	    MINBLKSIZE=4096
	    MAXBLKSIZE=1048576;;
	xxfs|xf2fs)
	    MINBLKSIZE=$SECSIZE
		# OS Limitation: GNU/Linux doesn't accept > 4096
	    MAXBLKSIZE=4096;;
	xxfs_crc)
	    # OS Limitation: GNU/Linux doesn't accept != 1024
	    MINBLKSIZE=1024
	    MAXBLKSIZE=1024;;
	xudf)
	    MINBLKSIZE=1024
	    MAXBLKSIZE=4096;;
	xbfs)
	    MINBLKSIZE=1024
	    MAXBLKSIZE=8192;;
	xufs*)
	    MINBLKSIZE=4096
		# OS Limitation: Linux rejects 65536 blocks.
	    MAXBLKSIZE=32768;;
	xminix3)
		# OS LIMITATION: Linux rejects non-power-of-two blocks.
		# OS LIMITATION: Linux rejects > 4096.
	    MINBLKSIZE=1024
	    MAXBLKSIZE=4096;;
    esac
    if test "$BLKSTEP" -eq 0; then
	blksizes="$(powrange "$MINBLKSIZE" "$MAXBLKSIZE")"
    else
	blksizes="$(range "$MINBLKSIZE" "$MAXBLKSIZE" "$BLKSTEP")"
    fi
    for BLKSIZE in $blksizes; do
	MAXDEVICES=1
	MINDEVICES=1
	export fs
	case x"$fs" in
	    x"zfs_raidz" | x"zfs_stripe" | x"zfs_mirror" | xbtrfs_raid0 \
		| xbtrfs_raid1 | x"mdraid"*"_raid4" | x"mdraid"*"_raid5" \
		| x"mdraid"*"_linear" \
		| x"mdraid"*"_raid10" | xlvm_raid1* | xlvm_mirror1 | xlvm_mirrorall)
		MINDEVICES=2
		MAXDEVICES=7
		;;
	    xbtrfs_raid10)
		MINDEVICES=4
		MAXDEVICES=7
		;;
	    x"zfs_raidz2"| xlvm_raid5 | xlvm_raid4)
		MINDEVICES=3
		MAXDEVICES=7;;
	    x"zfs_raidz3" | x"mdraid"*"_raid6")
		MINDEVICES=4
		MAXDEVICES=7;;
	    xlvm_raid6)
		MINDEVICES=5
		MAXDEVICES=7;;
	    x"mdraid"*"_raid0" | x"mdraid"*"_raid1" | x"lvm" | xlvm_stripe)
		MINDEVICES=1
		MAXDEVICES=7;;
	esac

	for NDEVICES in $(range "$MINDEVICES" "$MAXDEVICES" 1); do
	    export NDEVICES
	    unset FSIMAGEP
	    FSIMAGEP="${tempdir}/${fs}_${SECSIZE}_${BLKSIZE}_${NDEVICES}_"
	    export FSIMAGEP
	    unset NEED_IMAGES;

	    case x$fs in
  	    # RAID 1 has to work with even one device of the set.
		xzfs_mirror | x"mdraid"*"_raid1" | xlvm_mirrorall | xlvm_raid1all)
		    NEED_IMAGES_N=1;;
            # Degrade raidz by removing 3 devices
		xzfs_raidz3)
		    NEED_IMAGES_N=$((NDEVICES-3));;
	     # Degrade raidz by removing 2 devices
		xzfs_raidz2 | x"mdraid"*"_raid6" | x"lvm_raid6")
		    NEED_IMAGES_N=$((NDEVICES-2));;
	    # Degrade raidz and btrfs RAID1 by removing one device
 		xbtrfs_raid1 | xbtrfs_raid10 | xzfs_raidz | x"mdraid"*"_raid4" \
		    | x"mdraid"*"_raid5" | x"mdraid"*"_raid10" | xlvm_mirror1 \
		    | x"lvm_raid1" | x"lvm_raid4" | x"lvm_raid5")
		    NEED_IMAGES_N=$((NDEVICES-1));;
		*)
		    NEED_IMAGES_N=$NDEVICES;;
	    esac
	    export NEED_IMAGES_N

	    MNTPOINTRO="${tempdir}/${fs}_ro"
	    MNTPOINTRW="${tempdir}/${fs}_rw"
	    MOUNTOPTS=""
	    MOUNTFS="$fs"
	    MASTER="${tempdir}/master"
	    FSLABEL="grub_;/testé莭莽茝😁киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfewceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoirefoireoifoijfoirereoireoivoioirevoinvoinreoinvnoieoinreoinveoinveoinreoinvoineoinoinoineoinernoiveoinvreoiioewdioewoirvnoireoivfoirewfewoifoijewoijfoijewfoijfewoijoijoijoijoijoijoijfew"
	    CFILESRC=
	    for cand in /usr/share/dict/american-english /usr/share/dict/linux.words /data/data/com.termux/files/usr/share/hunspell/en_US.dic; do
		if test -f "$cand" ; then
		    CFILESRC="$cand"
		    break
		fi
	    done
	    if test "$CFILESRC" = "" ; then
		echo "Couldn't find compressible file" >&2
		exit 1
	    fi
	    case x"$fs" in
		    # FS LIMITATION: 8.3 names
		xmsdos*)
		    CFILE="american.eng";;
		xiso9660)
		    CFILE="american_english";;
		*)
		    CFILE="american-english";;
	    esac
        # OS LIMITATION: Limited by NAME_MAX (usually 255) in GNU/Linux
	    LONGNAME="qwertzuiopasdfghjklyxcvbnm1234567890qwertzuiopasdfghjklyxcvbnm1234567890oiewqfiewioqoiqoiurqruewqoiuwoieoiiuewqroreqiufieiuwrnureweriuvceoiroiewqoiricdsalkcndsakfirefoiwqeoircorejwoijfreoijojoiewjfwnfcoirenfoirefnreoifenoiwfnoi"
	    rm -rf "$MASTER"

	    case x"$fs" in
	        # FS LIMITATION: HFS+ label is at most 255 UTF-16 chars
		# OS LIMITATION: Linux HFS+ tools check UTF-8 length and don't
		# handle out-of-BMP characters
		x"hfsplus" | x"hfsplus_casesens" | x"hfsplus_wrap")
		    FSLABEL="grub_;/testé䏌䐓䏕киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoiq"
		    ;;
	    # FS LIMITATION: btrfs label is at most 255 UTF-8 chars
		x"btrfs"*)
		    FSLABEL="grub_;/testé莭莽😁киритi urewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoi";;

	    # FS LIMITATION: f2fs label is at most 512 UTF-16 chars
		x"f2fs")
		    FSLABEL="grub_;/testé䏌䐓䏕киритiurewfceniuewruewnuuireurevueurnievrewfnerfcnevirivinrewvnirewnivrewiuvcrewvnuewvrrrewniuerwreiuviurewiuviurewnuvewnvrenurnunuvrevuurerejiremvreijnvvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoirvcreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoircreivire nverivnreivrevnureiorfnfrvoeoiroireoireoifrefoieroifoireoifoiq";;

	    # FS LIMITATION: exfat is at most 15 UTF-16 chars
		x"exfat")
		    FSLABEL="géт ;/莭莽😁кир";;
	    # FS LIMITATION: ntfs label is at most ?? UTF-16 chars
		x"ntfs"*)
		    FSLABEL="grub_;/testéтi u莭😁茝кириrewfceniuewruevrewnuuireurevueurnievrewfnerfcnevirivinrewvniwnivrewiuvcrewvnuewvrrrewniureifiuewifjiww";;
	    # FS LIMITATION: nilfs2 label is at most 80 UTF-8 characters
		x"nilfs2")
		    FSLABEL="grub_;/testéтi u😁莽茝кириrewfceniuewruevrewnuuireurevueurnievrewfne";;
 	            # FS LIMITATION: afs and iso9660 label is at most 32 UTF-8 characters
		x"afs" | xiso9660 | xrockridge | xrockridge_joliet\
                     | xiso9660_1999 | xrockridge_1999 | xrockridge_joliet_1999)
		     FSLABEL="gr_;/é莭莽😁кирит u";;
 	            # FS LIMITATION: bfs label is at most 32 UTF-8 characters
 	            # OS LIMITATION: bfs label can't contain ; or /
		x"bfs")
		    FSLABEL="grub_é莭莽😁кирит u";;
 	        # FS LIMITATION: Joliet label is at most 16 UTF-16 characters
		# OS LIMITATION: xorriso doesn't handle out-of-BMP characters
		xjoliet | xjoliet_1999)
		    FSLABEL="g;/_é䏌䐓䏕䎛䎾䏴кит u"
		    #FSLABEL="g;/_é莭莽😁кит u"
		    ;;
	    # FS LIMITATION: reiserfs, extN and jfs label is at most 16 UTF-8 characters
		x"reiserfs_old" | x"reiserfs" | x"ext"* | x"lvm"* | x"mdraid"* | x"jfs" | x"jfs_caseins")
		    FSLABEL="g;/éт 莭😁";;
            # FS LIMITATION: No underscore, space, semicolon, slash or international characters in UFS* in label. Limited to 32 UTF-8 characters
		x"ufs1" | x"ufs1_sun" | x"ufs2")
		    FSLABEL="grubtest""ieurrucnenreeiurueurewf";;
	    # FS LIMITATION: XFS label is at most 12 UTF-8 characters
		x"xfs"|x"xfs_crc")
		    FSLABEL="géт 😁к";;
            # FS LIMITATION: FAT labels limited to 11 characters, no  international characters or lowercase
		x"vfat"* | xmsdos*)
		    FSLABEL="GRUBTEST ;_";;
	    # FS LIMITATION: AFFS is latin1. At most 29 characters
		x"affs" | xaffs_intl)
		    FSLABEL="grub_tt? #*w;/e£@¡¤½¾{[]}<>.,";;
	    # FS LIMITATION: SFS is latin1. At most 30 characters
		x"sfs"*)
		    FSLABEL="GRUB tt öäüé;/àèç åø¿ª©þð׫»µ¬";;
	    # FS LIMITATION:  HFS is Mac-Roman. At most 27 characters
		x"hfs")
		    FSLABEL="grub_t;/estéàèèéie fiucnree";;
	        # FS LIMITATION: UDF label is either up to 127 latin1 characters or 63 UTF-16 ones
		# OS LIMITATION: Linux UDF tools force ASCII label ...
		x"udf")
		    FSLABEL="grub_;/testurewfceniuewruevrewnuuireurevueurnievr";;
	    # FS LIMITATION:  ZFS doesn't accept non-ASCII in label
	    # FIXME: since this is used as a path component for mount it's very limited in length
		xzfs_* | xzfs)
		    FSLABEL="grub_testieufiue r";;
	    esac
	    case x"$fs" in
		xmdraid*)
		    DISKSIZE=314572800;;
		xlvm*)
		    LVMBLKMUL=$(((5800 * 1048576) / (8 * BLKSIZE * NDEVICES)))
		    DISKSIZE=$((8*BLKSIZE*LVMBLKMUL));;
		    # FS LIMITATION: some fs have disk size limit
		x"vfat12" | xmsdos12)
		    DISKSIZE=$((4000*BLKSIZE));;
		x"vfat12a" | xmsdos12a)
		    if [ $BLKSIZE -ge 2048 ]; then
			DISKSIZE=$((2500*BLKSIZE))
		    else
			DISKSIZE=$((3000*BLKSIZE))
		    fi
		    if [ $DISKSIZE -gt $((60000*SECSIZE)) ]; then
			DISKSIZE=$((60000*SECSIZE))
		    fi;;
		x"vfat16" | xmsdos16)
		    DISKSIZE=$((65000*BLKSIZE));;
		x"vfat16a" | xmsdos16a)
		    DISKSIZE=$((60000*SECSIZE))
		    ;;
		*)
		    DISKSIZE=10737418240;;
	    esac

	    if [ $DISKSIZE -ge $(((5800/NDEVICES)*1048576)) ]; then
		DISKSIZE=$(((5800/NDEVICES)*1048576))
	    fi

	    case x"$fs" in
		xvfat* | xmsdos* | xexfat* | xhfs | xhfsplus | xhfsplus_wrap | xaffs \
		    | xaffs_intl | xjfs_caseins | xsfs_caseins \
		    | xzfs_caseins | xiso9660)
		    CASESENS=n;;
		*)
		    CASESENS=y;;
	    esac

	    BIGBLOCKCNT=$((5000 * 1048576))
	    case x"$fs" in
		    # FS LIMITATION: small filesystems
		x"vfat12" | xmsdos12)
		    if [ $BLKSIZE -le 4096 ]; then
			BIGBLOCKCNT=0
		    elif [ $BLKSIZE = 8192 ]; then
			BIGBLOCKCNT=1500000
		    else
			BIGBLOCKCNT=$((2000*BLKSIZE))
		    fi
		    ;;
		x"vfat12a" | xmsdos12a)
		    if [ $BLKSIZE -le 4096 ] || [ $((128*SECSIZE)) = $BLKSIZE ]; then
			BIGBLOCKCNT=0
		    else
			BIGBLOCKCNT=700000
		    fi;;
		x"vfat16a" | xmsdos16a)
		    if [ $((128*SECSIZE)) = $BLKSIZE ]; then
			BIGBLOCKCNT=0
		    else
			BIGBLOCKCNT=$((2500*SECSIZE))
		    fi
		    ;;
		x"vfat16" | xmsdos16)
		    BIGBLOCKCNT=$((25000 * BLKSIZE))
		    if [ $BIGBLOCKCNT -gt 4294967295 ]; then
			BIGBLOCKCNT=4294967295
		    fi
		    ;;
		x"minix")
		    BIGBLOCKCNT=30000000;;

		xexfat)
			# Big blocks waste really a lot of space.
			# Not much is left.
		    if [ $BLKSIZE = 2097152 ]; then
			BIGBLOCKCNT=4500000000
		    fi
		    if [ $BLKSIZE = 4194304 ]; then
			BIGBLOCKCNT=3500000000
		    fi
		    ;;
		    # FS LIMITATION: romfs image is limited to 4G.
		x"romfs")
		    BIGBLOCKCNT=$((4000 * 1048576));;
		    # FS LIMITATION: These FS have uint32 as file size field
		x"vfat"* | xmsdos* | x"cpio_crc" | x"cpio_newc" | x"cpio_bin" | x"cpio_hpbin" | xsfs*)
		    BIGBLOCKCNT=4294967295;;
		    # FS LIMITATION: These FS have int32 as file size field
		    # FIXME: not so sure about AFFS
		    # OS LIMITATION: minix2/minix3 could be formatted in a way to permit more.
		x"minix3" | x"minix2" | x"hfs"| x"affs" | xaffs_intl | xreiserfs_old | xext2_old)
		    BIGBLOCKCNT=$((16#7fffffff));;

		    # FS LIMITATION: redundant storage
		    # We have only limited space. Mirroring multiplies it very effectively.
		xmdraid* | xlvm* | xzfs_mirror | xbtrfs_raid1)
		    BIGBLOCKCNT=$((100 * 1048576));;
   	            # We already test the FS for big files separately. Save some time here.
		x"zfs_raid"* | x"zfs_stripe"* | x"zfs_mirror"* | x"btrfs_raid"*)
		    BIGBLOCKCNT=$((100 * 1048576));;

                    # OS LIMITATION: bfs_fuse bugs beyond that
		xbfs)
		    BIGBLOCKCNT=$((800 * 1048576));;
	    esac

	    NOSYMLINK=n
	    case x"$fs" in
        # FS LIMITATION: no symlinks on FAT, exFAT, HFS, plain ISO9660 and Joliet
        # OS LIMITATION: ntfs-3g  creates interix symlinks which aren't real symlinks
		x"vfat"* | xmsdos* | x"hfs" | x"exfat" | x"ntfs"* \
		    | xiso9660 | xjoliet| xiso9660_1999 | xjoliet_1999)
		    NOSYMLINK=y;;
	    esac
	    NOHARDLINK=n
	    case x"$fs" in
                    # FS LIMITATION: no hardlinks on BFS, exfat, fat, hfs and SFS
		xbfs | xexfat | x"vfat"* | xmsdos* | xhfs | xsfs | xsfs_caseins)
		    NOHARDLINK=y;;
		    # GRUB LIMITATION: no hardlink support on newc and hfs+
		xcpio_crc | xcpio_newc | xhfsplus*)
		    NOHARDLINK=y;;
	    esac

                # FS LIMITATION: some filesystems limit file name size
	    case x"$fs" in
		x"cpio_ustar")
		    LONGNAME="`echo $LONGNAME |head -c 99`";;
		x"hfs")
		    LONGNAME="`echo $LONGNAME |head -c 31`";;
		x"minix" | x"minix2" | x"affs" | xaffs_intl | xiso9660)
		    LONGNAME="`echo $LONGNAME |head -c 30`";;
		x"sfs"*)
		    LONGNAME="`echo $LONGNAME |head -c 105`";;
		x"minix3")
		    LONGNAME="`echo $LONGNAME |head -c 60`";;
		x"udf")
		    LONGNAME="`echo $LONGNAME |head -c 192`";;
		    # GRUB LIMITATION: GRUB prefers Joliet over ISO9660:1999
		xjoliet | xjoliet_1999)
		    LONGNAME="`echo $LONGNAME |head -c 103`";;
		xiso9660_1999)
		    LONGNAME="`echo $LONGNAME |head -c 207`";;
		    # FS LIMITATION: 8.3
		xmsdos*)
		    LONGNAME="qwertzui.opa";;
	    esac
	    NOFILETIME=n
	    NOFSTIME=n
	    case x"$fs" in
	    # FIXME: Not sure about BtrFS, NTFS, JFS, AFS, UDF and SFS. Check it.
	# FS LIMITATION: as far as I know those FS don't store their last modification date.
		x"jfs_caseins" | x"jfs" | x"xfs" | x"xfs_crc" | x"btrfs"* | x"reiserfs_old" | x"reiserfs" \
		    | x"bfs" | x"afs" | x"f2fs" \
		    | x"tarfs" | x"cpio_"* | x"minix" | x"minix2" \
		    | x"minix3" | x"ntfs"* | x"udf" | x"sfs"*)
		    NOFSTIME=y;;
		    # OS LIMITATION: Linux doesn't update fstime.
		# OS LIMITATION: Linux apparently uses localtime instead of UTC
		xhfs)
		    NOFILETIME=y; NOFSTIME=y;;
	    # GRUB LIMITATION:  FAT and exFAT use localtime. Unusable for GRUB
		x"vfat"* | x"msdos"* | x"exfat")
		    NOFILETIME=y; NOFSTIME=y;;
	# FS LIMITATION: romfs has no timestamps.
		x"romfs")
		    NOFILETIME=y; NOFSTIME=y;;
	    esac

	    NOFSLABEL=n
	    case x"$fs" in
   	            # FS LIMITATION: these filesystems have no label.
		x"cpio_"* | x"tarfs" | x"squash4_"* | x"minix" | x"minix2" \
		    | x"minix3" | xreiserfs_old)
		    NOFSLABEL=y;;
	    esac

	    PDIRCOMPNUM=210
	    PDIR2COMPNUM=210

	    case x$fs in
		    # OS LIMITATION: bfs_fuse bugs beyond that
		xbfs)
		    PDIRCOMPNUM=10
		    PDIR2COMPNUM=10;;
		    # OS LIMITATION: Linux supports only inline symlinks
		xudf)
		    if [ $BLKSIZE = 1024 ]; then
			PDIR2COMPNUM=113
		    fi ;;
		    # FS LIMITATION: at most 255 on path length
		    # FS LIMITATION: at most 100 on symlink length
		xcpio_ustar)
		    PDIRCOMPNUM=84
		    PDIR2COMPNUM=30;;
		    # OS LIMITATION: Linux supports only symlink at most one block long on reiserfs
		xreiserfs | xreiserfs_old)
		    if [ $BLKSIZE = 512 ]; then
			PDIR2COMPNUM=114
		    fi ;;
		    # FS LIMITATION: SFS assumes that symlink
		    # with header fit in one block.
		    # FIXME: not sure about it.
		xsfs | xsfs_caseins)
		    if [ $BLKSIZE = 512 ]; then
			PDIR2COMPNUM=147
		    fi ;;
		    # FS LIMITATION: AFFS assumes that symlink
		    # with rather larger header fit in one block.
		    # FIXME: not sure about it.
		xaffs | xaffs_intl)
		    if [ $BLKSIZE = 512 ]; then
			PDIR2COMPNUM=97
		    fi ;;
	    esac


	    PDIR=""
		# OS LIMITATION: Limited by PATH_MAX (usually 1024)
	    for i in $(range 0 $((PDIRCOMPNUM-1)) 1); do
		PDIR="$PDIR/$i";
		if test $((i%3)) = 0; then
		    PDIR="$PDIR/"
		fi
	    done

	    PDIR2=""
		# OS LIMITATION: Limited by PATH_MAX (usually 1024)
	    for i in $(range 0 $((PDIR2COMPNUM-1)) 1); do
		PDIR2="${PDIR2}/$i";
		if test $((i%3)) = 0; then
		    PDIR2="${PDIR2}/"
		fi
	    done

	    PFIL="p.img"

	    unset LODEVICES
	    GENERATED=n
	    LODEVICES=
	    MOUNTDEVICE=
	    
	    case x"$fs" in
		x"tarfs" | x"cpio_"*| x"ziso9660" | x"romfs" | x"squash4_"*\
                    | x"iso9660" | xjoliet | xrockridge | xrockridge_joliet \
		    | x"iso9660_1999" | xjoliet_1999 | xrockridge_1999 \
		    | xrockridge_joliet_1999)
		    MNTPOINTRW="$MASTER"
		    MNTPOINTRO="$MASTER"
		    GENERATED=y
		    mkdir -p "$MASTER";;
  	            # No mkfs for GNU/Linux. Just unpack preformatted empty image
		*)
		    mkdir -p "$MNTPOINTRW"
		    mkdir -p "$MNTPOINTRO"
		    for i in $(range 0 $((NDEVICES-1)) 1); do
			dd if=/dev/zero of="$FSIMAGEP${i}.img" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null
			LODEVICE=$(losetup --find --show "$FSIMAGEP${i}.img")
			LODEVICES="$LODEVICES $LODEVICE"
			if test "$i" = 0; then
			    MOUNTDEVICE="$LODEVICE"
			fi
		    done ;;
	    esac

	    case x"$fs" in
		x"afs")
		    ;;
		x"btrfs")
		    "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}" ;;
		x"btrfs_zlib" | x"btrfs_lzo" | x"btrfs_zstd")
		    "mkfs.btrfs" -s $SECSIZE -L "$FSLABEL" "${MOUNTDEVICE}"
		    MOUNTOPTS="compress=${fs/btrfs_/},"
		    MOUNTFS="btrfs"
		    ;;
		x"btrfs_raid0")
		    "mkfs.btrfs" -s $SECSIZE -d raid0 -m raid0 -L "$FSLABEL" $LODEVICES
		    MOUNTFS="btrfs"
		    ;;
		x"btrfs_raid1")
		    "mkfs.btrfs" -s $SECSIZE -d raid1 -m raid1 -L "$FSLABEL" $LODEVICES
		    MOUNTFS="btrfs"
		    ;;
		x"btrfs_raid10")
		    "mkfs.btrfs" -s $SECSIZE -d raid10 -m raid10 -L "$FSLABEL" $LODEVICES
		    MOUNTFS="btrfs"
		    ;;
		x"btrfs_single")
		    "mkfs.btrfs" -s $SECSIZE -d single -L "$FSLABEL" $LODEVICES
		    MOUNTFS="btrfs"
		    ;;
		x"exfat")
		    "mkfs.$fs" -s $((BLKSIZE/512)) -n "$FSLABEL" "${MOUNTDEVICE}"
		    MOUNTOPTS="iocharset=utf8,"
		    MOUNTFS="exfat-fuse";;
		x"minix")
		    "mkfs.minix" "${MOUNTDEVICE}"
		    ;;
	# mkfs.hfs and mkfs.hfsplus don't fill UUID.
		x"hfsplus")
		    "mkfs.hfsplus" -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8 ;;
		x"hfsplus_wrap")
		    "mkfs.hfsplus" -w -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8
		    MOUNTFS="hfsplus";;
		x"hfsplus_casesens")
		    "mkfs.hfsplus" -s -b $BLKSIZE -v "$FSLABEL" "${MOUNTDEVICE}"
		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#468)) conv=notrunc count=8
		    MOUNTFS="hfsplus";;
		x"hfs")
		    "mkfs.hfs" -b $BLKSIZE -v "`echo $FSLABEL |recode utf8..macroman`" -h "${MOUNTDEVICE}"
		    dd if=/dev/urandom of="${MOUNTDEVICE}" bs=1 seek=$((16#474)) conv=notrunc count=8
		    MOUNTOPTS="iocharset=utf8,codepage=macroman,"
		    ;;
		x"vfat"*|xmsdos*)
		    BITS="${fs/vfat/}"
		    BITS="${BITS/msdos/}"
		    if [ "x${BITS:2:1}" = xa ]; then
			A=-A
		    else
			A=
		    fi
		    "mkfs.vfat" -a $A -S $SECSIZE -s $((BLKSIZE/SECSIZE)) -F "${BITS:0:2}" -n "$FSLABEL" "${MOUNTDEVICE}"
		    MOUNTOPTS="iocharset=utf8,codepage=437,"
		    MOUNTFS="$(echo "$fs"|sed 's,[0-9]*a\?$,,')";;
		x"minix2")
		    "mkfs.minix" -v "${MOUNTDEVICE}"
		    MOUNTFS="minix";;
		x"minix3")
		    "mkfs.minix" -B $BLKSIZE -3 "${MOUNTDEVICE}"
		    MOUNTFS="minix";;
		x"ntfs"*)
		    "mkfs.ntfs" -s "$SECSIZE" -c "$BLKSIZE" -L "$FSLABEL" -Q -q "${MOUNTDEVICE}"
		    MOUNTOPTS="iocharset=utf8,compression,"
		    MOUNTFS="ntfs-3g";;
		x"udf")
		    "mkudffs" --utf8 -b $BLKSIZE --lvid="$FSLABEL" "${MOUNTDEVICE}"
		    MOUNTOPTS="iocharset=utf8,bs=$BLKSIZE,";;
		x"ufs2")
		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 2 "${MOUNTDEVICE}"
		    MOUNTOPTS="ufstype=ufs2,"
		    MOUNTFS="ufs";;
		x"ufs1")
		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}"
		    MOUNTOPTS="ufstype=44bsd,"
		    MOUNTFS="ufs";;
		x"ufs1_sun")
		    "mkfs.ufs" -b $BLKSIZE -L "$FSLABEL" -O 1 "${MOUNTDEVICE}"
		    MOUNTOPTS="ufstype=sun,"
		    MOUNTFS="ufs";;
		x"zfs")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
		    sleep 1
		    "zfs" create "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_caseins")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
		    sleep 1
		    "zfs" create -o casesensitivity=insensitive "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_lzjb" | xzfs_gzip | xzfs_zle)
		    "zpool" create -O compression=${fs/zfs_/} -R "$MNTPOINTRW" "$FSLABEL" "${MOUNTDEVICE}"
		    sleep 1
		    "zfs" create -o compression=${fs/zfs_/} "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_raidz")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz1 $LODEVICES
		    sleep 1
		    "zfs" create "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_raidz2")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz2 $LODEVICES
		    sleep 1
		    "zfs" create "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_raidz3")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" raidz3 $LODEVICES
		    sleep 1
		    "zfs" create "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_mirror")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" mirror $LODEVICES
		    sleep 1
		    "zfs" create "$FSLABEL"/"grub fs"
		    sleep 1;;
		x"zfs_stripe")
		    "zpool" create -R "$MNTPOINTRW" "$FSLABEL" $LODEVICES
		    sleep 1
		    "zfs" create "$FSLABEL"/"grub fs"
		    sleep 1;;
		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_"*)
		    INSTDEVICE=/dev/null;;
		x"reiserfs")
		    "mkfs.reiserfs" --format=3.6 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}" ;;
		x"reiserfs_old")
		    "mkfs.reiserfs" --format=3.5 -b $BLKSIZE -l "$FSLABEL" -q "${MOUNTDEVICE}"
		    MOUNTFS=reiserfs;;
		x"jfs")
		    "mkfs.jfs" -L "$FSLABEL" -q "${MOUNTDEVICE}"
		    MOUNTOPTS="iocharset=utf8,";;
		x"jfs_caseins")
		    "mkfs.jfs" -O -L "$FSLABEL" -q "${MOUNTDEVICE}"
		    MOUNTFS=jfs
		    MOUNTOPTS="iocharset=utf8,";;
		x"mdraid"*)
		    mdadm -C --chunk=$((BLKSIZE/1024)) --force -e "${fs:6:1}.${fs:7:1}" "/dev/md/${fs}_${NDEVICES}" --level="${fs:13}" --raid-devices="$NDEVICES" $LODEVICES
		    MOUNTDEVICE="/dev/md/${fs}_${NDEVICES}"
		    MOUNTFS=ext2
		    "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
		x"lvm"*)
		    for lodev in $LODEVICES; do
			pvcreate "$lodev"
		    done
		    vgcreate -s $((BLKSIZE/1024))K grub_test $LODEVICES
		    if [ x$fs = xlvm ] ; then
			lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -n testvol grub_test
		    elif [ x$fs = xlvm_stripe ] ; then
			lvcreate -l "$((NDEVICES*7*LVMBLKMUL))" -i "$NDEVICES" -n testvol grub_test
		    elif [ x$fs = xlvm_mirror1 ] || [ x$fs = xlvm_raid1 ] ; then
			lvcreate -m 1 -l "$((NDEVICES*2*LVMBLKMUL))" --type "${fs/lvm_/}" -n testvol grub_test
		    elif [ x$fs = xlvm_mirrorall ] ; then
			lvcreate -m "$((NDEVICES-1))" -l "$((6*LVMBLKMUL))" --type mirror -n testvol grub_test
		    elif [ x$fs = xlvm_raid1all ] ; then
			# Until version 2.02.103 LVM counts metadata segments
			# twice when checking available space. Reduce segment
			# count to work around it.
			lvcreate -m "$((NDEVICES-1))" -l "$((6*LVMBLKMUL - 1))" --type raid1 -n testvol grub_test
		    elif [ x$fs = xlvm_raid4 ] || [ x$fs = xlvm_raid5 ]; then
			lvcreate -l "$(((NDEVICES-1) * 5*LVMBLKMUL))" -i "$((NDEVICES-1))" --type "${fs/lvm_/}" -n testvol grub_test
		    elif [ x$fs = xlvm_raid6 ]; then
			lvcreate -l "$(((NDEVICES-2) * 5*LVMBLKMUL))" -i "$((NDEVICES-2))" --type "${fs/lvm_/}" -n testvol grub_test
		    fi
		    MOUNTDEVICE="/dev/mapper/grub_test-testvol"
		    MOUNTFS=ext2
		    "mkfs.ext2" -L "$FSLABEL" -q "${MOUNTDEVICE}"  ;;
		xf2fs)
		    "mkfs.f2fs" -l "$FSLABEL" -q "${MOUNTDEVICE}" ;;
		xnilfs2)
		    "mkfs.nilfs2" -L "$FSLABEL" -b $BLKSIZE  -q "${MOUNTDEVICE}" ;;
		xext2_old)
		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext2" -r 0 -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
		    MOUNTFS=ext2
		    ;;
		xext4_metabg)
		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O meta_bg,^resize_inode -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
		    MOUNTFS=ext4
		    ;;
               xext4_encrypt)
                   MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.ext4" -O encrypt -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}"
                   MOUNTFS=ext4
                   ;;
		xext*)
		    MKE2FS_DEVICE_SECTSIZE=$SECSIZE "mkfs.$fs" -b $BLKSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
		xxfs)
		    "mkfs.xfs" -m crc=0 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
		xxfs_crc)
		    MOUNTFS="xfs"
		    "mkfs.xfs" -m crc=1 -b size=$BLKSIZE -s size=$SECSIZE -L "$FSLABEL" -q "${MOUNTDEVICE}" ;;
		*)
		    echo "Add appropriate mkfs command here"
		    exit 1
		    ;;
	    esac
	    BASEFILE="1.img"
	    NASTYFILE=".?*\\!\"#%@\$%&'()+ ,-.:;<=>^{_}[]\`|~."
	    case x"$fs" in

 	            # FS LIMITATION: AFFS and SFS don't accept :
		xsfs*)
		    NASTYFILE=".?*\\!\"#%@\$%&'()+ ,-.;<=>^{_}[]\`|~.";;
	            # FS LIMITATION: AFFS is limited in file name length (30)
		x"affs" | xaffs_intl)
		    NASTYFILE=".?*\\!\"#@\$'()+ ,-;<=>^{_}[]\`|~.";;
	    # FS LIMITATION: hfs, minix and minix2 are limited in file name length (30 or 31)
		x"hfs" | x"minix" | x"minix2")
		    NASTYFILE=".?*\\!\"#@\$&'()+ ,-:;<=>{}[]\`|~.";;
	    # FS LIMITATION: FAT doesn't accept ?, *, \, ", :,  <, >, |
	    # FS LIMITATION: FAT discards dots at the end.
		x"vfat"* | x"exfat")
		    NASTYFILE=".!#%@\$%&'()+ ,-.;=^{_}[]\`~";;
	    # FS LIMITATION: 8.3 limitations apply
		x"msdos"*)
		    NASTYFILE="!#%@\$%&.;=^";;
		    # FS LIMITATION: No ' ', '*', '/', ':', ';', '?', '\\' in joliet
		    # GRUB LIMITATION: GRUB prefers Joliet over ISO9660:1999
		xjoliet | xjoliet_1999)
		    NASTYFILE=".!\"#%@\$%&'()+,-.<=>^{_}[]\`|~.";;
		    # FS LIMITATION: iso9660 accepts only [0-9A-Z_]*, 32 characters at most
		xiso9660)
		    NASTYFILE="0123456789_acefghijknopqrvwxyz";;
	    esac

	    case x"$fs" in
 	            # FS LIMITATION: HFS, AFFS and SFS use legacy codepage (mac-roman or latin1)
		x"sfs"* | x"hfs" | x"affs" | xaffs_intl)
		    IFILE="éàèüöäëñ"
		    ISYM="ëñéüöäàè"
		    ;;
		    # FS LIMITATION: filename length limitation.
		x"minix" | x"minix2")
		    IFILE="éàèüö😁ñкиΕλκά"
		    ISYM="Ελκάкиéà😁öäëñ"
		    ;;
		xminix3)
		    IFILE="éàèüöäëñкирица莭茝Ελλικά😁😜😒"
		    ISYM="Ελλικά😁😜😒莭茝кирицаéàèüöäëñ";;
	        # GRUB LIMITATION: HFS+ uses NFD. GRUB doesn't handle NF conversion.
		# OS LIMITATION: Linux doesn't handle out-of-BMP characters for UTF-16
		x"hfsplus" | x"hfsplus_casesens" | x"hfsplus_wrap")
		    IFILE="éàèüöäëñкирилица䏌䐓䏕Ελληνικα̍䏌䐓䏕"
		    ISYM="Ελληνικα̍кирилица䏌䐓䏕éàèüöäëñ䏌䐓䏕"
		    ;;
		    # GRUB LIMITATION: On case-insensitive ZFS isn't supported with non-uppercase characters
		xzfs_caseins)
		    IFILE="ÉÀÈÜÖÄËÑКИРИЛИЦА莭莽茝ΕΛΛΗΝΙΚΆ😁😜😒"
		    ISYM="ΕΛΛΗΝΙΚΆКИРИЛИЦА😁😜😒ÉÀÈÜÖÄËÑ莭莽茝";;
		    # FS LIMITATION: 8.3 CP437
		x"msdos"*)
		    IFILE="éàèüöäëñ.éàè"
		    ;;
		    # FS LIMITATION: iso9660 is ASCII-only.
		x"iso9660")
		    IFILE="abcdefghijkmmnop"
		    ;;
		# OS LIMITATION: Linux doesn't handle out-of-BMP characters for UTF-16
		# OS LIMITATION: xorriso doesn't handle out-of-BMP characters
		xjoliet | xjoliet_1999 | x"vfat"* | x"jfs"* | x"udf"*)
		    IFILE="éàèüöäëñкирилица䏌䐓䏕Ελληνικά䏌䐓䏕"
		    ISYM="Ελληνικάкирилица䏌䐓䏕éàèüöäëñ䏌䐓䏕";;
		*)
		    IFILE="éàèüöäëñкирилица莭莽茝Ελληνικά😁😜😒"
		    ISYM="Ελληνικάкирилица😁😜😒éàèüöäëñ莭莽茝";;
	    esac
	    BIGFILE="big.img"
	    BASESYM="sym"
	    BASEHARD="hard"
	    SSYM="///sdir////ssym"
	    USYM="///sdir////usym"
	    LONGSYM="longsym"
	    PSYM="psym"
	    OSDIR=""
	    GRUBDEVICE=loop0
	    case x"$fs" in
		xmdraid*)
		    GRUBDEVICE="mduuid/`mdadm --detail --export $MOUNTDEVICE | grep MD_UUID=|sed 's,MD_UUID=,,g;s,:,,g'`";;
		xlvm*)
		    GRUBDEVICE="lvm/grub_test-testvol";;
	    esac
	    GRUBDIR="($GRUBDEVICE)"
	    case x"$fs" in
		x"zfs"*)
		    OSDIR="grub fs/"
		    GRUBDIR="($GRUBDEVICE)/grub fs@";;
		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_"* | xafs)
		    ;;
		*)
		    if ! mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRW" -o ${MOUNTOPTS}${SELINUXOPTS}rw  ; then
			echo "MOUNT FAILED."
			for lodev in $LODEVICES; do
			    while ! losetup -d "$lodev"; do
				sleep 1
			    done
			done
			for i in $(range 0 $((NDEVICES-1)) 1); do
			    rm "$FSIMAGEP${i}.img"
			done
			exit 1;
		    fi
		    ;;
	    esac
	    case x"$fs" in
		    # FS LIMITATION: redundant storage
		xmdraid* | xlvm*)
		    BLOCKCNT=1048576;;
		x"zfs_raid"* | x"zfs_stripe"* | x"zfs_mirror"* | x"btrfs_raid"*)
		    BLOCKCNT=1048576;;

		    # FS LIMITATION: small filesystems
		x"vfat16a" | x"msdos16a")
		    BLOCKCNT=65536;;
		x"vfat12a" | xmsdos12a)
		    BLOCKCNT=32768;;
		xminix)
		    BLOCKCNT=2621440;;
		xvfat16 | xmsdos16)
		    if [ $BLKSIZE = 512 ] || [ $BLKSIZE = 1024 ]; then
			BLOCKCNT=1048576
		    else
			BLOCKCNT=5242880
		    fi
		    ;;
		xvfat12 | xmsdos12)
		    BLOCKCNT=$((100*BLKSIZE))
		    if [ $BLOCKCNT -gt 5242880 ]; then
			BLOCKCNT=5242880;
		    fi
		    ;;
		*)
		    BLOCKCNT=5242880;;
	    esac
	    # Make sure file is not exact multiple of block size. This helps to force
	    # tail packing in case of squash4.
	    BLOCKCNT="$((BLOCKCNT-1))"
	    case x"$fs" in
		x"ntfscomp")
		    setfattr -h -v 0x00000800 -n system.ntfs_attrib_be "$MNTPOINTRW/$OSDIR";;
	    esac
		# OS LIMITATION: No AFS support under GNU/Linux
	    mkdir "$MNTPOINTRW/$OSDIR/sdir"
	    mkdir -p "$MNTPOINTRW/$OSDIR/$PDIR"
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/sdir/2.img"
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$BASEFILE"
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$NASTYFILE"
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$IFILE"
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$LONGNAME"
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/$PDIR/$PFIL"
	    if [ $PDIR != $PDIR2 ]; then
		"@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/${PDIR2}/$PFIL"
	    fi
	    "@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/CaSe"
	    if [ x$CASESENS = xy ]; then
		"@builddir@"/garbage-gen $BLOCKCNT > "$MNTPOINTRW/$OSDIR/cAsE"
	    fi
	    if (test x$fs = xvfat12a || test x$fs = xmsdos12a) && test x$BLKSIZE = x131072; then
		    # With this config there isn't enough space for full copy.
		    # Copy as much as we can
		cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}" &> /dev/null;
	    else

		cp "${CFILESRC}" "$MNTPOINTRW/$OSDIR/${CFILE}";

	    fi

	    if [ x$NOSYMLINK != xy ]; then
		ln -s "$BASEFILE" "$MNTPOINTRW/$OSDIR/$BASESYM"
		ln -s "2.img" "$MNTPOINTRW/$OSDIR/$SSYM"
		ln -s "../1.img" "$MNTPOINTRW/$OSDIR/$USYM"
		ln -s "$LONGNAME" "$MNTPOINTRW/$OSDIR/$LONGSYM"
		ln -s "${PDIR2}/$PFIL" "$MNTPOINTRW/$OSDIR/$PSYM"
		ln -s "$IFILE" "$MNTPOINTRW/$OSDIR/$ISYM"
	    fi
	    if [ x$NOHARDLINK != xy ]; then
		ln "$MNTPOINTRW/$OSDIR/$BASEFILE" "$MNTPOINTRW/$OSDIR/$BASEHARD"
	    fi

	    case x"$fs" in
		x"afs")
		    ;;
		x"zfs"*)
		    while ! zpool export "$FSLABEL" ; do
			sleep 1;
		    done
		    sleep 2
		    ;;
		x"tarfs")
		    (cd "$MASTER"; tar cf "${FSIMAGEP}0.img" .) ;;
		x"cpio_"*)
		    (cd "$MASTER"; find . | cpio -o -H "$(echo ${fs} | sed 's@^cpio_@@')" > "${FSIMAGEP}0.img" ) ;;
		x"ziso9660")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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" ;;
		x"iso9660")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"joliet")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"rockridge")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"rockridge_joliet")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"iso9660_1999")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"joliet_1999")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"rockridge_1999")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"rockridge_joliet_1999")
		    FSUUID=$(date -u +%Y-%m-%d-%H-%M-%S-00);
		    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"  ;;
		x"romfs")
		    genromfs -V "$FSLABEL" -f "${FSIMAGEP}0.img" -d "$MASTER" ;;
		xsquash4_*)
		    echo mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE
		    mksquashfs "$MASTER" "${FSIMAGEP}0.img" -always-use-fragments -comp "${fs/squash4_/}" -b $BLKSIZE ;;
		x"bfs")
		    sleep 1
		    fusermount -u "$MNTPOINTRW"
		    ;;
		xlvm*)
		    sleep 1
		    for try in $(range 0 20 1); do
			if umount "$MNTPOINTRW" ; then
			    break;
			fi
			sleep 1;
		    done
		    UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S")
		    sleep 1
		    vgchange -a n grub_test
		    ;;
		xmdraid*)
		    sleep 1
		    for try in $(range 0 20 1); do
			if umount "$MNTPOINTRW" ; then
			    break;
			fi
			sleep 1;
		    done
		    UMOUNT_TIME=$(date -u "+%Y-%m-%d %H:%M:%S")
		    sleep 1
		    mdadm --stop /dev/md/"${fs}_$NDEVICES"
		    ;;
		*)
		    sleep 1
		    for try in $(range 0 20 1); do
			if umount "$MNTPOINTRW" ; then
			    break;
			fi
			sleep 1;
		    done
		    ;;
	    esac
	    sleep 1

	    case x"$fs" in
		x"zfs"*)
		    "zpool" import -d /dev -R "$MNTPOINTRO" "$FSLABEL"
		    ;;
		x"tarfs")
		    ;;
		x"cpio_"*)
		    ;;
		x"ziso9660")
		    ;;
		xiso9660 | xrockridge | xjoliet | xrockridge_joliet)
		    ;;
		xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
		    ;;
		x"romfs")
		    ;;
		xsquash4_*)
		    ;;
		xlvm*)
		    vgchange -a y grub_test
		    sleep 1
		    mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
		xmdraid*)
		    mdadm --assemble /dev/md/"${fs}_$NDEVICES" $LODEVICES
		    sleep 1
		    mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
		*)
		    mount -t "$MOUNTFS" "${MOUNTDEVICE}" "$MNTPOINTRO" -o ${MOUNTOPTS}${SELINUXOPTS}ro ;;
	    esac

	    run_grubfstest ls -- -la
	    case x"$fs" in
		x"zfs"*)
		    LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/");;
		*)
		    LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/");;
	    esac
	    if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then
		:
	    else
		echo LIST FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO"
		exit 1
	    fi

	    if echo "$LSROUT" | grep -F " $NASTYFILE" | grep "$BLOCKCNT"> /dev/null; then
		:
	    else
		echo NLIST FAIL
		echo "$LSROUT"
		TZ=UTC ls -lA "$MNTPOINTRO"
		exit 1
	    fi

	    if echo "$LSROUT" | grep -F " $IFILE" | grep "$BLOCKCNT"> /dev/null; then
		:
	    else
		echo ILIST FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO"
		exit 1
	    fi

	    if echo "$LSROUT" | grep -F " $LONGNAME" | grep "$BLOCKCNT"> /dev/null; then
		:
	    else
		echo LONG LIST FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO"
		exit 1
	    fi

	    if [ x$NOFILETIME != xy ]; then
		filtime=$(TZ=UTC ls --time-style=+%Y%m%d%H%M%S -l -d "$MNTPOINTRO/$OSDIR/$BASEFILE"|awk '{print $6; }')
		if echo "$LSROUT" | grep -F "$filtime $BASEFILE" > /dev/null; then
		    :
		else
		    echo TIME FAIL
		    echo "$LSROUT"
		    TZ=UTC ls -l "$MNTPOINTRO"
		    exit 1
		fi

		filtime=$(TZ=UTC ls --time-style=+%Y%m%d%H%M%S -l -d "$MNTPOINTRO/$OSDIR/$LONGNAME"|awk '{print $6; }')
		if echo "$LSROUT" | grep -F "$filtime $LONGNAME" > /dev/null; then
		    :
		else
		    echo LONG TIME FAIL
		    echo "$LSROUT"
		    TZ=UTC ls -l "$MNTPOINTRO"
		    exit 1
		fi
	    fi

	    case x"$fs" in
		x"zfs"*)
		    LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/grub fs@/.");;
		*)
		    LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/.");;
	    esac
	    if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then
		:
	    else
		echo DOT IN ROOTDIR FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO"
		exit 1
	    fi

	    case x"$fs" in
		x"zfs"*)
		    ;;
		*)
		    LSROUT=$(run_grubfstest ls -- -la "($GRUBDEVICE)/..");
		    if echo "$LSROUT" | grep -F " $BASEFILE" | grep "$BLOCKCNT" > /dev/null; then
			:
		    else
			echo DOTDOT IN ROOTDIR FAIL
			echo "$LSROUT"
			TZ=UTC ls -l "$MNTPOINTRO"
			exit 1
		    fi
		    ;;
	    esac

	    case x"$fs" in
		x"zfs"*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/////sdir");;
		*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/////sdir");;
	    esac
	    if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then
		:
	    else
		echo SLIST FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO/sdir"
		exit 1
	    fi

	    case x"$fs" in
		x"zfs"*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/$PDIR");;
		*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/$PDIR");;
	    esac
	    if echo "$LSROUT" | grep -F " p.img" | grep $BLOCKCNT > /dev/null; then
		:
	    else
		echo PLIST FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO/$PDIR"
		exit 1
	    fi

	    case x"$fs" in
		x"zfs"*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/.");;
		*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/.");;
	    esac
	    if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then
		:
	    else
		echo DOT IN SUBDIR FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/sdir"
		exit 1
	    fi

	    case x"$fs" in
		x"zfs"*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/grub fs@/sdir/../sdir");;
		*)
		    LSROUT=$(run_grubfstest ls -- -l "($GRUBDEVICE)/sdir/../sdir");;
	    esac
	    if echo "$LSROUT" | grep -F " 2.img" | grep $BLOCKCNT > /dev/null; then
		:
	    else
		echo DOTDOT IN SUBDIR FAIL
		echo "$LSROUT"
		TZ=UTC ls -l "$MNTPOINTRO/$OSDIR/ssdir"
		exit 1
	    fi

	    LSOUT=`run_grubfstest ls -- -l "($GRUBDEVICE)"`
	    if [ x"$NOFSLABEL" = xy ]; then
		:
	    elif echo "$LSOUT" | grep -F "Label \`$FSLABEL'" > /dev/null; then
		:
	    else
		echo LABEL FAIL
		echo "$LSOUT"
		blkid "${MOUNTDEVICE}"
		exit 1
	    fi

    # Inconsistencies between GRUB and blkid.
	    case x"$fs" in
		x"iso9660" | x"ziso9660" | xrockridge | xjoliet | xrockridge_joliet | x"iso9660_1999" | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999) ;;
		x"zfs"*)
		    for lodev in $LODEVICES; do
			FSUUID=$(printf "%016x\n" $(blkid -o export "$lodev" |grep -F UUID=|sed s,UUID=,,g))
			if [ "$FSUUID" != 0000000000000000 ]; then
			    break;
			fi
		    done;;
		*)
		    FSUUID=`blkid -o export "${MOUNTDEVICE}" |grep -F UUID=|sed s,UUID=,,g`
		    ;;
	    esac
	    case x"$fs" in
		x"hfs"*)
		    GRUBUUID="`run_grubfstest xnu_uuid "$GRUBDEVICE"`"
		    if [ x"$GRUBUUID" = x"$FSUUID" ]; then
			:
		    else
			echo UUID FAIL
			echo "$LSOUT"
			echo "$GRUBUUID"
			for lodev in $LODEVICES; do
			    blkid "$lodev"
			done
			exit 1
		    fi
		    ;;
        # FS LIMITATION: romfs, cpio, tar, squash4, minix, AFS, old reiserfs and minix2
	# have no UUID.
		    # GRUB LIMITATION: use creation date for squash4, AFFS and SFS?
		    # GRUB LIMITATION: use tags serials on UDF?
		    # GRUB LIMITATION: use root ctime on cpio, tar, minix*, UDF, reiserfs_old?
	            # GRUB LIMITATION: Support Atari UUIDs
		x"romfs" | x"cpio_"* | x"tarfs" | x"squash4_"* | x"minix" \
		    | x"minix2" | x"minix3" | x"affs" | xaffs_intl \
		    | x"udf" | xvfat12a | xvfat16a | xmsdos12a | xmsdos16a | xafs | xsfs* \
		    | xreiserfs_old)
		    ;;
		*)
		    if [ x"$FSUUID" = x ]; then
			echo "Warning: blkid couldn't retrieve UUID"
		    elif echo "$LSOUT" | grep -F 'UUID '"$FSUUID"' ' > /dev/null; then
			:
		    else
			echo UUID FAIL
			echo "$FSUUID"
			echo "$LSOUT"
			blkid "${MOUNTDEVICE}"
			exit 1
		    fi
		    ;;
	    esac

	    if [ x$NOFSTIME != xy ]; then
		case x$fs in
		    xiso9660 | xziso9660 | xrockridge | xjoliet | xrockridge_joliet | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
			FSTIME="$(date -d "$(echo ${FSUUID} | awk -F - '{ print $1"-"$2"-"$3" "$4":"$5":"$6 ;}')" '+%Y-%m-%d %H:%M:%S')";;
		    xlvm*|xmdraid*)
			# With some abstractions like mdraid flushing to disk
			# may be delayed for a long time.
			FSTIME="$UMOUNT_TIME";;
		    *)
			FSTIME="$(TZ=UTC ls --time-style="+%Y-%m-%d_%H:%M:%S" -l -d "${FSIMAGEP}0.img"|awk '{print $6; }'|sed 's,_, ,g')";;
		esac
		# With some abstractions like mdraid computing of UMOUNT_TIME
		# is not precise. Account for small difference here.
		FSTIMEM1="$(date -d "$FSTIME UTC -1 second" -u "+%Y-%m-%d %H:%M:%S")"
		FSTIMEM2="$(date -d "$FSTIME UTC -2 second" -u "+%Y-%m-%d %H:%M:%S")"
		FSTIMEM3="$(date -d "$FSTIME UTC -3 second" -u "+%Y-%m-%d %H:%M:%S")"

		if echo "$LSOUT" | grep -F 'Last modification time '"$FSTIME" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM1" > /dev/null || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM2" || echo "$LSOUT" | grep -F 'Last modification time '"$FSTIMEM3" > /dev/null; then
		    :
		else
		    echo FSTIME FAIL
		    echo "$FSTIME"
		    echo "$LSOUT"
		    exit 1
		fi
	    fi

	    if [ x$NOHARDLINK != xy ]; then
		if run_grubfstest cmp "$GRUBDIR/$BASEHARD" "$MNTPOINTRO/$OSDIR/$BASEFILE"  ; then
		    :
		else
		    echo HARDLINK FAIL
		    exit 1
		fi
	    fi

	    if [ x$NOSYMLINK != xy ]; then
		if run_grubfstest cmp "$GRUBDIR/$BASESYM" "$MNTPOINTRO/$OSDIR/$BASEFILE"  ; then
		    :
		else
		    echo SYMLINK FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/$LONGSYM" "$MNTPOINTRO/$OSDIR/$LONGNAME"  ; then
		    :
		else
		    echo LONG SYMLINK FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/$ISYM" "$MNTPOINTRO/$OSDIR/$IFILE"  ; then
		    :
		else
		    echo INTL SYMLINK FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/$SSYM" "$MNTPOINTRO/$OSDIR/////sdir/////2.img"  ; then
		    :
		else
		    echo SDIR SYMLINK FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/$USYM" "$MNTPOINTRO/$OSDIR/1.img"  ; then
		    :
		else
		    echo SDIR SYMLINK FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/$PSYM" "$MNTPOINTRO/$OSDIR/${PDIR2}/$PFIL"  ; then
		    :
		else
		    echo PATH LONG SYMLINK FAIL
		    exit 1
		fi
	    fi

	    if run_grubfstest cmp "$GRUBDIR/$BASEFILE" "$MNTPOINTRO/$OSDIR/$BASEFILE"  ; then
		:
	    else
		echo READ FAIL
		exit 1
	    fi
	    if run_grubfstest cmp "$GRUBDIR/$NASTYFILE" "$MNTPOINTRO/$OSDIR/$NASTYFILE"  ; then
		:
	    else
		echo NREAD FAIL
		exit 1
	    fi
		# Reference archive contains original name
	    if run_grubfstest cmp "$GRUBDIR/$LONGNAME" "$MNTPOINTRO/$OSDIR/$LONGNAME"  ; then
		:
	    else
		echo LONG NAME READ FAIL
		exit 1
	    fi
	    if run_grubfstest cmp "$GRUBDIR/////sdir/////2.img" "$MNTPOINTRO/$OSDIR/sdir/2.img"  ; then
		:
	    else
		echo LONG NAME READ FAIL
		exit 1
	    fi
	    if run_grubfstest cmp "$GRUBDIR/$IFILE" "$MNTPOINTRO/$OSDIR/$IFILE"  ; then
		:
	    else
		echo IREAD FAIL
		exit 1
	    fi
	    if run_grubfstest cmp "$GRUBDIR/$PDIR/$PFIL" "$MNTPOINTRO/$OSDIR/$PDIR/$PFIL"  ; then
		:
	    else
		echo PREAD FAIL
		echo cmp "$GRUBDIR/$PDIR/$PFIL" "$MNTPOINTRO/$OSDIR/$PDIR/$PFIL"
		exit 1
	    fi
	    ok=true
	    if ! run_grubfstest cmp "$GRUBDIR/${CFILE}" "$MNTPOINTRO/$OSDIR/${CFILE}"  ; then
		ok=false;
	    fi
	    if  test x$ok = xtrue; then
		:
	    else
		echo CREAD FAIL
		exit 1
	    fi

	    if [ x$CASESENS = xy ]; then
		if run_grubfstest cmp "$GRUBDIR/CaSe" "$MNTPOINTRO/$OSDIR/CaSe"  ; then
		    :
		else
		    echo CASE1 READ FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/cAsE" "$MNTPOINTRO/$OSDIR/cAsE"  ; then
		    :
		else
		    exit 1
		fi
		if cmp "$MNTPOINTRO/$OSDIR/cAsE" "$MNTPOINTRO/$OSDIR/CaSe" > /dev/null ; then
		    exit 1
		fi
		if  test x$ok = xtrue; then
		    :
		else
		    echo CASE READ FAIL
		    exit 1
		fi
	    else
		# OS LIMITATION: Linux make FAT (partially) case-sensitive...
		# ISO9660 is generated and master doesn't change
		case x$fs in
		    xiso9660 | xvfat*)
			CASEX=CaSe;;
		    *)
			CASEX=cAsE;;
		esac
		if run_grubfstest cmp "$GRUBDIR/CaSe" "$MNTPOINTRO/$OSDIR/${CASEX}"  ; then
		    :
		else
		    echo CASE1 READ FAIL
		    exit 1
		fi
		if run_grubfstest cmp "$GRUBDIR/cAsE" "$MNTPOINTRO/$OSDIR/CaSe"  ; then
		    :
		else
		    echo CASE2 READ FAIL
		    exit 1
		fi
		if ! cmp "$MNTPOINTRO/$OSDIR/CaSe" "$MNTPOINTRO/$OSDIR/${CASEX}" > /dev/null ; then
		    echo CASE CMP READ FAIL
		    exit 1
		fi
		if  test x$ok = xtrue; then
		    :
		else
		    echo CASE READ FAIL
		    exit 1
		fi
	    fi

	    case x"$fs" in
		x"zfs"*)
		    while ! zpool export "$FSLABEL" ; do
			sleep 1;
		    done
		    sleep 5;;
		x"tarfs" | x"cpio_"* | xrockridge | xjoliet | xrockridge_joliet | x"ziso9660" | x"romfs" | x"squash4_"* | xiso9660 | xiso9660_1999 | xrockridge_1999 | xjoliet_1999 | xrockridge_joliet_1999)
		    rm -rf "$MNTPOINTRW";;
		x"afs")
		    rm -rf "$MNTPOINTRO"
		    ;;
		*)
		    sleep 1
		    umount "$MNTPOINTRO"  || true
		    umount "$MNTPOINTRW" || true
	    esac
	    sleep 1
	    case x"$fs" in
		xmdraid*)
		    mdadm --stop /dev/md/"${fs}_$NDEVICES"
		    sleep 1
		    ;;
		xlvm*)
		    vgchange -a n grub_test
		    sleep 1
		    ;;
	    esac
	    case x"$fs" in
		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) ;;
		*)
		    for lodev in $LODEVICES; do
			while ! losetup -d "$lodev"; do
			    sleep 1
			done
		    done;;
	    esac
	    for i in $(range 0 $((NDEVICES-1)) 1); do
		rm "$FSIMAGEP${i}.img"
	    done
	    if [ x"$fs" = x"zfs" ]; then
		rmdir "$MNTPOINTRW"/"grub fs"  || true
		rmdir "$MNTPOINTRO"/"grub fs"  || true
	    fi
	    rm -rf "$MNTPOINTRW"  || true
	    rm -rf "$MNTPOINTRO"  || true
	done
    done
done
rmdir "${tempdir}"