tests: add tests for handling of corrupt extents

Add some regression tests to examine how e2fsck deals with (a) extent
blocks with only a bad checksum; (b) extent blocks with a bad magic
number; and (c) extent entries with corruption.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
diff --git a/tests/f_extent_bad_node/name b/tests/f_extent_bad_node/name
index 9c9d79f..0b4ab8c 100644
--- a/tests/f_extent_bad_node/name
+++ b/tests/f_extent_bad_node/name
@@ -1 +1 @@
-bad interior node in extent tree
+bad interior node in extent tree (metadata_csum)
diff --git a/tests/f_extent_int_bad_csum/expect.1 b/tests/f_extent_int_bad_csum/expect.1
new file mode 100644
index 0000000..57a2a61
--- /dev/null
+++ b/tests/f_extent_int_bad_csum/expect.1
@@ -0,0 +1,11 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 extent block passes checks, but checksum does not match extent
+	(logical block 698, invalid physical block 1788, len 1)
+Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (16.7% non-contiguous), 1446/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_int_bad_csum/expect.2 b/tests/f_extent_int_bad_csum/expect.2
new file mode 100644
index 0000000..6f73d98
--- /dev/null
+++ b/tests/f_extent_int_bad_csum/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (16.7% non-contiguous), 1446/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_int_bad_csum/image.gz b/tests/f_extent_int_bad_csum/image.gz
new file mode 100644
index 0000000..f387898
--- /dev/null
+++ b/tests/f_extent_int_bad_csum/image.gz
Binary files differ
diff --git a/tests/f_extent_int_bad_csum/name b/tests/f_extent_int_bad_csum/name
new file mode 100644
index 0000000..87317e3
--- /dev/null
+++ b/tests/f_extent_int_bad_csum/name
@@ -0,0 +1 @@
+bad csum in internal extent (metadata_csum)
diff --git a/tests/f_extent_int_bad_extent/expect.1 b/tests/f_extent_int_bad_extent/expect.1
new file mode 100644
index 0000000..3d2fb58
--- /dev/null
+++ b/tests/f_extent_int_bad_extent/expect.1
@@ -0,0 +1,24 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 has an invalid extent
+	(logical block 0, invalid physical block 4294967295, len 168)
+Clear? yes
+
+Inode 12, i_blocks is 712, should be 542.  Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(1090--1091) -1093 -1095 -1097 -1099 -1101 -1103 -1105 -1107 -1109 -1111 -1113 -1115 -1117 -1119 -1121 -1123 -1125 -1127 -1129 -1131 -1133 -1135 -1137 -1139 -1141 -1143 -1145 -1147 -1149 -1151 -1153 -1155 -1157 -1159 -1161 -1163 -1165 -1167 -1169 -1171 -1173 -1175 -1177 -1179 -1181 -1183 -1185 -1187 -1189 -1191 -1193 -1195 -1197 -1199 -1201 -1203 -1205 -1207 -1209 -1211 -1213 -1215 -1217 -1219 -1221 -1223 -1225 -1227 -1229 -1231 -1233 -1235 -1237 -1239 -1241 -1243 -1245 -1247 -1249 -1251 -1253 -1255 -1257
+Fix? yes
+
+Free blocks count wrong for group #0 (602, counted=687).
+Fix? yes
+
+Free blocks count wrong (602, counted=687).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/128 files (16.7% non-contiguous), 1361/2048 blocks
+Exit status is 1
diff --git a/tests/f_extent_int_bad_extent/expect.2 b/tests/f_extent_int_bad_extent/expect.2
new file mode 100644
index 0000000..4e72e41
--- /dev/null
+++ b/tests/f_extent_int_bad_extent/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (16.7% non-contiguous), 1361/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_int_bad_extent/image.gz b/tests/f_extent_int_bad_extent/image.gz
new file mode 100644
index 0000000..e8745bf
--- /dev/null
+++ b/tests/f_extent_int_bad_extent/image.gz
Binary files differ
diff --git a/tests/f_extent_int_bad_extent/name b/tests/f_extent_int_bad_extent/name
new file mode 100644
index 0000000..e22f6b4
--- /dev/null
+++ b/tests/f_extent_int_bad_extent/name
@@ -0,0 +1 @@
+bad extent in internal extent (metadata_csum)
diff --git a/tests/f_extent_int_bad_magic/expect.1 b/tests/f_extent_int_bad_magic/expect.1
new file mode 100644
index 0000000..0e82e2b
--- /dev/null
+++ b/tests/f_extent_int_bad_magic/expect.1
@@ -0,0 +1,23 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 has an invalid extent node (blk 1295, lblk 0)
+Clear? yes
+
+Inode 12, i_blocks is 712, should be 0.  Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(1090--1093) -1095 -1097 -1099 -1101 -1103 -1105 -1107 -1109 -1111 -1113 -1115 -1117 -1119 -1121 -1123 -1125 -1127 -1129 -1131 -1133 -1135 -1137 -1139 -1141 -1143 -1145 -1147 -1149 -1151 -1153 -1155 -1157 -1159 -1161 -1163 -1165 -1167 -1169 -1171 -1173 -1175 -1177 -1179 -1181 -1183 -1185 -1187 -1189 -1191 -1193 -1195 -1197 -1199 -1201 -1203 -1205 -1207 -1209 -1211 -1213 -1215 -1217 -1219 -1221 -1223 -1225 -1227 -1229 -1231 -1233 -1235 -1237 -1239 -1241 -1243 -1245 -1247 -1249 -1251 -1253 -1255 -1257 -1259 -1261 -1263 -1265 -1267 -1269 -1271 -1273 -1275 -1277 -1279 -1281 -1283 -1285 -1287 -(1289--1298) -1300 -1302 -1304 -1306 -1308 -1310 -1312 -1314 -1316 -1318 -1320 -1322 -1324 -1326 -1328 -1330 -1332 -1334 -1336 -1338 -1340 -1342 -1344 -1346 -1348 -1350 -1352 -1354 -1356 -1358 -1360 -1362 -1364 -1366 -1368 -1370 -1372 -1374 -1376 -1378 -1380 -1382 -1384 -1386 -1388 -1390 -1392 -1394 -1396 -1398 -1400 -1402 -1404 -1406 -1408 -1410 -1412 -1414 -1416 -1418 -1420 -1422 -1424 -1426 -1428 -1430 -1432 -1434 -1436 -1438 -1440 -1442 -1444 -1446 -1448 -1450 -1452 -1454 -1456 -1458 -1460 -1462 -1464 -1466 -1468 -1470 -1472 -1474 -1476 -1478 -1480 -1482 -1484 -1486 -1488 -1490 -1492 -1494 -1496 -1498 -1500 -1502 -1504 -1506 -1508 -1510 -1512 -1514 -1516 -1518 -1520 -1522 -1524 -1526 -1528 -1530 -1532 -1534 -1536 -1538 -1540 -1542 -1544 -1546 -1548 -1550 -1552 -1554 -1556 -1558 -1560 -1562 -1564 -1566 -1568 -1570 -1572 -1574 -1576 -1578 -1580 -1582 -1584 -1586 -1588 -1590 -1592 -1594 -1596 -1598 -1600 -1602 -1604 -1606 -1608 -1610 -1612 -1614 -1616 -1618 -1620 -1622 -1624 -1626 -1628 -1630 -1632 -1634 -1636 -1638 -1640 -1642 -1644 -1646 -1648 -1650 -1652 -1654 -1656 -1658 -1660 -1662 -1664 -1666 -1668 -1670 -1672 -1674 -1676 -1678 -1680 -1682 -1684 -1686 -1688 -1690 -1692 -1694 -1696 -1698 -1700 -1702 -1704 -1706 -1708 -1710 -1712 -1714 -1716 -1718 -1720 -1722 -1724 -1726 -1728 -1730 -1732 -1734 -1736 -1738 -1740 -1742 -1744 -1746 -1748 -1750 -1752 -1754 -1756 -1758 -1760 -1762 -1764 -1766 -1768 -1770 -1772 -1774 -1776 -1778 -1780 -1782 -1784 -1786 -1788
+Fix? yes
+
+Free blocks count wrong for group #0 (602, counted=958).
+Fix? yes
+
+Free blocks count wrong (602, counted=958).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/128 files (8.3% non-contiguous), 1090/2048 blocks
+Exit status is 1
diff --git a/tests/f_extent_int_bad_magic/expect.2 b/tests/f_extent_int_bad_magic/expect.2
new file mode 100644
index 0000000..283cc1f
--- /dev/null
+++ b/tests/f_extent_int_bad_magic/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (8.3% non-contiguous), 1090/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_int_bad_magic/image.gz b/tests/f_extent_int_bad_magic/image.gz
new file mode 100644
index 0000000..e00f887
--- /dev/null
+++ b/tests/f_extent_int_bad_magic/image.gz
Binary files differ
diff --git a/tests/f_extent_int_bad_magic/name b/tests/f_extent_int_bad_magic/name
new file mode 100644
index 0000000..a451e9a
--- /dev/null
+++ b/tests/f_extent_int_bad_magic/name
@@ -0,0 +1 @@
+bad magic number in internal extent (metadata_csum)
diff --git a/tests/f_extent_leaf_bad_csum/expect.1 b/tests/f_extent_leaf_bad_csum/expect.1
new file mode 100644
index 0000000..0dc78ad
--- /dev/null
+++ b/tests/f_extent_leaf_bad_csum/expect.1
@@ -0,0 +1,11 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 extent block passes checks, but checksum does not match extent
+	(logical block 7, invalid physical block 1090, len 1)
+Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (16.7% non-contiguous), 1099/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_leaf_bad_csum/expect.2 b/tests/f_extent_leaf_bad_csum/expect.2
new file mode 100644
index 0000000..a564763
--- /dev/null
+++ b/tests/f_extent_leaf_bad_csum/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (16.7% non-contiguous), 1099/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_leaf_bad_csum/image.gz b/tests/f_extent_leaf_bad_csum/image.gz
new file mode 100644
index 0000000..6c778f6
--- /dev/null
+++ b/tests/f_extent_leaf_bad_csum/image.gz
Binary files differ
diff --git a/tests/f_extent_leaf_bad_csum/name b/tests/f_extent_leaf_bad_csum/name
new file mode 100644
index 0000000..62a2285
--- /dev/null
+++ b/tests/f_extent_leaf_bad_csum/name
@@ -0,0 +1 @@
+bad csum in leaf extent (metadata_csum)
diff --git a/tests/f_extent_leaf_bad_extent/expect.1 b/tests/f_extent_leaf_bad_extent/expect.1
new file mode 100644
index 0000000..f96a8a9
--- /dev/null
+++ b/tests/f_extent_leaf_bad_extent/expect.1
@@ -0,0 +1,24 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 has an invalid extent
+	(logical block 2, invalid physical block 4294967295, len 1)
+Clear? yes
+
+Inode 12, i_blocks is 18, should be 16.  Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -1096
+Fix? yes
+
+Free blocks count wrong for group #0 (949, counted=950).
+Fix? yes
+
+Free blocks count wrong (949, counted=950).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/128 files (16.7% non-contiguous), 1098/2048 blocks
+Exit status is 1
diff --git a/tests/f_extent_leaf_bad_extent/expect.2 b/tests/f_extent_leaf_bad_extent/expect.2
new file mode 100644
index 0000000..de1727c
--- /dev/null
+++ b/tests/f_extent_leaf_bad_extent/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (16.7% non-contiguous), 1098/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_leaf_bad_extent/image.gz b/tests/f_extent_leaf_bad_extent/image.gz
new file mode 100644
index 0000000..d34d4d4
--- /dev/null
+++ b/tests/f_extent_leaf_bad_extent/image.gz
Binary files differ
diff --git a/tests/f_extent_leaf_bad_extent/name b/tests/f_extent_leaf_bad_extent/name
new file mode 100644
index 0000000..1bd8bd1
--- /dev/null
+++ b/tests/f_extent_leaf_bad_extent/name
@@ -0,0 +1 @@
+bad extent in leaf extent (metadata_csum)
diff --git a/tests/f_extent_leaf_bad_magic/expect.1 b/tests/f_extent_leaf_bad_magic/expect.1
new file mode 100644
index 0000000..7b6dbf1
--- /dev/null
+++ b/tests/f_extent_leaf_bad_magic/expect.1
@@ -0,0 +1,23 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 12 has an invalid extent node (blk 1604, lblk 0)
+Clear? yes
+
+Inode 12, i_blocks is 18, should be 0.  Fix? yes
+
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(1090--1097) -1604
+Fix? yes
+
+Free blocks count wrong for group #0 (949, counted=958).
+Fix? yes
+
+Free blocks count wrong (949, counted=958).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 12/128 files (8.3% non-contiguous), 1090/2048 blocks
+Exit status is 1
diff --git a/tests/f_extent_leaf_bad_magic/expect.2 b/tests/f_extent_leaf_bad_magic/expect.2
new file mode 100644
index 0000000..283cc1f
--- /dev/null
+++ b/tests/f_extent_leaf_bad_magic/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 12/128 files (8.3% non-contiguous), 1090/2048 blocks
+Exit status is 0
diff --git a/tests/f_extent_leaf_bad_magic/image.gz b/tests/f_extent_leaf_bad_magic/image.gz
new file mode 100644
index 0000000..7dd044f
--- /dev/null
+++ b/tests/f_extent_leaf_bad_magic/image.gz
Binary files differ
diff --git a/tests/f_extent_leaf_bad_magic/name b/tests/f_extent_leaf_bad_magic/name
new file mode 100644
index 0000000..e9f756e
--- /dev/null
+++ b/tests/f_extent_leaf_bad_magic/name
@@ -0,0 +1 @@
+bad magic number in leaf extent (metadata_csum)