jffs2.patch 295.5 KB
Newer Older
X
x_xiny 已提交
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 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
diff -Nupr old/fs/jffs2/acl.c new/fs/jffs2/acl.c
--- old/fs/jffs2/acl.c	2022-05-09 17:15:24.350000000 +0800
+++ new/fs/jffs2/acl.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,307 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2006  NEC Corporation
- *
- * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/fs.h>
-#include <linux/sched.h>
-#include <linux/time.h>
-#include <linux/crc32.h>
-#include <linux/jffs2.h>
-#include <linux/xattr.h>
-#include <linux/posix_acl_xattr.h>
-#include <linux/mtd/mtd.h>
-#include "nodelist.h"
-
-static size_t jffs2_acl_size(int count)
-{
-	if (count <= 4) {
-		return sizeof(struct jffs2_acl_header)
-		       + count * sizeof(struct jffs2_acl_entry_short);
-	} else {
-		return sizeof(struct jffs2_acl_header)
-		       + 4 * sizeof(struct jffs2_acl_entry_short)
-		       + (count - 4) * sizeof(struct jffs2_acl_entry);
-	}
-}
-
-static int jffs2_acl_count(size_t size)
-{
-	size_t s;
-
-	size -= sizeof(struct jffs2_acl_header);
-	if (size < 4 * sizeof(struct jffs2_acl_entry_short)) {
-		if (size % sizeof(struct jffs2_acl_entry_short))
-			return -1;
-		return size / sizeof(struct jffs2_acl_entry_short);
-	} else {
-		s = size - 4 * sizeof(struct jffs2_acl_entry_short);
-		if (s % sizeof(struct jffs2_acl_entry))
-			return -1;
-		return s / sizeof(struct jffs2_acl_entry) + 4;
-	}
-}
-
-static struct posix_acl *jffs2_acl_from_medium(void *value, size_t size)
-{
-	void *end = value + size;
-	struct jffs2_acl_header *header = value;
-	struct jffs2_acl_entry *entry;
-	struct posix_acl *acl;
-	uint32_t ver;
-	int i, count;
-
-	if (!value)
-		return NULL;
-	if (size < sizeof(struct jffs2_acl_header))
-		return ERR_PTR(-EINVAL);
-	ver = je32_to_cpu(header->a_version);
-	if (ver != JFFS2_ACL_VERSION) {
-		JFFS2_WARNING("Invalid ACL version. (=%u)\n", ver);
-		return ERR_PTR(-EINVAL);
-	}
-
-	value += sizeof(struct jffs2_acl_header);
-	count = jffs2_acl_count(size);
-	if (count < 0)
-		return ERR_PTR(-EINVAL);
-	if (count == 0)
-		return NULL;
-
-	acl = posix_acl_alloc(count, GFP_KERNEL);
-	if (!acl)
-		return ERR_PTR(-ENOMEM);
-
-	for (i=0; i < count; i++) {
-		entry = value;
-		if (value + sizeof(struct jffs2_acl_entry_short) > end)
-			goto fail;
-		acl->a_entries[i].e_tag = je16_to_cpu(entry->e_tag);
-		acl->a_entries[i].e_perm = je16_to_cpu(entry->e_perm);
-		switch (acl->a_entries[i].e_tag) {
-			case ACL_USER_OBJ:
-			case ACL_GROUP_OBJ:
-			case ACL_MASK:
-			case ACL_OTHER:
-				value += sizeof(struct jffs2_acl_entry_short);
-				break;
-
-			case ACL_USER:
-				value += sizeof(struct jffs2_acl_entry);
-				if (value > end)
-					goto fail;
-				acl->a_entries[i].e_uid =
-					make_kuid(&init_user_ns,
-						  je32_to_cpu(entry->e_id));
-				break;
-			case ACL_GROUP:
-				value += sizeof(struct jffs2_acl_entry);
-				if (value > end)
-					goto fail;
-				acl->a_entries[i].e_gid =
-					make_kgid(&init_user_ns,
-						  je32_to_cpu(entry->e_id));
-				break;
-
-			default:
-				goto fail;
-		}
-	}
-	if (value != end)
-		goto fail;
-	return acl;
- fail:
-	posix_acl_release(acl);
-	return ERR_PTR(-EINVAL);
-}
-
-static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size)
-{
-	struct jffs2_acl_header *header;
-	struct jffs2_acl_entry *entry;
-	void *e;
-	size_t i;
-
-	*size = jffs2_acl_size(acl->a_count);
-	header = kmalloc(struct_size(header, a_entries, acl->a_count),
-			GFP_KERNEL);
-	if (!header)
-		return ERR_PTR(-ENOMEM);
-	header->a_version = cpu_to_je32(JFFS2_ACL_VERSION);
-	e = header + 1;
-	for (i=0; i < acl->a_count; i++) {
-		const struct posix_acl_entry *acl_e = &acl->a_entries[i];
-		entry = e;
-		entry->e_tag = cpu_to_je16(acl_e->e_tag);
-		entry->e_perm = cpu_to_je16(acl_e->e_perm);
-		switch(acl_e->e_tag) {
-			case ACL_USER:
-				entry->e_id = cpu_to_je32(
-					from_kuid(&init_user_ns, acl_e->e_uid));
-				e += sizeof(struct jffs2_acl_entry);
-				break;
-			case ACL_GROUP:
-				entry->e_id = cpu_to_je32(
-					from_kgid(&init_user_ns, acl_e->e_gid));
-				e += sizeof(struct jffs2_acl_entry);
-				break;
-
-			case ACL_USER_OBJ:
-			case ACL_GROUP_OBJ:
-			case ACL_MASK:
-			case ACL_OTHER:
-				e += sizeof(struct jffs2_acl_entry_short);
-				break;
-
-			default:
-				goto fail;
-		}
-	}
-	return header;
- fail:
-	kfree(header);
-	return ERR_PTR(-EINVAL);
-}
-
-struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
-{
-	struct posix_acl *acl;
-	char *value = NULL;
-	int rc, xprefix;
-
-	switch (type) {
-	case ACL_TYPE_ACCESS:
-		xprefix = JFFS2_XPREFIX_ACL_ACCESS;
-		break;
-	case ACL_TYPE_DEFAULT:
-		xprefix = JFFS2_XPREFIX_ACL_DEFAULT;
-		break;
-	default:
-		BUG();
-	}
-	rc = do_jffs2_getxattr(inode, xprefix, "", NULL, 0);
-	if (rc > 0) {
-		value = kmalloc(rc, GFP_KERNEL);
-		if (!value)
-			return ERR_PTR(-ENOMEM);
-		rc = do_jffs2_getxattr(inode, xprefix, "", value, rc);
-	}
-	if (rc > 0) {
-		acl = jffs2_acl_from_medium(value, rc);
-	} else if (rc == -ENODATA || rc == -ENOSYS) {
-		acl = NULL;
-	} else {
-		acl = ERR_PTR(rc);
-	}
-	kfree(value);
-	return acl;
-}
-
-static int __jffs2_set_acl(struct inode *inode, int xprefix, struct posix_acl *acl)
-{
-	char *value = NULL;
-	size_t size = 0;
-	int rc;
-
-	if (acl) {
-		value = jffs2_acl_to_medium(acl, &size);
-		if (IS_ERR(value))
-			return PTR_ERR(value);
-	}
-	rc = do_jffs2_setxattr(inode, xprefix, "", value, size, 0);
-	if (!value && rc == -ENODATA)
-		rc = 0;
-	kfree(value);
-
-	return rc;
-}
-
-int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
-{
-	int rc, xprefix;
-
-	switch (type) {
-	case ACL_TYPE_ACCESS:
-		xprefix = JFFS2_XPREFIX_ACL_ACCESS;
-		if (acl) {
-			umode_t mode;
-
-			rc = posix_acl_update_mode(inode, &mode, &acl);
-			if (rc)
-				return rc;
-			if (inode->i_mode != mode) {
-				struct iattr attr;
-
-				attr.ia_valid = ATTR_MODE | ATTR_CTIME;
-				attr.ia_mode = mode;
-				attr.ia_ctime = current_time(inode);
-				rc = jffs2_do_setattr(inode, &attr);
-				if (rc < 0)
-					return rc;
-			}
-		}
-		break;
-	case ACL_TYPE_DEFAULT:
-		xprefix = JFFS2_XPREFIX_ACL_DEFAULT;
-		if (!S_ISDIR(inode->i_mode))
-			return acl ? -EACCES : 0;
-		break;
-	default:
-		return -EINVAL;
-	}
-	rc = __jffs2_set_acl(inode, xprefix, acl);
-	if (!rc)
-		set_cached_acl(inode, type, acl);
-	return rc;
-}
-
-int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, umode_t *i_mode)
-{
-	struct posix_acl *default_acl, *acl;
-	int rc;
-
-	cache_no_acl(inode);
-
-	rc = posix_acl_create(dir_i, i_mode, &default_acl, &acl);
-	if (rc)
-		return rc;
-
-	if (default_acl) {
-		set_cached_acl(inode, ACL_TYPE_DEFAULT, default_acl);
-		posix_acl_release(default_acl);
-	}
-	if (acl) {
-		set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
-		posix_acl_release(acl);
-	}
-	return 0;
-}
-
-int jffs2_init_acl_post(struct inode *inode)
-{
-	int rc;
-
-	if (inode->i_default_acl) {
-		rc = __jffs2_set_acl(inode, JFFS2_XPREFIX_ACL_DEFAULT, inode->i_default_acl);
-		if (rc)
-			return rc;
-	}
-
-	if (inode->i_acl) {
-		rc = __jffs2_set_acl(inode, JFFS2_XPREFIX_ACL_ACCESS, inode->i_acl);
-		if (rc)
-			return rc;
-	}
-
-	return 0;
-}
diff -Nupr old/fs/jffs2/acl.h new/fs/jffs2/acl.h
--- old/fs/jffs2/acl.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/acl.h	2022-05-10 14:52:22.930000000 +0800
@@ -8,6 +8,8 @@
  * For licensing information, see the file 'LICENCE' in this directory.
  *
  */
+#ifndef _JFFS2_ACL_H_
+#define _JFFS2_ACL_H_
 
 struct jffs2_acl_entry {
 	jint16_t	e_tag;
@@ -27,11 +29,6 @@ struct jffs2_acl_header {
 
 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
 
-struct posix_acl *jffs2_get_acl(struct inode *inode, int type);
-int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
-extern int jffs2_init_acl_pre(struct inode *, struct inode *, umode_t *);
-extern int jffs2_init_acl_post(struct inode *);
-
 #else
 
 #define jffs2_get_acl				(NULL)
@@ -40,3 +37,4 @@ extern int jffs2_init_acl_post(struct in
 #define jffs2_init_acl_post(inode)		(0)
 
 #endif	/* CONFIG_JFFS2_FS_POSIX_ACL */
+#endif  /* _JFFS2_ACL_H_ */
diff -Nupr old/fs/jffs2/background.c new/fs/jffs2/background.c
--- old/fs/jffs2/background.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/background.c	2022-05-10 14:53:26.200000000 +0800
@@ -10,156 +10,113 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
-#include <linux/jffs2.h>
-#include <linux/mtd/mtd.h>
-#include <linux/completion.h>
-#include <linux/sched/signal.h>
-#include <linux/freezer.h>
-#include <linux/kthread.h>
+#include <stdio.h>
 #include "nodelist.h"
+#include "vfs_jffs2.h"
+#include "mtd_partition.h"
 
+#define GC_THREAD_FLAG_TRIG 1
+#define GC_THREAD_FLAG_STOP 2
+#define GC_THREAD_FLAG_HAS_EXIT 4
 
-static int jffs2_garbage_collect_thread(void *);
+extern struct MtdNorDev jffs2_dev_list[CONFIG_MTD_PATTITION_NUM];
+static void jffs2_garbage_collect_thread(unsigned long data);
 
 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
 {
-	assert_spin_locked(&c->erase_completion_lock);
-	if (c->gc_task && jffs2_thread_should_wake(c))
-		send_sig(SIGHUP, c->gc_task, 1);
+	struct super_block *sb = OFNI_BS_2SFFJ(c);
+	/* Wake up the thread */
+	jffs2_dbg(1, "jffs2_garbage_collect_trigger\n");
+	LOS_EventWrite(&sb->s_gc_thread_flags, GC_THREAD_FLAG_TRIG);
 }
 
 /* This must only ever be called when no GC thread is currently running */
-int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
+void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
 {
-	struct task_struct *tsk;
-	int ret = 0;
+	struct super_block *sb = OFNI_BS_2SFFJ(c);
+	TSK_INIT_PARAM_S stGcTask;
 
-	BUG_ON(c->gc_task);
+	if (c == NULL)
+		return;
 
-	init_completion(&c->gc_thread_start);
-	init_completion(&c->gc_thread_exit);
+	if (sb->s_root == NULL)
+		return;
 
-	tsk = kthread_run(jffs2_garbage_collect_thread, c, "jffs2_gcd_mtd%d", c->mtd->index);
-	if (IS_ERR(tsk)) {
-		pr_warn("fork failed for JFFS2 garbage collect thread: %ld\n",
-			-PTR_ERR(tsk));
-		complete(&c->gc_thread_exit);
-		ret = PTR_ERR(tsk);
-	} else {
-		/* Wait for it... */
-		jffs2_dbg(1, "Garbage collect thread is pid %d\n", tsk->pid);
-		wait_for_completion(&c->gc_thread_start);
-		ret = tsk->pid;
+	LOS_EventInit(&sb->s_gc_thread_flags);
+
+	/* Start the thread. Doesn't matter if it fails -- it's only an
+	 * optimisation anyway */
+	(void)memset_s(&stGcTask, sizeof(TSK_INIT_PARAM_S), 0, sizeof(TSK_INIT_PARAM_S));
+
+	stGcTask.pfnTaskEntry = (TSK_ENTRY_FUNC)jffs2_garbage_collect_thread;
+	stGcTask.auwArgs[0] = (UINTPTR)c;
+	stGcTask.uwStackSize  = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE;
+	stGcTask.pcName = "jffs2_gc_thread";
+#ifdef LOSCFG_KERNEL_SMP
+	unsigned int i;
+	for (i = 0; i < CONFIG_MTD_PATTITION_NUM; i++) {
+		if (sb->s_dev == &jffs2_dev_list[i])
+			break;
 	}
+	stGcTask.usCpuAffiMask = CPUID_TO_AFFI_MASK(i % LOSCFG_KERNEL_CORE_NUM);
+#endif
+	stGcTask.usTaskPrio = JFFS2_GC_THREAD_PRIORITY;
 
-	return ret;
+	if (LOS_TaskCreate(&sb->s_gc_thread, &stGcTask))
+		JFFS2_ERROR("Create gc task failed!!!\n");
 }
 
 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
 {
-	int wait = 0;
-	spin_lock(&c->erase_completion_lock);
-	if (c->gc_task) {
-		jffs2_dbg(1, "Killing GC task %d\n", c->gc_task->pid);
-		send_sig(SIGKILL, c->gc_task, 1);
-		wait = 1;
-	}
-	spin_unlock(&c->erase_completion_lock);
-	if (wait)
-		wait_for_completion(&c->gc_thread_exit);
+	struct super_block *sb = OFNI_BS_2SFFJ(c);
+
+	JFFS2_DEBUG("jffs2_stop_garbage_collect_thread\n");
+	/* Stop the thread and wait for it if necessary */
+
+	LOS_EventWrite(&sb->s_gc_thread_flags, GC_THREAD_FLAG_STOP);
+
+	JFFS2_DEBUG("jffs2_stop_garbage_collect_thread wait\n");
+
+	(void)LOS_EventRead(&sb->s_gc_thread_flags,
+			GC_THREAD_FLAG_HAS_EXIT,
+			LOS_WAITMODE_OR | LOS_WAITMODE_CLR,
+			LOS_WAIT_FOREVER);
+
+	// Kill and free the resources ...  this is safe due to the flag
+	// from the thread.
+	(void)LOS_TaskDelete(sb->s_gc_thread);
+	(void)LOS_EventWrite(&sb->s_gc_thread_flags, 0xFFFFFFFF);
 }
 
-static int jffs2_garbage_collect_thread(void *_c)
+static void jffs2_garbage_collect_thread(unsigned long data)
 {
-	struct jffs2_sb_info *c = _c;
-	sigset_t hupmask;
+	struct jffs2_sb_info *c = (struct jffs2_sb_info *)data;
+	struct super_block *sb = OFNI_BS_2SFFJ(c);
+	unsigned int flag = 0;
+
+	jffs2_dbg(1, "jffs2_garbage_collect_thread START\n");
+	while(1) {
+		flag = LOS_EventRead(&sb->s_gc_thread_flags,
+			GC_THREAD_FLAG_TRIG | GC_THREAD_FLAG_STOP,
+			LOS_WAITMODE_OR | LOS_WAITMODE_CLR,
+			LOS_WAIT_FOREVER
+		);
+		if (flag & GC_THREAD_FLAG_STOP)
+			break;
 
-	siginitset(&hupmask, sigmask(SIGHUP));
-	allow_signal(SIGKILL);
-	allow_signal(SIGSTOP);
-	allow_signal(SIGHUP);
-
-	c->gc_task = current;
-	complete(&c->gc_thread_start);
-
-	set_user_nice(current, 10);
-
-	set_freezable();
-	for (;;) {
-		sigprocmask(SIG_UNBLOCK, &hupmask, NULL);
-	again:
-		spin_lock(&c->erase_completion_lock);
-		if (!jffs2_thread_should_wake(c)) {
-			set_current_state (TASK_INTERRUPTIBLE);
-			spin_unlock(&c->erase_completion_lock);
-			jffs2_dbg(1, "%s(): sleeping...\n", __func__);
-			schedule();
-		} else {
-			spin_unlock(&c->erase_completion_lock);
-		}
-		/* Problem - immediately after bootup, the GCD spends a lot
-		 * of time in places like jffs2_kill_fragtree(); so much so
-		 * that userspace processes (like gdm and X) are starved
-		 * despite plenty of cond_resched()s and renicing.  Yield()
-		 * doesn't help, either (presumably because userspace and GCD
-		 * are generally competing for a higher latency resource -
-		 * disk).
-		 * This forces the GCD to slow the hell down.   Pulling an
-		 * inode in with read_inode() is much preferable to having
-		 * the GC thread get there first. */
-		schedule_timeout_interruptible(msecs_to_jiffies(50));
-
-		if (kthread_should_stop()) {
-			jffs2_dbg(1, "%s(): kthread_stop() called\n", __func__);
-			goto die;
-		}
+		jffs2_dbg(1, "jffs2: GC THREAD GC BEGIN\n");
 
-		/* Put_super will send a SIGKILL and then wait on the sem.
-		 */
-		while (signal_pending(current) || freezing(current)) {
-			unsigned long signr;
-
-			if (try_to_freeze())
-				goto again;
-
-			signr = kernel_dequeue_signal();
-
-			switch(signr) {
-			case SIGSTOP:
-				jffs2_dbg(1, "%s(): SIGSTOP received\n",
-					  __func__);
-				kernel_signal_stop();
-				break;
-
-			case SIGKILL:
-				jffs2_dbg(1, "%s(): SIGKILL received\n",
-					  __func__);
-				goto die;
-
-			case SIGHUP:
-				jffs2_dbg(1, "%s(): SIGHUP received\n",
-					  __func__);
-				break;
-			default:
-				jffs2_dbg(1, "%s(): signal %ld received\n",
-					  __func__, signr);
-			}
-		}
-		/* We don't want SIGHUP to interrupt us. STOP and KILL are OK though. */
-		sigprocmask(SIG_BLOCK, &hupmask, NULL);
+		if (sb->s_root == NULL)
+			return;
 
-		jffs2_dbg(1, "%s(): pass\n", __func__);
 		if (jffs2_garbage_collect_pass(c) == -ENOSPC) {
-			pr_notice("No space for garbage collection. Aborting GC thread\n");
-			goto die;
+			PRINTK("No space for garbage collection. "
+			"Aborting JFFS2 GC thread\n");
+			break;
 		}
+		jffs2_dbg(1, "jffs2: GC THREAD GC END\n");
 	}
- die:
-	spin_lock(&c->erase_completion_lock);
-	c->gc_task = NULL;
-	spin_unlock(&c->erase_completion_lock);
-	complete_and_exit(&c->gc_thread_exit, 0);
+	JFFS2_DEBUG("jffs2_garbage_collect_thread EXIT\n");
+	LOS_EventWrite(&sb->s_gc_thread_flags, GC_THREAD_FLAG_HAS_EXIT);
 }
diff -Nupr old/fs/jffs2/build.c new/fs/jffs2/build.c
--- old/fs/jffs2/build.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/build.c	2022-05-10 15:01:38.800000000 +0800
@@ -10,15 +10,13 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
+#include <dirent.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/mtd/mtd.h>
-#include <linux/mm.h> /* kvfree() */
+#include <mtd_dev.h>
 #include "nodelist.h"
+#include "los_exc.h"
 
 static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *,
 		struct jffs2_inode_cache *, struct jffs2_full_dirent **);
@@ -50,8 +48,7 @@ next_inode(int *i, struct jffs2_inode_ca
 
 
 static void jffs2_build_inode_pass1(struct jffs2_sb_info *c,
-				    struct jffs2_inode_cache *ic,
-				    int *dir_hardlinks)
+				    struct jffs2_inode_cache *ic)
 {
 	struct jffs2_full_dirent *fd;
 
@@ -372,20 +369,24 @@ int jffs2_do_mount_fs(struct jffs2_sb_in
 	int ret;
 	int i;
 	int size;
+	struct super_block *sb;
+	struct MtdNorDev *device;
 
 	c->free_size = c->flash_size;
 	c->nr_blocks = c->flash_size / c->sector_size;
-	size = sizeof(struct jffs2_eraseblock) * c->nr_blocks;
+	sb = OFNI_BS_2SFFJ(c);
+	device = (struct MtdNorDev *)(sb->s_dev);
+	size = sizeof(struct jffs2_eraseblock) *(c->nr_blocks + device->blockStart);
 #ifndef __ECOS
 	if (jffs2_blocks_use_vmalloc(c))
-		c->blocks = vzalloc(size);
+		c->blocks = malloc(size);
 	else
 #endif
 		c->blocks = kzalloc(size, GFP_KERNEL);
 	if (!c->blocks)
 		return -ENOMEM;
 
-	for (i=0; i<c->nr_blocks; i++) {
+	for (i = device->blockStart; i < c->nr_blocks + device->blockStart; i++) {
 		INIT_LIST_HEAD(&c->blocks[i].list);
 		c->blocks[i].offset = i * c->sector_size;
 		c->blocks[i].free_size = c->sector_size;
diff -Nupr old/fs/jffs2/compr.c new/fs/jffs2/compr.c
--- old/fs/jffs2/compr.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/compr.c	2022-05-10 15:02:17.440000000 +0800
@@ -12,14 +12,13 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include "compr.h"
+#include "jffs2.h"
+#include "user_copy.h"
 
-static DEFINE_SPINLOCK(jffs2_compressor_list_lock);
-
+static spinlock_t jffs2_compressor_list_lock;
 /* Available compressors are on this list */
-static LIST_HEAD(jffs2_compressor_list);
+static LINUX_LIST_HEAD(jffs2_compressor_list);
 
 /* Actual compression mode */
 static int jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
@@ -71,15 +70,15 @@ static int jffs2_is_best_compression(str
  * could not be compressed; probably because we couldn't find the requested
  * compression mode.
  */
-static int jffs2_selected_compress(u8 compr, unsigned char *data_in,
-		unsigned char **cpage_out, u32 *datalen, u32 *cdatalen)
+static int jffs2_selected_compress(uint8_t compr, unsigned char *data_in,
+		unsigned char **cpage_out, uint32_t *datalen, uint32_t *cdatalen)
 {
 	struct jffs2_compressor *this;
 	int err, ret = JFFS2_COMPR_NONE;
 	uint32_t orig_slen, orig_dlen;
-	char *output_buf;
+	unsigned char *output_buf;
 
-	output_buf = kmalloc(*cdatalen, GFP_KERNEL);
+	output_buf = kmalloc(*cdatalen,GFP_KERNEL);
 	if (!output_buf) {
 		pr_warn("No memory for compressor allocation. Compression failed.\n");
 		return ret;
@@ -265,11 +264,16 @@ int jffs2_decompress(struct jffs2_sb_inf
 	switch (comprtype & 0xff) {
 	case JFFS2_COMPR_NONE:
 		/* This should be special-cased elsewhere, but we might as well deal with it */
-		memcpy(data_out, cdata_in, datalen);
+		if (LOS_CopyFromKernel(data_out, datalen, cdata_in, datalen) != 0) {
+			return -EFAULT;
+		}
 		none_stat_decompr_blocks++;
 		break;
 	case JFFS2_COMPR_ZERO:
-		memset(data_out, 0, datalen);
+		ret = LOS_UserMemClear(data_out, datalen);
+		if (ret != 0) {
+			return ret;
+		}
 		break;
 	default:
 		spin_lock(&jffs2_compressor_list_lock);
diff -Nupr old/fs/jffs2/compr.h new/fs/jffs2/compr.h
--- old/fs/jffs2/compr.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/compr.h	2022-05-10 15:02:50.040000000 +0800
@@ -13,18 +13,20 @@
 #define __JFFS2_COMPR_H__
 
 #include <linux/kernel.h>
-#include <linux/vmalloc.h>
 #include <linux/list.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/errno.h>
-#include <linux/fs.h>
-#include <linux/jffs2.h>
-#include "jffs2_fs_i.h"
-#include "jffs2_fs_sb.h"
+#include <linux/stat.h>
 #include "nodelist.h"
 
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #define JFFS2_RUBINMIPS_PRIORITY 10
 #define JFFS2_DYNRUBIN_PRIORITY  20
 #define JFFS2_LZARI_PRIORITY     30
@@ -102,4 +104,10 @@ int jffs2_lzo_init(void);
 void jffs2_lzo_exit(void);
 #endif
 
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #endif /* __JFFS2_COMPR_H__ */
diff -Nupr old/fs/jffs2/compr_lzo.c new/fs/jffs2/compr_lzo.c
--- old/fs/jffs2/compr_lzo.c	2022-05-09 17:15:24.350000000 +0800
+++ new/fs/jffs2/compr_lzo.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,110 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2007 Nokia Corporation. All rights reserved.
- * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
- *
- * Created by Richard Purdie <rpurdie@openedhand.com>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/vmalloc.h>
-#include <linux/init.h>
-#include <linux/lzo.h>
-#include "compr.h"
-
-static void *lzo_mem;
-static void *lzo_compress_buf;
-static DEFINE_MUTEX(deflate_mutex);	/* for lzo_mem and lzo_compress_buf */
-
-static void free_workspace(void)
-{
-	vfree(lzo_mem);
-	vfree(lzo_compress_buf);
-}
-
-static int __init alloc_workspace(void)
-{
-	lzo_mem = vmalloc(LZO1X_MEM_COMPRESS);
-	lzo_compress_buf = vmalloc(lzo1x_worst_compress(PAGE_SIZE));
-
-	if (!lzo_mem || !lzo_compress_buf) {
-		free_workspace();
-		return -ENOMEM;
-	}
-
-	return 0;
-}
-
-static int jffs2_lzo_compress(unsigned char *data_in, unsigned char *cpage_out,
-			      uint32_t *sourcelen, uint32_t *dstlen)
-{
-	size_t compress_size;
-	int ret;
-
-	mutex_lock(&deflate_mutex);
-	ret = lzo1x_1_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem);
-	if (ret != LZO_E_OK)
-		goto fail;
-
-	if (compress_size > *dstlen)
-		goto fail;
-
-	memcpy(cpage_out, lzo_compress_buf, compress_size);
-	mutex_unlock(&deflate_mutex);
-
-	*dstlen = compress_size;
-	return 0;
-
- fail:
-	mutex_unlock(&deflate_mutex);
-	return -1;
-}
-
-static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out,
-				 uint32_t srclen, uint32_t destlen)
-{
-	size_t dl = destlen;
-	int ret;
-
-	ret = lzo1x_decompress_safe(data_in, srclen, cpage_out, &dl);
-
-	if (ret != LZO_E_OK || dl != destlen)
-		return -1;
-
-	return 0;
-}
-
-static struct jffs2_compressor jffs2_lzo_comp = {
-	.priority = JFFS2_LZO_PRIORITY,
-	.name = "lzo",
-	.compr = JFFS2_COMPR_LZO,
-	.compress = &jffs2_lzo_compress,
-	.decompress = &jffs2_lzo_decompress,
-	.disabled = 0,
-};
-
-int __init jffs2_lzo_init(void)
-{
-	int ret;
-
-	ret = alloc_workspace();
-	if (ret < 0)
-		return ret;
-
-	ret = jffs2_register_compressor(&jffs2_lzo_comp);
-	if (ret)
-		free_workspace();
-
-	return ret;
-}
-
-void jffs2_lzo_exit(void)
-{
-	jffs2_unregister_compressor(&jffs2_lzo_comp);
-	free_workspace();
-}
diff -Nupr old/fs/jffs2/compr_rtime.c new/fs/jffs2/compr_rtime.c
--- old/fs/jffs2/compr_rtime.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/compr_rtime.c	2022-05-10 15:05:05.970000000 +0800
@@ -25,7 +25,7 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/string.h>
-#include <linux/jffs2.h>
+#include "jffs2.h"
 #include "compr.h"
 
 /* _compress returns the compressed size, -1 if bigger */
diff -Nupr old/fs/jffs2/compr_rubin.c new/fs/jffs2/compr_rubin.c
--- old/fs/jffs2/compr_rubin.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/compr_rubin.c	2022-05-10 15:05:51.830000000 +0800
@@ -10,15 +10,12 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/string.h>
 #include <linux/types.h>
-#include <linux/jffs2.h>
 #include <linux/errno.h>
+#include "jffs2.h"
 #include "compr.h"
 
-
 #define RUBIN_REG_SIZE   16
 #define UPPER_BIT_RUBIN    (((long) 1)<<(RUBIN_REG_SIZE-1))
 #define LOWER_BITS_RUBIN   ((((long) 1)<<(RUBIN_REG_SIZE-1))-1)
@@ -48,7 +45,7 @@ static inline void init_pushpull(struct
 				 unsigned buflen, unsigned ofs,
 				 unsigned reserve)
 {
-	pp->buf = buf;
+	pp->buf = (unsigned char *)buf;
 	pp->buflen = buflen;
 	pp->ofs = ofs;
 	pp->reserve = reserve;
@@ -267,7 +264,7 @@ static int rubin_do_compress(int bit_div
 	int pos=0;
 	struct rubin_state rs;
 
-	init_pushpull(&rs.pp, cpage_out, *dstlen * 8, 0, 32);
+	init_pushpull(&rs.pp, (char *)cpage_out, *dstlen * 8, 0, 32);
 
 	init_rubin(&rs, bit_divider, bits);
 
@@ -366,14 +363,14 @@ static int jffs2_dynrubin_compress(unsig
 }
 
 static void rubin_do_decompress(int bit_divider, int *bits,
-				unsigned char *cdata_in, 
+				unsigned char *cdata_in,
 				unsigned char *page_out, uint32_t srclen,
 				uint32_t destlen)
 {
 	int outpos = 0;
 	struct rubin_state rs;
 
-	init_pushpull(&rs.pp, cdata_in, srclen, 0, 0);
+	init_pushpull(&rs.pp, (char *)cdata_in, srclen, 0, 0);
 	init_decode(&rs, bit_divider, bits);
 
 	while (outpos < destlen)
diff -Nupr old/fs/jffs2/compr_zlib.c new/fs/jffs2/compr_zlib.c
--- old/fs/jffs2/compr_zlib.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/compr_zlib.c	2022-05-10 15:06:46.640000000 +0800
@@ -10,15 +10,10 @@
  *
  */
 
-#if !defined(__KERNEL__) && !defined(__ECOS)
-#error "The userspace support got too messy and was removed. Update your mkfs.jffs2"
-#endif
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
-#include <linux/zlib.h>
+#include <zlib.h>
 #include <linux/zutil.h>
+#include <linux/semaphore.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -35,39 +30,8 @@ static DEFINE_MUTEX(deflate_mutex);
 static DEFINE_MUTEX(inflate_mutex);
 static z_stream inf_strm, def_strm;
 
-#ifdef __KERNEL__ /* Linux-only */
-#include <linux/vmalloc.h>
-#include <linux/init.h>
-#include <linux/mutex.h>
-
-static int __init alloc_workspaces(void)
-{
-	def_strm.workspace = vmalloc(zlib_deflate_workspacesize(MAX_WBITS,
-							MAX_MEM_LEVEL));
-	if (!def_strm.workspace)
-		return -ENOMEM;
-
-	jffs2_dbg(1, "Allocated %d bytes for deflate workspace\n",
-		  zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL));
-	inf_strm.workspace = vmalloc(zlib_inflate_workspacesize());
-	if (!inf_strm.workspace) {
-		vfree(def_strm.workspace);
-		return -ENOMEM;
-	}
-	jffs2_dbg(1, "Allocated %d bytes for inflate workspace\n",
-		  zlib_inflate_workspacesize());
-	return 0;
-}
-
-static void free_workspaces(void)
-{
-	vfree(def_strm.workspace);
-	vfree(inf_strm.workspace);
-}
-#else
 #define alloc_workspaces() (0)
 #define free_workspaces() do { } while(0)
-#endif /* __KERNEL__ */
 
 static int jffs2_zlib_compress(unsigned char *data_in,
 			       unsigned char *cpage_out,
@@ -80,7 +44,7 @@ static int jffs2_zlib_compress(unsigned
 
 	mutex_lock(&deflate_mutex);
 
-	if (Z_OK != zlib_deflateInit(&def_strm, 3)) {
+	if (Z_OK != deflateInit(&def_strm, 3)) {
 		pr_warn("deflateInit failed\n");
 		mutex_unlock(&deflate_mutex);
 		return -1;
@@ -98,21 +62,21 @@ static int jffs2_zlib_compress(unsigned
 			(*sourcelen-def_strm.total_in), def_strm.avail_out);
 		jffs2_dbg(1, "calling deflate with avail_in %ld, avail_out %ld\n",
 			  def_strm.avail_in, def_strm.avail_out);
-		ret = zlib_deflate(&def_strm, Z_PARTIAL_FLUSH);
+		ret = deflate(&def_strm, Z_PARTIAL_FLUSH);
 		jffs2_dbg(1, "deflate returned with avail_in %ld, avail_out %ld, total_in %ld, total_out %ld\n",
 			  def_strm.avail_in, def_strm.avail_out,
 			  def_strm.total_in, def_strm.total_out);
 		if (ret != Z_OK) {
 			jffs2_dbg(1, "deflate in loop returned %d\n", ret);
-			zlib_deflateEnd(&def_strm);
+			deflateEnd(&def_strm);
 			mutex_unlock(&deflate_mutex);
 			return -1;
 		}
 	}
 	def_strm.avail_out += STREAM_END_SPACE;
 	def_strm.avail_in = 0;
-	ret = zlib_deflate(&def_strm, Z_FINISH);
-	zlib_deflateEnd(&def_strm);
+	ret = deflate(&def_strm, Z_FINISH);
+	deflateEnd(&def_strm);
 
 	if (ret != Z_STREAM_END) {
 		jffs2_dbg(1, "final deflate returned %d\n", ret);
@@ -171,18 +135,18 @@ static int jffs2_zlib_decompress(unsigne
 	}
 
 
-	if (Z_OK != zlib_inflateInit2(&inf_strm, wbits)) {
+	if (Z_OK != inflateInit2(&inf_strm, wbits)) {
 		pr_warn("inflateInit failed\n");
 		mutex_unlock(&inflate_mutex);
 		return 1;
 	}
 
-	while((ret = zlib_inflate(&inf_strm, Z_FINISH)) == Z_OK)
+	while((ret = inflate(&inf_strm, Z_FINISH)) == Z_OK)
 		;
 	if (ret != Z_STREAM_END) {
 		pr_notice("inflate returned %d\n", ret);
 	}
-	zlib_inflateEnd(&inf_strm);
+	inflateEnd(&inf_strm);
 	mutex_unlock(&inflate_mutex);
 	return 0;
 }
@@ -204,13 +168,30 @@ int __init jffs2_zlib_init(void)
 {
     int ret;
 
+    ret = pthread_mutex_init(&inflate_mutex, NULL);
+    if (ret) {
+        return ret;
+    }
+
+    ret = pthread_mutex_init(&deflate_mutex, NULL);
+    if (ret) {
+        pthread_mutex_destroy(&inflate_mutex);
+        return ret;
+    }
+
     ret = alloc_workspaces();
-    if (ret)
-	    return ret;
+    if (ret) {
+        pthread_mutex_destroy(&inflate_mutex);
+        pthread_mutex_destroy(&deflate_mutex);
+        return ret;
+    }
 
     ret = jffs2_register_compressor(&jffs2_zlib_comp);
-    if (ret)
-	    free_workspaces();
+    if (ret) {
+        pthread_mutex_destroy(&inflate_mutex);
+        pthread_mutex_destroy(&deflate_mutex);
+        free_workspaces();
+    }
 
     return ret;
 }
@@ -219,4 +200,6 @@ void jffs2_zlib_exit(void)
 {
     jffs2_unregister_compressor(&jffs2_zlib_comp);
     free_workspaces();
+    pthread_mutex_destroy(&inflate_mutex);
+    pthread_mutex_destroy(&deflate_mutex);
 }
diff -Nupr old/fs/jffs2/debug.c new/fs/jffs2/debug.c
--- old/fs/jffs2/debug.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/debug.c	2022-05-10 15:11:46.200000000 +0800
@@ -10,15 +10,12 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/pagemap.h>
-#include <linux/crc32.h>
-#include <linux/jffs2.h>
-#include <linux/mtd/mtd.h>
 #include <linux/slab.h>
+#include <mtd_dev.h>
+#include "los_crc32.h"
 #include "nodelist.h"
 #include "debug.h"
 
@@ -133,7 +130,7 @@ __jffs2_dbg_prewrite_paranoia_check(stru
 	if (!buf)
 		return;
 
-	ret = jffs2_flash_read(c, ofs, len, &retlen, buf);
+	ret = jffs2_flash_read(c, ofs, len, &retlen, (char *)buf);
 	if (ret || (retlen != len)) {
 		JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n",
 				len, ret, retlen);
diff -Nupr old/fs/jffs2/debug.h new/fs/jffs2/debug.h
--- old/fs/jffs2/debug.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/debug.h	2022-05-10 15:12:30.850000000 +0800
@@ -14,7 +14,12 @@
 #define _JFFS2_DEBUG_H_
 
 #include <linux/sched.h>
-
+#include "los_process.h"
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
 #ifndef CONFIG_JFFS2_FS_DEBUG
 #define CONFIG_JFFS2_FS_DEBUG 0
 #endif
@@ -71,25 +76,26 @@ do {						\
 
 /* The prefixes of JFFS2 messages */
 #define JFFS2_DBG		KERN_DEBUG
+#define JFFS2_DBG_LVL	KERN_DEBUG
 #define JFFS2_DBG_PREFIX	"[JFFS2 DBG]"
 #define JFFS2_DBG_MSG_PREFIX	JFFS2_DBG JFFS2_DBG_PREFIX
 
 /* JFFS2 message macros */
 #define JFFS2_ERROR(fmt, ...)					\
-	pr_err("error: (%d) %s: " fmt,				\
-	       task_pid_nr(current), __func__, ##__VA_ARGS__)
+	pr_err("error: (%u) %s: " fmt,				\
+	       LOS_GetCurrProcessID, __func__, ##__VA_ARGS__)
 
 #define JFFS2_WARNING(fmt, ...)						\
-	pr_warn("warning: (%d) %s: " fmt,				\
-		task_pid_nr(current), __func__, ##__VA_ARGS__)
+	pr_warn("warning: (%u) %s: " fmt,				\
+		LOS_GetCurrProcessID, __func__, ##__VA_ARGS__)
 
 #define JFFS2_NOTICE(fmt, ...)						\
-	pr_notice("notice: (%d) %s: " fmt,				\
-		  task_pid_nr(current), __func__, ##__VA_ARGS__)
+	pr_notice("notice: (%u) %s: " fmt,				\
+		  LOS_GetCurrProcessID, __func__, ##__VA_ARGS__)
 
 #define JFFS2_DEBUG(fmt, ...)						\
-	printk(KERN_DEBUG "[JFFS2 DBG] (%d) %s: " fmt,			\
-	       task_pid_nr(current), __func__, ##__VA_ARGS__)
+	printk(KERN_DEBUG "[JFFS2 DBG] (%u) %s: " fmt,			\
+	       LOS_GetCurrProcessID, __func__, ##__VA_ARGS__)
 
 /*
  * We split our debugging messages on several parts, depending on the JFFS2
@@ -272,4 +278,10 @@ __jffs2_dbg_dump_node(struct jffs2_sb_in
 #define jffs2_dbg_acct_sanity_check_nolock(c, jeb)
 #endif /* !JFFS2_DBG_SANITY_CHECKS */
 
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #endif /* _JFFS2_DEBUG_H_ */
diff -Nupr old/fs/jffs2/dir.c new/fs/jffs2/dir.c
--- old/fs/jffs2/dir.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/dir.c	2022-05-10 16:08:26.380000000 +0800
@@ -10,95 +10,42 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
+#include <dirent.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
-#include <linux/crc32.h>
-#include <linux/jffs2.h>
-#include "jffs2_fs_i.h"
-#include "jffs2_fs_sb.h"
-#include <linux/time.h>
+#include "los_crc32.h"
 #include "nodelist.h"
-
-static int jffs2_readdir (struct file *, struct dir_context *);
-
-static int jffs2_create (struct inode *,struct dentry *,umode_t,
-			 bool);
-static struct dentry *jffs2_lookup (struct inode *,struct dentry *,
-				    unsigned int);
-static int jffs2_link (struct dentry *,struct inode *,struct dentry *);
-static int jffs2_unlink (struct inode *,struct dentry *);
-static int jffs2_symlink (struct inode *,struct dentry *,const char *);
-static int jffs2_mkdir (struct inode *,struct dentry *,umode_t);
-static int jffs2_rmdir (struct inode *,struct dentry *);
-static int jffs2_mknod (struct inode *,struct dentry *,umode_t,dev_t);
-static int jffs2_rename (struct inode *, struct dentry *,
-			 struct inode *, struct dentry *,
-			 unsigned int);
-
-const struct file_operations jffs2_dir_operations =
-{
-	.read =		generic_read_dir,
-	.iterate_shared=jffs2_readdir,
-	.unlocked_ioctl=jffs2_ioctl,
-	.fsync =	jffs2_fsync,
-	.llseek =	generic_file_llseek,
-};
-
-
-const struct inode_operations jffs2_dir_inode_operations =
-{
-	.create =	jffs2_create,
-	.lookup =	jffs2_lookup,
-	.link =		jffs2_link,
-	.unlink =	jffs2_unlink,
-	.symlink =	jffs2_symlink,
-	.mkdir =	jffs2_mkdir,
-	.rmdir =	jffs2_rmdir,
-	.mknod =	jffs2_mknod,
-	.rename =	jffs2_rename,
-	.get_acl =	jffs2_get_acl,
-	.set_acl =	jffs2_set_acl,
-	.setattr =	jffs2_setattr,
-	.listxattr =	jffs2_listxattr,
-};
-
-/***********************************************************************/
-
+#include "vfs_jffs2.h"
+#include "jffs2_hash.h"
 
 /* We keep the dirent list sorted in increasing order of name hash,
    and we use the same hash function as the dentries. Makes this
    nice and simple
 */
-static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
-				   unsigned int flags)
+struct jffs2_inode *jffs2_lookup(struct jffs2_inode *dir_i, const unsigned char *d_name, int namelen)
 {
 	struct jffs2_inode_info *dir_f;
 	struct jffs2_full_dirent *fd = NULL, *fd_list;
 	uint32_t ino = 0;
-	struct inode *inode = NULL;
-	unsigned int nhash;
+	uint32_t hash = full_name_hash(d_name, namelen);
+	struct jffs2_inode *inode = NULL;
 
 	jffs2_dbg(1, "jffs2_lookup()\n");
 
-	if (target->d_name.len > JFFS2_MAX_NAME_LEN)
+	if (namelen > JFFS2_MAX_NAME_LEN)
 		return ERR_PTR(-ENAMETOOLONG);
 
 	dir_f = JFFS2_INODE_INFO(dir_i);
 
-	/* The 'nhash' on the fd_list is not the same as the dentry hash */
-	nhash = full_name_hash(NULL, target->d_name.name, target->d_name.len);
-
 	mutex_lock(&dir_f->sem);
 
 	/* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
-	for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= nhash; fd_list = fd_list->next) {
-		if (fd_list->nhash == nhash &&
-		    (!fd || fd_list->version > fd->version) &&
-		    strlen(fd_list->name) == target->d_name.len &&
-		    !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) {
+	for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= hash; fd_list = fd_list->next) {
+		if (fd_list->nhash == hash &&
+			(!fd || fd_list->version > fd->version) &&
+			strlen((char *)fd_list->name) == namelen &&
+			!strncmp((char *)fd_list->name, (char *)d_name, namelen)) {
 			fd = fd_list;
 		}
 	}
@@ -111,176 +58,57 @@ static struct dentry *jffs2_lookup(struc
 			pr_warn("iget() failed for ino #%u\n", ino);
 	}
 
-	return d_splice_alias(inode, target);
-}
-
-/***********************************************************************/
-
-
-static int jffs2_readdir(struct file *file, struct dir_context *ctx)
-{
-	struct inode *inode = file_inode(file);
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-	struct jffs2_full_dirent *fd;
-	unsigned long curofs = 1;
-
-	jffs2_dbg(1, "jffs2_readdir() for dir_i #%lu\n", inode->i_ino);
-
-	if (!dir_emit_dots(file, ctx))
-		return 0;
-
-	mutex_lock(&f->sem);
-	for (fd = f->dents; fd; fd = fd->next) {
-		curofs++;
-		/* First loop: curofs = 2; pos = 2 */
-		if (curofs < ctx->pos) {
-			jffs2_dbg(2, "Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n",
-				  fd->name, fd->ino, fd->type, curofs, (unsigned long)ctx->pos);
-			continue;
-		}
-		if (!fd->ino) {
-			jffs2_dbg(2, "Skipping deletion dirent \"%s\"\n",
-				  fd->name);
-			ctx->pos++;
-			continue;
-		}
-		jffs2_dbg(2, "Dirent %ld: \"%s\", ino #%u, type %d\n",
-			  (unsigned long)ctx->pos, fd->name, fd->ino, fd->type);
-		if (!dir_emit(ctx, fd->name, strlen(fd->name), fd->ino, fd->type))
-			break;
-		ctx->pos++;
-	}
-	mutex_unlock(&f->sem);
-	return 0;
-}
-
-/***********************************************************************/
-
-
-static int jffs2_create(struct inode *dir_i, struct dentry *dentry,
-			umode_t mode, bool excl)
-{
-	struct jffs2_raw_inode *ri;
-	struct jffs2_inode_info *f, *dir_f;
-	struct jffs2_sb_info *c;
-	struct inode *inode;
-	int ret;
-
-	ri = jffs2_alloc_raw_inode();
-	if (!ri)
-		return -ENOMEM;
-
-	c = JFFS2_SB_INFO(dir_i->i_sb);
-
-	jffs2_dbg(1, "%s()\n", __func__);
-
-	inode = jffs2_new_inode(dir_i, mode, ri);
-
-	if (IS_ERR(inode)) {
-		jffs2_dbg(1, "jffs2_new_inode() failed\n");
-		jffs2_free_raw_inode(ri);
-		return PTR_ERR(inode);
-	}
-
-	inode->i_op = &jffs2_file_inode_operations;
-	inode->i_fop = &jffs2_file_operations;
-	inode->i_mapping->a_ops = &jffs2_file_address_operations;
-	inode->i_mapping->nrpages = 0;
-
-	f = JFFS2_INODE_INFO(inode);
-	dir_f = JFFS2_INODE_INFO(dir_i);
-
-	/* jffs2_do_create() will want to lock it, _after_ reserving
-	   space and taking c-alloc_sem. If we keep it locked here,
-	   lockdep gets unhappy (although it's a false positive;
-	   nothing else will be looking at this inode yet so there's
-	   no chance of AB-BA deadlock involving its f->sem). */
-	mutex_unlock(&f->sem);
-
-	ret = jffs2_do_create(c, dir_f, f, ri, &dentry->d_name);
-	if (ret)
-		goto fail;
-
-	dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(ri->ctime));
-
-	jffs2_free_raw_inode(ri);
-
-	jffs2_dbg(1, "%s(): Created ino #%lu with mode %o, nlink %d(%d). nrpages %ld\n",
-		  __func__, inode->i_ino, inode->i_mode, inode->i_nlink,
-		  f->inocache->pino_nlink, inode->i_mapping->nrpages);
-
-	d_instantiate_new(dentry, inode);
-	return 0;
-
- fail:
-	iget_failed(inode);
-	jffs2_free_raw_inode(ri);
-	return ret;
+	return inode;
 }
 
-/***********************************************************************/
-
-
-static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
+int jffs2_unlink(struct jffs2_inode *dir_i, struct jffs2_inode *d_inode, const unsigned char *d_name)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
 	struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
-	struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(d_inode(dentry));
+	struct jffs2_inode_info *dead_f = JFFS2_INODE_INFO(d_inode);
 	int ret;
-	uint32_t now = JFFS2_NOW();
+	uint32_t now = Jffs2CurSec();
 
-	ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
-			      dentry->d_name.len, dead_f, now);
+	ret = jffs2_do_unlink(c, dir_f, (const char *)d_name,
+		strlen((char *)d_name), dead_f, now);
 	if (dead_f->inocache)
-		set_nlink(d_inode(dentry), dead_f->inocache->pino_nlink);
+		d_inode->i_nlink = dead_f->inocache->pino_nlink;
 	if (!ret)
-		dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
+		dir_i->i_mtime = dir_i->i_ctime = now;
 	return ret;
 }
-/***********************************************************************/
 
-
-static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct dentry *dentry)
+int jffs2_link(struct jffs2_inode *old_d_inode, struct jffs2_inode *dir_i, const unsigned char *d_name)
 {
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dentry->d_sb);
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(old_dentry));
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(old_d_inode->i_sb);
+	struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_d_inode);
 	struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
 	int ret;
 	uint8_t type;
 	uint32_t now;
 
-	/* Don't let people make hard links to bad inodes. */
-	if (!f->inocache)
-		return -EIO;
-
-	if (d_is_dir(old_dentry))
-		return -EPERM;
-
 	/* XXX: This is ugly */
-	type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12;
+	type = (old_d_inode->i_mode & S_IFMT) >> 12;
 	if (!type) type = DT_REG;
 
-	now = JFFS2_NOW();
-	ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, dentry->d_name.name, dentry->d_name.len, now);
+	now = Jffs2CurSec();
+	ret = jffs2_do_link(c, dir_f, f->inocache->ino, type, (const char *)d_name,
+						strlen((char *)d_name), now);
 
 	if (!ret) {
 		mutex_lock(&f->sem);
-		set_nlink(d_inode(old_dentry), ++f->inocache->pino_nlink);
+		old_d_inode->i_nlink = ++f->inocache->pino_nlink;
 		mutex_unlock(&f->sem);
-		d_instantiate(dentry, d_inode(old_dentry));
-		dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
-		ihold(d_inode(old_dentry));
+		dir_i->i_mtime = dir_i->i_ctime = now;
 	}
 	return ret;
 }
 
-/***********************************************************************/
-
-static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char *target)
+int jffs2_symlink(struct jffs2_inode *dir_i, struct jffs2_inode **d_inode, const unsigned char *d_name, const char *target)
 {
 	struct jffs2_inode_info *f, *dir_f;
 	struct jffs2_sb_info *c;
-	struct inode *inode;
+	struct jffs2_inode *inode;
 	struct jffs2_raw_inode *ri;
 	struct jffs2_raw_dirent *rd;
 	struct jffs2_full_dnode *fn;
@@ -304,7 +132,7 @@ static int jffs2_symlink (struct inode *
 	/* Try to reserve enough space for both node and dirent.
 	 * Just the node will do for now, though
 	 */
-	namelen = dentry->d_name.len;
+	namelen = strlen((char *)d_name);
 	ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &alloclen,
 				  ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
 
@@ -321,8 +149,6 @@ static int jffs2_symlink (struct inode *
 		return PTR_ERR(inode);
 	}
 
-	inode->i_op = &jffs2_symlink_inode_operations;
-
 	f = JFFS2_INODE_INFO(inode);
 
 	inode->i_size = targetlen;
@@ -334,7 +160,7 @@ static int jffs2_symlink (struct inode *
 	ri->data_crc = cpu_to_je32(crc32(0, target, targetlen));
 	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 
-	fn = jffs2_write_dnode(c, f, ri, target, targetlen, ALLOC_NORMAL);
+	fn = jffs2_write_dnode(c, f, ri, (const unsigned char *)target, targetlen, ALLOC_NORMAL);
 
 	jffs2_free_raw_inode(ri);
 
@@ -347,7 +173,8 @@ static int jffs2_symlink (struct inode *
 	}
 
 	/* We use f->target field to store the target path. */
-	f->target = kmemdup(target, targetlen + 1, GFP_KERNEL);
+
+	f->target = (unsigned char *)malloc(targetlen + 1);
 	if (!f->target) {
 		pr_warn("Can't allocate %d bytes of memory\n", targetlen + 1);
 		mutex_unlock(&f->sem);
@@ -355,7 +182,15 @@ static int jffs2_symlink (struct inode *
 		ret = -ENOMEM;
 		goto fail;
 	}
-	inode->i_link = f->target;
+
+	ret = LOS_CopyToKernel((char *)f->target, targetlen + 1, target, targetlen + 1);
+	if (ret != EOK) {
+		(void)free(f->target);
+		f->target = NULL;
+		mutex_unlock(&f->sem);
+		jffs2_complete_reservation(c);
+		goto fail;
+	}
 
 	jffs2_dbg(1, "%s(): symlink's target '%s' cached\n",
 		  __func__, (char *)f->target);
@@ -368,14 +203,6 @@ static int jffs2_symlink (struct inode *
 
 	jffs2_complete_reservation(c);
 
-	ret = jffs2_init_security(inode, dir_i, &dentry->d_name);
-	if (ret)
-		goto fail;
-
-	ret = jffs2_init_acl_post(inode);
-	if (ret)
-		goto fail;
-
 	ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
 				  ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
 	if (ret)
@@ -400,13 +227,13 @@ static int jffs2_symlink (struct inode *
 	rd->pino = cpu_to_je32(dir_i->i_ino);
 	rd->version = cpu_to_je32(++dir_f->highest_version);
 	rd->ino = cpu_to_je32(inode->i_ino);
-	rd->mctime = cpu_to_je32(JFFS2_NOW());
+	rd->mctime = cpu_to_je32(Jffs2CurSec());
 	rd->nsize = namelen;
 	rd->type = DT_LNK;
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
-	rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
+	rd->name_crc = cpu_to_je32(crc32(0, (const char *)d_name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
+	fd = jffs2_write_dirent(c, dir_f, rd, (const unsigned char *)d_name, namelen, ALLOC_NORMAL);
 
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally
@@ -418,7 +245,7 @@ static int jffs2_symlink (struct inode *
 		goto fail;
 	}
 
-	dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
+	dir_i->i_mtime = dir_i->i_ctime = je32_to_cpu(rd->mctime);
 
 	jffs2_free_raw_dirent(rd);
 
@@ -429,20 +256,20 @@ static int jffs2_symlink (struct inode *
 	mutex_unlock(&dir_f->sem);
 	jffs2_complete_reservation(c);
 
-	d_instantiate_new(dentry, inode);
+	*d_inode = inode;
 	return 0;
 
  fail:
-	iget_failed(inode);
+	inode->i_nlink = 0;
+	jffs2_iput(inode);
 	return ret;
 }
 
-
-static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, umode_t mode)
+int jffs2_mkdir(struct jffs2_inode *dir_i, const unsigned char *d_name, int mode, struct jffs2_inode **new_i)
 {
 	struct jffs2_inode_info *f, *dir_f;
 	struct jffs2_sb_info *c;
-	struct inode *inode;
+	struct jffs2_inode *inode;
 	struct jffs2_raw_inode *ri;
 	struct jffs2_raw_dirent *rd;
 	struct jffs2_full_dnode *fn;
@@ -450,7 +277,7 @@ static int jffs2_mkdir (struct inode *di
 	int namelen;
 	uint32_t alloclen;
 	int ret;
-
+	mode  &= ~S_IFMT;
 	mode |= S_IFDIR;
 
 	ri = jffs2_alloc_raw_inode();
@@ -462,9 +289,8 @@ static int jffs2_mkdir (struct inode *di
 	/* Try to reserve enough space for both node and dirent.
 	 * Just the node will do for now, though
 	 */
-	namelen = dentry->d_name.len;
-	ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
-				  JFFS2_SUMMARY_INODE_SIZE);
+	namelen = strlen((char *)d_name);
+	ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
 
 	if (ret) {
 		jffs2_free_raw_inode(ri);
@@ -478,14 +304,8 @@ static int jffs2_mkdir (struct inode *di
 		jffs2_complete_reservation(c);
 		return PTR_ERR(inode);
 	}
-
-	inode->i_op = &jffs2_dir_inode_operations;
-	inode->i_fop = &jffs2_dir_operations;
-
 	f = JFFS2_INODE_INFO(inode);
 
-	/* Directories get nlink 2 at start */
-	set_nlink(inode, 2);
 	/* but ic->pino_nlink is the parent ino# */
 	f->inocache->pino_nlink = dir_i->i_ino;
 
@@ -500,6 +320,7 @@ static int jffs2_mkdir (struct inode *di
 		/* Eeek. Wave bye bye */
 		mutex_unlock(&f->sem);
 		jffs2_complete_reservation(c);
+
 		ret = PTR_ERR(fn);
 		goto fail;
 	}
@@ -511,14 +332,6 @@ static int jffs2_mkdir (struct inode *di
 
 	jffs2_complete_reservation(c);
 
-	ret = jffs2_init_security(inode, dir_i, &dentry->d_name);
-	if (ret)
-		goto fail;
-
-	ret = jffs2_init_acl_post(inode);
-	if (ret)
-		goto fail;
-
 	ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
 				  ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
 	if (ret)
@@ -543,13 +356,13 @@ static int jffs2_mkdir (struct inode *di
 	rd->pino = cpu_to_je32(dir_i->i_ino);
 	rd->version = cpu_to_je32(++dir_f->highest_version);
 	rd->ino = cpu_to_je32(inode->i_ino);
-	rd->mctime = cpu_to_je32(JFFS2_NOW());
+	rd->mctime = cpu_to_je32(Jffs2CurSec());
 	rd->nsize = namelen;
 	rd->type = DT_DIR;
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
-	rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
+	rd->name_crc = cpu_to_je32(crc32(0, d_name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
+	fd = jffs2_write_dirent(c, dir_f, rd, d_name, namelen, ALLOC_NORMAL);
 
 	if (IS_ERR(fd)) {
 		/* dirent failed to write. Delete the inode normally
@@ -557,12 +370,12 @@ static int jffs2_mkdir (struct inode *di
 		jffs2_complete_reservation(c);
 		jffs2_free_raw_dirent(rd);
 		mutex_unlock(&dir_f->sem);
+		inode->i_nlink = 0;
 		ret = PTR_ERR(fd);
 		goto fail;
 	}
 
-	dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
-	inc_nlink(dir_i);
+	dir_i->i_mtime = dir_i->i_ctime = je32_to_cpu(rd->mctime);
 
 	jffs2_free_raw_dirent(rd);
 
@@ -572,300 +385,198 @@ static int jffs2_mkdir (struct inode *di
 
 	mutex_unlock(&dir_f->sem);
 	jffs2_complete_reservation(c);
+	*new_i = inode;
 
-	d_instantiate_new(dentry, inode);
 	return 0;
 
  fail:
-	iget_failed(inode);
+	inode->i_nlink = 0;
+	jffs2_iput(inode);
 	return ret;
 }
 
-static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
+int jffs2_rmdir (struct jffs2_inode *dir_i, struct jffs2_inode *d_inode, const unsigned char *d_name)
 {
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
 	struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(dentry));
+	struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode);
 	struct jffs2_full_dirent *fd;
 	int ret;
-	uint32_t now = JFFS2_NOW();
+	uint32_t now = Jffs2CurSec();
 
-	mutex_lock(&f->sem);
 	for (fd = f->dents ; fd; fd = fd->next) {
 		if (fd->ino) {
-			mutex_unlock(&f->sem);
+			PRINT_ERR("%s-%d: ret=%d\n", __FUNCTION__, __LINE__, ENOTEMPTY);
 			return -ENOTEMPTY;
 		}
 	}
-	mutex_unlock(&f->sem);
 
-	ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
-			      dentry->d_name.len, f, now);
-	if (!ret) {
-		dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
-		clear_nlink(d_inode(dentry));
-		drop_nlink(dir_i);
-	}
+	ret = jffs2_do_unlink(c, dir_f, (const char *)d_name,
+						strlen((char *)d_name), f, now);
+	if (f->inocache)
+		d_inode->i_nlink = f->inocache->pino_nlink;
+	if (!ret)
+		dir_i->i_mtime = dir_i->i_ctime = now;
+
 	return ret;
 }
 
-static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode, dev_t rdev)
+int jffs2_rename (struct jffs2_inode *old_dir_i, struct jffs2_inode *d_inode, const unsigned char *old_d_name,
+		struct jffs2_inode *new_dir_i, const unsigned char *new_d_name)
 {
-	struct jffs2_inode_info *f, *dir_f;
-	struct jffs2_sb_info *c;
-	struct inode *inode;
-	struct jffs2_raw_inode *ri;
-	struct jffs2_raw_dirent *rd;
-	struct jffs2_full_dnode *fn;
-	struct jffs2_full_dirent *fd;
-	int namelen;
-	union jffs2_device_node dev;
-	int devlen = 0;
-	uint32_t alloclen;
 	int ret;
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
+	uint8_t type;
+	uint32_t now;
 
-	ri = jffs2_alloc_raw_inode();
-	if (!ri)
-		return -ENOMEM;
-
-	c = JFFS2_SB_INFO(dir_i->i_sb);
-
-	if (S_ISBLK(mode) || S_ISCHR(mode))
-		devlen = jffs2_encode_dev(&dev, rdev);
+	/* XXX: This is ugly */
+	type = (d_inode->i_mode & S_IFMT) >> 12;
+	if (!type) type = DT_REG;
 
-	/* Try to reserve enough space for both node and dirent.
-	 * Just the node will do for now, though
-	 */
-	namelen = dentry->d_name.len;
-	ret = jffs2_reserve_space(c, sizeof(*ri) + devlen, &alloclen,
-				  ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
+	now = Jffs2CurSec();
+	ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
+				d_inode->i_ino, type,
+				(const char *)new_d_name, strlen((char *)new_d_name), now);
 
-	if (ret) {
-		jffs2_free_raw_inode(ri);
+	if (ret)
 		return ret;
-	}
 
-	inode = jffs2_new_inode(dir_i, mode, ri);
 
-	if (IS_ERR(inode)) {
-		jffs2_free_raw_inode(ri);
-		jffs2_complete_reservation(c);
-		return PTR_ERR(inode);
+	/* If it was a directory we moved, and there was no victim,
+	   increase i_nlink on its new parent */
+	if ((d_inode->i_mode & S_IFMT) == S_IFDIR) {
+		new_dir_i->i_nlink++;
 	}
-	inode->i_op = &jffs2_file_inode_operations;
-	init_special_inode(inode, inode->i_mode, rdev);
 
-	f = JFFS2_INODE_INFO(inode);
-
-	ri->dsize = ri->csize = cpu_to_je32(devlen);
-	ri->totlen = cpu_to_je32(sizeof(*ri) + devlen);
-	ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
-
-	ri->compr = JFFS2_COMPR_NONE;
-	ri->data_crc = cpu_to_je32(crc32(0, &dev, devlen));
-	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
-
-	fn = jffs2_write_dnode(c, f, ri, (char *)&dev, devlen, ALLOC_NORMAL);
+	/* Unlink the original */
+	ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
+				(const char *)old_d_name, strlen((char *)old_d_name), NULL, now);
 
-	jffs2_free_raw_inode(ri);
+	/* We don't touch inode->i_nlink */
 
-	if (IS_ERR(fn)) {
-		/* Eeek. Wave bye bye */
+	if (ret) {
+		/* Oh shit. We really ought to make a single node which can do both atomically */
+		struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode);
+		mutex_lock(&f->sem);
+		if (f->inocache)
+			d_inode->i_nlink = f->inocache->pino_nlink++;
 		mutex_unlock(&f->sem);
-		jffs2_complete_reservation(c);
-		ret = PTR_ERR(fn);
-		goto fail;
-	}
-	/* No data here. Only a metadata node, which will be
-	   obsoleted by the first data write
-	*/
-	f->metadata = fn;
-	mutex_unlock(&f->sem);
-
-	jffs2_complete_reservation(c);
-
-	ret = jffs2_init_security(inode, dir_i, &dentry->d_name);
-	if (ret)
-		goto fail;
-
-	ret = jffs2_init_acl_post(inode);
-	if (ret)
-		goto fail;
-
-	ret = jffs2_reserve_space(c, sizeof(*rd)+namelen, &alloclen,
-				  ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
-	if (ret)
-		goto fail;
 
-	rd = jffs2_alloc_raw_dirent();
-	if (!rd) {
-		/* Argh. Now we treat it like a normal delete */
-		jffs2_complete_reservation(c);
-		ret = -ENOMEM;
-		goto fail;
+		pr_notice("%s(): Link succeeded, unlink failed (err %d). You now have a hard link\n",
+			  __func__, ret);
+		/* Might as well let the VFS know */
+		new_dir_i->i_mtime = new_dir_i->i_ctime = now;
+		return ret;
 	}
 
-	dir_f = JFFS2_INODE_INFO(dir_i);
-	mutex_lock(&dir_f->sem);
 
-	rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
-	rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
-	rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
-	rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
+	new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = now;
 
-	rd->pino = cpu_to_je32(dir_i->i_ino);
-	rd->version = cpu_to_je32(++dir_f->highest_version);
-	rd->ino = cpu_to_je32(inode->i_ino);
-	rd->mctime = cpu_to_je32(JFFS2_NOW());
-	rd->nsize = namelen;
+	return 0;
+}
 
-	/* XXX: This is ugly. */
-	rd->type = (mode & S_IFMT) >> 12;
+int jffs2_create(struct jffs2_inode *dir_i, const unsigned char *d_name, int mode,
+		struct jffs2_inode **new_i)
+{
+	struct jffs2_raw_inode *ri;
+	struct jffs2_inode_info *f, *dir_f;
+	struct jffs2_sb_info *c;
+	struct jffs2_inode *inode;
+	int ret;
+	mode  &= ~S_IFMT;
+	mode |= S_IFREG;
+	ri = jffs2_alloc_raw_inode();
+	if (!ri)
+		return -ENOMEM;
 
-	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
-	rd->name_crc = cpu_to_je32(crc32(0, dentry->d_name.name, namelen));
+	c = JFFS2_SB_INFO(dir_i->i_sb);
 
-	fd = jffs2_write_dirent(c, dir_f, rd, dentry->d_name.name, namelen, ALLOC_NORMAL);
+	D1(printk(KERN_DEBUG "jffs2_create()\n"));
+	inode = jffs2_new_inode(dir_i, mode, ri);
 
-	if (IS_ERR(fd)) {
-		/* dirent failed to write. Delete the inode normally
-		   as if it were the final unlink() */
-		jffs2_complete_reservation(c);
-		jffs2_free_raw_dirent(rd);
-		mutex_unlock(&dir_f->sem);
-		ret = PTR_ERR(fd);
-		goto fail;
+	if (IS_ERR(inode)) {
+		D1(printk(KERN_DEBUG "jffs2_new_inode() failed, error:%ld\n", PTR_ERR(inode)));
+		jffs2_free_raw_inode(ri);
+		return PTR_ERR(inode);
 	}
 
-	dir_i->i_mtime = dir_i->i_ctime = ITIME(je32_to_cpu(rd->mctime));
+	f = JFFS2_INODE_INFO(inode);
+	dir_f = JFFS2_INODE_INFO(dir_i);
 
-	jffs2_free_raw_dirent(rd);
+	/* jffs2_do_create() will want to lock it, _after_ reserving
+	   space and taking c-alloc_sem. If we keep it locked here,
+	   lockdep gets unhappy (although it's a false positive;
+	   nothing else will be looking at this inode yet so there's
+	   no chance of AB-BA deadlock involving its f->sem). */
+	mutex_unlock(&f->sem);
+	ret = jffs2_do_create(c, dir_f, f, ri,
+				(const char *)d_name,
+				strlen((char *)d_name));
 
-	/* Link the fd into the inode's list, obsoleting an old
-	   one if necessary. */
-	jffs2_add_fd_to_list(c, fd, &dir_f->dents);
+	if (ret) {
+		inode->i_nlink = 0;
+		jffs2_iput(inode);
+		jffs2_free_raw_inode(ri);
+		return ret;
+	}
 
-	mutex_unlock(&dir_f->sem);
-	jffs2_complete_reservation(c);
+	jffs2_free_raw_inode(ri);
 
-	d_instantiate_new(dentry, inode);
+	D1(printk(KERN_DEBUG "jffs2_create: Created ino #%lu with mode %o, nlink %d(%d)\n",
+		inode->i_ino, inode->i_mode, inode->i_nlink, f->inocache->pino_nlink));
+	*new_i = inode;
 	return 0;
+}
 
- fail:
-	iget_failed(inode);
-	return ret;
+static __inline void fill_name(char *dst_name, int nlen, const unsigned char *name, int namlen)
+{
+	int len = nlen < namlen ? nlen : namlen;
+	(void)memcpy_s(dst_name, nlen, name, len);
+	dst_name[len] = '\0';
 }
 
-static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
-			 struct inode *new_dir_i, struct dentry *new_dentry,
-			 unsigned int flags)
+int jffs2_readdir(struct jffs2_inode *inode, off_t *offset, off_t *int_off, struct dirent *ent)
 {
-	int ret;
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
-	struct jffs2_inode_info *victim_f = NULL;
-	uint8_t type;
-	uint32_t now;
+	struct jffs2_inode_info *f;
+	struct jffs2_full_dirent *fd;
+	off_t curofs = 0;
 
-	if (flags & ~RENAME_NOREPLACE)
-		return -EINVAL;
+	f = JFFS2_INODE_INFO(inode);
 
-	/* The VFS will check for us and prevent trying to rename a
-	 * file over a directory and vice versa, but if it's a directory,
-	 * the VFS can't check whether the victim is empty. The filesystem
-	 * needs to do that for itself.
-	 */
-	if (d_really_is_positive(new_dentry)) {
-		victim_f = JFFS2_INODE_INFO(d_inode(new_dentry));
-		if (d_is_dir(new_dentry)) {
-			struct jffs2_full_dirent *fd;
-
-			mutex_lock(&victim_f->sem);
-			for (fd = victim_f->dents; fd; fd = fd->next) {
-				if (fd->ino) {
-					mutex_unlock(&victim_f->sem);
-					return -ENOTEMPTY;
-				}
-			}
-			mutex_unlock(&victim_f->sem);
+	mutex_lock(&f->sem);
+	for (fd = f->dents; fd; fd = fd->next) {
+		if (curofs++ < *int_off) {
+			D2(printk
+				(KERN_DEBUG
+				"Skipping dirent: \"%s\", ino #%u, type %d, because curofs %ld < offset %ld\n",
+				fd->name, fd->ino, fd->type, curofs, offset));
+			continue;
 		}
-	}
-
-	/* XXX: We probably ought to alloc enough space for
-	   both nodes at the same time. Writing the new link,
-	   then getting -ENOSPC, is quite bad :)
-	*/
-
-	/* Make a hard link */
-
-	/* XXX: This is ugly */
-	type = (d_inode(old_dentry)->i_mode & S_IFMT) >> 12;
-	if (!type) type = DT_REG;
-
-	now = JFFS2_NOW();
-	ret = jffs2_do_link(c, JFFS2_INODE_INFO(new_dir_i),
-			    d_inode(old_dentry)->i_ino, type,
-			    new_dentry->d_name.name, new_dentry->d_name.len, now);
-
-	if (ret)
-		return ret;
-
-	if (victim_f) {
-		/* There was a victim. Kill it off nicely */
-		if (d_is_dir(new_dentry))
-			clear_nlink(d_inode(new_dentry));
-		else
-			drop_nlink(d_inode(new_dentry));
-		/* Don't oops if the victim was a dirent pointing to an
-		   inode which didn't exist. */
-		if (victim_f->inocache) {
-			mutex_lock(&victim_f->sem);
-			if (d_is_dir(new_dentry))
-				victim_f->inocache->pino_nlink = 0;
-			else
-				victim_f->inocache->pino_nlink--;
-			mutex_unlock(&victim_f->sem);
+		if (!fd->ino) {
+			D2(printk (KERN_DEBUG "Skipping deletion dirent \"%s\"\n", fd->name));
+			(*int_off)++;
+			continue;
 		}
-	}
 
-	/* If it was a directory we moved, and there was no victim,
-	   increase i_nlink on its new parent */
-	if (d_is_dir(old_dentry) && !victim_f)
-		inc_nlink(new_dir_i);
-
-	/* Unlink the original */
-	ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
-			      old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
-
-	/* We don't touch inode->i_nlink */
-
-	if (ret) {
-		/* Oh shit. We really ought to make a single node which can do both atomically */
-		struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(old_dentry));
-		mutex_lock(&f->sem);
-		inc_nlink(d_inode(old_dentry));
-		if (f->inocache && !d_is_dir(old_dentry))
-			f->inocache->pino_nlink++;
-		mutex_unlock(&f->sem);
+		D2(printk
+			(KERN_DEBUG "%s-%d: Dirent %ld: \"%s\", ino #%u, type %d\n", __FUNCTION__, __LINE__, offset,
+			fd->name, fd->ino, fd->type));
+		fill_name(ent->d_name, sizeof(ent->d_name) - 1, fd->name, strlen((char *)fd->name));
+		ent->d_type = fd->type;
+		ent->d_off = ++(*offset);
+		ent->d_reclen = (uint16_t)sizeof(struct dirent);
 
-		pr_notice("%s(): Link succeeded, unlink failed (err %d). You now have a hard link\n",
-			  __func__, ret);
-		/*
-		 * We can't keep the target in dcache after that.
-		 * For one thing, we can't afford dentry aliases for directories.
-		 * For another, if there was a victim, we _can't_ set new inode
-		 * for that sucker and we have to trigger mount eviction - the
-		 * caller won't do it on its own since we are returning an error.
-		 */
-		d_invalidate(new_dentry);
-		new_dir_i->i_mtime = new_dir_i->i_ctime = ITIME(now);
-		return ret;
+		(*int_off)++;
+		break;
 	}
 
-	if (d_is_dir(old_dentry))
-		drop_nlink(old_dir_i);
+	mutex_unlock(&f->sem);
 
-	new_dir_i->i_mtime = new_dir_i->i_ctime = old_dir_i->i_mtime = old_dir_i->i_ctime = ITIME(now);
+	if (fd == NULL) {
+		D2(printk(KERN_DEBUG "reached the end of the directory\n"));
+		return ENOENT;
+	}
 
-	return 0;
+	return ENOERR;
 }
 
diff -Nupr old/fs/jffs2/erase.c new/fs/jffs2/erase.c
--- old/fs/jffs2/erase.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/erase.c	2022-05-10 16:09:47.150000000 +0800
@@ -10,16 +10,19 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/mtd/mtd.h>
 #include <linux/compiler.h>
-#include <linux/crc32.h>
 #include <linux/sched.h>
 #include <linux/pagemap.h>
+#include "mtd_dev.h"
 #include "nodelist.h"
+#include "los_crc32.h"
+
+struct erase_priv_struct {
+	struct jffs2_eraseblock *jeb;
+	struct jffs2_sb_info *c;
+};
 
 static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
 static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
@@ -29,50 +32,14 @@ static void jffs2_erase_block(struct jff
 			      struct jffs2_eraseblock *jeb)
 {
 	int ret;
-	uint32_t bad_offset;
-#ifdef __ECOS
-       ret = jffs2_flash_erase(c, jeb);
-       if (!ret) {
-	       jffs2_erase_succeeded(c, jeb);
-	       return;
-       }
-       bad_offset = jeb->offset;
-#else /* Linux */
-	struct erase_info *instr;
-
-	jffs2_dbg(1, "%s(): erase block %#08x (range %#08x-%#08x)\n",
-		  __func__,
-		  jeb->offset, jeb->offset, jeb->offset + c->sector_size);
-	instr = kmalloc(sizeof(struct erase_info), GFP_KERNEL);
-	if (!instr) {
-		pr_warn("kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
-		mutex_lock(&c->erase_free_sem);
-		spin_lock(&c->erase_completion_lock);
-		list_move(&jeb->list, &c->erase_pending_list);
-		c->erasing_size -= c->sector_size;
-		c->dirty_size += c->sector_size;
-		jeb->dirty_size = c->sector_size;
-		spin_unlock(&c->erase_completion_lock);
-		mutex_unlock(&c->erase_free_sem);
-		return;
-	}
+	uint64_t bad_offset = 0;
 
-	memset(instr, 0, sizeof(*instr));
-
-	instr->addr = jeb->offset;
-	instr->len = c->sector_size;
-
-	ret = mtd_erase(c->mtd, instr);
+	ret = c->mtd->erase(c->mtd, jeb->offset, c->sector_size, &bad_offset);
 	if (!ret) {
 		jffs2_erase_succeeded(c, jeb);
-		kfree(instr);
 		return;
 	}
 
-	bad_offset = instr->fail_addr;
-	kfree(instr);
-#endif /* __ECOS */
-
 	if (ret == -ENOMEM || ret == -EAGAIN) {
 		/* Erase failed immediately. Refile it on the list */
 		jffs2_dbg(1, "Erase at 0x%08x failed: %d. Refiling on erase_pending_list\n",
@@ -168,29 +135,10 @@ static void jffs2_erase_succeeded(struct
 	jffs2_garbage_collect_trigger(c);
 	spin_unlock(&c->erase_completion_lock);
 	mutex_unlock(&c->erase_free_sem);
-	wake_up(&c->erase_wait);
 }
 
 static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset)
 {
-	/* For NAND, if the failure did not occur at the device level for a
-	   specific physical page, don't bother updating the bad block table. */
-	if (jffs2_cleanmarker_oob(c) && (bad_offset != (uint32_t)MTD_FAIL_ADDR_UNKNOWN)) {
-		/* We had a device-level failure to erase.  Let's see if we've
-		   failed too many times. */
-		if (!jffs2_write_nand_badblock(c, jeb, bad_offset)) {
-			/* We'd like to give this block another try. */
-			mutex_lock(&c->erase_free_sem);
-			spin_lock(&c->erase_completion_lock);
-			list_move(&jeb->list, &c->erase_pending_list);
-			c->erasing_size -= c->sector_size;
-			c->dirty_size += c->sector_size;
-			jeb->dirty_size = c->sector_size;
-			spin_unlock(&c->erase_completion_lock);
-			mutex_unlock(&c->erase_free_sem);
-			return;
-		}
-	}
 
 	mutex_lock(&c->erase_free_sem);
 	spin_lock(&c->erase_completion_lock);
@@ -200,7 +148,6 @@ static void jffs2_erase_failed(struct jf
 	c->nr_erasing_blocks--;
 	spin_unlock(&c->erase_completion_lock);
 	mutex_unlock(&c->erase_free_sem);
-	wake_up(&c->erase_wait);
 }
 
 /* Hmmm. Maybe we should accept the extra space it takes and make
@@ -315,40 +262,8 @@ static int jffs2_block_check_erase(struc
 	void *ebuf;
 	uint32_t ofs;
 	size_t retlen;
-	int ret;
-	unsigned long *wordebuf;
+	int ret = -EIO;
 
-	ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen,
-			&ebuf, NULL);
-	if (ret != -EOPNOTSUPP) {
-		if (ret) {
-			jffs2_dbg(1, "MTD point failed %d\n", ret);
-			goto do_flash_read;
-		}
-		if (retlen < c->sector_size) {
-			/* Don't muck about if it won't let us point to the whole erase sector */
-			jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
-				  retlen);
-			mtd_unpoint(c->mtd, jeb->offset, retlen);
-			goto do_flash_read;
-		}
-		wordebuf = ebuf-sizeof(*wordebuf);
-		retlen /= sizeof(*wordebuf);
-		do {
-		   if (*++wordebuf != ~0)
-			   break;
-		} while(--retlen);
-		mtd_unpoint(c->mtd, jeb->offset, c->sector_size);
-		if (retlen) {
-			pr_warn("Newly-erased block contained word 0x%lx at offset 0x%08tx\n",
-				*wordebuf,
-				jeb->offset +
-				c->sector_size-retlen * sizeof(*wordebuf));
-			return -EIO;
-		}
-		return 0;
-	}
- do_flash_read:
 	ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
 	if (!ebuf) {
 		pr_warn("Failed to allocate page buffer for verifying erase at 0x%08x. Refiling\n",
@@ -364,7 +279,7 @@ static int jffs2_block_check_erase(struc
 
 		*bad_offset = ofs;
 
-		ret = mtd_read(c->mtd, ofs, readlen, &retlen, ebuf);
+		ret = jffs2_flash_read(c, ofs, readlen, &retlen, ebuf);
 		if (ret) {
 			pr_warn("Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n",
 				ofs, ret);
@@ -379,7 +294,7 @@ static int jffs2_block_check_erase(struc
 		}
 		for (i=0; i<readlen; i += sizeof(unsigned long)) {
 			/* It's OK. We know it's properly aligned */
-			unsigned long *datum = ebuf + i;
+			unsigned long *datum = (unsigned long *)((char *)ebuf + i);;
 			if (*datum + 1) {
 				*bad_offset += i;
 				pr_warn("Newly-erased block contained word 0x%lx at offset 0x%08x\n",
@@ -469,7 +384,6 @@ static void jffs2_mark_erased_block(stru
 
 	spin_unlock(&c->erase_completion_lock);
 	mutex_unlock(&c->erase_free_sem);
-	wake_up(&c->erase_wait);
 	return;
 
 filebad:
diff -Nupr old/fs/jffs2/file.c new/fs/jffs2/file.c
--- old/fs/jffs2/file.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/file.c	2022-05-10 09:43:14.250000000 +0800
W
wenfei 已提交
2314
@@ -9,335 +9,30 @@
X
x_xiny 已提交
2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338
  * For licensing information, see the file 'LICENCE' in this directory.
  *
  */
+#include "los_vm_common.h"
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/time.h>
-#include <linux/pagemap.h>
-#include <linux/highmem.h>
-#include <linux/crc32.h>
-#include <linux/jffs2.h>
 #include "nodelist.h"
+#include "vfs_jffs2.h"
 
-static int jffs2_write_end(struct file *filp, struct address_space *mapping,
-			loff_t pos, unsigned len, unsigned copied,
-			struct page *pg, void *fsdata);
-static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
-			loff_t pos, unsigned len, unsigned flags,
-			struct page **pagep, void **fsdata);
-static int jffs2_readpage (struct file *filp, struct page *pg);
W
wenfei 已提交
2339 2340
+static unsigned char gc_buffer[PAGE_SIZE];	//avoids malloc when user may be under memory pressure
 
X
x_xiny 已提交
2341
-int jffs2_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
W
wenfei 已提交
2342 2343 2344 2345 2346
+unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
+				   struct jffs2_inode_info *f,
+				   unsigned long offset,
+				   unsigned long *priv)
 {
X
x_xiny 已提交
2347 2348
-	struct inode *inode = filp->f_mapping->host;
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
W
wenfei 已提交
2349 2350
+	/* FIXME: This works only with one file system mounted at a time */
 	int ret;
X
x_xiny 已提交
2351 2352
-
-	ret = file_write_and_wait_range(filp, start, end);
W
wenfei 已提交
2353 2354 2355
+	ret = jffs2_read_inode_range(c, f, gc_buffer,
+			 offset & ~(PAGE_SIZE-1), PAGE_SIZE);
 	if (ret)
X
x_xiny 已提交
2356
-		return ret;
W
wenfei 已提交
2357
-
X
x_xiny 已提交
2358 2359 2360 2361
-	inode_lock(inode);
-	/* Trigger GC to flush any pending writes for this inode */
-	jffs2_flush_wbuf_gc(c, inode->i_ino);
-	inode_unlock(inode);
W
wenfei 已提交
2362
-
X
x_xiny 已提交
2363 2364
-	return 0;
-}
W
wenfei 已提交
2365
-
X
x_xiny 已提交
2366
-const struct file_operations jffs2_file_operations =
W
wenfei 已提交
2367
-{
X
x_xiny 已提交
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400
-	.llseek =	generic_file_llseek,
-	.open =		generic_file_open,
- 	.read_iter =	generic_file_read_iter,
- 	.write_iter =	generic_file_write_iter,
-	.unlocked_ioctl=jffs2_ioctl,
-	.mmap =		generic_file_readonly_mmap,
-	.fsync =	jffs2_fsync,
-	.splice_read =	generic_file_splice_read,
-	.splice_write = iter_file_splice_write,
-};
-
-/* jffs2_file_inode_operations */
-
-const struct inode_operations jffs2_file_inode_operations =
-{
-	.get_acl =	jffs2_get_acl,
-	.set_acl =	jffs2_set_acl,
-	.setattr =	jffs2_setattr,
-	.listxattr =	jffs2_listxattr,
-};
-
-const struct address_space_operations jffs2_file_address_operations =
-{
-	.readpage =	jffs2_readpage,
-	.write_begin =	jffs2_write_begin,
-	.write_end =	jffs2_write_end,
-};
-
-static int jffs2_do_readpage_nolock (struct inode *inode, struct page *pg)
-{
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
-	unsigned char *pg_buf;
W
wenfei 已提交
2401 2402
-	int ret;
-
X
x_xiny 已提交
2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440
-	jffs2_dbg(2, "%s(): ino #%lu, page at offset 0x%lx\n",
-		  __func__, inode->i_ino, pg->index << PAGE_SHIFT);
-
-	BUG_ON(!PageLocked(pg));
-
-	pg_buf = kmap(pg);
-	/* FIXME: Can kmap fail? */
-
-	ret = jffs2_read_inode_range(c, f, pg_buf, pg->index << PAGE_SHIFT,
-				     PAGE_SIZE);
-
-	if (ret) {
-		ClearPageUptodate(pg);
-		SetPageError(pg);
-	} else {
-		SetPageUptodate(pg);
-		ClearPageError(pg);
-	}
-
-	flush_dcache_page(pg);
-	kunmap(pg);
-
-	jffs2_dbg(2, "readpage finished\n");
-	return ret;
-}
-
-int jffs2_do_readpage_unlock(void *data, struct page *pg)
-{
-	int ret = jffs2_do_readpage_nolock(data, pg);
-	unlock_page(pg);
-	return ret;
-}
-
-
-static int jffs2_readpage (struct file *filp, struct page *pg)
-{
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(pg->mapping->host);
-	int ret;
W
wenfei 已提交
2441
-
X
x_xiny 已提交
2442 2443 2444 2445
-	mutex_lock(&f->sem);
-	ret = jffs2_do_readpage_unlock(pg->mapping->host, pg);
-	mutex_unlock(&f->sem);
-	return ret;
W
wenfei 已提交
2446
+		return ERR_PTR(ret);
X
x_xiny 已提交
2447 2448
+	return gc_buffer;
 }
W
wenfei 已提交
2449
 
X
x_xiny 已提交
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459
-static int jffs2_write_begin(struct file *filp, struct address_space *mapping,
-			loff_t pos, unsigned len, unsigned flags,
-			struct page **pagep, void **fsdata)
+void jffs2_gc_release_page(struct jffs2_sb_info *c,
+			   unsigned char *ptr,
+			   unsigned long *priv)
 {
-	struct page *pg;
-	struct inode *inode = mapping->host;
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
W
wenfei 已提交
2460
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
X
x_xiny 已提交
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
-	pgoff_t index = pos >> PAGE_SHIFT;
-	uint32_t pageofs = index << PAGE_SHIFT;
-	int ret = 0;
-
-	jffs2_dbg(1, "%s()\n", __func__);
-
-	if (pageofs > inode->i_size) {
-		/* Make new hole frag from old EOF to new page */
-		struct jffs2_raw_inode ri;
-		struct jffs2_full_dnode *fn;
-		uint32_t alloc_len;
-
-		jffs2_dbg(1, "Writing new hole frag 0x%x-0x%x between current EOF and new page\n",
-			  (unsigned int)inode->i_size, pageofs);
-
-		ret = jffs2_reserve_space(c, sizeof(ri), &alloc_len,
-					  ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
-		if (ret)
W
wenfei 已提交
2479
-			goto out_err;
X
x_xiny 已提交
2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508
-
-		mutex_lock(&f->sem);
-		memset(&ri, 0, sizeof(ri));
-
-		ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
-		ri.nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
-		ri.totlen = cpu_to_je32(sizeof(ri));
-		ri.hdr_crc = cpu_to_je32(crc32(0, &ri, sizeof(struct jffs2_unknown_node)-4));
-
-		ri.ino = cpu_to_je32(f->inocache->ino);
-		ri.version = cpu_to_je32(++f->highest_version);
-		ri.mode = cpu_to_jemode(inode->i_mode);
-		ri.uid = cpu_to_je16(i_uid_read(inode));
-		ri.gid = cpu_to_je16(i_gid_read(inode));
-		ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
-		ri.atime = ri.ctime = ri.mtime = cpu_to_je32(JFFS2_NOW());
-		ri.offset = cpu_to_je32(inode->i_size);
-		ri.dsize = cpu_to_je32(pageofs - inode->i_size);
-		ri.csize = cpu_to_je32(0);
-		ri.compr = JFFS2_COMPR_ZERO;
-		ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
-		ri.data_crc = cpu_to_je32(0);
-
-		fn = jffs2_write_dnode(c, f, &ri, NULL, 0, ALLOC_NORMAL);
-
-		if (IS_ERR(fn)) {
-			ret = PTR_ERR(fn);
-			jffs2_complete_reservation(c);
-			mutex_unlock(&f->sem);
W
wenfei 已提交
2509
-			goto out_err;
X
x_xiny 已提交
2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523
-		}
-		ret = jffs2_add_full_dnode_to_inode(c, f, fn);
-		if (f->metadata) {
-			jffs2_mark_node_obsolete(c, f->metadata->raw);
-			jffs2_free_full_dnode(f->metadata);
-			f->metadata = NULL;
-		}
-		if (ret) {
-			jffs2_dbg(1, "Eep. add_full_dnode_to_inode() failed in write_begin, returned %d\n",
-				  ret);
-			jffs2_mark_node_obsolete(c, fn->raw);
-			jffs2_free_full_dnode(fn);
-			jffs2_complete_reservation(c);
-			mutex_unlock(&f->sem);
W
wenfei 已提交
2524
-			goto out_err;
X
x_xiny 已提交
2525 2526 2527 2528 2529 2530 2531
-		}
-		jffs2_complete_reservation(c);
-		inode->i_size = pageofs;
-		mutex_unlock(&f->sem);
-	}
-
-	/*
W
wenfei 已提交
2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544
-	 * While getting a page and reading data in, lock c->alloc_sem until
-	 * the page is Uptodate. Otherwise GC task may attempt to read the same
-	 * page in read_cache_page(), which causes a deadlock.
-	 */
-	mutex_lock(&c->alloc_sem);
-	pg = grab_cache_page_write_begin(mapping, index, flags);
-	if (!pg) {
-		ret = -ENOMEM;
-		goto release_sem;
-	}
-	*pagep = pg;
-
-	/*
X
x_xiny 已提交
2545 2546 2547 2548 2549 2550 2551 2552
-	 * Read in the page if it wasn't already present. Cannot optimize away
-	 * the whole page write case until jffs2_write_end can handle the
-	 * case of a short-copy.
-	 */
-	if (!PageUptodate(pg)) {
-		mutex_lock(&f->sem);
-		ret = jffs2_do_readpage_nolock(inode, pg);
-		mutex_unlock(&f->sem);
W
wenfei 已提交
2553 2554 2555 2556 2557
-		if (ret) {
-			unlock_page(pg);
-			put_page(pg);
-			goto release_sem;
-		}
X
x_xiny 已提交
2558 2559 2560
-	}
-	jffs2_dbg(1, "end write_begin(). pg->flags %lx\n", pg->flags);
-
W
wenfei 已提交
2561 2562 2563
-release_sem:
-	mutex_unlock(&c->alloc_sem);
-out_err:
X
x_xiny 已提交
2564
-	return ret;
W
wenfei 已提交
2565 2566
-}
-
X
x_xiny 已提交
2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663
-static int jffs2_write_end(struct file *filp, struct address_space *mapping,
-			loff_t pos, unsigned len, unsigned copied,
-			struct page *pg, void *fsdata)
-{
-	/* Actually commit the write from the page cache page we're looking at.
-	 * For now, we write the full page out each time. It sucks, but it's simple
-	 */
-	struct inode *inode = mapping->host;
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
-	struct jffs2_raw_inode *ri;
-	unsigned start = pos & (PAGE_SIZE - 1);
-	unsigned end = start + copied;
-	unsigned aligned_start = start & ~3;
-	int ret = 0;
-	uint32_t writtenlen = 0;
-
-	jffs2_dbg(1, "%s(): ino #%lu, page at 0x%lx, range %d-%d, flags %lx\n",
-		  __func__, inode->i_ino, pg->index << PAGE_SHIFT,
-		  start, end, pg->flags);
-
-	/* We need to avoid deadlock with page_cache_read() in
-	   jffs2_garbage_collect_pass(). So the page must be
-	   up to date to prevent page_cache_read() from trying
-	   to re-lock it. */
-	BUG_ON(!PageUptodate(pg));
-
-	if (end == PAGE_SIZE) {
-		/* When writing out the end of a page, write out the
-		   _whole_ page. This helps to reduce the number of
-		   nodes in files which have many short writes, like
-		   syslog files. */
-		aligned_start = 0;
-	}
-
-	ri = jffs2_alloc_raw_inode();
-
-	if (!ri) {
-		jffs2_dbg(1, "%s(): Allocation of raw inode failed\n",
-			  __func__);
-		unlock_page(pg);
-		put_page(pg);
-		return -ENOMEM;
-	}
-
-	/* Set the fields that the generic jffs2_write_inode_range() code can't find */
-	ri->ino = cpu_to_je32(inode->i_ino);
-	ri->mode = cpu_to_jemode(inode->i_mode);
-	ri->uid = cpu_to_je16(i_uid_read(inode));
-	ri->gid = cpu_to_je16(i_gid_read(inode));
-	ri->isize = cpu_to_je32((uint32_t)inode->i_size);
-	ri->atime = ri->ctime = ri->mtime = cpu_to_je32(JFFS2_NOW());
-
-	/* In 2.4, it was already kmapped by generic_file_write(). Doesn't
-	   hurt to do it again. The alternative is ifdefs, which are ugly. */
-	kmap(pg);
-
-	ret = jffs2_write_inode_range(c, f, ri, page_address(pg) + aligned_start,
-				      (pg->index << PAGE_SHIFT) + aligned_start,
-				      end - aligned_start, &writtenlen);
-
-	kunmap(pg);
-
-	if (ret) {
-		/* There was an error writing. */
-		SetPageError(pg);
-	}
-
-	/* Adjust writtenlen for the padding we did, so we don't confuse our caller */
-	writtenlen -= min(writtenlen, (start - aligned_start));
-
-	if (writtenlen) {
-		if (inode->i_size < pos + writtenlen) {
-			inode->i_size = pos + writtenlen;
-			inode->i_blocks = (inode->i_size + 511) >> 9;
-
-			inode->i_ctime = inode->i_mtime = ITIME(je32_to_cpu(ri->ctime));
-		}
-	}
-
-	jffs2_free_raw_inode(ri);
-
-	if (start+writtenlen < end) {
-		/* generic_file_write has written more to the page cache than we've
-		   actually written to the medium. Mark the page !Uptodate so that
-		   it gets reread */
-		jffs2_dbg(1, "%s(): Not all bytes written. Marking page !uptodate\n",
-			__func__);
-		SetPageError(pg);
-		ClearPageUptodate(pg);
-	}
-
-	jffs2_dbg(1, "%s() returning %d\n",
-		  __func__, writtenlen > 0 ? writtenlen : ret);
-	unlock_page(pg);
-	put_page(pg);
-	return writtenlen > 0 ? writtenlen : ret;
W
wenfei 已提交
2664 2665
+	/* Do nothing */
 }
X
x_xiny 已提交
2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510
diff -Nupr old/fs/jffs2/fs.c new/fs/jffs2/fs.c
--- old/fs/jffs2/fs.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/fs.c	2022-05-10 16:13:37.830000000 +0800
@@ -10,136 +10,129 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/capability.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/cred.h>
-#include <linux/fs.h>
-#include <linux/fs_context.h>
-#include <linux/list.h>
-#include <linux/mtd/mtd.h>
-#include <linux/pagemap.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/vfs.h>
-#include <linux/crc32.h>
+#include <linux/delay.h>
 #include "nodelist.h"
+#include "os-linux.h"
+#include "los_crc32.h"
+#include "jffs2_hash.h"
+#include "capability_type.h"
+#include "capability_api.h"
 
-static int jffs2_flash_setup(struct jffs2_sb_info *c);
-
-int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
+int jffs2_setattr (struct jffs2_inode *inode, struct IATTR *attr)
 {
 	struct jffs2_full_dnode *old_metadata, *new_metadata;
 	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
 	struct jffs2_raw_inode *ri;
-	union jffs2_device_node dev;
-	unsigned char *mdata = NULL;
-	int mdatalen = 0;
 	unsigned int ivalid;
+	mode_t tmp_mode;
+	uint c_uid = OsCurrUserGet()->effUserID;
+	uint c_gid = OsCurrUserGet()->effGid;
 	uint32_t alloclen;
 	int ret;
 	int alloc_type = ALLOC_NORMAL;
 
 	jffs2_dbg(1, "%s(): ino #%lu\n", __func__, inode->i_ino);
-
-	/* Special cases - we don't want more than one data node
-	   for these types on the medium at any time. So setattr
-	   must read the original data associated with the node
-	   (i.e. the device numbers or the target name) and write
-	   it out again with the appropriate data attached */
-	if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
-		/* For these, we don't actually need to read the old node */
-		mdatalen = jffs2_encode_dev(&dev, inode->i_rdev);
-		mdata = (char *)&dev;
-		jffs2_dbg(1, "%s(): Writing %d bytes of kdev_t\n",
-			  __func__, mdatalen);
-	} else if (S_ISLNK(inode->i_mode)) {
-		mutex_lock(&f->sem);
-		mdatalen = f->metadata->size;
-		mdata = kmalloc(f->metadata->size, GFP_USER);
-		if (!mdata) {
-			mutex_unlock(&f->sem);
-			return -ENOMEM;
-		}
-		ret = jffs2_read_dnode(c, f, f->metadata, mdata, 0, mdatalen);
-		if (ret) {
-			mutex_unlock(&f->sem);
-			kfree(mdata);
-			return ret;
-		}
-		mutex_unlock(&f->sem);
-		jffs2_dbg(1, "%s(): Writing %d bytes of symlink target\n",
-			  __func__, mdatalen);
-	}
-
 	ri = jffs2_alloc_raw_inode();
 	if (!ri) {
-		if (S_ISLNK(inode->i_mode))
-			kfree(mdata);
 		return -ENOMEM;
 	}
 
-	ret = jffs2_reserve_space(c, sizeof(*ri) + mdatalen, &alloclen,
-				  ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
+	ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
+
 	if (ret) {
 		jffs2_free_raw_inode(ri);
-		if (S_ISLNK(inode->i_mode))
-			 kfree(mdata);
 		return ret;
 	}
 	mutex_lock(&f->sem);
-	ivalid = iattr->ia_valid;
+	ivalid = attr->attr_chg_valid;
+	tmp_mode = inode->i_mode;
 
 	ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 	ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
-	ri->totlen = cpu_to_je32(sizeof(*ri) + mdatalen);
-	ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
+	ri->totlen = cpu_to_je32(sizeof(*ri));
+	ri->hdr_crc = cpu_to_je32(crc32(0, ri, (sizeof(struct jffs2_unknown_node)-4)));
 
 	ri->ino = cpu_to_je32(inode->i_ino);
 	ri->version = cpu_to_je32(++f->highest_version);
+	ri->uid = cpu_to_je16(inode->i_uid);
+	ri->gid = cpu_to_je16(inode->i_gid);
+
+	if (ivalid & CHG_UID) {
+		if (((c_uid != inode->i_uid) || (attr->attr_chg_uid != inode->i_uid)) && (!IsCapPermit(CAP_CHOWN))) {
+			jffs2_complete_reservation(c);
+			jffs2_free_raw_inode(ri);
+			mutex_unlock(&f->sem);
+			return -EPERM;
+		} else {
+			ri->uid = cpu_to_je16(attr->attr_chg_uid);
+		}
+	}
+
+	if (ivalid & CHG_GID) {
+		if (((c_gid != inode->i_gid) || (attr->attr_chg_gid != inode->i_gid)) && (!IsCapPermit(CAP_CHOWN))) {
+			jffs2_complete_reservation(c);
+			jffs2_free_raw_inode(ri);
+			mutex_unlock(&f->sem);
+			return -EPERM;
+		} else {
+			ri->gid = cpu_to_je16(attr->attr_chg_gid);
+		}
+	}
 
-	ri->uid = cpu_to_je16((ivalid & ATTR_UID)?
-		from_kuid(&init_user_ns, iattr->ia_uid):i_uid_read(inode));
-	ri->gid = cpu_to_je16((ivalid & ATTR_GID)?
-		from_kgid(&init_user_ns, iattr->ia_gid):i_gid_read(inode));
-
-	if (ivalid & ATTR_MODE)
-		ri->mode = cpu_to_jemode(iattr->ia_mode);
-	else
-		ri->mode = cpu_to_jemode(inode->i_mode);
+	if (ivalid & CHG_MODE) {
+		if (!IsCapPermit(CAP_FOWNER) && (c_uid != inode->i_uid)) {
+			jffs2_complete_reservation(c);
+			jffs2_free_raw_inode(ri);
+			mutex_unlock(&f->sem);
+			return -EPERM;
+		} else {
+			attr->attr_chg_mode  &= ~S_IFMT; // delete file type
+			tmp_mode &= S_IFMT;
+			tmp_mode = attr->attr_chg_mode | tmp_mode; // add old file type
+		}
+	}
 
+	if (ivalid & CHG_ATIME) {
+		if ((c_uid != inode->i_uid) || (attr->attr_chg_uid != inode->i_uid)) {
+			return -EPERM;
+		} else {
+			ri->atime = cpu_to_je32(attr->attr_chg_atime);
+		}
+	} else {
+		ri->atime = cpu_to_je32(inode->i_atime);
+	}
+
+	if (ivalid & CHG_MTIME) {
+		if ((c_uid != inode->i_uid) || (attr->attr_chg_uid != inode->i_uid)) {
+			return -EPERM;
+		} else {
+			ri->mtime = cpu_to_je32(attr->attr_chg_mtime);
+		}
+	} else {
+		ri->mtime = cpu_to_je32(Jffs2CurSec());
+	}
+	ri->mode = cpu_to_jemode(tmp_mode);
 
-	ri->isize = cpu_to_je32((ivalid & ATTR_SIZE)?iattr->ia_size:inode->i_size);
-	ri->atime = cpu_to_je32(I_SEC((ivalid & ATTR_ATIME)?iattr->ia_atime:inode->i_atime));
-	ri->mtime = cpu_to_je32(I_SEC((ivalid & ATTR_MTIME)?iattr->ia_mtime:inode->i_mtime));
-	ri->ctime = cpu_to_je32(I_SEC((ivalid & ATTR_CTIME)?iattr->ia_ctime:inode->i_ctime));
+	ri->isize = cpu_to_je32((ivalid & CHG_SIZE) ? attr->attr_chg_size : inode->i_size);
+	ri->ctime = cpu_to_je32(Jffs2CurSec());
 
 	ri->offset = cpu_to_je32(0);
-	ri->csize = ri->dsize = cpu_to_je32(mdatalen);
+	ri->csize = ri->dsize = cpu_to_je32(0);
 	ri->compr = JFFS2_COMPR_NONE;
-	if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
+	if (ivalid & CHG_SIZE && inode->i_size < attr->attr_chg_size) {
 		/* It's an extension. Make it a hole node */
 		ri->compr = JFFS2_COMPR_ZERO;
-		ri->dsize = cpu_to_je32(iattr->ia_size - inode->i_size);
+		ri->dsize = cpu_to_je32(attr->attr_chg_size - inode->i_size);
 		ri->offset = cpu_to_je32(inode->i_size);
-	} else if (ivalid & ATTR_SIZE && !iattr->ia_size) {
+	} else if (ivalid & CHG_SIZE && !attr->attr_chg_size) {
 		/* For truncate-to-zero, treat it as deletion because
 		   it'll always be obsoleting all previous nodes */
 		alloc_type = ALLOC_DELETION;
 	}
-	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
-	if (mdatalen)
-		ri->data_crc = cpu_to_je32(crc32(0, mdata, mdatalen));
-	else
-		ri->data_crc = cpu_to_je32(0);
-
-	new_metadata = jffs2_write_dnode(c, f, ri, mdata, mdatalen, alloc_type);
-	if (S_ISLNK(inode->i_mode))
-		kfree(mdata);
-
+	ri->node_crc = cpu_to_je32(crc32(0, ri, (sizeof(*ri)-8)));
+	ri->data_crc = cpu_to_je32(0);
+	new_metadata = jffs2_write_dnode(c, f, ri, NULL, 0, alloc_type);
 	if (IS_ERR(new_metadata)) {
 		jffs2_complete_reservation(c);
 		jffs2_free_raw_inode(ri);
@@ -147,23 +140,20 @@ int jffs2_do_setattr (struct inode *inod
 		return PTR_ERR(new_metadata);
 	}
 	/* It worked. Update the inode */
-	inode->i_atime = ITIME(je32_to_cpu(ri->atime));
-	inode->i_ctime = ITIME(je32_to_cpu(ri->ctime));
-	inode->i_mtime = ITIME(je32_to_cpu(ri->mtime));
+	inode->i_atime = je32_to_cpu(ri->atime);
+	inode->i_ctime = je32_to_cpu(ri->ctime);
+	inode->i_mtime = je32_to_cpu(ri->mtime);
 	inode->i_mode = jemode_to_cpu(ri->mode);
-	i_uid_write(inode, je16_to_cpu(ri->uid));
-	i_gid_write(inode, je16_to_cpu(ri->gid));
-
+	inode->i_uid = je16_to_cpu(ri->uid);
+	inode->i_gid = je16_to_cpu(ri->gid);
 
 	old_metadata = f->metadata;
+	if (ivalid & CHG_SIZE && inode->i_size > attr->attr_chg_size)
+		jffs2_truncate_fragtree (c, &f->fragtree, attr->attr_chg_size);
 
-	if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size)
-		jffs2_truncate_fragtree (c, &f->fragtree, iattr->ia_size);
-
-	if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
+	if (ivalid & CHG_SIZE && inode->i_size < attr->attr_chg_size) {
 		jffs2_add_full_dnode_to_inode(c, f, new_metadata);
-		inode->i_size = iattr->ia_size;
-		inode->i_blocks = (inode->i_size + 511) >> 9;
+		inode->i_size = attr->attr_chg_size;
 		f->metadata = NULL;
 	} else {
 		f->metadata = new_metadata;
@@ -182,315 +172,201 @@ int jffs2_do_setattr (struct inode *inod
 	   We are protected from a simultaneous write() extending i_size
 	   back past iattr->ia_size, because do_truncate() holds the
 	   generic inode semaphore. */
-	if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
-		truncate_setsize(inode, iattr->ia_size);
-		inode->i_blocks = (inode->i_size + 511) >> 9;
+	if (ivalid & CHG_SIZE && inode->i_size > attr->attr_chg_size) {
+		inode->i_size = attr->attr_chg_size; // truncate_setsize
 	}
 
 	return 0;
 }
 
-int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
+static void jffs2_clear_inode (struct jffs2_inode *inode)
 {
-	struct inode *inode = d_inode(dentry);
-	int rc;
-
-	rc = setattr_prepare(dentry, iattr);
-	if (rc)
-		return rc;
-
-	rc = jffs2_do_setattr(inode, iattr);
-	if (!rc && (iattr->ia_valid & ATTR_MODE))
-		rc = posix_acl_chmod(inode, inode->i_mode);
+	/* We can forget about this inode for now - drop all
+	 *  the nodelists associated with it, etc.
+	 */
+	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
+	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
 
-	return rc;
+	jffs2_do_clear_inode(c, f);
 }
 
-int jffs2_statfs(struct dentry *dentry, struct kstatfs *buf)
+static struct jffs2_inode *ilookup(struct super_block *sb, uint32_t ino)
 {
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(dentry->d_sb);
-	unsigned long avail;
+	struct jffs2_inode *node = NULL;
 
-	buf->f_type = JFFS2_SUPER_MAGIC;
-	buf->f_bsize = 1 << PAGE_SHIFT;
-	buf->f_blocks = c->flash_size >> PAGE_SHIFT;
-	buf->f_files = 0;
-	buf->f_ffree = 0;
-	buf->f_namelen = JFFS2_MAX_NAME_LEN;
-	buf->f_fsid.val[0] = JFFS2_SUPER_MAGIC;
-	buf->f_fsid.val[1] = c->mtd->index;
-
-	spin_lock(&c->erase_completion_lock);
-	avail = c->dirty_size + c->free_size;
-	if (avail > c->sector_size * c->resv_blocks_write)
-		avail -= c->sector_size * c->resv_blocks_write;
-	else
-		avail = 0;
-	spin_unlock(&c->erase_completion_lock);
-
-	buf->f_bavail = buf->f_bfree = avail >> PAGE_SHIFT;
+	if (sb->s_root == NULL) {
+		return NULL;
+	}
 
-	return 0;
+	// Check for this inode in the cache
+	Jffs2NodeLock();
+	(void)Jffs2HashGet(&sb->s_node_hash_lock, &sb->s_node_hash[0], sb, ino, &node);
+	Jffs2NodeUnlock();
+	return node;
 }
 
-
-void jffs2_evict_inode (struct inode *inode)
+struct jffs2_inode *new_inode(struct super_block *sb)
 {
-	/* We can forget about this inode for now - drop all
-	 *  the nodelists associated with it, etc.
-	 */
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
+	struct jffs2_inode *inode = NULL;
 
-	jffs2_dbg(1, "%s(): ino #%lu mode %o\n",
-		  __func__, inode->i_ino, inode->i_mode);
-	truncate_inode_pages_final(&inode->i_data);
-	clear_inode(inode);
-	jffs2_do_clear_inode(c, f);
+	inode = zalloc(sizeof (struct jffs2_inode));
+	if (inode == NULL)
+		return 0;
+
+	D2(PRINTK("malloc new_inode %x ####################################\n",
+		inode));
+
+	inode->i_sb = sb;
+	inode->i_ino = 1;
+	inode->i_nlink = 1;    // Let JFFS2 manage the link count
+	inode->i_size = 0;
+	LOS_ListInit((&(inode->i_hashlist)));
+
+	return inode;
 }
 
-struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
+struct jffs2_inode *jffs2_iget(struct super_block *sb, uint32_t ino)
 {
 	struct jffs2_inode_info *f;
 	struct jffs2_sb_info *c;
 	struct jffs2_raw_inode latest_node;
-	union jffs2_device_node jdev;
-	struct inode *inode;
-	dev_t rdev = 0;
+	struct jffs2_inode *inode;
 	int ret;
 
-	jffs2_dbg(1, "%s(): ino == %lu\n", __func__, ino);
-
-	inode = iget_locked(sb, ino);
-	if (!inode)
-		return ERR_PTR(-ENOMEM);
-	if (!(inode->i_state & I_NEW))
+	Jffs2NodeLock();
+	inode = ilookup(sb, ino);
+	if (inode) {
+		Jffs2NodeUnlock();
 		return inode;
+	}
+	inode = new_inode(sb);
+	if (inode == NULL) {
+		Jffs2NodeUnlock();
+		return (struct jffs2_inode *)-ENOMEM;
+	}
 
+	inode->i_ino = ino;
 	f = JFFS2_INODE_INFO(inode);
 	c = JFFS2_SB_INFO(inode->i_sb);
 
-	jffs2_init_inode_info(f);
-	mutex_lock(&f->sem);
+	(void)mutex_init(&f->sem);
+	(void)mutex_lock(&f->sem);
 
 	ret = jffs2_do_read_inode(c, f, inode->i_ino, &latest_node);
-	if (ret)
-		goto error;
+	if (ret) {
+		(void)mutex_unlock(&f->sem);
+        inode->i_nlink = 0;
+        free(inode);
+		Jffs2NodeUnlock();
+		return (struct jffs2_inode *)ret;
+	}
 
 	inode->i_mode = jemode_to_cpu(latest_node.mode);
-	i_uid_write(inode, je16_to_cpu(latest_node.uid));
-	i_gid_write(inode, je16_to_cpu(latest_node.gid));
+	inode->i_uid = je16_to_cpu(latest_node.uid);
+	inode->i_gid = je16_to_cpu(latest_node.gid);
 	inode->i_size = je32_to_cpu(latest_node.isize);
-	inode->i_atime = ITIME(je32_to_cpu(latest_node.atime));
-	inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime));
-	inode->i_ctime = ITIME(je32_to_cpu(latest_node.ctime));
-
-	set_nlink(inode, f->inocache->pino_nlink);
+	inode->i_atime = je32_to_cpu(latest_node.atime);
+	inode->i_mtime = je32_to_cpu(latest_node.mtime);
+	inode->i_ctime = je32_to_cpu(latest_node.ctime);
+	inode->i_nlink = f->inocache->pino_nlink;
 
-	inode->i_blocks = (inode->i_size + 511) >> 9;
+	(void)mutex_unlock(&f->sem);
 
-	switch (inode->i_mode & S_IFMT) {
-
-	case S_IFLNK:
-		inode->i_op = &jffs2_symlink_inode_operations;
-		inode->i_link = f->target;
-		break;
-
-	case S_IFDIR:
-	{
-		struct jffs2_full_dirent *fd;
-		set_nlink(inode, 2); /* parent and '.' */
-
-		for (fd=f->dents; fd; fd = fd->next) {
-			if (fd->type == DT_DIR && fd->ino)
-				inc_nlink(inode);
-		}
-		/* Root dir gets i_nlink 3 for some reason */
-		if (inode->i_ino == 1)
-			inc_nlink(inode);
-
-		inode->i_op = &jffs2_dir_inode_operations;
-		inode->i_fop = &jffs2_dir_operations;
-		break;
-	}
-	case S_IFREG:
-		inode->i_op = &jffs2_file_inode_operations;
-		inode->i_fop = &jffs2_file_operations;
-		inode->i_mapping->a_ops = &jffs2_file_address_operations;
-		inode->i_mapping->nrpages = 0;
-		break;
-
-	case S_IFBLK:
-	case S_IFCHR:
-		/* Read the device numbers from the media */
-		if (f->metadata->size != sizeof(jdev.old_id) &&
-		    f->metadata->size != sizeof(jdev.new_id)) {
-			pr_notice("Device node has strange size %d\n",
-				  f->metadata->size);
-			goto error_io;
-		}
-		jffs2_dbg(1, "Reading device numbers from flash\n");
-		ret = jffs2_read_dnode(c, f, f->metadata, (char *)&jdev, 0, f->metadata->size);
-		if (ret < 0) {
-			/* Eep */
-			pr_notice("Read device numbers for inode %lu failed\n",
-				  (unsigned long)inode->i_ino);
-			goto error;
-		}
-		if (f->metadata->size == sizeof(jdev.old_id))
-			rdev = old_decode_dev(je16_to_cpu(jdev.old_id));
-		else
-			rdev = new_decode_dev(je32_to_cpu(jdev.new_id));
-		fallthrough;
-
-	case S_IFSOCK:
-	case S_IFIFO:
-		inode->i_op = &jffs2_file_inode_operations;
-		init_special_inode(inode, inode->i_mode, rdev);
-		break;
-
-	default:
-		pr_warn("%s(): Bogus i_mode %o for ino %lu\n",
-			__func__, inode->i_mode, (unsigned long)inode->i_ino);
-	}
-
-	mutex_unlock(&f->sem);
+	(void)Jffs2HashInsert(&sb->s_node_hash_lock, &sb->s_node_hash[0], inode, ino);
 
 	jffs2_dbg(1, "jffs2_read_inode() returning\n");
-	unlock_new_inode(inode);
-	return inode;
-
-error_io:
-	ret = -EIO;
-error:
-	mutex_unlock(&f->sem);
-	iget_failed(inode);
-	return ERR_PTR(ret);
-}
+	Jffs2NodeUnlock();
 
-void jffs2_dirty_inode(struct inode *inode, int flags)
-{
-	struct iattr iattr;
-
-	if (!(inode->i_state & I_DIRTY_DATASYNC)) {
-		jffs2_dbg(2, "%s(): not calling setattr() for ino #%lu\n",
-			  __func__, inode->i_ino);
-		return;
-	}
-
-	jffs2_dbg(1, "%s(): calling setattr() for ino #%lu\n",
-		  __func__, inode->i_ino);
-
-	iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME;
-	iattr.ia_mode = inode->i_mode;
-	iattr.ia_uid = inode->i_uid;
-	iattr.ia_gid = inode->i_gid;
-	iattr.ia_atime = inode->i_atime;
-	iattr.ia_mtime = inode->i_mtime;
-	iattr.ia_ctime = inode->i_ctime;
-
-	jffs2_do_setattr(inode, &iattr);
+	return inode;
 }
 
-int jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc)
-{
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-
-	if (c->flags & JFFS2_SB_FLAG_RO && !sb_rdonly(sb))
-		return -EROFS;
 
-	/* We stop if it was running, then restart if it needs to.
-	   This also catches the case where it was stopped and this
-	   is just a remount to restart it.
-	   Flush the writebuffer, if neccecary, else we loose it */
-	if (!sb_rdonly(sb)) {
-		jffs2_stop_garbage_collect_thread(c);
-		mutex_lock(&c->alloc_sem);
-		jffs2_flush_wbuf_pad(c);
-		mutex_unlock(&c->alloc_sem);
-	}
+// -------------------------------------------------------------------------
+// Decrement the reference count on an inode. If this makes the ref count
+// zero, then this inode can be freed.
+
+int jffs2_iput(struct jffs2_inode *i)
+{
+	// Called in jffs2_find
+	// (and jffs2_open and jffs2_ops_mkdir?)
+	// super.c jffs2_fill_super,
+	// and gc.c jffs2_garbage_collect_pass
+	struct jffs2_inode_info *f = NULL;
+
+	Jffs2NodeLock();
+	if (!i || i->i_nlink) {
+		// and let it fault...
+		Jffs2NodeUnlock();
+		return -EBUSY;
+	}
+
+	jffs2_clear_inode(i);
+	f = JFFS2_INODE_INFO(i);
+	(void)mutex_destroy(&(f->sem));
+	(void)Jffs2HashRemove(&i->i_sb->s_node_hash_lock, i);
+	(void)memset_s(i, sizeof(*i), 0x5a, sizeof(*i));
+	free(i);
+	Jffs2NodeUnlock();
 
-	if (!(fc->sb_flags & SB_RDONLY))
-		jffs2_start_garbage_collect_thread(c);
-
-	fc->sb_flags |= SB_NOATIME;
 	return 0;
 }
 
+
 /* jffs2_new_inode: allocate a new inode and inocache, add it to the hash,
    fill in the raw_inode while you're at it. */
-struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_raw_inode *ri)
+struct jffs2_inode *jffs2_new_inode (struct jffs2_inode *dir_i, int mode, struct jffs2_raw_inode *ri)
 {
-	struct inode *inode;
+	struct jffs2_inode *inode;
 	struct super_block *sb = dir_i->i_sb;
 	struct jffs2_sb_info *c;
 	struct jffs2_inode_info *f;
 	int ret;
 
-	jffs2_dbg(1, "%s(): dir_i %ld, mode 0x%x\n",
-		  __func__, dir_i->i_ino, mode);
-
 	c = JFFS2_SB_INFO(sb);
 
+	Jffs2NodeLock();
 	inode = new_inode(sb);
 
 	if (!inode)
-		return ERR_PTR(-ENOMEM);
+		return (struct jffs2_inode *)-ENOMEM;
 
 	f = JFFS2_INODE_INFO(inode);
-	jffs2_init_inode_info(f);
-	mutex_lock(&f->sem);
+	(void)mutex_init(&f->sem);
+	(void)mutex_lock(&f->sem);;
 
 	memset(ri, 0, sizeof(*ri));
 	/* Set OS-specific defaults for new inodes */
-	ri->uid = cpu_to_je16(from_kuid(&init_user_ns, current_fsuid()));
+	ri->uid = cpu_to_je16(OsCurrUserGet()->effUserID);
+	ri->gid = cpu_to_je16(OsCurrUserGet()->effGid);
 
-	if (dir_i->i_mode & S_ISGID) {
-		ri->gid = cpu_to_je16(i_gid_read(dir_i));
-		if (S_ISDIR(mode))
-			mode |= S_ISGID;
-	} else {
-		ri->gid = cpu_to_je16(from_kgid(&init_user_ns, current_fsgid()));
-	}
-
-	/* POSIX ACLs have to be processed now, at least partly.
-	   The umask is only applied if there's no default ACL */
-	ret = jffs2_init_acl_pre(dir_i, inode, &mode);
-	if (ret) {
-		mutex_unlock(&f->sem);
-		make_bad_inode(inode);
-		iput(inode);
-		return ERR_PTR(ret);
-	}
 	ret = jffs2_do_new_inode (c, f, mode, ri);
 	if (ret) {
-		mutex_unlock(&f->sem);
-		make_bad_inode(inode);
-		iput(inode);
-		return ERR_PTR(ret);
+		mutex_unlock(&(f->sem));
+		jffs2_clear_inode(inode);
+		(void)mutex_destroy(&(f->sem));
+		(void)memset_s(inode, sizeof(*inode), 0x6a, sizeof(*inode));
+		free(inode);
+		Jffs2NodeUnlock();
+		return (struct jffs2_inode *)ret;
+
 	}
-	set_nlink(inode, 1);
+	inode->i_nlink = 1;
 	inode->i_ino = je32_to_cpu(ri->ino);
 	inode->i_mode = jemode_to_cpu(ri->mode);
-	i_gid_write(inode, je16_to_cpu(ri->gid));
-	i_uid_write(inode, je16_to_cpu(ri->uid));
-	inode->i_atime = inode->i_ctime = inode->i_mtime = current_time(inode);
-	ri->atime = ri->mtime = ri->ctime = cpu_to_je32(I_SEC(inode->i_mtime));
+	inode->i_gid = je16_to_cpu(ri->gid);
+	inode->i_uid = je16_to_cpu(ri->uid);
+	inode->i_atime = inode->i_ctime = inode->i_mtime = Jffs2CurSec();
+	ri->atime = ri->mtime = ri->ctime = cpu_to_je32(inode->i_mtime);
 
-	inode->i_blocks = 0;
 	inode->i_size = 0;
 
-	if (insert_inode_locked(inode) < 0) {
-		mutex_unlock(&f->sem);
-		make_bad_inode(inode);
-		iput(inode);
-		return ERR_PTR(-EINVAL);
-	}
+	(void)Jffs2HashInsert(&sb->s_node_hash_lock, &sb->s_node_hash[0], inode, inode->i_ino);
+	Jffs2NodeUnlock();
 
 	return inode;
 }
 
-static int calculate_inocache_hashsize(uint32_t flash_size)
+int calculate_inocache_hashsize(uint32_t flash_size)
 {
 	/*
 	 * Pick a inocache hash size based on the size of the medium.
@@ -510,117 +386,17 @@ static int calculate_inocache_hashsize(u
 	return hashsize;
 }
 
-int jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc)
-{
-	struct jffs2_sb_info *c;
-	struct inode *root_i;
-	int ret;
-	size_t blocks;
-
-	c = JFFS2_SB_INFO(sb);
-
-	/* Do not support the MLC nand */
-	if (c->mtd->type == MTD_MLCNANDFLASH)
-		return -EINVAL;
-
-#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
-	if (c->mtd->type == MTD_NANDFLASH) {
-		errorf(fc, "Cannot operate on NAND flash unless jffs2 NAND support is compiled in");
-		return -EINVAL;
-	}
-	if (c->mtd->type == MTD_DATAFLASH) {
-		errorf(fc, "Cannot operate on DataFlash unless jffs2 DataFlash support is compiled in");
-		return -EINVAL;
-	}
-#endif
-
-	c->flash_size = c->mtd->size;
-	c->sector_size = c->mtd->erasesize;
-	blocks = c->flash_size / c->sector_size;
-
-	/*
-	 * Size alignment check
-	 */
-	if ((c->sector_size * blocks) != c->flash_size) {
-		c->flash_size = c->sector_size * blocks;
-		infof(fc, "Flash size not aligned to erasesize, reducing to %dKiB",
-		      c->flash_size / 1024);
-	}
-
-	if (c->flash_size < 5*c->sector_size) {
-		errorf(fc, "Too few erase blocks (%d)",
-		       c->flash_size / c->sector_size);
-		return -EINVAL;
-	}
-
-	c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
-
-	/* NAND (or other bizarre) flash... do setup accordingly */
-	ret = jffs2_flash_setup(c);
-	if (ret)
-		return ret;
-
-	c->inocache_hashsize = calculate_inocache_hashsize(c->flash_size);
-	c->inocache_list = kcalloc(c->inocache_hashsize, sizeof(struct jffs2_inode_cache *), GFP_KERNEL);
-	if (!c->inocache_list) {
-		ret = -ENOMEM;
-		goto out_wbuf;
-	}
-
-	jffs2_init_xattr_subsystem(c);
-
-	if ((ret = jffs2_do_mount_fs(c)))
-		goto out_inohash;
-
-	jffs2_dbg(1, "%s(): Getting root inode\n", __func__);
-	root_i = jffs2_iget(sb, 1);
-	if (IS_ERR(root_i)) {
-		jffs2_dbg(1, "get root inode failed\n");
-		ret = PTR_ERR(root_i);
-		goto out_root;
-	}
-
-	ret = -ENOMEM;
-
-	jffs2_dbg(1, "%s(): d_make_root()\n", __func__);
-	sb->s_root = d_make_root(root_i);
-	if (!sb->s_root)
-		goto out_root;
-
-	sb->s_maxbytes = 0xFFFFFFFF;
-	sb->s_blocksize = PAGE_SIZE;
-	sb->s_blocksize_bits = PAGE_SHIFT;
-	sb->s_magic = JFFS2_SUPER_MAGIC;
-	sb->s_time_min = 0;
-	sb->s_time_max = U32_MAX;
-
-	if (!sb_rdonly(sb))
-		jffs2_start_garbage_collect_thread(c);
-	return 0;
-
-out_root:
-	jffs2_free_ino_caches(c);
-	jffs2_free_raw_node_refs(c);
-	kvfree(c->blocks);
- out_inohash:
-	jffs2_clear_xattr_subsystem(c);
-	kfree(c->inocache_list);
- out_wbuf:
-	jffs2_flash_cleanup(c);
-
-	return ret;
-}
-
 void jffs2_gc_release_inode(struct jffs2_sb_info *c,
-				   struct jffs2_inode_info *f)
+		   	    struct jffs2_inode_info *f)
 {
-	iput(OFNI_EDONI_2SFFJ(f));
+	struct jffs2_inode *node = OFNI_EDONI_2SFFJ(f);
+	jffs2_iput(node);
 }
 
 struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
 					      int inum, int unlinked)
 {
-	struct inode *inode;
+	struct jffs2_inode *inode;
 	struct jffs2_inode_cache *ic;
 
 	if (unlinked) {
@@ -668,72 +444,9 @@ struct jffs2_inode_info *jffs2_gc_fetch_
 		   Just iget() it, and if read_inode() is necessary that's OK.
 		*/
 		inode = jffs2_iget(OFNI_BS_2SFFJ(c), inum);
-		if (IS_ERR(inode))
-			return ERR_CAST(inode);
-	}
-	if (is_bad_inode(inode)) {
-		pr_notice("Eep. read_inode() failed for ino #%u. unlinked %d\n",
-			  inum, unlinked);
-		/* NB. This will happen again. We need to do something appropriate here. */
-		iput(inode);
-		return ERR_PTR(-EIO);
+		if (inode <= 0)
+			return (struct jffs2_inode_info *)inode;
 	}
 
 	return JFFS2_INODE_INFO(inode);
 }
-
-static int jffs2_flash_setup(struct jffs2_sb_info *c) {
-	int ret = 0;
-
-	if (jffs2_cleanmarker_oob(c)) {
-		/* NAND flash... do setup accordingly */
-		ret = jffs2_nand_flash_setup(c);
-		if (ret)
-			return ret;
-	}
-
-	/* and Dataflash */
-	if (jffs2_dataflash(c)) {
-		ret = jffs2_dataflash_setup(c);
-		if (ret)
-			return ret;
-	}
-
-	/* and Intel "Sibley" flash */
-	if (jffs2_nor_wbuf_flash(c)) {
-		ret = jffs2_nor_wbuf_flash_setup(c);
-		if (ret)
-			return ret;
-	}
-
-	/* and an UBI volume */
-	if (jffs2_ubivol(c)) {
-		ret = jffs2_ubivol_setup(c);
-		if (ret)
-			return ret;
-	}
-
-	return ret;
-}
-
-void jffs2_flash_cleanup(struct jffs2_sb_info *c) {
-
-	if (jffs2_cleanmarker_oob(c)) {
-		jffs2_nand_flash_cleanup(c);
-	}
-
-	/* and DataFlash */
-	if (jffs2_dataflash(c)) {
-		jffs2_dataflash_cleanup(c);
-	}
-
-	/* and Intel "Sibley" flash */
-	if (jffs2_nor_wbuf_flash(c)) {
-		jffs2_nor_wbuf_flash_cleanup(c);
-	}
-
-	/* and an UBI volume */
-	if (jffs2_ubivol(c)) {
-		jffs2_ubivol_cleanup(c);
-	}
-}
diff -Nupr old/fs/jffs2/gc.c new/fs/jffs2/gc.c
--- old/fs/jffs2/gc.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/gc.c	2022-05-10 16:11:42.090000000 +0800
@@ -10,17 +10,17 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
-#include <linux/mtd/mtd.h>
 #include <linux/slab.h>
 #include <linux/pagemap.h>
-#include <linux/crc32.h>
+#include <linux/delay.h>
+#include <linux/semaphore.h>
 #include <linux/compiler.h>
 #include <linux/stat.h>
+#include "mtd_dev.h"
 #include "nodelist.h"
 #include "compr.h"
+#include "los_crc32.h"
 
 static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
 					  struct jffs2_inode_cache *ic,
@@ -43,7 +43,7 @@ static int jffs2_garbage_collect_live(st
 /* Called with erase_completion_lock held */
 static struct jffs2_eraseblock *jffs2_find_gc_block(struct jffs2_sb_info *c)
 {
-	struct jffs2_eraseblock *ret;
+	struct jffs2_eraseblock *ret = NULL;
 	struct list_head *nextlist = NULL;
 	int n = jiffies % 128;
 
@@ -131,62 +131,40 @@ int jffs2_garbage_collect_pass(struct jf
 	int ret = 0, inum, nlink;
 	int xattr = 0;
 
-	if (mutex_lock_interruptible(&c->alloc_sem))
+	if (mutex_lock(&c->alloc_sem))
 		return -EINTR;
 
-
 	for (;;) {
-		/* We can't start doing GC until we've finished checking
-		   the node CRCs etc. */
-		int bucket, want_ino;
-
 		spin_lock(&c->erase_completion_lock);
 		if (!c->unchecked_size)
 			break;
+
+		/* We can't start doing GC yet. We haven't finished checking
+		   the node CRCs etc. Do it now. */
+
+		/* checked_ino is protected by the alloc_sem */
+		if (c->checked_ino > c->highest_ino && xattr) {
+			pr_crit("Checked all inodes but still 0x%x bytes of unchecked space?\n",
+				c->unchecked_size);
+			jffs2_dbg_dump_block_lists_nolock(c);
+			spin_unlock(&c->erase_completion_lock);
+			mutex_unlock(&c->alloc_sem);
+			return -ENOSPC;
+		}
+
 		spin_unlock(&c->erase_completion_lock);
 
 		if (!xattr)
 			xattr = jffs2_verify_xattr(c);
 
 		spin_lock(&c->inocache_lock);
-		/* Instead of doing the inodes in numeric order, doing a lookup
-		 * in the hash for each possible number, just walk the hash
-		 * buckets of *existing* inodes. This means that we process
-		 * them out-of-order, but it can be a lot faster if there's
-		 * a sparse inode# space. Which there often is. */
-		want_ino = c->check_ino;
-		for (bucket = c->check_ino % c->inocache_hashsize ; bucket < c->inocache_hashsize; bucket++) {
-			for (ic = c->inocache_list[bucket]; ic; ic = ic->next) {
-				if (ic->ino < want_ino)
-					continue;
-
-				if (ic->state != INO_STATE_CHECKEDABSENT &&
-				    ic->state != INO_STATE_PRESENT)
-					goto got_next; /* with inocache_lock held */
 
-				jffs2_dbg(1, "Skipping ino #%u already checked\n",
-					  ic->ino);
-			}
-			want_ino = 0;
-		}
-
-		/* Point c->check_ino past the end of the last bucket. */
-		c->check_ino = ((c->highest_ino + c->inocache_hashsize + 1) &
-				~c->inocache_hashsize) - 1;
-
-		spin_unlock(&c->inocache_lock);
-
-		pr_crit("Checked all inodes but still 0x%x bytes of unchecked space?\n",
-			c->unchecked_size);
-		jffs2_dbg_dump_block_lists_nolock(c);
-		mutex_unlock(&c->alloc_sem);
-		return -ENOSPC;
+		ic = jffs2_get_ino_cache(c, c->checked_ino++);
 
-	got_next:
-		/* For next time round the loop, we want c->checked_ino to indicate
-		 * the *next* one we want to check. And since we're walking the
-		 * buckets rather than doing it sequentially, it's: */
-		c->check_ino = ic->ino + c->inocache_hashsize;
+		if (!ic) {
+			spin_unlock(&c->inocache_lock);
+			continue;
+		}
 
 		if (!ic->pino_nlink) {
 			jffs2_dbg(1, "Skipping check of ino #%d with nlink/pino zero\n",
@@ -198,6 +176,8 @@ int jffs2_garbage_collect_pass(struct jf
 		switch(ic->state) {
 		case INO_STATE_CHECKEDABSENT:
 		case INO_STATE_PRESENT:
+			jffs2_dbg(1, "Skipping ino #%u already checked\n",
+				  ic->ino);
 			spin_unlock(&c->inocache_lock);
 			continue;
 
@@ -207,6 +187,7 @@ int jffs2_garbage_collect_pass(struct jf
 				ic->ino, ic->state);
 			spin_unlock(&c->inocache_lock);
 			BUG();
+			break;
 
 		case INO_STATE_READING:
 			/* We need to wait for it to finish, lest we move on
@@ -216,7 +197,7 @@ int jffs2_garbage_collect_pass(struct jf
 				  ic->ino);
 			/* We need to come back again for the _same_ inode. We've
 			 made no progress in this case, but that should be OK */
-			c->check_ino = ic->ino;
+			c->checked_ino--;
 
 			mutex_unlock(&c->alloc_sem);
 			sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
@@ -224,6 +205,7 @@ int jffs2_garbage_collect_pass(struct jf
 
 		default:
 			BUG();
+			break;
 
 		case INO_STATE_UNCHECKED:
 			;
@@ -290,7 +272,7 @@ int jffs2_garbage_collect_pass(struct jf
 	raw = jeb->gc_node;
 	gcblock_dirty = jeb->dirty_size;
 
-	while(ref_obsolete(raw)) {
+	while(raw && ref_obsolete(raw)) {
 		jffs2_dbg(1, "Node at 0x%08x is obsolete... skipping\n",
 			  ref_offset(raw));
 		raw = ref_next(raw);
@@ -310,7 +292,7 @@ int jffs2_garbage_collect_pass(struct jf
 	jffs2_dbg(1, "Going to garbage collect node at 0x%08x\n",
 		  ref_offset(raw));
 
-	if (!raw->next_in_ino) {
+	if (raw &&!raw->next_in_ino) {
 		/* Inode-less node. Clean marker, snapshot or something like that */
 		spin_unlock(&c->erase_completion_lock);
 		if (ref_flags(raw) == REF_PRISTINE) {
@@ -368,7 +350,7 @@ int jffs2_garbage_collect_pass(struct jf
 		   We can just copy any pristine nodes, but have
 		   to prevent anyone else from doing read_inode() while
 		   we're at it, so we set the state accordingly */
-		if (ref_flags(raw) == REF_PRISTINE)
+		if (raw && ref_flags(raw) == REF_PRISTINE)
 			ic->state = INO_STATE_GC;
 		else {
 			jffs2_dbg(1, "Ino #%u is absent but node not REF_PRISTINE. Reading.\n",
@@ -393,6 +375,7 @@ int jffs2_garbage_collect_pass(struct jf
 		mutex_unlock(&c->alloc_sem);
 		spin_unlock(&c->inocache_lock);
 		BUG();
+		break;
 
 	case INO_STATE_READING:
 		/* Someone's currently trying to read it. We must wait for
@@ -430,7 +413,6 @@ int jffs2_garbage_collect_pass(struct jf
 
 		spin_lock(&c->inocache_lock);
 		ic->state = INO_STATE_CHECKEDABSENT;
-		wake_up(&c->inocache_wq);
 
 		if (ret != -EBADFD) {
 			spin_unlock(&c->inocache_lock);
@@ -460,9 +442,7 @@ int jffs2_garbage_collect_pass(struct jf
 		ret = 0;
 		goto release_sem;
 	}
-
 	ret = jffs2_garbage_collect_live(c, jeb, raw, f);
-
 	jffs2_gc_release_inode(c, f);
 
  test_gcnode:
@@ -541,7 +521,7 @@ static int jffs2_garbage_collect_live(st
 				break; /* We've found them all */
 		}
 	}
-	if (fn) {
+	if (fn != NULL && frag != NULL) {
 		if (ref_flags(raw) == REF_PRISTINE) {
 			ret = jffs2_garbage_collect_pristine(c, f->inocache, raw);
 			if (!ret) {
@@ -552,7 +532,7 @@ static int jffs2_garbage_collect_live(st
 				goto upnout;
 		}
 		/* We found a datanode. Do the GC */
-		if((start >> PAGE_SHIFT) < ((end-1) >> PAGE_SHIFT)) {
+		if((start >> PAGE_CACHE_SHIFT) < ((end-1) >> PAGE_CACHE_SHIFT)) {
 			/* It crosses a page boundary. Therefore, it must be a hole. */
 			ret = jffs2_garbage_collect_hole(c, jeb, f, fn, start, end);
 		} else {
@@ -635,6 +615,7 @@ static int jffs2_garbage_collect_pristin
 	if (je32_to_cpu(node->u.hdr_crc) != crc) {
 		pr_warn("Header CRC failed on REF_PRISTINE node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
 			ref_offset(raw), je32_to_cpu(node->u.hdr_crc), crc);
+		jffs2_dbg_dump_node(c, ref_offset(raw));
 		goto bail;
 	}
 
@@ -645,6 +626,7 @@ static int jffs2_garbage_collect_pristin
 			pr_warn("Node CRC failed on REF_PRISTINE data node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
 				ref_offset(raw), je32_to_cpu(node->i.node_crc),
 				crc);
+			jffs2_dbg_dump_node(c, ref_offset(raw));
 			goto bail;
 		}
 
@@ -654,6 +636,7 @@ static int jffs2_garbage_collect_pristin
 				pr_warn("Data CRC failed on REF_PRISTINE data node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
 					ref_offset(raw),
 					je32_to_cpu(node->i.data_crc), crc);
+				jffs2_dbg_dump_node(c, ref_offset(raw));
 				goto bail;
 			}
 		}
@@ -665,12 +648,14 @@ static int jffs2_garbage_collect_pristin
 			pr_warn("Node CRC failed on REF_PRISTINE dirent node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
 				ref_offset(raw),
 				je32_to_cpu(node->d.node_crc), crc);
+			jffs2_dbg_dump_node(c, ref_offset(raw));
 			goto bail;
 		}
 
-		if (strnlen(node->d.name, node->d.nsize) != node->d.nsize) {
+		if (strnlen((const char *)node->d.name, node->d.nsize) != node->d.nsize) {
 			pr_warn("Name in dirent node at 0x%08x contains zeroes\n",
 				ref_offset(raw));
+			jffs2_dbg_dump_node(c, ref_offset(raw));
 			goto bail;
 		}
 
@@ -680,6 +665,7 @@ static int jffs2_garbage_collect_pristin
 				pr_warn("Name CRC failed on REF_PRISTINE dirent node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
 					ref_offset(raw),
 					je32_to_cpu(node->d.name_crc), crc);
+				jffs2_dbg_dump_node(c, ref_offset(raw));
 				goto bail;
 			}
 		}
@@ -689,6 +675,7 @@ static int jffs2_garbage_collect_pristin
 		if (ic) {
 			pr_warn("Unknown node type for REF_PRISTINE node at 0x%08x: 0x%04x\n",
 				ref_offset(raw), je16_to_cpu(node->u.nodetype));
+			jffs2_dbg_dump_node(c, ref_offset(raw));
 			goto bail;
 		}
 	}
@@ -697,7 +684,7 @@ static int jffs2_garbage_collect_pristin
  retry:
 	phys_ofs = write_ofs(c);
 
-	ret = jffs2_flash_write(c, phys_ofs, rawlen, &retlen, (char *)node);
+	ret = jffs2_flash_write(c, phys_ofs, rawlen, &retlen, (const u_char *)node);
 
 	if (ret || (retlen != rawlen)) {
 		pr_notice("Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n",
@@ -761,7 +748,7 @@ static int jffs2_garbage_collect_metadat
 	struct jffs2_full_dnode *new_fn;
 	struct jffs2_raw_inode ri;
 	struct jffs2_node_frag *last_frag;
-	union jffs2_device_node dev;
+	jint16_t dev;
 	char *mdata = NULL;
 	int mdatalen = 0;
 	uint32_t alloclen, ilen;
@@ -770,8 +757,9 @@ static int jffs2_garbage_collect_metadat
 	if (S_ISBLK(JFFS2_F_I_MODE(f)) ||
 	    S_ISCHR(JFFS2_F_I_MODE(f)) ) {
 		/* For these, we don't actually need to read the old node */
-		mdatalen = jffs2_encode_dev(&dev, JFFS2_F_I_RDEV(f));
+		dev = cpu_to_je16(((JFFS2_F_I_RDEV_MAJ(f) << 8) | JFFS2_F_I_RDEV_MIN(f)));
 		mdata = (char *)&dev;
+		mdatalen = sizeof(dev);
 		jffs2_dbg(1, "%s(): Writing %d bytes of kdev_t\n",
 			  __func__, mdatalen);
 	} else if (S_ISLNK(JFFS2_F_I_MODE(f))) {
@@ -781,7 +769,7 @@ static int jffs2_garbage_collect_metadat
 			pr_warn("kmalloc of mdata failed in jffs2_garbage_collect_metadata()\n");
 			return -ENOMEM;
 		}
-		ret = jffs2_read_dnode(c, f, fn, mdata, 0, mdatalen);
+		ret = jffs2_read_dnode(c, f, fn, (unsigned char *)mdata, 0, mdatalen);
 		if (ret) {
 			pr_warn("read of old metadata failed in jffs2_garbage_collect_metadata(): %d\n",
 				ret);
@@ -831,7 +819,7 @@ static int jffs2_garbage_collect_metadat
 	ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
 	ri.data_crc = cpu_to_je32(crc32(0, mdata, mdatalen));
 
-	new_fn = jffs2_write_dnode(c, f, &ri, mdata, mdatalen, ALLOC_GC);
+	new_fn = jffs2_write_dnode(c, f, &ri, (unsigned char *)mdata, mdatalen, ALLOC_GC);
 
 	if (IS_ERR(new_fn)) {
 		pr_warn("Error writing new dnode: %ld\n", PTR_ERR(new_fn));
@@ -857,7 +845,7 @@ static int jffs2_garbage_collect_dirent(
 
 	rd.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 	rd.nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
-	rd.nsize = strlen(fd->name);
+	rd.nsize = strlen((const char *)fd->name);
 	rd.totlen = cpu_to_je32(sizeof(rd) + rd.nsize);
 	rd.hdr_crc = cpu_to_je32(crc32(0, &rd, sizeof(struct jffs2_unknown_node)-4));
 
@@ -908,7 +896,7 @@ static int jffs2_garbage_collect_deletio
 		struct jffs2_raw_node_ref *raw;
 		int ret;
 		size_t retlen;
-		int name_len = strlen(fd->name);
+		int name_len = strlen((const char *)fd->name);
 		uint32_t name_crc = crc32(0, fd->name, name_len);
 		uint32_t rawlen = ref_totlen(c, jeb, fd->raw);
 
@@ -1053,6 +1041,7 @@ static int jffs2_garbage_collect_hole(st
 			pr_warn("%s: Node at 0x%08x had CRC 0x%08x which doesn't match calculated CRC 0x%08x\n",
 				__func__, ref_offset(fn->raw),
 				je32_to_cpu(ri.node_crc), crc);
+				jffs2_dbg_dump_node(c, ref_offset(fn->raw));
 			/* FIXME: We could possibly deal with this by writing new holes for each frag */
 			pr_warn("Data in the range 0x%08x to 0x%08x of inode #%u will be lost\n",
 				start, end, f->inocache->ino);
@@ -1165,13 +1154,12 @@ static int jffs2_garbage_collect_dnode(s
 				       struct jffs2_inode_info *f, struct jffs2_full_dnode *fn,
 				       uint32_t start, uint32_t end)
 {
-	struct inode *inode = OFNI_EDONI_2SFFJ(f);
 	struct jffs2_full_dnode *new_fn;
 	struct jffs2_raw_inode ri;
 	uint32_t alloclen, offset, orig_end, orig_start;
 	int ret = 0;
 	unsigned char *comprbuf = NULL, *writebuf;
-	struct page *page;
+	unsigned long pg;
 	unsigned char *pg_ptr;
 
 	memset(&ri, 0, sizeof(ri));
@@ -1193,8 +1181,8 @@ static int jffs2_garbage_collect_dnode(s
 		struct jffs2_node_frag *frag;
 		uint32_t min, max;
 
-		min = start & ~(PAGE_SIZE-1);
-		max = min + PAGE_SIZE;
+		min = start & ~(PAGE_CACHE_SIZE-1);
+		max = min + PAGE_CACHE_SIZE;
 
 		frag = jffs2_lookup_node_frag(&f->fragtree, start);
 
@@ -1203,7 +1191,7 @@ static int jffs2_garbage_collect_dnode(s
 		BUG_ON(frag->ofs != start);
 
 		/* First grow down... */
-		while((frag = frag_prev(frag)) && frag->ofs >= min) {
+		while(frag && (frag = frag_prev(frag)) && frag->ofs >= min) {
 
 			/* If the previous frag doesn't even reach the beginning, there's
 			   excessive fragmentation. Just merge. */
@@ -1259,7 +1247,7 @@ static int jffs2_garbage_collect_dnode(s
 		/* Find last frag which is actually part of the node we're to GC. */
 		frag = jffs2_lookup_node_frag(&f->fragtree, end-1);
 
-		while((frag = frag_next(frag)) && frag->ofs+frag->size <= max) {
+		while(frag && (frag = frag_next(frag)) && frag->ofs+frag->size <= max) {
 
 			/* If the previous frag doesn't even reach the beginning, there's lots
 			   of fragmentation. Just merge. */
@@ -1317,27 +1305,21 @@ static int jffs2_garbage_collect_dnode(s
 		BUG_ON(start > orig_start);
 	}
 
-	/* The rules state that we must obtain the page lock *before* f->sem, so
-	 * drop f->sem temporarily. Since we also hold c->alloc_sem, nothing's
-	 * actually going to *change* so we're safe; we only allow reading.
-	 *
-	 * It is important to note that jffs2_write_begin() will ensure that its
-	 * page is marked Uptodate before allocating space. That means that if we
-	 * end up here trying to GC the *same* page that jffs2_write_begin() is
-	 * trying to write out, read_cache_page() will not deadlock. */
-	mutex_unlock(&f->sem);
-	page = read_cache_page(inode->i_mapping, start >> PAGE_SHIFT,
-			       jffs2_do_readpage_unlock, inode);
-	if (IS_ERR(page)) {
+	/* First, use readpage() to read the appropriate page into the page cache */
+	/* Q: What happens if we actually try to GC the _same_ page for which commit_write()
+	 *    triggered garbage collection in the first place?
+	 * A: I _think_ it's OK. read_cache_page shouldn't deadlock, we'll write out the
+	 *    page OK. We'll actually write it out again in commit_write, which is a little
+	 *    suboptimal, but at least we're correct.
+	 */
+	pg_ptr = jffs2_gc_fetch_page(c, f, start, &pg);
+
+	if (IS_ERR(pg_ptr)) {
 		pr_warn("read_cache_page() returned error: %ld\n",
-			PTR_ERR(page));
-		mutex_lock(&f->sem);
-		return PTR_ERR(page);
+			PTR_ERR(pg_ptr));
+		return PTR_ERR(pg_ptr);
 	}
 
-	pg_ptr = kmap(page);
-	mutex_lock(&f->sem);
-
 	offset = start;
 	while(offset < orig_end) {
 		uint32_t datalen;
@@ -1355,7 +1337,7 @@ static int jffs2_garbage_collect_dnode(s
 		cdatalen = min_t(uint32_t, alloclen - sizeof(ri), end - offset);
 		datalen = end - offset;
 
-		writebuf = pg_ptr + (offset & (PAGE_SIZE -1));
+		writebuf = pg_ptr + (offset & (PAGE_CACHE_SIZE -1));
 
 		comprtype = jffs2_compress(c, f, writebuf, &comprbuf, &datalen, &cdatalen);
 
@@ -1400,7 +1382,6 @@ static int jffs2_garbage_collect_dnode(s
 		}
 	}
 
-	kunmap(page);
-	put_page(page);
+	jffs2_gc_release_page(c, pg_ptr, &pg);
 	return ret;
 }
diff -Nupr old/fs/jffs2/ioctl.c new/fs/jffs2/ioctl.c
--- old/fs/jffs2/ioctl.c	2022-05-09 17:15:24.350000000 +0800
+++ new/fs/jffs2/ioctl.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,22 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2001-2007 Red Hat, Inc.
- * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
- *
- * Created by David Woodhouse <dwmw2@infradead.org>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#include <linux/fs.h>
-#include "nodelist.h"
-
-long jffs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-	/* Later, this will provide for lsattr.jffs2 and chattr.jffs2, which
-	   will include compression support etc. */
-	return -ENOTTY;
-}
-
diff -Nupr old/fs/jffs2/jffs2_fs_i.h new/fs/jffs2/jffs2_fs_i.h
--- old/fs/jffs2/jffs2_fs_i.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/jffs2_fs_i.h	2022-05-09 20:50:05.810000000 +0800
@@ -14,8 +14,13 @@
 #define _JFFS2_FS_I
 
 #include <linux/rbtree.h>
-#include <linux/posix_acl.h>
-#include <linux/mutex.h>
+#include <linux/kernel.h>
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
 
 struct jffs2_inode_info {
 	/* We need an internal mutex similar to inode->i_mutex.
@@ -24,7 +29,7 @@ struct jffs2_inode_info {
 	   before letting GC proceed. Or we'd have to put ugliness
 	   into the GC code so it didn't attempt to obtain the i_mutex
 	   for the inode(s) which are already locked */
-	struct mutex sem;
+	struct pthread_mutex sem;
 
 	/* The highest (datanode) version number used for this ino */
 	uint32_t highest_version;
@@ -50,7 +55,29 @@ struct jffs2_inode_info {
 
 	uint16_t flags;
 	uint8_t usercompr;
-	struct inode vfs_inode;
 };
 
+struct super_block;
+
+struct jffs2_inode {
+	uint32_t i_ino;
+	mode_t i_mode;
+	nlink_t i_nlink;
+	uid_t i_uid;
+	gid_t i_gid;
+	time_t i_atime;
+	time_t i_mtime;
+	time_t i_ctime;
+	off_t i_size;
+	struct super_block *i_sb;
+	LOS_DL_LIST i_hashlist;
+	struct jffs2_inode_info jffs2_i;
+};
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #endif /* _JFFS2_FS_I */
diff -Nupr old/fs/jffs2/jffs2_fs_sb.h new/fs/jffs2/jffs2_fs_sb.h
--- old/fs/jffs2/jffs2_fs_sb.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/jffs2_fs_sb.h	2022-05-09 20:49:43.100000000 +0800
@@ -17,11 +17,18 @@
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
 #include <linux/completion.h>
-#include <linux/mutex.h>
 #include <linux/timer.h>
 #include <linux/wait.h>
 #include <linux/list.h>
 #include <linux/rwsem.h>
+#include "vfs_jffs2.h"
+#include "mtd_dev.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
 
 #define JFFS2_SB_FLAG_RO 1
 #define JFFS2_SB_FLAG_SCANNING 2 /* Flash scanning is in progress */
@@ -47,10 +54,10 @@ struct jffs2_mount_opts {
    Nee jffs_control
 */
 struct jffs2_sb_info {
-	struct mtd_info *mtd;
+	struct MtdDev *mtd;
 
 	uint32_t highest_ino;
-	uint32_t check_ino;		/* *NEXT* inode to be checked */
+	uint32_t checked_ino;
 
 	unsigned int flags;
 
@@ -58,7 +65,7 @@ struct jffs2_sb_info {
 	struct completion gc_thread_start; /* GC thread start completion */
 	struct completion gc_thread_exit; /* GC thread exit completion port */
 
-	struct mutex alloc_sem;		/* Used to protect all the following
+	struct pthread_mutex alloc_sem;	/* Used to protect all the following
 					   fields, and also to protect against
 					   out-of-order writing of nodes. And GC. */
 	uint32_t cleanmarker_size;	/* Size of an _inline_ CLEANMARKER
@@ -120,7 +127,7 @@ struct jffs2_sb_info {
 	/* Sem to allow jffs2_garbage_collect_deletion_dirent to
 	   drop the erase_completion_lock while it's holding a pointer
 	   to an obsoleted node. I don't like this. Alternatives welcomed. */
-	struct mutex erase_free_sem;
+	struct pthread_mutex  erase_free_sem;
 
 	uint32_t wbuf_pagesize; /* 0 for NOR and other flashes with no wbuf */
 
@@ -160,4 +167,27 @@ struct jffs2_sb_info {
 	void *os_priv;
 };
 
+struct super_block {
+	struct jffs2_sb_info	jffs2_sb;
+	LIST_HEAD		s_node_hash[JFFS2_NODE_HASH_BUCKETS];
+	LosMux			s_node_hash_lock;
+	struct jffs2_inode 	*s_root;
+	void			*s_dev;
+
+	UINT32			s_lock;			/* Lock the inode cache */
+	EVENT_CB_S		s_gc_thread_flags;	/* Communication with the gcthread */
+	unsigned int		s_gc_thread;
+	unsigned long		s_mount_flags;
+};
+
+#define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb)
+#define OFNI_BS_2SFFJ(c)  \
+        ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) )
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #endif /* _JFFS2_FS_SB */
diff -Nupr old/fs/jffs2/malloc.c new/fs/jffs2/malloc.c
--- old/fs/jffs2/malloc.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/malloc.c	2022-05-10 09:43:16.720000000 +0800
@@ -9,111 +9,31 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/jffs2.h>
+#include <stdlib.h>
 #include "nodelist.h"
 
-/* These are initialised to NULL in the kernel startup code.
-   If you're porting to other operating systems, beware */
-static struct kmem_cache *full_dnode_slab;
-static struct kmem_cache *raw_dirent_slab;
-static struct kmem_cache *raw_inode_slab;
-static struct kmem_cache *tmp_dnode_info_slab;
-static struct kmem_cache *raw_node_ref_slab;
-static struct kmem_cache *node_frag_slab;
-static struct kmem_cache *inode_cache_slab;
-#ifdef CONFIG_JFFS2_FS_XATTR
-static struct kmem_cache *xattr_datum_cache;
-static struct kmem_cache *xattr_ref_cache;
+#if !defined(JFFS2NUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE)
+# define JFFS2NUM_FS_JFFS2_RAW_NODE_REF_CACHE_POOL_SIZE 0
 #endif
 
 int __init jffs2_create_slab_caches(void)
 {
-	full_dnode_slab = kmem_cache_create("jffs2_full_dnode",
-					    sizeof(struct jffs2_full_dnode),
-					    0, 0, NULL);
-	if (!full_dnode_slab)
-		goto err;
-
-	raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent",
-					    sizeof(struct jffs2_raw_dirent),
-					    0, SLAB_HWCACHE_ALIGN, NULL);
-	if (!raw_dirent_slab)
-		goto err;
-
-	raw_inode_slab = kmem_cache_create("jffs2_raw_inode",
-					   sizeof(struct jffs2_raw_inode),
-					   0, SLAB_HWCACHE_ALIGN, NULL);
-	if (!raw_inode_slab)
-		goto err;
-
-	tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode",
-						sizeof(struct jffs2_tmp_dnode_info),
-						0, 0, NULL);
-	if (!tmp_dnode_info_slab)
-		goto err;
-
-	raw_node_ref_slab = kmem_cache_create("jffs2_refblock",
-					      sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK + 1),
-					      0, 0, NULL);
-	if (!raw_node_ref_slab)
-		goto err;
-
-	node_frag_slab = kmem_cache_create("jffs2_node_frag",
-					   sizeof(struct jffs2_node_frag),
-					   0, 0, NULL);
-	if (!node_frag_slab)
-		goto err;
-
-	inode_cache_slab = kmem_cache_create("jffs2_inode_cache",
-					     sizeof(struct jffs2_inode_cache),
-					     0, 0, NULL);
-	if (!inode_cache_slab)
-		goto err;
-
-#ifdef CONFIG_JFFS2_FS_XATTR
-	xattr_datum_cache = kmem_cache_create("jffs2_xattr_datum",
-					     sizeof(struct jffs2_xattr_datum),
-					     0, 0, NULL);
-	if (!xattr_datum_cache)
-		goto err;
-
-	xattr_ref_cache = kmem_cache_create("jffs2_xattr_ref",
-					   sizeof(struct jffs2_xattr_ref),
-					   0, 0, NULL);
-	if (!xattr_ref_cache)
-		goto err;
-#endif
-
 	return 0;
- err:
-	jffs2_destroy_slab_caches();
-	return -ENOMEM;
+
 }
 
 void jffs2_destroy_slab_caches(void)
 {
-	kmem_cache_destroy(full_dnode_slab);
-	kmem_cache_destroy(raw_dirent_slab);
-	kmem_cache_destroy(raw_inode_slab);
-	kmem_cache_destroy(tmp_dnode_info_slab);
-	kmem_cache_destroy(raw_node_ref_slab);
-	kmem_cache_destroy(node_frag_slab);
-	kmem_cache_destroy(inode_cache_slab);
-#ifdef CONFIG_JFFS2_FS_XATTR
-	kmem_cache_destroy(xattr_datum_cache);
-	kmem_cache_destroy(xattr_ref_cache);
-#endif
+	return;
 }
 
+
 struct jffs2_full_dirent *jffs2_alloc_full_dirent(int namesize)
 {
 	struct jffs2_full_dirent *ret;
-	ret = kmalloc(sizeof(struct jffs2_full_dirent) + namesize, GFP_KERNEL);
+	ret = zalloc(sizeof(struct jffs2_full_dirent) + namesize);
 	dbg_memalloc("%p\n", ret);
 	return ret;
 }
@@ -127,7 +47,7 @@ void jffs2_free_full_dirent(struct jffs2
 struct jffs2_full_dnode *jffs2_alloc_full_dnode(void)
 {
 	struct jffs2_full_dnode *ret;
-	ret = kmem_cache_alloc(full_dnode_slab, GFP_KERNEL);
+	ret = zalloc(sizeof(struct jffs2_full_dnode));
 	dbg_memalloc("%p\n", ret);
 	return ret;
 }
@@ -135,13 +55,13 @@ struct jffs2_full_dnode *jffs2_alloc_ful
 void jffs2_free_full_dnode(struct jffs2_full_dnode *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(full_dnode_slab, x);
+	free(x);
 }
 
 struct jffs2_raw_dirent *jffs2_alloc_raw_dirent(void)
 {
 	struct jffs2_raw_dirent *ret;
-	ret = kmem_cache_alloc(raw_dirent_slab, GFP_KERNEL);
+	ret = zalloc(sizeof(struct jffs2_raw_dirent));
 	dbg_memalloc("%p\n", ret);
 	return ret;
 }
@@ -149,13 +69,13 @@ struct jffs2_raw_dirent *jffs2_alloc_raw
 void jffs2_free_raw_dirent(struct jffs2_raw_dirent *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(raw_dirent_slab, x);
+	free(x);
 }
 
 struct jffs2_raw_inode *jffs2_alloc_raw_inode(void)
 {
 	struct jffs2_raw_inode *ret;
-	ret = kmem_cache_alloc(raw_inode_slab, GFP_KERNEL);
+	ret = zalloc(sizeof(struct jffs2_raw_inode));
 	dbg_memalloc("%p\n", ret);
 	return ret;
 }
@@ -163,13 +83,13 @@ struct jffs2_raw_inode *jffs2_alloc_raw_
 void jffs2_free_raw_inode(struct jffs2_raw_inode *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(raw_inode_slab, x);
+	free(x);
 }
 
 struct jffs2_tmp_dnode_info *jffs2_alloc_tmp_dnode_info(void)
 {
 	struct jffs2_tmp_dnode_info *ret;
-	ret = kmem_cache_alloc(tmp_dnode_info_slab, GFP_KERNEL);
+	ret = zalloc(sizeof(struct jffs2_tmp_dnode_info));
 	dbg_memalloc("%p\n",
 		ret);
 	return ret;
@@ -178,14 +98,14 @@ struct jffs2_tmp_dnode_info *jffs2_alloc
 void jffs2_free_tmp_dnode_info(struct jffs2_tmp_dnode_info *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(tmp_dnode_info_slab, x);
+	free(x);
 }
 
 static struct jffs2_raw_node_ref *jffs2_alloc_refblock(void)
 {
 	struct jffs2_raw_node_ref *ret;
 
-	ret = kmem_cache_alloc(raw_node_ref_slab, GFP_KERNEL);
+	ret = malloc(sizeof(struct jffs2_raw_node_ref) * (REFS_PER_BLOCK+1));
 	if (ret) {
 		int i = 0;
 		for (i=0; i < REFS_PER_BLOCK; i++) {
@@ -242,13 +162,13 @@ int jffs2_prealloc_raw_node_refs(struct
 void jffs2_free_refblock(struct jffs2_raw_node_ref *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(raw_node_ref_slab, x);
+	free(x);
 }
 
 struct jffs2_node_frag *jffs2_alloc_node_frag(void)
 {
 	struct jffs2_node_frag *ret;
-	ret = kmem_cache_alloc(node_frag_slab, GFP_KERNEL);
+	ret = malloc(sizeof(struct jffs2_node_frag));
 	dbg_memalloc("%p\n", ret);
 	return ret;
 }
@@ -256,13 +176,14 @@ struct jffs2_node_frag *jffs2_alloc_node
 void jffs2_free_node_frag(struct jffs2_node_frag *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(node_frag_slab, x);
+	free(x);
 }
 
+
 struct jffs2_inode_cache *jffs2_alloc_inode_cache(void)
 {
 	struct jffs2_inode_cache *ret;
-	ret = kmem_cache_alloc(inode_cache_slab, GFP_KERNEL);
+	ret = zalloc(sizeof(struct jffs2_inode_cache));;
 	dbg_memalloc("%p\n", ret);
 	return ret;
 }
@@ -270,14 +191,14 @@ struct jffs2_inode_cache *jffs2_alloc_in
 void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
 {
 	dbg_memalloc("%p\n", x);
-	kmem_cache_free(inode_cache_slab, x);
+	kfree(x);
 }
 
 #ifdef CONFIG_JFFS2_FS_XATTR
 struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
 {
 	struct jffs2_xattr_datum *xd;
-	xd = kmem_cache_zalloc(xattr_datum_cache, GFP_KERNEL);
+	xd = malloc(sizeof(struct jffs2_xattr_datum));
 	dbg_memalloc("%p\n", xd);
 	if (!xd)
 		return NULL;
@@ -291,13 +212,13 @@ struct jffs2_xattr_datum *jffs2_alloc_xa
 void jffs2_free_xattr_datum(struct jffs2_xattr_datum *xd)
 {
 	dbg_memalloc("%p\n", xd);
-	kmem_cache_free(xattr_datum_cache, xd);
+	kfree(xd);
 }
 
 struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
 {
 	struct jffs2_xattr_ref *ref;
-	ref = kmem_cache_zalloc(xattr_ref_cache, GFP_KERNEL);
+	ref = malloc(sizeof(struct jffs2_xattr_ref));
 	dbg_memalloc("%p\n", ref);
 	if (!ref)
 		return NULL;
@@ -310,6 +231,6 @@ struct jffs2_xattr_ref *jffs2_alloc_xatt
 void jffs2_free_xattr_ref(struct jffs2_xattr_ref *ref)
 {
 	dbg_memalloc("%p\n", ref);
-	kmem_cache_free(xattr_ref_cache, ref);
+	kfree(ref);
 }
 #endif
diff -Nupr old/fs/jffs2/nodelist.c new/fs/jffs2/nodelist.c
--- old/fs/jffs2/nodelist.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/nodelist.c	2022-05-09 20:37:35.680000000 +0800
@@ -9,16 +9,15 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/fs.h>
-#include <linux/mtd/mtd.h>
 #include <linux/rbtree.h>
-#include <linux/crc32.h>
 #include <linux/pagemap.h>
+#include <mtd_dev.h>
 #include "nodelist.h"
+#include "jffs2.h"
+#include "los_crc32.h"
 
 static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
 				     struct jffs2_node_frag *this);
@@ -30,7 +29,7 @@ void jffs2_add_fd_to_list(struct jffs2_s
 	dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino);
 
 	while ((*prev) && (*prev)->nhash <= new->nhash) {
-		if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
+		if ((*prev)->nhash == new->nhash && !strcmp((const char *)((*prev)->name), (const char *)new->name)) {
 			/* Duplicate. Free one */
 			if (new->version < (*prev)->version) {
 				dbg_dentlist("Eep! Marking new dirent node obsolete, old is \"%s\", ino #%u\n",
@@ -41,7 +40,7 @@ void jffs2_add_fd_to_list(struct jffs2_s
 				dbg_dentlist("marking old dirent \"%s\", ino #%u obsolete\n",
 					(*prev)->name, (*prev)->ino);
 				new->next = (*prev)->next;
-				/* It may have been a 'placeholder' deletion dirent, 
+				/* It may have been a 'placeholder' deletion dirent,
 				   if jffs2_can_mark_obsolete() (see jffs2_do_unlink()) */
 				if ((*prev)->raw)
 					jffs2_mark_node_obsolete(c, ((*prev)->raw));
@@ -65,13 +64,14 @@ uint32_t jffs2_truncate_fragtree(struct
 	/* We know frag->ofs <= size. That's what lookup does for us */
 	if (frag && frag->ofs != size) {
 		if (frag->ofs+frag->size > size) {
+		    dbg_fragtree("truncating frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size);
 			frag->size = size - frag->ofs;
 		}
 		frag = frag_next(frag);
 	}
 	while (frag && frag->ofs >= size) {
 		struct jffs2_node_frag *next = frag_next(frag);
-
+        dbg_fragtree("removing frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size);
 		frag_erase(frag, list);
 		jffs2_obsolete_node_frag(c, frag);
 		frag = next;
@@ -90,7 +90,7 @@ uint32_t jffs2_truncate_fragtree(struct
 
 	/* If the last fragment starts at the RAM page boundary, it is
 	 * REF_PRISTINE irrespective of its size. */
-	if (frag->node && (frag->ofs & (PAGE_SIZE - 1)) == 0) {
+	if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) {
 		dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
 			frag->ofs, frag->ofs + frag->size);
 		frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
@@ -237,7 +237,7 @@ static int jffs2_add_frag_to_fragtree(st
 		   If so, both 'this' and the new node get marked REF_NORMAL so
 		   the GC can take a look.
 		*/
-		if (lastend && (lastend-1) >> PAGE_SHIFT == newfrag->ofs >> PAGE_SHIFT) {
+		if (lastend && (lastend-1) >> PAGE_CACHE_SHIFT == newfrag->ofs >> PAGE_CACHE_SHIFT) {
 			if (this->node)
 				mark_ref_normal(this->node->raw);
 			mark_ref_normal(newfrag->node->raw);
@@ -382,7 +382,7 @@ int jffs2_add_full_dnode_to_inode(struct
 
 	/* If we now share a page with other nodes, mark either previous
 	   or next node REF_NORMAL, as appropriate.  */
-	if (newfrag->ofs & (PAGE_SIZE-1)) {
+	if (newfrag->ofs & (PAGE_CACHE_SIZE-1)) {
 		struct jffs2_node_frag *prev = frag_prev(newfrag);
 
 		mark_ref_normal(fn->raw);
@@ -391,7 +391,7 @@ int jffs2_add_full_dnode_to_inode(struct
 			mark_ref_normal(prev->node->raw);
 	}
 
-	if ((newfrag->ofs+newfrag->size) & (PAGE_SIZE-1)) {
+	if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) {
 		struct jffs2_node_frag *next = frag_next(newfrag);
 
 		if (next) {
@@ -401,7 +401,7 @@ int jffs2_add_full_dnode_to_inode(struct
 		}
 	}
 	jffs2_dbg_fragtree_paranoia_check_nolock(f);
-
+	jffs2_dbg_dump_fragtree_nolock(f);
 	return 0;
 }
 
@@ -409,7 +409,6 @@ void jffs2_set_inocache_state(struct jff
 {
 	spin_lock(&c->inocache_lock);
 	ic->state = state;
-	wake_up(&c->inocache_wq);
 	spin_unlock(&c->inocache_lock);
 }
 
@@ -505,8 +504,12 @@ void jffs2_free_raw_node_refs(struct jff
 {
 	int i;
 	struct jffs2_raw_node_ref *this, *next;
+	struct super_block *sb = NULL;
+	struct MtdNorDev *device = NULL;
+	sb = OFNI_BS_2SFFJ(c);
+	device = (struct MtdNorDev*)(sb->s_dev);
 
-	for (i=0; i<c->nr_blocks; i++) {
+	for (i=device->blockStart; i<c->nr_blocks+device->blockStart; i++) {
 		this = c->blocks[i].first_node;
 		while (this) {
 			if (this[REFS_PER_BLOCK].flash_offset == REF_LINK_NODE)
@@ -536,14 +539,22 @@ struct jffs2_node_frag *jffs2_lookup_nod
 	while(next) {
 		frag = rb_entry(next, struct jffs2_node_frag, rb);
 
+		dbg_fragtree2("considering frag %#04x-%#04x (%p). left %p, right %p\n",
+			  frag->ofs, frag->ofs+frag->size, frag, frag->rb.rb_left, frag->rb.rb_right);
 		if (frag->ofs + frag->size <= offset) {
+			dbg_fragtree2("going right from frag %#04x-%#04x, before the region we care about\n",
+				  frag->ofs, frag->ofs+frag->size);
 			/* Remember the closest smaller match on the way down */
 			if (!prev || frag->ofs > prev->ofs)
 				prev = frag;
 			next = frag->rb.rb_right;
 		} else if (frag->ofs > offset) {
+			dbg_fragtree2("going left from frag %#04x-%#04x, after the region we care about\n",
+				  frag->ofs, frag->ofs+frag->size);
 			next = frag->rb.rb_left;
 		} else {
+			dbg_fragtree2("returning frag %#04x-%#04x, matched\n",
+				  frag->ofs, frag->ofs+frag->size);
 			return frag;
 		}
 	}
@@ -564,10 +575,12 @@ struct jffs2_node_frag *jffs2_lookup_nod
    they're killed. */
 void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
 {
-	struct jffs2_node_frag *frag, *next;
+	struct jffs2_node_frag *frag;
+	struct rb_node *tn,*next;
 
 	dbg_fragtree("killing\n");
-	rbtree_postorder_for_each_entry_safe(frag, next, root, rb) {
+	RB_POSTORDER_FOREACH_SAFE(tn, linux_root, (struct linux_root *)root, next) {
+		frag = (struct jffs2_node_frag *)tn;
 		if (frag->node && !(--frag->node->frags)) {
 			/* Not a hole, and it's the final remaining frag
 			   of this node. Free the node */
@@ -604,7 +617,7 @@ struct jffs2_raw_node_ref *jffs2_link_no
 			ref++;
 	}
 
-	dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref, 
+	dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref,
 		    ref->flash_offset, ofs, ref->next_in_ino, len);
 
 	ref->flash_offset = ofs;
@@ -617,7 +630,7 @@ struct jffs2_raw_node_ref *jffs2_link_no
 
 		JFFS2_ERROR("Adding new ref %p at (0x%08x-0x%08x) not immediately after previous (0x%08x-0x%08x)\n",
 			    ref, ref_offset(ref), ref_offset(ref)+len,
-			    ref_offset(jeb->last_node), 
+			    ref_offset(jeb->last_node),
 			    ref_offset(jeb->last_node)+last_len);
 		BUG();
 	}
@@ -734,7 +747,7 @@ uint32_t __jffs2_ref_totlen(struct jffs2
 			pr_crit("next %p (0x%08x-0x%08x)\n",
 				ref_next(ref), ref_offset(ref_next(ref)),
 				ref_offset(ref_next(ref)) + ref->__totlen);
-		} else 
+		} else
 			pr_crit("No next ref. jeb->last_node is %p\n",
 				jeb->last_node);
 
diff -Nupr old/fs/jffs2/nodelist.h new/fs/jffs2/nodelist.h
--- old/fs/jffs2/nodelist.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/nodelist.h	2022-05-09 20:36:25.460000000 +0800
@@ -12,20 +12,28 @@
 #ifndef __JFFS2_NODELIST_H__
 #define __JFFS2_NODELIST_H__
 
-#include <linux/fs.h>
+#include <linux/stat.h>
 #include <linux/types.h>
-#include <linux/jffs2.h>
+#include <linux/list.h>
+#include "jffs2.h"
 #include "jffs2_fs_sb.h"
 #include "jffs2_fs_i.h"
 #include "xattr.h"
 #include "acl.h"
 #include "summary.h"
-
-#ifdef __ECOS
-#include "os-ecos.h"
-#else
+#include "vfs_jffs2.h"
 #include "os-linux.h"
-#endif
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+struct kvec {
+	void *iov_base;
+	long iov_len;
+};
 
 #define JFFS2_NATIVE_ENDIAN
 
@@ -193,6 +201,8 @@ struct jffs2_inode_cache {
 #define INO_STATE_READING	5	/* In read_inode() */
 #define INO_STATE_CLEARING	6	/* In clear_inode() */
 
+#define INOCACHE_HASHSIZE 128
+
 #define INO_FLAGS_XATTR_CHECKED	0x01	/* has no duplicate xattr_ref */
 #define INO_FLAGS_IS_DIR	0x02	/* is a directory */
 
@@ -250,10 +260,7 @@ struct jffs2_readinode_info
 
 struct jffs2_full_dirent
 {
-	union {
-		struct jffs2_raw_node_ref *raw;
-		struct jffs2_inode_cache *ic; /* Just during part of build */
-	};
+	struct jffs2_raw_node_ref *raw;
 	struct jffs2_full_dirent *next;
 	uint32_t version;
 	uint32_t ino; /* == zero for unlink */
@@ -313,34 +320,26 @@ static inline int jffs2_blocks_use_vmall
 
 #define PAD(x) (((x)+3)&~3)
 
-static inline int jffs2_encode_dev(union jffs2_device_node *jdev, dev_t rdev)
-{
-	if (old_valid_dev(rdev)) {
-		jdev->old_id = cpu_to_je16(old_encode_dev(rdev));
-		return sizeof(jdev->old_id);
-	} else {
-		jdev->new_id = cpu_to_je32(new_encode_dev(rdev));
-		return sizeof(jdev->new_id);
-	}
-}
 
 static inline struct jffs2_node_frag *frag_first(struct rb_root *root)
 {
-	struct rb_node *node = rb_first(root);
+	struct rb_node *node = root->rb_node;
 
 	if (!node)
 		return NULL;
-
+	while(node->rb_left)
+		node = node->rb_left;
 	return rb_entry(node, struct jffs2_node_frag, rb);
 }
 
 static inline struct jffs2_node_frag *frag_last(struct rb_root *root)
 {
-	struct rb_node *node = rb_last(root);
+	struct rb_node *node = root->rb_node;
 
 	if (!node)
 		return NULL;
-
+	while(node->rb_right)
+		node = node->rb_right;
 	return rb_entry(node, struct jffs2_node_frag, rb);
 }
 
@@ -404,8 +403,9 @@ struct jffs2_full_dirent *jffs2_write_di
 int jffs2_write_inode_range(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
 			    struct jffs2_raw_inode *ri, unsigned char *buf,
 			    uint32_t offset, uint32_t writelen, uint32_t *retlen);
-int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, struct jffs2_inode_info *f,
-		    struct jffs2_raw_inode *ri, const struct qstr *qstr);
+int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
+		    struct jffs2_inode_info *f, struct jffs2_raw_inode *ri,
+		    const char *name, int namelen);
 int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, const char *name,
 		    int namelen, struct jffs2_inode_info *dead_f, uint32_t time);
 int jffs2_do_link(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, uint32_t ino,
@@ -481,4 +481,10 @@ int jffs2_write_nand_cleanmarker(struct
 
 #include "debug.h"
 
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
 #endif /* __JFFS2_NODELIST_H__ */
diff -Nupr old/fs/jffs2/nodemgmt.c new/fs/jffs2/nodemgmt.c
--- old/fs/jffs2/nodemgmt.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/nodemgmt.c	2022-05-09 20:35:50.910000000 +0800
@@ -9,46 +9,14 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
-#include <linux/mtd/mtd.h>
 #include <linux/compiler.h>
-#include <linux/sched/signal.h>
+#include <linux/sched.h> /* For cond_resched() */
+#include <linux/semaphore.h>
+#include <mtd_dev.h>
 #include "nodelist.h"
 #include "debug.h"
 
-/*
- * Check whether the user is allowed to write.
- */
-static int jffs2_rp_can_write(struct jffs2_sb_info *c)
-{
-	uint32_t avail;
-	struct jffs2_mount_opts *opts = &c->mount_opts;
-
-	avail = c->dirty_size + c->free_size + c->unchecked_size +
-		c->erasing_size - c->resv_blocks_write * c->sector_size
-		- c->nospc_dirty_size;
-
-	if (avail < 2 * opts->rp_size)
-		jffs2_dbg(1, "rpsize %u, dirty_size %u, free_size %u, "
-			  "erasing_size %u, unchecked_size %u, "
-			  "nr_erasing_blocks %u, avail %u, resrv %u\n",
-			  opts->rp_size, c->dirty_size, c->free_size,
-			  c->erasing_size, c->unchecked_size,
-			  c->nr_erasing_blocks, avail, c->nospc_dirty_size);
-
-	if (avail > opts->rp_size)
-		return 1;
-
-	/* Always allow root */
-	if (capable(CAP_SYS_RESOURCE))
-		return 1;
-
-	jffs2_dbg(1, "forbid writing\n");
-	return 0;
-}
-
 /**
  *	jffs2_reserve_space - request physical space to write nodes to flash
  *	@c: superblock info
@@ -57,8 +25,8 @@ static int jffs2_rp_can_write(struct jff
  *	@prio: Allocation type - ALLOC_{NORMAL,DELETION}
  *
  *	Requests a block of physical space on the flash. Returns zero for success
- *	and puts 'len' into the appropriate place, or returns -ENOSPC or other 
- *	error if appropriate. Doesn't return len since that's 
+ *	and puts 'len' into the appropriate place, or returns -ENOSPC or other
+ *	error if appropriate. Doesn't return len since that's
  *
  *	If it returns zero, jffs2_reserve_space() also downs the per-filesystem
  *	allocation semaphore, to prevent more than one allocation from being
@@ -86,15 +54,6 @@ int jffs2_reserve_space(struct jffs2_sb_
 
 	spin_lock(&c->erase_completion_lock);
 
-	/*
-	 * Check if the free space is greater then size of the reserved pool.
-	 * If not, only allow root to proceed with writing.
-	 */
-	if (prio != ALLOC_DELETION && !jffs2_rp_can_write(c)) {
-		ret = -ENOSPC;
-		goto out;
-	}
-
 	/* this needs a little more thought (true <tglx> :)) */
 	while(ret == -EAGAIN) {
 		while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) {
@@ -165,24 +124,7 @@ int jffs2_reserve_space(struct jffs2_sb_
 			spin_unlock(&c->erase_completion_lock);
 
 			ret = jffs2_garbage_collect_pass(c);
-
-			if (ret == -EAGAIN) {
-				spin_lock(&c->erase_completion_lock);
-				if (c->nr_erasing_blocks &&
-				    list_empty(&c->erase_pending_list) &&
-				    list_empty(&c->erase_complete_list)) {
-					DECLARE_WAITQUEUE(wait, current);
-					set_current_state(TASK_UNINTERRUPTIBLE);
-					add_wait_queue(&c->erase_wait, &wait);
-					jffs2_dbg(1, "%s waiting for erase to complete\n",
-						  __func__);
-					spin_unlock(&c->erase_completion_lock);
-
-					schedule();
-					remove_wait_queue(&c->erase_wait, &wait);
-				} else
-					spin_unlock(&c->erase_completion_lock);
-			} else if (ret)
+			if (ret)
 				return ret;
 
 			cond_resched();
@@ -200,7 +142,6 @@ int jffs2_reserve_space(struct jffs2_sb_
 		}
 	}
 
-out:
 	spin_unlock(&c->erase_completion_lock);
 	if (!ret)
 		ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
@@ -509,7 +450,7 @@ struct jffs2_raw_node_ref *jffs2_add_phy
 	jffs2_dbg(1, "%s(): Node at 0x%x(%d), size 0x%x\n",
 		  __func__, ofs & ~3, ofs & 3, len);
 #if 1
-	/* Allow non-obsolete nodes only to be added at the end of c->nextblock, 
+	/* Allow non-obsolete nodes only to be added at the end of c->nextblock,
 	   if c->nextblock is set. Note that wbuf.c will file obsolete nodes
 	   even after refiling c->nextblock */
 	if ((c->nextblock || ((ofs & 3) != REF_OBSOLETE))
@@ -584,6 +525,8 @@ void jffs2_mark_node_obsolete(struct jff
 	int ret, addedsize;
 	size_t retlen;
 	uint32_t freed_len;
+	struct super_block *sb;
+	struct MtdNorDev *device;
 
 	if(unlikely(!ref)) {
 		pr_notice("EEEEEK. jffs2_mark_node_obsolete called with NULL node\n");
@@ -595,9 +538,10 @@ void jffs2_mark_node_obsolete(struct jff
 		return;
 	}
 	blocknr = ref->flash_offset / c->sector_size;
-	if (blocknr >= c->nr_blocks) {
-		pr_notice("raw node at 0x%08x is off the end of device!\n",
-			  ref->flash_offset);
+	sb = OFNI_BS_2SFFJ(c);
+	device = (struct MtdNorDev*)(sb->s_dev);
+	if (blocknr >= c->nr_blocks +device->blockStart) {
+		pr_notice("raw node at 0x%08x is off the end of device!\n",ref->flash_offset);
 		BUG();
 	}
 	jeb = &c->blocks[blocknr];
@@ -778,7 +722,7 @@ void jffs2_mark_node_obsolete(struct jff
 	}
 	/* XXX FIXME: This is ugly now */
 	n.nodetype = cpu_to_je16(je16_to_cpu(n.nodetype) & ~JFFS2_NODE_ACCURATE);
-	ret = jffs2_flash_write(c, ref_offset(ref), sizeof(n), &retlen, (char *)&n);
+	ret = jffs2_flash_write(c, ref_offset(ref), sizeof(n), &retlen, (const u_char *)&n);
 	if (ret) {
 		pr_warn("Write error in obliterating obsoleted node at 0x%08x: %d\n",
 			ref_offset(ref), ret);
@@ -846,8 +790,8 @@ int jffs2_thread_should_wake(struct jffs
 		return 1;
 
 	if (c->unchecked_size) {
-		jffs2_dbg(1, "jffs2_thread_should_wake(): unchecked_size %d, check_ino #%d\n",
-			  c->unchecked_size, c->check_ino);
+		jffs2_dbg(1, "jffs2_thread_should_wake(): unchecked_size %d, checked_ino #%d\n",
+			  c->unchecked_size, c->checked_ino);
 		return 1;
 	}
 
diff -Nupr old/fs/jffs2/os-linux.h new/fs/jffs2/os-linux.h
--- old/fs/jffs2/os-linux.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/os-linux.h	2022-05-09 20:33:21.200000000 +0800
@@ -12,59 +12,57 @@
 #ifndef __JFFS2_OS_LINUX_H__
 #define __JFFS2_OS_LINUX_H__
 
+#include <dirent.h>
+#include "fs/fs.h"
+#include "jffs2.h"
+#include "jffs2_fs_sb.h"
+
+
+/* jffs2 debug output opion */
+#define CONFIG_JFFS2_FS_DEBUG       0  /* 1 or 2 */
+
+/* jffs2 gc thread section */
+#define JFFS2_GC_THREAD_PRIORITY  10 /* GC thread's priority */
+
+/* zlib section*/
+#define CONFIG_JFFS2_ZLIB
+#define CONFIG_JFFS2_RTIME
+#define CONFIG_JFFS2_RUBIN
+
 /* JFFS2 uses Linux mode bits natively -- no need for conversion */
 #define os_to_jffs2_mode(x) (x)
 #define jffs2_to_os_mode(x) (x)
 
+#ifndef BUG_ON
+#define BUG_ON(x) do {if (unlikely(x)) BUG();} while (0)
+#endif
+
 struct kstatfs;
 struct kvec;
 
-#define JFFS2_INODE_INFO(i) (container_of(i, struct jffs2_inode_info, vfs_inode))
-#define OFNI_EDONI_2SFFJ(f)  (&(f)->vfs_inode)
-#define JFFS2_SB_INFO(sb) (sb->s_fs_info)
-#define OFNI_BS_2SFFJ(c)  ((struct super_block *)c->os_priv)
 
+#define JFFS2_INODE_INFO(i) (&(i)->jffs2_i)
+#define OFNI_EDONI_2SFFJ(f)  \
+        ((struct jffs2_inode *) (((char *)f) - ((char *)(&((struct jffs2_inode *)NULL)->jffs2_i))))
 
 #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
 #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
-#define JFFS2_F_I_UID(f) (i_uid_read(OFNI_EDONI_2SFFJ(f)))
-#define JFFS2_F_I_GID(f) (i_gid_read(OFNI_EDONI_2SFFJ(f)))
-#define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev)
-
-#define JFFS2_CLAMP_TIME(t) ((uint32_t)clamp_t(time64_t, (t), 0, U32_MAX))
-#define ITIME(sec) ((struct timespec64){sec, 0})
-#define JFFS2_NOW() JFFS2_CLAMP_TIME(ktime_get_real_seconds())
-#define I_SEC(tv) JFFS2_CLAMP_TIME((tv).tv_sec)
-#define JFFS2_F_I_CTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_ctime)
-#define JFFS2_F_I_MTIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_mtime)
-#define JFFS2_F_I_ATIME(f) I_SEC(OFNI_EDONI_2SFFJ(f)->i_atime)
-#define sleep_on_spinunlock(wq, s)				\
-	do {							\
-		DECLARE_WAITQUEUE(__wait, current);		\
-		add_wait_queue((wq), &__wait);			\
-		set_current_state(TASK_UNINTERRUPTIBLE);	\
-		spin_unlock(s);					\
-		schedule();					\
-		remove_wait_queue((wq), &__wait);		\
-	} while(0)
-
-static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
-{
-	f->highest_version = 0;
-	f->fragtree = RB_ROOT;
-	f->metadata = NULL;
-	f->dents = NULL;
-	f->target = NULL;
-	f->flags = 0;
-	f->usercompr = 0;
-}
+#define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
+#define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
+#define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime)
+#define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime)
+#define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime)
+
+#define ITIME(sec) ((struct timespec){sec, 0})
+#define I_SEC(tv) ((tv).tv_sec)
 
+#define sleep_on_spinunlock(wq, sl) do {spin_unlock(sl); msleep(100);} while (0)
 
-#define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & SB_RDONLY)
+#define jffs2_is_readonly(c) (0)
 
 #define SECTOR_ADDR(x) ( (((unsigned long)(x) / c->sector_size) * c->sector_size) )
-#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
 
+#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
 
 #ifdef CONFIG_JFFS2_SUMMARY
 #define jffs2_can_mark_obsolete(c) (0)
@@ -77,10 +75,10 @@ static inline void jffs2_init_inode_info
 #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
 
 #define jffs2_flash_write(c, ofs, len, retlen, buf) jffs2_flash_direct_write(c, ofs, len, retlen, buf)
-#define jffs2_flash_read(c, ofs, len, retlen, buf) (mtd_read((c)->mtd, ofs, len, retlen, buf))
-#define jffs2_flush_wbuf_pad(c) ({ do{} while(0); (void)(c), 0; })
+#define jffs2_flash_read(c, ofs, len, retlen, buf) jffs2_flash_direct_read(c, ofs, len, retlen, buf)
+#define jffs2_flush_wbuf_pad(c) (c=c)
 #define jffs2_flush_wbuf_gc(c, i) ({ do{} while(0); (void)(c), (void) i, 0; })
-#define jffs2_write_nand_badblock(c,jeb,bad_offset) (1)
+#define jffs2_write_nand_badblock(c,jeb,p) (0)
 #define jffs2_nand_flash_setup(c) (0)
 #define jffs2_nand_flash_cleanup(c) do {} while(0)
 #define jffs2_wbuf_dirty(c) (0)
@@ -100,7 +98,8 @@ static inline void jffs2_init_inode_info
 
 #else /* NAND and/or ECC'd NOR support present */
 
-#define jffs2_is_writebuffered(c) (c->wbuf != NULL)
+/* current not support */
+#define jffs2_is_writebuffered(c) (0)
 
 #ifdef CONFIG_JFFS2_SUMMARY
 #define jffs2_can_mark_obsolete(c) (0)
@@ -142,38 +141,28 @@ void jffs2_dirty_trigger(struct jffs2_sb
 #endif /* WRITEBUFFER */
 
 /* background.c */
-int jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
+void jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c);
 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c);
 void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c);
 
 /* dir.c */
-extern const struct file_operations jffs2_dir_operations;
-extern const struct inode_operations jffs2_dir_inode_operations;
-
-/* file.c */
-extern const struct file_operations jffs2_file_operations;
-extern const struct inode_operations jffs2_file_inode_operations;
-extern const struct address_space_operations jffs2_file_address_operations;
-int jffs2_fsync(struct file *, loff_t, loff_t, int);
-int jffs2_do_readpage_unlock(void *data, struct page *pg);
-
-/* ioctl.c */
-long jffs2_ioctl(struct file *, unsigned int, unsigned long);
-
-/* symlink.c */
-extern const struct inode_operations jffs2_symlink_inode_operations;
+struct jffs2_inode *jffs2_lookup(struct jffs2_inode *dir_i, const unsigned char *name, int namelen);
+int jffs2_create(struct jffs2_inode *dir_i, const unsigned char *d_name, int mode, struct jffs2_inode **new_i);
+int jffs2_mkdir (struct jffs2_inode *dir_i, const unsigned char *d_name, int mode, struct jffs2_inode **new_i);
+int jffs2_link (struct jffs2_inode *old_d_inode, struct jffs2_inode *dir_i, const unsigned char *d_name);
+int jffs2_symlink(struct jffs2_inode *dir_i, struct jffs2_inode **d_inode, const unsigned char *d_name, const char *target);
+int jffs2_unlink(struct jffs2_inode *dir_i, struct jffs2_inode *d_inode, const unsigned char *d_name);
+int jffs2_rmdir (struct jffs2_inode *dir_i, struct jffs2_inode *d_inode, const unsigned char *d_name);
+int jffs2_rename (struct jffs2_inode *old_dir_i, struct jffs2_inode *d_inode, const unsigned char *old_d_name,
+		  struct jffs2_inode *new_dir_i, const unsigned char *new_d_name);
+int jffs2_readdir(struct jffs2_inode *inode, off_t *offset, off_t *int_off, struct dirent *ent);
 
 /* fs.c */
-int jffs2_setattr (struct dentry *, struct iattr *);
-int jffs2_do_setattr (struct inode *, struct iattr *);
-struct inode *jffs2_iget(struct super_block *, unsigned long);
-void jffs2_evict_inode (struct inode *);
-void jffs2_dirty_inode(struct inode *inode, int flags);
-struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode,
-			       struct jffs2_raw_inode *ri);
-int jffs2_statfs (struct dentry *, struct kstatfs *);
-int jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc);
-int jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc);
+int jffs2_setattr (struct jffs2_inode *inode, struct IATTR *attr);
+struct jffs2_inode *jffs2_iget(struct super_block *sb, uint32_t ino);
+int jffs2_iput(struct jffs2_inode * i);
+struct jffs2_inode *jffs2_new_inode (struct jffs2_inode *dir_i, int mode, struct jffs2_raw_inode *ri);
+
 void jffs2_gc_release_inode(struct jffs2_sb_info *c,
 			    struct jffs2_inode_info *f);
 struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
@@ -183,15 +172,25 @@ unsigned char *jffs2_gc_fetch_page(struc
 				   struct jffs2_inode_info *f,
 				   unsigned long offset,
 				   unsigned long *priv);
+void jffs2_gc_release_page(struct jffs2_sb_info *c,
+			   unsigned char *pg,
+			   unsigned long *priv);
 void jffs2_flash_cleanup(struct jffs2_sb_info *c);
 
+int calculate_inocache_hashsize(uint32_t flash_size);
 
 /* writev.c */
 int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
 		       unsigned long count, loff_t to, size_t *retlen);
 int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
 			size_t *retlen, const u_char *buf);
+int jffs2_flash_direct_read(struct jffs2_sb_info *c, loff_t ofs, size_t len,
+			size_t *retlen, const char *buf);
 
-#endif /* __JFFS2_OS_LINUX_H__ */
+/* super.c */
+int jffs2_fill_super(struct super_block *sb);
+int jffs2_mount(int part_no, struct jffs2_inode **root_node, unsigned long mountflags);
+int jffs2_umount(struct jffs2_inode *root_node);
 
+#endif /* __JFFS2_OS_LINUX_H__ */
 
diff -Nupr old/fs/jffs2/read.c new/fs/jffs2/read.c
--- old/fs/jffs2/read.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/read.c	2022-05-09 20:27:15.580000000 +0800
@@ -9,16 +9,15 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/crc32.h>
 #include <linux/pagemap.h>
-#include <linux/mtd/mtd.h>
 #include <linux/compiler.h>
+#include <mtd_dev.h>
 #include "nodelist.h"
 #include "compr.h"
+#include "los_crc32.h"
+#include "user_copy.h"
 
 int jffs2_read_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
 		     struct jffs2_full_dnode *fd, unsigned char *buf,
@@ -57,6 +56,7 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 	if (crc != je32_to_cpu(ri->node_crc)) {
 		pr_warn("Node CRC %08x != calculated CRC %08x for node at %08x\n",
 			je32_to_cpu(ri->node_crc), crc, ref_offset(fd->raw));
+			jffs2_dbg_dump_node(c, ref_offset(fd->raw));
 		ret = -EIO;
 		goto out_ri;
 	}
@@ -75,9 +75,8 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 		goto out_ri;
 	});
 
-
 	if (ri->compr == JFFS2_COMPR_ZERO) {
-		memset(buf, 0, len);
+		ret = LOS_UserMemClear(buf, len);
 		goto out_ri;
 	}
 
@@ -88,7 +87,11 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 	   Reading partial node and it's compressed - read into readbuf, check checksum, decompress to decomprbuf and copy
 	*/
 	if (ri->compr == JFFS2_COMPR_NONE && len == je32_to_cpu(ri->dsize)) {
-		readbuf = buf;
+		readbuf = kmalloc(je32_to_cpu(ri->dsize), GFP_KERNEL);
+		if (!readbuf) {
+			ret = -ENOMEM;
+			goto out_ri;
+		}
 	} else {
 		readbuf = kmalloc(je32_to_cpu(ri->csize), GFP_KERNEL);
 		if (!readbuf) {
@@ -97,14 +100,10 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 		}
 	}
 	if (ri->compr != JFFS2_COMPR_NONE) {
-		if (len < je32_to_cpu(ri->dsize)) {
-			decomprbuf = kmalloc(je32_to_cpu(ri->dsize), GFP_KERNEL);
-			if (!decomprbuf) {
-				ret = -ENOMEM;
-				goto out_readbuf;
-			}
-		} else {
-			decomprbuf = buf;
+		decomprbuf = kmalloc(je32_to_cpu(ri->dsize), GFP_KERNEL);
+		if (!decomprbuf) {
+			ret = -ENOMEM;
+			goto out_readbuf;
 		}
 	} else {
 		decomprbuf = readbuf;
@@ -113,7 +112,7 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 	jffs2_dbg(2, "Read %d bytes to %p\n", je32_to_cpu(ri->csize),
 		  readbuf);
 	ret = jffs2_flash_read(c, (ref_offset(fd->raw)) + sizeof(*ri),
-			       je32_to_cpu(ri->csize), &readlen, readbuf);
+			       je32_to_cpu(ri->csize), &readlen, (char *)readbuf);
 
 	if (!ret && readlen != je32_to_cpu(ri->csize))
 		ret = -EIO;
@@ -124,6 +123,7 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 	if (crc != je32_to_cpu(ri->data_crc)) {
 		pr_warn("Data CRC %08x != calculated CRC %08x for node at %08x\n",
 			je32_to_cpu(ri->data_crc), crc, ref_offset(fd->raw));
+		jffs2_dbg_dump_node(c, ref_offset(fd->raw));
 		ret = -EIO;
 		goto out_decomprbuf;
 	}
@@ -139,8 +139,8 @@ int jffs2_read_dnode(struct jffs2_sb_inf
 		}
 	}
 
-	if (len < je32_to_cpu(ri->dsize)) {
-		memcpy(buf, decomprbuf+ofs, len);
+	if (LOS_CopyFromKernel(buf, len, decomprbuf + ofs, len) != 0) {
+		ret = -EFAULT;
 	}
  out_decomprbuf:
 	if(decomprbuf != buf && decomprbuf != readbuf)
@@ -184,7 +184,10 @@ int jffs2_read_inode_range(struct jffs2_
 			}
 			jffs2_dbg(1, "Filling non-frag hole from %d-%d\n",
 				  offset, offset + holesize);
-			memset(buf, 0, holesize);
+			ret = LOS_UserMemClear(buf, holesize);
+			if (ret != 0) {
+				return ret;
+			}
 			buf += holesize;
 			offset += holesize;
 			continue;
@@ -193,7 +196,10 @@ int jffs2_read_inode_range(struct jffs2_
 			jffs2_dbg(1, "Filling frag hole from %d-%d (frag 0x%x 0x%x)\n",
 				  offset, holeend, frag->ofs,
 				  frag->ofs + frag->size);
-			memset(buf, 0, holeend - offset);
+			ret = LOS_UserMemClear(buf, holeend - offset);
+			if (ret != 0) {
+				return ret;
+			}
 			buf += holeend - offset;
 			offset = holeend;
 			frag = frag_next(frag);
@@ -214,7 +220,7 @@ int jffs2_read_inode_range(struct jffs2_
 			if (ret) {
 				jffs2_dbg(1, "%s(): error %d\n",
 					  __func__, ret);
-				memset(buf, 0, readlen);
+				(void)LOS_UserMemClear(buf, readlen);
 				return ret;
 			}
 			buf += readlen;
@@ -226,3 +232,15 @@ int jffs2_read_inode_range(struct jffs2_
 	return 0;
 }
 
+int jffs2_flash_direct_read(struct jffs2_sb_info *c, loff_t ofs, size_t len,
+			size_t *retlen, const char *buf)
+{
+	int ret;
+	ret = c->mtd->read(c->mtd, ofs, len, (char *)buf);
+	if (ret >= 0) {
+		*retlen = ret;
+		return 0;
+	}
+	*retlen = 0;
+	return ret;
+}
\ No newline at end of file
diff -Nupr old/fs/jffs2/readinode.c new/fs/jffs2/readinode.c
--- old/fs/jffs2/readinode.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/readinode.c	2022-05-09 20:26:31.030000000 +0800
@@ -9,17 +9,18 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
-#include <linux/crc32.h>
+#include <linux/delay.h>
+#include <linux/semaphore.h>
 #include <linux/pagemap.h>
-#include <linux/mtd/mtd.h>
 #include <linux/compiler.h>
+#include <mtd_dev.h>
 #include "nodelist.h"
+#include "os-linux.h"
+#include "los_crc32.h"
 
 /*
  * Check the data CRC of the node.
@@ -31,9 +32,9 @@
 static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info *tn)
 {
 	struct jffs2_raw_node_ref *ref = tn->fn->raw;
-	int err = 0, pointed = 0;
+	int err = 0;
 	struct jffs2_eraseblock *jeb;
-	unsigned char *buffer;
+	unsigned char *buffer = NULL;
 	uint32_t crc, ofs, len;
 	size_t retlen;
 
@@ -61,48 +62,28 @@ static int check_node_data(struct jffs2_
 	dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n",
 		ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len);
 
-#ifndef __ECOS
-	/* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
-	 * adding and jffs2_flash_read_end() interface. */
-	err = mtd_point(c->mtd, ofs, len, &retlen, (void **)&buffer, NULL);
-	if (!err && retlen < len) {
-		JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize);
-		mtd_unpoint(c->mtd, ofs, retlen);
-	} else if (err) {
-		if (err != -EOPNOTSUPP)
-			JFFS2_WARNING("MTD point failed: error code %d.\n", err);
-	} else
-		pointed = 1; /* succefully pointed to device */
-#endif
-
-	if (!pointed) {
-		buffer = kmalloc(len, GFP_KERNEL);
-		if (unlikely(!buffer))
-			return -ENOMEM;
+	buffer = kmalloc(len, GFP_KERNEL);
+	if (unlikely(!buffer))
+		return -ENOMEM;
 
-		/* TODO: this is very frequent pattern, make it a separate
-		 * routine */
-		err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
-		if (err) {
-			JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
-			goto free_out;
-		}
+	/* TODO: this is very frequent pattern, make it a separate
+		* routine */
+	err = jffs2_flash_read(c, ofs, len, &retlen, (char *)buffer);
+	if (err) {
+		JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
+		goto free_out;
+	}
 
-		if (retlen != len) {
-			JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
-			err = -EIO;
-			goto free_out;
-		}
+	if (retlen != len) {
+		JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
+		err = -EIO;
+		goto free_out;
 	}
 
 	/* Continue calculating CRC */
 	crc = crc32(tn->partial_crc, buffer, len);
-	if(!pointed)
-		kfree(buffer);
-#ifndef __ECOS
-	else
-		mtd_unpoint(c->mtd, ofs, len);
-#endif
+
+	kfree(buffer);
 
 	if (crc != tn->data_crc) {
 		JFFS2_NOTICE("wrong data CRC in data node at 0x%08x: read %#08x, calculated %#08x.\n",
@@ -133,12 +114,7 @@ adj_acc:
 	return 0;
 
 free_out:
-	if(!pointed)
-		kfree(buffer);
-#ifndef __ECOS
-	else
-		mtd_unpoint(c->mtd, ofs, len);
-#endif
+	kfree(buffer);
 	return err;
 }
 
@@ -415,8 +391,12 @@ static void eat_last(struct rb_root *roo
 		link = &parent->rb_right;
 
 	*link = node->rb_left;
-	if (node->rb_left)
-		node->rb_left->__rb_parent_color = node->__rb_parent_color;
+	if (node->rb_left) {
+		node->rb_left->rb_parent_color = node->rb_parent_color;
+		// set child parent only
+		rb_parent(node->rb_left) = parent;
+		node->rb_left = NULL;
+	}
 }
 
 /* We put the version tree in reverse order, so we can use the same eat_last()
@@ -464,8 +444,8 @@ static int jffs2_build_inode_fragtree(st
 #ifdef JFFS2_DBG_READINODE_MESSAGES
 	this = tn_last(&rii->tn_root);
 	while (this) {
-		dbg_readinode("tn %p ver %d range 0x%x-0x%x ov %d\n", this, this->version, this->fn->ofs,
-			      this->fn->ofs+this->fn->size, this->overlapped);
+		dbg_readinode("tn %p ver %d range 0x%x-0x%x ov %d,left %p,right %p ,parent %p\n", this, this->version, this->fn->ofs,
+			      this->fn->ofs+this->fn->size, this->overlapped,this->rb.rb_left,this->rb.rb_right,rb_parent(&(this->rb)));
 		this = tn_prev(this);
 	}
 #endif
@@ -543,11 +523,13 @@ static int jffs2_build_inode_fragtree(st
 
 static void jffs2_free_tmp_dnode_info_list(struct rb_root *list)
 {
-	struct jffs2_tmp_dnode_info *tn, *next;
+	struct jffs2_tmp_dnode_info *tn;
+	struct rb_node *rbn,*next;
 
-	rbtree_postorder_for_each_entry_safe(tn, next, list, rb) {
-			jffs2_free_full_dnode(tn->fn);
-			jffs2_free_tmp_dnode_info(tn);
+	RB_POSTORDER_FOREACH_SAFE(rbn, linux_root, (struct linux_root *)list, next) {
+		tn = (struct jffs2_tmp_dnode_info *)rbn;
+		jffs2_free_full_dnode(tn->fn);
+		jffs2_free_tmp_dnode_info(tn);
 	}
 
 	*list = RB_ROOT;
@@ -659,7 +641,7 @@ static inline int read_direntry(struct j
 		int already = read - sizeof(*rd);
 
 		err = jffs2_flash_read(c, (ref_offset(ref)) + read,
-				rd->nsize - already, &read, &fd->name[already]);
+				rd->nsize - already, &read, (char *)&fd->name[already]);
 		if (unlikely(read != rd->nsize - already) && likely(!err)) {
 			jffs2_free_full_dirent(fd);
 			JFFS2_ERROR("short read: wanted %d bytes, got %zd\n",
@@ -690,7 +672,7 @@ static inline int read_direntry(struct j
 #endif
 	}
 
-	fd->nhash = full_name_hash(NULL, fd->name, rd->nsize);
+	fd->nhash = full_name_hash(fd->name, rd->nsize);
 	fd->next = NULL;
 	fd->name[rd->nsize] = '\0';
 
@@ -956,7 +938,7 @@ static int read_more(struct jffs2_sb_inf
 
 	dbg_readinode("read more %d bytes\n", to_read);
 
-	err = jffs2_flash_read(c, offs, to_read, &retlen, buf + *rdlen);
+	err = jffs2_flash_read(c, offs, to_read, &retlen, (char *)(buf + *rdlen));
 	if (err) {
 		JFFS2_ERROR("can not read %d bytes from 0x%08x, "
 			"error code: %d.\n", to_read, offs, err);
@@ -1042,7 +1024,7 @@ static int jffs2_get_inode_nodes(struct
 		dbg_readinode("read %d bytes at %#08x(%d).\n", len, ref_offset(ref), ref_flags(ref));
 
 		/* FIXME: point() */
-		err = jffs2_flash_read(c, ref_offset(ref), len, &retlen, buf);
+		err = jffs2_flash_read(c, ref_offset(ref), len, &retlen, (char *)buf);
 		if (err) {
 			JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ref_offset(ref), err);
 			goto free_out;
@@ -1079,6 +1061,7 @@ static int jffs2_get_inode_nodes(struct
 
 		case JFFS2_NODETYPE_DIRENT:
 
+			dbg_readinode("node at %08x (%d) is a dirent node\n", ref_offset(ref), ref_flags(ref));
 			if (JFFS2_MIN_NODE_HEADER < sizeof(struct jffs2_raw_dirent) &&
 			    len < sizeof(struct jffs2_raw_dirent)) {
 				err = read_more(c, ref, sizeof(struct jffs2_raw_dirent), &len, buf);
@@ -1094,6 +1077,7 @@ static int jffs2_get_inode_nodes(struct
 
 		case JFFS2_NODETYPE_INODE:
 
+			dbg_readinode("node at %08x (%d) is a data node\n", ref_offset(ref), ref_flags(ref));
 			if (JFFS2_MIN_NODE_HEADER < sizeof(struct jffs2_raw_inode) &&
 			    len < sizeof(struct jffs2_raw_inode)) {
 				err = read_more(c, ref, sizeof(struct jffs2_raw_inode), &len, buf);
@@ -1289,7 +1273,7 @@ static int jffs2_do_read_inode_internal(
 			dbg_readinode("symlink's target '%s' cached\n", f->target);
 		}
 
-		fallthrough;
+		/* fall through... */
 
 	case S_IFBLK:
 	case S_IFCHR:
@@ -1315,7 +1299,7 @@ static int jffs2_do_read_inode_internal(
 		/* OK. We're happy */
 		f->metadata = frag_first(&f->fragtree)->node;
 		jffs2_free_node_frag(frag_first(&f->fragtree));
-		f->fragtree = RB_ROOT;
+		f->fragtree.rb_node = NULL;
 		break;
 	}
 	if (f->inocache->state == INO_STATE_READING)
@@ -1362,6 +1346,7 @@ int jffs2_do_read_inode(struct jffs2_sb_
 			break;
 
 		default:
L
lihongjin 已提交
5511
+		    JFFS2_ERROR("Unknown f->inocache->state %d!\n", f->inocache->state);
X
x_xiny 已提交
5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936
 			BUG();
 		}
 	}
@@ -1375,14 +1360,13 @@ int jffs2_do_read_inode(struct jffs2_sb_
 			return -ENOMEM;
 		}
 		dbg_readinode("creating inocache for root inode\n");
-		memset(f->inocache, 0, sizeof(struct jffs2_inode_cache));
 		f->inocache->ino = f->inocache->pino_nlink = 1;
 		f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
 		f->inocache->state = INO_STATE_READING;
 		jffs2_add_ino_cache(c, f->inocache);
 	}
 	if (!f->inocache) {
-		JFFS2_ERROR("requested to read a nonexistent ino %u\n", ino);
+		JFFS2_ERROR("requestied to read an nonexistent ino %u\n", ino);
 		return -ENOENT;
 	}
 
@@ -1430,6 +1414,11 @@ void jffs2_do_clear_inode(struct jffs2_s
 
 	jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL);
 
+	if (f->target) {
+		kfree(f->target);
+		f->target = NULL;
+	}
+
 	fds = f->dents;
 	while(fds) {
 		fd = fds;
diff -Nupr old/fs/jffs2/scan.c new/fs/jffs2/scan.c
--- old/fs/jffs2/scan.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/scan.c	2022-05-09 20:23:02.230000000 +0800
@@ -9,18 +9,17 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
-#include <linux/mtd/mtd.h>
 #include <linux/pagemap.h>
-#include <linux/crc32.h>
 #include <linux/compiler.h>
 #include "nodelist.h"
 #include "summary.h"
 #include "debug.h"
+#include "mtd_dev.h"
+#include "los_typedef.h"
+#include "los_crc32.h"
 
 #define DEFAULT_EMPTY_SCAN_SIZE 256
 
@@ -74,7 +73,7 @@ static int file_dirty(struct jffs2_sb_in
 		return ret;
 	if ((ret = jffs2_scan_dirty_space(c, jeb, jeb->free_size)))
 		return ret;
-	/* Turned wasted size into dirty, since we apparently 
+	/* Turned wasted size into dirty, since we apparently
 	   think it's recoverable now. */
 	jeb->dirty_size += jeb->wasted_size;
 	c->dirty_size += jeb->wasted_size;
@@ -95,40 +94,26 @@ int jffs2_scan_medium(struct jffs2_sb_in
 	unsigned char *flashbuf = NULL;
 	uint32_t buf_size = 0;
 	struct jffs2_summary *s = NULL; /* summary info collected by the scan process */
-#ifndef __ECOS
-	size_t pointlen, try_size;
+	struct super_block *sb = NULL;
+	struct MtdNorDev *device = NULL;
 
-	ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen,
-			(void **)&flashbuf, NULL);
-	if (!ret && pointlen < c->mtd->size) {
-		/* Don't muck about if it won't let us point to the whole flash */
-		jffs2_dbg(1, "MTD point returned len too short: 0x%zx\n",
-			  pointlen);
-		mtd_unpoint(c->mtd, 0, pointlen);
-		flashbuf = NULL;
-	}
-	if (ret && ret != -EOPNOTSUPP)
-		jffs2_dbg(1, "MTD point failed %d\n", ret);
-#endif
 	if (!flashbuf) {
 		/* For NAND it's quicker to read a whole eraseblock at a time,
 		   apparently */
 		if (jffs2_cleanmarker_oob(c))
-			try_size = c->sector_size;
+			buf_size = c->sector_size;
 		else
-			try_size = PAGE_SIZE;
+			buf_size = PAGE_SIZE;
 
 		jffs2_dbg(1, "Trying to allocate readbuf of %zu "
-			  "bytes\n", try_size);
+			  "bytes\n", buf_size);
 
-		flashbuf = mtd_kmalloc_up_to(c->mtd, &try_size);
+		flashbuf = kmalloc(buf_size, GFP_KERNEL);
 		if (!flashbuf)
 			return -ENOMEM;
 
 		jffs2_dbg(1, "Allocated readbuf of %zu bytes\n",
-			  try_size);
-
-		buf_size = (uint32_t)try_size;
+			  buf_size);
 	}
 
 	if (jffs2_sum_active()) {
@@ -140,7 +125,9 @@ int jffs2_scan_medium(struct jffs2_sb_in
 		}
 	}
 
-	for (i=0; i<c->nr_blocks; i++) {
+	sb = OFNI_BS_2SFFJ(c);
+	device = (struct MtdNorDev*)(sb->s_dev);
+	for (i=device->blockStart; i<c->nr_blocks + device->blockStart; i++) {
 		struct jffs2_eraseblock *jeb = &c->blocks[i];
 
 		cond_resched();
@@ -269,19 +256,12 @@ int jffs2_scan_medium(struct jffs2_sb_in
 			ret = -EIO;
 			goto out;
 		}
-		spin_lock(&c->erase_completion_lock);
-		jffs2_garbage_collect_trigger(c);
-		spin_unlock(&c->erase_completion_lock);
 	}
 	ret = 0;
  out:
-	if (buf_size)
-		kfree(flashbuf);
-#ifndef __ECOS
-	else
-		mtd_unpoint(c->mtd, 0, c->mtd->size);
-#endif
-	kfree(s);
+
+	kfree(flashbuf);
+
 	return ret;
 }
 
@@ -411,7 +391,7 @@ static int jffs2_scan_xref_node(struct j
 	if (!ref)
 		return -ENOMEM;
 
-	/* BEFORE jffs2_build_xattr_subsystem() called, 
+	/* BEFORE jffs2_build_xattr_subsystem() called,
 	 * and AFTER xattr_ref is marked as a dead xref,
 	 * ref->xid is used to store 32bit xid, xd is not used
 	 * ref->ino is used to store 32bit inode-number, ic is not used
@@ -484,10 +464,10 @@ static int jffs2_scan_eraseblock (struct
 		struct jffs2_sum_marker *sm;
 		void *sumptr = NULL;
 		uint32_t sumlen;
-	      
+
 		if (!buf_size) {
 			/* XIP case. Just look, point at the summary if it's there */
-			sm = (void *)buf + c->sector_size - sizeof(*sm);
+			sm = (struct jffs2_sum_marker *)((uint8_t *)buf + c->sector_size - sizeof(*sm));
 			if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) {
 				sumptr = buf + je32_to_cpu(sm->offset);
 				sumlen = c->sector_size - je32_to_cpu(sm->offset);
@@ -500,13 +480,13 @@ static int jffs2_scan_eraseblock (struct
 				buf_len = sizeof(*sm);
 
 			/* Read as much as we want into the _end_ of the preallocated buffer */
-			err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len, 
+			err = jffs2_fill_scan_buf(c, buf + buf_size - buf_len,
 						  jeb->offset + c->sector_size - buf_len,
-						  buf_len);				
+						  buf_len);
 			if (err)
 				return err;
 
-			sm = (void *)buf + buf_size - sizeof(*sm);
+			sm = (struct jffs2_sum_marker *)((uint8_t *)buf + buf_size - sizeof(*sm));
 			if (je32_to_cpu(sm->magic) == JFFS2_SUM_MAGIC) {
 				sumlen = c->sector_size - je32_to_cpu(sm->offset);
 				sumptr = buf + buf_size - sumlen;
@@ -521,18 +501,15 @@ static int jffs2_scan_eraseblock (struct
 					sumptr = kmalloc(sumlen, GFP_KERNEL);
 					if (!sumptr)
 						return -ENOMEM;
-					memcpy(sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len);
+					memcpy((uint8_t *)sumptr + sumlen - buf_len, buf + buf_size - buf_len, buf_len);
 				}
 				if (buf_len < sumlen) {
 					/* Need to read more so that the entire summary node is present */
-					err = jffs2_fill_scan_buf(c, sumptr, 
+					err = jffs2_fill_scan_buf(c, sumptr,
 								  jeb->offset + c->sector_size - sumlen,
-								  sumlen - buf_len);				
-					if (err) {
-						if (sumlen > buf_size)
-							kfree(sumptr);
+								  sumlen - buf_len);
+					if (err)
 						return err;
-					}
 				}
 			}
 
@@ -543,7 +520,7 @@ static int jffs2_scan_eraseblock (struct
 
 			if (buf_size && sumlen > buf_size)
 				kfree(sumptr);
-			/* If it returns with a real error, bail. 
+			/* If it returns with a real error, bail.
 			   If it returns positive, that's a block classification
 			   (i.e. BLK_STATE_xxx) so return that too.
 			   If it returns zero, fall through to full scan. */
@@ -605,7 +582,7 @@ full_scan:
 	/* Now ofs is a complete physical flash offset as it always was... */
 	ofs += jeb->offset;
 
-	noise = 10;
+	noise = 1;
 
 	dbg_summary("no summary found in jeb 0x%08x. Apply original scan.\n",jeb->offset);
 
@@ -698,7 +675,7 @@ scan_more:
 				scan_end = buf_len;
 				goto more_empty;
 			}
-			
+
 			/* See how much more there is to read in this eraseblock... */
 			buf_len = min_t(uint32_t, buf_size, jeb->offset + c->sector_size - ofs);
 			if (!buf_len) {
@@ -948,7 +925,7 @@ scan_more:
 	jffs2_dbg(1, "Block at 0x%08x: free 0x%08x, dirty 0x%08x, unchecked 0x%08x, used 0x%08x, wasted 0x%08x\n",
 		  jeb->offset, jeb->free_size, jeb->dirty_size,
 		  jeb->unchecked_size, jeb->used_size, jeb->wasted_size);
-	
+
 	/* mark_node_obsolete can add to wasted !! */
 	if (jeb->wasted_size) {
 		jeb->dirty_size += jeb->wasted_size;
@@ -976,7 +953,6 @@ struct jffs2_inode_cache *jffs2_scan_mak
 		pr_notice("%s(): allocation of inode cache failed\n", __func__);
 		return NULL;
 	}
-	memset(ic, 0, sizeof(*ic));
 
 	ic->ino = ino;
 	ic->nodes = (void *)ic;
@@ -1067,7 +1043,7 @@ static int jffs2_scan_dirent_node(struct
 	pseudo_random += je32_to_cpu(rd->version);
 
 	/* Should never happen. Did. (OLPC trac #4184)*/
-	checkedlen = strnlen(rd->name, rd->nsize);
+	checkedlen = strnlen((const char *)rd->name, rd->nsize);
 	if (checkedlen < rd->nsize) {
 		pr_err("Dirent at %08x has zeroes in name. Truncating to %d chars\n",
 		       ofs, checkedlen);
@@ -1079,7 +1055,7 @@ static int jffs2_scan_dirent_node(struct
 	memcpy(&fd->name, rd->name, checkedlen);
 	fd->name[checkedlen] = 0;
 
-	crc = crc32(0, fd->name, checkedlen);
+	crc = crc32(0, fd->name, rd->nsize);
 	if (crc != je32_to_cpu(rd->name_crc)) {
 		pr_notice("%s(): Name CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
 			  __func__, ofs, je32_to_cpu(rd->name_crc), crc);
@@ -1104,7 +1080,7 @@ static int jffs2_scan_dirent_node(struct
 	fd->next = NULL;
 	fd->version = je32_to_cpu(rd->version);
 	fd->ino = je32_to_cpu(rd->ino);
-	fd->nhash = full_name_hash(NULL, fd->name, checkedlen);
+	fd->nhash = full_name_hash(fd->name, checkedlen);
 	fd->type = rd->type;
 	jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
 
diff -Nupr old/fs/jffs2/security.c new/fs/jffs2/security.c
--- old/fs/jffs2/security.c	2022-05-09 17:15:24.350000000 +0800
+++ new/fs/jffs2/security.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,72 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2006  NEC Corporation
- *
- * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/fs.h>
-#include <linux/time.h>
-#include <linux/pagemap.h>
-#include <linux/highmem.h>
-#include <linux/crc32.h>
-#include <linux/jffs2.h>
-#include <linux/xattr.h>
-#include <linux/mtd/mtd.h>
-#include <linux/security.h>
-#include "nodelist.h"
-
-/* ---- Initial Security Label(s) Attachment callback --- */
-static int jffs2_initxattrs(struct inode *inode,
-			    const struct xattr *xattr_array, void *fs_info)
-{
-	const struct xattr *xattr;
-	int err = 0;
-
-	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
-		err = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
-					xattr->name, xattr->value,
-					xattr->value_len, 0);
-		if (err < 0)
-			break;
-	}
-	return err;
-}
-
-/* ---- Initial Security Label(s) Attachment ----------- */
-int jffs2_init_security(struct inode *inode, struct inode *dir,
-			const struct qstr *qstr)
-{
-	return security_inode_init_security(inode, dir, qstr,
-					    &jffs2_initxattrs, NULL);
-}
-
-/* ---- XATTR Handler for "security.*" ----------------- */
-static int jffs2_security_getxattr(const struct xattr_handler *handler,
-				   struct dentry *unused, struct inode *inode,
-				   const char *name, void *buffer, size_t size)
-{
-	return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY,
-				 name, buffer, size);
-}
-
-static int jffs2_security_setxattr(const struct xattr_handler *handler,
-				   struct dentry *unused, struct inode *inode,
-				   const char *name, const void *buffer,
-				   size_t size, int flags)
-{
-	return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
-				 name, buffer, size, flags);
-}
-
-const struct xattr_handler jffs2_security_xattr_handler = {
-	.prefix = XATTR_SECURITY_PREFIX,
-	.set = jffs2_security_setxattr,
-	.get = jffs2_security_getxattr
-};
diff -Nupr old/fs/jffs2/summary.c new/fs/jffs2/summary.c
--- old/fs/jffs2/summary.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/summary.c	2022-05-09 20:13:24.440000000 +0800
@@ -10,16 +10,20 @@
  * For licensing information, see the file 'LICENCE' in this directory.
  *
  */
+#include "summary.h"
 
+#ifdef CONFIG_JFFS2_SUMMARY
+
+#ifndef pr_fmt
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#endif
 
 #include <linux/kernel.h>
 #include <linux/slab.h>
-#include <linux/mtd/mtd.h>
+#include <mtd_dev.h>
 #include <linux/pagemap.h>
-#include <linux/crc32.h>
+#include "los_crc32.h"
 #include <linux/compiler.h>
-#include <linux/vmalloc.h>
 #include "nodelist.h"
 #include "debug.h"
 
@@ -388,11 +392,25 @@ static int jffs2_sum_process_sum_data(st
 {
 	struct jffs2_inode_cache *ic;
 	struct jffs2_full_dirent *fd;
-	void *sp;
+	uintptr_t sp;
 	int i, ino;
 	int err;
 
-	sp = summary->sum;
+	sp = (uintptr_t)summary->sum;
+
+#if 0
+	PRINTK("summary: %x %x %d %d %x %x %d %x %x  %p %p\n",
+	je16_to_cpu(summary->magic),
+	je16_to_cpu(summary->nodetype),
+	je32_to_cpu(summary->totlen),
+	je32_to_cpu(summary->hdr_crc),
+	je32_to_cpu(summary->sum_num),
+	je32_to_cpu(summary->cln_mkr),
+	je32_to_cpu(summary->padded),
+	je32_to_cpu(summary->sum_crc),
+	je32_to_cpu(summary->node_crc),
+	sp, summary->sum);
+#endif
 
 	for (i=0; i<je32_to_cpu(summary->sum_num); i++) {
 		dbg_summary("processing summary index %d\n", i);
@@ -404,10 +422,12 @@ static int jffs2_sum_process_sum_data(st
 		if (err)
 			return err;
 
+		//PRINTK("sum type %d \n", je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype));
+
 		switch (je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
 			case JFFS2_NODETYPE_INODE: {
 				struct jffs2_sum_inode_flash *spi;
-				spi = sp;
+				spi = (struct jffs2_sum_inode_flash *)sp;
 
 				ino = je32_to_cpu(spi->inode);
 
@@ -428,13 +448,29 @@ static int jffs2_sum_process_sum_data(st
 
 				sp += JFFS2_SUMMARY_INODE_SIZE;
 
+				//PRINTK("1 sp + %d %p\n", JFFS2_SUMMARY_INODE_SIZE, sp);
+
 				break;
 			}
 
 			case JFFS2_NODETYPE_DIRENT: {
 				struct jffs2_sum_dirent_flash *spd;
 				int checkedlen;
-				spd = sp;
+				spd = (struct jffs2_sum_dirent_flash *)sp;
+
+
+#if 0
+					PRINTK("dir: %x %d %d %d %d %d %d %d %d\n",
+	je16_to_cpu(spd->nodetype),
+	je32_to_cpu(spd->totlen),
+	je32_to_cpu(spd->offset),
+	je32_to_cpu(spd->pino),
+	je32_to_cpu(spd->version),
+	je32_to_cpu(spd->ino),
+	spd->nsize,
+	spd->type,
+	spd->name);
+#endif
 
 				dbg_summary("Dirent at 0x%08x-0x%08x\n",
 					    jeb->offset + je32_to_cpu(spd->offset),
@@ -442,7 +478,7 @@ static int jffs2_sum_process_sum_data(st
 
 
 				/* This should never happen, but https://dev.laptop.org/ticket/4184 */
-				checkedlen = strnlen(spd->name, spd->nsize);
+				checkedlen = strnlen((const char *)spd->name, spd->nsize);
 				if (!checkedlen) {
 					pr_err("Dirent at %08x has zero at start of name. Aborting mount.\n",
 					       jeb->offset +
@@ -463,6 +499,7 @@ static int jffs2_sum_process_sum_data(st
 
 				memcpy(&fd->name, spd->name, checkedlen);
 				fd->name[checkedlen] = 0;
+				//PRINTK("add %s \n", fd->name);
 
 				ic = jffs2_scan_make_ino_cache(c, je32_to_cpu(spd->pino));
 				if (!ic) {
@@ -476,15 +513,19 @@ static int jffs2_sum_process_sum_data(st
 				fd->next = NULL;
 				fd->version = je32_to_cpu(spd->version);
 				fd->ino = je32_to_cpu(spd->ino);
-				fd->nhash = full_name_hash(NULL, fd->name, checkedlen);
+				fd->nhash = full_name_hash((const unsigned char *)fd->name, checkedlen);
 				fd->type = spd->type;
 
 				jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
 
 				*pseudo_random += je32_to_cpu(spd->version);
 
+				//PRINTK("2 sp before add %p\n", sp);
+
 				sp += JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize);
 
+			    //PRINTK("2 sp + %d %p\n", JFFS2_SUMMARY_DIRENT_SIZE(spd->nsize), sp);
+
 				break;
 			}
 #ifdef CONFIG_JFFS2_FS_XATTR
@@ -493,7 +534,7 @@ static int jffs2_sum_process_sum_data(st
 				struct jffs2_sum_xattr_flash *spx;
 
 				spx = (struct jffs2_sum_xattr_flash *)sp;
-				dbg_summary("xattr at %#08x-%#08x (xid=%u, version=%u)\n", 
+				dbg_summary("xattr at %#08x-%#08x (xid=%u, version=%u)\n",
 					    jeb->offset + je32_to_cpu(spx->offset),
 					    jeb->offset + je32_to_cpu(spx->offset) + je32_to_cpu(spx->totlen),
 					    je32_to_cpu(spx->xid), je32_to_cpu(spx->version));
@@ -526,7 +567,7 @@ static int jffs2_sum_process_sum_data(st
 				spr = (struct jffs2_sum_xref_flash *)sp;
 				dbg_summary("xref at %#08x-%#08x\n",
 					    jeb->offset + je32_to_cpu(spr->offset),
-					    jeb->offset + je32_to_cpu(spr->offset) + 
+					    jeb->offset + je32_to_cpu(spr->offset) +
 					    (uint32_t)PAD(sizeof(struct jffs2_raw_xref)));
 
 				ref = jffs2_alloc_xattr_ref();
@@ -679,7 +720,7 @@ static int jffs2_sum_write_data(struct j
 	struct jffs2_sum_marker *sm;
 	struct kvec vecs[2];
 	uint32_t sum_ofs;
-	void *wpage;
+	uintptr_t wpage;
 	int ret;
 	size_t retlen;
 
@@ -713,14 +754,14 @@ static int jffs2_sum_write_data(struct j
 	isum.padded = cpu_to_je32(c->summary->sum_padded);
 	isum.cln_mkr = cpu_to_je32(c->cleanmarker_size);
 	isum.sum_num = cpu_to_je32(c->summary->sum_num);
-	wpage = c->summary->sum_buf;
+	wpage = (uintptr_t)c->summary->sum_buf;
 
 	while (c->summary->sum_num) {
 		temp = c->summary->sum_list_head;
 
 		switch (je16_to_cpu(temp->u.nodetype)) {
 			case JFFS2_NODETYPE_INODE: {
-				struct jffs2_sum_inode_flash *sino_ptr = wpage;
+				struct jffs2_sum_inode_flash *sino_ptr = (struct jffs2_sum_inode_flash *)wpage;
 
 				sino_ptr->nodetype = temp->i.nodetype;
 				sino_ptr->inode = temp->i.inode;
@@ -734,7 +775,7 @@ static int jffs2_sum_write_data(struct j
 			}
 
 			case JFFS2_NODETYPE_DIRENT: {
-				struct jffs2_sum_dirent_flash *sdrnt_ptr = wpage;
+				struct jffs2_sum_dirent_flash *sdrnt_ptr = (struct jffs2_sum_dirent_flash *)wpage;
 
 				sdrnt_ptr->nodetype = temp->d.nodetype;
 				sdrnt_ptr->totlen = temp->d.totlen;
@@ -802,7 +843,7 @@ static int jffs2_sum_write_data(struct j
 
 	wpage += padsize;
 
-	sm = wpage;
+	sm = (struct jffs2_sum_marker *)wpage;
 	sm->offset = cpu_to_je32(c->sector_size - jeb->free_size);
 	sm->magic = cpu_to_je32(JFFS2_SUM_MAGIC);
 
@@ -847,7 +888,7 @@ static int jffs2_sum_write_data(struct j
 /* Write out summary information - called from jffs2_do_reserve_space */
 
 int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
-	__must_hold(&c->erase_completion_block)
+	//__must_hold(&c->erase_completion_block)
 {
 	int datasize, infosize, padsize;
 	struct jffs2_eraseblock *jeb;
@@ -875,3 +916,5 @@ int jffs2_sum_write_sumnode(struct jffs2
 	spin_lock(&c->erase_completion_lock);
 	return ret;
 }
+
+#endif
diff -Nupr old/fs/jffs2/summary.h new/fs/jffs2/summary.h
--- old/fs/jffs2/summary.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/summary.h	2022-05-09 20:35:43.430000000 +0800
@@ -19,8 +19,9 @@
    anyway. */
 #define MAX_SUMMARY_SIZE 65536
 
-#include <linux/uio.h>
-#include <linux/jffs2.h>
+#include <sys/uio.h>
+#include <linux/types.h>
+#include "jffs2.h"
 
 #define BLK_STATE_ALLFF		0
 #define BLK_STATE_CLEAN		1
@@ -169,6 +170,10 @@ struct jffs2_sum_marker
 
 #define JFFS2_SUMMARY_FRAME_SIZE (sizeof(struct jffs2_raw_summary) + sizeof(struct jffs2_sum_marker))
 
+#ifdef LOSCFG_FS_JFFS2_SUMMARY
+#define CONFIG_JFFS2_SUMMARY
+#endif
+
 #ifdef CONFIG_JFFS2_SUMMARY	/* SUMMARY SUPPORT ENABLED */
 
 #define jffs2_sum_active() (1)
diff -Nupr old/fs/jffs2/super.c new/fs/jffs2/super.c
--- old/fs/jffs2/super.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/super.c	2022-05-09 20:09:32.170000000 +0800
@@ -9,433 +9,188 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <linux/fs.h>
-#include <linux/err.h>
-#include <linux/mount.h>
-#include <linux/fs_context.h>
-#include <linux/fs_parser.h>
-#include <linux/jffs2.h>
-#include <linux/pagemap.h>
-#include <linux/mtd/super.h>
-#include <linux/ctype.h>
-#include <linux/namei.h>
-#include <linux/seq_file.h>
-#include <linux/exportfs.h>
-#include "compr.h"
+#include "jffs2.h"
 #include "nodelist.h"
+#include "jffs2_fs_sb.h"
+#include "mtd_dev.h"
+#include "mtd_partition.h"
+#include "compr.h"
+#include "jffs2_hash.h"
 
-static void jffs2_put_super(struct super_block *);
-
-static struct kmem_cache *jffs2_inode_cachep;
+static unsigned char jffs2_mounted_number = 0; /* a counter to track the number of jffs2 instances mounted */
+struct MtdNorDev jffs2_dev_list[CONFIG_MTD_PATTITION_NUM];
 
-static struct inode *jffs2_alloc_inode(struct super_block *sb)
+/*
+ * fill in the superblock
+ */
+int jffs2_fill_super(struct super_block *sb)
 {
-	struct jffs2_inode_info *f;
-
-	f = kmem_cache_alloc(jffs2_inode_cachep, GFP_KERNEL);
-	if (!f)
-		return NULL;
-	return &f->vfs_inode;
-}
+	int ret;
+	struct jffs2_sb_info *c;
+	struct MtdNorDev *device;
 
-static void jffs2_free_inode(struct inode *inode)
-{
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
+	c = JFFS2_SB_INFO(sb);
+	device = (struct MtdNorDev*)(sb->s_dev);
 
-	kfree(f->target);
-	kmem_cache_free(jffs2_inode_cachep, f);
-}
+	(void)mutex_init(&c->alloc_sem);
+	(void)mutex_init(&c->erase_free_sem);
+	spin_lock_init(&c->erase_completion_lock);
+	spin_lock_init(&c->inocache_lock);
 
-static void jffs2_i_init_once(void *foo)
-{
-	struct jffs2_inode_info *f = foo;
+	/* sector size is the erase block size */
+	c->sector_size = device->blockSize;
+	c->flash_size  = (device->blockEnd - device->blockStart + 1) * device->blockSize;
+	c->cleanmarker_size = sizeof(struct jffs2_unknown_node);
 
-	mutex_init(&f->sem);
-	inode_init_once(&f->vfs_inode);
-}
+	ret = jffs2_do_mount_fs(c);
+	if (ret) {
+		(void)mutex_destroy(&c->alloc_sem);
+		(void)mutex_destroy(&c->erase_free_sem);
+		return ret;
+	}
+	D1(printk(KERN_DEBUG "jffs2_fill_super(): Getting root inode\n"));
+
+	sb->s_root = jffs2_iget(sb, 1);
+
+	if (IS_ERR(sb->s_root)) {
+		D1(printk(KERN_WARNING "get root inode failed\n"));
+		ret = PTR_ERR(sb->s_root);
+		sb->s_root = NULL;
+		jffs2_free_ino_caches(c);
+		jffs2_free_raw_node_refs(c);
+		free(c->blocks);
+		(void)mutex_destroy(&c->alloc_sem);
+		(void)mutex_destroy(&c->erase_free_sem);
 
-static const char *jffs2_compr_name(unsigned int compr)
-{
-	switch (compr) {
-	case JFFS2_COMPR_MODE_NONE:
-		return "none";
-#ifdef CONFIG_JFFS2_LZO
-	case JFFS2_COMPR_MODE_FORCELZO:
-		return "lzo";
-#endif
-#ifdef CONFIG_JFFS2_ZLIB
-	case JFFS2_COMPR_MODE_FORCEZLIB:
-		return "zlib";
-#endif
-	default:
-		/* should never happen; programmer error */
-		WARN_ON(1);
-		return "";
+		return ret;
 	}
-}
-
-static int jffs2_show_options(struct seq_file *s, struct dentry *root)
-{
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(root->d_sb);
-	struct jffs2_mount_opts *opts = &c->mount_opts;
-
-	if (opts->override_compr)
-		seq_printf(s, ",compr=%s", jffs2_compr_name(opts->compr));
-	if (opts->set_rp_size)
-		seq_printf(s, ",rp_size=%u", opts->rp_size / 1024);
-
-	return 0;
-}
-
-static int jffs2_sync_fs(struct super_block *sb, int wait)
-{
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-
-#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
-	if (jffs2_is_writebuffered(c))
-		cancel_delayed_work_sync(&c->wbuf_dwork);
-#endif
-
-	mutex_lock(&c->alloc_sem);
-	jffs2_flush_wbuf_pad(c);
-	mutex_unlock(&c->alloc_sem);
 	return 0;
 }
 
-static struct inode *jffs2_nfs_get_inode(struct super_block *sb, uint64_t ino,
-					 uint32_t generation)
+int jffs2_mount(int part_no, struct jffs2_inode **root_node, unsigned long mountflags)
 {
-	/* We don't care about i_generation. We'll destroy the flash
-	   before we start re-using inode numbers anyway. And even
-	   if that wasn't true, we'd have other problems...*/
-	return jffs2_iget(sb, ino);
-}
-
-static struct dentry *jffs2_fh_to_dentry(struct super_block *sb, struct fid *fid,
-					 int fh_len, int fh_type)
-{
-        return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
-                                    jffs2_nfs_get_inode);
-}
-
-static struct dentry *jffs2_fh_to_parent(struct super_block *sb, struct fid *fid,
-					 int fh_len, int fh_type)
-{
-        return generic_fh_to_parent(sb, fid, fh_len, fh_type,
-                                    jffs2_nfs_get_inode);
-}
-
-static struct dentry *jffs2_get_parent(struct dentry *child)
-{
-	struct jffs2_inode_info *f;
-	uint32_t pino;
-
-	BUG_ON(!d_is_dir(child));
-
-	f = JFFS2_INODE_INFO(d_inode(child));
-
-	pino = f->inocache->pino_nlink;
-
-	JFFS2_DEBUG("Parent of directory ino #%u is #%u\n",
-		    f->inocache->ino, pino);
-
-	return d_obtain_alias(jffs2_iget(child->d_sb, pino));
-}
-
-static const struct export_operations jffs2_export_ops = {
-	.get_parent = jffs2_get_parent,
-	.fh_to_dentry = jffs2_fh_to_dentry,
-	.fh_to_parent = jffs2_fh_to_parent,
-};
-
-/*
- * JFFS2 mount options.
- *
- * Opt_source: The source device
- * Opt_override_compr: override default compressor
- * Opt_rp_size: size of reserved pool in KiB
- */
-enum {
-	Opt_override_compr,
-	Opt_rp_size,
-};
-
-static const struct constant_table jffs2_param_compr[] = {
-	{"none",	JFFS2_COMPR_MODE_NONE },
-#ifdef CONFIG_JFFS2_LZO
-	{"lzo",		JFFS2_COMPR_MODE_FORCELZO },
-#endif
-#ifdef CONFIG_JFFS2_ZLIB
-	{"zlib",	JFFS2_COMPR_MODE_FORCEZLIB },
-#endif
-	{}
-};
+	struct super_block *sb = NULL;
+	struct jffs2_sb_info *c = NULL;
+	LOS_DL_LIST *part_head = NULL;
+	struct MtdDev *spinor_mtd = NULL;
+	mtd_partition *mtd_part = GetSpinorPartitionHead();
+	int ret;
 
-static const struct fs_parameter_spec jffs2_fs_parameters[] = {
-	fsparam_enum	("compr",	Opt_override_compr, jffs2_param_compr),
-	fsparam_u32	("rp_size",	Opt_rp_size),
-	{}
-};
+	jffs2_dbg(1, "begin los_jffs2_mount:%d\n", part_no);
 
-static int jffs2_parse_param(struct fs_context *fc, struct fs_parameter *param)
-{
-	struct fs_parse_result result;
-	struct jffs2_sb_info *c = fc->s_fs_info;
-	int opt;
-
-	opt = fs_parse(fc, jffs2_fs_parameters, param, &result);
-	if (opt < 0)
-		return opt;
-
-	switch (opt) {
-	case Opt_override_compr:
-		c->mount_opts.compr = result.uint_32;
-		c->mount_opts.override_compr = true;
-		break;
-	case Opt_rp_size:
-		if (result.uint_32 > UINT_MAX / 1024)
-			return invalf(fc, "jffs2: rp_size unrepresentable");
-		c->mount_opts.rp_size = result.uint_32 * 1024;
-		c->mount_opts.set_rp_size = true;
-		break;
-	default:
-		return -EINVAL;
+	sb = zalloc(sizeof(struct super_block));
+	if (sb == NULL) {
+		return -ENOMEM;
 	}
 
-	return 0;
-}
-
-static inline void jffs2_update_mount_opts(struct fs_context *fc)
-{
-	struct jffs2_sb_info *new_c = fc->s_fs_info;
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(fc->root->d_sb);
-
-	mutex_lock(&c->alloc_sem);
-	if (new_c->mount_opts.override_compr) {
-		c->mount_opts.override_compr = new_c->mount_opts.override_compr;
-		c->mount_opts.compr = new_c->mount_opts.compr;
-	}
-	if (new_c->mount_opts.set_rp_size) {
-		c->mount_opts.set_rp_size = new_c->mount_opts.set_rp_size;
-		c->mount_opts.rp_size = new_c->mount_opts.rp_size;
+	ret = Jffs2HashInit(&sb->s_node_hash_lock, &sb->s_node_hash[0]);
+	if (ret) {
+		free(sb);
+		return ret;
+	}
+	part_head = &(GetSpinorPartitionHead()->node_info);
+	LOS_DL_LIST_FOR_EACH_ENTRY(mtd_part,part_head, mtd_partition, node_info) {
+		if (mtd_part->patitionnum == part_no)
+			break;
+	}
+#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
+	spinor_mtd = GetMtd("spinor");
+#else
+	spinor_mtd = (struct MtdDev *)LOS_DL_LIST_ENTRY(part_head->pstNext, mtd_partition, node_info)->mtd_info;
+#endif
+	if (spinor_mtd == NULL) {
+		free(sb);
+		return -EPERM;
+	}
+	jffs2_dev_list[part_no].blockEnd = mtd_part->end_block;
+	jffs2_dev_list[part_no].blockSize = spinor_mtd->eraseSize;
+	jffs2_dev_list[part_no].blockStart = mtd_part->start_block;
+#ifndef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
+	(void)FreeMtd(spinor_mtd);
+#endif
+	sb->jffs2_sb.mtd = mtd_part->mtd_info;
+	sb->s_dev = &jffs2_dev_list[part_no];
+
+	c = JFFS2_SB_INFO(sb);
+	c->flash_size  = (mtd_part->end_block - mtd_part->start_block + 1) * spinor_mtd->eraseSize;
+	c->inocache_hashsize = calculate_inocache_hashsize(c->flash_size);
+	c->sector_size = spinor_mtd->eraseSize;
+
+	jffs2_dbg(1, "C mtd_size:%d,mtd-erase:%d,blocks:%d,hashsize:%d\n",
+		c->flash_size, c->sector_size, c->flash_size / c->sector_size, c->inocache_hashsize);
+
+	c->inocache_list = zalloc(sizeof(struct jffs2_inode_cache *) * c->inocache_hashsize);
+	if (c->inocache_list == NULL) {
+		free(sb);
+		return -ENOMEM;
+	}
+	if (jffs2_mounted_number++ == 0) {
+		(void)jffs2_create_slab_caches(); // No error check, cannot fail
+		(void)jffs2_compressors_init();
 	}
-	mutex_unlock(&c->alloc_sem);
-}
-
-static int jffs2_reconfigure(struct fs_context *fc)
-{
-	struct super_block *sb = fc->root->d_sb;
-
-	sync_filesystem(sb);
-	jffs2_update_mount_opts(fc);
-
-	return jffs2_do_remount_fs(sb, fc);
-}
-
-static const struct super_operations jffs2_super_operations =
-{
-	.alloc_inode =	jffs2_alloc_inode,
-	.free_inode =	jffs2_free_inode,
-	.put_super =	jffs2_put_super,
-	.statfs =	jffs2_statfs,
-	.evict_inode =	jffs2_evict_inode,
-	.dirty_inode =	jffs2_dirty_inode,
-	.show_options =	jffs2_show_options,
-	.sync_fs =	jffs2_sync_fs,
-};
-
-/*
- * fill in the superblock
- */
-static int jffs2_fill_super(struct super_block *sb, struct fs_context *fc)
-{
-	struct jffs2_sb_info *c = sb->s_fs_info;
-
-	jffs2_dbg(1, "jffs2_get_sb_mtd():"
-		  " New superblock for device %d (\"%s\")\n",
-		  sb->s_mtd->index, sb->s_mtd->name);
-
-	c->mtd = sb->s_mtd;
-	c->os_priv = sb;
-
-	if (c->mount_opts.rp_size > c->mtd->size)
-		return invalf(fc, "jffs2: Too large reserve pool specified, max is %llu KB",
-			      c->mtd->size / 1024);
-
-	/* Initialize JFFS2 superblock locks, the further initialization will
-	 * be done later */
-	mutex_init(&c->alloc_sem);
-	mutex_init(&c->erase_free_sem);
-	init_waitqueue_head(&c->erase_wait);
-	init_waitqueue_head(&c->inocache_wq);
-	spin_lock_init(&c->erase_completion_lock);
-	spin_lock_init(&c->inocache_lock);
-
-	sb->s_op = &jffs2_super_operations;
-	sb->s_export_op = &jffs2_export_ops;
-	sb->s_flags = sb->s_flags | SB_NOATIME;
-	sb->s_xattr = jffs2_xattr_handlers;
-#ifdef CONFIG_JFFS2_FS_POSIX_ACL
-	sb->s_flags |= SB_POSIXACL;
-#endif
-	return jffs2_do_fill_super(sb, fc);
-}
-
-static int jffs2_get_tree(struct fs_context *fc)
-{
-	return get_tree_mtd(fc, jffs2_fill_super);
-}
-
-static void jffs2_free_fc(struct fs_context *fc)
-{
-	kfree(fc->s_fs_info);
-}
 
-static const struct fs_context_operations jffs2_context_ops = {
-	.free		= jffs2_free_fc,
-	.parse_param	= jffs2_parse_param,
-	.get_tree	= jffs2_get_tree,
-	.reconfigure	= jffs2_reconfigure,
-};
+	ret = jffs2_fill_super(sb);
+	if (ret) {
+		if (--jffs2_mounted_number == 0) {
+			jffs2_destroy_slab_caches();
+			(void)jffs2_compressors_exit();
+		}
 
-static int jffs2_init_fs_context(struct fs_context *fc)
-{
-	struct jffs2_sb_info *ctx;
+		free(sb);
+		free(c->inocache_list);
+		c->inocache_list = NULL;
+		return ret;
+	}
 
-	ctx = kzalloc(sizeof(struct jffs2_sb_info), GFP_KERNEL);
-	if (!ctx)
-		return -ENOMEM;
+	if (!(mountflags & MS_RDONLY)) {
+		jffs2_start_garbage_collect_thread(c);
+	}
 
-	fc->s_fs_info = ctx;
-	fc->ops = &jffs2_context_ops;
+	sb->s_mount_flags = mountflags;
+	*root_node = sb->s_root;
 	return 0;
 }
 
-static void jffs2_put_super (struct super_block *sb)
+int jffs2_umount(struct jffs2_inode *root_node)
 {
+	struct super_block *sb = root_node->i_sb;
 	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
+	struct jffs2_full_dirent *fd, *next;
 
-	jffs2_dbg(2, "%s()\n", __func__);
+	D2(PRINTK("Jffs2Umount\n"));
 
-	mutex_lock(&c->alloc_sem);
-	jffs2_flush_wbuf_pad(c);
-	mutex_unlock(&c->alloc_sem);
-
-	jffs2_sum_exit(c);
-
-	jffs2_free_ino_caches(c);
-	jffs2_free_raw_node_refs(c);
-	kvfree(c->blocks);
-	jffs2_flash_cleanup(c);
-	kfree(c->inocache_list);
-	jffs2_clear_xattr_subsystem(c);
-	mtd_sync(c->mtd);
-	jffs2_dbg(1, "%s(): returning\n", __func__);
-}
-
-static void jffs2_kill_sb(struct super_block *sb)
-{
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
-	if (c && !sb_rdonly(sb))
+	// Only really umount if this is the only mount
+	if (!(sb->s_mount_flags & MS_RDONLY)) {
 		jffs2_stop_garbage_collect_thread(c);
-	kill_mtd_super(sb);
-	kfree(c);
-}
-
-static struct file_system_type jffs2_fs_type = {
-	.owner =	THIS_MODULE,
-	.name =		"jffs2",
-	.init_fs_context = jffs2_init_fs_context,
-	.parameters =	jffs2_fs_parameters,
-	.kill_sb =	jffs2_kill_sb,
-};
-MODULE_ALIAS_FS("jffs2");
+	}
 
-static int __init init_jffs2_fs(void)
-{
-	int ret;
+	// free directory entries
+	for (fd = root_node->jffs2_i.dents; fd; fd = next) {
+		next = fd->next;
+		jffs2_free_full_dirent(fd);
+	}
 
-	/* Paranoia checks for on-medium structures. If we ask GCC
-	   to pack them with __attribute__((packed)) then it _also_
-	   assumes that they're not aligned -- so it emits crappy
-	   code on some architectures. Ideally we want an attribute
-	   which means just 'no padding', without the alignment
-	   thing. But GCC doesn't have that -- we have to just
-	   hope the structs are the right sizes, instead. */
-	BUILD_BUG_ON(sizeof(struct jffs2_unknown_node) != 12);
-	BUILD_BUG_ON(sizeof(struct jffs2_raw_dirent) != 40);
-	BUILD_BUG_ON(sizeof(struct jffs2_raw_inode) != 68);
-	BUILD_BUG_ON(sizeof(struct jffs2_raw_summary) != 32);
-
-	pr_info("version 2.2."
-#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
-	       " (NAND)"
-#endif
-#ifdef CONFIG_JFFS2_SUMMARY
-	       " (SUMMARY) "
-#endif
-	       " © 2001-2006 Red Hat, Inc.\n");
+	free(root_node);
 
-	jffs2_inode_cachep = kmem_cache_create("jffs2_i",
-					     sizeof(struct jffs2_inode_info),
-					     0, (SLAB_RECLAIM_ACCOUNT|
-						SLAB_MEM_SPREAD|SLAB_ACCOUNT),
-					     jffs2_i_init_once);
-	if (!jffs2_inode_cachep) {
-		pr_err("error: Failed to initialise inode cache\n");
-		return -ENOMEM;
-	}
-	ret = jffs2_compressors_init();
-	if (ret) {
-		pr_err("error: Failed to initialise compressors\n");
-		goto out;
-	}
-	ret = jffs2_create_slab_caches();
-	if (ret) {
-		pr_err("error: Failed to initialise slab caches\n");
-		goto out_compressors;
-	}
-	ret = register_filesystem(&jffs2_fs_type);
-	if (ret) {
-		pr_err("error: Failed to register filesystem\n");
-		goto out_slab;
+	// Clean up the super block and root_node inode
+	jffs2_free_ino_caches(c);
+	jffs2_free_raw_node_refs(c);
+	free(c->blocks);
+	c->blocks = NULL;
+	free(c->inocache_list);
+	c->inocache_list = NULL;
+	(void)Jffs2HashDeinit(&sb->s_node_hash_lock);
+
+	(void)mutex_destroy(&c->alloc_sem);
+	(void)mutex_destroy(&c->erase_free_sem);
+	free(sb);
+	// That's all folks.
+	D2(PRINTK("Jffs2Umount No current mounts\n"));
+
+	if (--jffs2_mounted_number == 0) {
+		jffs2_destroy_slab_caches();
+		(void)jffs2_compressors_exit();
 	}
 	return 0;
-
- out_slab:
-	jffs2_destroy_slab_caches();
- out_compressors:
-	jffs2_compressors_exit();
- out:
-	kmem_cache_destroy(jffs2_inode_cachep);
-	return ret;
 }
-
-static void __exit exit_jffs2_fs(void)
-{
-	unregister_filesystem(&jffs2_fs_type);
-	jffs2_destroy_slab_caches();
-	jffs2_compressors_exit();
-
-	/*
-	 * Make sure all delayed rcu free inodes are flushed before we
-	 * destroy cache.
-	 */
-	rcu_barrier();
-	kmem_cache_destroy(jffs2_inode_cachep);
-}
-
-module_init(init_jffs2_fs);
-module_exit(exit_jffs2_fs);
-
-MODULE_DESCRIPTION("The Journalling Flash File System, v2");
-MODULE_AUTHOR("Red Hat, Inc.");
-MODULE_LICENSE("GPL"); // Actually dual-licensed, but it doesn't matter for
-		       // the sake of this tag. It's Free Software.
diff -Nupr old/fs/jffs2/symlink.c new/fs/jffs2/symlink.c
--- old/fs/jffs2/symlink.c	2022-05-09 17:15:24.350000000 +0800
+++ new/fs/jffs2/symlink.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,19 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2001-2007 Red Hat, Inc.
- *
- * Created by David Woodhouse <dwmw2@infradead.org>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#include "nodelist.h"
-
-const struct inode_operations jffs2_symlink_inode_operations =
-{
-	.get_link =	simple_get_link,
-	.setattr =	jffs2_setattr,
-	.listxattr =	jffs2_listxattr,
-};
diff -Nupr old/fs/jffs2/wbuf.c new/fs/jffs2/wbuf.c
--- old/fs/jffs2/wbuf.c	2022-05-09 17:15:24.350000000 +0800
+++ new/fs/jffs2/wbuf.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,1350 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2001-2007 Red Hat, Inc.
- * Copyright © 2004 Thomas Gleixner <tglx@linutronix.de>
- *
- * Created by David Woodhouse <dwmw2@infradead.org>
- * Modified debugged and enhanced by Thomas Gleixner <tglx@linutronix.de>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/mtd/mtd.h>
-#include <linux/crc32.h>
-#include <linux/mtd/rawnand.h>
-#include <linux/jiffies.h>
-#include <linux/sched.h>
-#include <linux/writeback.h>
-
-#include "nodelist.h"
-
-/* For testing write failures */
-#undef BREAKME
-#undef BREAKMEHEADER
-
-#ifdef BREAKME
-static unsigned char *brokenbuf;
-#endif
-
-#define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(c->wbuf_pagesize)) * (unsigned long)(c->wbuf_pagesize) )
-#define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(c->wbuf_pagesize) )
-
-/* max. erase failures before we mark a block bad */
-#define MAX_ERASE_FAILURES 	2
-
-struct jffs2_inodirty {
-	uint32_t ino;
-	struct jffs2_inodirty *next;
-};
-
-static struct jffs2_inodirty inodirty_nomem;
-
-static int jffs2_wbuf_pending_for_ino(struct jffs2_sb_info *c, uint32_t ino)
-{
-	struct jffs2_inodirty *this = c->wbuf_inodes;
-
-	/* If a malloc failed, consider _everything_ dirty */
-	if (this == &inodirty_nomem)
-		return 1;
-
-	/* If ino == 0, _any_ non-GC writes mean 'yes' */
-	if (this && !ino)
-		return 1;
-
-	/* Look to see if the inode in question is pending in the wbuf */
-	while (this) {
-		if (this->ino == ino)
-			return 1;
-		this = this->next;
-	}
-	return 0;
-}
-
-static void jffs2_clear_wbuf_ino_list(struct jffs2_sb_info *c)
-{
-	struct jffs2_inodirty *this;
-
-	this = c->wbuf_inodes;
-
-	if (this != &inodirty_nomem) {
-		while (this) {
-			struct jffs2_inodirty *next = this->next;
-			kfree(this);
-			this = next;
-		}
-	}
-	c->wbuf_inodes = NULL;
-}
-
-static void jffs2_wbuf_dirties_inode(struct jffs2_sb_info *c, uint32_t ino)
-{
-	struct jffs2_inodirty *new;
-
-	/* Schedule delayed write-buffer write-out */
-	jffs2_dirty_trigger(c);
-
-	if (jffs2_wbuf_pending_for_ino(c, ino))
-		return;
-
-	new = kmalloc(sizeof(*new), GFP_KERNEL);
-	if (!new) {
-		jffs2_dbg(1, "No memory to allocate inodirty. Fallback to all considered dirty\n");
-		jffs2_clear_wbuf_ino_list(c);
-		c->wbuf_inodes = &inodirty_nomem;
-		return;
-	}
-	new->ino = ino;
-	new->next = c->wbuf_inodes;
-	c->wbuf_inodes = new;
-	return;
-}
-
-static inline void jffs2_refile_wbuf_blocks(struct jffs2_sb_info *c)
-{
-	struct list_head *this, *next;
-	static int n;
-
-	if (list_empty(&c->erasable_pending_wbuf_list))
-		return;
-
-	list_for_each_safe(this, next, &c->erasable_pending_wbuf_list) {
-		struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
-
-		jffs2_dbg(1, "Removing eraseblock at 0x%08x from erasable_pending_wbuf_list...\n",
-			  jeb->offset);
-		list_del(this);
-		if ((jiffies + (n++)) & 127) {
-			/* Most of the time, we just erase it immediately. Otherwise we
-			   spend ages scanning it on mount, etc. */
-			jffs2_dbg(1, "...and adding to erase_pending_list\n");
-			list_add_tail(&jeb->list, &c->erase_pending_list);
-			c->nr_erasing_blocks++;
-			jffs2_garbage_collect_trigger(c);
-		} else {
-			/* Sometimes, however, we leave it elsewhere so it doesn't get
-			   immediately reused, and we spread the load a bit. */
-			jffs2_dbg(1, "...and adding to erasable_list\n");
-			list_add_tail(&jeb->list, &c->erasable_list);
-		}
-	}
-}
-
-#define REFILE_NOTEMPTY 0
-#define REFILE_ANYWAY   1
-
-static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, int allow_empty)
-{
-	jffs2_dbg(1, "About to refile bad block at %08x\n", jeb->offset);
-
-	/* File the existing block on the bad_used_list.... */
-	if (c->nextblock == jeb)
-		c->nextblock = NULL;
-	else /* Not sure this should ever happen... need more coffee */
-		list_del(&jeb->list);
-	if (jeb->first_node) {
-		jffs2_dbg(1, "Refiling block at %08x to bad_used_list\n",
-			  jeb->offset);
-		list_add(&jeb->list, &c->bad_used_list);
-	} else {
-		BUG_ON(allow_empty == REFILE_NOTEMPTY);
-		/* It has to have had some nodes or we couldn't be here */
-		jffs2_dbg(1, "Refiling block at %08x to erase_pending_list\n",
-			  jeb->offset);
-		list_add(&jeb->list, &c->erase_pending_list);
-		c->nr_erasing_blocks++;
-		jffs2_garbage_collect_trigger(c);
-	}
-
-	if (!jffs2_prealloc_raw_node_refs(c, jeb, 1)) {
-		uint32_t oldfree = jeb->free_size;
-
-		jffs2_link_node_ref(c, jeb, 
-				    (jeb->offset+c->sector_size-oldfree) | REF_OBSOLETE,
-				    oldfree, NULL);
-		/* convert to wasted */
-		c->wasted_size += oldfree;
-		jeb->wasted_size += oldfree;
-		c->dirty_size -= oldfree;
-		jeb->dirty_size -= oldfree;
-	}
-
-	jffs2_dbg_dump_block_lists_nolock(c);
-	jffs2_dbg_acct_sanity_check_nolock(c,jeb);
-	jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
-}
-
-static struct jffs2_raw_node_ref **jffs2_incore_replace_raw(struct jffs2_sb_info *c,
-							    struct jffs2_inode_info *f,
-							    struct jffs2_raw_node_ref *raw,
-							    union jffs2_node_union *node)
-{
-	struct jffs2_node_frag *frag;
-	struct jffs2_full_dirent *fd;
-
-	dbg_noderef("incore_replace_raw: node at %p is {%04x,%04x}\n",
-		    node, je16_to_cpu(node->u.magic), je16_to_cpu(node->u.nodetype));
-
-	BUG_ON(je16_to_cpu(node->u.magic) != 0x1985 &&
-	       je16_to_cpu(node->u.magic) != 0);
-
-	switch (je16_to_cpu(node->u.nodetype)) {
-	case JFFS2_NODETYPE_INODE:
-		if (f->metadata && f->metadata->raw == raw) {
-			dbg_noderef("Will replace ->raw in f->metadata at %p\n", f->metadata);
-			return &f->metadata->raw;
-		}
-		frag = jffs2_lookup_node_frag(&f->fragtree, je32_to_cpu(node->i.offset));
-		BUG_ON(!frag);
-		/* Find a frag which refers to the full_dnode we want to modify */
-		while (!frag->node || frag->node->raw != raw) {
-			frag = frag_next(frag);
-			BUG_ON(!frag);
-		}
-		dbg_noderef("Will replace ->raw in full_dnode at %p\n", frag->node);
-		return &frag->node->raw;
-
-	case JFFS2_NODETYPE_DIRENT:
-		for (fd = f->dents; fd; fd = fd->next) {
-			if (fd->raw == raw) {
-				dbg_noderef("Will replace ->raw in full_dirent at %p\n", fd);
-				return &fd->raw;
-			}
-		}
-		BUG();
-
-	default:
-		dbg_noderef("Don't care about replacing raw for nodetype %x\n",
-			    je16_to_cpu(node->u.nodetype));
-		break;
-	}
-	return NULL;
-}
-
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf,
-			      uint32_t ofs)
-{
-	int ret;
-	size_t retlen;
-	char *eccstr;
-
-	ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, c->wbuf_verify);
-	if (ret && ret != -EUCLEAN && ret != -EBADMSG) {
-		pr_warn("%s(): Read back of page at %08x failed: %d\n",
-			__func__, c->wbuf_ofs, ret);
-		return ret;
-	} else if (retlen != c->wbuf_pagesize) {
-		pr_warn("%s(): Read back of page at %08x gave short read: %zd not %d\n",
-			__func__, ofs, retlen, c->wbuf_pagesize);
-		return -EIO;
-	}
-	if (!memcmp(buf, c->wbuf_verify, c->wbuf_pagesize))
-		return 0;
-
-	if (ret == -EUCLEAN)
-		eccstr = "corrected";
-	else if (ret == -EBADMSG)
-		eccstr = "correction failed";
-	else
-		eccstr = "OK or unused";
-
-	pr_warn("Write verify error (ECC %s) at %08x. Wrote:\n",
-		eccstr, c->wbuf_ofs);
-	print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1,
-		       c->wbuf, c->wbuf_pagesize, 0);
-
-	pr_warn("Read back:\n");
-	print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET, 16, 1,
-		       c->wbuf_verify, c->wbuf_pagesize, 0);
-
-	return -EIO;
-}
-#else
-#define jffs2_verify_write(c,b,o) (0)
-#endif
-
-/* Recover from failure to write wbuf. Recover the nodes up to the
- * wbuf, not the one which we were starting to try to write. */
-
-static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
-{
-	struct jffs2_eraseblock *jeb, *new_jeb;
-	struct jffs2_raw_node_ref *raw, *next, *first_raw = NULL;
-	size_t retlen;
-	int ret;
-	int nr_refile = 0;
-	unsigned char *buf;
-	uint32_t start, end, ofs, len;
-
-	jeb = &c->blocks[c->wbuf_ofs / c->sector_size];
-
-	spin_lock(&c->erase_completion_lock);
-	if (c->wbuf_ofs % c->mtd->erasesize)
-		jffs2_block_refile(c, jeb, REFILE_NOTEMPTY);
-	else
-		jffs2_block_refile(c, jeb, REFILE_ANYWAY);
-	spin_unlock(&c->erase_completion_lock);
-
-	BUG_ON(!ref_obsolete(jeb->last_node));
-
-	/* Find the first node to be recovered, by skipping over every
-	   node which ends before the wbuf starts, or which is obsolete. */
-	for (next = raw = jeb->first_node; next; raw = next) {
-		next = ref_next(raw);
-
-		if (ref_obsolete(raw) || 
-		    (next && ref_offset(next) <= c->wbuf_ofs)) {
-			dbg_noderef("Skipping node at 0x%08x(%d)-0x%08x which is either before 0x%08x or obsolete\n",
-				    ref_offset(raw), ref_flags(raw),
-				    (ref_offset(raw) + ref_totlen(c, jeb, raw)),
-				    c->wbuf_ofs);
-			continue;
-		}
-		dbg_noderef("First node to be recovered is at 0x%08x(%d)-0x%08x\n",
-			    ref_offset(raw), ref_flags(raw),
-			    (ref_offset(raw) + ref_totlen(c, jeb, raw)));
-
-		first_raw = raw;
-		break;
-	}
-
-	if (!first_raw) {
-		/* All nodes were obsolete. Nothing to recover. */
-		jffs2_dbg(1, "No non-obsolete nodes to be recovered. Just filing block bad\n");
-		c->wbuf_len = 0;
-		return;
-	}
-
-	start = ref_offset(first_raw);
-	end = ref_offset(jeb->last_node);
-	nr_refile = 1;
-
-	/* Count the number of refs which need to be copied */
-	while ((raw = ref_next(raw)) != jeb->last_node)
-		nr_refile++;
-
-	dbg_noderef("wbuf recover %08x-%08x (%d bytes in %d nodes)\n",
-		    start, end, end - start, nr_refile);
-
-	buf = NULL;
-	if (start < c->wbuf_ofs) {
-		/* First affected node was already partially written.
-		 * Attempt to reread the old data into our buffer. */
-
-		buf = kmalloc(end - start, GFP_KERNEL);
-		if (!buf) {
-			pr_crit("Malloc failure in wbuf recovery. Data loss ensues.\n");
-
-			goto read_failed;
-		}
-
-		/* Do the read... */
-		ret = mtd_read(c->mtd, start, c->wbuf_ofs - start, &retlen,
-			       buf);
-
-		/* ECC recovered ? */
-		if ((ret == -EUCLEAN || ret == -EBADMSG) &&
-		    (retlen == c->wbuf_ofs - start))
-			ret = 0;
-
-		if (ret || retlen != c->wbuf_ofs - start) {
-			pr_crit("Old data are already lost in wbuf recovery. Data loss ensues.\n");
-
-			kfree(buf);
-			buf = NULL;
-		read_failed:
-			first_raw = ref_next(first_raw);
-			nr_refile--;
-			while (first_raw && ref_obsolete(first_raw)) {
-				first_raw = ref_next(first_raw);
-				nr_refile--;
-			}
-
-			/* If this was the only node to be recovered, give up */
-			if (!first_raw) {
-				c->wbuf_len = 0;
-				return;
-			}
-
-			/* It wasn't. Go on and try to recover nodes complete in the wbuf */
-			start = ref_offset(first_raw);
-			dbg_noderef("wbuf now recover %08x-%08x (%d bytes in %d nodes)\n",
-				    start, end, end - start, nr_refile);
-
-		} else {
-			/* Read succeeded. Copy the remaining data from the wbuf */
-			memcpy(buf + (c->wbuf_ofs - start), c->wbuf, end - c->wbuf_ofs);
-		}
-	}
-	/* OK... we're to rewrite (end-start) bytes of data from first_raw onwards.
-	   Either 'buf' contains the data, or we find it in the wbuf */
-
-	/* ... and get an allocation of space from a shiny new block instead */
-	ret = jffs2_reserve_space_gc(c, end-start, &len, JFFS2_SUMMARY_NOSUM_SIZE);
-	if (ret) {
-		pr_warn("Failed to allocate space for wbuf recovery. Data loss ensues.\n");
-		kfree(buf);
-		return;
-	}
-
-	/* The summary is not recovered, so it must be disabled for this erase block */
-	jffs2_sum_disable_collecting(c->summary);
-
-	ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, nr_refile);
-	if (ret) {
-		pr_warn("Failed to allocate node refs for wbuf recovery. Data loss ensues.\n");
-		kfree(buf);
-		return;
-	}
-
-	ofs = write_ofs(c);
-
-	if (end-start >= c->wbuf_pagesize) {
-		/* Need to do another write immediately, but it's possible
-		   that this is just because the wbuf itself is completely
-		   full, and there's nothing earlier read back from the
-		   flash. Hence 'buf' isn't necessarily what we're writing
-		   from. */
-		unsigned char *rewrite_buf = buf?:c->wbuf;
-		uint32_t towrite = (end-start) - ((end-start)%c->wbuf_pagesize);
-
-		jffs2_dbg(1, "Write 0x%x bytes at 0x%08x in wbuf recover\n",
-			  towrite, ofs);
-
-#ifdef BREAKMEHEADER
-		static int breakme;
-		if (breakme++ == 20) {
-			pr_notice("Faking write error at 0x%08x\n", ofs);
-			breakme = 0;
-			mtd_write(c->mtd, ofs, towrite, &retlen, brokenbuf);
-			ret = -EIO;
-		} else
-#endif
-			ret = mtd_write(c->mtd, ofs, towrite, &retlen,
-					rewrite_buf);
-
-		if (ret || retlen != towrite || jffs2_verify_write(c, rewrite_buf, ofs)) {
-			/* Argh. We tried. Really we did. */
-			pr_crit("Recovery of wbuf failed due to a second write error\n");
-			kfree(buf);
-
-			if (retlen)
-				jffs2_add_physical_node_ref(c, ofs | REF_OBSOLETE, ref_totlen(c, jeb, first_raw), NULL);
-
-			return;
-		}
-		pr_notice("Recovery of wbuf succeeded to %08x\n", ofs);
-
-		c->wbuf_len = (end - start) - towrite;
-		c->wbuf_ofs = ofs + towrite;
-		memmove(c->wbuf, rewrite_buf + towrite, c->wbuf_len);
-		/* Don't muck about with c->wbuf_inodes. False positives are harmless. */
-	} else {
-		/* OK, now we're left with the dregs in whichever buffer we're using */
-		if (buf) {
-			memcpy(c->wbuf, buf, end-start);
-		} else {
-			memmove(c->wbuf, c->wbuf + (start - c->wbuf_ofs), end - start);
-		}
-		c->wbuf_ofs = ofs;
-		c->wbuf_len = end - start;
-	}
-
-	/* Now sort out the jffs2_raw_node_refs, moving them from the old to the next block */
-	new_jeb = &c->blocks[ofs / c->sector_size];
-
-	spin_lock(&c->erase_completion_lock);
-	for (raw = first_raw; raw != jeb->last_node; raw = ref_next(raw)) {
-		uint32_t rawlen = ref_totlen(c, jeb, raw);
-		struct jffs2_inode_cache *ic;
-		struct jffs2_raw_node_ref *new_ref;
-		struct jffs2_raw_node_ref **adjust_ref = NULL;
-		struct jffs2_inode_info *f = NULL;
-
-		jffs2_dbg(1, "Refiling block of %08x at %08x(%d) to %08x\n",
-			  rawlen, ref_offset(raw), ref_flags(raw), ofs);
-
-		ic = jffs2_raw_ref_to_ic(raw);
-
-		/* Ick. This XATTR mess should be fixed shortly... */
-		if (ic && ic->class == RAWNODE_CLASS_XATTR_DATUM) {
-			struct jffs2_xattr_datum *xd = (void *)ic;
-			BUG_ON(xd->node != raw);
-			adjust_ref = &xd->node;
-			raw->next_in_ino = NULL;
-			ic = NULL;
-		} else if (ic && ic->class == RAWNODE_CLASS_XATTR_REF) {
-			struct jffs2_xattr_datum *xr = (void *)ic;
-			BUG_ON(xr->node != raw);
-			adjust_ref = &xr->node;
-			raw->next_in_ino = NULL;
-			ic = NULL;
-		} else if (ic && ic->class == RAWNODE_CLASS_INODE_CACHE) {
-			struct jffs2_raw_node_ref **p = &ic->nodes;
-
-			/* Remove the old node from the per-inode list */
-			while (*p && *p != (void *)ic) {
-				if (*p == raw) {
-					(*p) = (raw->next_in_ino);
-					raw->next_in_ino = NULL;
-					break;
-				}
-				p = &((*p)->next_in_ino);
-			}
-
-			if (ic->state == INO_STATE_PRESENT && !ref_obsolete(raw)) {
-				/* If it's an in-core inode, then we have to adjust any
-				   full_dirent or full_dnode structure to point to the
-				   new version instead of the old */
-				f = jffs2_gc_fetch_inode(c, ic->ino, !ic->pino_nlink);
-				if (IS_ERR(f)) {
-					/* Should never happen; it _must_ be present */
-					JFFS2_ERROR("Failed to iget() ino #%u, err %ld\n",
-						    ic->ino, PTR_ERR(f));
-					BUG();
-				}
-				/* We don't lock f->sem. There's a number of ways we could
-				   end up in here with it already being locked, and nobody's
-				   going to modify it on us anyway because we hold the
-				   alloc_sem. We're only changing one ->raw pointer too,
-				   which we can get away with without upsetting readers. */
-				adjust_ref = jffs2_incore_replace_raw(c, f, raw,
-								      (void *)(buf?:c->wbuf) + (ref_offset(raw) - start));
-			} else if (unlikely(ic->state != INO_STATE_PRESENT &&
-					    ic->state != INO_STATE_CHECKEDABSENT &&
-					    ic->state != INO_STATE_GC)) {
-				JFFS2_ERROR("Inode #%u is in strange state %d!\n", ic->ino, ic->state);
-				BUG();
-			}
-		}
-
-		new_ref = jffs2_link_node_ref(c, new_jeb, ofs | ref_flags(raw), rawlen, ic);
-
-		if (adjust_ref) {
-			BUG_ON(*adjust_ref != raw);
-			*adjust_ref = new_ref;
-		}
-		if (f)
-			jffs2_gc_release_inode(c, f);
-
-		if (!ref_obsolete(raw)) {
-			jeb->dirty_size += rawlen;
-			jeb->used_size  -= rawlen;
-			c->dirty_size += rawlen;
-			c->used_size -= rawlen;
-			raw->flash_offset = ref_offset(raw) | REF_OBSOLETE;
-			BUG_ON(raw->next_in_ino);
-		}
-		ofs += rawlen;
-	}
-
-	kfree(buf);
-
-	/* Fix up the original jeb now it's on the bad_list */
-	if (first_raw == jeb->first_node) {
-		jffs2_dbg(1, "Failing block at %08x is now empty. Moving to erase_pending_list\n",
-			  jeb->offset);
-		list_move(&jeb->list, &c->erase_pending_list);
-		c->nr_erasing_blocks++;
-		jffs2_garbage_collect_trigger(c);
-	}
-
-	jffs2_dbg_acct_sanity_check_nolock(c, jeb);
-	jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
-
-	jffs2_dbg_acct_sanity_check_nolock(c, new_jeb);
-	jffs2_dbg_acct_paranoia_check_nolock(c, new_jeb);
-
-	spin_unlock(&c->erase_completion_lock);
-
-	jffs2_dbg(1, "wbuf recovery completed OK. wbuf_ofs 0x%08x, len 0x%x\n",
-		  c->wbuf_ofs, c->wbuf_len);
-
-}
-
-/* Meaning of pad argument:
-   0: Do not pad. Probably pointless - we only ever use this when we can't pad anyway.
-   1: Pad, do not adjust nextblock free_size
-   2: Pad, adjust nextblock free_size
-*/
-#define NOPAD		0
-#define PAD_NOACCOUNT	1
-#define PAD_ACCOUNTING	2
-
-static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad)
-{
-	struct jffs2_eraseblock *wbuf_jeb;
-	int ret;
-	size_t retlen;
-
-	/* Nothing to do if not write-buffering the flash. In particular, we shouldn't
-	   del_timer() the timer we never initialised. */
-	if (!jffs2_is_writebuffered(c))
-		return 0;
-
-	if (!mutex_is_locked(&c->alloc_sem)) {
-		pr_crit("jffs2_flush_wbuf() called with alloc_sem not locked!\n");
-		BUG();
-	}
-
-	if (!c->wbuf_len)	/* already checked c->wbuf above */
-		return 0;
-
-	wbuf_jeb = &c->blocks[c->wbuf_ofs / c->sector_size];
-	if (jffs2_prealloc_raw_node_refs(c, wbuf_jeb, c->nextblock->allocated_refs + 1))
-		return -ENOMEM;
-
-	/* claim remaining space on the page
-	   this happens, if we have a change to a new block,
-	   or if fsync forces us to flush the writebuffer.
-	   if we have a switch to next page, we will not have
-	   enough remaining space for this.
-	*/
-	if (pad ) {
-		c->wbuf_len = PAD(c->wbuf_len);
-
-		/* Pad with JFFS2_DIRTY_BITMASK initially.  this helps out ECC'd NOR
-		   with 8 byte page size */
-		memset(c->wbuf + c->wbuf_len, 0, c->wbuf_pagesize - c->wbuf_len);
-
-		if ( c->wbuf_len + sizeof(struct jffs2_unknown_node) < c->wbuf_pagesize) {
-			struct jffs2_unknown_node *padnode = (void *)(c->wbuf + c->wbuf_len);
-			padnode->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
-			padnode->nodetype = cpu_to_je16(JFFS2_NODETYPE_PADDING);
-			padnode->totlen = cpu_to_je32(c->wbuf_pagesize - c->wbuf_len);
-			padnode->hdr_crc = cpu_to_je32(crc32(0, padnode, sizeof(*padnode)-4));
-		}
-	}
-	/* else jffs2_flash_writev has actually filled in the rest of the
-	   buffer for us, and will deal with the node refs etc. later. */
-
-#ifdef BREAKME
-	static int breakme;
-	if (breakme++ == 20) {
-		pr_notice("Faking write error at 0x%08x\n", c->wbuf_ofs);
-		breakme = 0;
-		mtd_write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen,
-			  brokenbuf);
-		ret = -EIO;
-	} else
-#endif
-
-		ret = mtd_write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize,
-				&retlen, c->wbuf);
-
-	if (ret) {
-		pr_warn("jffs2_flush_wbuf(): Write failed with %d\n", ret);
-		goto wfail;
-	} else if (retlen != c->wbuf_pagesize) {
-		pr_warn("jffs2_flush_wbuf(): Write was short: %zd instead of %d\n",
-			retlen, c->wbuf_pagesize);
-		ret = -EIO;
-		goto wfail;
-	} else if ((ret = jffs2_verify_write(c, c->wbuf, c->wbuf_ofs))) {
-	wfail:
-		jffs2_wbuf_recover(c);
-
-		return ret;
-	}
-
-	/* Adjust free size of the block if we padded. */
-	if (pad) {
-		uint32_t waste = c->wbuf_pagesize - c->wbuf_len;
-
-		jffs2_dbg(1, "jffs2_flush_wbuf() adjusting free_size of %sblock at %08x\n",
-			  (wbuf_jeb == c->nextblock) ? "next" : "",
-			  wbuf_jeb->offset);
-
-		/* wbuf_pagesize - wbuf_len is the amount of space that's to be
-		   padded. If there is less free space in the block than that,
-		   something screwed up */
-		if (wbuf_jeb->free_size < waste) {
-			pr_crit("jffs2_flush_wbuf(): Accounting error. wbuf at 0x%08x has 0x%03x bytes, 0x%03x left.\n",
-				c->wbuf_ofs, c->wbuf_len, waste);
-			pr_crit("jffs2_flush_wbuf(): But free_size for block at 0x%08x is only 0x%08x\n",
-				wbuf_jeb->offset, wbuf_jeb->free_size);
-			BUG();
-		}
-
-		spin_lock(&c->erase_completion_lock);
-
-		jffs2_link_node_ref(c, wbuf_jeb, (c->wbuf_ofs + c->wbuf_len) | REF_OBSOLETE, waste, NULL);
-		/* FIXME: that made it count as dirty. Convert to wasted */
-		wbuf_jeb->dirty_size -= waste;
-		c->dirty_size -= waste;
-		wbuf_jeb->wasted_size += waste;
-		c->wasted_size += waste;
-	} else
-		spin_lock(&c->erase_completion_lock);
-
-	/* Stick any now-obsoleted blocks on the erase_pending_list */
-	jffs2_refile_wbuf_blocks(c);
-	jffs2_clear_wbuf_ino_list(c);
-	spin_unlock(&c->erase_completion_lock);
-
-	memset(c->wbuf,0xff,c->wbuf_pagesize);
-	/* adjust write buffer offset, else we get a non contiguous write bug */
-	c->wbuf_ofs += c->wbuf_pagesize;
-	c->wbuf_len = 0;
-	return 0;
-}
-
-/* Trigger garbage collection to flush the write-buffer.
-   If ino arg is zero, do it if _any_ real (i.e. not GC) writes are
-   outstanding. If ino arg non-zero, do it only if a write for the
-   given inode is outstanding. */
-int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino)
-{
-	uint32_t old_wbuf_ofs;
-	uint32_t old_wbuf_len;
-	int ret = 0;
-
-	jffs2_dbg(1, "jffs2_flush_wbuf_gc() called for ino #%u...\n", ino);
-
-	if (!c->wbuf)
-		return 0;
-
-	mutex_lock(&c->alloc_sem);
-	if (!jffs2_wbuf_pending_for_ino(c, ino)) {
-		jffs2_dbg(1, "Ino #%d not pending in wbuf. Returning\n", ino);
-		mutex_unlock(&c->alloc_sem);
-		return 0;
-	}
-
-	old_wbuf_ofs = c->wbuf_ofs;
-	old_wbuf_len = c->wbuf_len;
-
-	if (c->unchecked_size) {
-		/* GC won't make any progress for a while */
-		jffs2_dbg(1, "%s(): padding. Not finished checking\n",
-			  __func__);
-		down_write(&c->wbuf_sem);
-		ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING);
-		/* retry flushing wbuf in case jffs2_wbuf_recover
-		   left some data in the wbuf */
-		if (ret)
-			ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING);
-		up_write(&c->wbuf_sem);
-	} else while (old_wbuf_len &&
-		      old_wbuf_ofs == c->wbuf_ofs) {
-
-		mutex_unlock(&c->alloc_sem);
-
-		jffs2_dbg(1, "%s(): calls gc pass\n", __func__);
-
-		ret = jffs2_garbage_collect_pass(c);
-		if (ret) {
-			/* GC failed. Flush it with padding instead */
-			mutex_lock(&c->alloc_sem);
-			down_write(&c->wbuf_sem);
-			ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING);
-			/* retry flushing wbuf in case jffs2_wbuf_recover
-			   left some data in the wbuf */
-			if (ret)
-				ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING);
-			up_write(&c->wbuf_sem);
-			break;
-		}
-		mutex_lock(&c->alloc_sem);
-	}
-
-	jffs2_dbg(1, "%s(): ends...\n", __func__);
-
-	mutex_unlock(&c->alloc_sem);
-	return ret;
-}
-
-/* Pad write-buffer to end and write it, wasting space. */
-int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c)
-{
-	int ret;
-
-	if (!c->wbuf)
-		return 0;
-
-	down_write(&c->wbuf_sem);
-	ret = __jffs2_flush_wbuf(c, PAD_NOACCOUNT);
-	/* retry - maybe wbuf recover left some data in wbuf. */
-	if (ret)
-		ret = __jffs2_flush_wbuf(c, PAD_NOACCOUNT);
-	up_write(&c->wbuf_sem);
-
-	return ret;
-}
-
-static size_t jffs2_fill_wbuf(struct jffs2_sb_info *c, const uint8_t *buf,
-			      size_t len)
-{
-	if (len && !c->wbuf_len && (len >= c->wbuf_pagesize))
-		return 0;
-
-	if (len > (c->wbuf_pagesize - c->wbuf_len))
-		len = c->wbuf_pagesize - c->wbuf_len;
-	memcpy(c->wbuf + c->wbuf_len, buf, len);
-	c->wbuf_len += (uint32_t) len;
-	return len;
-}
-
-int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs,
-		       unsigned long count, loff_t to, size_t *retlen,
-		       uint32_t ino)
-{
-	struct jffs2_eraseblock *jeb;
-	size_t wbuf_retlen, donelen = 0;
-	uint32_t outvec_to = to;
-	int ret, invec;
-
-	/* If not writebuffered flash, don't bother */
-	if (!jffs2_is_writebuffered(c))
-		return jffs2_flash_direct_writev(c, invecs, count, to, retlen);
-
-	down_write(&c->wbuf_sem);
-
-	/* If wbuf_ofs is not initialized, set it to target address */
-	if (c->wbuf_ofs == 0xFFFFFFFF) {
-		c->wbuf_ofs = PAGE_DIV(to);
-		c->wbuf_len = PAGE_MOD(to);
-		memset(c->wbuf,0xff,c->wbuf_pagesize);
-	}
-
-	/*
-	 * Sanity checks on target address.  It's permitted to write
-	 * at PAD(c->wbuf_len+c->wbuf_ofs), and it's permitted to
-	 * write at the beginning of a new erase block. Anything else,
-	 * and you die.  New block starts at xxx000c (0-b = block
-	 * header)
-	 */
-	if (SECTOR_ADDR(to) != SECTOR_ADDR(c->wbuf_ofs)) {
-		/* It's a write to a new block */
-		if (c->wbuf_len) {
-			jffs2_dbg(1, "%s(): to 0x%lx causes flush of wbuf at 0x%08x\n",
-				  __func__, (unsigned long)to, c->wbuf_ofs);
-			ret = __jffs2_flush_wbuf(c, PAD_NOACCOUNT);
-			if (ret)
-				goto outerr;
-		}
-		/* set pointer to new block */
-		c->wbuf_ofs = PAGE_DIV(to);
-		c->wbuf_len = PAGE_MOD(to);
-	}
-
-	if (to != PAD(c->wbuf_ofs + c->wbuf_len)) {
-		/* We're not writing immediately after the writebuffer. Bad. */
-		pr_crit("%s(): Non-contiguous write to %08lx\n",
-			__func__, (unsigned long)to);
-		if (c->wbuf_len)
-			pr_crit("wbuf was previously %08x-%08x\n",
-				c->wbuf_ofs, c->wbuf_ofs + c->wbuf_len);
-		BUG();
-	}
-
-	/* adjust alignment offset */
-	if (c->wbuf_len != PAGE_MOD(to)) {
-		c->wbuf_len = PAGE_MOD(to);
-		/* take care of alignment to next page */
-		if (!c->wbuf_len) {
-			c->wbuf_len = c->wbuf_pagesize;
-			ret = __jffs2_flush_wbuf(c, NOPAD);
-			if (ret)
-				goto outerr;
-		}
-	}
-
-	for (invec = 0; invec < count; invec++) {
-		int vlen = invecs[invec].iov_len;
-		uint8_t *v = invecs[invec].iov_base;
-
-		wbuf_retlen = jffs2_fill_wbuf(c, v, vlen);
-
-		if (c->wbuf_len == c->wbuf_pagesize) {
-			ret = __jffs2_flush_wbuf(c, NOPAD);
-			if (ret)
-				goto outerr;
-		}
-		vlen -= wbuf_retlen;
-		outvec_to += wbuf_retlen;
-		donelen += wbuf_retlen;
-		v += wbuf_retlen;
-
-		if (vlen >= c->wbuf_pagesize) {
-			ret = mtd_write(c->mtd, outvec_to, PAGE_DIV(vlen),
-					&wbuf_retlen, v);
-			if (ret < 0 || wbuf_retlen != PAGE_DIV(vlen))
-				goto outfile;
-
-			vlen -= wbuf_retlen;
-			outvec_to += wbuf_retlen;
-			c->wbuf_ofs = outvec_to;
-			donelen += wbuf_retlen;
-			v += wbuf_retlen;
-		}
-
-		wbuf_retlen = jffs2_fill_wbuf(c, v, vlen);
-		if (c->wbuf_len == c->wbuf_pagesize) {
-			ret = __jffs2_flush_wbuf(c, NOPAD);
-			if (ret)
-				goto outerr;
-		}
-
-		outvec_to += wbuf_retlen;
-		donelen += wbuf_retlen;
-	}
-
-	/*
-	 * If there's a remainder in the wbuf and it's a non-GC write,
-	 * remember that the wbuf affects this ino
-	 */
-	*retlen = donelen;
-
-	if (jffs2_sum_active()) {
-		int res = jffs2_sum_add_kvec(c, invecs, count, (uint32_t) to);
-		if (res)
-			return res;
-	}
-
-	if (c->wbuf_len && ino)
-		jffs2_wbuf_dirties_inode(c, ino);
-
-	ret = 0;
-	up_write(&c->wbuf_sem);
-	return ret;
-
-outfile:
-	/*
-	 * At this point we have no problem, c->wbuf is empty. However
-	 * refile nextblock to avoid writing again to same address.
-	 */
-
-	spin_lock(&c->erase_completion_lock);
-
-	jeb = &c->blocks[outvec_to / c->sector_size];
-	jffs2_block_refile(c, jeb, REFILE_ANYWAY);
-
-	spin_unlock(&c->erase_completion_lock);
-
-outerr:
-	*retlen = 0;
-	up_write(&c->wbuf_sem);
-	return ret;
-}
-
-/*
- *	This is the entry for flash write.
- *	Check, if we work on NAND FLASH, if so build an kvec and write it via vritev
-*/
-int jffs2_flash_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
-		      size_t *retlen, const u_char *buf)
-{
-	struct kvec vecs[1];
-
-	if (!jffs2_is_writebuffered(c))
-		return jffs2_flash_direct_write(c, ofs, len, retlen, buf);
-
-	vecs[0].iov_base = (unsigned char *) buf;
-	vecs[0].iov_len = len;
-	return jffs2_flash_writev(c, vecs, 1, ofs, retlen, 0);
-}
-
-/*
-	Handle readback from writebuffer and ECC failure return
-*/
-int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf)
-{
-	loff_t	orbf = 0, owbf = 0, lwbf = 0;
-	int	ret;
-
-	if (!jffs2_is_writebuffered(c))
-		return mtd_read(c->mtd, ofs, len, retlen, buf);
-
-	/* Read flash */
-	down_read(&c->wbuf_sem);
-	ret = mtd_read(c->mtd, ofs, len, retlen, buf);
-
-	if ( (ret == -EBADMSG || ret == -EUCLEAN) && (*retlen == len) ) {
-		if (ret == -EBADMSG)
-			pr_warn("mtd->read(0x%zx bytes from 0x%llx) returned ECC error\n",
-				len, ofs);
-		/*
-		 * We have the raw data without ECC correction in the buffer,
-		 * maybe we are lucky and all data or parts are correct. We
-		 * check the node.  If data are corrupted node check will sort
-		 * it out.  We keep this block, it will fail on write or erase
-		 * and the we mark it bad. Or should we do that now? But we
-		 * should give him a chance.  Maybe we had a system crash or
-		 * power loss before the ecc write or a erase was completed.
-		 * So we return success. :)
-		 */
-		ret = 0;
-	}
-
-	/* if no writebuffer available or write buffer empty, return */
-	if (!c->wbuf_pagesize || !c->wbuf_len)
-		goto exit;
-
-	/* if we read in a different block, return */
-	if (SECTOR_ADDR(ofs) != SECTOR_ADDR(c->wbuf_ofs))
-		goto exit;
-
-	if (ofs >= c->wbuf_ofs) {
-		owbf = (ofs - c->wbuf_ofs);	/* offset in write buffer */
-		if (owbf > c->wbuf_len)		/* is read beyond write buffer ? */
-			goto exit;
-		lwbf = c->wbuf_len - owbf;	/* number of bytes to copy */
-		if (lwbf > len)
-			lwbf = len;
-	} else {
-		orbf = (c->wbuf_ofs - ofs);	/* offset in read buffer */
-		if (orbf > len)			/* is write beyond write buffer ? */
-			goto exit;
-		lwbf = len - orbf;		/* number of bytes to copy */
-		if (lwbf > c->wbuf_len)
-			lwbf = c->wbuf_len;
-	}
-	if (lwbf > 0)
-		memcpy(buf+orbf,c->wbuf+owbf,lwbf);
-
-exit:
-	up_read(&c->wbuf_sem);
-	return ret;
-}
-
-#define NR_OOB_SCAN_PAGES 4
-
-/* For historical reasons we use only 8 bytes for OOB clean marker */
-#define OOB_CM_SIZE 8
-
-static const struct jffs2_unknown_node oob_cleanmarker =
-{
-	.magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
-	.nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
-	.totlen = constant_cpu_to_je32(8)
-};
-
-/*
- * Check, if the out of band area is empty. This function knows about the clean
- * marker and if it is present in OOB, treats the OOB as empty anyway.
- */
-int jffs2_check_oob_empty(struct jffs2_sb_info *c,
-			  struct jffs2_eraseblock *jeb, int mode)
-{
-	int i, ret;
-	int cmlen = min_t(int, c->oobavail, OOB_CM_SIZE);
-	struct mtd_oob_ops ops;
-
-	ops.mode = MTD_OPS_AUTO_OOB;
-	ops.ooblen = NR_OOB_SCAN_PAGES * c->oobavail;
-	ops.oobbuf = c->oobbuf;
-	ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
-	ops.datbuf = NULL;
-
-	ret = mtd_read_oob(c->mtd, jeb->offset, &ops);
-	if ((ret && !mtd_is_bitflip(ret)) || ops.oobretlen != ops.ooblen) {
-		pr_err("cannot read OOB for EB at %08x, requested %zd bytes, read %zd bytes, error %d\n",
-		       jeb->offset, ops.ooblen, ops.oobretlen, ret);
-		if (!ret || mtd_is_bitflip(ret))
-			ret = -EIO;
-		return ret;
-	}
-
-	for(i = 0; i < ops.ooblen; i++) {
-		if (mode && i < cmlen)
-			/* Yeah, we know about the cleanmarker */
-			continue;
-
-		if (ops.oobbuf[i] != 0xFF) {
-			jffs2_dbg(2, "Found %02x at %x in OOB for "
-				  "%08x\n", ops.oobbuf[i], i, jeb->offset);
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
-/*
- * Check for a valid cleanmarker.
- * Returns: 0 if a valid cleanmarker was found
- *	    1 if no cleanmarker was found
- *	    negative error code if an error occurred
- */
-int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c,
-				 struct jffs2_eraseblock *jeb)
-{
-	struct mtd_oob_ops ops;
-	int ret, cmlen = min_t(int, c->oobavail, OOB_CM_SIZE);
-
-	ops.mode = MTD_OPS_AUTO_OOB;
-	ops.ooblen = cmlen;
-	ops.oobbuf = c->oobbuf;
-	ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
-	ops.datbuf = NULL;
-
-	ret = mtd_read_oob(c->mtd, jeb->offset, &ops);
-	if ((ret && !mtd_is_bitflip(ret)) || ops.oobretlen != ops.ooblen) {
-		pr_err("cannot read OOB for EB at %08x, requested %zd bytes, read %zd bytes, error %d\n",
-		       jeb->offset, ops.ooblen, ops.oobretlen, ret);
-		if (!ret || mtd_is_bitflip(ret))
-			ret = -EIO;
-		return ret;
-	}
-
-	return !!memcmp(&oob_cleanmarker, c->oobbuf, cmlen);
-}
-
-int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c,
-				 struct jffs2_eraseblock *jeb)
-{
-	int ret;
-	struct mtd_oob_ops ops;
-	int cmlen = min_t(int, c->oobavail, OOB_CM_SIZE);
-
-	ops.mode = MTD_OPS_AUTO_OOB;
-	ops.ooblen = cmlen;
-	ops.oobbuf = (uint8_t *)&oob_cleanmarker;
-	ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0;
-	ops.datbuf = NULL;
-
-	ret = mtd_write_oob(c->mtd, jeb->offset, &ops);
-	if (ret || ops.oobretlen != ops.ooblen) {
-		pr_err("cannot write OOB for EB at %08x, requested %zd bytes, read %zd bytes, error %d\n",
-		       jeb->offset, ops.ooblen, ops.oobretlen, ret);
-		if (!ret)
-			ret = -EIO;
-		return ret;
-	}
-
-	return 0;
-}
-
-/*
- * On NAND we try to mark this block bad. If the block was erased more
- * than MAX_ERASE_FAILURES we mark it finally bad.
- * Don't care about failures. This block remains on the erase-pending
- * or badblock list as long as nobody manipulates the flash with
- * a bootloader or something like that.
- */
-
-int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset)
-{
-	int 	ret;
-
-	/* if the count is < max, we try to write the counter to the 2nd page oob area */
-	if( ++jeb->bad_count < MAX_ERASE_FAILURES)
-		return 0;
-
-	pr_warn("marking eraseblock at %08x as bad\n", bad_offset);
-	ret = mtd_block_markbad(c->mtd, bad_offset);
-
-	if (ret) {
-		jffs2_dbg(1, "%s(): Write failed for block at %08x: error %d\n",
-			  __func__, jeb->offset, ret);
-		return ret;
-	}
-	return 1;
-}
-
-static struct jffs2_sb_info *work_to_sb(struct work_struct *work)
-{
-	struct delayed_work *dwork;
-
-	dwork = to_delayed_work(work);
-	return container_of(dwork, struct jffs2_sb_info, wbuf_dwork);
-}
-
-static void delayed_wbuf_sync(struct work_struct *work)
-{
-	struct jffs2_sb_info *c = work_to_sb(work);
-	struct super_block *sb = OFNI_BS_2SFFJ(c);
-
-	if (!sb_rdonly(sb)) {
-		jffs2_dbg(1, "%s()\n", __func__);
-		jffs2_flush_wbuf_gc(c, 0);
-	}
-}
-
-void jffs2_dirty_trigger(struct jffs2_sb_info *c)
-{
-	struct super_block *sb = OFNI_BS_2SFFJ(c);
-	unsigned long delay;
-
-	if (sb_rdonly(sb))
-		return;
-
-	delay = msecs_to_jiffies(dirty_writeback_interval * 10);
-	if (queue_delayed_work(system_long_wq, &c->wbuf_dwork, delay))
-		jffs2_dbg(1, "%s()\n", __func__);
-}
-
-int jffs2_nand_flash_setup(struct jffs2_sb_info *c)
-{
-	if (!c->mtd->oobsize)
-		return 0;
-
-	/* Cleanmarker is out-of-band, so inline size zero */
-	c->cleanmarker_size = 0;
-
-	if (c->mtd->oobavail == 0) {
-		pr_err("inconsistent device description\n");
-		return -EINVAL;
-	}
-
-	jffs2_dbg(1, "using OOB on NAND\n");
-
-	c->oobavail = c->mtd->oobavail;
-
-	/* Initialise write buffer */
-	init_rwsem(&c->wbuf_sem);
-	INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
-	c->wbuf_pagesize = c->mtd->writesize;
-	c->wbuf_ofs = 0xFFFFFFFF;
-
-	c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf)
-		return -ENOMEM;
-
-	c->oobbuf = kmalloc_array(NR_OOB_SCAN_PAGES, c->oobavail, GFP_KERNEL);
-	if (!c->oobbuf) {
-		kfree(c->wbuf);
-		return -ENOMEM;
-	}
-
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-	c->wbuf_verify = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf_verify) {
-		kfree(c->oobbuf);
-		kfree(c->wbuf);
-		return -ENOMEM;
-	}
-#endif
-	return 0;
-}
-
-void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c)
-{
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-	kfree(c->wbuf_verify);
-#endif
-	kfree(c->wbuf);
-	kfree(c->oobbuf);
-}
-
-int jffs2_dataflash_setup(struct jffs2_sb_info *c) {
-	c->cleanmarker_size = 0;		/* No cleanmarkers needed */
-
-	/* Initialize write buffer */
-	init_rwsem(&c->wbuf_sem);
-	INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
-	c->wbuf_pagesize =  c->mtd->erasesize;
-
-	/* Find a suitable c->sector_size
-	 * - Not too much sectors
-	 * - Sectors have to be at least 4 K + some bytes
-	 * - All known dataflashes have erase sizes of 528 or 1056
-	 * - we take at least 8 eraseblocks and want to have at least 8K size
-	 * - The concatenation should be a power of 2
-	*/
-
-	c->sector_size = 8 * c->mtd->erasesize;
-
-	while (c->sector_size < 8192) {
-		c->sector_size *= 2;
-	}
-
-	/* It may be necessary to adjust the flash size */
-	c->flash_size = c->mtd->size;
-
-	if ((c->flash_size % c->sector_size) != 0) {
-		c->flash_size = (c->flash_size / c->sector_size) * c->sector_size;
-		pr_warn("flash size adjusted to %dKiB\n", c->flash_size);
-	}
-
-	c->wbuf_ofs = 0xFFFFFFFF;
-	c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf)
-		return -ENOMEM;
-
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-	c->wbuf_verify = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf_verify) {
-		kfree(c->wbuf);
-		return -ENOMEM;
-	}
-#endif
-
-	pr_info("write-buffering enabled buffer (%d) erasesize (%d)\n",
-		c->wbuf_pagesize, c->sector_size);
-
-	return 0;
-}
-
-void jffs2_dataflash_cleanup(struct jffs2_sb_info *c) {
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-	kfree(c->wbuf_verify);
-#endif
-	kfree(c->wbuf);
-}
-
-int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c) {
-	/* Cleanmarker currently occupies whole programming regions,
-	 * either one or 2 for 8Byte STMicro flashes. */
-	c->cleanmarker_size = max(16u, c->mtd->writesize);
-
-	/* Initialize write buffer */
-	init_rwsem(&c->wbuf_sem);
-	INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
-
-	c->wbuf_pagesize = c->mtd->writesize;
-	c->wbuf_ofs = 0xFFFFFFFF;
-
-	c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf)
-		return -ENOMEM;
-
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-	c->wbuf_verify = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf_verify) {
-		kfree(c->wbuf);
-		return -ENOMEM;
-	}
-#endif
-	return 0;
-}
-
-void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c) {
-#ifdef CONFIG_JFFS2_FS_WBUF_VERIFY
-	kfree(c->wbuf_verify);
-#endif
-	kfree(c->wbuf);
-}
-
-int jffs2_ubivol_setup(struct jffs2_sb_info *c) {
-	c->cleanmarker_size = 0;
-
-	if (c->mtd->writesize == 1)
-		/* We do not need write-buffer */
-		return 0;
-
-	init_rwsem(&c->wbuf_sem);
-	INIT_DELAYED_WORK(&c->wbuf_dwork, delayed_wbuf_sync);
-
-	c->wbuf_pagesize =  c->mtd->writesize;
-	c->wbuf_ofs = 0xFFFFFFFF;
-	c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL);
-	if (!c->wbuf)
-		return -ENOMEM;
-
-	pr_info("write-buffering enabled buffer (%d) erasesize (%d)\n",
-		c->wbuf_pagesize, c->sector_size);
-
-	return 0;
-}
-
-void jffs2_ubivol_cleanup(struct jffs2_sb_info *c) {
-	kfree(c->wbuf);
-}
diff -Nupr old/fs/jffs2/write.c new/fs/jffs2/write.c
--- old/fs/jffs2/write.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/write.c	2022-05-09 20:07:33.520000000 +0800
@@ -9,16 +9,15 @@
  *
  */
 
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
+#include <dirent.h>
 #include <linux/kernel.h>
 #include <linux/fs.h>
-#include <linux/crc32.h>
 #include <linux/pagemap.h>
-#include <linux/mtd/mtd.h>
+#include <linux/semaphore.h>
+#include "mtd_dev.h"
 #include "nodelist.h"
 #include "compr.h"
-
+#include "los_crc32.h"
 
 int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
 		       uint32_t mode, struct jffs2_raw_inode *ri)
@@ -30,8 +29,6 @@ int jffs2_do_new_inode(struct jffs2_sb_i
 		return -ENOMEM;
 	}
 
-	memset(ic, 0, sizeof(*ic));
-
 	f->inocache = ic;
 	f->inocache->pino_nlink = 1; /* Will be overwritten shortly for directories */
 	f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
@@ -69,8 +66,10 @@ struct jffs2_full_dnode *jffs2_write_dno
 	int retried = 0;
 	unsigned long cnt = 2;
 
-	D1(if(je32_to_cpu(ri->hdr_crc) != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
-		pr_crit("Eep. CRC not correct in jffs2_write_dnode()\n");
+	D1(if (je32_to_cpu(ri->hdr_crc) != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
+		printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dnode(), je32_to_cpu(ri->hdr_crc):%d, "
+			"crc32(0, ri, sizeof(struct jffs2_unknown_node) - 4):%d\n", je32_to_cpu(ri->hdr_crc),
+			crc32(0, ri, sizeof(struct jffs2_unknown_node) - 4));
 		BUG();
 	}
 	   );
@@ -172,8 +171,8 @@ struct jffs2_full_dnode *jffs2_write_dno
 	   beginning of a page and runs to the end of the file, or if
 	   it's a hole node, mark it REF_PRISTINE, else REF_NORMAL.
 	*/
-	if ((je32_to_cpu(ri->dsize) >= PAGE_SIZE) ||
-	    ( ((je32_to_cpu(ri->offset)&(PAGE_SIZE-1))==0) &&
+	if ((je32_to_cpu(ri->dsize) >= PAGE_CACHE_SIZE) ||
+	    ( ((je32_to_cpu(ri->offset)&(PAGE_CACHE_SIZE-1))==0) &&
 	      (je32_to_cpu(ri->dsize)+je32_to_cpu(ri->offset) ==  je32_to_cpu(ri->isize)))) {
 		flash_ofs |= REF_PRISTINE;
 	} else {
@@ -219,11 +218,13 @@ struct jffs2_full_dirent *jffs2_write_di
 		  je32_to_cpu(rd->name_crc));
 
 	D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
-		pr_crit("Eep. CRC not correct in jffs2_write_dirent()\n");
+	    printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent(), je32_to_cpu(rd->hdr_crc):%d, "
+		    "crc32(0, rd, sizeof(struct jffs2_unknown_node) - 4):%d\n", je32_to_cpu(rd->hdr_crc),
+			crc32(0, rd, sizeof(struct jffs2_unknown_node) - 4));
 		BUG();
 	   });
 
-	if (strnlen(name, namelen) != namelen) {
+	if (strnlen((const char *)name, namelen) != namelen) {
 		/* This should never happen, but seems to have done on at least one
 		   occasion: https://dev.laptop.org/ticket/4184 */
 		pr_crit("Error in jffs2_write_dirent() -- name contains zero bytes!\n");
@@ -245,7 +246,7 @@ struct jffs2_full_dirent *jffs2_write_di
 
 	fd->version = je32_to_cpu(rd->version);
 	fd->ino = je32_to_cpu(rd->ino);
-	fd->nhash = full_name_hash(NULL, name, namelen);
+	fd->nhash = full_name_hash(name, namelen);
 	fd->type = rd->type;
 	memcpy(fd->name, name, namelen);
 	fd->name[namelen]=0;
@@ -343,10 +344,24 @@ int jffs2_write_inode_range(struct jffs2
 {
 	int ret = 0;
 	uint32_t writtenlen = 0;
+	unsigned char *bufRet = NULL;
+	unsigned char *bufRetBak = NULL;
 
 	jffs2_dbg(1, "%s(): Ino #%u, ofs 0x%x, len 0x%x\n",
 		  __func__, f->inocache->ino, offset, writelen);
 
+	if (writelen > 0) {
+		bufRet = kmalloc(writelen, GFP_KERNEL);
+		if (bufRet == NULL) {
+			return -ENOMEM;
+		}
+		bufRetBak = bufRet;
+		if (LOS_CopyToKernel(bufRet, writelen, buf, writelen) != 0) {
+			kfree(bufRet);
+			return -EFAULT;
+		}
+	}
+
 	while(writelen) {
 		struct jffs2_full_dnode *fn;
 		unsigned char *comprbuf = NULL;
@@ -366,11 +381,10 @@ int jffs2_write_inode_range(struct jffs2
 			break;
 		}
 		mutex_lock(&f->sem);
-		datalen = min_t(uint32_t, writelen,
-				PAGE_SIZE - (offset & (PAGE_SIZE-1)));
+		datalen = min_t(uint32_t, writelen, PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1)));
 		cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen);
 
-		comprtype = jffs2_compress(c, f, buf, &comprbuf, &datalen, &cdatalen);
+		comprtype = jffs2_compress(c, f, bufRet, &comprbuf, &datalen, &cdatalen);
 
 		ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 		ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
@@ -390,7 +404,7 @@ int jffs2_write_inode_range(struct jffs2
 
 		fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, ALLOC_NORETRY);
 
-		jffs2_free_comprbuf(comprbuf, buf);
+		jffs2_free_comprbuf(comprbuf, bufRet);
 
 		if (IS_ERR(fn)) {
 			ret = PTR_ERR(fn);
@@ -432,15 +446,18 @@ int jffs2_write_inode_range(struct jffs2
 		writtenlen += datalen;
 		offset += datalen;
 		writelen -= datalen;
-		buf += datalen;
+		bufRet += datalen;
 	}
 	*retlen = writtenlen;
+	if (bufRetBak != NULL) {
+		kfree(bufRetBak);
+	}
 	return ret;
 }
 
 int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
 		    struct jffs2_inode_info *f, struct jffs2_raw_inode *ri,
-		    const struct qstr *qstr)
+		    const char *name, int namelen)
 {
 	struct jffs2_raw_dirent *rd;
 	struct jffs2_full_dnode *fn;
@@ -468,7 +485,8 @@ int jffs2_do_create(struct jffs2_sb_info
 		  jemode_to_cpu(ri->mode));
 
 	if (IS_ERR(fn)) {
-		jffs2_dbg(1, "jffs2_write_dnode() failed\n");
+		jffs2_dbg(1, "jffs2_write_dnode() failed,error:%ld\n",
+		    PTR_ERR(fn));
 		/* Eeek. Wave bye bye */
 		mutex_unlock(&f->sem);
 		jffs2_complete_reservation(c);
@@ -482,19 +500,12 @@ int jffs2_do_create(struct jffs2_sb_info
 	mutex_unlock(&f->sem);
 	jffs2_complete_reservation(c);
 
-	ret = jffs2_init_security(&f->vfs_inode, &dir_f->vfs_inode, qstr);
-	if (ret)
-		return ret;
-	ret = jffs2_init_acl_post(&f->vfs_inode);
-	if (ret)
-		return ret;
-
-	ret = jffs2_reserve_space(c, sizeof(*rd)+qstr->len, &alloclen,
-				ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(qstr->len));
+	ret = jffs2_reserve_space(c, sizeof(*rd)+ namelen, &alloclen,
+				ALLOC_NORMAL, JFFS2_SUMMARY_DIRENT_SIZE(namelen));
 
 	if (ret) {
 		/* Eep. */
-		jffs2_dbg(1, "jffs2_reserve_space() for dirent failed\n");
+		jffs2_dbg(1, "jffs2_reserve_space() for dirent failed,ret:%d\n",ret);
 		return ret;
 	}
 
@@ -509,19 +520,19 @@ int jffs2_do_create(struct jffs2_sb_info
 
 	rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 	rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
-	rd->totlen = cpu_to_je32(sizeof(*rd) + qstr->len);
+	rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
 	rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
 
 	rd->pino = cpu_to_je32(dir_f->inocache->ino);
 	rd->version = cpu_to_je32(++dir_f->highest_version);
 	rd->ino = ri->ino;
 	rd->mctime = ri->ctime;
-	rd->nsize = qstr->len;
+	rd->nsize = namelen;
 	rd->type = DT_REG;
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
-	rd->name_crc = cpu_to_je32(crc32(0, qstr->name, qstr->len));
+	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, qstr->name, qstr->len, ALLOC_NORMAL);
+	fd = jffs2_write_dirent(c, dir_f, rd, (const unsigned char *)name, namelen, ALLOC_NORMAL);
 
 	jffs2_free_raw_dirent(rd);
 
@@ -553,7 +564,7 @@ int jffs2_do_unlink(struct jffs2_sb_info
 	uint32_t alloclen;
 	int ret;
 
-	if (!jffs2_can_mark_obsolete(c)) {
+	if (jffs2_can_mark_obsolete(c)) {
 		/* We can't mark stuff obsolete on the medium. We need to write a deletion dirent */
 
 		rd = jffs2_alloc_raw_dirent();
@@ -584,7 +595,7 @@ int jffs2_do_unlink(struct jffs2_sb_info
 		rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 		rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
-		fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_DELETION);
+		fd = jffs2_write_dirent(c, dir_f, rd, (const unsigned char *)name, namelen, ALLOC_DELETION);
 
 		jffs2_free_raw_dirent(rd);
 
@@ -598,7 +609,7 @@ int jffs2_do_unlink(struct jffs2_sb_info
 		jffs2_add_fd_to_list(c, fd, &dir_f->dents);
 		mutex_unlock(&dir_f->sem);
 	} else {
-		uint32_t nhash = full_name_hash(NULL, name, namelen);
+		uint32_t nhash = full_name_hash((const unsigned char *)name, namelen);
 
 		fd = dir_f->dents;
 		/* We don't actually want to reserve any space, but we do
@@ -703,7 +714,7 @@ int jffs2_do_link (struct jffs2_sb_info
 	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
 	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
-	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, ALLOC_NORMAL);
+	fd = jffs2_write_dirent(c, dir_f, rd, (const unsigned char *)name, namelen, ALLOC_NORMAL);
 
 	jffs2_free_raw_dirent(rd);
 
diff -Nupr old/fs/jffs2/writev.c new/fs/jffs2/writev.c
--- old/fs/jffs2/writev.c	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/writev.c	2022-05-09 20:05:36.440000000 +0800
@@ -10,42 +10,97 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/mtd/mtd.h>
+#include "mtd_dev.h"
 #include "nodelist.h"
 
 int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
 			      unsigned long count, loff_t to, size_t *retlen)
 {
-	if (!jffs2_is_writebuffered(c)) {
-		if (jffs2_sum_active()) {
-			int res;
-			res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
-			if (res) {
-				return res;
+	unsigned long i;
+	size_t totlen = 0, thislen;
+	int ret = 0;
+
+	for (i = 0; i < count; i++) {
+		// writes need to be aligned but the data we're passed may not be
+		// Observation suggests most unaligned writes are small, so we
+		// optimize for that case.
+
+		if (((vecs[i].iov_len & (sizeof(int) - 1))) ||
+		(((unsigned long) vecs[i].iov_base & (sizeof(unsigned long) - 1)))) {
+			// are there iov's after this one? Or is it so much we'd need
+			// to do multiple writes anyway?
+			if ((i + 1) < count || vecs[i].iov_len > 256) {
+				// cop out and malloc
+				unsigned long j;
+				size_t sizetomalloc = 0, totvecsize = 0;
+				char *cbuf, *cbufptr;
+
+				for (j = i; j < count; j++)
+					totvecsize += vecs[j].iov_len;
+
+				// pad up in case unaligned
+				sizetomalloc = totvecsize + sizeof(int) - 1;
+				sizetomalloc &= ~(sizeof(int) - 1);
+				cbuf = (char *) malloc(sizetomalloc);
+				// malloc returns aligned memory
+				if (!cbuf) {
+					ret = -ENOMEM;
+					goto writev_out;
+				}
+				cbufptr = cbuf;
+				for (j = i; j < count; j++) {
+					(void)memcpy_s(cbufptr, vecs[j].iov_len, vecs[j].iov_base, vecs[j].iov_len);
+					cbufptr += vecs[j].iov_len;
+				}
+				ret = jffs2_flash_write(c, to, sizetomalloc, &thislen,
+					(unsigned char *) cbuf);
+				if (thislen > totvecsize) // in case it was aligned up
+					thislen = totvecsize;
+				totlen += thislen;
+				free(cbuf);
+				goto writev_out;
+			} else {
+				// otherwise optimize for the common case
+				int buf[256/sizeof(int)]; // int, so int aligned
+				size_t lentowrite;
+
+				lentowrite = vecs[i].iov_len;
+				// pad up in case its unaligned
+				lentowrite += sizeof(int) - 1;
+				lentowrite &= ~(sizeof(int) - 1);
+				ret = memcpy_s(buf, sizeof(buf), vecs[i].iov_base, vecs[i].iov_len);
+				if (ret != EOK)
+					goto writev_out;
+
+				ret = jffs2_flash_write(c, to, lentowrite, &thislen,
+					(unsigned char *) &buf[0]);
+				if (thislen > vecs[i].iov_len)
+					thislen = vecs[i].iov_len;
 			}
+		} else {
+				ret = jffs2_flash_write(c, to, vecs[i].iov_len, &thislen,
+					vecs[i].iov_base);
 		}
+		totlen += thislen;
+		if (ret || thislen != vecs[i].iov_len) break;
+		to += vecs[i].iov_len;
 	}
 
-	return mtd_writev(c->mtd, vecs, count, to, retlen);
+writev_out:
+	if (retlen) *retlen = totlen;
+
+	return ret;
 }
 
 int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
 			size_t *retlen, const u_char *buf)
 {
 	int ret;
-	ret = mtd_write(c->mtd, ofs, len, retlen, buf);
-
-	if (jffs2_sum_active()) {
-		struct kvec vecs[1];
-		int res;
-
-		vecs[0].iov_base = (unsigned char *) buf;
-		vecs[0].iov_len = len;
-
-		res = jffs2_sum_add_kvec(c, vecs, 1, (uint32_t) ofs);
-		if (res) {
-			return res;
-		}
+	ret = c->mtd->write(c->mtd, ofs, len, (char *)buf);
+	if (ret >= 0) {
+		*retlen = ret;
+		return 0;
 	}
+	*retlen = 0;
 	return ret;
 }
diff -Nupr old/fs/jffs2/xattr.c new/fs/jffs2/xattr.c
--- old/fs/jffs2/xattr.c	2022-05-09 17:15:24.360000000 +0800
+++ new/fs/jffs2/xattr.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,1347 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2006  NEC Corporation
- *
- * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#define JFFS2_XATTR_IS_CORRUPTED	1
-
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/fs.h>
-#include <linux/time.h>
-#include <linux/pagemap.h>
-#include <linux/highmem.h>
-#include <linux/crc32.h>
-#include <linux/jffs2.h>
-#include <linux/xattr.h>
-#include <linux/posix_acl_xattr.h>
-#include <linux/mtd/mtd.h>
-#include "nodelist.h"
-/* -------- xdatum related functions ----------------
- * xattr_datum_hashkey(xprefix, xname, xvalue, xsize)
- *   is used to calcurate xdatum hashkey. The reminder of hashkey into XATTRINDEX_HASHSIZE is
- *   the index of the xattr name/value pair cache (c->xattrindex).
- * is_xattr_datum_unchecked(c, xd)
- *   returns 1, if xdatum contains any unchecked raw nodes. if all raw nodes are not
- *   unchecked, it returns 0.
- * unload_xattr_datum(c, xd)
- *   is used to release xattr name/value pair and detach from c->xattrindex.
- * reclaim_xattr_datum(c)
- *   is used to reclaim xattr name/value pairs on the xattr name/value pair cache when
- *   memory usage by cache is over c->xdatum_mem_threshold. Currently, this threshold
- *   is hard coded as 32KiB.
- * do_verify_xattr_datum(c, xd)
- *   is used to load the xdatum informations without name/value pair from the medium.
- *   It's necessary once, because those informations are not collected during mounting
- *   process when EBS is enabled.
- *   0 will be returned, if success. An negative return value means recoverable error, and
- *   positive return value means unrecoverable error. Thus, caller must remove this xdatum
- *   and xref when it returned positive value.
- * do_load_xattr_datum(c, xd)
- *   is used to load name/value pair from the medium.
- *   The meanings of return value is same as do_verify_xattr_datum().
- * load_xattr_datum(c, xd)
- *   is used to be as a wrapper of do_verify_xattr_datum() and do_load_xattr_datum().
- *   If xd need to call do_verify_xattr_datum() at first, it's called before calling
- *   do_load_xattr_datum(). The meanings of return value is same as do_verify_xattr_datum().
- * save_xattr_datum(c, xd)
- *   is used to write xdatum to medium. xd->version will be incremented.
- * create_xattr_datum(c, xprefix, xname, xvalue, xsize)
- *   is used to create new xdatum and write to medium.
- * unrefer_xattr_datum(c, xd)
- *   is used to delete a xdatum. When nobody refers this xdatum, JFFS2_XFLAGS_DEAD
- *   is set on xd->flags and chained xattr_dead_list or release it immediately.
- *   In the first case, the garbage collector release it later.
- * -------------------------------------------------- */
-static uint32_t xattr_datum_hashkey(int xprefix, const char *xname, const char *xvalue, int xsize)
-{
-	int name_len = strlen(xname);
-
-	return crc32(xprefix, xname, name_len) ^ crc32(xprefix, xvalue, xsize);
-}
-
-static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	struct jffs2_raw_node_ref *raw;
-	int rc = 0;
-
-	spin_lock(&c->erase_completion_lock);
-	for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
-		if (ref_flags(raw) == REF_UNCHECKED) {
-			rc = 1;
-			break;
-		}
-	}
-	spin_unlock(&c->erase_completion_lock);
-	return rc;
-}
-
-static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem) */
-	D1(dbg_xattr("%s: xid=%u, version=%u\n", __func__, xd->xid, xd->version));
-	if (xd->xname) {
-		c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len);
-		kfree(xd->xname);
-	}
-
-	list_del_init(&xd->xindex);
-	xd->hashkey = 0;
-	xd->xname = NULL;
-	xd->xvalue = NULL;
-}
-
-static void reclaim_xattr_datum(struct jffs2_sb_info *c)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_xattr_datum *xd, *_xd;
-	uint32_t target, before;
-	static int index = 0;
-	int count;
-
-	if (c->xdatum_mem_threshold > c->xdatum_mem_usage)
-		return;
-
-	before = c->xdatum_mem_usage;
-	target = c->xdatum_mem_usage * 4 / 5; /* 20% reduction */
-	for (count = 0; count < XATTRINDEX_HASHSIZE; count++) {
-		list_for_each_entry_safe(xd, _xd, &c->xattrindex[index], xindex) {
-			if (xd->flags & JFFS2_XFLAGS_HOT) {
-				xd->flags &= ~JFFS2_XFLAGS_HOT;
-			} else if (!(xd->flags & JFFS2_XFLAGS_BIND)) {
-				unload_xattr_datum(c, xd);
-			}
-			if (c->xdatum_mem_usage <= target)
-				goto out;
-		}
-		index = (index+1) % XATTRINDEX_HASHSIZE;
-	}
- out:
-	JFFS2_NOTICE("xdatum_mem_usage from %u byte to %u byte (%u byte reclaimed)\n",
-		     before, c->xdatum_mem_usage, before - c->xdatum_mem_usage);
-}
-
-static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_eraseblock *jeb;
-	struct jffs2_raw_node_ref *raw;
-	struct jffs2_raw_xattr rx;
-	size_t readlen;
-	uint32_t crc, offset, totlen;
-	int rc;
-
-	spin_lock(&c->erase_completion_lock);
-	offset = ref_offset(xd->node);
-	if (ref_flags(xd->node) == REF_PRISTINE)
-		goto complete;
-	spin_unlock(&c->erase_completion_lock);
-
-	rc = jffs2_flash_read(c, offset, sizeof(rx), &readlen, (char *)&rx);
-	if (rc || readlen != sizeof(rx)) {
-		JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu at %#08x\n",
-			      rc, sizeof(rx), readlen, offset);
-		return rc ? rc : -EIO;
-	}
-	crc = crc32(0, &rx, sizeof(rx) - 4);
-	if (crc != je32_to_cpu(rx.node_crc)) {
-		JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
-			    offset, je32_to_cpu(rx.hdr_crc), crc);
-		xd->flags |= JFFS2_XFLAGS_INVALID;
-		return JFFS2_XATTR_IS_CORRUPTED;
-	}
-	totlen = PAD(sizeof(rx) + rx.name_len + 1 + je16_to_cpu(rx.value_len));
-	if (je16_to_cpu(rx.magic) != JFFS2_MAGIC_BITMASK
-	    || je16_to_cpu(rx.nodetype) != JFFS2_NODETYPE_XATTR
-	    || je32_to_cpu(rx.totlen) != totlen
-	    || je32_to_cpu(rx.xid) != xd->xid
-	    || je32_to_cpu(rx.version) != xd->version) {
-		JFFS2_ERROR("inconsistent xdatum at %#08x, magic=%#04x/%#04x, "
-			    "nodetype=%#04x/%#04x, totlen=%u/%u, xid=%u/%u, version=%u/%u\n",
-			    offset, je16_to_cpu(rx.magic), JFFS2_MAGIC_BITMASK,
-			    je16_to_cpu(rx.nodetype), JFFS2_NODETYPE_XATTR,
-			    je32_to_cpu(rx.totlen), totlen,
-			    je32_to_cpu(rx.xid), xd->xid,
-			    je32_to_cpu(rx.version), xd->version);
-		xd->flags |= JFFS2_XFLAGS_INVALID;
-		return JFFS2_XATTR_IS_CORRUPTED;
-	}
-	xd->xprefix = rx.xprefix;
-	xd->name_len = rx.name_len;
-	xd->value_len = je16_to_cpu(rx.value_len);
-	xd->data_crc = je32_to_cpu(rx.data_crc);
-
-	spin_lock(&c->erase_completion_lock);
- complete:
-	for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
-		jeb = &c->blocks[ref_offset(raw) / c->sector_size];
-		totlen = PAD(ref_totlen(c, jeb, raw));
-		if (ref_flags(raw) == REF_UNCHECKED) {
-			c->unchecked_size -= totlen; c->used_size += totlen;
-			jeb->unchecked_size -= totlen; jeb->used_size += totlen;
-		}
-		raw->flash_offset = ref_offset(raw) | ((xd->node==raw) ? REF_PRISTINE : REF_NORMAL);
-	}
-	spin_unlock(&c->erase_completion_lock);
-
-	/* unchecked xdatum is chained with c->xattr_unchecked */
-	list_del_init(&xd->xindex);
-
-	dbg_xattr("success on verifying xdatum (xid=%u, version=%u)\n",
-		  xd->xid, xd->version);
-
-	return 0;
-}
-
-static int do_load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem) */
-	char *data;
-	size_t readlen;
-	uint32_t crc, length;
-	int i, ret, retry = 0;
-
-	BUG_ON(ref_flags(xd->node) != REF_PRISTINE);
-	BUG_ON(!list_empty(&xd->xindex));
- retry:
-	length = xd->name_len + 1 + xd->value_len;
-	data = kmalloc(length, GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	ret = jffs2_flash_read(c, ref_offset(xd->node)+sizeof(struct jffs2_raw_xattr),
-			       length, &readlen, data);
-
-	if (ret || length!=readlen) {
-		JFFS2_WARNING("jffs2_flash_read() returned %d, request=%d, readlen=%zu, at %#08x\n",
-			      ret, length, readlen, ref_offset(xd->node));
-		kfree(data);
-		return ret ? ret : -EIO;
-	}
-
-	data[xd->name_len] = '\0';
-	crc = crc32(0, data, length);
-	if (crc != xd->data_crc) {
-		JFFS2_WARNING("node CRC failed (JFFS2_NODETYPE_XATTR)"
-			      " at %#08x, read: 0x%08x calculated: 0x%08x\n",
-			      ref_offset(xd->node), xd->data_crc, crc);
-		kfree(data);
-		xd->flags |= JFFS2_XFLAGS_INVALID;
-		return JFFS2_XATTR_IS_CORRUPTED;
-	}
-
-	xd->flags |= JFFS2_XFLAGS_HOT;
-	xd->xname = data;
-	xd->xvalue = data + xd->name_len+1;
-
-	c->xdatum_mem_usage += length;
-
-	xd->hashkey = xattr_datum_hashkey(xd->xprefix, xd->xname, xd->xvalue, xd->value_len);
-	i = xd->hashkey % XATTRINDEX_HASHSIZE;
-	list_add(&xd->xindex, &c->xattrindex[i]);
-	if (!retry) {
-		retry = 1;
-		reclaim_xattr_datum(c);
-		if (!xd->xname)
-			goto retry;
-	}
-
-	dbg_xattr("success on loading xdatum (xid=%u, xprefix=%u, xname='%s')\n",
-		  xd->xid, xd->xprefix, xd->xname);
-
-	return 0;
-}
-
-static int load_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem);
-	 * rc < 0 : recoverable error, try again
-	 * rc = 0 : success
-	 * rc > 0 : Unrecoverable error, this node should be deleted.
-	 */
-	int rc = 0;
-
-	BUG_ON(xd->flags & JFFS2_XFLAGS_DEAD);
-	if (xd->xname)
-		return 0;
-	if (xd->flags & JFFS2_XFLAGS_INVALID)
-		return JFFS2_XATTR_IS_CORRUPTED;
-	if (unlikely(is_xattr_datum_unchecked(c, xd)))
-		rc = do_verify_xattr_datum(c, xd);
-	if (!rc)
-		rc = do_load_xattr_datum(c, xd);
-	return rc;
-}
-
-static int save_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_raw_xattr rx;
-	struct kvec vecs[2];
-	size_t length;
-	int rc, totlen;
-	uint32_t phys_ofs = write_ofs(c);
-
-	BUG_ON(!xd->xname);
-	BUG_ON(xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID));
-
-	vecs[0].iov_base = &rx;
-	vecs[0].iov_len = sizeof(rx);
-	vecs[1].iov_base = xd->xname;
-	vecs[1].iov_len = xd->name_len + 1 + xd->value_len;
-	totlen = vecs[0].iov_len + vecs[1].iov_len;
-
-	/* Setup raw-xattr */
-	memset(&rx, 0, sizeof(rx));
-	rx.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
-	rx.nodetype = cpu_to_je16(JFFS2_NODETYPE_XATTR);
-	rx.totlen = cpu_to_je32(PAD(totlen));
-	rx.hdr_crc = cpu_to_je32(crc32(0, &rx, sizeof(struct jffs2_unknown_node) - 4));
-
-	rx.xid = cpu_to_je32(xd->xid);
-	rx.version = cpu_to_je32(++xd->version);
-	rx.xprefix = xd->xprefix;
-	rx.name_len = xd->name_len;
-	rx.value_len = cpu_to_je16(xd->value_len);
-	rx.data_crc = cpu_to_je32(crc32(0, vecs[1].iov_base, vecs[1].iov_len));
-	rx.node_crc = cpu_to_je32(crc32(0, &rx, sizeof(struct jffs2_raw_xattr) - 4));
-
-	rc = jffs2_flash_writev(c, vecs, 2, phys_ofs, &length, 0);
-	if (rc || totlen != length) {
-		JFFS2_WARNING("jffs2_flash_writev()=%d, req=%u, wrote=%zu, at %#08x\n",
-			      rc, totlen, length, phys_ofs);
-		rc = rc ? rc : -EIO;
-		if (length)
-			jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(totlen), NULL);
-
-		return rc;
-	}
-	/* success */
-	jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(totlen), (void *)xd);
-
-	dbg_xattr("success on saving xdatum (xid=%u, version=%u, xprefix=%u, xname='%s')\n",
-		  xd->xid, xd->version, xd->xprefix, xd->xname);
-
-	return 0;
-}
-
-static struct jffs2_xattr_datum *create_xattr_datum(struct jffs2_sb_info *c,
-						    int xprefix, const char *xname,
-						    const char *xvalue, int xsize)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_xattr_datum *xd;
-	uint32_t hashkey, name_len;
-	char *data;
-	int i, rc;
-
-	/* Search xattr_datum has same xname/xvalue by index */
-	hashkey = xattr_datum_hashkey(xprefix, xname, xvalue, xsize);
-	i = hashkey % XATTRINDEX_HASHSIZE;
-	list_for_each_entry(xd, &c->xattrindex[i], xindex) {
-		if (xd->hashkey==hashkey
-		    && xd->xprefix==xprefix
-		    && xd->value_len==xsize
-		    && !strcmp(xd->xname, xname)
-		    && !memcmp(xd->xvalue, xvalue, xsize)) {
-			atomic_inc(&xd->refcnt);
-			return xd;
-		}
-	}
-
-	/* Not found, Create NEW XATTR-Cache */
-	name_len = strlen(xname);
-
-	xd = jffs2_alloc_xattr_datum();
-	if (!xd)
-		return ERR_PTR(-ENOMEM);
-
-	data = kmalloc(name_len + 1 + xsize, GFP_KERNEL);
-	if (!data) {
-		jffs2_free_xattr_datum(xd);
-		return ERR_PTR(-ENOMEM);
-	}
-	strcpy(data, xname);
-	memcpy(data + name_len + 1, xvalue, xsize);
-
-	atomic_set(&xd->refcnt, 1);
-	xd->xid = ++c->highest_xid;
-	xd->flags |= JFFS2_XFLAGS_HOT;
-	xd->xprefix = xprefix;
-
-	xd->hashkey = hashkey;
-	xd->xname = data;
-	xd->xvalue = data + name_len + 1;
-	xd->name_len = name_len;
-	xd->value_len = xsize;
-	xd->data_crc = crc32(0, data, xd->name_len + 1 + xd->value_len);
-
-	rc = save_xattr_datum(c, xd);
-	if (rc) {
-		kfree(xd->xname);
-		jffs2_free_xattr_datum(xd);
-		return ERR_PTR(rc);
-	}
-
-	/* Insert Hash Index */
-	i = hashkey % XATTRINDEX_HASHSIZE;
-	list_add(&xd->xindex, &c->xattrindex[i]);
-
-	c->xdatum_mem_usage += (xd->name_len + 1 + xd->value_len);
-	reclaim_xattr_datum(c);
-
-	return xd;
-}
-
-static void unrefer_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem) */
-	if (atomic_dec_and_lock(&xd->refcnt, &c->erase_completion_lock)) {
-		unload_xattr_datum(c, xd);
-		xd->flags |= JFFS2_XFLAGS_DEAD;
-		if (xd->node == (void *)xd) {
-			BUG_ON(!(xd->flags & JFFS2_XFLAGS_INVALID));
-			jffs2_free_xattr_datum(xd);
-		} else {
-			list_add(&xd->xindex, &c->xattr_dead_list);
-		}
-		spin_unlock(&c->erase_completion_lock);
-
-		dbg_xattr("xdatum(xid=%u, version=%u) was removed.\n",
-			  xd->xid, xd->version);
-	}
-}
-
-/* -------- xref related functions ------------------
- * verify_xattr_ref(c, ref)
- *   is used to load xref information from medium. Because summary data does not
- *   contain xid/ino, it's necessary to verify once while mounting process.
- * save_xattr_ref(c, ref)
- *   is used to write xref to medium. If delete marker is marked, it write
- *   a delete marker of xref into medium.
- * create_xattr_ref(c, ic, xd)
- *   is used to create a new xref and write to medium.
- * delete_xattr_ref(c, ref)
- *   is used to delete jffs2_xattr_ref. It marks xref XREF_DELETE_MARKER,
- *   and allows GC to reclaim those physical nodes.
- * jffs2_xattr_delete_inode(c, ic)
- *   is called to remove xrefs related to obsolete inode when inode is unlinked.
- * jffs2_xattr_free_inode(c, ic)
- *   is called to release xattr related objects when unmounting. 
- * check_xattr_ref_inode(c, ic)
- *   is used to confirm inode does not have duplicate xattr name/value pair.
- * jffs2_xattr_do_crccheck_inode(c, ic)
- *   is used to force xattr data integrity check during the initial gc scan.
- * -------------------------------------------------- */
-static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
-{
-	struct jffs2_eraseblock *jeb;
-	struct jffs2_raw_node_ref *raw;
-	struct jffs2_raw_xref rr;
-	size_t readlen;
-	uint32_t crc, offset, totlen;
-	int rc;
-
-	spin_lock(&c->erase_completion_lock);
-	if (ref_flags(ref->node) != REF_UNCHECKED)
-		goto complete;
-	offset = ref_offset(ref->node);
-	spin_unlock(&c->erase_completion_lock);
-
-	rc = jffs2_flash_read(c, offset, sizeof(rr), &readlen, (char *)&rr);
-	if (rc || sizeof(rr) != readlen) {
-		JFFS2_WARNING("jffs2_flash_read()=%d, req=%zu, read=%zu, at %#08x\n",
-			      rc, sizeof(rr), readlen, offset);
-		return rc ? rc : -EIO;
-	}
-	/* obsolete node */
-	crc = crc32(0, &rr, sizeof(rr) - 4);
-	if (crc != je32_to_cpu(rr.node_crc)) {
-		JFFS2_ERROR("node CRC failed at %#08x, read=%#08x, calc=%#08x\n",
-			    offset, je32_to_cpu(rr.node_crc), crc);
-		return JFFS2_XATTR_IS_CORRUPTED;
-	}
-	if (je16_to_cpu(rr.magic) != JFFS2_MAGIC_BITMASK
-	    || je16_to_cpu(rr.nodetype) != JFFS2_NODETYPE_XREF
-	    || je32_to_cpu(rr.totlen) != PAD(sizeof(rr))) {
-		JFFS2_ERROR("inconsistent xref at %#08x, magic=%#04x/%#04x, "
-			    "nodetype=%#04x/%#04x, totlen=%u/%zu\n",
-			    offset, je16_to_cpu(rr.magic), JFFS2_MAGIC_BITMASK,
-			    je16_to_cpu(rr.nodetype), JFFS2_NODETYPE_XREF,
-			    je32_to_cpu(rr.totlen), PAD(sizeof(rr)));
-		return JFFS2_XATTR_IS_CORRUPTED;
-	}
-	ref->ino = je32_to_cpu(rr.ino);
-	ref->xid = je32_to_cpu(rr.xid);
-	ref->xseqno = je32_to_cpu(rr.xseqno);
-	if (ref->xseqno > c->highest_xseqno)
-		c->highest_xseqno = (ref->xseqno & ~XREF_DELETE_MARKER);
-
-	spin_lock(&c->erase_completion_lock);
- complete:
-	for (raw=ref->node; raw != (void *)ref; raw=raw->next_in_ino) {
-		jeb = &c->blocks[ref_offset(raw) / c->sector_size];
-		totlen = PAD(ref_totlen(c, jeb, raw));
-		if (ref_flags(raw) == REF_UNCHECKED) {
-			c->unchecked_size -= totlen; c->used_size += totlen;
-			jeb->unchecked_size -= totlen; jeb->used_size += totlen;
-		}
-		raw->flash_offset = ref_offset(raw) | ((ref->node==raw) ? REF_PRISTINE : REF_NORMAL);
-	}
-	spin_unlock(&c->erase_completion_lock);
-
-	dbg_xattr("success on verifying xref (ino=%u, xid=%u) at %#08x\n",
-		  ref->ino, ref->xid, ref_offset(ref->node));
-	return 0;
-}
-
-static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_raw_xref rr;
-	size_t length;
-	uint32_t xseqno, phys_ofs = write_ofs(c);
-	int ret;
-
-	rr.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
-	rr.nodetype = cpu_to_je16(JFFS2_NODETYPE_XREF);
-	rr.totlen = cpu_to_je32(PAD(sizeof(rr)));
-	rr.hdr_crc = cpu_to_je32(crc32(0, &rr, sizeof(struct jffs2_unknown_node) - 4));
-
-	xseqno = (c->highest_xseqno += 2);
-	if (is_xattr_ref_dead(ref)) {
-		xseqno |= XREF_DELETE_MARKER;
-		rr.ino = cpu_to_je32(ref->ino);
-		rr.xid = cpu_to_je32(ref->xid);
-	} else {
-		rr.ino = cpu_to_je32(ref->ic->ino);
-		rr.xid = cpu_to_je32(ref->xd->xid);
-	}
-	rr.xseqno = cpu_to_je32(xseqno);
-	rr.node_crc = cpu_to_je32(crc32(0, &rr, sizeof(rr) - 4));
-
-	ret = jffs2_flash_write(c, phys_ofs, sizeof(rr), &length, (char *)&rr);
-	if (ret || sizeof(rr) != length) {
-		JFFS2_WARNING("jffs2_flash_write() returned %d, request=%zu, retlen=%zu, at %#08x\n",
-			      ret, sizeof(rr), length, phys_ofs);
-		ret = ret ? ret : -EIO;
-		if (length)
-			jffs2_add_physical_node_ref(c, phys_ofs | REF_OBSOLETE, PAD(sizeof(rr)), NULL);
-
-		return ret;
-	}
-	/* success */
-	ref->xseqno = xseqno;
-	jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref);
-
-	dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid);
-
-	return 0;
-}
-
-static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic,
-						struct jffs2_xattr_datum *xd)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_xattr_ref *ref;
-	int ret;
-
-	ref = jffs2_alloc_xattr_ref();
-	if (!ref)
-		return ERR_PTR(-ENOMEM);
-	ref->ic = ic;
-	ref->xd = xd;
-
-	ret = save_xattr_ref(c, ref);
-	if (ret) {
-		jffs2_free_xattr_ref(ref);
-		return ERR_PTR(ret);
-	}
-
-	/* Chain to inode */
-	ref->next = ic->xref;
-	ic->xref = ref;
-
-	return ref; /* success */
-}
-
-static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
-{
-	/* must be called under down_write(xattr_sem) */
-	struct jffs2_xattr_datum *xd;
-
-	xd = ref->xd;
-	ref->xseqno |= XREF_DELETE_MARKER;
-	ref->ino = ref->ic->ino;
-	ref->xid = ref->xd->xid;
-	spin_lock(&c->erase_completion_lock);
-	ref->next = c->xref_dead_list;
-	c->xref_dead_list = ref;
-	spin_unlock(&c->erase_completion_lock);
-
-	dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n",
-		  ref->ino, ref->xid, ref->xseqno);
-
-	unrefer_xattr_datum(c, xd);
-}
-
-void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
-{
-	/* It's called from jffs2_evict_inode() on inode removing.
-	   When an inode with XATTR is removed, those XATTRs must be removed. */
-	struct jffs2_xattr_ref *ref, *_ref;
-
-	if (!ic || ic->pino_nlink > 0)
-		return;
-
-	down_write(&c->xattr_sem);
-	for (ref = ic->xref; ref; ref = _ref) {
-		_ref = ref->next;
-		delete_xattr_ref(c, ref);
-	}
-	ic->xref = NULL;
-	up_write(&c->xattr_sem);
-}
-
-void jffs2_xattr_free_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
-{
-	/* It's called from jffs2_free_ino_caches() until unmounting FS. */
-	struct jffs2_xattr_datum *xd;
-	struct jffs2_xattr_ref *ref, *_ref;
-
-	down_write(&c->xattr_sem);
-	for (ref = ic->xref; ref; ref = _ref) {
-		_ref = ref->next;
-		xd = ref->xd;
-		if (atomic_dec_and_test(&xd->refcnt)) {
-			unload_xattr_datum(c, xd);
-			jffs2_free_xattr_datum(xd);
-		}
-		jffs2_free_xattr_ref(ref);
-	}
-	ic->xref = NULL;
-	up_write(&c->xattr_sem);
-}
-
-static int check_xattr_ref_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
-{
-	/* success of check_xattr_ref_inode() means that inode (ic) dose not have
-	 * duplicate name/value pairs. If duplicate name/value pair would be found,
-	 * one will be removed.
-	 */
-	struct jffs2_xattr_ref *ref, *cmp, **pref, **pcmp;
-	int rc = 0;
-
-	if (likely(ic->flags & INO_FLAGS_XATTR_CHECKED))
-		return 0;
-	down_write(&c->xattr_sem);
- retry:
-	rc = 0;
-	for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
-		if (!ref->xd->xname) {
-			rc = load_xattr_datum(c, ref->xd);
-			if (unlikely(rc > 0)) {
-				*pref = ref->next;
-				delete_xattr_ref(c, ref);
-				goto retry;
-			} else if (unlikely(rc < 0))
-				goto out;
-		}
-		for (cmp=ref->next, pcmp=&ref->next; cmp; pcmp=&cmp->next, cmp=cmp->next) {
-			if (!cmp->xd->xname) {
-				ref->xd->flags |= JFFS2_XFLAGS_BIND;
-				rc = load_xattr_datum(c, cmp->xd);
-				ref->xd->flags &= ~JFFS2_XFLAGS_BIND;
-				if (unlikely(rc > 0)) {
-					*pcmp = cmp->next;
-					delete_xattr_ref(c, cmp);
-					goto retry;
-				} else if (unlikely(rc < 0))
-					goto out;
-			}
-			if (ref->xd->xprefix == cmp->xd->xprefix
-			    && !strcmp(ref->xd->xname, cmp->xd->xname)) {
-				if (ref->xseqno > cmp->xseqno) {
-					*pcmp = cmp->next;
-					delete_xattr_ref(c, cmp);
-				} else {
-					*pref = ref->next;
-					delete_xattr_ref(c, ref);
-				}
-				goto retry;
-			}
-		}
-	}
-	ic->flags |= INO_FLAGS_XATTR_CHECKED;
- out:
-	up_write(&c->xattr_sem);
-
-	return rc;
-}
-
-void jffs2_xattr_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
-{
-	check_xattr_ref_inode(c, ic);
-}
-
-/* -------- xattr subsystem functions ---------------
- * jffs2_init_xattr_subsystem(c)
- *   is used to initialize semaphore and list_head, and some variables.
- * jffs2_find_xattr_datum(c, xid)
- *   is used to lookup xdatum while scanning process.
- * jffs2_clear_xattr_subsystem(c)
- *   is used to release any xattr related objects.
- * jffs2_build_xattr_subsystem(c)
- *   is used to associate xdatum and xref while super block building process.
- * jffs2_setup_xattr_datum(c, xid, version)
- *   is used to insert xdatum while scanning process.
- * -------------------------------------------------- */
-void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c)
-{
-	int i;
-
-	for (i=0; i < XATTRINDEX_HASHSIZE; i++)
-		INIT_LIST_HEAD(&c->xattrindex[i]);
-	INIT_LIST_HEAD(&c->xattr_unchecked);
-	INIT_LIST_HEAD(&c->xattr_dead_list);
-	c->xref_dead_list = NULL;
-	c->xref_temp = NULL;
-
-	init_rwsem(&c->xattr_sem);
-	c->highest_xid = 0;
-	c->highest_xseqno = 0;
-	c->xdatum_mem_usage = 0;
-	c->xdatum_mem_threshold = 32 * 1024;	/* Default 32KB */
-}
-
-static struct jffs2_xattr_datum *jffs2_find_xattr_datum(struct jffs2_sb_info *c, uint32_t xid)
-{
-	struct jffs2_xattr_datum *xd;
-	int i = xid % XATTRINDEX_HASHSIZE;
-
-	/* It's only used in scanning/building process. */
-	BUG_ON(!(c->flags & (JFFS2_SB_FLAG_SCANNING|JFFS2_SB_FLAG_BUILDING)));
-
-	list_for_each_entry(xd, &c->xattrindex[i], xindex) {
-		if (xd->xid==xid)
-			return xd;
-	}
-	return NULL;
-}
-
-void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c)
-{
-	struct jffs2_xattr_datum *xd, *_xd;
-	struct jffs2_xattr_ref *ref, *_ref;
-	int i;
-
-	for (ref=c->xref_temp; ref; ref = _ref) {
-		_ref = ref->next;
-		jffs2_free_xattr_ref(ref);
-	}
-
-	for (ref=c->xref_dead_list; ref; ref = _ref) {
-		_ref = ref->next;
-		jffs2_free_xattr_ref(ref);
-	}
-
-	for (i=0; i < XATTRINDEX_HASHSIZE; i++) {
-		list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) {
-			list_del(&xd->xindex);
-			kfree(xd->xname);
-			jffs2_free_xattr_datum(xd);
-		}
-	}
-
-	list_for_each_entry_safe(xd, _xd, &c->xattr_dead_list, xindex) {
-		list_del(&xd->xindex);
-		jffs2_free_xattr_datum(xd);
-	}
-	list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) {
-		list_del(&xd->xindex);
-		jffs2_free_xattr_datum(xd);
-	}
-}
-
-#define XREF_TMPHASH_SIZE	(128)
-void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
-{
-	struct jffs2_xattr_ref *ref, *_ref;
-	struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE];
-	struct jffs2_xattr_datum *xd, *_xd;
-	struct jffs2_inode_cache *ic;
-	struct jffs2_raw_node_ref *raw;
-	int i, xdatum_count = 0, xdatum_unchecked_count = 0, xref_count = 0;
-	int xdatum_orphan_count = 0, xref_orphan_count = 0, xref_dead_count = 0;
-
-	BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
-
-	/* Phase.1 : Merge same xref */
-	for (i=0; i < XREF_TMPHASH_SIZE; i++)
-		xref_tmphash[i] = NULL;
-	for (ref=c->xref_temp; ref; ref=_ref) {
-		struct jffs2_xattr_ref *tmp;
-
-		_ref = ref->next;
-		if (ref_flags(ref->node) != REF_PRISTINE) {
-			if (verify_xattr_ref(c, ref)) {
-				BUG_ON(ref->node->next_in_ino != (void *)ref);
-				ref->node->next_in_ino = NULL;
-				jffs2_mark_node_obsolete(c, ref->node);
-				jffs2_free_xattr_ref(ref);
-				continue;
-			}
-		}
-
-		i = (ref->ino ^ ref->xid) % XREF_TMPHASH_SIZE;
-		for (tmp=xref_tmphash[i]; tmp; tmp=tmp->next) {
-			if (tmp->ino == ref->ino && tmp->xid == ref->xid)
-				break;
-		}
-		if (tmp) {
-			raw = ref->node;
-			if (ref->xseqno > tmp->xseqno) {
-				tmp->xseqno = ref->xseqno;
-				raw->next_in_ino = tmp->node;
-				tmp->node = raw;
-			} else {
-				raw->next_in_ino = tmp->node->next_in_ino;
-				tmp->node->next_in_ino = raw;
-			}
-			jffs2_free_xattr_ref(ref);
-			continue;
-		} else {
-			ref->next = xref_tmphash[i];
-			xref_tmphash[i] = ref;
-		}
-	}
-	c->xref_temp = NULL;
-
-	/* Phase.2 : Bind xref with inode_cache and xattr_datum */
-	for (i=0; i < XREF_TMPHASH_SIZE; i++) {
-		for (ref=xref_tmphash[i]; ref; ref=_ref) {
-			xref_count++;
-			_ref = ref->next;
-			if (is_xattr_ref_dead(ref)) {
-				ref->next = c->xref_dead_list;
-				c->xref_dead_list = ref;
-				xref_dead_count++;
-				continue;
-			}
-			/* At this point, ref->xid and ref->ino contain XID and inode number.
-			   ref->xd and ref->ic are not valid yet. */
-			xd = jffs2_find_xattr_datum(c, ref->xid);
-			ic = jffs2_get_ino_cache(c, ref->ino);
-			if (!xd || !ic || !ic->pino_nlink) {
-				dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) is orphan.\n",
-					  ref->ino, ref->xid, ref->xseqno);
-				ref->xseqno |= XREF_DELETE_MARKER;
-				ref->next = c->xref_dead_list;
-				c->xref_dead_list = ref;
-				xref_orphan_count++;
-				continue;
-			}
-			ref->xd = xd;
-			ref->ic = ic;
-			atomic_inc(&xd->refcnt);
-			ref->next = ic->xref;
-			ic->xref = ref;
-		}
-	}
-
-	/* Phase.3 : Link unchecked xdatum to xattr_unchecked list */
-	for (i=0; i < XATTRINDEX_HASHSIZE; i++) {
-		list_for_each_entry_safe(xd, _xd, &c->xattrindex[i], xindex) {
-			xdatum_count++;
-			list_del_init(&xd->xindex);
-			if (!atomic_read(&xd->refcnt)) {
-				dbg_xattr("xdatum(xid=%u, version=%u) is orphan.\n",
-					  xd->xid, xd->version);
-				xd->flags |= JFFS2_XFLAGS_DEAD;
-				list_add(&xd->xindex, &c->xattr_unchecked);
-				xdatum_orphan_count++;
-				continue;
-			}
-			if (is_xattr_datum_unchecked(c, xd)) {
-				dbg_xattr("unchecked xdatum(xid=%u, version=%u)\n",
-					  xd->xid, xd->version);
-				list_add(&xd->xindex, &c->xattr_unchecked);
-				xdatum_unchecked_count++;
-			}
-		}
-	}
-	/* build complete */
-	JFFS2_NOTICE("complete building xattr subsystem, %u of xdatum"
-		     " (%u unchecked, %u orphan) and "
-		     "%u of xref (%u dead, %u orphan) found.\n",
-		     xdatum_count, xdatum_unchecked_count, xdatum_orphan_count,
-		     xref_count, xref_dead_count, xref_orphan_count);
-}
-
-struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
-						  uint32_t xid, uint32_t version)
-{
-	struct jffs2_xattr_datum *xd;
-
-	xd = jffs2_find_xattr_datum(c, xid);
-	if (!xd) {
-		xd = jffs2_alloc_xattr_datum();
-		if (!xd)
-			return ERR_PTR(-ENOMEM);
-		xd->xid = xid;
-		xd->version = version;
-		if (xd->xid > c->highest_xid)
-			c->highest_xid = xd->xid;
-		list_add_tail(&xd->xindex, &c->xattrindex[xid % XATTRINDEX_HASHSIZE]);
-	}
-	return xd;
-}
-
-/* -------- xattr subsystem functions ---------------
- * xprefix_to_handler(xprefix)
- *   is used to translate xprefix into xattr_handler.
- * jffs2_listxattr(dentry, buffer, size)
- *   is an implementation of listxattr handler on jffs2.
- * do_jffs2_getxattr(inode, xprefix, xname, buffer, size)
- *   is an implementation of getxattr handler on jffs2.
- * do_jffs2_setxattr(inode, xprefix, xname, buffer, size, flags)
- *   is an implementation of setxattr handler on jffs2.
- * -------------------------------------------------- */
-const struct xattr_handler *jffs2_xattr_handlers[] = {
-	&jffs2_user_xattr_handler,
-#ifdef CONFIG_JFFS2_FS_SECURITY
-	&jffs2_security_xattr_handler,
-#endif
-#ifdef CONFIG_JFFS2_FS_POSIX_ACL
-	&posix_acl_access_xattr_handler,
-	&posix_acl_default_xattr_handler,
-#endif
-	&jffs2_trusted_xattr_handler,
-	NULL
-};
-
-static const struct xattr_handler *xprefix_to_handler(int xprefix) {
-	const struct xattr_handler *ret;
-
-	switch (xprefix) {
-	case JFFS2_XPREFIX_USER:
-		ret = &jffs2_user_xattr_handler;
-		break;
-#ifdef CONFIG_JFFS2_FS_SECURITY
-	case JFFS2_XPREFIX_SECURITY:
-		ret = &jffs2_security_xattr_handler;
-		break;
-#endif
-#ifdef CONFIG_JFFS2_FS_POSIX_ACL
-	case JFFS2_XPREFIX_ACL_ACCESS:
-		ret = &posix_acl_access_xattr_handler;
-		break;
-	case JFFS2_XPREFIX_ACL_DEFAULT:
-		ret = &posix_acl_default_xattr_handler;
-		break;
-#endif
-	case JFFS2_XPREFIX_TRUSTED:
-		ret = &jffs2_trusted_xattr_handler;
-		break;
-	default:
-		ret = NULL;
-		break;
-	}
-	return ret;
-}
-
-ssize_t jffs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
-{
-	struct inode *inode = d_inode(dentry);
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
-	struct jffs2_inode_cache *ic = f->inocache;
-	struct jffs2_xattr_ref *ref, **pref;
-	struct jffs2_xattr_datum *xd;
-	const struct xattr_handler *xhandle;
-	const char *prefix;
-	ssize_t prefix_len, len, rc;
-	int retry = 0;
-
-	rc = check_xattr_ref_inode(c, ic);
-	if (unlikely(rc))
-		return rc;
-
-	down_read(&c->xattr_sem);
- retry:
-	len = 0;
-	for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
-		BUG_ON(ref->ic != ic);
-		xd = ref->xd;
-		if (!xd->xname) {
-			/* xdatum is unchached */
-			if (!retry) {
-				retry = 1;
-				up_read(&c->xattr_sem);
-				down_write(&c->xattr_sem);
-				goto retry;
-			} else {
-				rc = load_xattr_datum(c, xd);
-				if (unlikely(rc > 0)) {
-					*pref = ref->next;
-					delete_xattr_ref(c, ref);
-					goto retry;
-				} else if (unlikely(rc < 0))
-					goto out;
-			}
-		}
-		xhandle = xprefix_to_handler(xd->xprefix);
-		if (!xhandle || (xhandle->list && !xhandle->list(dentry)))
-			continue;
-		prefix = xhandle->prefix ?: xhandle->name;
-		prefix_len = strlen(prefix);
-		rc = prefix_len + xd->name_len + 1;
-
-		if (buffer) {
-			if (rc > size - len) {
-				rc = -ERANGE;
-				goto out;
-			}
-			memcpy(buffer, prefix, prefix_len);
-			buffer += prefix_len;
-			memcpy(buffer, xd->xname, xd->name_len);
-			buffer += xd->name_len;
-			*buffer++ = 0;
-		}
-		len += rc;
-	}
-	rc = len;
- out:
-	if (!retry) {
-		up_read(&c->xattr_sem);
-	} else {
-		up_write(&c->xattr_sem);
-	}
-	return rc;
-}
-
-int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname,
-		      char *buffer, size_t size)
-{
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
-	struct jffs2_inode_cache *ic = f->inocache;
-	struct jffs2_xattr_datum *xd;
-	struct jffs2_xattr_ref *ref, **pref;
-	int rc, retry = 0;
-
-	rc = check_xattr_ref_inode(c, ic);
-	if (unlikely(rc))
-		return rc;
-
-	down_read(&c->xattr_sem);
- retry:
-	for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
-		BUG_ON(ref->ic!=ic);
-
-		xd = ref->xd;
-		if (xd->xprefix != xprefix)
-			continue;
-		if (!xd->xname) {
-			/* xdatum is unchached */
-			if (!retry) {
-				retry = 1;
-				up_read(&c->xattr_sem);
-				down_write(&c->xattr_sem);
-				goto retry;
-			} else {
-				rc = load_xattr_datum(c, xd);
-				if (unlikely(rc > 0)) {
-					*pref = ref->next;
-					delete_xattr_ref(c, ref);
-					goto retry;
-				} else if (unlikely(rc < 0)) {
-					goto out;
-				}
-			}
-		}
-		if (!strcmp(xname, xd->xname)) {
-			rc = xd->value_len;
-			if (buffer) {
-				if (size < rc) {
-					rc = -ERANGE;
-				} else {
-					memcpy(buffer, xd->xvalue, rc);
-				}
-			}
-			goto out;
-		}
-	}
-	rc = -ENODATA;
- out:
-	if (!retry) {
-		up_read(&c->xattr_sem);
-	} else {
-		up_write(&c->xattr_sem);
-	}
-	return rc;
-}
-
-int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
-		      const char *buffer, size_t size, int flags)
-{
-	struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
-	struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
-	struct jffs2_inode_cache *ic = f->inocache;
-	struct jffs2_xattr_datum *xd;
-	struct jffs2_xattr_ref *ref, *newref, **pref;
-	uint32_t length, request;
-	int rc;
-
-	rc = check_xattr_ref_inode(c, ic);
-	if (unlikely(rc))
-		return rc;
-
-	request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
-	rc = jffs2_reserve_space(c, request, &length,
-				 ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
-	if (rc) {
-		JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
-		return rc;
-	}
-
-	/* Find existing xattr */
-	down_write(&c->xattr_sem);
- retry:
-	for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
-		xd = ref->xd;
-		if (xd->xprefix != xprefix)
-			continue;
-		if (!xd->xname) {
-			rc = load_xattr_datum(c, xd);
-			if (unlikely(rc > 0)) {
-				*pref = ref->next;
-				delete_xattr_ref(c, ref);
-				goto retry;
-			} else if (unlikely(rc < 0))
-				goto out;
-		}
-		if (!strcmp(xd->xname, xname)) {
-			if (flags & XATTR_CREATE) {
-				rc = -EEXIST;
-				goto out;
-			}
-			if (!buffer) {
-				ref->ino = ic->ino;
-				ref->xid = xd->xid;
-				ref->xseqno |= XREF_DELETE_MARKER;
-				rc = save_xattr_ref(c, ref);
-				if (!rc) {
-					*pref = ref->next;
-					spin_lock(&c->erase_completion_lock);
-					ref->next = c->xref_dead_list;
-					c->xref_dead_list = ref;
-					spin_unlock(&c->erase_completion_lock);
-					unrefer_xattr_datum(c, xd);
-				} else {
-					ref->ic = ic;
-					ref->xd = xd;
-					ref->xseqno &= ~XREF_DELETE_MARKER;
-				}
-				goto out;
-			}
-			goto found;
-		}
-	}
-	/* not found */
-	if (flags & XATTR_REPLACE) {
-		rc = -ENODATA;
-		goto out;
-	}
-	if (!buffer) {
-		rc = -ENODATA;
-		goto out;
-	}
- found:
-	xd = create_xattr_datum(c, xprefix, xname, buffer, size);
-	if (IS_ERR(xd)) {
-		rc = PTR_ERR(xd);
-		goto out;
-	}
-	up_write(&c->xattr_sem);
-	jffs2_complete_reservation(c);
-
-	/* create xattr_ref */
-	request = PAD(sizeof(struct jffs2_raw_xref));
-	rc = jffs2_reserve_space(c, request, &length,
-				 ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE);
-	down_write(&c->xattr_sem);
-	if (rc) {
-		JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
-		unrefer_xattr_datum(c, xd);
-		up_write(&c->xattr_sem);
-		return rc;
-	}
-	if (ref)
-		*pref = ref->next;
-	newref = create_xattr_ref(c, ic, xd);
-	if (IS_ERR(newref)) {
-		if (ref) {
-			ref->next = ic->xref;
-			ic->xref = ref;
-		}
-		rc = PTR_ERR(newref);
-		unrefer_xattr_datum(c, xd);
-	} else if (ref) {
-		delete_xattr_ref(c, ref);
-	}
- out:
-	up_write(&c->xattr_sem);
-	jffs2_complete_reservation(c);
-	return rc;
-}
-
-/* -------- garbage collector functions -------------
- * jffs2_garbage_collect_xattr_datum(c, xd, raw)
- *   is used to move xdatum into new node.
- * jffs2_garbage_collect_xattr_ref(c, ref, raw)
- *   is used to move xref into new node.
- * jffs2_verify_xattr(c)
- *   is used to call do_verify_xattr_datum() before garbage collecting.
- * jffs2_release_xattr_datum(c, xd)
- *   is used to release an in-memory object of xdatum.
- * jffs2_release_xattr_ref(c, ref)
- *   is used to release an in-memory object of xref.
- * -------------------------------------------------- */
-int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd,
-				      struct jffs2_raw_node_ref *raw)
-{
-	uint32_t totlen, length, old_ofs;
-	int rc = 0;
-
-	down_write(&c->xattr_sem);
-	if (xd->node != raw)
-		goto out;
-	if (xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID))
-		goto out;
-
-	rc = load_xattr_datum(c, xd);
-	if (unlikely(rc)) {
-		rc = (rc > 0) ? 0 : rc;
-		goto out;
-	}
-	old_ofs = ref_offset(xd->node);
-	totlen = PAD(sizeof(struct jffs2_raw_xattr)
-			+ xd->name_len + 1 + xd->value_len);
-	rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
-	if (rc) {
-		JFFS2_WARNING("jffs2_reserve_space_gc()=%d, request=%u\n", rc, totlen);
-		goto out;
-	}
-	rc = save_xattr_datum(c, xd);
-	if (!rc)
-		dbg_xattr("xdatum (xid=%u, version=%u) GC'ed from %#08x to %08x\n",
-			  xd->xid, xd->version, old_ofs, ref_offset(xd->node));
- out:
-	if (!rc)
-		jffs2_mark_node_obsolete(c, raw);
-	up_write(&c->xattr_sem);
-	return rc;
-}
-
-int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
-				    struct jffs2_raw_node_ref *raw)
-{
-	uint32_t totlen, length, old_ofs;
-	int rc = 0;
-
-	down_write(&c->xattr_sem);
-	BUG_ON(!ref->node);
-
-	if (ref->node != raw)
-		goto out;
-	if (is_xattr_ref_dead(ref) && (raw->next_in_ino == (void *)ref))
-		goto out;
-
-	old_ofs = ref_offset(ref->node);
-	totlen = ref_totlen(c, c->gcblock, ref->node);
-
-	rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
-	if (rc) {
-		JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n",
-			      __func__, rc, totlen);
-		goto out;
-	}
-	rc = save_xattr_ref(c, ref);
-	if (!rc)
-		dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n",
-			  ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node));
- out:
-	if (!rc)
-		jffs2_mark_node_obsolete(c, raw);
-	up_write(&c->xattr_sem);
-	return rc;
-}
-
-int jffs2_verify_xattr(struct jffs2_sb_info *c)
-{
-	struct jffs2_xattr_datum *xd, *_xd;
-	struct jffs2_eraseblock *jeb;
-	struct jffs2_raw_node_ref *raw;
-	uint32_t totlen;
-	int rc;
-
-	down_write(&c->xattr_sem);
-	list_for_each_entry_safe(xd, _xd, &c->xattr_unchecked, xindex) {
-		rc = do_verify_xattr_datum(c, xd);
-		if (rc < 0)
-			continue;
-		list_del_init(&xd->xindex);
-		spin_lock(&c->erase_completion_lock);
-		for (raw=xd->node; raw != (void *)xd; raw=raw->next_in_ino) {
-			if (ref_flags(raw) != REF_UNCHECKED)
-				continue;
-			jeb = &c->blocks[ref_offset(raw) / c->sector_size];
-			totlen = PAD(ref_totlen(c, jeb, raw));
-			c->unchecked_size -= totlen; c->used_size += totlen;
-			jeb->unchecked_size -= totlen; jeb->used_size += totlen;
-			raw->flash_offset = ref_offset(raw)
-				| ((xd->node == (void *)raw) ? REF_PRISTINE : REF_NORMAL);
-		}
-		if (xd->flags & JFFS2_XFLAGS_DEAD)
-			list_add(&xd->xindex, &c->xattr_dead_list);
-		spin_unlock(&c->erase_completion_lock);
-	}
-	up_write(&c->xattr_sem);
-	return list_empty(&c->xattr_unchecked) ? 1 : 0;
-}
-
-void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
-{
-	/* must be called under spin_lock(&c->erase_completion_lock) */
-	if (atomic_read(&xd->refcnt) || xd->node != (void *)xd)
-		return;
-
-	list_del(&xd->xindex);
-	jffs2_free_xattr_datum(xd);
-}
-
-void jffs2_release_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
-{
-	/* must be called under spin_lock(&c->erase_completion_lock) */
-	struct jffs2_xattr_ref *tmp, **ptmp;
-
-	if (ref->node != (void *)ref)
-		return;
-
-	for (tmp=c->xref_dead_list, ptmp=&c->xref_dead_list; tmp; ptmp=&tmp->next, tmp=tmp->next) {
-		if (ref == tmp) {
-			*ptmp = tmp->next;
-			break;
-		}
-	}
-	jffs2_free_xattr_ref(ref);
-}
diff -Nupr old/fs/jffs2/xattr.h new/fs/jffs2/xattr.h
--- old/fs/jffs2/xattr.h	2022-05-09 17:22:53.000000000 +0800
+++ new/fs/jffs2/xattr.h	2022-05-09 20:04:55.580000000 +0800
@@ -12,7 +12,6 @@
 #ifndef _JFFS2_FS_XATTR_H_
 #define _JFFS2_FS_XATTR_H_
 
-#include <linux/xattr.h>
 #include <linux/list.h>
 
 #define JFFS2_XFLAGS_HOT	(0x01)	/* This datum is HOT */
@@ -48,7 +47,7 @@ struct jffs2_xattr_ref
 	struct jffs2_raw_node_ref *node;
 	uint8_t class;
 	uint8_t flags;		/* Currently unused */
-	u16 unused;
+	uint16_t unused;
 
 	uint32_t xseqno;
 	union {
@@ -89,16 +88,14 @@ extern int jffs2_verify_xattr(struct jff
 extern void jffs2_release_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd);
 extern void jffs2_release_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref);
 
-extern int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname,
-			     char *buffer, size_t size);
-extern int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
-			     const char *buffer, size_t size, int flags);
-
 extern const struct xattr_handler *jffs2_xattr_handlers[];
 extern const struct xattr_handler jffs2_user_xattr_handler;
 extern const struct xattr_handler jffs2_trusted_xattr_handler;
 
 extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t);
+#define jffs2_getxattr		generic_getxattr
+#define jffs2_setxattr		generic_setxattr
+#define jffs2_removexattr	generic_removexattr
 
 #else
 
@@ -113,12 +110,13 @@ extern ssize_t jffs2_listxattr(struct de
 
 #define jffs2_xattr_handlers	NULL
 #define jffs2_listxattr		NULL
+#define jffs2_getxattr		NULL
+#define jffs2_setxattr		NULL
+#define jffs2_removexattr	NULL
 
 #endif /* CONFIG_JFFS2_FS_XATTR */
 
 #ifdef CONFIG_JFFS2_FS_SECURITY
-extern int jffs2_init_security(struct inode *inode, struct inode *dir,
-			       const struct qstr *qstr);
 extern const struct xattr_handler jffs2_security_xattr_handler;
 #else
 #define jffs2_init_security(inode,dir,qstr)	(0)
diff -Nupr old/fs/jffs2/xattr_trusted.c new/fs/jffs2/xattr_trusted.c
--- old/fs/jffs2/xattr_trusted.c	2022-05-09 17:15:24.360000000 +0800
+++ new/fs/jffs2/xattr_trusted.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,46 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2006  NEC Corporation
- *
- * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/jffs2.h>
-#include <linux/xattr.h>
-#include <linux/mtd/mtd.h>
-#include "nodelist.h"
-
-static int jffs2_trusted_getxattr(const struct xattr_handler *handler,
-				  struct dentry *unused, struct inode *inode,
-				  const char *name, void *buffer, size_t size)
-{
-	return do_jffs2_getxattr(inode, JFFS2_XPREFIX_TRUSTED,
-				 name, buffer, size);
-}
-
-static int jffs2_trusted_setxattr(const struct xattr_handler *handler,
-				  struct dentry *unused, struct inode *inode,
-				  const char *name, const void *buffer,
-				  size_t size, int flags)
-{
-	return do_jffs2_setxattr(inode, JFFS2_XPREFIX_TRUSTED,
-				 name, buffer, size, flags);
-}
-
-static bool jffs2_trusted_listxattr(struct dentry *dentry)
-{
-	return capable(CAP_SYS_ADMIN);
-}
-
-const struct xattr_handler jffs2_trusted_xattr_handler = {
-	.prefix = XATTR_TRUSTED_PREFIX,
-	.list = jffs2_trusted_listxattr,
-	.set = jffs2_trusted_setxattr,
-	.get = jffs2_trusted_getxattr
-};
diff -Nupr old/fs/jffs2/xattr_user.c new/fs/jffs2/xattr_user.c
--- old/fs/jffs2/xattr_user.c	2022-05-09 17:15:24.360000000 +0800
+++ new/fs/jffs2/xattr_user.c	1970-01-01 08:00:00.000000000 +0800
@@ -1,40 +0,0 @@
-/*
- * JFFS2 -- Journalling Flash File System, Version 2.
- *
- * Copyright © 2006  NEC Corporation
- *
- * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
- *
- * For licensing information, see the file 'LICENCE' in this directory.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/jffs2.h>
-#include <linux/xattr.h>
-#include <linux/mtd/mtd.h>
-#include "nodelist.h"
-
-static int jffs2_user_getxattr(const struct xattr_handler *handler,
-			       struct dentry *unused, struct inode *inode,
-			       const char *name, void *buffer, size_t size)
-{
-	return do_jffs2_getxattr(inode, JFFS2_XPREFIX_USER,
-				 name, buffer, size);
-}
-
-static int jffs2_user_setxattr(const struct xattr_handler *handler,
-			       struct dentry *unused, struct inode *inode,
-			       const char *name, const void *buffer,
-			       size_t size, int flags)
-{
-	return do_jffs2_setxattr(inode, JFFS2_XPREFIX_USER,
-				 name, buffer, size, flags);
-}
-
-const struct xattr_handler jffs2_user_xattr_handler = {
-	.prefix = XATTR_USER_PREFIX,
-	.set = jffs2_user_setxattr,
-	.get = jffs2_user_getxattr
-};