115{
120 SIZE_T NumberBytesWritten = 0;
129
130
132
135
138
140
153
155
157
158
160
163 UDFPrint((
" FSRTL_FSP_TOP_LEVEL_IRP\n"));
164 break;
166 UDFPrint((
" FSRTL_CACHE_TOP_LEVEL_IRP\n"));
167 break;
169 UDFPrint((
" FSRTL_MOD_WRITE_TOP_LEVEL_IRP\n"));
170 break;
172 UDFPrint((
" FSRTL_FAST_IO_TOP_LEVEL_IRP\n"));
174 break;
176 UDFPrint((
" NULL TOP_LEVEL_IRP\n"));
177 break;
178 default:
181 } else {
182 UDFPrint((
" RECURSIVE_IRP, TOP = %x\n", TopIrp));
183 }
184 break;
185 }
186
187
190 MmPrint((
" Enter Irp, MDL=%x\n",
Irp->MdlAddress));
191 if(
Irp->MdlAddress) {
193 }
194
197
198
199
200
202
203
205
207 }
208
209
212 }
213
214
220
224 }
225
226
229 }
231
232
233
234
235
237
242 UDFPrint((
" Flags: %s; %s; %s; %s; Irp(W): %8.8x\n",
243 CanWait ? "Wt" : "nw", PagingIo ? "Pg" : "np",
244 NonBufferedIo ? "NBuf" : "buff", SynchronousIo ? "Snc" : "Asc",
246
248
250 if(!Res1Acq) {
252 }
254 if(!Res2Acq) {
256 }
257
258 if(!NonBufferedIo &&
265 } else {
269 }
270 }
271
272
275
276 if (SynchronousIo && !PagingIo &&
NT_SUCCESS(RC)) {
277
279 }
281 }
282
283
284
285 if (!PagingIo &&
288 }
289
290
291
292
294
295
297 if(!CanWait)
299
302 }
303
305
306 UDFPrint((
" UDF_IRP_CONTEXT_FLUSH2_REQUIRED\n"));
308
311 }
312#ifdef UDF_DELAYED_CLOSE
314#endif
315
316 }
317
318
320 PtrResourceAcquired = &(
Vcb->VCBResource);
321
322
324
326 }
327#if defined(_MSC_VER) && !defined(__clang__)
328
329 if(PagingIo) {
332 }
333#endif
334
335
338 }
340 if(!SystemBuffer)
342
343
346
347
349
352 &NumberBytesWritten);
355 }
356
359 }
360
361
362 if(!NonBufferedIo) {
363
364 if(
Vcb->VerifyCtx.QueuedCount ||
367 }
368 } else {
371 }
372 }
373
374
375
376
377
378
379
380
381
383
384 if (!NonBufferedIo) {
387
388
390 UDFPrint((
"UDFCommonWrite: Defer write\n"));
391 MmPrint((
" CcDeferWrite()\n"));
394 }
395 }
396
397
398
400 NonBufferedIo =
TRUE;
401 }
402
403
404
405
409 }
410
411
412
413
414
419 } else
422 }
423 }
424
425
426
429 }
430
431
432
433
434
435
438 TruncatedLength = 0;
439 } else {
441 }
443 } else {
445 }
446
447#if defined(_MSC_VER) && !defined(__clang__)
448
449 if(PagingIo) {
452 }
453#endif
454
455
456
457
458
459
460
461
462
463
464
465 if ( NonBufferedIo &&
466 !PagingIo &&
467 NtReqFcb->SectionObject.DataSectionObject &&
468 TruncatedLength &&
470
471 if(!Res1Acq) {
472
475 }
476 PtrResourceAcquired = &(
NtReqFcb->MainResource);
477 }
478
479 if(!Res2Acq) {
480
481
483 PtrResourceAcquired2 = &(
NtReqFcb->PagingIoResource);
484 }
485
486
487 if((
ByteOffset.QuadPart + TruncatedLength) >
NtReqFcb->CommonFCBHeader.FileSize.QuadPart) {
488 NumberBytesWritten = TruncatedLength;
489 } else {
491 }
492
493 MmPrint((
" CcFlushCache()\n"));
495
496 if(PtrResourceAcquired2) {
498 PtrResourceAcquired2 =
NULL;
499 }
500
502 NumberBytesWritten = 0;
504 }
505
506 if(!Res2Acq) {
507
508
509
512 }
513
514
515 MmPrint((
" CcPurgeCacheSection()\n"));
517 NumberBytesWritten,
FALSE);
518 NumberBytesWritten = 0;
519
520 if(PtrResourceAcquired) {
522 PtrResourceAcquired =
NULL;
523 }
524 }
525
526
527
529
530
531 if(PagingIo) {
532
533
535 if(!IsThisADeferredWrite) {
536 if(!Res2Acq) {
537
540 }
541
542 PtrResourceAcquired2 = &(
NtReqFcb->PagingIoResource);
543 }
544 }
545 } else {
546
547 if(NonBufferedIo) {
548 if(!Res2Acq) {
550
552 }
553 PtrResourceAcquired2 = &(
NtReqFcb->PagingIoResource);
554 }
555 } else {
556 if(!Res1Acq) {
559
561 }
562 PtrResourceAcquired = &(
NtReqFcb->MainResource);
563 }
564 }
565
566 }
567
568
570
571
572
573
576
577
578
580
584
585
586
589
590 RecursiveWriteThrough =
TRUE;
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 OldVDL =
NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart;
620
621 if (!PagingIo &&
622 !RecursiveWriteThrough &&
623 !IsThisADeferredWrite) {
624
626
627 ExtendFS = (
ByteOffset.QuadPart + TruncatedLength >
NtReqFcb->CommonFCBHeader.FileSize.QuadPart);
628
629 if( WriteToEOF || ZeroBlock || ExtendFS) {
630
631
632 if(!CanWait)
634
635
636 if (PtrResourceAcquired2) {
638 PtrResourceAcquired2 =
NULL;
639 }
640 if (PtrResourceAcquired) {
642 PtrResourceAcquired =
NULL;
643 }
646 }
648 if(!Res1Acq) {
649
653 }
654
655 PtrResourceAcquired = &(
NtReqFcb->MainResource);
656 }
657
658 if(!Res2Acq) {
659
660 AdPrint((
" Try to acquire PagingIoRes\n"));
662 PtrResourceAcquired2 = &(
NtReqFcb->PagingIoResource);
663 }
664 AdPrint((
" PagingIoRes Ok, Resizing...\n"));
665
666 if(ExtendFS) {
668
670 if(PtrResourceAcquired2) {
672 PtrResourceAcquired2 =
NULL;
673 }
675 }
677
680 if(!
Vcb->LowFreeSpace) {
682 } else {
684 }
686 }
687
688 UDFPrint((
"UDFCommonWrite: Set size %x (alloc size %x)\n",
ByteOffset.LowPart + TruncatedLength,
NtReqFcb->CommonFCBHeader.AllocationSize.LowPart));
690 if(ExtendFS) {
691 MmPrint((
" CcSetFileSizes()\n"));
694 }
695
696
697
698
699
700 if(ZeroBlock) {
702 ThPrint((
" UDFZeroDataEx(1)\n"));
704 OldVDL,
705 NtReqFcb->CommonFCBHeader.FileSize.QuadPart - OldVDL,
707#ifdef UDF_DBG
708 ZeroBlockDone =
TRUE;
709#endif
710 }
711 }
712 if (PtrResourceAcquired2) {
714 PtrResourceAcquired2 =
NULL;
715 }
716
717
722 } else {
726 }
727 }
728
729 }
730
731#ifdef UDF_DISABLE_SYSTEM_CACHE_MANAGER
732 NonBufferedIo =
TRUE;
733#endif
734 if(
Fcb &&
Fcb->FileInfo &&
Fcb->FileInfo->Dloc) {
735 AdPrint((
"UDFCommonWrite: DataLoc %x, Mapping %x\n",
Fcb->FileInfo->Dloc->DataLoc,
Fcb->FileInfo->Dloc->DataLoc.Mapping));
736 }
737
738
739 if (!NonBufferedIo) {
740
741
742
744
745
746 UDFPrint((
"UDFCommonWrite: Init system cache\n"));
747 MmPrint((
" CcInitializeCacheMap()\n"));
752 MmPrint((
" CcSetReadAheadGranularity()\n"));
754
755 }
756
757 if(ZeroBlock && !ZeroBlockDone) {
758 ThPrint((
" UDFZeroDataEx(2)\n"));
760 OldVDL,
761 ByteOffset.QuadPart + TruncatedLength - OldVDL,
764 }
765 }
766
769
771
772
773 MmPrint((
" CcPrepareMdlWrite()\n"));
774
775
776
777
778 NumberBytesWritten = 0;
780
782 }
783
784 if(
NtReqFcb->SectionObject.DataSectionObject &&
785 TruncatedLength >= 0x10000 &&
788
789
790
791
792 MmPrint((
" CcFlushCache() 16Mb\n"));
793
794
795
797
798 }
799
800
801
802
803
804
806 if(!SystemBuffer)
810 PerfPrint((
"UDFCommonWrite: CcCopyWrite %x bytes at %x\n", TruncatedLength,
ByteOffset.LowPart));
813
814
815
817 }
818
820
822 NumberBytesWritten = TruncatedLength;
823
825
826 } else {
827
828 MmPrint((
" Write NonBufferedIo\n"));
829
830
831
832
833 if (!RecursiveWriteThrough &&
834 !IsThisADeferredWrite &&
836#ifdef UDF_DBG
838#endif
840 OldVDL,
843 }
844 if(OldVDL < (
ByteOffset.QuadPart + TruncatedLength)) {
845 NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart =
ByteOffset.QuadPart + TruncatedLength;
846 }
847
848#if 1
850 UDFPrint((
"FSRTL_MOD_WRITE_TOP_LEVEL_IRP => CanWait\n"));
852 } else
854 UDFPrint((
"FSRTL_CACHE_TOP_LEVEL_IRP => CanWait\n"));
856 }
857
861 } else
862 {}
863
864
865
866
867#endif
869 MmPrint((
" !PASSIVE_LEVEL\n"));
872 }
873
875 UDFPrint((
"UDFCommonWrite: Cached => CanWait\n"));
878 }
879
880 if(!CanWait) {
881 UDFPrint((
"UDFCommonWrite: Post physical write %x bytes at %x\n", TruncatedLength,
ByteOffset.LowPart));
882
884 }
885
886 if(!Res2Acq) {
888 PtrResourceAcquired2 = &(
NtReqFcb->PagingIoResource);
889 }
890 }
891
892 PerfPrint((
"UDFCommonWrite: Physical write %x bytes at %x\n", TruncatedLength,
ByteOffset.LowPart));
893
894
897 }
898
900 if(!SystemBuffer) {
902 }
905 CacheLocked, (
PCHAR)SystemBuffer, &NumberBytesWritten);
906
908
909#if defined(_MSC_VER) && !defined(__clang__)
910
911 if(PagingIo) {
913 } else {
915 }
916#endif
917 WriteFileSizeToDirNdx =
TRUE;
918
920 }
921
923
925
926 if(CacheLocked) {
928 }
929
930
931 if(PtrResourceAcquired2) {
933 }
934 if(PtrResourceAcquired) {
936 (PtrResourceAcquired ==
939 }
941 }
942 if(VcbAcquired) {
944 }
945
946
948
949
950
954 }
955 if(PagingIo) {
956 if(Res1Acq) {
958 }
959 if(Res2Acq) {
961 }
962 }
963
964
965
967
968 } else {
969
970
971 if (SynchronousIo && !PagingIo &&
NT_SUCCESS(RC)) {
973 }
974
975
976
979
980
982 if(Resized) {
983 if(!WriteFileSizeToDirNdx) {
985 } else {
988 }
989 }
990
991 if(!IsThisADeferredWrite &&
993 if(
NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart < (
ByteOffset.QuadPart + NumberBytesWritten)) {
994
995 NtReqFcb->CommonFCBHeader.ValidDataLength.QuadPart =
998 }
999 }
1000 }
1001
1002
1003
1004
1005
1006
1007
1010 Irp->IoStatus.Status = RC;
1011 Irp->IoStatus.Information = NumberBytesWritten;
1012
1013 MmPrint((
" Complete Irp, MDL=%x\n",
Irp->MdlAddress));
1014 if(
Irp->MdlAddress) {
1016 }
1018 }
1019
1021
1022 }
1024
1026 return(RC);
1027}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
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)
#define CcIsFileCached(FO)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
VOID UDFCloseAllDelayed(IN PVCB Vcb)
#define NT_SUCCESS(StatCode)
_In_ PIO_STACK_LOCATION IrpSp
BOOLEAN UDFAcquireResourceExclusiveWithCheck(IN PERESOURCE Resource)
NTSTATUS UDFPostRequest(IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp)
VOID UDFReleaseIrpContext(PtrUDFIrpContext PtrIrpContext)
ULONG UDFIsResourceAcquired(IN PERESOURCE Resource)
#define CollectStatistics(VCB, Field)
__inline VOID UDFNotifyFullReportChange(PVCB V, PUDF_FILE_INFO FI, ULONG E, ULONG A)
#define CollectStatisticsEx(VCB, Field, a)
#define CollectStatistics2(VCB, Field)
#define UDFReleaseResource(Resource)
#define UDFAcquireResourceShared(Resource, CanWait)
#define UDFAcquireResourceExclusive(Resource, CanWait)
#define KeGetCurrentIrql()
#define UDFAcquireSharedStarveExclusive(Resource, CanWait)
#define FILE_WRITE_TO_END_OF_FILE
FAST_IO_POSSIBLE NTAPI UDFIsFastIoPossible(IN PtrUDFFCB Fcb)
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
BOOLEAN NTAPI FsRtlCheckLockForWriteAccess(IN PFILE_LOCK FileLock, IN PIRP Irp)
ULONG UDFFlushLogicalVolume(IN PtrUDFIrpContext PtrIrpContext, IN PIRP Irp, IN PVCB Vcb, IN ULONG FlushFlags)
#define FSRTL_FSP_TOP_LEVEL_IRP
#define FSRTL_CACHE_TOP_LEVEL_IRP
#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG
#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP
#define FSRTL_FAST_IO_TOP_LEVEL_IRP
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
#define FILE_USE_FILE_POINTER_POSITION
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)
#define IoCompleteRequest
PIRP NTAPI IoGetTopLevelIrp(VOID)
#define STATUS_FILE_LOCK_CONFLICT
OSSTATUS UDFTWrite(IN void *_Vcb, IN void *Buffer, IN SIZE_T Length, IN uint32 LBA, OUT PSIZE_T WrittenBytes, IN uint32 Flags)
#define UDFZeroDataEx(NtReqFcb, Offset, Length, CanWait, Vcb, FileObject)
NTSTATUS UDFLockCallersBuffer(PtrUDFIrpContext PtrIrpContext, PIRP Irp, BOOLEAN IsReadOperation, uint32 Length)
VOID UDFMdlComplete(PtrUDFIrpContext PtrIrpContext, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN ReadCompletion)
PVOID UDFGetCallersBuffer(PtrUDFIrpContext PtrIrpContext, PIRP Irp)
NTSTATUS UDFUnlockCallersBuffer(PtrUDFIrpContext PtrIrpContext, PIRP Irp, PVOID SystemBuffer)
#define UDFCloseAllSystemDelayedInDir(Vcb, FI)
#define _SEH2_AbnormalTermination()
VOID UDFVVerify(IN PVCB Vcb, IN ULONG Flags)
#define UDF_IRP_CONTEXT_RES1_ACQ
#define UDF_IRP_CONTEXT_DEFERRED_WRITE
#define UDF_IRP_CONTEXT_NOT_TOP_LEVEL
#define UDF_IRP_CONTEXT_FLUSH2_REQUIRED
#define UDF_FCB_PAGE_FILE
#define UDF_IRP_CONTEXT_CAN_BLOCK
#define UDF_IRP_CONTEXT_FORCED_POST
struct _UDFContextControlBlock * PtrUDFCCB
#define UDF_IRP_CONTEXT_WRITE_THROUGH
#define UDF_NTREQ_FCB_MODIFIED
#define UDF_NODE_TYPE_VCB
#define UDF_FCB_DIRECTORY
#define UDF_IRP_CONTEXT_RES2_ACQ
struct _FCB::@729::@732 Fcb
union _IO_STACK_LOCATION::@1579 Parameters
struct _IO_STACK_LOCATION::@3978::@3983 Write
#define UDF_VCB_FLAGS_VOLUME_MOUNTED
#define UDF_VCB_FLAGS_VOLUME_LOCKED
#define UDF_VCB_FLAGS_UNSAFE_IOCTL
#define UDF_VCB_FLAGS_VOLUME_READ_ONLY
#define UDF_VCB_FLAGS_RAW_DISK
#define UDF_VCB_FLAGS_MEDIA_READ_ONLY
#define UDF_VCB_FLAGS_SHUTDOWN
#define UDF_VCB_SKIP_EJECT_CHECK
OSSTATUS UDFWriteFile__(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 Offset, IN SIZE_T Length, IN BOOLEAN Direct, IN int8 *Buffer, OUT PSIZE_T WrittenBytes)
void UDFSetFileSizeInDirNdx(IN PVCB Vcb, IN PUDF_FILE_INFO FileInfo, IN int64 *ASize)
OSSTATUS UDFResizeFile__(IN PVCB Vcb, IN OUT PUDF_FILE_INFO FileInfo, IN int64 NewLength)
#define UDFIsFileCached__(Vcb, FileInfo, Offset, Length, ForWrite)
#define UDF_MAX_VERIFY_CACHE
#define UFD_VERIFY_FLAG_WAIT
#define UDFGetFileAllocationSize(Vcb, FileInfo)
#define UDF_SYS_CACHE_STOP_THR
#define STATUS_INVALID_DEVICE_REQUEST
#define STATUS_ACCESS_DENIED
#define STATUS_INVALID_PARAMETER
#define STATUS_INVALID_USER_BUFFER
#define UDF_CHECK_PAGING_IO_RESOURCE(NTReqFCB)
OSSTATUS WCacheEODirect__(IN PW_CACHE Cache, IN PVOID Context)
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
VOID NTAPI UDFDeferredWriteCallBack(IN PVOID Context1, IN PVOID Context2)
#define FILE_ACTION_MODIFIED_STREAM
#define FILE_NOTIFY_CHANGE_SIZE
#define FILE_ACTION_MODIFIED
#define FILE_NOTIFY_CHANGE_LAST_ACCESS
#define FILE_NOTIFY_CHANGE_STREAM_WRITE
#define FILE_NOTIFY_CHANGE_STREAM_SIZE
#define FO_FILE_SIZE_CHANGED
#define IO_DISK_INCREMENT
#define FO_SYNCHRONOUS_IO
#define FILE_NOTIFY_CHANGE_LAST_WRITE
#define IRP_SYNCHRONOUS_PAGING_IO