249{
253
257 ULONG InitialFileSize = 0;
258 ULONG InitialValidDataLength = 0;
259
263
278
285
287
288
289
290
291
292
293
294
295
297
299
301
302
303
304
305
308
309
315
316
317
318
319
324
325
326
327
328
329
330
332
333
334
335
336
338
339 Irp->IoStatus.Information = 0;
342 }
343
344
345
346
347
348 if (!NonCachedIo &&
353
355
357
359
362 IrpContext,
365 Retrying );
366
368 }
369
370
371
372
373
374
375
378
381
382
383
384
385
387
389
390
391
392
393
395
397 }
398
400
401
402
403
404
405
406 if (PagingIo) {
408
411 } else {
413 }
414 }
415
416
417
418
419
420
421
422
423
425
426
428
429
430 Irp->IoStatus.Information = 0;
432
434 }
435 }
436
437
438
439
440
441
442
443 if (NonCachedIo) {
444
445 if (IrpContext->FatIoContext ==
NULL) {
446
448
449 IrpContext->FatIoContext =
453
454 } else {
455
456 IrpContext->FatIoContext = &StackFatIoContext;
457
459 }
460 }
461
463
465
469
470 } else {
471
472 if (PagingIo) {
473
474 IrpContext->FatIoContext->Wait.Async.ResourceThreadId =
476
477 } else {
478
479 IrpContext->FatIoContext->Wait.Async.ResourceThreadId =
480 ((
ULONG_PTR)IrpContext->FatIoContext) | 3;
481 }
482
483 IrpContext->FatIoContext->Wait.Async.RequestedByteCount =
485
486 IrpContext->FatIoContext->Wait.Async.FileObject =
FileObject;
487 }
488
489 }
490
491
492
493
494
495
497
498 Irp->IoStatus.Information = 0;
501 }
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
523
526
528 VBO StartingDirtyVbo;
529
530 ULONG DirtyByteCount;
531 ULONG CleanByteCount;
532
534
536
538
539 DebugTrace(0,
Dbg,
"Type of write is Virtual Volume File\n", 0);
540
541
542
543
544
546
548
550
552 }
553
554
555
556
557
558
559
560
562
564 }
565
566
567
568
569
570
572
573
574
575
576
577
578
579
580
581
582
583
584
585
588 &DirtyLbo,
589 &DirtyByteCount,
591
592 || ( (DirtyLbo == 0) && (DirtyByteCount >=
ByteCount) ) ) {
593
595 "No dirty fat sectors in the write range.\n", 0);
596
599 }
600
601 DirtyVbo = (
VBO)DirtyLbo;
602
603
604
605
606
607
608 if (DirtyVbo == 0) {
609
611 }
612
613
614
615
616
617 StartingDirtyVbo = DirtyVbo;
618
619
620
621
622
623
624
625 while ( MoreDirtyRuns ) {
626
627
628
629
630
631
633 DirtyVbo,
634 &DirtyLbo,
635 &DirtyByteCount,
637
638#ifdef _MSC_VER
639#pragma prefast( suppress:28931, "needed for debug build" )
640#endif
641 DirtyVbo = (
VBO)DirtyLbo;
642
643 DebugTrace(0,
Dbg,
"Last dirty fat Mcb entry was a hole: corrupt.\n", 0);
644
645#ifdef _MSC_VER
646#pragma prefast( suppress:28159, "things are seriously wrong if we get here" )
647#endif
649
650 } else {
651
652 DirtyVbo = (
VBO)DirtyLbo;
653
654
655
656
657
658
659
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
685
687
688 MoreDirtyRuns =
FALSE;
689
690 } else {
691
692
693
694
695
696
698 DirtyVbo + DirtyByteCount,
699 &CleanLbo,
700 &CleanByteCount,
702
703 MoreDirtyRuns =
FALSE;
704
705 } else {
706
707
708
709
710
711
713
714
715
716
717
718
719
720 if (DirtyVbo + DirtyByteCount + CleanByteCount >=
722
723 MoreDirtyRuns =
FALSE;
724
725 } else {
726
727
728
729
730
731 DirtyVbo += DirtyByteCount + CleanByteCount;
732 }
733 }
734 }
735 }
736 }
737
738
739
740
741
742
743
744
745 WriteLength = (DirtyVbo + DirtyByteCount) - StartingDirtyVbo;
746
747
748
749
750
751
752
755
756
757
758
759
760
761
762 {
767
769
771
775
776 } else {
777
778 IoRuns = StackIoRuns;
779 }
780
781 for (Fat = 0; Fat < (
ULONG)
Vcb->Bpb.Fats; Fat++) {
782
783 IoRuns[Fat].Vbo = StartingDirtyVbo;
784 IoRuns[Fat].Lbo = Fat * BytesPerFat + StartingDirtyVbo;
785 IoRuns[Fat].Offset = StartingDirtyVbo -
StartingVbo;
787 }
788
789
790
791
792
794
796
801 IoRuns );
802
804
805 if (IoRuns != StackIoRuns) {
806
808 }
810
811#if (NTDDI_VERSION >= NTDDI_WIN8)
812
813
814
815
816
818
820
822 0,
824 0,
825 1,
826 0 );
827 }
828
829#endif
830
831
832
833
835
836
837
838
839
841
844 "Error %X while writing volume file.\n",
845 Irp->IoStatus.Status );
846
847 RaiseIosb =
Irp->IoStatus;
848 }
849 }
850
851
852
853
854
855
856
857
858
859
860
861 Irp->IoStatus = RaiseIosb;
862
864
866 StartingDirtyVbo,
868
869 } else {
870
872 }
873
875
878 }
879
880
881
882
883
884
886
889
890
891
892
893
894
896 (
Vcb->Bpb.Sectors != 0 ?
Vcb->Bpb.Sectors :
897 Vcb->Bpb.LargeSectors));
898
899 StartingLbo = StartingByte.
QuadPart;
900
902
903
904
905
906
907
908
909
910
911
916
917
918
919
920
921 if (!WriteToEof && (StartingLbo < VolumeSize)) {
922
923
924
925
926
929
932 }
933 }
934 }
935
936
937
938
939
940
941
943
945 }
946
947
948
949
950
951
952
953
954
956
958 }
959
961
963
964
965
966
967
968
969
970
971
972
973
976
978
979
980
981
982
984
988 0,
990
991 FatPurgeReferencedFileObjects( IrpContext,
Vcb->RootDcb,
Flush );
992 }
993
995
997 if (!PreviousWait) {
999 }
1001
1004 }
1005
1007
1008
1009
1010
1011
1012
1013 if (WriteToEof || StartingLbo >= VolumeSize) {
1016 }
1017
1018 if (
ByteCount > VolumeSize - StartingLbo) {
1019
1021
1022
1023
1024
1025
1026
1028
1029 IrpContext->FatIoContext->Wait.Async.RequestedByteCount =
1031 }
1032 }
1033 } else {
1034
1035
1036
1037
1038
1039
1040 if (WriteToEof) {
1041
1042 StartingLbo = VolumeSize;
1043 }
1044 }
1045
1046
1047
1048
1049
1051
1052
1053
1054
1055
1056
1057
1058
1060
1061
1062
1063
1064
1067 StartingLbo,
1070
1071#if (NTDDI_VERSION >= NTDDI_WIN8)
1072
1073
1074
1075
1076
1078
1080
1082 0,
1084 0,
1085 1,
1086 0 );
1087 }
1088
1089#endif
1090
1092
1093
1094
1095
1096
1097 IrpContext->FatIoContext =
NULL;
1098
1100
1101 DebugTrace(-1,
Dbg,
"FatNonCachedIo -> STATUS_PENDING\n", 0);
1102
1104 }
1105
1107
1108
1109
1110
1111
1112
1113
1114
1116
1118 }
1119
1120
1121
1122
1123
1124
1125 if (SynchronousIo && !PagingIo) {
1127 StartingLbo +
Irp->IoStatus.Information;
1128 }
1129
1131
1134 }
1135
1136
1137
1138
1139
1141
1142
1143
1144
1145
1147
1148
1149
1150
1151
1153 ) {
1154
1155 ULONG ValidDataLength;
1156 ULONG ValidDataToDisk;
1157 ULONG ValidDataToCheck;
1158
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171 if (NonCachedIo && !PagingIo &&
1173
1175
1176
1177
1178
1179
1180 if (!FatAcquireExclusiveFcb( IrpContext,
FcbOrDcb )) {
1181
1183
1185 }
1186
1187 FcbOrDcbAcquired =
TRUE;
1188 FcbAcquiredExclusive =
TRUE;
1189
1190
1191
1192
1193
1195
1196#if (NTDDI_VERSION >= NTDDI_WIN7)
1197
1198
1199
1200
1201
1202 PagingIoResourceAcquired =
TRUE;
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1222 0 );
1223
1225
1226#else
1227
1232
1234
1237 }
1238
1239
1240
1241
1242
1243 PagingIoResourceAcquired =
TRUE;
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1258
1259#endif
1260
1262
1263
1264
1265
1266
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1284 }
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294 FcbCanDemoteToShared =
TRUE;
1295 }
1296
1297
1298
1299
1300
1302
1303
1304
1305
1306
1307
1308 if ( PagingIo ) {
1309
1311 PagingIoResourceAcquired =
TRUE;
1312
1314
1315 IrpContext->FatIoContext->Wait.Async.Resource =
1317 }
1318
1319
1320
1321
1322
1323
1325
1331 }
1332
1333 } else {
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351 if (!
Wait && NonCachedIo) {
1352
1353 if (!FcbOrDcbAcquired &&
1355
1358 }
1359
1360
1361
1362
1363
1364
1365
1366 IrpContext->FatIoContext->Wait.Async.Resource =
FcbOrDcb->
Header.Resource;
1367
1368 if (FcbCanDemoteToShared) {
1369
1370 IrpContext->FatIoContext->Wait.Async.Resource2 =
FcbOrDcb->
Header.PagingIoResource;
1371 }
1372 } else {
1373
1374 if (!FcbOrDcbAcquired &&
1375 !FatAcquireSharedFcb( IrpContext,
FcbOrDcb )) {
1376
1379 }
1380 }
1381
1382 FcbOrDcbAcquired =
TRUE;
1383 }
1384
1385
1386
1387
1388
1389
1390
1391
1395
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413 if ( PagingIo ) {
1414
1416
1418
1419 Irp->IoStatus.Information = 0;
1420
1422 }
1423
1425
1426 DebugTrace( 0,
Dbg,
"PagingIo extending beyond EOF.\n", 0 );
1427
1429 }
1430 }
1431
1432
1433
1434
1435
1436
1438
1439 CalledByLazyWriter =
TRUE;
1440
1442
1443
1444
1445
1446
1447
1448
1451
1452
1453
1454
1455
1456
1458
1459
1460
1461
1462
1464 }
1465 }
1466 }
1467 }
1468
1469
1470
1471
1472
1473
1476
1478
1480
1481
1482
1483
1484
1485
1486
1487
1488
1491
1493
1495
1496
1497
1498
1499
1500
1504
1505 RecursiveWriteThrough =
TRUE;
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 if ( !CalledByLazyWriter &&
1544
1545 !RecursiveWriteThrough &&
1546
1547 (WriteToEof ||
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1562
1565
1566 if (NonCachedIo) {
1567
1569
1570 SwitchBackToAsync =
TRUE;
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 if ( PagingIo ) {
1601
1603 PagingIoResourceAcquired =
FALSE;
1604
1605 } else {
1606
1607
1608
1609
1610
1611
1612 if (!FcbAcquiredExclusive) {
1613
1615 FcbOrDcbAcquired =
FALSE;
1616
1617 if (!FatAcquireExclusiveFcb( IrpContext,
FcbOrDcb )) {
1618
1620
1622 }
1623
1624 FcbOrDcbAcquired =
TRUE;
1625
1626#ifdef _MSC_VER
1627#pragma prefast( suppress:28931, "convenient for debugging" )
1628#endif
1629 FcbAcquiredExclusive =
TRUE;
1630 }
1631 }
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642 if (SwitchBackToAsync) {
1643
1647
1649
1653
1654 SwitchBackToAsync =
FALSE;
1655
1656 } else {
1657
1659
1664
1668 }
1669
1670
1671
1672
1673
1675 1,
1677
1679 }
1680
1681 UnwindOutstandingAsync =
TRUE;
1682
1684 }
1685 }
1686
1687
1688
1689
1690
1691
1695
1696
1697
1698
1699
1700
1701
1702 if ( PagingIo ) {
1703
1705 Irp->IoStatus.Information = 0;
1707 }
1708
1710
1713 }
1714 }
1715 }
1716
1717
1718
1719
1720
1721 if (NonCachedIo && !
Wait) {
1722
1723 IrpContext->FatIoContext->Wait.Async.RequestedByteCount =
1725 }
1726
1727
1728
1729
1730
1731
1733
1734 InitialValidDataLength = ValidDataLength;
1735
1736
1737
1738
1739
1740 FatVerifyFcb( IrpContext,
FcbOrDcb );
1741
1742
1743
1744
1745
1746
1747 if ( WriteToEof ) {
1748
1751
1752
1753
1754
1755
1756
1757
1758
1760
1761 Irp->IoStatus.Information = 0;
1763 }
1764
1765
1766 }
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1778
1781 IrpContext,
1784
1786
1787 OplockPostIrp =
TRUE;
1790 }
1791
1792
1793
1794
1795
1796
1797
1798
1800
1802 }
1803
1804
1805
1806
1807
1809
1811 }
1812 }
1813
1814
1815
1816
1817
1818
1819
1821
1822 ExtendingFile =
TRUE;
1823 }
1824
1825 if ( ExtendingFile ) {
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1838
1840 }
1841
1842
1843
1844
1845
1847
1848
1850
1851 FatLookupFileAllocationSize( IrpContext,
FcbOrDcb );
1852 }
1853
1854
1855
1856
1857
1858
1859
1861
1862
1864
1865
1866
1867
1868
1869
1871
1876 ULONG BytesPerCluster;
1877 ULONG ClusterAlignedFileSize;
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 BytesPerCluster = 1 <<
Vcb->AllocationSupport.LogOfBytesPerCluster;
1916
1917
1918
1919
1920
1921
1922
1923
1924 ClusterAlignedFileSize = ((
FileSize) + (BytesPerCluster - 1)) &
1925 ~(BytesPerCluster - 1);
1926
1927
1928 if (ClusterAlignedFileSize != 0) {
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941 Multiplier = ((
Vcb->AllocationSupport.NumberOfFreeClusters *
1942 (BytesPerCluster >> 5)) /
1943 (ClusterAlignedFileSize -
1945
1946 if (Multiplier > 32) { Multiplier = 32; }
1947
1948
1949
1950 AddedAllocation = Multiplier * (ClusterAlignedFileSize -
FcbOrDcb->
Header.AllocationSize.LowPart);
1951
1952 TargetAllocation =
FcbOrDcb->
Header.AllocationSize.LowPart + AddedAllocation;
1953
1954
1955
1956
1957
1958
1959
1960 if (TargetAllocation > ~BytesPerCluster + 1) {
1961
1962 TargetAllocation = ~BytesPerCluster + 1;
1963 AddedAllocation = TargetAllocation -
FcbOrDcb->
Header.AllocationSize.LowPart;
1964 }
1965
1966
1967
1968
1969
1970
1971
1972
1973 ApproximateClusterCount = (AddedAllocation / BytesPerCluster);
1974
1975 if (ApproximateClusterCount <= Vcb->AllocationSupport.NumberOfFreeClusters) {
1976
1978
1979 FatAddFileAllocation( IrpContext,
1982 (
ULONG)TargetAllocation );
1983
1984 AllocateMinimumSize =
FALSE;
1986
1989
1992 }
1993 }
1994 }
1995
1996 if ( AllocateMinimumSize ) {
1997
1998
1999 FatAddFileAllocation( IrpContext,
2003
2004
2005 }
2006
2007
2008
2009
2010
2011
2013
2014
2015 }
2016
2017
2018
2019
2020
2021
2023
2024
2026
2027
2028
2029
2030
2031
2034 }
2035 }
2036
2037
2038
2039
2040
2041 if ( !CalledByLazyWriter &&
2042 !RecursiveWriteThrough &&
2044
2045 ExtendingValidData =
TRUE;
2046
2047 } else {
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062 if (FcbCanDemoteToShared) {
2063
2066 FcbAcquiredExclusive =
FALSE;
2067 }
2068 }
2069
2070 if (ValidDataToDisk > ValidDataLength) {
2071
2072 ValidDataToCheck = ValidDataToDisk;
2073
2074 } else {
2075
2076 ValidDataToCheck = ValidDataLength;
2077 }
2078
2079
2080
2081
2082
2083
2084
2085 if ( NonCachedIo ) {
2086
2087
2088
2089
2090
2091
2092
2094
2096
2098
2099
2100
2101
2102
2103
2105
2108
2109
2110
2111
2112
2113
2115
2118
2120
2121 DebugTrace( 0,
Dbg,
"FatCommonWrite -> STATUS_NOT_IMPLEMENTED\n", 0);
2123 }
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144 if (!CalledByLazyWriter &&
2145 !RecursiveWriteThrough &&
2147
2151 ValidDataToCheck,
2153 }
2154
2155
2156
2157
2158
2159
2160
2161 WriteFileSizeToDirent =
TRUE;
2162
2163
2164
2165
2166
2167 if (SwitchBackToAsync) {
2168
2171 }
2172
2173#ifdef SYSCACHE_COMPILE
2174
2175#define MY_SIZE 0x1000000
2176#define LONGMAP_COUNTER
2177
2178#ifdef BITMAP
2179
2180
2181
2182
2183 {
2185
2186 if (
NULL == WriteMask) {
2187
2190 'wtaF' );
2191
2194 }
2195
2197
2200
2201 if (Off +
Len > MY_SIZE) {
2202 Len = MY_SIZE - Off;
2203 }
2204
2208
2211 break;
2212 }
2214 }
2215 }
2216 }
2217#endif
2218
2219#ifdef LONGMAP_COUNTER
2220
2221
2222
2223
2224
2225
2226
2227 {
2229
2231
2234 'wtaF' );
2235
2238 }
2239
2241
2245
2246 if (Off +
Len > MY_SIZE) {
2247 Len = MY_SIZE - Off;
2248 }
2249
2252
2255 break;
2256 }
2258 }
2259 }
2260 }
2261#endif
2262
2263#endif
2264
2265
2266 if (FatNonCachedIo( IrpContext,
2270 BytesToWrite,
2271 BytesToWrite,
2273
2274
2275 UnwindOutstandingAsync =
FALSE;
2276
2277#ifdef _MSC_VER
2278#pragma prefast( suppress:28931, "convenient for debugging" )
2279#endif
2282
2283 IrpContext->FatIoContext =
NULL;
2285
2286
2287
2288
2289
2290
2291
2292
2294
2296 }
2297
2298
2299
2300
2301
2303
2305
2306 } else {
2307
2308 ULONG NewValidDataToDisk;
2309
2310
2311
2312
2313
2314
2315 NT_ASSERT(
Irp->IoStatus.Information == BytesToWrite );
2316
2318
2319
2320
2321
2322
2324
2325 if (NewValidDataToDisk >
FileSize) {
2327 }
2328
2331 }
2332 }
2333
2334
2335
2336
2337
2338
2340
2341 }
2342
2343
2344
2345
2346
2347
2348 else {
2349
2351
2352
2353
2354
2355
2356
2357
2359
2361
2362
2363
2364
2365
2366
2368
2369 FatLookupFileAllocationSize( IrpContext,
FcbOrDcb );
2370 }
2371
2373
2374 FatPopUpFileCorrupt( IrpContext,
FcbOrDcb );
2375
2377 }
2378
2379
2380
2381
2382
2388
2390
2391
2392
2393
2394
2395
2396
2397
2400
2403
2405
2406 } else {
2407
2410
2411
2412
2413
2414
2418
2420
2423 FlushContext );
2424
2425
2426
2427
2428
2429
2431
2433
2434
2435
2436
2437
2439
2441 OneSecondFromNow,
2442 &FlushContext->
Dpc );
2443 }
2444 }
2445 }
2446
2447
2448
2449
2450
2451
2453
2454
2455
2456
2457
2461 ValidDataToCheck,
2463
2464 DebugTrace( 0,
Dbg,
"Cached Write could not wait to zero\n", 0 );
2465
2467 }
2468 }
2469
2472
2473
2474
2475
2476
2477
2479
2481
2482
2483
2484
2485
2487
2488
2489
2490
2491
2492#if (NTDDI_VERSION >= NTDDI_WIN8)
2494 &StartingByte,
2497 SystemBuffer,
2498 Irp->Tail.Overlay.Thread )) {
2499#else
2501 &StartingByte,
2504 SystemBuffer )) {
2505#endif
2506
2508
2510 }
2511
2514
2516
2517 } else {
2518
2519
2520
2521
2522
2524
2526
2528 &StartingByte,
2532
2534
2536 }
2537 }
2538 }
2539
2540
2541
2542
2543
2544
2546 ) {
2547
2549
2550#if FASTFATDBG
2555 }
2556#endif
2557
2558
2559
2560
2561
2562 FatVerifyFcb( IrpContext,
FcbOrDcb );
2563
2564
2565
2566
2567
2568
2571
2573
2575 }
2576
2577 PagingIoResourceAcquired =
TRUE;
2578
2580
2581 IrpContext->FatIoContext->Wait.Async.Resource =
2583 }
2584
2585
2586
2587
2588
2589
2591
2597 }
2598
2599
2600
2601
2602
2603
2604
2605
2607
2609 }
2610
2611
2612
2613
2614
2615
2616#ifdef _MSC_VER
2617#pragma prefast( suppress:28931, "needed for debug build" )
2618#endif
2620
2621
2622
2623
2624
2625
2628
2629
2630
2631
2632
2633
2634
2635
2637
2638 DebugTrace( 0,
Dbg,
"PagingIo dirent started beyond EOF.\n", 0 );
2639
2640 Irp->IoStatus.Information = 0;
2641
2643 }
2644
2646
2647 DebugTrace( 0,
Dbg,
"PagingIo dirent extending beyond EOF.\n", 0 );
2649 }
2650
2651
2652
2653
2654
2655
2656 if (FatNonCachedIo( IrpContext,
2663
2664 IrpContext->FatIoContext =
NULL;
2665
2667
2669 }
2670
2671
2672
2673
2674
2675
2676
2677
2678
2680
2682 }
2683
2685 }
2686
2687
2688
2689
2690
2691
2693
2694 DebugTrace( 0,
Dbg,
"FatCommonWrite -> STATUS_INVALID_PARAMETER\n", 0);
2695
2697 }
2698
2699
2700
2701
2702
2704
2705#ifdef _MSC_VER
2706#pragma prefast( suppress:28159, "things are seriously wrong if we get here" )
2707#endif
2709
2711
2712
2713
2714
2715
2716
2717
2719
2720 if ( !PostIrp ) {
2721
2722 ULONG ActualBytesWrote;
2723
2724 DebugTrace( 0,
Dbg,
"Completing request with status = %08lx\n",
2726
2728 Irp->IoStatus.Information);
2729
2730
2731
2732
2733
2734 ActualBytesWrote = (
ULONG)
Irp->IoStatus.Information;
2735
2736
2737
2738
2739
2740
2741 if (SynchronousIo && !PagingIo) {
2742
2745 }
2746
2747
2748
2749
2750
2752
2753
2754
2755
2756
2757
2758 if ( !PagingIo ) {
2759
2761 }
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771 if ( ExtendingFile && WriteFileSizeToDirent ) {
2772
2774
2776
2777
2778
2779
2780
2786 }
2787
2788 if ( ExtendingFile && !WriteFileSizeToDirent ) {
2789
2791 }
2792
2793 if ( ExtendingValidData ) {
2794
2796
2797
2798
2799
2800
2801 if (
FileSize < EndingVboWritten ) {
2802
2804
2805 } else {
2806
2808 }
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2822 }
2823 }
2824
2825 }
2826
2827
2828
2829
2830
2831
2832
2834
2835 } else {
2836
2837
2838
2839
2840
2841 if (!OplockPostIrp) {
2842
2844
2845 if ( ExtendingFile ) {
2846
2847
2848
2849
2850
2851
2853
2855
2857
2859
2860
2861
2862
2863
2865
2867 }
2868
2870 }
2871
2873
2875 }
2876 }
2877 }
2878
2880
2882
2884
2885
2886
2887
2888
2889 if (ExtendingFile || ExtendingValidData) {
2890
2891
2892
2893
2894
2896 FcbOrDcb->
Header.ValidDataLength.LowPart = InitialValidDataLength;
2897
2899
2900
2901
2902
2903
2905
2907 }
2908 }
2909 }
2910
2911
2912
2913
2914
2915 if (UnwindOutstandingAsync) {
2916
2918 0xffffffff,
2920 }
2921
2922
2923
2924
2925
2926 if (FcbOrDcbAcquired &&
Irp) {
2927
2929 }
2930
2931 if (PagingIoResourceAcquired &&
Irp) {
2932
2934 }
2935
2936
2937
2938
2939
2940
2941
2942
2944
2946 }
2947
2950
2952}
#define InterlockedIncrement
#define InterlockedExchange
#define READ_AHEAD_GRANULARITY
PEPROCESS __stdcall PsGetThreadProcess(_In_ PETHREAD Thread)
VOID NTAPI CcPrepareMdlWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, OUT PMDL *MdlChain, OUT PIO_STATUS_BLOCK IoStatus)
VOID NTAPI CcSetReadAheadGranularity(IN PFILE_OBJECT FileObject, IN ULONG Granularity)
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
NTKERNELAPI VOID NTAPI CcCoherencyFlushAndPurgeCache(_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_opt_ PLARGE_INTEGER FileOffset, _In_ ULONG Length, _Out_ PIO_STATUS_BLOCK IoStatus, _In_opt_ ULONG Flags)
#define CcGetFileSizePointer(FO)
#define CcIsFileCached(FO)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
enum _TYPE_OF_OPEN TYPE_OF_OPEN
#define CCB_FLAG_ALLOW_EXTENDED_DASD_IO
#define IRP_CONTEXT_FLAG_IN_FSP
#define IRP_CONTEXT_FLAG_WAIT
#define NT_SUCCESS(StatCode)
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
_In_ PIO_STACK_LOCATION IrpSp
#define FatReservedBytes(B)
#define FatBytesPerFat(B)
#define TAG_DEFERRED_FLUSH_CONTEXT
#define TAG_FAT_IO_CONTEXT
#define FatBugCheck(A, B, C)
KDEFERRED_ROUTINE FatDeferredFlushDpc
#define CollectWriteStats(VCB, OPEN_TYPE, BYTE_COUNT)
#define PsGetCurrentThread()
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
#define KeInitializeEvent(pEvt, foo, foo2)
#define ExGetCurrentResourceThread()
#define ExConvertExclusiveToSharedLite(res)
#define ExAcquireResourceExclusiveLite(res, wait)
#define ExAcquireResourceSharedLite(res, wait)
VOID NTAPI KeClearEvent(IN PKEVENT Event)
#define ClearFlag(_F, _SF)
#define IRP_CONTEXT_FLAG_USER_IO
#define FILE_WRITE_TO_END_OF_FILE
#define IRP_CONTEXT_FLAG_WRITE_THROUGH
#define IRP_CONTEXT_STACK_IO_CONTEXT
#define BooleanFlagOn(F, SF)
VOID FatUnpinRepinnedBcbs(IN PIRP_CONTEXT IrpContext)
VOID FatInitializeCacheMap(_In_ PFILE_OBJECT FileObject, _In_ PCC_FILE_SIZES FileSizes, _In_ BOOLEAN PinAccess, _In_ PCACHE_MANAGER_CALLBACKS Callbacks, _In_ PVOID LazyWriteContext)
FINISHED FatZeroData(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PFILE_OBJECT FileObject, IN ULONG StartingZero, IN ULONG ByteCount)
PVOID FatMapUserBuffer(IN PIRP_CONTEXT IrpContext, IN OUT PIRP Irp)
VOID FatMultipleAsync(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN PIRP MasterIrp, IN ULONG MultipleIrpCount, IN PIO_RUN IoRuns)
VOID FatWaitSync(IN PIRP_CONTEXT IrpContext)
VOID FatSingleAsync(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb, IN LBO Lbo, IN ULONG ByteCount, IN PIRP Irp)
VOID FatLockUserBuffer(IN PIRP_CONTEXT IrpContext, IN OUT PIRP Irp, IN LOCK_OPERATION Operation, IN ULONG BufferLength)
LOGICAL FatDiskAccountingEnabled
#define DebugDump(STR, LEVEL, PTR)
VOID FatQuickVerifyVcb(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
#define FatDeleteIrpContext(IRPCONTEXT)
IN PVCB IN VBO StartingVbo
NTSTATUS FatFsdPostRequest(IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
#define FatAcquireExclusiveVolume(IRPCONTEXT, VCB)
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
BOOLEAN FatLookupMcbEntry(IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, OUT PLBO Lbo, OUT PULONG ByteCount OPTIONAL, OUT PULONG Index OPTIONAL)
#define FatReleaseVolume(IRPCONTEXT, VCB)
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
#define FatNotifyReportChange(I, V, F, FL, A)
#define FatReleaseFcb(IRPCONTEXT, Fcb)
NTSTATUS FatFlushFat(IN PIRP_CONTEXT IrpContext, IN PVCB Vcb)
VOID NTAPI FatPrePostIrp(IN PVOID Context, IN PIRP Irp)
#define FatResetExceptionState(IRPCONTEXT)
VOID FatRemoveMcbEntry(IN PVCB Vcb, IN PLARGE_MCB Mcb, IN VBO Vbo, IN ULONG SectorCount)
#define FatIsFastIoPossible(FCB)
VOID NTAPI FatOplockComplete(IN PVOID Context, IN PIRP Irp)
#define FatNormalizeAndRaiseStatus(IRPCONTEXT, STATUS)
#define FatRaiseStatus(IRPCONTEXT, STATUS)
_Acquires_shared_lock_ Fcb FINISHED FatAcquireSharedFcbWaitForEx(IN PIRP_CONTEXT IrpContext, IN PFCB Fcb)
#define FatGetFcbOplock(F)
VOID FatAddToWorkque(IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
static INLINE BOOLEAN FatIsIoRangeValid(IN PVCB Vcb, IN LARGE_INTEGER Start, IN ULONG Length)
#define IRP_CONTEXT_FLAG_RECURSIVE_CALL
#define VCB_STATE_FLAG_LOCKED
#define VCB_STATE_FLAG_SHUTDOWN
#define IRP_CONTEXT_FLAG_DEFERRED_WRITE
#define VCB_STATE_FLAG_DEFERRED_FLUSH
#define IRP_CONTEXT_FLAG_OVERRIDE_VERIFY
#define FCB_LOOKUP_ALLOCATIONSIZE_HINT
#define FCB_STATE_TRUNCATE_ON_CLOSE
#define CCB_FLAG_DASD_FLUSH_DONE
#define CCB_FLAG_SENT_FORMAT_UNIT
#define IRP_CONTEXT_FLAG_DISABLE_WRITE_THROUGH
#define CCB_FLAG_DASD_PURGE_DONE
#define CCB_FLAG_COMPLETE_DISMOUNT
BOOLEAN NTAPI FsRtlCheckLockForWriteAccess(IN PFILE_LOCK FileLock, IN PIRP Irp)
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
#define FSRTL_CACHE_TOP_LEVEL_IRP
#define FSRTL_FLAG_USER_MAPPED_FILE
#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
#define EXCEPTION_EXECUTE_HANDLER
#define EXCEPTION_CONTINUE_SEARCH
ULONG NTAPI ExInterlockedAddUlong(IN OUT PULONG Addend, IN ULONG Increment, IN OUT PKSPIN_LOCK Lock)
ULONG NTAPI FsRtlNumberOfRunsInLargeMcb(IN PLARGE_MCB Mcb)
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
#define Int32x32To64(a, b)
BOOLEAN NTAPI CcCopyWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN PVOID Buffer)
BOOLEAN NTAPI CcCanIWrite(IN PFILE_OBJECT FileObject, IN ULONG BytesToWrite, IN BOOLEAN Wait, IN UCHAR Retrying)
VOID NTAPI CcDeferWrite(IN PFILE_OBJECT FileObject, IN PCC_POST_DEFERRED_WRITE PostRoutine, IN PVOID Context1, IN PVOID Context2, IN ULONG BytesToWrite, IN BOOLEAN Retrying)
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
#define STATUS_PURGE_FAILED
#define STATUS_FILE_LOCK_CONFLICT
#define STATUS_NOT_IMPLEMENTED
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
#define _SEH2_AbnormalTermination()
KSPIN_LOCK GeneralSpinLock
CACHE_MANAGER_CALLBACKS CacheManagerCallbacks
union _FCB::@729 Specific
struct _FCB::@729::@732 Fcb
FSRTL_ADVANCED_FCB_HEADER Header
CLONG PurgeFailureModeEnableCount
struct _IO_STACK_LOCATION::@3974::@3979 Write
union _IO_STACK_LOCATION::@1575 Parameters
PKEVENT OutstandingAsyncEvent
ULONG OutstandingAsyncWrites
SECTION_OBJECT_POINTERS SectionObjectPointers
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
#define RtlZeroMemory(Destination, Length)
#define STATUS_ACCESS_DENIED
#define STATUS_INVALID_PARAMETER
#define STATUS_FILE_CORRUPT_ERROR
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
_In_ WDFDPC _In_ BOOLEAN Wait
VOID(NTAPI * PCC_POST_DEFERRED_WRITE)(_In_ PVOID Context1, _In_ PVOID Context2)
#define FILE_NOTIFY_CHANGE_SIZE
#define FILE_ACTION_MODIFIED
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
#define SL_FORCE_DIRECT_WRITE
#define FO_FILE_SIZE_CHANGED
#define FO_SYNCHRONOUS_IO
#define IRP_SYNCHRONOUS_PAGING_IO
#define ObReferenceObject