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
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
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
2401
2402
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
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
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
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
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
2664
2665
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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
*
* super.c: exFAT glue layer for supporting VFS
*/
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/time.h>
#include <linux/slab.h>
#include <linux/seq_file.h>
#include <linux/pagemap.h>
#include <linux/mpage.h>
#include <linux/buffer_head.h>
#include <linux/exportfs.h>
#include <linux/mount.h>
#include <linux/vfs.h>
#include <linux/parser.h>
#include <linux/uio.h>
#include <linux/writeback.h>
#include <linux/log2.h>
#include <linux/hash.h>
#include <linux/backing-dev.h>
#include <linux/sched.h>
#include <linux/fs_struct.h>
#include <linux/namei.h>
#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/swap.h> /* for mark_page_accessed() */
#include <linux/vmalloc.h>
#include <linux/mutex.h>
#include <asm/current.h>
#include <asm/unaligned.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
#include <linux/aio.h>
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
#error EXFAT only supports linux kernel version 3.0 or higher
#endif
#include "version.h"
#include "config.h"
#include "exfat.h"
#include "core.h"
/* skip iterating emit_dots when dir is empty */
#define ITER_POS_FILLED_DOTS (2)
static struct kset *exfat_kset;
static struct kmem_cache *exfat_inode_cachep;
static DEFINE_MUTEX(_lock_core);
static int exfat_default_codepage = CONFIG_EXFAT_DEFAULT_CODEPAGE;
static char exfat_default_iocharset[] = CONFIG_EXFAT_DEFAULT_IOCHARSET;
static const char exfat_iocharset_with_utf8[] = "iso8859-1";
static void exfat_truncate(struct inode *inode, loff_t old_size);
static int exfat_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create);
static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos);
static struct inode *exfat_build_inode(struct super_block *sb, const FILE_ID_T *fid, loff_t i_pos);
static void exfat_detach(struct inode *inode);
static void exfat_attach(struct inode *inode, loff_t i_pos);
static inline unsigned long exfat_hash(loff_t i_pos);
static s32 __exfat_sync_fs(struct super_block *sb, s32 do_sync);
static int __exfat_write_inode(struct inode *inode, int sync);
static int exfat_sync_inode(struct inode *inode);
static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc);
static void exfat_write_super(struct super_block *sb);
static void exfat_write_failed(struct address_space *mapping, loff_t to);
static void exfat_init_namebuf(DENTRY_NAMEBUF_T *nb);
static int exfat_alloc_namebuf(DENTRY_NAMEBUF_T *nb);
static void exfat_free_namebuf(DENTRY_NAMEBUF_T *nb);
static int __exfat_getattr(struct inode *inode, struct kstat *stat);
static void __exfat_writepage_end_io(struct bio *bio, int err);
static inline void lock_super(struct super_block *sb);
static inline void unlock_super(struct super_block *sb);
static int exfat_create_compat(struct inode *dir, struct dentry *dentry);
static int __exfat_revalidate(struct dentry *dentry);
static int __exfat_revalidate_ci(struct dentry *dentry, unsigned int flags);
static int __exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync);
static struct dentry *__exfat_lookup(struct inode *dir, struct dentry *dentry);
static int __exfat_mkdir(struct inode *dir, struct dentry *dentry);
static int __exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry);
static int __exfat_show_options(struct seq_file *m, struct super_block *sb);
static inline ssize_t __exfat_blkdev_direct_IO(int rw, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
unsigned long nr_segs);
static inline ssize_t __exfat_direct_IO(int rw, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
loff_t count, unsigned long nr_segs);
static int __exfat_d_hash(const struct dentry *dentry, struct qstr *qstr);
static int __exfat_d_hashi(const struct dentry *dentry, struct qstr *qstr);
static int __exfat_cmp(const struct dentry *dentry, unsigned int len,
const char *str, const struct qstr *name);
static int __exfat_cmpi(const struct dentry *dentry, unsigned int len,
const char *str, const struct qstr *name);
/* mount the file system volume */
static s32 exfat_mount(struct super_block *sb)
{
s32 err;
/* acquire the core lock for file system ccritical section */
mutex_lock(&_lock_core);
err = exfat_meta_cache_init(sb);
if (err)
goto out;
err = exfat_fscore_mount(sb);
out:
if (err)
exfat_meta_cache_shutdown(sb);
/* release the core lock for file system critical section */
mutex_unlock(&_lock_core);
return err;
}
/* unmount the file system volume */
static s32 exfat_umount(struct super_block *sb)
{
s32 err;
/* acquire the core lock for file system ccritical section */
mutex_lock(&_lock_core);
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_umount(sb);
exfat_meta_cache_shutdown(sb);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
/* release the core lock for file system critical section */
mutex_unlock(&_lock_core);
return err;
}
static s32 exfat_set_vol_flags(struct super_block *sb, u16 new_flag, s32 always_sync)
{
s32 err;
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_set_vol_flags(sb, new_flag, always_sync);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* read the target string of symlink */
static s32 exfat_read_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *rcount)
{
s32 err;
struct super_block *sb = inode->i_sb;
/* check the validity of pointer parameters */
ASSERT(fid && buffer);
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_read_link(inode, fid, buffer, count, rcount);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* write the target string of symlink */
static s32 exfat_write_link(struct inode *inode, FILE_ID_T *fid, void *buffer, u64 count, u64 *wcount)
{
s32 err;
struct super_block *sb = inode->i_sb;
/* check the validity of pointer parameters */
ASSERT(fid && buffer);
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_write_link(inode, fid, buffer, count, wcount);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* remove a file */
static s32 exfat_remove(struct inode *inode, FILE_ID_T *fid)
{
s32 err;
struct super_block *sb = inode->i_sb;
/* check the validity of pointer parameters */
ASSERT(fid);
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_remove(inode, fid);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* get the information of a given file */
static s32 exfat_read_inode(struct inode *inode, DIR_ENTRY_T *info)
{
s32 err;
struct super_block *sb = inode->i_sb;
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_read_inode(inode, info);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* return the cluster number in the given cluster offset */
static s32 exfat_map_clus(struct inode *inode, u32 clu_offset, u32 *clu, int dest)
{
s32 err;
struct super_block *sb = inode->i_sb;
/* check the validity of pointer parameters */
ASSERT(clu);
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_map_clus(inode, clu_offset, clu, dest);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* read a directory entry from the opened directory */
static s32 __exfat_readdir(struct inode *inode, DIR_ENTRY_T *dir_entry)
{
s32 err;
struct super_block *sb = inode->i_sb;
/* check the validity of pointer parameters */
ASSERT(dir_entry);
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_readdir(inode, dir_entry);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
/* reflect the internal dirty flags to VFS bh dirty flags */
static s32 exfat_cache_flush(struct super_block *sb, int do_sync)
{
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
exfat_fcache_flush(sb, do_sync);
exfat_dcache_flush(sb, do_sync);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return 0;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
/* EMPTY */
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) */
static inline void bio_set_dev(struct bio *bio, struct block_device *bdev)
{
bio->bi_bdev = bdev;
}
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,9,0)
#define current_time(x) CURRENT_TIME_SEC
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
static int exfat_getattr(const struct path *path, struct kstat *stat,
u32 request_mask, unsigned int query_flags)
{
struct inode *inode = d_backing_inode(path->dentry);
return __exfat_getattr(inode, stat);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) */
static int exfat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
{
struct inode *inode = dentry->d_inode;
return __exfat_getattr(inode, stat);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
static inline void __exfat_clean_bdev_aliases(struct block_device *bdev, sector_t block)
{
clean_bdev_aliases(bdev, block, 1);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0) */
static inline void __exfat_clean_bdev_aliases(struct block_device *bdev, sector_t block)
{
unmap_underlying_metadata(bdev, block);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
/*
* The VFS already checks for existence, so for local filesystems
* the RENAME_NOREPLACE implementation is equivalent to plain rename.
* Don't support any other flags
*/
if (flags & ~RENAME_NOREPLACE)
return -EINVAL;
return __exfat_rename(old_dir, old_dentry, new_dir, new_dentry);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) */
static int exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
{
return __exfat_rename(old_dir, old_dentry, new_dir, new_dentry);
}
// setattr_prepare() was backported to several LTS kernels
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 39) && \
LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
#define SETATTR_PREPARE_AVAILABLE
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 37) && \
LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
#define SETATTR_PREPARE_AVAILABLE
#endif
#ifndef SETATTR_PREPARE_AVAILABLE
static int setattr_prepare(struct dentry *dentry, struct iattr *attr)
{
struct inode *inode = dentry->d_inode;
return inode_change_ok(inode, attr);
}
#endif
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
static inline void __exfat_submit_bio_write(struct bio *bio)
{
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
submit_bio(bio);
}
static inline unsigned int __exfat_full_name_hash(const struct dentry *dentry, const char *name, unsigned int len)
{
return full_name_hash(dentry, name, len);
}
static inline unsigned long __exfat_init_name_hash(const struct dentry *dentry)
{
return init_name_hash(dentry);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0) */
static inline void __exfat_submit_bio_write(struct bio *bio)
{
submit_bio(WRITE, bio);
}
static inline unsigned int __exfat_full_name_hash(const struct dentry *unused, const char *name, unsigned int len)
{
return full_name_hash(name, len);
}
static inline unsigned long __exfat_init_name_hash(const struct dentry *unused)
{
return init_name_hash();
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 21)
/* EMPTY */
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 21) */
static inline void inode_lock(struct inode *inode)
{
mutex_lock(&inode->i_mutex);
}
static inline void inode_unlock(struct inode *inode)
{
mutex_unlock(&inode->i_mutex);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
static inline int exfat_remount_syncfs(struct super_block *sb)
{
sync_filesystem(sb);
return 0;
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) */
static inline int exfat_remount_syncfs(struct super_block *sb)
{
/*
* We don`t need to call sync_filesystem(sb),
* Because VFS calls it.
*/
return 0;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
static inline sector_t __exfat_bio_sector(struct bio *bio)
{
return bio->bi_iter.bi_sector;
}
static inline void __exfat_set_bio_iterate(struct bio *bio, sector_t sector,
unsigned int size, unsigned int idx, unsigned int done)
{
struct bvec_iter *iter = &(bio->bi_iter);
iter->bi_sector = sector;
iter->bi_size = size;
iter->bi_idx = idx;
iter->bi_bvec_done = done;
}
static void __exfat_truncate_pagecache(struct inode *inode,
loff_t to, loff_t newsize)
{
truncate_pagecache(inode, newsize);
}
static int exfat_d_hash(const struct dentry *dentry, struct qstr *qstr)
{
return __exfat_d_hash(dentry, qstr);
}
static int exfat_d_hashi(const struct dentry *dentry, struct qstr *qstr)
{
return __exfat_d_hashi(dentry, qstr);
}
//instead of exfat_readdir
static int exfat_iterate(struct file *filp, struct dir_context *ctx)
{
struct inode *inode = filp->f_path.dentry->d_inode;
struct super_block *sb = inode->i_sb;
DIR_ENTRY_T de;
DENTRY_NAMEBUF_T *nb = &(de.NameBuf);
unsigned long inum;
loff_t cpos;
int err = 0, fake_offset = 0;
exfat_init_namebuf(nb);
lock_super(sb);
cpos = ctx->pos;
if (!dir_emit_dots(filp, ctx))
goto out;
if (ctx->pos == ITER_POS_FILLED_DOTS) {
cpos = 0;
fake_offset = 1;
}
if (cpos & (DENTRY_SIZE - 1)) {
err = -ENOENT;
goto out;
}
/* name buffer should be allocated before use */
err = exfat_alloc_namebuf(nb);
if (err)
goto out;
get_new:
EXFAT_I(inode)->fid.size = i_size_read(inode);
EXFAT_I(inode)->fid.rwoffset = cpos >> DENTRY_SIZE_BITS;
if (cpos >= EXFAT_I(inode)->fid.size)
goto end_of_dir;
err = __exfat_readdir(inode, &de);
if (err) {
// at least we tried to read a sector
// move cpos to next sector position (should be aligned)
if (err == -EIO) {
cpos += 1 << (sb->s_blocksize_bits);
cpos &= ~((u32)sb->s_blocksize-1);
}
err = -EIO;
goto end_of_dir;
}
cpos = EXFAT_I(inode)->fid.rwoffset << DENTRY_SIZE_BITS;
if (!nb->lfn[0])
goto end_of_dir;
if (!memcmp(nb->sfn, DOS_CUR_DIR_NAME, DOS_NAME_LENGTH)) {
inum = inode->i_ino;
} else if (!memcmp(nb->sfn, DOS_PAR_DIR_NAME, DOS_NAME_LENGTH)) {
inum = parent_ino(filp->f_path.dentry);
} else {
loff_t i_pos = ((loff_t) EXFAT_I(inode)->fid.start_clu << 32) |
((EXFAT_I(inode)->fid.rwoffset-1) & 0xffffffff);
struct inode *tmp = exfat_iget(sb, i_pos);
if (tmp) {
inum = tmp->i_ino;
iput(tmp);
} else {
inum = iunique(sb, EXFAT_ROOT_INO);
}
}
/* Before calling dir_emit(), sb_lock should be released.
* Because page fault can occur in dir_emit() when the size of buffer given
* from user is larger than one page size
*/
unlock_super(sb);
if (!dir_emit(ctx, nb->lfn, strlen(nb->lfn), inum,
(de.Attr & ATTR_SUBDIR) ? DT_DIR : DT_REG))
goto out_unlocked;
lock_super(sb);
ctx->pos = cpos;
goto get_new;
end_of_dir:
if (!cpos && fake_offset)
cpos = ITER_POS_FILLED_DOTS;
ctx->pos = cpos;
out:
unlock_super(sb);
out_unlocked:
/*
* To improve performance, free namebuf after unlock sb_lock.
* If namebuf is not allocated, this function do nothing
*/
exfat_free_namebuf(nb);
return err;
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) */
static inline sector_t __exfat_bio_sector(struct bio *bio)
{
return bio->bi_sector;
}
static inline void __exfat_set_bio_iterate(struct bio *bio, sector_t sector,
unsigned int size, unsigned int idx, unsigned int done)
{
bio->bi_sector = sector;
bio->bi_idx = idx;
bio->bi_size = size; //PAGE_SIZE;
}
static void __exfat_truncate_pagecache(struct inode *inode,
loff_t to, loff_t newsize)
{
truncate_pagecache(inode, to, newsize);
}
static int exfat_d_hash(const struct dentry *dentry,
const struct inode *inode, struct qstr *qstr)
{
return __exfat_d_hash(dentry, qstr);
}
static int exfat_d_hashi(const struct dentry *dentry,
const struct inode *inode, struct qstr *qstr)
{
return __exfat_d_hashi(dentry, qstr);
}
static int exfat_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
struct inode *inode = filp->f_path.dentry->d_inode;
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi);
DIR_ENTRY_T de;
DENTRY_NAMEBUF_T *nb = &(de.NameBuf);
unsigned long inum;
loff_t cpos;
int err = 0, fake_offset = 0;
exfat_init_namebuf(nb);
lock_super(sb);
cpos = filp->f_pos;
/* Fake . and .. for the root directory. */
while (cpos < ITER_POS_FILLED_DOTS) {
if (inode->i_ino == EXFAT_ROOT_INO)
inum = EXFAT_ROOT_INO;
else if (cpos == 0)
inum = inode->i_ino;
else /* (cpos == 1) */
inum = parent_ino(filp->f_path.dentry);
if (filldir(dirent, "..", cpos+1, cpos, inum, DT_DIR) < 0)
goto out;
cpos++;
filp->f_pos++;
}
if (cpos == ITER_POS_FILLED_DOTS) {
cpos = 0;
fake_offset = 1;
}
if (cpos & (DENTRY_SIZE - 1)) {
err = -ENOENT;
goto out;
}
/* name buffer should be allocated before use */
err = exfat_alloc_namebuf(nb);
if (err)
goto out;
get_new:
EXFAT_I(inode)->fid.size = i_size_read(inode);
EXFAT_I(inode)->fid.rwoffset = cpos >> DENTRY_SIZE_BITS;
if (cpos >= EXFAT_I(inode)->fid.size)
goto end_of_dir;
err = __exfat_readdir(inode, &de);
if (err) {
// at least we tried to read a sector
// move cpos to next sector position (should be aligned)
if (err == -EIO) {
cpos += 1 << (sb->s_blocksize_bits);
cpos &= ~((u32)sb->s_blocksize-1);
}
err = -EIO;
goto end_of_dir;
}
cpos = EXFAT_I(inode)->fid.rwoffset << DENTRY_SIZE_BITS;
if (!nb->lfn[0])
goto end_of_dir;
if (!memcmp(nb->sfn, DOS_CUR_DIR_NAME, DOS_NAME_LENGTH)) {
inum = inode->i_ino;
} else if (!memcmp(nb->sfn, DOS_PAR_DIR_NAME, DOS_NAME_LENGTH)) {
inum = parent_ino(filp->f_path.dentry);
} else {
loff_t i_pos = ((loff_t) EXFAT_I(inode)->fid.start_clu << 32) |
((EXFAT_I(inode)->fid.rwoffset-1) & 0xffffffff);
struct inode *tmp = exfat_iget(sb, i_pos);
if (tmp) {
inum = tmp->i_ino;
iput(tmp);
} else {
inum = iunique(sb, EXFAT_ROOT_INO);
}
}
/* Before calling dir_emit(), sb_lock should be released.
* Because page fault can occur in dir_emit() when the size of buffer given
* from user is larger than one page size
*/
unlock_super(sb);
if (filldir(dirent, nb->lfn, strlen(nb->lfn), cpos, inum,
(de.Attr & ATTR_SUBDIR) ? DT_DIR : DT_REG) < 0)
goto out_unlocked;
lock_super(sb);
filp->f_pos = cpos;
goto get_new;
end_of_dir:
if (!cpos && fake_offset)
cpos = ITER_POS_FILLED_DOTS;
filp->f_pos = cpos;
out:
unlock_super(sb);
out_unlocked:
/*
* To improve performance, free namebuf after unlock sb_lock.
* If namebuf is not allocated, this function do nothing
*/
exfat_free_namebuf(nb);
return err;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
/* EMPTY */
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) */
static inline struct inode *file_inode(const struct file *f)
{
return f->f_dentry->d_inode;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
static inline int __is_sb_dirty(struct super_block *sb)
{
return EXFAT_SB(sb)->s_dirt;
}
static inline void __set_sb_clean(struct super_block *sb)
{
EXFAT_SB(sb)->s_dirt = 0;
}
/* Workqueue wrapper for exfat_write_super () */
static void __write_super_delayed(struct work_struct *work)
{
struct exfat_sb_info *sbi;
struct super_block *sb;
sbi = container_of(work, struct exfat_sb_info, write_super_work.work);
sb = sbi->host_sb;
/* XXX: Is this needed? */
if (!sb || !down_read_trylock(&sb->s_umount)) {
DMSG("%s: skip delayed work(write_super).\n", __func__);
return;
}
DMSG("%s: do delayed_work(write_super).\n", __func__);
spin_lock(&sbi->work_lock);
sbi->write_super_queued = 0;
spin_unlock(&sbi->work_lock);
exfat_write_super(sb);
up_read(&sb->s_umount);
}
static void setup_exfat_sync_super_wq(struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
mutex_init(&sbi->s_lock);
spin_lock_init(&sbi->work_lock);
INIT_DELAYED_WORK(&sbi->write_super_work, __write_super_delayed);
sbi->host_sb = sb;
}
static inline bool __cancel_delayed_work_sync(struct exfat_sb_info *sbi)
{
return cancel_delayed_work_sync(&sbi->write_super_work);
}
static inline void lock_super(struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
mutex_lock(&sbi->s_lock);
}
static inline void unlock_super(struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
mutex_unlock(&sbi->s_lock);
}
static int exfat_revalidate(struct dentry *dentry, unsigned int flags)
{
if (flags & LOOKUP_RCU)
return -ECHILD;
return __exfat_revalidate(dentry);
}
static int exfat_revalidate_ci(struct dentry *dentry, unsigned int flags)
{
if (flags & LOOKUP_RCU)
return -ECHILD;
return __exfat_revalidate_ci(dentry, flags);
}
static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *info;
struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
struct inode *inode = NULL;
spin_lock(&sbi->inode_hash_lock);
hlist_for_each_entry(info, head, i_hash_fat) {
BUG_ON(info->vfs_inode.i_sb != sb);
if (i_pos != info->i_pos)
continue;
inode = igrab(&info->vfs_inode);
if (inode)
break;
}
spin_unlock(&sbi->inode_hash_lock);
return inode;
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) */
static inline int __is_sb_dirty(struct super_block *sb)
{
return sb->s_dirt;
}
static inline void __set_sb_clean(struct super_block *sb)
{
sb->s_dirt = 0;
}
static void setup_exfat_sync_super_wq(struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
sbi->host_sb = sb;
}
static inline bool __cancel_delayed_work_sync(struct exfat_sb_info *sbi)
{
/* DO NOTHING */
return 0;
}
static inline void clear_inode(struct inode *inode)
{
end_writeback(inode);
}
static int exfat_revalidate(struct dentry *dentry, struct nameidata *nd)
{
if (nd && nd->flags & LOOKUP_RCU)
return -ECHILD;
return __exfat_revalidate(dentry);
}
static int exfat_revalidate_ci(struct dentry *dentry, struct nameidata *nd)
{
if (nd && nd->flags & LOOKUP_RCU)
return -ECHILD;
return __exfat_revalidate_ci(dentry, nd ? nd->flags : 0);
}
static struct inode *exfat_iget(struct super_block *sb, loff_t i_pos)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_inode_info *info;
struct hlist_node *node;
struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
struct inode *inode = NULL;
spin_lock(&sbi->inode_hash_lock);
hlist_for_each_entry(info, node, head, i_hash_fat) {
BUG_ON(info->vfs_inode.i_sb != sb);
if (i_pos != info->i_pos)
continue;
inode = igrab(&info->vfs_inode);
if (inode)
break;
}
spin_unlock(&sbi->inode_hash_lock);
return inode;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags)
{
return __exfat_lookup(dir, dentry);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0) */
static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry,
struct nameidata *nd)
{
return __exfat_lookup(dir, dentry);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
/* NOTHING NOW */
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 5, 0) */
#define GLOBAL_ROOT_UID (0)
#define GLOBAL_ROOT_GID (0)
static inline bool uid_eq(uid_t left, uid_t right)
{
return left == right;
}
static inline bool gid_eq(gid_t left, gid_t right)
{
return left == right;
}
static inline uid_t from_kuid_munged(struct user_namespace *to, uid_t kuid)
{
return kuid;
}
static inline gid_t from_kgid_munged(struct user_namespace *to, gid_t kgid)
{
return kgid;
}
static inline uid_t make_kuid(struct user_namespace *from, uid_t uid)
{
return uid;
}
static inline gid_t make_kgid(struct user_namespace *from, gid_t gid)
{
return gid;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
static struct dentry *__d_make_root(struct inode *root_inode)
{
return d_make_root(root_inode);
}
static void __exfat_do_truncate(struct inode *inode, loff_t old, loff_t new)
{
down_write(&EXFAT_I(inode)->truncate_lock);
truncate_setsize(inode, new);
exfat_truncate(inode, old);
up_write(&EXFAT_I(inode)->truncate_lock);
}
static sector_t exfat_aop_bmap(struct address_space *mapping, sector_t block)
{
sector_t blocknr;
/* exfat_get_cluster() assumes the requested blocknr isn't truncated. */
down_read(&EXFAT_I(mapping->host)->truncate_lock);
blocknr = generic_block_bmap(mapping, block, exfat_get_block);
up_read(&EXFAT_I(mapping->host)->truncate_lock);
return blocknr;
}
static int exfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
return __exfat_mkdir(dir, dentry);
}
static int exfat_show_options(struct seq_file *m, struct dentry *root)
{
return __exfat_show_options(m, root->d_sb);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) */
static inline void set_nlink(struct inode *inode, unsigned int nlink)
{
inode->i_nlink = nlink;
}
static struct dentry *__d_make_root(struct inode *root_inode)
{
return d_alloc_root(root_inode);
}
static void __exfat_do_truncate(struct inode *inode, loff_t old, loff_t new)
{
truncate_setsize(inode, new);
exfat_truncate(inode, old);
}
static sector_t exfat_aop_bmap(struct address_space *mapping, sector_t block)
{
sector_t blocknr;
/* exfat_get_cluster() assumes the requested blocknr isn't truncated. */
down_read(&mapping->host->i_alloc_sem);
blocknr = generic_block_bmap(mapping, block, exfat_get_block);
up_read(&mapping->host->i_alloc_sem);
return blocknr;
}
static int exfat_mkdir(struct inode *dir, struct dentry *dentry, int mode)
{
return __exfat_mkdir(dir, dentry);
}
static int exfat_show_options(struct seq_file *m, struct vfsmount *mnt)
{
return __exfat_show_options(m, mnt->mnt_sb);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
#define __exfat_generic_file_fsync(filp, start, end, datasync) \
generic_file_fsync(filp, start, end, datasync)
static int exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
{
return __exfat_file_fsync(filp, start, end, datasync);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) */
#define __exfat_generic_file_fsync(filp, start, end, datasync) \
generic_file_fsync(filp, datasync)
static int exfat_file_fsync(struct file *filp, int datasync)
{
return __exfat_file_fsync(filp, 0, 0, datasync);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
static void exfat_writepage_end_io(struct bio *bio)
{
__exfat_writepage_end_io(bio, blk_status_to_errno(bio->bi_status));
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
static void exfat_writepage_end_io(struct bio *bio)
{
__exfat_writepage_end_io(bio, bio->bi_error);
}
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) */
static void exfat_writepage_end_io(struct bio *bio, int err)
{
if (test_bit(BIO_UPTODATE, &bio->bi_flags))
err = 0;
__exfat_writepage_end_io(bio, err);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
static int exfat_cmp(const struct dentry *dentry,
unsigned int len, const char *str, const struct qstr *name)
{
return __exfat_cmp(dentry, len, str, name);
}
static int exfat_cmpi(const struct dentry *dentry,
unsigned int len, const char *str, const struct qstr *name)
{
return __exfat_cmpi(dentry, len, str, name);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
static int exfat_cmp(const struct dentry *parent, const struct dentry *dentry,
unsigned int len, const char *str, const struct qstr *name)
{
return __exfat_cmp(dentry, len, str, name);
}
static int exfat_cmpi(const struct dentry *parent, const struct dentry *dentry,
unsigned int len, const char *str, const struct qstr *name)
{
return __exfat_cmpi(dentry, len, str, name);
}
#else
static int exfat_cmp(const struct dentry *parent, const struct inode *pinode,
const struct dentry *dentry, const struct inode *inode,
unsigned int len, const char *str, const struct qstr *name)
{
return __exfat_cmp(dentry, len, str, name);
}
static int exfat_cmpi(const struct dentry *parent, const struct inode *pinode,
const struct dentry *dentry, const struct inode *inode,
unsigned int len, const char *str, const struct qstr *name)
{
return __exfat_cmpi(dentry, len, str, name);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
static ssize_t exfat_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
{
struct file *file = iocb->ki_filp;
struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host;
size_t count = iov_iter_count(iter);
int rw = iov_iter_rw(iter);
loff_t offset = iocb->ki_pos;
return __exfat_direct_IO(rw, iocb, inode,
(void *)iter, offset, count, 0 /* UNUSED */);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
static ssize_t exfat_direct_IO(struct kiocb *iocb,
struct iov_iter *iter,
loff_t offset)
{
struct file *file = iocb->ki_filp;
struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host;
size_t count = iov_iter_count(iter);
int rw = iov_iter_rw(iter);
return __exfat_direct_IO(rw, iocb, inode,
(void *)iter, offset, count, 0 /* UNUSED */);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
static ssize_t exfat_direct_IO(int rw, struct kiocb *iocb,
struct iov_iter *iter,
loff_t offset)
{
struct file *file = iocb->ki_filp;
struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host;
size_t count = iov_iter_count(iter);
return __exfat_direct_IO(rw, iocb, inode,
(void *)iter, offset, count, 0 /* UNUSED */);
}
#else
static ssize_t exfat_direct_IO(int rw, struct kiocb *iocb,
const struct iovec *iov, loff_t offset, unsigned long nr_segs)
{
struct file *file = iocb->ki_filp;
struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host;
size_t count = iov_length(iov, nr_segs);
return __exfat_direct_IO(rw, iocb, inode,
(void *)iov, offset, count, nr_segs);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
static inline ssize_t __exfat_blkdev_direct_IO(int unused, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t unused_1,
unsigned long nr_segs)
{
struct iov_iter *iter = (struct iov_iter *)iov_u;
return blockdev_direct_IO(iocb, inode, iter, exfat_get_block);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
static inline ssize_t __exfat_blkdev_direct_IO(int unused, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
unsigned long nr_segs)
{
struct iov_iter *iter = (struct iov_iter *)iov_u;
return blockdev_direct_IO(iocb, inode, iter, offset, exfat_get_block);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
static inline ssize_t __exfat_blkdev_direct_IO(int rw, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
unsigned long nr_segs)
{
struct iov_iter *iter = (struct iov_iter *)iov_u;
return blockdev_direct_IO(rw, iocb, inode, iter,
offset, exfat_get_block);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
static inline ssize_t __exfat_blkdev_direct_IO(int rw, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
unsigned long nr_segs)
{
const struct iovec *iov = (const struct iovec *)iov_u;
return blockdev_direct_IO(rw, iocb, inode, iov,
offset, nr_segs, exfat_get_block);
}
#else
static inline ssize_t __exfat_blkdev_direct_IO(int rw, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
unsigned long nr_segs)
{
const struct iovec *iov = (const struct iovec *)iov_u;
return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
offset, nr_segs, exfat_get_block, NULL);
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
static const char *exfat_follow_link(struct dentry *dentry, struct inode *inode, struct delayed_call *done)
{
struct exfat_inode_info *ei = EXFAT_I(inode);
return (char *)(ei->target);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
static const char *exfat_follow_link(struct dentry *dentry, void **cookie)
{
struct exfat_inode_info *ei = EXFAT_I(dentry->d_inode);
return *cookie = (char *)(ei->target);
}
#else
static void *exfat_follow_link(struct dentry *dentry, struct nameidata *nd)
{
struct exfat_inode_info *ei = EXFAT_I(dentry->d_inode);
nd_set_link(nd, (char *)(ei->target));
return NULL;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
bool excl)
{
return exfat_create_compat(dir, dentry);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
static int exfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
struct nameidata *nd)
{
return exfat_create_compat(dir, dentry);
}
#else
static int exfat_create(struct inode *dir, struct dentry *dentry, int mode,
struct nameidata *nd)
{
return exfat_create_compat(dir, dentry);
}
#endif
static inline loff_t exfat_make_i_pos(FILE_ID_T *fid)
{
return ((loff_t) fid->dir.dir << 32) | (fid->entry & 0xffffffff);
}
static void exfat_init_namebuf(DENTRY_NAMEBUF_T *nb)
{
nb->lfn = NULL;
nb->sfn = NULL;
nb->lfnbuf_len = 0;
nb->sfnbuf_len = 0;
}
static int exfat_alloc_namebuf(DENTRY_NAMEBUF_T *nb)
{
nb->lfn = __getname();
if (!nb->lfn)
return -ENOMEM;
nb->sfn = nb->lfn + MAX_VFSNAME_BUF_SIZE;
nb->lfnbuf_len = MAX_VFSNAME_BUF_SIZE;
nb->sfnbuf_len = MAX_VFSNAME_BUF_SIZE;
return 0;
}
static void exfat_free_namebuf(DENTRY_NAMEBUF_T *nb)
{
if (!nb->lfn)
return;
__putname(nb->lfn);
exfat_init_namebuf(nb);
}
#define EXFAT_DSTATE_LOCKED (void *)(0xCAFE2016)
#define EXFAT_DSTATE_UNLOCKED (void *)(0x00000000)
static inline void __lock_d_revalidate(struct dentry *dentry)
{
spin_lock(&dentry->d_lock);
dentry->d_fsdata = EXFAT_DSTATE_LOCKED;
spin_unlock(&dentry->d_lock);
}
static inline void __unlock_d_revalidate(struct dentry *dentry)
{
spin_lock(&dentry->d_lock);
dentry->d_fsdata = EXFAT_DSTATE_UNLOCKED;
spin_unlock(&dentry->d_lock);
}
/* __check_dstate_locked requires dentry->d_lock */
static inline int __check_dstate_locked(struct dentry *dentry)
{
if (dentry->d_fsdata == EXFAT_DSTATE_LOCKED)
return 1;
return 0;
}
/*
* If new entry was created in the parent, it could create the 8.3
* alias (the shortname of logname). So, the parent may have the
* negative-dentry which matches the created 8.3 alias.
*
* If it happened, the negative dentry isn't actually negative
* anymore. So, drop it.
*/
static int __exfat_revalidate_common(struct dentry *dentry)
{
int ret = 1;
spin_lock(&dentry->d_lock);
if ((!dentry->d_inode) && (!__check_dstate_locked(dentry) &&
(dentry->d_time != GET_IVERSION(dentry->d_parent->d_inode)))) {
ret = 0;
}
spin_unlock(&dentry->d_lock);
return ret;
}
static int __exfat_revalidate(struct dentry *dentry)
{
/* This is not negative dentry. Always valid. */
if (dentry->d_inode)
return 1;
return __exfat_revalidate_common(dentry);
}
static int __exfat_revalidate_ci(struct dentry *dentry, unsigned int flags)
{
/*
* This is not negative dentry. Always valid.
*
* Note, rename() to existing directory entry will have ->d_inode,
* and will use existing name which isn't specified name by user.
*
* We may be able to drop this positive dentry here. But dropping
* positive dentry isn't good idea. So it's unsupported like
* rename("filename", "FILENAME") for now.
*/
if (dentry->d_inode)
return 1;
#if 0 /* Blocked below code for lookup_one_len() called by stackable FS */
/*
* This may be nfsd (or something), anyway, we can't see the
* intent of this. So, since this can be for creation, drop it.
*/
if (!flags)
return 0;
#endif
/*
* Drop the negative dentry, in order to make sure to use the
* case sensitive name which is specified by user if this is
* for creation.
*/
if (flags & (LOOKUP_CREATE | LOOKUP_RENAME_TARGET))
return 0;
return __exfat_revalidate_common(dentry);
}
/* returns the length of a struct qstr, ignoring trailing dots */
static unsigned int __exfat_striptail_len(unsigned int len, const char *name)
{
while (len && name[len - 1] == '.')
len--;
return len;
}
static unsigned int exfat_striptail_len(const struct qstr *qstr)
{
return __exfat_striptail_len(qstr->len, qstr->name);
}
/*
* Compute the hash for the exfat name corresponding to the dentry.
* Note: if the name is invalid, we leave the hash code unchanged so
* that the existing dentry can be used. The exfat fs routines will
* return ENOENT or EINVAL as appropriate.
*/
static int __exfat_d_hash(const struct dentry *dentry, struct qstr *qstr)
{
unsigned int len = exfat_striptail_len(qstr);
qstr->hash = __exfat_full_name_hash(dentry, qstr->name, len);
return 0;
}
/*
* Compute the hash for the exfat name corresponding to the dentry.
* Note: if the name is invalid, we leave the hash code unchanged so
* that the existing dentry can be used. The exfat fs routines will
* return ENOENT or EINVAL as appropriate.
*/
static int __exfat_d_hashi(const struct dentry *dentry, struct qstr *qstr)
{
struct nls_table *t = EXFAT_SB(dentry->d_sb)->nls_io;
const unsigned char *name;
unsigned int len;
unsigned long hash;
name = qstr->name;
len = exfat_striptail_len(qstr);
hash = __exfat_init_name_hash(dentry);
while (len--)
hash = partial_name_hash(nls_tolower(t, *name++), hash);
qstr->hash = end_name_hash(hash);
return 0;
}
/*
* Case sensitive compare of two exfat names.
*/
static int __exfat_cmp(const struct dentry *dentry, unsigned int len,
const char *str, const struct qstr *name)
{
unsigned int alen, blen;
/* A filename cannot end in '.' or we treat it like it has none */
alen = exfat_striptail_len(name);
blen = __exfat_striptail_len(len, str);
if (alen == blen) {
if (strncmp(name->name, str, alen) == 0)
return 0;
}
return 1;
}
/*
* Case insensitive compare of two exfat names.
*/
static int __exfat_cmpi(const struct dentry *dentry, unsigned int len,
const char *str, const struct qstr *name)
{
struct nls_table *t = EXFAT_SB(dentry->d_sb)->nls_io;
unsigned int alen, blen;
/* A filename cannot end in '.' or we treat it like it has none */
alen = exfat_striptail_len(name);
blen = __exfat_striptail_len(len, str);
if (alen == blen) {
if (nls_strnicmp(t, name->name, str, alen) == 0)
return 0;
}
return 1;
}
static const struct dentry_operations exfat_dentry_ops = {
.d_revalidate = exfat_revalidate,
.d_hash = exfat_d_hash,
.d_compare = exfat_cmp,
};
static const struct dentry_operations exfat_ci_dentry_ops = {
.d_revalidate = exfat_revalidate_ci,
.d_hash = exfat_d_hashi,
.d_compare = exfat_cmpi,
};
static int exfat_file_mmap(struct file *file, struct vm_area_struct *vm_struct)
{
return generic_file_mmap(file, vm_struct);
}
static int exfat_ioctl_volume_id(struct inode *dir)
{
struct exfat_sb_info *sbi = EXFAT_SB(dir->i_sb);
FS_INFO_T *fsi = &(sbi->fsi);
return fsi->vol_id;
}
static long exfat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
struct inode *inode = file_inode(filp);
if (cmd != EXFAT_IOCTL_GET_VOLUME_ID)
return -ENOTSUPP;
return exfat_ioctl_volume_id(inode);
}
static int __exfat_getattr(struct inode *inode, struct kstat *stat)
{
generic_fillattr(inode, stat);
stat->blksize = EXFAT_SB(inode->i_sb)->fsi.cluster_size;
return 0;
}
static void __exfat_writepage_end_io(struct bio *bio, int err)
{
struct page *page = bio->bi_io_vec->bv_page;
struct super_block *sb = page->mapping->host->i_sb;
ASSERT(bio->bi_vcnt == 1); /* Single page endio */
ASSERT(bio_data_dir(bio)); /* Write */
if (err) {
SetPageError(page);
mapping_set_error(page->mapping, err);
}
end_page_writeback(page);
bio_put(bio);
// Update trace info.
atomic_dec(&EXFAT_SB(sb)->stat_n_pages_queued);
}
static int __exfat_file_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
{
return __exfat_generic_file_fsync(filp, start, end, datasync);
}
static const struct file_operations exfat_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
.iterate = exfat_iterate,
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) */
.readdir = exfat_readdir,
#endif
.fsync = exfat_file_fsync,
.unlocked_ioctl = exfat_generic_ioctl,
};
/* create a file */
static s32 __exfat_create(struct inode *inode, u8 *path, u8 mode, FILE_ID_T *fid)
{
s32 err;
struct super_block *sb = inode->i_sb;
/* check the validity of pointer parameters */
ASSERT(fid && path);
if (unlikely(!strlen(path)))
return -EINVAL;
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_create(inode, path, mode, fid);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
static int exfat_create_compat(struct inode *dir, struct dentry *dentry)
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
FILE_ID_T fid;
loff_t i_pos;
int err;
lock_super(sb);
err = __exfat_create(dir, (u8 *) dentry->d_name.name, FM_REGULAR, &fid);
if (err)
goto out;
__lock_d_revalidate(dentry);
INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
i_pos = exfat_make_i_pos(&fid);
inode = exfat_build_inode(sb, &fid, i_pos);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
goto out;
}
INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
d_instantiate(dentry, inode);
out:
__unlock_d_revalidate(dentry);
unlock_super(sb);
return err;
}
static int exfat_find(struct inode *dir, struct qstr *qname, FILE_ID_T *fid)
{
struct super_block *sb = dir->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
u8 *path = (u8 *)qname->name;
int err;
if (qname->len == 0)
return -ENOENT;
/* check the validity of pointer parameters */
ASSERT(fid && path);
if (unlikely(!strlen(path)))
return -EINVAL;
mutex_lock(&(sbi->s_vlock));
err = exfat_fscore_lookup(dir, path, fid);
mutex_unlock(&(sbi->s_vlock));
if (err)
return -ENOENT;
return 0;
}
static int exfat_d_anon_disconn(struct dentry *dentry)
{
return IS_ROOT(dentry) && (dentry->d_flags & DCACHE_DISCONNECTED);
}
static struct dentry *__exfat_lookup(struct inode *dir, struct dentry *dentry)
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
struct dentry *alias;
int err;
FILE_ID_T fid;
loff_t i_pos;
u64 ret;
mode_t i_mode;
lock_super(sb);
err = exfat_find(dir, &dentry->d_name, &fid);
if (err) {
if (err == -ENOENT) {
inode = NULL;
goto out;
}
goto error;
}
i_pos = exfat_make_i_pos(&fid);
inode = exfat_build_inode(sb, &fid, i_pos);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
goto error;
}
i_mode = inode->i_mode;
if (S_ISLNK(i_mode) && !EXFAT_I(inode)->target) {
EXFAT_I(inode)->target = kmalloc((i_size_read(inode)+1), GFP_KERNEL);
if (!EXFAT_I(inode)->target) {
err = -ENOMEM;
goto error;
}
exfat_read_link(dir, &fid, EXFAT_I(inode)->target, i_size_read(inode), &ret);
*(EXFAT_I(inode)->target + i_size_read(inode)) = '\0';
}
alias = d_find_alias(inode);
/*
* Checking "alias->d_parent == dentry->d_parent" to make sure
* FS is not corrupted (especially double linked dir).
*/
if (alias && alias->d_parent == dentry->d_parent &&
!exfat_d_anon_disconn(alias)) {
/*
* Unhashed alias is able to exist because of revalidate()
* called by lookup_fast. You can easily make this status
* by calling create and lookup concurrently
* In such case, we reuse an alias instead of new dentry
*/
if (d_unhashed(alias)) {
exfat_msg(sb, KERN_INFO, "rehashed a dentry(%p) "
"in read lookup", alias);
d_drop(dentry);
d_rehash(alias);
} else if (!S_ISDIR(i_mode)) {
/*
* This inode has non anonymous-DCACHE_DISCONNECTED
* dentry. This means, the user did ->lookup() by an
* another name (longname vs 8.3 alias of it) in past.
*
* Switch to new one for reason of locality if possible.
*/
d_move(alias, dentry);
}
iput(inode);
unlock_super(sb);
return alias;
}
dput(alias);
out:
/* initialize d_time even though it is positive dentry */
dentry->d_time = GET_IVERSION(dir);
unlock_super(sb);
dentry = d_splice_alias(inode, dentry);
return dentry;
error:
unlock_super(sb);
return ERR_PTR(err);
}
static int exfat_unlink(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
struct super_block *sb = dir->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FILE_ID_T *fid = &(EXFAT_I(inode)->fid);
int err;
lock_super(sb);
EXFAT_I(inode)->fid.size = i_size_read(inode);
/* check the validity of pointer parameters */
ASSERT(fid);
mutex_lock(&(sbi->s_vlock));
err = exfat_fscore_unlink(dir, fid);
mutex_unlock(&(sbi->s_vlock));
if (err)
goto out;
__lock_d_revalidate(dentry);
INC_IVERSION(dir);
dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
clear_nlink(inode);
inode->i_mtime = inode->i_atime = current_time(inode);
exfat_detach(inode);
dentry->d_time = GET_IVERSION(dir);
out:
__unlock_d_revalidate(dentry);
unlock_super(sb);
return err;
}
static int exfat_symlink(struct inode *dir, struct dentry *dentry, const char *target)
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
FILE_ID_T fid;
loff_t i_pos;
int err;
u64 len = (u64) strlen(target);
u64 ret;
/* symlink option check */
if (!EXFAT_SB(sb)->options.symlink)
return -ENOTSUPP;
lock_super(sb);
err = __exfat_create(dir, (u8 *) dentry->d_name.name, FM_SYMLINK, &fid);
if (err)
goto out;
err = exfat_write_link(dir, &fid, (char *) target, len, &ret);
if (err) {
exfat_remove(dir, &fid);
goto out;
}
__lock_d_revalidate(dentry);
INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
i_pos = exfat_make_i_pos(&fid);
inode = exfat_build_inode(sb, &fid, i_pos);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
goto out;
}
INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
EXFAT_I(inode)->target = kmemdup(target, len + 1, GFP_KERNEL);
if (!EXFAT_I(inode)->target) {
err = -ENOMEM;
goto out;
}
d_instantiate(dentry, inode);
out:
__unlock_d_revalidate(dentry);
unlock_super(sb);
return err;
}
static int __exfat_mkdir(struct inode *dir, struct dentry *dentry)
{
struct super_block *sb = dir->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct inode *inode;
FILE_ID_T fid;
loff_t i_pos;
u8 *path;
int err;
lock_super(sb);
path = (u8 *) dentry->d_name.name;
/* check the validity of pointer parameters */
ASSERT(path);
if (unlikely(!strlen(path))) {
err = -EINVAL;
goto out;
}
mutex_lock(&(sbi->s_vlock));
err = exfat_fscore_mkdir(dir, path, &fid);
mutex_unlock(&(sbi->s_vlock));
if (err)
goto out;
__lock_d_revalidate(dentry);
INC_IVERSION(dir);
dir->i_ctime = dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
inc_nlink(dir);
i_pos = exfat_make_i_pos(&fid);
inode = exfat_build_inode(sb, &fid, i_pos);
if (IS_ERR(inode)) {
err = PTR_ERR(inode);
goto out;
}
INC_IVERSION(inode);
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
/* timestamp is already written, so mark_inode_dirty() is unneeded. */
d_instantiate(dentry, inode);
out:
__unlock_d_revalidate(dentry);
unlock_super(sb);
return err;
}
static int exfat_rmdir(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
struct super_block *sb = dir->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FILE_ID_T *fid = &(EXFAT_I(inode)->fid);
int err;
lock_super(sb);
EXFAT_I(inode)->fid.size = i_size_read(inode);
/* check the validity of pointer parameters */
ASSERT(fid);
mutex_lock(&(sbi->s_vlock));
err = exfat_fscore_rmdir(inode, fid);
mutex_unlock(&(sbi->s_vlock));
if (err)
goto out;
__lock_d_revalidate(dentry);
INC_IVERSION(dir);
dir->i_mtime = dir->i_atime = current_time(dir);
if (IS_DIRSYNC(dir))
(void) exfat_sync_inode(dir);
else
mark_inode_dirty(dir);
drop_nlink(dir);
clear_nlink(inode);
inode->i_mtime = inode->i_atime = current_time(inode);
exfat_detach(inode);
dentry->d_time = GET_IVERSION(dir);
out:
__unlock_d_revalidate(dentry);
unlock_super(sb);
return err;
}
static int __exfat_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
{
struct inode *old_inode, *new_inode;
struct super_block *sb = old_dir->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
loff_t i_pos;
int err;
lock_super(sb);
old_inode = old_dentry->d_inode;
new_inode = new_dentry->d_inode;
EXFAT_I(old_inode)->fid.size = i_size_read(old_inode);
/* check the validity of pointer parameters */
ASSERT(&(EXFAT_I(old_inode)->fid));
mutex_lock(&(sbi->s_vlock));
err = exfat_fscore_rename(old_dir, &(EXFAT_I(old_inode)->fid),
new_dir, new_dentry);
mutex_unlock(&(sbi->s_vlock));
if (err)
goto out;
__lock_d_revalidate(old_dentry);
__lock_d_revalidate(new_dentry);
INC_IVERSION(new_dir);
new_dir->i_ctime = new_dir->i_mtime = new_dir->i_atime = current_time(new_dir);
if (IS_DIRSYNC(new_dir))
(void) exfat_sync_inode(new_dir);
else
mark_inode_dirty(new_dir);
i_pos = exfat_make_i_pos(&(EXFAT_I(old_inode)->fid));
exfat_detach(old_inode);
exfat_attach(old_inode, i_pos);
if (IS_DIRSYNC(new_dir))
(void) exfat_sync_inode(old_inode);
else
mark_inode_dirty(old_inode);
if ((S_ISDIR(old_inode->i_mode)) && (old_dir != new_dir)) {
drop_nlink(old_dir);
if (!new_inode)
inc_nlink(new_dir);
}
INC_IVERSION(old_dir);
old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
if (IS_DIRSYNC(old_dir))
(void) exfat_sync_inode(old_dir);
else
mark_inode_dirty(old_dir);
if (new_inode) {
exfat_detach(new_inode);
/* skip drop_nlink if new_inode already has been dropped */
if (new_inode->i_nlink) {
drop_nlink(new_inode);
if (S_ISDIR(new_inode->i_mode))
drop_nlink(new_inode);
} else {
EMSG("%s : abnormal access to an inode dropped\n",
__func__);
WARN_ON(new_inode->i_nlink == 0);
}
new_inode->i_ctime = current_time(new_inode);
#if 0
(void) exfat_sync_inode(new_inode);
#endif
}
out:
__unlock_d_revalidate(old_dentry);
__unlock_d_revalidate(new_dentry);
unlock_super(sb);
return err;
}
static int exfat_cont_expand(struct inode *inode, loff_t size)
{
struct address_space *mapping = inode->i_mapping;
loff_t start = i_size_read(inode), count = size - i_size_read(inode);
int err, err2;
err = generic_cont_expand_simple(inode, size);
if (err)
return err;
inode->i_ctime = inode->i_mtime = current_time(inode);
mark_inode_dirty(inode);
if (!IS_SYNC(inode))
return 0;
err = filemap_fdatawrite_range(mapping, start, start + count - 1);
err2 = sync_mapping_buffers(mapping);
err = (err)?(err):(err2);
err2 = write_inode_now(inode, 1);
err = (err)?(err):(err2);
if (err)
return err;
return filemap_fdatawait_range(mapping, start, start + count - 1);
}
static int exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode)
{
mode_t allow_utime = sbi->options.allow_utime;
if (!uid_eq(current_fsuid(), inode->i_uid)) {
if (in_group_p(inode->i_gid))
allow_utime >>= 3;
if (allow_utime & MAY_WRITE)
return 1;
}
/* use a default check */
return 0;
}
static int exfat_sanitize_mode(const struct exfat_sb_info *sbi,
struct inode *inode, umode_t *mode_ptr)
{
mode_t i_mode, mask, perm;
i_mode = inode->i_mode;
if (S_ISREG(i_mode) || S_ISLNK(i_mode))
mask = sbi->options.fs_fmask;
else
mask = sbi->options.fs_dmask;
perm = *mode_ptr & ~(S_IFMT | mask);
/* Of the r and x bits, all (subject to umask) must be present.*/
if ((perm & (S_IRUGO | S_IXUGO)) != (i_mode & (S_IRUGO | S_IXUGO)))
return -EPERM;
if (exfat_mode_can_hold_ro(inode)) {
/* Of the w bits, either all (subject to umask) or none must be present. */
if ((perm & S_IWUGO) && ((perm & S_IWUGO) != (S_IWUGO & ~mask)))
return -EPERM;
} else {
/* If exfat_mode_can_hold_ro(inode) is false, can't change w bits. */
if ((perm & S_IWUGO) != (S_IWUGO & ~mask))
return -EPERM;
}
*mode_ptr &= S_IFMT | perm;
return 0;
}
static int exfat_setattr(struct dentry *dentry, struct iattr *attr)
{
struct exfat_sb_info *sbi = EXFAT_SB(dentry->d_sb);
struct inode *inode = dentry->d_inode;
unsigned int ia_valid;
int error;
loff_t old_size;
if ((attr->ia_valid & ATTR_SIZE)
&& (attr->ia_size > i_size_read(inode))) {
error = exfat_cont_expand(inode, attr->ia_size);
if (error || attr->ia_valid == ATTR_SIZE)
goto out;
attr->ia_valid &= ~ATTR_SIZE;
}
/* Check for setting the inode time. */
ia_valid = attr->ia_valid;
if ((ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET))
&& exfat_allow_set_time(sbi, inode)) {
attr->ia_valid &= ~(ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET);
}
error = setattr_prepare(dentry, attr);
attr->ia_valid = ia_valid;
if (error) {
if (sbi->options.quiet)
error = 0;
goto out;
}
if (((attr->ia_valid & ATTR_UID) &&
(!uid_eq(attr->ia_uid, sbi->options.fs_uid))) ||
((attr->ia_valid & ATTR_GID) &&
(!gid_eq(attr->ia_gid, sbi->options.fs_gid))) ||
((attr->ia_valid & ATTR_MODE) &&
(attr->ia_mode & ~(S_IFREG | S_IFLNK | S_IFDIR | S_IRWXUGO)))) {
error = -EPERM;
}
if (error) {
if (sbi->options.quiet)
error = 0;
goto out;
}
/*
* We don't return -EPERM here. Yes, strange, but this is too
* old behavior.
*/
if (attr->ia_valid & ATTR_MODE) {
if (exfat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0)
attr->ia_valid &= ~ATTR_MODE;
}
EXFAT_I(inode)->fid.size = i_size_read(inode);
/* patch 1.2.0 : fixed the problem of size mismatch. */
if (attr->ia_valid & ATTR_SIZE) {
old_size = i_size_read(inode);
/* TO CHECK evicting directory works correctly */
MMSG("%s: inode(%p) truncate size (%llu->%llu)\n", __func__,
inode, (u64)old_size, (u64)attr->ia_size);
__exfat_do_truncate(inode, old_size, attr->ia_size);
}
setattr_copy(inode, attr);
mark_inode_dirty(inode);
out:
return error;
}
static const struct inode_operations exfat_dir_inode_operations = {
.create = exfat_create,
.lookup = exfat_lookup,
.unlink = exfat_unlink,
.symlink = exfat_symlink,
.mkdir = exfat_mkdir,
.rmdir = exfat_rmdir,
.rename = exfat_rename,
.setattr = exfat_setattr,
.getattr = exfat_getattr,
#ifdef CONFIG_EXFAT_VIRTUAL_XATTR
.listxattr = exfat_listxattr,
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
.setxattr = exfat_setxattr,
.getxattr = exfat_getxattr,
.removexattr = exfat_removexattr,
#endif
#endif
};
static const struct inode_operations exfat_symlink_inode_operations = {
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
.readlink = generic_readlink,
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
.get_link = exfat_follow_link,
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) */
.follow_link = exfat_follow_link,
#endif
#ifdef CONFIG_EXFAT_VIRTUAL_XATTR
.listxattr = exfat_listxattr,
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
.setxattr = exfat_setxattr,
.getxattr = exfat_getxattr,
.removexattr = exfat_removexattr,
#endif
#endif
};
static int exfat_file_release(struct inode *inode, struct file *filp)
{
struct super_block *sb = inode->i_sb;
/* Moved below code from exfat_write_inode
* TO FIX size-mismatch problem.
*/
/* FIXME : Added bug_on to confirm that there is no size mismatch */
exfat_debug_bug_on(EXFAT_I(inode)->fid.size != i_size_read(inode));
EXFAT_I(inode)->fid.size = i_size_read(inode);
__exfat_sync_fs(sb, 0);
return 0;
}
static const struct file_operations exfat_file_operations = {
.llseek = generic_file_llseek,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0)
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
.read = new_sync_read,
.write = new_sync_write,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
#else /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) */
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write,
#endif
.mmap = exfat_file_mmap,
.release = exfat_file_release,
.unlocked_ioctl = exfat_generic_ioctl,
.fsync = exfat_file_fsync,
.splice_read = generic_file_splice_read,
};
static const struct address_space_operations exfat_aops;
/* resize the file length */
static s32 __exfat_truncate(struct inode *inode, u64 old_size, u64 new_size)
{
s32 err;
struct super_block *sb = inode->i_sb;
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_truncate(inode, old_size, new_size);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
static void exfat_truncate(struct inode *inode, loff_t old_size)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi);
unsigned int blocksize = 1 << inode->i_blkbits;
loff_t aligned_size;
int err;
lock_super(sb);
if (EXFAT_I(inode)->fid.start_clu == 0) {
/* Stange statement:
* Empty start_clu != ~0 (not allocated)
*/
exfat_fs_error(sb, "tried to truncate zeroed cluster.");
goto out;
}
err = __exfat_truncate(inode, old_size, i_size_read(inode));
if (err)
goto out;
inode->i_ctime = inode->i_mtime = current_time(inode);
if (IS_DIRSYNC(inode))
(void) exfat_sync_inode(inode);
else
mark_inode_dirty(inode);
// FIXME: Please check
// inode->i_blocks = ((EXFAT_I(inode)->i_size_ondisk + (fsi->cluster_size - 1))
inode->i_blocks = ((i_size_read(inode) + (fsi->cluster_size - 1)) &
~((loff_t)fsi->cluster_size - 1)) >> inode->i_blkbits;
out:
/*
* This protects against truncating a file bigger than it was then
* trying to write into the hole.
*
* comment by sh.hong:
* This seems to mean 'intra page/block' truncate and writing.
* I couldn't find a reason to change the values prior to __exfat_truncate
* Therefore, I switched the order of operations
* so that it's possible to utilize i_size_ondisk in __exfat_truncate
*/
aligned_size = i_size_read(inode);
if (aligned_size & (blocksize - 1)) {
aligned_size |= (blocksize - 1);
aligned_size++;
}
if (EXFAT_I(inode)->i_size_ondisk > i_size_read(inode))
EXFAT_I(inode)->i_size_ondisk = aligned_size;
if (EXFAT_I(inode)->i_size_aligned > i_size_read(inode))
EXFAT_I(inode)->i_size_aligned = aligned_size;
/* After truncation :
* 1) Delayed allocation is OFF
* i_size = i_size_ondisk <= i_size_aligned
* (useless size var.)
* (block-aligned)
* 2) Delayed allocation is ON
* i_size = i_size_ondisk = i_size_aligned
* (will be block-aligned after write)
* or
* i_size_ondisk < i_size <= i_size_aligned (block_aligned)
* (will be block-aligned after write)
*/
unlock_super(sb);
}
static const struct inode_operations exfat_file_inode_operations = {
.setattr = exfat_setattr,
.getattr = exfat_getattr,
#ifdef CONFIG_EXFAT_VIRTUAL_XATTR
.listxattr = exfat_listxattr,
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0)
.setxattr = exfat_setxattr,
.getxattr = exfat_getxattr,
.removexattr = exfat_removexattr,
#endif
#endif
};
/* 2-level option flag */
#define BMAP_NOT_CREATE 0
#define BMAP_ADD_BLOCK 1
#define BMAP_ADD_CLUSTER 2
#define BLOCK_ADDED(bmap_ops) (bmap_ops)
static int exfat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
unsigned long *mapped_blocks, int *create)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi);
const unsigned long blocksize = sb->s_blocksize;
const unsigned char blocksize_bits = sb->s_blocksize_bits;
sector_t last_block;
unsigned int cluster, clu_offset, sec_offset;
int err = 0;
*phys = 0;
*mapped_blocks = 0;
/* core code should handle EIO */
#if 0
if (fsi->prev_eio && BLOCK_ADDED(*create))
return -EIO;
#endif
last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits;
if ((sector >= last_block) && (*create == BMAP_NOT_CREATE))
return 0;
/* Is this block already allocated? */
clu_offset = sector >> fsi->sect_per_clus_bits; /* cluster offset */
EXFAT_I(inode)->fid.size = i_size_read(inode);
if (*create & BMAP_ADD_CLUSTER)
err = exfat_map_clus(inode, clu_offset, &cluster, 1);
else
err = exfat_map_clus(inode, clu_offset, &cluster, ALLOC_NOWHERE);
if (err) {
if (err != -ENOSPC)
return -EIO;
return err;
}
if (!IS_CLUS_EOF(cluster)) {
/* sector offset in cluster */
sec_offset = sector & (fsi->sect_per_clus - 1);
*phys = CLUS_TO_SECT(fsi, cluster) + sec_offset;
*mapped_blocks = fsi->sect_per_clus - sec_offset;
}
#if 0
else {
/* Debug purpose (new clu needed) */
ASSERT((*create & BMAP_ADD_CLUSTER) == 0);
ASSERT(sector >= last_block);
}
#endif
if (sector < last_block)
*create = BMAP_NOT_CREATE;
#if 0
else if (sector >= last_block)
*create = non-zero;
if (iblock <= last mapped-block)
*phys != 0
*create = BMAP_NOT_CREATE
else if (iblock <= last cluster)
*phys != 0
*create = non-zero
#endif
return 0;
}
static int exfat_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh_result, int create)
{
struct super_block *sb = inode->i_sb;
unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
int err = 0;
unsigned long mapped_blocks;
sector_t phys;
loff_t pos;
int bmap_create = create ? BMAP_ADD_CLUSTER : BMAP_NOT_CREATE;
lock_super(sb);
err = exfat_bmap(inode, iblock, &phys, &mapped_blocks, &bmap_create);
if (err) {
if (err != -ENOSPC)
exfat_fs_error_ratelimit(sb, "%s: failed to bmap "
"(inode:%p iblock:%u, err:%d)",
__func__, inode, (u32)iblock, err);
goto unlock_ret;
}
if (phys) {
max_blocks = min(mapped_blocks, max_blocks);
/* Treat newly added block / cluster */
if (BLOCK_ADDED(bmap_create) || buffer_delay(bh_result)) {
/* Update i_size_ondisk */
pos = (iblock + 1) << sb->s_blocksize_bits;
if (EXFAT_I(inode)->i_size_ondisk < pos) {
/* Debug purpose */
if ((pos - EXFAT_I(inode)->i_size_ondisk) > bh_result->b_size) {
/* This never happens without DA */
MMSG("Jumping get_block\n");
}
EXFAT_I(inode)->i_size_ondisk = pos;
}
if (BLOCK_ADDED(bmap_create)) {
/* Old way (w/o DA)
* create == 1 only if iblock > i_size
* (in block unit)
*/
/* 20130723 CHECK
* If happened concurrently with truncation,
* buffer_delay() can be left on whilst
* i_size < (position of i_block).
*
* It's not a big deal as we're re-writing
* previously allocated blocks, but in such cases,
* it has to be an area with i_size_aligned expanded
* beforehand.
*/
/* FOR GRACEFUL ERROR HANDLING */
if (buffer_delay(bh_result) &&
(pos > EXFAT_I(inode)->i_size_aligned)) {
exfat_fs_error(sb, "requested for bmap "
"out of range(pos:(%llu)>i_size_aligned(%llu)\n",
pos, EXFAT_I(inode)->i_size_aligned);
exfat_debug_bug_on(1);
err = -EIO;
goto unlock_ret;
}
set_buffer_new(bh_result);
/*
* adjust i_size_aligned if i_size_ondisk is
* bigger than it. (i.e. non-DA)
*/
if (EXFAT_I(inode)->i_size_ondisk >
EXFAT_I(inode)->i_size_aligned) {
EXFAT_I(inode)->i_size_aligned =
EXFAT_I(inode)->i_size_ondisk;
}
}
if (buffer_delay(bh_result))
clear_buffer_delay(bh_result);
#if 0
/* Debug purpose */
if (EXFAT_I(inode)->i_size_ondisk >
EXFAT_I(inode)->i_size_aligned) {
/* Only after truncate
* and the two size variables should indicate
* same i_block
*/
unsigned int blocksize = 1 << inode->i_blkbits;
BUG_ON(EXFAT_I(inode)->i_size_ondisk -
EXFAT_I(inode)->i_size_aligned >= blocksize);
}
#endif
}
map_bh(bh_result, sb, phys);
}
bh_result->b_size = max_blocks << sb->s_blocksize_bits;
unlock_ret:
unlock_super(sb);
return err;
}
static int exfat_readpage(struct file *file, struct page *page)
{
int ret;
ret = mpage_readpage(page, exfat_get_block);
return ret;
}
static int exfat_readpages(struct file *file, struct address_space *mapping,
struct list_head *pages, unsigned int nr_pages)
{
int ret;
ret = mpage_readpages(mapping, pages, nr_pages, exfat_get_block);
return ret;
}
static inline void exfat_submit_fullpage_bio(struct block_device *bdev,
sector_t sector, unsigned int length, struct page *page)
{
/* Single page bio submit */
struct bio *bio;
BUG_ON((length > PAGE_SIZE) || (length == 0));
/*
* If __GFP_WAIT is set, then bio_alloc will always be able to allocate
* a bio. This is due to the mempool guarantees. To make this work, callers
* must never allocate more than 1 bio at a time from this pool.
*
* #define GFP_NOIO (__GFP_WAIT)
*/
bio = bio_alloc(GFP_NOIO, 1);
bio_set_dev(bio, bdev);
bio->bi_vcnt = 1;
bio->bi_io_vec[0].bv_page = page; /* Inline vec */
bio->bi_io_vec[0].bv_len = length; /* PAGE_SIZE */
bio->bi_io_vec[0].bv_offset = 0;
__exfat_set_bio_iterate(bio, sector, length, 0, 0);
bio->bi_end_io = exfat_writepage_end_io;
__exfat_submit_bio_write(bio);
}
static int exfat_writepage(struct page *page, struct writeback_control *wbc)
{
struct inode * const inode = page->mapping->host;
struct super_block *sb = inode->i_sb;
loff_t i_size = i_size_read(inode);
const pgoff_t end_index = i_size >> PAGE_SHIFT;
const unsigned int blocks_per_page = PAGE_SIZE >> inode->i_blkbits;
FS_INFO_T *fsi = &(EXFAT_SB(sb)->fsi);
struct buffer_head *bh, *head;
sector_t block, block_0, last_phys;
int ret;
unsigned int nr_blocks_towrite = blocks_per_page;
/* Don't distinguish 0-filled/clean block.
* Just write back the whole page
*/
if (fsi->cluster_size < PAGE_SIZE)
goto confused;
if (!PageUptodate(page)) {
MMSG("%s: Not up-to-date page -> block_write_full_page\n",
__func__);
goto confused;
}
if (page->index >= end_index) {
/* last page or outside i_size */
unsigned int offset = i_size & (PAGE_SIZE-1);
/* If a truncation is in progress */
if (page->index > end_index || !offset)
goto confused;
/* 0-fill after i_size */
zero_user_segment(page, offset, PAGE_SIZE);
}
if (!page_has_buffers(page)) {
MMSG("WP: No buffers -> block_write_full_page\n");
goto confused;
}
block = (sector_t)page->index << (PAGE_SHIFT - inode->i_blkbits);
block_0 = block; /* first block */
head = page_buffers(page);
bh = head;
last_phys = 0;
do {
BUG_ON(buffer_locked(bh));
if (!buffer_dirty(bh) || !buffer_uptodate(bh)) {
if (nr_blocks_towrite == blocks_per_page)
nr_blocks_towrite = (unsigned int) (block - block_0);
BUG_ON(nr_blocks_towrite >= blocks_per_page);
// !uptodate but dirty??
if (buffer_dirty(bh))
goto confused;
// Nothing to writeback in this block
bh = bh->b_this_page;
block++;
continue;
}
if (nr_blocks_towrite != blocks_per_page)
// Dirty -> Non-dirty -> Dirty again case
goto confused;
/* Map if needed */
if (!buffer_mapped(bh) || buffer_delay(bh)) {
BUG_ON(bh->b_size != (1 << (inode->i_blkbits)));
ret = exfat_get_block(inode, block, bh, 1);
if (ret)
goto confused;
if (buffer_new(bh)) {
clear_buffer_new(bh);
__exfat_clean_bdev_aliases(bh->b_bdev, bh->b_blocknr);
}
}
/* continuity check */
if (((last_phys + 1) != bh->b_blocknr) && (last_phys != 0)) {
DMSG("Non-contiguous block mapping in single page");
goto confused;
}
last_phys = bh->b_blocknr;
bh = bh->b_this_page;
block++;
} while (bh != head);
if (nr_blocks_towrite == 0) {
DMSG("Page dirty but no dirty bh? alloc_208\n");
goto confused;
}
/* Write-back */
do {
clear_buffer_dirty(bh);
bh = bh->b_this_page;
} while (bh != head);
BUG_ON(PageWriteback(page));
set_page_writeback(page);
// Trace # of pages queued (Approx.)
atomic_inc(&EXFAT_SB(sb)->stat_n_pages_queued);
exfat_submit_fullpage_bio(head->b_bdev,
head->b_blocknr << (sb->s_blocksize_bits - SECTOR_SIZE_BITS),
nr_blocks_towrite << inode->i_blkbits,
page);
unlock_page(page);
return 0;
confused:
ret = block_write_full_page(page, exfat_get_block, wbc);
return ret;
}
static int exfat_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
MMSG("%s(inode:%p) with nr_to_write = 0x%08lx "
"(ku %d, bg %d, tag %d, rc %d )\n",
__func__, mapping->host, wbc->nr_to_write,
wbc->for_kupdate, wbc->for_background, wbc->tagged_writepages,
wbc->for_reclaim);
ASSERT(mapping->a_ops == &exfat_aops);
return mpage_writepages(mapping, wbc, exfat_get_block);
}
static void exfat_write_failed(struct address_space *mapping, loff_t to)
{
struct inode *inode = mapping->host;
if (to > i_size_read(inode)) {
__exfat_truncate_pagecache(inode, to, i_size_read(inode));
exfat_truncate(inode, EXFAT_I(inode)->i_size_aligned);
}
}
static int exfat_check_writable(struct super_block *sb)
{
if (exfat_fscore_check_bdi_valid(sb))
return -EIO;
if (EXFAT_IS_SB_RDONLY(sb))
return -EROFS;
return 0;
}
static int __exfat_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned int len,
unsigned int flags, struct page **pagep,
void **fsdata, get_block_t *get_block,
loff_t *bytes, const char *fname)
{
struct super_block *sb = mapping->host->i_sb;
int ret;
ret = exfat_check_writable(sb);
if (unlikely(ret < 0))
return ret;
*pagep = NULL;
ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
get_block, bytes);
if (ret < 0)
exfat_write_failed(mapping, pos+len);
return ret;
}
static int exfat_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned int len, unsigned int flags,
struct page **pagep, void **fsdata)
{
return __exfat_write_begin(file, mapping, pos, len, flags,
pagep, fsdata, exfat_get_block,
&EXFAT_I(mapping->host)->i_size_ondisk,
__func__);
}
static int exfat_write_end(struct file *file, struct address_space *mapping,
loff_t pos, unsigned int len, unsigned int copied,
struct page *pagep, void *fsdata)
{
struct inode *inode = mapping->host;
FILE_ID_T *fid = &(EXFAT_I(inode)->fid);
int err;
err = generic_write_end(file, mapping, pos, len, copied, pagep, fsdata);
/* FOR GRACEFUL ERROR HANDLING */
if (EXFAT_I(inode)->i_size_aligned < i_size_read(inode)) {
exfat_fs_error(inode->i_sb, "invalid size(size(%llu) "
"> aligned(%llu)\n", i_size_read(inode),
EXFAT_I(inode)->i_size_aligned);
exfat_debug_bug_on(1);
}
if (err < len)
exfat_write_failed(mapping, pos+len);
if (!(err < 0) && !(fid->attr & ATTR_ARCHIVE)) {
inode->i_mtime = inode->i_ctime = current_time(inode);
fid->attr |= ATTR_ARCHIVE;
mark_inode_dirty(inode);
}
return err;
}
static inline ssize_t __exfat_direct_IO(int rw, struct kiocb *iocb,
struct inode *inode, void *iov_u, loff_t offset,
loff_t count, unsigned long nr_segs)
{
struct address_space *mapping = inode->i_mapping;
loff_t size = offset + count;
ssize_t ret;
if (rw == WRITE) {
/*
* FIXME: blockdev_direct_IO() doesn't use ->write_begin(),
* so we need to update the ->i_size_aligned to block boundary.
*
* But we must fill the remaining area or hole by nul for
* updating ->i_size_aligned
*
* Return 0, and fallback to normal buffered write.
*/
if (EXFAT_I(inode)->i_size_aligned < size)
return 0;
}
/*
* exFAT need to use the DIO_LOCKING for avoiding the race
* condition of exfat_get_block() and ->truncate().
*/
ret = __exfat_blkdev_direct_IO(rw, iocb, inode, iov_u, offset, nr_segs);
if (ret < 0 && (rw & WRITE))
exfat_write_failed(mapping, size);
return ret;
}
static const struct address_space_operations exfat_aops = {
.readpage = exfat_readpage,
.readpages = exfat_readpages,
.writepage = exfat_writepage,
.writepages = exfat_writepages,
.write_begin = exfat_write_begin,
.write_end = exfat_write_end,
.direct_IO = exfat_direct_IO,
.bmap = exfat_aop_bmap
};
static inline unsigned long exfat_hash(loff_t i_pos)
{
return hash_32(i_pos, EXFAT_HASH_BITS);
}
static void exfat_attach(struct inode *inode, loff_t i_pos)
{
struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
struct hlist_head *head = sbi->inode_hashtable + exfat_hash(i_pos);
spin_lock(&sbi->inode_hash_lock);
EXFAT_I(inode)->i_pos = i_pos;
hlist_add_head(&EXFAT_I(inode)->i_hash_fat, head);
spin_unlock(&sbi->inode_hash_lock);
}
static void exfat_detach(struct inode *inode)
{
struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
spin_lock(&sbi->inode_hash_lock);
hlist_del_init(&EXFAT_I(inode)->i_hash_fat);
EXFAT_I(inode)->i_pos = 0;
spin_unlock(&sbi->inode_hash_lock);
}
/* doesn't deal with root inode */
static int exfat_fill_inode(struct inode *inode, const FILE_ID_T *fid)
{
struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
FS_INFO_T *fsi = &(sbi->fsi);
DIR_ENTRY_T info;
u64 size = fid->size;
memcpy(&(EXFAT_I(inode)->fid), fid, sizeof(FILE_ID_T));
EXFAT_I(inode)->i_pos = 0;
EXFAT_I(inode)->target = NULL;
inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid;
INC_IVERSION(inode);
inode->i_generation = get_seconds();
if (exfat_read_inode(inode, &info) < 0) {
MMSG("%s: failed to read stat!\n", __func__);
return -EIO;
}
if (info.Attr & ATTR_SUBDIR) { /* directory */
inode->i_generation &= ~1;
inode->i_mode = exfat_make_mode(sbi, info.Attr, S_IRWXUGO);
inode->i_op = &exfat_dir_inode_operations;
inode->i_fop = &exfat_dir_operations;
set_nlink(inode, info.NumSubdirs);
} else if (info.Attr & ATTR_SYMLINK) { /* symbolic link */
inode->i_op = &exfat_symlink_inode_operations;
inode->i_generation |= 1;
inode->i_mode = exfat_make_mode(sbi, info.Attr, S_IRWXUGO);
} else { /* regular file */
inode->i_generation |= 1;
inode->i_mode = exfat_make_mode(sbi, info.Attr, S_IRWXUGO);
inode->i_op = &exfat_file_inode_operations;
inode->i_fop = &exfat_file_operations;
inode->i_mapping->a_ops = &exfat_aops;
inode->i_mapping->nrpages = 0;
}
/*
* Use fid->size instead of info.Size
* because info.Size means the value saved on disk
*/
i_size_write(inode, size);
/* ondisk and aligned size should be aligned with block size */
if (size & (inode->i_sb->s_blocksize - 1)) {
size |= (inode->i_sb->s_blocksize - 1);
size++;
}
EXFAT_I(inode)->i_size_aligned = size;
EXFAT_I(inode)->i_size_ondisk = size;
exfat_save_attr(inode, info.Attr);
inode->i_blocks = ((i_size_read(inode) + (fsi->cluster_size - 1))
& ~((loff_t)fsi->cluster_size - 1)) >> inode->i_blkbits;
exfat_time_fat2unix(sbi, &inode->i_mtime, &info.ModifyTimestamp);
exfat_time_fat2unix(sbi, &inode->i_ctime, &info.CreateTimestamp);
exfat_time_fat2unix(sbi, &inode->i_atime, &info.AccessTimestamp);
return 0;
}
static struct inode *exfat_build_inode(struct super_block *sb,
const FILE_ID_T *fid, loff_t i_pos)
{
struct inode *inode;
int err;
inode = exfat_iget(sb, i_pos);
if (inode)
goto out;
inode = new_inode(sb);
if (!inode) {
inode = ERR_PTR(-ENOMEM);
goto out;
}
inode->i_ino = iunique(sb, EXFAT_ROOT_INO);
SET_IVERSION(inode, 1);
err = exfat_fill_inode(inode, fid);
if (err) {
iput(inode);
inode = ERR_PTR(err);
goto out;
}
exfat_attach(inode, i_pos);
insert_inode_hash(inode);
out:
return inode;
}
static struct inode *exfat_alloc_inode(struct super_block *sb)
{
struct exfat_inode_info *ei;
ei = kmem_cache_alloc(exfat_inode_cachep, GFP_NOFS);
if (!ei)
return NULL;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
init_rwsem(&ei->truncate_lock);
#endif
return &ei->vfs_inode;
}
static void exfat_destroy_inode(struct inode *inode)
{
kfree(EXFAT_I(inode)->target);
EXFAT_I(inode)->target = NULL;
kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode));
}
static int __exfat_write_inode(struct inode *inode, int sync)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
DIR_ENTRY_T info;
s32 err;
if (inode->i_ino == EXFAT_ROOT_INO)
return 0;
info.Attr = exfat_make_attr(inode);
info.Size = i_size_read(inode);
exfat_time_unix2fat(sbi, &inode->i_mtime, &info.ModifyTimestamp);
exfat_time_unix2fat(sbi, &inode->i_ctime, &info.CreateTimestamp);
exfat_time_unix2fat(sbi, &inode->i_atime, &info.AccessTimestamp);
/* FIXME : Do we need handling error? */
mutex_lock(&(sbi->s_vlock));
err = exfat_fscore_write_inode(inode, &info, sync);
mutex_unlock(&(sbi->s_vlock));
return err;
}
static int exfat_sync_inode(struct inode *inode)
{
return __exfat_write_inode(inode, 1);
}
static int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
{
return __exfat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
}
static void exfat_evict_inode(struct inode *inode)
{
truncate_inode_pages(&inode->i_data, 0);
if (!inode->i_nlink) {
loff_t old_size = i_size_read(inode);
i_size_write(inode, 0);
EXFAT_I(inode)->fid.size = old_size;
/* TO CHECK evicting directory works correctly */
MMSG("%s: inode(%p) evict %s (size(%llu) to zero)\n",
__func__, inode,
S_ISDIR(inode->i_mode) ? "directory" : "file",
(u64)old_size);
__exfat_truncate(inode, old_size, 0);
}
invalidate_inode_buffers(inode);
clear_inode(inode);
exfat_extent_cache_inval_inode(inode);
exfat_detach(inode);
/* after end of this function, caller will remove inode hash */
/* remove_inode_hash(inode); */
}
static void exfat_put_super(struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
int err;
exfat_log_msg(sb, KERN_INFO, "trying to unmount...");
__cancel_delayed_work_sync(sbi);
if (__is_sb_dirty(sb))
exfat_write_super(sb);
err = exfat_umount(sb);
if (sbi->nls_disk) {
unload_nls(sbi->nls_disk);
sbi->nls_disk = NULL;
sbi->options.codepage = exfat_default_codepage;
}
if (sbi->nls_io) {
unload_nls(sbi->nls_io);
sbi->nls_io = NULL;
}
if (sbi->options.iocharset != exfat_default_iocharset) {
kfree(sbi->options.iocharset);
sbi->options.iocharset = exfat_default_iocharset;
}
sb->s_fs_info = NULL;
kobject_del(&sbi->sb_kobj);
kobject_put(&sbi->sb_kobj);
if (!sbi->use_vmalloc)
kfree(sbi);
else
vfree(sbi);
exfat_log_msg(sb, KERN_INFO, "unmounted successfully! %s",
err ? "(with previous I/O errors)" : "");
}
static inline void __flush_delayed_meta(struct super_block *sb, s32 sync)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
if (sbi->options.delayed_meta)
exfat_cache_flush(sb, sync);
}
static void exfat_write_super(struct super_block *sb)
{
int time = 0;
lock_super(sb);
__set_sb_clean(sb);
/* flush delayed FAT/DIR dirty */
__flush_delayed_meta(sb, 0);
if (!EXFAT_IS_SB_RDONLY(sb))
__exfat_sync_fs(sb, 0);
unlock_super(sb);
time = jiffies;
/* Issuing bdev requests is needed
* to guarantee DIR updates in time
* whether w/ or w/o delayed DIR dirty feature.
* (otherwise DIR updates could be delayed for 5 + 5 secs at max.)
*/
sync_blockdev(sb->s_bdev);
MMSG("BD: exfat_write_super (bdev_sync for %ld ms)\n",
(jiffies - time) * 1000 / HZ);
}
/* synchronize a file system volume */
static s32 __exfat_sync_fs(struct super_block *sb, s32 do_sync)
{
s32 err;
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_sync_fs(sb, do_sync);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return err;
}
static int exfat_sync_fs(struct super_block *sb, int wait)
{
int err = 0;
/* If there are some dirty buffers in the bdev inode */
if (__is_sb_dirty(sb)) {
lock_super(sb);
__set_sb_clean(sb);
err = __exfat_sync_fs(sb, 1);
unlock_super(sb);
}
return err;
}
static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
{
/*
* patch 1.2.2 :
* fixed the slow-call problem because of volume-lock contention.
*/
struct super_block *sb = dentry->d_sb;
u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
FS_INFO_T *fsi = &(EXFAT_SB(sb)->fsi);
VOL_INFO_T info;
/* exfat_statfs will try to get a volume lock if needed */
if (fsi->used_clusters == UINT_MAX) {
s32 err;
mutex_lock(&(EXFAT_SB(sb)->s_vlock));
err = exfat_fscore_statfs(sb, &info);
mutex_unlock(&(EXFAT_SB(sb)->s_vlock));
return -EIO;
}
info.ClusterSize = fsi->cluster_size;
info.NumClusters = fsi->num_clusters - 2; /* clu 0 & 1 */
info.UsedClusters = fsi->used_clusters + fsi->reserved_clusters;
info.FreeClusters = info.NumClusters - info.UsedClusters;
if (fsi->prev_eio)
exfat_msg(sb, KERN_INFO, "called statfs with previous"
" I/O error(0x%02X).", fsi->prev_eio);
buf->f_type = sb->s_magic;
buf->f_bsize = info.ClusterSize;
buf->f_blocks = info.NumClusters;
buf->f_bfree = info.FreeClusters;
buf->f_bavail = info.FreeClusters;
buf->f_fsid.val[0] = (u32)id;
buf->f_fsid.val[1] = (u32)(id >> 32);
buf->f_namelen = 260;
return 0;
}
static int exfat_remount(struct super_block *sb, int *flags, char *data)
{
unsigned long prev_sb_flags;
char *orig_data = kstrdup(data, GFP_KERNEL);
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
*flags |= MS_NODIRATIME;
#else
*flags |= SB_NODIRATIME;
#endif
prev_sb_flags = sb->s_flags;
exfat_remount_syncfs(sb);
exfat_set_vol_flags(sb, VOL_CLEAN, 1);
exfat_log_msg(sb, KERN_INFO, "re-mounted(%s->%s), eio=0x%x, Opts: %s",
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
(prev_sb_flags & MS_RDONLY) ? "ro" : "rw",
(*flags & MS_RDONLY) ? "ro" : "rw",
#else
(prev_sb_flags & SB_RDONLY) ? "ro" : "rw",
(*flags & SB_RDONLY) ? "ro" : "rw",
#endif
fsi->prev_eio, orig_data);
kfree(orig_data);
return 0;
}
static int __exfat_show_options(struct seq_file *m, struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct exfat_mount_options *opts = &sbi->options;
FS_INFO_T *fsi = &(sbi->fsi);
/* Show partition info */
if (fsi->prev_eio)
seq_printf(m, ",eio=0x%x", fsi->prev_eio);
if (!uid_eq(opts->fs_uid, GLOBAL_ROOT_UID))
seq_printf(m, ",uid=%u",
from_kuid_munged(&init_user_ns, opts->fs_uid));
if (!gid_eq(opts->fs_gid, GLOBAL_ROOT_GID))
seq_printf(m, ",gid=%u",
from_kgid_munged(&init_user_ns, opts->fs_gid));
seq_printf(m, ",fmask=%04o", opts->fs_fmask);
seq_printf(m, ",dmask=%04o", opts->fs_dmask);
if (opts->allow_utime)
seq_printf(m, ",allow_utime=%04o", opts->allow_utime);
if (sbi->nls_disk)
seq_printf(m, ",codepage=%s", sbi->nls_disk->charset);
if (sbi->nls_io)
seq_printf(m, ",iocharset=%s", sbi->nls_io->charset);
if (opts->quiet)
seq_puts(m, ",quiet");
if (opts->utf8)
seq_puts(m, ",utf8");
seq_printf(m, ",namecase=%u", opts->casesensitive);
if (opts->tz_utc)
seq_puts(m, ",tz=UTC");
seq_printf(m, ",symlink=%u", opts->symlink);
seq_printf(m, ",bps=%ld", sb->s_blocksize);
if (opts->errors == EXFAT_ERRORS_CONT)
seq_puts(m, ",errors=continue");
else if (opts->errors == EXFAT_ERRORS_PANIC)
seq_puts(m, ",errors=panic");
else
seq_puts(m, ",errors=remount-ro");
if (opts->discard)
seq_puts(m, ",discard");
if (opts->delayed_meta)
seq_puts(m, ",delayed_meta");
return 0;
}
static const struct super_operations exfat_sops = {
.alloc_inode = exfat_alloc_inode,
.destroy_inode = exfat_destroy_inode,
.write_inode = exfat_write_inode,
.evict_inode = exfat_evict_inode,
.put_super = exfat_put_super,
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
.write_super = exfat_write_super,
#endif
.sync_fs = exfat_sync_fs,
.statfs = exfat_statfs,
.remount_fs = exfat_remount,
.show_options = exfat_show_options,
};
#define EXFAT_ATTR(name, mode, show, store) \
static struct exfat_attr exfat_attr_##name = __ATTR(name, mode, show, store)
struct exfat_attr {
struct attribute attr;
ssize_t (*show)(struct exfat_sb_info *, char *);
ssize_t (*store)(struct exfat_sb_info *, const char *, size_t);
};
static ssize_t exfat_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
{
struct exfat_sb_info *sbi = container_of(kobj, struct exfat_sb_info, sb_kobj);
struct exfat_attr *a = container_of(attr, struct exfat_attr, attr);
return a->show ? a->show(sbi, buf) : 0;
}
static ssize_t exfat_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t len)
{
struct exfat_sb_info *sbi = container_of(kobj, struct exfat_sb_info, sb_kobj);
struct exfat_attr *a = container_of(attr, struct exfat_attr, attr);
return a->store ? a->store(sbi, buf, len) : len;
}
static const struct sysfs_ops exfat_attr_ops = {
.show = exfat_attr_show,
.store = exfat_attr_store,
};
static ssize_t eio_show(struct exfat_sb_info *sbi, char *buf)
{
FS_INFO_T *fsi = &(sbi->fsi);
return snprintf(buf, PAGE_SIZE, "0x%x\n", fsi->prev_eio);
}
EXFAT_ATTR(eio, 0444, eio_show, NULL);
static ssize_t fratio_show(struct exfat_sb_info *sbi, char *buf)
{
unsigned int n_total_au = 0;
unsigned int n_clean_au = 0;
unsigned int n_full_au = 0;
unsigned int n_dirty_au = 0;
unsigned int fr = 0;
n_total_au = exfat_fscore_get_au_stat(sbi->host_sb, VOL_AU_STAT_TOTAL);
n_clean_au = exfat_fscore_get_au_stat(sbi->host_sb, VOL_AU_STAT_CLEAN);
n_full_au = exfat_fscore_get_au_stat(sbi->host_sb, VOL_AU_STAT_FULL);
n_dirty_au = n_total_au - (n_full_au + n_clean_au);
if (!n_dirty_au)
fr = 0;
else if (!n_clean_au)
fr = 100;
else
fr = (n_dirty_au * 100) / (n_clean_au + n_dirty_au);
return snprintf(buf, PAGE_SIZE, "%u\n", fr);
}
EXFAT_ATTR(fratio, 0444, fratio_show, NULL);
static ssize_t totalau_show(struct exfat_sb_info *sbi, char *buf)
{
unsigned int n_au = 0;
n_au = exfat_fscore_get_au_stat(sbi->host_sb, VOL_AU_STAT_TOTAL);
return snprintf(buf, PAGE_SIZE, "%u\n", n_au);
}
EXFAT_ATTR(totalau, 0444, totalau_show, NULL);
static ssize_t cleanau_show(struct exfat_sb_info *sbi, char *buf)
{
unsigned int n_clean_au = 0;
n_clean_au = exfat_fscore_get_au_stat(sbi->host_sb, VOL_AU_STAT_CLEAN);
return snprintf(buf, PAGE_SIZE, "%u\n", n_clean_au);
}
EXFAT_ATTR(cleanau, 0444, cleanau_show, NULL);
static ssize_t fullau_show(struct exfat_sb_info *sbi, char *buf)
{
unsigned int n_full_au = 0;
n_full_au = exfat_fscore_get_au_stat(sbi->host_sb, VOL_AU_STAT_FULL);
return snprintf(buf, PAGE_SIZE, "%u\n", n_full_au);
}
EXFAT_ATTR(fullau, 0444, fullau_show, NULL);
static struct attribute *exfat_attrs[] = {
&exfat_attr_eio.attr,
&exfat_attr_fratio.attr,
&exfat_attr_totalau.attr,
&exfat_attr_cleanau.attr,
&exfat_attr_fullau.attr,
NULL,
};
static struct kobj_type exfat_ktype = {
.default_attrs = exfat_attrs,
.sysfs_ops = &exfat_attr_ops,
};
static ssize_t version_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "FS Version %s\n", EXFAT_VERSION);
}
static struct kobj_attribute version_attr = __ATTR_RO(version);
static struct attribute *attributes[] = {
&version_attr.attr,
NULL,
};
static struct attribute_group attr_group = {
.attrs = attributes,
};
enum {
Opt_uid,
Opt_gid,
Opt_umask,
Opt_dmask,
Opt_fmask,
Opt_allow_utime,
Opt_codepage,
Opt_charset,
Opt_quiet,
Opt_utf8,
Opt_namecase,
Opt_tz_utc,
Opt_symlink,
Opt_err_cont,
Opt_err_panic,
Opt_err_ro,
Opt_err,
Opt_discard,
Opt_delayed_meta,
Opt_nodelayed_meta,
};
static const match_table_t exfat_tokens = {
{Opt_uid, "uid=%u"},
{Opt_gid, "gid=%u"},
{Opt_umask, "umask=%o"},
{Opt_dmask, "dmask=%o"},
{Opt_fmask, "fmask=%o"},
{Opt_allow_utime, "allow_utime=%o"},
{Opt_codepage, "codepage=%u"},
{Opt_charset, "iocharset=%s"},
{Opt_quiet, "quiet"},
{Opt_utf8, "utf8"},
{Opt_namecase, "namecase=%u"},
{Opt_tz_utc, "tz=UTC"},
{Opt_symlink, "symlink=%u"},
{Opt_err_cont, "errors=continue"},
{Opt_err_panic, "errors=panic"},
{Opt_err_ro, "errors=remount-ro"},
{Opt_discard, "discard"},
{Opt_delayed_meta, "delayed_meta"},
{Opt_nodelayed_meta, "nodelayed_meta"},
{Opt_err, NULL}
};
static int parse_options(struct super_block *sb, char *options, int silent,
struct exfat_mount_options *opts)
{
char *p;
substring_t args[MAX_OPT_ARGS];
int option;
char *tmpstr;
opts->fs_uid = current_uid();
opts->fs_gid = current_gid();
opts->fs_fmask = opts->fs_dmask = current->fs->umask;
opts->allow_utime = U16_MAX;
opts->codepage = exfat_default_codepage;
opts->iocharset = exfat_default_iocharset;
opts->quiet = 0;
opts->casesensitive = 0;
opts->utf8 = 0;
opts->tz_utc = 0;
opts->symlink = 0;
opts->errors = EXFAT_ERRORS_RO;
opts->discard = 0;
opts->delayed_meta = 1;
if (!options)
goto out;
while ((p = strsep(&options, ",")) != NULL) {
int token;
if (!*p)
continue;
token = match_token(p, exfat_tokens, args);
switch (token) {
case Opt_uid:
if (match_int(&args[0], &option))
return 0;
opts->fs_uid = make_kuid(current_user_ns(), option);
break;
case Opt_gid:
if (match_int(&args[0], &option))
return 0;
opts->fs_gid = make_kgid(current_user_ns(), option);
break;
case Opt_umask:
case Opt_dmask:
case Opt_fmask:
if (match_octal(&args[0], &option))
return 0;
if (token != Opt_dmask)
opts->fs_fmask = option;
if (token != Opt_fmask)
opts->fs_dmask = option;
break;
case Opt_allow_utime:
if (match_octal(&args[0], &option))
return 0;
opts->allow_utime = option & (S_IWGRP | S_IWOTH);
break;
case Opt_codepage:
if (match_int(&args[0], &option))
return 0;
opts->codepage = option;
break;
case Opt_charset:
if (opts->iocharset != exfat_default_iocharset)
kfree(opts->iocharset);
tmpstr = match_strdup(&args[0]);
if (!tmpstr)
return -ENOMEM;
opts->iocharset = tmpstr;
break;
case Opt_quiet:
opts->quiet = 1;
break;
case Opt_namecase:
if (match_int(&args[0], &option))
return 0;
opts->casesensitive = (option > 0) ? 1:0;
break;
case Opt_utf8:
opts->utf8 = 1;
break;
case Opt_tz_utc:
opts->tz_utc = 1;
break;
case Opt_symlink:
if (match_int(&args[0], &option))
return 0;
opts->symlink = option > 0 ? 1 : 0;
break;
case Opt_err_cont:
opts->errors = EXFAT_ERRORS_CONT;
break;
case Opt_err_panic:
opts->errors = EXFAT_ERRORS_PANIC;
break;
case Opt_err_ro:
opts->errors = EXFAT_ERRORS_RO;
break;
case Opt_discard:
opts->discard = 1;
break;
case Opt_nodelayed_meta:
opts->delayed_meta = 0;
break;
default:
if (!silent) {
exfat_msg(sb, KERN_ERR,
"unrecognized mount option \"%s\" "
"or missing value", p);
}
return -EINVAL;
}
}
out:
if (opts->allow_utime == U16_MAX)
opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH);
if (opts->utf8 && strcmp(opts->iocharset, exfat_iocharset_with_utf8)) {
exfat_msg(sb, KERN_WARNING,
"utf8 enabled, \"iocharset=%s\" is recommended",
exfat_iocharset_with_utf8);
}
if (opts->discard) {
struct request_queue *q = bdev_get_queue(sb->s_bdev);
if (!blk_queue_discard(q))
exfat_msg(sb, KERN_WARNING,
"mounting with \"discard\" option, but "
"the device does not support discard");
opts->discard = 0;
}
return 0;
}
static void exfat_hash_init(struct super_block *sb)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
int i;
spin_lock_init(&sbi->inode_hash_lock);
for (i = 0; i < EXFAT_HASH_SIZE; i++)
INIT_HLIST_HEAD(&sbi->inode_hashtable[i]);
}
static int exfat_read_root(struct inode *inode)
{
struct super_block *sb = inode->i_sb;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
FS_INFO_T *fsi = &(sbi->fsi);
DIR_ENTRY_T info;
EXFAT_I(inode)->fid.dir.dir = fsi->root_dir;
EXFAT_I(inode)->fid.dir.flags = 0x01;
EXFAT_I(inode)->fid.entry = -1;
EXFAT_I(inode)->fid.start_clu = fsi->root_dir;
EXFAT_I(inode)->fid.flags = 0x01;
EXFAT_I(inode)->fid.type = TYPE_DIR;
EXFAT_I(inode)->fid.version = 0;
EXFAT_I(inode)->fid.rwoffset = 0;
EXFAT_I(inode)->fid.hint_bmap.off = CLUS_EOF;
EXFAT_I(inode)->fid.hint_stat.eidx = 0;
EXFAT_I(inode)->fid.hint_stat.clu = fsi->root_dir;
EXFAT_I(inode)->fid.hint_femp.eidx = -1;
EXFAT_I(inode)->target = NULL;
if (exfat_read_inode(inode, &info) < 0)
return -EIO;
inode->i_uid = sbi->options.fs_uid;
inode->i_gid = sbi->options.fs_gid;
INC_IVERSION(inode);
inode->i_generation = 0;
inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, S_IRWXUGO);
inode->i_op = &exfat_dir_inode_operations;
inode->i_fop = &exfat_dir_operations;
i_size_write(inode, info.Size);
EXFAT_I(inode)->fid.size = info.Size;
inode->i_blocks = ((i_size_read(inode) + (fsi->cluster_size - 1))
& ~((loff_t)fsi->cluster_size - 1)) >> inode->i_blkbits;
EXFAT_I(inode)->i_pos = ((loff_t) fsi->root_dir << 32) | 0xffffffff;
EXFAT_I(inode)->i_size_aligned = i_size_read(inode);
EXFAT_I(inode)->i_size_ondisk = i_size_read(inode);
exfat_save_attr(inode, ATTR_SUBDIR);
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
set_nlink(inode, info.NumSubdirs + 2);
return 0;
}
static void setup_dops(struct super_block *sb)
{
if (EXFAT_SB(sb)->options.casesensitive == 0)
sb->s_d_op = &exfat_ci_dentry_ops;
else
sb->s_d_op = &exfat_dentry_ops;
}
static int exfat_fill_super(struct super_block *sb, void *data, int silent)
{
struct inode *root_inode = NULL;
struct exfat_sb_info *sbi;
int err;
char buf[50];
struct block_device *bdev = sb->s_bdev;
dev_t bd_dev = bdev ? bdev->bd_dev : 0;
exfat_log_msg(sb, KERN_INFO, "trying to mount...");
/*
* GFP_KERNEL is ok here, because while we do hold the
* supeblock lock, memory pressure can't call back into
* the filesystem, since we're only just about to mount
* it and have no inodes etc active!
*/
sbi = kzalloc(sizeof(struct exfat_sb_info), GFP_KERNEL);
if (!sbi) {
exfat_log_msg(sb, KERN_INFO,
"trying to alloc sbi with vzalloc()");
sbi = vzalloc(sizeof(struct exfat_sb_info));
if (!sbi) {
exfat_log_msg(sb, KERN_ERR, "failed to mount! (ENOMEM)");
return -ENOMEM;
}
sbi->use_vmalloc = 1;
}
mutex_init(&sbi->s_vlock);
sb->s_fs_info = sbi;
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
sb->s_flags |= MS_NODIRATIME;
#else
sb->s_flags |= SB_NODIRATIME;
#endif
sb->s_magic = EXFAT_SUPER_MAGIC;
sb->s_op = &exfat_sops;
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
DEFAULT_RATELIMIT_BURST);
err = parse_options(sb, data, silent, &sbi->options);
if (err) {
exfat_log_msg(sb, KERN_ERR, "failed to parse options");
goto failed_mount;
}
setup_exfat_xattr_handler(sb);
setup_exfat_sync_super_wq(sb);
setup_dops(sb);
err = exfat_mount(sb);
if (err) {
exfat_log_msg(sb, KERN_ERR, "failed to recognize fat type");
goto failed_mount;
}
/* set up enough so that it can read an inode */
exfat_hash_init(sb);
/*
* The low byte of FAT's first entry must have same value with
* media-field. But in real world, too many devices is
* writing wrong value. So, removed that validity check.
*
* if (FAT_FIRST_ENT(sb, media) != first)
*/
err = -EINVAL;
sprintf(buf, "cp%d", sbi->options.codepage);
sbi->nls_disk = load_nls(buf);
if (!sbi->nls_disk) {
exfat_log_msg(sb, KERN_ERR, "codepage %s not found", buf);
goto failed_mount2;
}
sbi->nls_io = load_nls(sbi->options.iocharset);
if (!sbi->nls_io) {
exfat_log_msg(sb, KERN_ERR, "IO charset %s not found",
sbi->options.iocharset);
goto failed_mount2;
}
err = -ENOMEM;
root_inode = new_inode(sb);
if (!root_inode) {
exfat_log_msg(sb, KERN_ERR, "failed to allocate root inode.");
goto failed_mount2;
}
root_inode->i_ino = EXFAT_ROOT_INO;
SET_IVERSION(root_inode, 1);
err = exfat_read_root(root_inode);
if (err) {
exfat_log_msg(sb, KERN_ERR, "failed to initialize root inode.");
goto failed_mount2;
}
exfat_attach(root_inode, EXFAT_I(root_inode)->i_pos);
insert_inode_hash(root_inode);
err = -ENOMEM;
sb->s_root = __d_make_root(root_inode);
if (!sb->s_root) {
exfat_msg(sb, KERN_ERR, "failed to get the root dentry");
goto failed_mount2;
}
/*
* Initialize filesystem attributes (for sysfs)
* ex: /sys/fs/exfat/mmcblk1[179:17]
*/
sbi->sb_kobj.kset = exfat_kset;
err = kobject_init_and_add(&sbi->sb_kobj, &exfat_ktype, NULL,
"%s[%d:%d]", sb->s_id, MAJOR(bd_dev), MINOR(bd_dev));
if (err) {
exfat_msg(sb, KERN_ERR, "Unable to create exfat attributes for"
" %s[%d:%d](%d)", sb->s_id,
MAJOR(bd_dev), MINOR(bd_dev), err);
goto failed_mount2;
}
exfat_log_msg(sb, KERN_INFO, "mounted successfully!");
return 0;
failed_mount2:
exfat_umount(sb);
failed_mount:
exfat_log_msg(sb, KERN_INFO, "failed to mount! (%d)", err);
if (root_inode)
iput(root_inode);
sb->s_root = NULL;
if (sbi->nls_io)
unload_nls(sbi->nls_io);
if (sbi->nls_disk)
unload_nls(sbi->nls_disk);
if (sbi->options.iocharset != exfat_default_iocharset)
kfree(sbi->options.iocharset);
sb->s_fs_info = NULL;
if (!sbi->use_vmalloc)
kfree(sbi);
else
vfree(sbi);
return err;
}
static struct dentry *exfat_fs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
return mount_bdev(fs_type, flags, dev_name, data, exfat_fill_super);
}
static void init_once(void *foo)
{
struct exfat_inode_info *ei = (struct exfat_inode_info *)foo;
INIT_HLIST_NODE(&ei->i_hash_fat);
inode_init_once(&ei->vfs_inode);
}
static int __init exfat_init_inodecache(void)
{
exfat_inode_cachep = kmem_cache_create("exfat_inode_cache",
sizeof(struct exfat_inode_info),
0, (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
init_once);
if (!exfat_inode_cachep)
return -ENOMEM;
return 0;
}
static void exfat_destroy_inodecache(void)
{
/*
* Make sure all delayed rcu free inodes are flushed before we
* destroy cache.
*/
rcu_barrier();
kmem_cache_destroy(exfat_inode_cachep);
}
static struct file_system_type exfat_fs_type = {
.owner = THIS_MODULE,
.name = "exfat",
.mount = exfat_fs_mount,
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
static int __init init_exfat_fs(void)
{
int err;
exfat_log_version();
err = exfat_fscore_init();
if (err)
goto error;
exfat_kset = kset_create_and_add("exfat", NULL, fs_kobj);
if (!exfat_kset) {
pr_err("exFAT: failed to create fs_kobj\n");
err = -ENOMEM;
goto error;
}
err = sysfs_create_group(&exfat_kset->kobj, &attr_group);
if (err) {
pr_err("exFAT: failed to create exfat version attributes\n");
goto error;
}
err = exfat_uevent_init(exfat_kset);
if (err)
goto error;
err = exfat_init_inodecache();
if (err) {
pr_err("exFAT: failed to initialize inode cache\n");
goto error;
}
err = register_filesystem(&exfat_fs_type);
if (err) {
pr_err("exFAT: failed to register filesystem\n");
goto error;
}
return 0;
error:
exfat_uevent_uninit();
if (exfat_kset) {
sysfs_remove_group(&exfat_kset->kobj, &attr_group);
kset_unregister(exfat_kset);
exfat_kset = NULL;
}
exfat_destroy_inodecache();
exfat_fscore_shutdown();
pr_err("exFAT: failed to initialize FS driver(err:%d)\n", err);
return err;
}
static void __exit exit_exfat_fs(void)
{
exfat_uevent_uninit();
if (exfat_kset) {
sysfs_remove_group(&exfat_kset->kobj, &attr_group);
kset_unregister(exfat_kset);
exfat_kset = NULL;
}
exfat_destroy_inodecache();
unregister_filesystem(&exfat_fs_type);
exfat_fscore_shutdown();
}
module_init(init_exfat_fs);
module_exit(exit_exfat_fs);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
MODULE_ALIAS_FS("exfat");
#endif
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("FAT/exFAT filesystem support");
MODULE_AUTHOR("Samsung Electronics Co., Ltd.");
|