File: rs01.bash

package info (click to toggle)
dvdisaster 0.79.5-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 42,960 kB
  • sloc: ansic: 33,411; sh: 4,898; makefile: 138
file content (1803 lines) | stat: -rwxr-xr-x 68,350 bytes parent folder | download | duplicates (2)
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
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
#!/usr/bin/env bash

. common.bash

ISOSIZE=21000
REDUNDANCY="-n normal"

MASTERISO=$ISODIR/rs01-master.iso
MASTERECC=$ISODIR/rs01-master.ecc
TMPISO=$ISODIR/rs01-tmp.iso
TMPECC=$ISODIR/rs01-tmp.ecc
SIMISO=$ISODIR/rs01-sim.iso

CODEC_PREFIX=RS01

# Create master image and ecc file

if ! file_exists $MASTERISO; then
    echo "$NEWVER --debug -i$MASTERISO --random-image $ISOSIZE" >>$LOGFILE
    $NEWVER --debug -i$MASTERISO --random-image $ISOSIZE >>$LOGFILE 2>&1
    echo -e "$FILE_MSG"
    FILE_MSG=""
fi

if ! file_exists $MASTERECC; then
    echo "$NEWVER --debug --set-version $SETVERSION -i$MASTERISO -e$MASTERECC -c $REDUNDANCY" >>$LOGFILE
    $NEWVER --debug --set-version $SETVERSION -i$MASTERISO -e$MASTERECC -c $REDUNDANCY >>$LOGFILE 2>&1
    echo -e "$FILE_MSG"
    FILE_MSG=""
fi

ISO_PLUS56=$ISODIR/rs01-plus56_bytes.iso
ECC_PLUS56=$ISODIR/rs01-plus56_bytes.ecc
if ! file_exists $ISO_PLUS56; then
    cp $MASTERISO $ISO_PLUS56
    dd if=/dev/zero of=/tmp/padding count=1 bs=56 >>$LOGFILE 2>&1
    cat /tmp/padding >>$ISO_PLUS56
    rm -f /tmp/padding
    echo -e "$FILE_MSG"
    FILE_MSG=""
fi

if ! file_exists $ECC_PLUS56; then
    $NEWVER --debug --set-version $SETVERSION -i$ISO_PLUS56 -e$ECC_PLUS56 -c $REDUNDANCY >>$LOGFILE 2>&1
    echo -e "$FILE_MSG"
    FILE_MSG=""
fi

### Verification tests

echo "# Verify tests"

# Test good files
if try "good image" good; then

  run_regtest good "-t" $MASTERISO $MASTERECC
fi

# Test good files
if try "good image, quick test" good_quick; then
  run_regtest good_quick "-tq" $MASTERISO $MASTERECC
fi

# Test with neither image nor ecc file
if try "missing files" no_files; then
   run_regtest no_files "-t" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Test with missing image, ecc file
if try "missing image" no_image; then
   run_regtest no_image "-t" $ISODIR/no.iso  $MASTERECC
fi

# Test with good image, no ecc file
if try "missing ecc" no_ecc; then
   run_regtest no_ecc "-t" $MASTERISO $ISODIR/no.ecc
fi

# Test with missing sectors, no ecc file
if try "defective image, no ecc" defective_image_no_ecc; then
   cp $MASTERISO $TMPISO
   $NEWVER -i$TMPISO --debug --erase 1000-1049 >>$LOGFILE 2>&1
   $NEWVER -i$TMPISO --debug --erase 11230 >>$LOGFILE 2>&1
   $NEWVER -i$TMPISO --debug --erase 12450-12457 >>$LOGFILE 2>&1
   $NEWVER -i$TMPISO --debug --byteset 13444,0,154 >>$LOGFILE 2>&1

  run_regtest defective_image_no_ecc "-t" $TMPISO $ISODIR/no.ecc
fi

# Test with good image and ecc file, both not multiple of 2048
if try "image with 56 extra bytes" plus56_bytes; then
  run_regtest plus56_bytes "-t" $ISO_PLUS56 $ECC_PLUS56
fi

# Test with good image not multiple of 2048, no ecc file
if try "image with 56 extra bytes, no ecc" image_plus56_bytes; then
  run_regtest image_plus56_bytes "-t" $ISO_PLUS56 $ISODIR/no.ecc
fi

# Test with no image, ecc for image not multiple of 2048 
if try "only ecc for image with 56 extra bytes" ecc_plus56_bytes; then
  run_regtest ecc_plus56_bytes "-t" $ISODIR/no.iso $ECC_PLUS56
fi

# Test with normal image, ecc for image not multiple of 2048 
if try "normal image, ecc file plus 56 bytes" normal_image_ecc_plus56b; then
  run_regtest normal_image_ecc_plus56b "-t" $MASTERISO $ECC_PLUS56
fi

# Test with image not multiple of 2048, normal ecc file
if try "image not multiple of 2048, normal ecc file" image_plus56b_normal_ecc; then
  run_regtest image_plus56b_normal_ecc "-t" $ISO_PLUS56 $MASTERECC
fi

# Test with image a few bytes shorter than ecc
if try "image a few bytes shorter then ecc" image_few_bytes_shorter; then

  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=55 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest image_few_bytes_shorter "-t" $TMPISO $ECC_PLUS56
fi

# Test with image a few bytes longer than ecc
if try "image a few bytes longer then ecc" image_few_bytes_longer; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=57 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest image_few_bytes_longer "-t" $TMPISO $ECC_PLUS56
fi

# Image is a few bytes shorter (original multiple of 2048)
if try "image a few bytes truncated" truncated_by_bytes; then
  dd if=$MASTERISO of=$TMPISO count=1 bs=$((2048*ISOSIZE-7)) >>$LOGFILE 2>&1

  run_regtest truncated_by_bytes "-t" $TMPISO $MASTERECC
fi

# Image is truncated by 5 sectors
if try "truncated image" truncated; then
  cp $MASTERISO $TMPISO
  NEWSIZE=$((ISOSIZE-5))
  $NEWVER -i$TMPISO --debug --truncate=$NEWSIZE >>$LOGFILE 2>&1

  run_regtest truncated "-t" $TMPISO $MASTERECC
fi

# Image contains 1 extra sector
if try "image with one extra sector" plus1; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=2048 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest plus1 "-t" $TMPISO $MASTERECC
fi

# Image contains 17 extra sectors
if try "image with 17 extra sectors" plus17; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=17 bs=2048 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest plus17 "-t" $TMPISO $MASTERECC
fi

# Image contains 2 rows of missing sectors, a single one
# and a CRC error
if try "image with missing sectors and crc errors" defective_with_ecc; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --erase 1000-1049 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 11230 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 12450-12457 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --byteset 13444,0,154 >>$LOGFILE 2>&1

  run_regtest defective_with_ecc "-t" $TMPISO $MASTERECC
fi

# Image contains just missing blocks
if try "image with missing sectors" missing_sectors_with_ecc; then

  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --erase 1000-1049 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 11230 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 12450-12457 >>$LOGFILE 2>&1
  
  run_regtest missing_sectors_with_ecc "-t" $TMPISO $MASTERECC
fi

# Image contains just CRC errors
if try "image with crc errors" crc_errors_with_ecc; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --byteset 13444,0,154 >>$LOGFILE 2>&1

  run_regtest crc_errors_with_ecc "-t" $TMPISO $MASTERECC
fi

# CRC error in fingerprint sector
if try "crc in fingerprint sector" crc_in_fingerprint; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --byteset 16,201,55 >>$LOGFILE 2>&1

  run_regtest crc_in_fingerprint "-t" $TMPISO $MASTERECC
fi

# fingerprint sector unreadable
if try "missing fingerprint sector" missing_fingerprint; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --erase 16 >>$LOGFILE 2>&1

  run_regtest missing_fingerprint "-t" $TMPISO $MASTERECC
fi

# Ecc header is missing
if try "Ecc header is missing" missing_ecc_header; then
  cp $MASTERECC $TMPECC
  $NEWVER --debug -i $TMPECC --erase 0 >>$LOGFILE 2>&1

  run_regtest missing_ecc_header "-t" $MASTERISO $TMPECC
fi

# Ecc header has checksum error

if try "checksum error in Ecc header" ecc_header_crc_error; then
  cp $MASTERECC $TMPECC
  $NEWVER --debug -i $TMPECC --byteset 0,22,107 >>$LOGFILE 2>&1

  run_regtest ecc_header_crc_error "-t" $MASTERISO $TMPECC
fi

# Test image containing several uncorrectable dead sector markers
# (sector displacement)

if try "image with uncorrectable dead sector markers" uncorrectable_dsm_in_image; then

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,353,49 >>$LOGFILE 2>&1 // displaced from sector 3130
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,353,53 >>$LOGFILE 2>&1 // displaced from sector 4500
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,353,53 >>$LOGFILE 2>&1 // displaced from sector 4511

  run_regtest uncorrectable_dsm_in_image  "-t" $TMPISO $MASTERECC
fi

# Test image containing several uncorrectable dead sector markers, verbose output

if try "image with uncorrectable dead sector markers, verbose output" uncorrectable_dsm_in_image_verbose; then

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,353,49 >>$LOGFILE 2>&1 // displaced from sector 3130
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,353,53 >>$LOGFILE 2>&1 // displaced from sector 4500
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,353,53 >>$LOGFILE 2>&1 // displaced from sector 4511

  run_regtest uncorrectable_dsm_in_image_verbose  "-t -v" $TMPISO $MASTERECC
fi

# Testimage containing several uncorrectable dead sector markers
# (non matching fingerprint)

if try "image with uncorrectable dead sector markers (2)" uncorrectable_dsm_in_image2; then

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,416,55 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 3030,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 4400,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4400,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 4411,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4411,557,50 >>$LOGFILE 2>&1 // changed label

  run_regtest uncorrectable_dsm_in_image2 "-t" $TMPISO $MASTERECC
fi

# Test image containing several uncorrectable dead sector markers, verbose
# (non matching fingerprint)

if try "image with uncorrectable dead sector markers (2), verbose output" uncorrectable_dsm_in_image2_verbose; then

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,416,55 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 3030,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 4400,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4400,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 4411,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4411,557,50 >>$LOGFILE 2>&1 // changed label

  run_regtest uncorrectable_dsm_in_image2_verbose "-t -v" $TMPISO $MASTERECC
fi

### Creation tests

echo "# Creation tests"

# Create ecc file
if try "ecc file creation" ecc_create; then

  extra_args="--debug --set-version $SETVERSION"
  run_regtest ecc_create "-c $REDUNDANCY" $MASTERISO $TMPECC
fi

# Create with missing image
if try "ecc creating with missing image" ecc_missing_image; then
  NO_FILE=$ISODIR/none.iso

  run_regtest ecc_missing_image "-c $REDUNDANCY" $NO_FILE $TMPECC
fi

# Create with no read permission on image
if try "ecc creating with no read permission" ecc_no_read_perm; then
  cp $MASTERISO $TMPISO
  chmod 000 $TMPISO

  run_regtest ecc_no_read_perm "-c $REDUNDANCY" $TMPISO $TMPECC
  rm -f $TMPISO
fi

# Create with no write permission on ecc file
# Should not do any harm at all: Ecc file will
# be recreated with write permissions
if try "ecc creating with no write permission" ecc_no_write_perm; then
  touch $TMPECC
  chmod 400 $TMPECC

  extra_args="--debug --set-version $SETVERSION"
  run_regtest ecc_no_write_perm "-c $REDUNDANCY" $MASTERISO $TMPECC
fi

# Create with image size not being a multiple of 2048

if try "ecc file creation with image not multiple of 2048" ecc_create_plus56; then

  extra_args="--debug --set-version $SETVERSION"
  run_regtest ecc_create_plus56 "-c $REDUNDANCY" $ISO_PLUS56 $TMPECC
fi

# Create test image with unreadable sectors 
if try "ecc creating with unreadable sectors" ecc_missing_sectors; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --erase 1000-1049 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 11230 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 12450-12457 >>$LOGFILE 2>&1

  run_regtest ecc_missing_sectors "-c $REDUNDANCY" $TMPISO $TMPECC
fi

# Read image and create ecc in the same program call.
# Tests whether CRC and ECC information is handed over correctly.
# NOTE: cache handling is currently disabled and will be fixed in 0.79.6!

if try "read image and create ecc in one call" ecc_create_after_read; then
  cp $MASTERISO $SIMISO

  rm -f $TMPISO $TMPECC
  replace_config read-and-create 1
  extra_args="--debug --set-version $SETVERSION --sim-cd=$SIMISO  --fixed-speed-values"
  run_regtest ecc_create_after_read "-r -c $REDUNDANCY --spinup-delay=0" $TMPISO $TMPECC
fi

# Read image with ecc file and create new (other) ecc in the same program call.
# Tests whether CRC and ECC information is handed over correctly.
# NOTE: cache handling is currently disabled and will be fixed in 0.79.6!

if try "read image with ecc (RS01) and create new ecc" ecc_recreate_after_read_rs01; then
  cp $MASTERISO $SIMISO

  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e$TMPECC -c -n 8 >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --set-version $SETVERSION --sim-cd=$SIMISO  --fixed-speed-values"
  run_regtest ecc_recreate_after_read_rs01 "-r -c $REDUNDANCY --spinup-delay=0" $TMPISO $TMPECC
fi

# Read image with ecc file and create new (other) ecc in the same program call.
# Tests whether CRC and ECC information is handed over correctly.
# Note: RS02 information will not be removed from the image. This ist intentional behaviour.
# NOTE: cache handling is currently disabled and will be fixed in 0.79.6!

if try "read image with ecc (RS02) and create additional ecc file" ecc_recreate_after_read_rs02; then
  cp $MASTERISO $SIMISO

  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -c -mRS02 -n$((ISOSIZE+6000)) >>$LOGFILE 2>&1

  rm -f $TMPISO $TMPECC
  extra_args="--debug --set-version $SETVERSION --sim-cd=$SIMISO  --fixed-speed-values"
  run_regtest ecc_recreate_after_read_rs02 "-r -c $REDUNDANCY --spinup-delay=0" $TMPISO $TMPECC
fi

# Read image with ecc file and create new (other) ecc in the same program call.
# Tests whether CRC and ECC information is handed over correctly.
# Note: RS03 information will not be removed from the image. This ist intentional behaviour.
# NOTE: cache handling is currently disabled and will be fixed in 0.79.6!

if try "read image with ecc (RS03i) and create additional ecc file" ecc_recreate_after_read_rs03i; then
  cp $MASTERISO $SIMISO

  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -c -mRS03 -n$((ISOSIZE+6000)) >>$LOGFILE 2>&1

  rm -f $TMPISO $TMPECC
  extra_args="--debug --set-version $SETVERSION --sim-cd=$SIMISO  --fixed-speed-values"
  run_regtest ecc_recreate_after_read_rs03i "-r -c $REDUNDANCY --spinup-delay=0" $TMPISO $TMPECC
fi

# Read image with ecc file and create new (other) ecc in the same program call.
# Tests whether CRC and ECC information is handed over correctly.
# NOTE: cache handling is currently disabled and will be fixed in 0.79.6!

if try "read image with ecc (RS03f) and create new ecc" ecc_recreate_after_read_rs03f; then
  cp $MASTERISO $SIMISO

  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e$TMPECC -c -n 8 -mRS03 -o file >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --set-version $SETVERSION --sim-cd=$SIMISO  --fixed-speed-values"
  run_regtest ecc_recreate_after_read_rs03f "-r -c $REDUNDANCY --spinup-delay=0" $TMPISO $TMPECC
fi

# Complete image in a reading pass, then create an ecc file for it.
# Cached checksums must be discarded before creating the ecc.

if try "create ecc after completing partial image" ecc_create_after_partial_read; then
   cp $MASTERISO $SIMISO
   cp $MASTERISO $TMPISO

  $NEWVER --debug -i$TMPISO --erase 1000-1500 >>$LOGFILE 2>&1

  rm -f $TMPECC
  extra_args="--debug --set-version $SETVERSION --sim-cd=$SIMISO  --fixed-speed-values"
  run_regtest ecc_create_after_partial_read "-r -c $REDUNDANCY --spinup-delay=0" $TMPISO $TMPECC
fi

### Fixing tests

echo "# Repair tests"

# Fix good image

if try "fixing good image" fix_good; then

  cp $MASTERISO $TMPISO
  run_regtest fix_good "-f" $TMPISO $MASTERECC
fi

# Fix image without read permission

if try "fixing image without read permission" fix_no_read_perm; then

  cp $MASTERISO $TMPISO
  chmod 000 $TMPISO

  run_regtest fix_no_read_perm "-f" $TMPISO $MASTERECC
  rm -f $TMPISO
fi

# Fix image without read permission for ecc

if try "fixing image without read permission for ecc" fix_no_read_perm_ecc; then

  cp $MASTERISO $TMPISO
  cp $MASTERECC $TMPECC
  chmod 000 $TMPECC

  run_regtest fix_no_read_perm_ecc "-f" $TMPISO $TMPECC
  rm -f $TMPECC
fi

# Fix good image not multiple of 2048

if try "fixing good image not multiple of 2048" fix_good_plus56; then
  cp $ISO_PLUS56 $TMPISO
  
  run_regtest fix_plus56_bytes "-f" $TMPISO $ECC_PLUS56
fi

# Fix image without write permission

if try "fixing image without write permission" fix_no_write_perm; then

  cp $MASTERISO $TMPISO
  chmod 400 $TMPISO

  run_regtest fix_no_write_perm "-f" $TMPISO $MASTERECC
  rm -f $TMPISO
fi

# Fix image with missing sectors

if try "fixing image with missing sectors" fix_missing_sectors; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --erase 0 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 190 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 192 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 590-649 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 2000-2139 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase 2141-2176 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --erase $((ISOSIZE-1)) >>$LOGFILE 2>&1

  run_regtest fix_missing_sectors "-f" $TMPISO $MASTERECC

fi

# Fix image with CRC errors

if try "fixing image with crc errors" fix_crc_errors; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --byteset 0,1,1 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --byteset 190,200,143 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --byteset 1200,100,1 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --byteset 1201,100,1 >>$LOGFILE 2>&1
  $NEWVER -i$TMPISO --debug --byteset $((ISOSIZE-1)),500,91 >>$LOGFILE 2>&1

  run_regtest fix_crc_errors "-f" $TMPISO $MASTERECC
fi

# Fix image with additional sectors (TAO case)

if try "fixing image with one additional sector" fix_additional_sector; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=2048 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest fix_additional_sector "-f" $TMPISO $MASTERECC
fi

# Fix image with additional sectors (general case)

if try "fixing image with 17 additional sectors" fix_plus17; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=17 bs=2048 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest fix_plus17 "-f" $TMPISO $MASTERECC
fi

# Fix image with additional sectors (general case), with --truncate

if try "fixing image with 17 additional sectors with --truncate" fix_plus17_truncate; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=17 bs=2048 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest fix_plus17_truncate "-f --truncate" $TMPISO $MASTERECC
fi

# Fix image+56bytes 

if try "fixing image with CRC error in 56 additional bytes" fix_plus56; then
  cp $ISO_PLUS56 $TMPISO
  $NEWVER -i$TMPISO --debug --byteset 21000,28,90 >>$LOGFILE 2>&1
  run_regtest fix_plus56 "-f" $TMPISO $ECC_PLUS56
fi

# Fix image+56bytes+more bytes

if try "fixing image with CRC error in 56 additional bytes + few bytes more" fix_plus56_plus17; then
  cp $ISO_PLUS56 $TMPISO
  echo "0123456789abcdef" >>$TMPISO
  $NEWVER -i$TMPISO --debug --byteset 21000,55,90 >>$LOGFILE 2>&1

  run_regtest fix_plus56_plus17 "-f --truncate" $TMPISO $ECC_PLUS56
fi

# Fix image+56bytes+1 sector 

if try "fixing image with CRC error in 56 additional bytes + one sector more" fix_plus56_plus1s; then
  cp $ISO_PLUS56 $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=2048 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  $NEWVER -i$TMPISO --debug --byteset 21000,55,90 >>$LOGFILE 2>&1

  run_regtest fix_plus56_plus1s "-f --truncate" $TMPISO $ECC_PLUS56
fi

# Fix image+56bytes+2 sectors 

if try "fixing image with CRC error in 56 additional bytes + two sectors more" fix_plus56_plus2s; then
  cp $ISO_PLUS56 $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=4096 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  $NEWVER -i$TMPISO --debug --byteset 21000,55,90 >>$LOGFILE 2>&1

  run_regtest fix_plus56_plus2s "-f --truncate" $TMPISO $ECC_PLUS56
fi

# Fix image+56bytes+more sectors 

if try "fixing image with CRC error in 56 additional bytes + more sectors" fix_plus56_plus17500; then
  cp $ISO_PLUS56 $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=17500 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  $NEWVER -i$TMPISO --debug --byteset 21000,55,90 >>$LOGFILE 2>&1

  run_regtest fix_plus56_plus17500 "-f --truncate" $TMPISO $ECC_PLUS56
fi

# Fix truncated image

if try "fixing truncated image" fix_truncated; then
  cp $MASTERISO $TMPISO
  $NEWVER -i$TMPISO --debug --truncate=20731 >>$LOGFILE 2>&1
  run_regtest fix_truncated "-f" $TMPISO $MASTERECC
fi

# Fix truncated image not a multiple of 2048

if try "fixing truncated image not a multiple of 2048" fix_plus56_truncated; then
  cp $ISO_PLUS56 $TMPISO
  $NEWVER -i$TMPISO --debug --truncate=20972 >>$LOGFILE 2>&1
  run_regtest fix_plus56_truncated "-f" $TMPISO $ECC_PLUS56
fi

# Fix truncated image not a multiple of 2048 and a few bytes shorter

if try "fixing image not a multiple of 2048 missing a few bytes" fix_plus56_little_truncated; then
  cp $MASTERISO $TMPISO
  dd if=/dev/zero of=/tmp/padding count=1 bs=50 >>$LOGFILE 2>&1
  cat /tmp/padding >>$TMPISO
  rm -f /tmp/padding

  run_regtest fix_plus56_little_truncated "-f" $TMPISO $ECC_PLUS56
fi

### Scanning tests

echo "# Scanning tests"

# Scan image without error correction data available

if try "scanning image, no ecc data" scan_no_ecc; then

  extra_args="--debug -d sim-cd --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest scan_no_ecc "--spinup-delay=0 -s" $ISODIR/no.iso $ISODIR/no.ecc
fi

# Scan image from non-existant device
# not applicable to GUI mode since drives are discovered differently there

if try "scanning image, device not existant" scan_no_device; then

  extra_args="--debug -d /dev/sdz --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest scan_no_device "--spinup-delay=0 -s" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan image from device with insufficient permissions
# not applicable to GUI mode since drives are discovered differently there

if try "scanning image, device access denied" scan_no_device_access; then

  touch $ISODIR/sdz
  chmod 000 $ISODIR/sdz
    
  run_regtest scan_no_device_access "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -d $ISODIR/sdz -s" $ISODIR/no.iso  $ISODIR/no.ecc
  rm -f $ISODIR/sdz
fi

# Scan image from defective media without error correction data available
# Will report more missing sectors than the original due to the 16 sector skip default

if try "scanning image, defective media, no ecc data" scan_defective_no_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 100-200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 766 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 2410 >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_defective_no_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan image from above test again, this time with a 1 sector skip size
# Will report an exact error count of the (damaged) original

if try "scanning image, defective media, no ecc data, reading w/ 1 sec step" scan_defective_no_ecc_again; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 100-200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 766 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 2410 >>$LOGFILE 2>&1

  replace_config jump 0
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_defective_no_ecc_again "--spinup-delay=0 -j 1 -s" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan image from defective media without error correction data available
# using a large sector skip of 256

if try "scanning image, defective media, large sector skip" scan_defective_large_skip; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 1600-1615 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 6400-10000 >>$LOGFILE 2>&1
  
  replace_config jump 256
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_defective_large_skip "--spinup-delay=0 -s -j 256" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan a new image, but only for a partial range.
# range 10000-15000 must be entered manually in the GUI;
# there is no way for pre-configuring it

if try "scanning new image with given range, no ecc data" scan_new_with_range_no_ecc; then

  cp $MASTERISO $SIMISO

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_new_with_range_no_ecc "--spinup-delay=0 -s10000-15000" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan a new image, but only for an invalid range.
# Makes no sense in GUI mode (invalid value can not be entered)

if try "scanning new image with invalid range, no ecc data" scan_new_with_invalid_range_no_ecc; then

  cp $MASTERISO $SIMISO

  run_regtest scan_new_with_invalid_range_no_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -s10000-55000" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan image with error correction data available

if try "scanning image, ecc data" scan_with_ecc; then

  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest scan_with_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan image with non existing error correction file given
# Please note that this fact will be silently ignored; e.g. the image
# will be scanned as if no ecc file was given at all.

if try "scanning image, ecc file does not exist" scan_with_non_existing_ecc; then

  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest scan_with_non_existing_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $ISODIR/no_ecc
fi

# Scan image with non accessible error correction file given
# Please note that this fact will be silently ignored; e.g. the image
# will be scanned as if no ecc file was given at all.

if try "scanning image, no permission to access ecc file" scan_with_no_permission_for_ecc; then
  cp $MASTERECC $TMPECC
  chmod 000 $TMPECC

  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest scan_with_no_permission_for_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $TMPECC
  rm -f $TMPECC
fi

# Scan image with error correction data available
# and CRC errors

if try "scanning image, crc errors, ecc data" scan_crc_errors_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --byteset 0,100,255 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 1,180,200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 7910,23,98 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 20999,55,123 >>$LOGFILE 2>&1
    
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_crc_errors_with_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan image with error correction data available
# which is a few sectors shorter than expected.

if try "scanning image, less sectors than expected, ecc data" scan_shorter_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --truncate=$((ISOSIZE-44)) >>$LOGFILE 2>&1

  replace_config ignore-iso-size 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_shorter_with_ecc "--ignore-iso-size --spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan image with error correction data available
# which is a few sectors longer than expected.

if try "scanning image, more sectors than expected, ecc data" scan_longer_with_ecc; then

  cp $MASTERISO $SIMISO
  for i in $(seq 22); do cat fixed-random-sequence >>$SIMISO; done
    
  replace_config ignore-iso-size 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_longer_with_ecc "--ignore-iso-size --spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan image with error correction data available
# simulating the multisession case with two additional defective sectors trailing the medium

if try "scanning image, tao tail case, ecc data" scan_tao_tail_with_ecc; then

  cp $MASTERISO $SIMISO
  cat fixed-random-sequence >>$SIMISO
  $NEWVER --debug -i$SIMISO --erase 21000-21001 >>$LOGFILE 2>&1
    
  replace_config ignore-iso-size 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_tao_tail_with_ecc "--ignore-iso-size --spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan image with error correction data available
# with two defective sectors at the end and the --dao option

if try "scanning image, tao tail case and --dao, ecc data" scan_no_tao_tail_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20998-20999 >>$LOGFILE 2>&1
    
  replace_config dao 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_no_tao_tail_with_ecc "--dao --spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan image with error correction data available
# and more than two defective sectors at the end

if try "scanning image, more than 2 sectors missing at end, ecc data" scan_more_missing_at_end_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20954-20999 >>$LOGFILE 2>&1
    
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_more_missing_at_end_with_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $MASTERECC
fi

# Scan an augmented image for which an ecc file is also available.
# In that case, the ecc file gets precedence over the embedded ecc.
# To make sure the RS01 data is used we introduce a CRC error in the RS02
# ecc area - this can only be detected by the "outer" RS01 CRC.

if try "scanning image with RS02 data and a RS01 ecc file" scan_with_double_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -mRS02 -n$((ISOSIZE+5000)) -c >>$LOGFILE 2>&1
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e $TMPECC -c $REDUNDANCY >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 25910,100,200 >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_with_double_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $TMPECC
fi

# Scan an image for which ecc information is available,
# but requiring a newer dvdisaster version.

if try "scanning image ecc file requiring a newer dvdisaster version" scan_with_incompatible_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e $TMPECC -c $REDUNDANCY >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,88,220 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,89,65 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,90,15 >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_with_incompatible_ecc "--spinup-delay=0 -s" $ISODIR/no.iso  $TMPECC
fi

# Scan an image with a simulated hardware failure and 
# --ignore-fatal-sense not set.

if try "scanning image with simulated hardware failure" scan_with_hardware_failure; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "5000:hardware failure" >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_with_hardware_failure "--spinup-delay=0 -s" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan an image with a simulated hardware failure and 
# --ignore-fatal-sense being set.

if try "scanning image, ignoring simulated hardware failure" scan_with_ignored_hardware_failure; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "5000:hardware failure" >>$LOGFILE 2>&1

  replace_config ignore-fatal-sense 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_with_ignored_hardware_failure "--spinup-delay=0 -s --ignore-fatal-sense" $ISODIR/no.iso  $ISODIR/no.ecc
fi

# Scan medium containing dead sector markers

if try "scanning medium containing dead sector markers" scan_medium_with_dsm; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "4999:pass as dead sector marker" >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest scan_medium_with_dsm "--spinup-delay=0 -s" $ISODIR/no.iso  $ISODIR/no.ecc
fi

### Reading tests (linear)

echo "# Reading tests (linear)"

# Read image without error correction data available

if try "reading image, no ecc data" read_no_ecc; then

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest read_no_ecc "--spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Read into existing and complete image file

if try "reading good image in good file" read_no_ecc_good_file; then
  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_no_ecc_good_file "--spinup-delay=0 -r" $TMPISO
fi

# Read image from non-existant device
# Makes no sense in GUI mode.

if try "reading image, device not existant" read_no_device; then

  rm -f $TMPISO
  run_regtest read_no_device "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -d /dev/sdz -r" $TMPISO  $ISODIR/no.ecc
fi

# Read image from device with insufficient permissions
# not applicable to GUI mode since drives are discovered differently there

if try "reading image, device access denied" read_no_device_access; then

  touch $ISODIR/sdz
  chmod 000 $ISODIR/sdz
    
  rm -f $TMPISO
  run_regtest read_no_device_access "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -d $ISODIR/sdz -r" $TMPISO  $ISODIR/no.ecc
  rm -f $ISODIR/sdz
fi

# Read image from defective media without error correction data available
# Will have more missing sectors than the original due to the 16 sector skip default

if try "reading image, defective media, no ecc data" read_defective_no_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 100-200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 766 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 2410 >>$LOGFILE 2>&1
  
  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_defective_no_ecc "--spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Read image from above test again, this time with a 1 sector skip size
# Will provide an exact copy of the (damaged) original

if try "reading image, defective media, no ecc data, completing w/ 1 sec step" read_defective_no_ecc_again; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 100-200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 766 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 2410 >>$LOGFILE 2>&1

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 96-207 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --erase 752-767 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --erase 2400-2415 >>$LOGFILE 2>&1

  replace_config jump 0
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_defective_no_ecc_again "--spinup-delay=0 -j 1 -r" $TMPISO  $ISODIR/no.ecc
fi

# Read image from defective media without error correction data available
# using a large sector skip of 256

if try "reading image, defective media, large sector skip" read_defective_large_skip; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 1600-1615 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 6400-10000 >>$LOGFILE 2>&1
  
  rm -f $TMPISO
  replace_config jump 256
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_defective_large_skip "--spinup-delay=0 -r -j 256" $TMPISO  $ISODIR/no.ecc
fi

# Complete a truncated image

if try "completing truncated image with no ecc data available" read_truncated_no_ecc; then

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=$((ISOSIZE-560)) >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_truncated_no_ecc "--spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Complete a truncated image from simulated defective media

if try "completing truncated image, defective media, no ecc data" read_truncated_no_ecc_again; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20800-20875 >>$LOGFILE 2>&1

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=$((ISOSIZE-560)) >>$LOGFILE 2>&1

  replace_config jump 0
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_truncated_no_ecc_again "--spinup-delay=0 -j 1 -r" $TMPISO  $ISODIR/no.ecc
fi

# Complete a truncated image from simulated defective media

if try "completing truncated image, defective media, multipass, no ecc data" read_multipass_no_ecc_again; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20800-20875 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 3000-3045 >>$LOGFILE 2>&1

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=$((ISOSIZE-560)) >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --erase 2980-3120 >>$LOGFILE 2>&1

  replace_config jump 0
  replace_config read-medium 3
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_multipass_no_ecc_again "--read-medium=3 --spinup-delay=0 -j 1 -r" $TMPISO  $ISODIR/no.ecc
fi

# Complete a partially read image, but continue with gap between the last
# read and the next sector.

if try "completing truncated image with reading gap, no ecc data" read_with_gap_no_ecc; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=10000 >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_with_gap_no_ecc "--spinup-delay=0 -r15000-end" $TMPISO  $ISODIR/no.ecc
fi

# Read a new image, but only for a partial range.

if try "reading new image with given range, no ecc data" read_new_with_range_no_ecc; then

  cp $MASTERISO $SIMISO
  rm -f $TMPISO

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_new_with_range_no_ecc "--spinup-delay=0 -r10000-15000" $TMPISO  $ISODIR/no.ecc
fi

# Read a new image, but only for an invalid range.
# not possible in GUI mode

if try "reading new image with invalid range, no ecc data" read_new_with_invalid_range_no_ecc; then

  cp $MASTERISO $SIMISO
  rm -f $TMPISO

  run_regtest read_new_with_invalid_range_no_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r10000-55000" $TMPISO  $ISODIR/no.ecc
fi

# Read a new image, containing two missing sectors
# but not at the end, so no tao tail case

if try "reading new image with two missing sectors, no ecc data" read_two_missing_secs_no_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 8020 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase $((ISOSIZE-1)) >>$LOGFILE 2>&1

  rm -f $TMPISO

  replace_config jump 0
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_two_missing_secs_no_ecc "--spinup-delay=0 -r -j 1" $TMPISO  $ISODIR/no.ecc
fi

# Read image with error correction data available

if try "reading image, ecc data" read_with_ecc; then

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest read_with_ecc "--spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read with ecc into existing and complete image file

if try "reading image, ecc data, good file" read_with_ecc_good_file; then
  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_with_ecc_good_file "--spinup-delay=0 -r" $TMPISO $MASTERECC
fi

# Read image with non existing error correction file given
# Please note that this fact will be silently ignored; e.g. the image
# will be read as if no ecc file was given at all.

if try "reading image, ecc file does not exist" read_with_non_existing_ecc; then

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest read_with_non_existing_ecc "--spinup-delay=0 -r" $TMPISO  $ISODIR/no_ecc
fi

# Read image with non accessible error correction file given
# Please note that this fact will be silently ignored; e.g. the image
# will be read as if no ecc file was given at all.

if try "reading image, no permission to access ecc file" read_with_no_permission_for_ecc; then
  cp $MASTERECC $TMPECC
  chmod 000 $TMPECC

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$MASTERISO --fixed-speed-values"
  run_regtest read_with_no_permission_for_ecc "--spinup-delay=0 -r" $TMPISO  $TMPECC
  rm -f $TMPECC
fi

# Read image with error correction data available
# and CRC errors

if try "reading image, crc errors, ecc data" read_crc_errors_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --byteset 0,100,255 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 1,180,200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 7910,23,98 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 20999,55,123 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_crc_errors_with_ecc "--spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# which is a few sectors shorter than expected.

if try "reading image, less sectors than expected, ecc data" read_shorter_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --truncate=$((ISOSIZE-44)) >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  replace_config ignore-iso-size 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_shorter_with_ecc "--ignore-iso-size --spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# from a medium which is a few sectors longer than expected.

if try "reading image, more sectors than expected, ecc data" read_longer_with_ecc; then

  cp $MASTERISO $SIMISO
  for i in $(seq 22); do cat fixed-random-sequence >>$SIMISO; done
    
  rm -f $TMPISO
  replace_config ignore-iso-size 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_longer_with_ecc "--ignore-iso-size --spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# simulating the multisession case with two additional defective sectors trailing the medium

if try "reading image, tao tail case, ecc data" read_tao_tail_with_ecc; then

  cp $MASTERISO $SIMISO
  cat fixed-random-sequence >>$SIMISO
  $NEWVER --debug -i$SIMISO --erase 21000-21001 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  replace_config ignore-iso-size 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_tao_tail_with_ecc "--ignore-iso-size --spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# with two defective sectors at the end and the --dao option

if try "reading image, tao tail case and --dao, ecc data" read_no_tao_tail_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20998-20999 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  replace_config dao 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_no_tao_tail_with_ecc "--dao --spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# and more than two defective sectors at the end

if try "reading image, more than 2 sectors missing at end, ecc data" read_more_missing_at_end_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20954-20999 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_more_missing_at_end_with_ecc "--spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Re-read image with error correction data available
# and wrong fingerprint in existing image

if try "re-reading image, wrong fingerprint, ecc data" read_wrong_fp_with_ecc; then

  cp $MASTERISO $SIMISO

  dd if=$MASTERISO of=$TMPISO bs=2048 count=800 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 16,100,200 >>$LOGFILE 2>&1
    
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_wrong_fp_with_ecc "--spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read an augmented image for which an ecc file is also available.
# In that case, the ecc file gets precedence over the embedded ecc.
# To make sure the RS01 data is used we introduce a CRC error in the RS02
# ecc area - this can only be detected by the "outer" RS01 CRC.

if try "reading image with RS02 data and a RS01 ecc file" read_with_double_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -mRS02 -n$((ISOSIZE+5000)) -c >>$LOGFILE 2>&1
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e $TMPECC -c $REDUNDANCY >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 25910,100,200 >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_with_double_ecc "--spinup-delay=0 -r" $TMPISO  $TMPECC
fi

# Read an image for which ecc information is available,
# but requiring a newer dvdisaster version.

if try "reading image ecc file requiring a newer dvdisaster version" read_with_incompatible_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e $TMPECC -c $REDUNDANCY >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,88,220 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,89,65 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,90,15 >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_with_incompatible_ecc "--spinup-delay=0 -r" $TMPISO  $TMPECC
fi

# Read an image with a simulated hardware failure and 
# --ignore-fatal-sense not set.

if try "reading image with simulated hardware failure" read_with_hardware_failure; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "5000:hardware failure" >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_with_hardware_failure "--spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Read an image with a simulated hardware failure and 
# --ignore-fatal-sense being set.

if try "reading image, ignoring simulated hardware failure" read_with_ignored_hardware_failure; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "5000:hardware failure" >>$LOGFILE 2>&1

  rm -f $TMPISO
  replace_config ignore-fatal-sense 1
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_with_ignored_hardware_failure "--spinup-delay=0 -r --ignore-fatal-sense" $TMPISO  $ISODIR/no.ecc
fi

# Read medium in several passes; some sectors become readable in the third pass.

if try "reading medium in 3 passes; 3rd pass recovers some" read_multipass_partial_success; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 15800-16199 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase "15900-16099:readable in pass 3" >>$LOGFILE 2>&1

  rm -f $TMPISO
  replace_config read-medium 3
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_multipass_partial_success "--read-medium=3 --spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Do a second successful read attempt at an incomplete image;
# see whether correct results are reported when ecc data is present
# since CRC caching is a bit complicated in this case.

if try "re-reading medium with ecc, successfull" read_second_pass_with_ecc_success; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 15800-16199 >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_second_pass_with_ecc_success "--spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Do a second read attempt at an incomplete image;
# see whether CRC errors are still discovered since CRC caching is a bit
# complicated in this case.

if try "re-reading medium with CRC error" read_second_pass_with_crc_error; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --byteset 15830,8,3 >>$LOGFILE 2>&1
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 15800-16199 >>$LOGFILE 2>&1

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_second_pass_with_crc_error "--spinup-delay=0 -r" $TMPISO  $MASTERECC
fi

# Read medium containing several dead sector markers

if try "reading medium containing dead sector markers" read_medium_with_dsm; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "4999:pass as dead sector marker" >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase "5005:pass as dead sector marker" >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase "5007:pass as dead sector marker" >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_medium_with_dsm "--spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Read medium containing several dead sector markers, verbose output
# not applicable in GUI mode

if try "reading medium containing dead sector markers, verbose output" read_medium_with_dsm_verbose; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "4999:pass as dead sector marker" >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase "5005:pass as dead sector marker" >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase "5007:pass as dead sector marker" >>$LOGFILE 2>&1

  rm -f $TMPISO
  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_medium_with_dsm_verbose "--spinup-delay=0 -r -v" $TMPISO  $ISODIR/no.ecc
fi

# Complete medium for image containing several uncorrectable dead sector markers
# (sector displacement)

if try "completing image with uncorrectable dead sector markers" read_medium_with_dsm_in_image; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,353,49 >>$LOGFILE 2>&1 // displaced from sector 3130
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,353,53 >>$LOGFILE 2>&1 // displaced from sector 4500
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,353,53 >>$LOGFILE 2>&1 // displaced from sector 4511

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_medium_with_dsm_in_image "--spinup-delay=0 -r" $TMPISO  $ISODIR/no.ecc
fi

# Complete medium for image containing several uncorrectable dead sector markers, verbose output

if try "completing image with uncorrectable dead sector markers, verbose output" read_medium_with_dsm_in_image_verbose; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,353,49 >>$LOGFILE 2>&1 // displaced from sector 3130
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,353,53 >>$LOGFILE 2>&1 // displaced from sector 4500
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,353,53 >>$LOGFILE 2>&1 // displaced from sector 4511

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_medium_with_dsm_in_image_verbose "--spinup-delay=0 -r -v" $TMPISO  $ISODIR/no.ecc
fi

# Complete medium for image containing several uncorrectable dead sector markers
# (non matching fingerprint)

if try "completing image with uncorrectable dead sector markers (2)" read_medium_with_dsm_in_image2; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,416,55 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 3030,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4400,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4411,557,50 >>$LOGFILE 2>&1 // changed label

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_medium_with_dsm_in_image2 "--spinup-delay=0 -r " $TMPISO  $ISODIR/no.ecc
fi

# Complete medium for image containing several uncorrectable dead sector markers, verbose
# (non matching fingerprint)

if try "completing image with uncorrectable dead sector markers (2), verbose output" read_medium_with_dsm_in_image2_verbose; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --erase 3030 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 3030,416,55 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 3030,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4400 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4400,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4400,557,50 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --erase 4411 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 4411,416,53 >>$LOGFILE 2>&1 // wrong fingerprint
  $NEWVER --debug -i$TMPISO --byteset 3030,556,32 >>$LOGFILE 2>&1 // changed label
  $NEWVER --debug -i$TMPISO --byteset 4411,557,50 >>$LOGFILE 2>&1 // changed label

  extra_args="--debug --sim-cd=$SIMISO --fixed-speed-values"
  run_regtest read_medium_with_dsm_in_image2_verbose "--spinup-delay=0 -r -v" $TMPISO  $ISODIR/no.ecc
fi

# Mechanismus um C2-Errors zu testen?

### Reading tests (adaptive)

echo "# Reading tests (adaptive)"

echo "Currently not enabled!"
exit 0

# Read good image with error correction data available

if try "reading good image" adaptive_good; then

  rm -f $TMPISO
  run_regtest adaptive_good "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Read image without error correction data available

if try "reading image, no ecc data" adaptive_no_ecc; then

  rm -f $TMPISO
  run_regtest adaptive_no_ecc "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Read image from non-existant device

if try "reading image, device not existant" adaptive_no_device; then

  rm -f $TMPISO
  run_regtest adaptive_no_device "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -d /dev/sdz -r --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Read image from device with insufficient permissions

if try "reading image, device access denied" adaptive_no_device_access; then

  touch $ISODIR/sdz
  chmod 000 $ISODIR/sdz
    
  rm -f $TMPISO
  run_regtest adaptive_no_device_access "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -d $ISODIR/sdz -r --adaptive-read" $TMPISO  $ISODIR/no.ecc
  rm -f $ISODIR/sdz
fi

# Read image from defective media without error correction data available
# Will have more missing sectors than the original due to the divide and conquer 
# cut-off between intervals: e.g the following sectors will be missing:  
# 100- 202; 766-786; 2410-2428
# Please do also note that the termination criterion is somehow misleading
# as it applies to any intervals resulting from a split.
# If we are supposed to terminate when no intervals >= n=16 sectors are
# available, we are actually terminating when the first interval with
# less than 32 sectors is being split (so we are effectively terminating below  2n).
# The example run terminates as soon as the following intervals are left over:
# 20 [    101..    120]
# 20 [    142..    161]
# 20 [    183..    202]
# 20 [    767..    786]
# 19 [    122..    140]
# 19 [    163..    181]
# 18 [   2411..   2428]
#
# Having said that, the results from the following run have been manually
# checked to match what the programmer intended ;-)

if try "reading image, defective media, no ecc data" adaptive_defective_no_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 100-200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 766 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 2410 >>$LOGFILE 2>&1
  
  rm -f $TMPISO
  run_regtest adaptive_defective_no_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read -v" $TMPISO  $ISODIR/no.ecc
fi

# Read image from defective media without error correction data available
# using a large sector skip of 256

if try "reading image, defective media, large sector skip" adaptive_defective_large_skip; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 1600-1615 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --erase 6400-10000 >>$LOGFILE 2>&1
  
  rm -f $TMPISO
  run_regtest adaptive_defective_large_skip "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r -j 256 --adaptive-read -v" $TMPISO  $ISODIR/no.ecc
fi

# Complete a truncated image

if try "completing truncated image with no ecc data available" adaptive_truncated_no_ecc; then

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=$((ISOSIZE-560)) >>$LOGFILE 2>&1

  run_regtest adaptive_truncated_no_ecc "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Complete a truncated image from simulated defective media
# Leaves 100 unread sectors.

if try "completing truncated image, defective media, no ecc data" adaptive_truncated_no_ecc_again; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20800-20875 >>$LOGFILE 2>&1

  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=$((ISOSIZE-560)) >>$LOGFILE 2>&1

  run_regtest adaptive_truncated_no_ecc_again "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r -v --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Complete a partially read image, but continue with gap between the last
# read and the next sector.
# (not a recommended setup for adaptive reading, but technically allowed)

if try "completing truncated image with reading gap, no ecc data" adaptive_with_gap_no_ecc; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=10000 >>$LOGFILE 2>&1

  run_regtest adaptive_with_gap_no_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r15000-end --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Complete a partially read image, but continue with gap between the last
# read and the next sector.
# (not a recommended setup for adaptive reading, but technically allowed)
# specified area ends before actual medium size

if try "completing truncated image with reading gap, no ecc data(2)" adaptive_with_gap_no_ecc2; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=10000 >>$LOGFILE 2>&1

  run_regtest adaptive_with_gap_no_ecc2 "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r15000-19999 --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Complete a partially read image, but continue with gap between the last
# read and the next sector.
# (not a recommended setup for adaptive reading, but technically allowed)
# specified area overlaps already read part

if try "completing truncated image with reading gap, no ecc data(3)" adaptive_with_gap_no_ecc3; then

  cp $MASTERISO $SIMISO
  cp $MASTERISO $TMPISO
  $NEWVER --debug -i$TMPISO --truncate=10000 >>$LOGFILE 2>&1

  run_regtest adaptive_with_gap_no_ecc3 "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r9000-15000 --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Read a new image, but only for a partial range.

if try "reading new image with given range, no ecc data" adaptive_new_with_range_no_ecc; then

  cp $MASTERISO $SIMISO
  rm -f $TMPISO

  run_regtest adaptive_new_with_range_no_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r10000-15000 --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Read a new image, but only for an invalid range.

if try "reading new image with invalid range, no ecc data" adaptive_new_with_invalid_range_no_ecc; then

  cp $MASTERISO $SIMISO
  rm -f $TMPISO

  run_regtest adaptive_new_with_invalid_range_no_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r10000-55000 --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi

# Read image with non accessible error correction file given
# Please note that this fact will be silently ignored; e.g. the image
# will be read as if no ecc file was given at all.

if try "reading image, no permission to access ecc file" adaptive_with_no_permission_for_ecc; then
  cp $MASTERECC $TMPECC
  chmod 000 $TMPECC

  rm -f $TMPISO
  run_regtest adaptive_with_no_permission_for_ecc "--debug --sim-cd=$MASTERISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $TMPECC
  rm -f $TMPECC
fi

# Read image with error correction data available
# and CRC errors
# Adaptive reading will create a new interval on CRC errors,
# but mark them as erasure as expected. The resulting image
# is successfully corrected with 32 erasures/block.

if try "reading image, crc errors, ecc data" adaptive_crc_errors_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --byteset 0,100,255 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 1,180,200 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 7910,23,98 >>$LOGFILE 2>&1
  $NEWVER --debug -i$SIMISO --byteset 20999,55,123 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  run_regtest adaptive_crc_errors_with_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Read image with error correction data available.
# The image is a few sectors shorter than expected.

if try "reading image, less sectors than expected, ecc data" adaptive_shorter_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --truncate=$((ISOSIZE-44)) >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  run_regtest adaptive_shorter_with_ecc "--debug --ignore-iso-size --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# from a medium which is a few sectors longer than expected.

if try "reading image, more sectors than expected, ecc data" adaptive_longer_with_ecc; then

  cp $MASTERISO $SIMISO
  for i in $(seq 22); do cat fixed-random-sequence >>$SIMISO; done
    
  rm -f $TMPISO
  run_regtest adaptive_longer_with_ecc "--debug --ignore-iso-size --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# simulating the multisession case with two additional defective sectors trailing the medium
# Both this case and the next one do not really make sense for the adaptive
# reading case as the right behaviour is simply caused by using the respective
# values from the ecc data.

if try "reading image, tao tail case, ecc data" adaptive_tao_tail_with_ecc; then

  cp $MASTERISO $SIMISO
  cat fixed-random-sequence >>$SIMISO
  $NEWVER --debug -i$SIMISO --erase 21000-21001 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  run_regtest adaptive_tao_tail_with_ecc "--debug --ignore-iso-size --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Read image with error correction data available
# with two defective sectors at the end and the --dao option

if try "reading image, tao tail case and --dao, ecc data" adaptive_no_tao_tail_with_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase 20998-20999 >>$LOGFILE 2>&1
    
  rm -f $TMPISO
  run_regtest adaptive_no_tao_tail_with_ecc "--debug --dao --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Re-read image with error correction data available
# and wrong fingerprint in existing image

if try "re-reading image, wrong fingerprint, ecc data" adaptive_wrong_fp_with_ecc; then

  cp $MASTERISO $SIMISO

  dd if=$MASTERISO of=$TMPISO bs=2048 count=800 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPISO --byteset 16,100,200 >>$LOGFILE 2>&1
    
  run_regtest adapive_wrong_fp_with_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $MASTERECC
fi

# Read an augmented image for which an ecc file is also available.
# In that case, the ecc file gets precedence over the embedded ecc.

if try "reading image with RS02 data and a RS01 ecc file" adaptive_with_double_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -mRS02 -n$((ISOSIZE+5000)) -c >>$LOGFILE 2>&1
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e $TMPECC -c $REDUNDANCY >>$LOGFILE 2>&1

  rm -f $TMPISO
  run_regtest adaptive_with_double_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $TMPECC
fi

# Read an image for which ecc information is available,
# but requiring a newer dvdisaster version.

if try "reading image w/ ecc file requiring a newer dvdisaster version" adaptive_with_incompatible_ecc; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug --set-version $SETVERSION -i$SIMISO -e $TMPECC -c $REDUNDANCY >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,88,220 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,89,65 >>$LOGFILE 2>&1
  $NEWVER --debug -i$TMPECC --byteset 0,90,15 >>$LOGFILE 2>&1

  rm -f $TMPISO
  run_regtest adaptive_with_incompatible_ecc "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $TMPECC
fi

# Read an image with a simulated hardware failure and 
# --ignore-fatal-sense not set.

if try "reading image with simulated hardware failure" adaptive_with_hardware_failure; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "5000:hardware failure" >>$LOGFILE 2>&1

  rm -f $TMPISO
  run_regtest adaptive_with_hardware_failure "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $ISODIR/no.iso
fi

# Read an image with a simulated hardware failure and 
# --ignore-fatal-sense being set.

if try "reading image, ignoring simulated hardware failure" adaptive_with_ignored_hardware_failure; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "5000:hardware failure" >>$LOGFILE 2>&1

  rm -f $TMPISO
  run_regtest adaptive_with_ignored_hardware_failure "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read --ignore-fatal-sense" $TMPISO  $ISODIR/no.iso
fi

# Read medium containing several dead sector markers

if try "reading medium containing dead sector markers" adaptive_medium_with_dsm; then

  cp $MASTERISO $SIMISO
  $NEWVER --debug -i$SIMISO --erase "4999:pass as dead sector marker" >>$LOGFILE 2>&1

  rm -f $TMPISO
  run_regtest adaptive_medium_with_dsm "--debug --sim-cd=$SIMISO --fixed-speed-values --spinup-delay=0 -r --adaptive-read" $TMPISO  $ISODIR/no.ecc
fi