38#define RX_TOPLEVELCTX_FLAG_FROM_POOL 1
626 RxAssert(#exp, __FILE__, __LINE__, NULL); \
632#undef RxAllocatePoolWithTag
635#define RxAllocatePool(P, S) _RxAllocatePoolWithTag(P, S, 0)
636#define RxAllocatePoolWithTag _RxAllocatePoolWithTag
637#define RxFreePool _RxFreePool
638#define RxFreePoolWithTag _RxFreePoolWithTag
654#define ALLSCR_LENGTH (sizeof(L"all.scr") - sizeof(UNICODE_NULL))
680 DPRINT(
"__RxInitializeTopLevelIrpContext(%p, %p, %p, %u)\n", TopLevelContext,
Irp, RxDeviceObject,
Flags);
683 TopLevelContext->Irp =
Irp;
686 TopLevelContext->RxDeviceObject = RxDeviceObject;
719 if (ResourceOwnerSet)
735 if (ResourceOwnerSet)
757 DPRINT(
"RxAddToTopLevelIrpAllocatedContextsList(%p)\n", TopLevelContext);
782 RxContext->PostRequest =
FALSE;
832 BOOLEAN FileModified, SetLastChange, SetLastAccess, SetLastWrite, NeedUpdate;
855 SetLastAccess = SetLastWrite ||
862 if (!FileModified && !SetLastWrite && !SetLastAccess && !SetLastChange)
899 RxContext->
Info.Buffer = &FileBasicInfo;
900 RxContext->
Info.Length =
sizeof(FileBasicInfo);
912 RxContext->
Info.Buffer = &FileEOFInfo;
913 RxContext->
Info.Length =
sizeof(FileEOFInfo);
931 DPRINT(
"RxContext: %p - CanonicalNameBuffer: %p\n", RxContext, RxContext->
Create.CanonicalNameBuffer);
949 CanonicalName->
Length = 0;
953 RxContext->
Create.CanonicalNameBuffer = CanonicalName->
Buffer;
1089 if (!ForceFilesClosed)
1146 OperationToCancel =
FALSE;
1175 OperationToCancel =
TRUE;
1182 if (OperationToCancel)
1188 return OperationToCancel;
1242 if (RxContext !=
NULL)
1265 USHORT NextChar, CurChar;
1278 for (NextChar = 0, CurChar = 0; CurChar + 1 < MaxChars; NextChar = CurChar + 1)
1282 for (
i = NextChar + 1;
i < MaxChars; ++
i)
1284 if (NetRootName->
Buffer[
i] ==
'\\' || NetRootName->
Buffer[
i] ==
':')
1291 if (CurChar == NextChar)
1293 if (((NetRootName->
Buffer[NextChar] !=
'\\' && NetRootName->
Buffer[NextChar] !=
':') || NextChar == (MaxChars - 1)) && NetRootName->
Buffer[NextChar] !=
'.')
1300 if (CurChar >= MaxChars - 1)
1305 if (NetRootName->
Buffer[CurChar + 1] !=
':')
1312 if (NetRootName->
Buffer[1] !=
':')
1320 if ((CurChar - NextChar) == 1)
1322 if (NetRootName->
Buffer[NextChar + 2] !=
'.')
1327 if (NetRootName->
Buffer[NextChar] ==
'\\' || NetRootName->
Buffer[NextChar] ==
':' || NetRootName->
Buffer[NextChar] ==
'.')
1334 if ((CurChar - NextChar) != 2 || (NetRootName->
Buffer[NextChar] !=
'\\' && NetRootName->
Buffer[NextChar] !=
':')
1335 || NetRootName->
Buffer[NextChar + 1] !=
'.')
1340 if (NetRootName->
Buffer[NextChar + 2] ==
'.')
1368 RtlInitEmptyUnicodeString(NetRootName,
NULL, 0);
1369 RtlInitEmptyUnicodeString(&CanonicalName,
NULL, 0);
1433 MINIRDR_CALL(IgnoredStatus, RxContext, RxContext->
Create.pNetRoot->pSrvCall->RxDeviceObject->Dispatch,
1434 MRxPreparseName, (RxContext, NetRootName));
1435 (
void)IgnoredStatus;
1547 CloseSrvOpen =
FALSE;
1554 SrvOpen = Fobx->SrvOpen;
1559 CloseSrvOpen =
TRUE;
1568 if (SrvOpen->OpenCount > 0)
1570 --SrvOpen->OpenCount;
1586 if (RxContext ==
NULL)
1597 if (RxContext ==
NULL)
1602 if (LocalContext ==
NULL)
1614 LocalContext = RxContext;
1630 if (SrvOpen ==
NULL)
1635 if (LocalContext != RxContext)
1646 if (LocalContext != RxContext)
1655 if (SrvOpen->OpenCount > 0)
1657 --SrvOpen->OpenCount;
1661 if (SrvOpen->OpenCount == 1)
1673 if (SrvOpen->OpenCount == 0 && RxContext ==
NULL)
1679 SrvOpen = Fobx->SrvOpen;
1680 if (SrvOpen ==
NULL ||
1685 if (LocalContext != RxContext)
1697 DPRINT(
"MRxCloseSrvOpen returned: %lx, called with RX_CONTEXT %p for FOBX %p (FCB %p, SRV_OPEN %p)\n ",
1702 SrvOpen->Key = (
PVOID)-1;
1720 if (LocalContext != RxContext)
1747 DPRINT(
"RxCollapseOrCreateSrvOpen(%p)\n", RxContext);
1763 if (SrvOpen ==
NULL)
1797 capFcb->Header.AllocationSize.QuadPart = 0
LL;
1798 capFcb->Header.FileSize.QuadPart = 0
LL;
1799 capFcb->Header.ValidDataLength.QuadPart = 0
LL;
1833 SrvOpen->CreateOptions = RxContext->
Create.NtCreateParameters.CreateOptions;
1869 ++SrvOpen->OpenCount;
1899 --SrvOpen->OpenCount;
1918#define BugCheckFileId RDBSS_BUG_CHECK_CLEANUP
1927 BOOLEAN NeedPurge, FcbTableAcquired, OneLeft, IsFile, FcbAcquired, LeftForDelete;
1969 Fobx->AssociatedFileObject =
NULL;
1979 --
Fcb->UncachedUncleanCount;
1986 --Fobx->
SrvOpen->UncleanFobxCount;
2008 FcbTableAcquired =
FALSE;
2009 LeftForDelete =
FALSE;
2019 FcbTableAcquired =
TRUE;
2034 FcbTableAcquired =
TRUE;
2040 LeftForDelete =
TRUE;
2045 FcbTableAcquired =
FALSE;
2050 TruncateSizePtr =
NULL;
2066 if (
Context->LowIoContext.ParamsFor.Locks.LockList !=
NULL)
2069 Context->LowIoContext.ParamsFor.Locks.Flags = 0;
2085 Fcb->
Header.ValidDataLength.QuadPart = 0;
2107 TruncateSizePtr = &TruncateSize;
2136 --
Fcb->UncachedUncleanCount;
2143 --Fobx->
SrvOpen->UncleanFobxCount;
2152 DPRINT(
"Flushing %p due to last cached handle cleanup\n",
Context);
2169 if (
Fcb->UncachedUncleanCount != 0)
2181 if (!LeftForDelete && NeedPurge)
2190 DPRINT(
"Uninit cache map for file\n");
2195 if (LeftForDelete || NeedPurge)
2203 FcbTableAcquired =
FALSE;
2215 RxWriteCacheingAllowed(
Fcb, Fobx->pSrvOpen))
2225 if (InternalContext !=
NULL)
2239 InternalContext->
Info.Buffer = &FileEOF;
2240 InternalContext->
Info.Length =
sizeof(FileEOF);
2250 ClearFlag(Fobx->Flags, FOBX_FLAG_DISABLE_COLLAPSING);
2261 FcbAcquired =
FALSE;
2271 if (FcbTableAcquired)
2279#undef BugCheckFileId
2287#define BugCheckFileId RDBSS_BUG_CHECK_CLOSE
2292 BOOLEAN DereferenceFobx, AcquiredFcb;
2322 DereferenceFobx =
FALSE;
2338 DPRINT(
"Delay close for FOBX: %p, SrvOpen %p\n", Fobx, SrvOpen);
2348 DereferenceFobx =
TRUE;
2357 if (!DereferenceFobx)
2385 if (DereferenceFobx)
2400 AcquiredFcb = !Freed;
2411 AcquiredFcb =
FALSE;
2432#undef BugCheckFileId
2478 DPRINT1(
"Create.Options: %x\n",
Stack->Parameters.Create.Options);
2482 DPRINT(
"Ctxt: %p, FO: %p, Options: %lx, Flags: %lx, Attr: %lx, ShareAccess: %lx, DesiredAccess: %lx\n",
2484 Stack->Parameters.Create.ShareAccess,
Stack->Parameters.Create.SecurityContext->DesiredAccess);
2489 RelatedFcb =
FileObject->RelatedFileObject->FsContext;
2572 if (
Context->Create.TryForScavengingOnSharingViolation &&
2573 !
Context->Create.ScavengingAlreadyTried)
2622 Context->CurrentIrp->IoStatus.Information = 0;
2702 if (NetRoot !=
NULL)
2829 DPRINT(
"RxCommonDirectoryControl(%p) FOBX: %p, FCB: %p, Minor: %d\n",
Context, Fobx,
Fcb,
Stack->MinorFunction);
2917#define SET_SIZE_AND_QUERY(AlreadyConsummed, Function) \
2918 Context->Info.Length = Stack->Parameters.QueryFile.Length - (AlreadyConsummed); \
2919 Status = Function(Context, Add2Ptr(Buffer, AlreadyConsummed))
2933 DPRINT(
"RxCommonQueryInformation(%p) FCB: %p, FOBX: %p\n",
Context,
Fcb, Fobx);
2937 DPRINT(
"Buffer: %p, Length: %lx, Class: %ld\n",
Irp->AssociatedIrp.SystemBuffer,
2938 Stack->Parameters.QueryFile.Length,
Stack->Parameters.QueryFile.FileInformationClass);
2940 Context->Info.Length =
Stack->Parameters.QueryFile.Length;
2941 FileInfoClass =
Stack->Parameters.QueryFile.FileInformationClass;
3008 switch (FileInfoClass)
3097 Context->Info.Length =
Stack->Parameters.QueryFile.Length;
3100 Irp->IoStatus.Information =
Stack->Parameters.QueryFile.Length -
Context->Info.Length;
3114#undef SET_SIZE_AND_QUERY
3154 DPRINT(
"RxCommonQueryVolumeInformation(%p) FCB: %p, FOBX: %p\n",
Context,
Fcb, Fobx);
3158 DPRINT(
"Length: %lx, Class: %lx, Buffer %p\n",
Stack->Parameters.QueryVolume.Length,
3159 Stack->Parameters.QueryVolume.FsInformationClass,
Irp->AssociatedIrp.SystemBuffer);
3161 Context->Info.FsInformationClass =
Stack->Parameters.QueryVolume.FsInformationClass;
3162 Context->Info.Buffer =
Irp->AssociatedIrp.SystemBuffer;
3163 Context->Info.Length =
Stack->Parameters.QueryVolume.Length;
3175 Irp->IoStatus.Information =
Stack->Parameters.QueryVolume.Length -
Context->Info.Length;
3199 BOOLEAN CanWait, PagingIo, NoCache, Sync, PostRequest,
IsPipe, ReadCachingEnabled, ReadCachingDisabled, InFsp, OwnerSet;
3205 DPRINT(
"RxCommonRead(%p) FOBX: %p, FCB: %p\n", RxContext, Fobx,
Fcb);
3218 (CanWait ?
"CW" :
"!CW"), (PagingIo ?
"PI" :
"!PI"), (NoCache ?
"NC" :
"!NC"), (Sync ?
"S" :
"!S"));
3222 Irp->IoStatus.Information = 0;
3231 DPRINT(
"LoudRead %I64x/%lx on %lx vdl/size/alloc %I64x/%I64x/%I64x\n",
3284 PostRequest =
FALSE;
3285 ReadCachingDisabled =
FALSE;
3295 if (!PagingIo && NoCache && !ReadCachingEnabled &&
FileObject->SectionObjectPointer !=
NULL)
3323 if (PagingIo && !ReadCachingEnabled)
3340 if (!ReadCachingEnabled)
3342 if (!CanWait && NoCache)
3347 DPRINT1(
"RdAsyLNG %x\n", RxContext);
3353 DPRINT1(
"RdAsyOthr %x\n", RxContext);
3385 ReadCachingDisabled = (ReadCachingEnabled ==
FALSE);
3419 if (!PagingIo && !NoCache && ReadCachingEnabled &&
3463 if (SystemBuffer ==
NULL)
3476 if (!ReadCachingEnabled)
3487 if (!ReadCachingEnabled)
3515 if (InFsp && ReadCachingDisabled)
3559 if (!
IsPipe && !PagingIo)
3571 if (!
IsPipe && !PagingIo)
3581 if (ReadCachingDisabled)
3623 ASSERT(
Irp->IoStatus.Information <=
Stack->Parameters.Read.Length);
3662 BOOLEAN CanWait, FcbTableAcquired, FcbAcquired;
3668 DPRINT(
"RxCommonSetInformation(%p), FCB: %p, FOBX: %p\n",
Context,
Fcb, Fobx);
3672 Class =
Stack->Parameters.SetFile.FileInformationClass;
3673 DPRINT(
"Buffer: %p, Length: %lx, Class: %ld, ReplaceIfExists: %d\n",
3674 Irp->AssociatedIrp.SystemBuffer,
Stack->Parameters.SetFile.Length,
3675 Class,
Stack->Parameters.SetFile.ReplaceIfExists);
3679 FcbTableAcquired =
FALSE;
3680 FcbAcquired =
FALSE;
3734 FcbTableAcquired =
TRUE;
3768 FDI =
Irp->AssociatedIrp.SystemBuffer;
3780 ASSERT(FcbAcquired && FcbTableAcquired);
3784 FcbTableAcquired =
FALSE;
3831 ASSERT(FcbAcquired && FcbTableAcquired);
3880 if (FcbTableAcquired)
3887#undef _SEH2_TRY_RETURN
3946 LONGLONG FileSize, ValidDataLength, InitialFileSize, InitialValidDataLength;
3947 BOOLEAN CanWait, PagingIo, NoCache, Sync, NormalFile, WriteToEof,
IsPipe, NoPreposting, InFsp, RecursiveWriteThrough, CalledByLazyWriter, SwitchBackToAsync, ExtendingFile, ExtendingValidData, UnwindOutstandingAsync, ResourceOwnerSet, PostIrp, ContextReferenced;
3971 DPRINT(
"RxCommonWrite(%p) FOBX: %p, FCB: %p\n", RxContext, Fobx,
Fcb);
3984 (CanWait ?
"CW" :
"!CW"), (PagingIo ?
"PI" :
"!PI"), (NoCache ?
"NC" :
"!NC"), (Sync ?
"S" :
"!S"));
3995 DPRINT(
"LoudWrite %I64x/%lx on %lx vdl/size/alloc %I64x/%I64x/%I64x\n",
4069 if (RxWriteCacheingAllowed(
Fcb, SrvOpen))
4094 RecursiveWriteThrough =
FALSE;
4095 CalledByLazyWriter =
FALSE;
4096 SwitchBackToAsync =
FALSE;
4097 ExtendingFile =
FALSE;
4098 ExtendingValidData =
FALSE;
4099 UnwindOutstandingAsync =
FALSE;
4100 ResourceOwnerSet =
FALSE;
4102 ContextReferenced =
FALSE;
4104#define _SEH2_TRY_RETURN(S) S; goto try_exit
4114 ASSERT(!(WriteToEof && PagingIo));
4119 if (!PagingIo && !NoPreposting)
4134 (!NoCache && RxWriteCacheingAllowed(
Fcb, SrvOpen)))
4147 DPRINT1(
"Failed to acquire lock!\n");
4193 DPRINT1(
"Failed to acquire lock!\n");
4207 if (
ByteOffset.QuadPart + WriteLength <= Fcb->
Header.ValidDataLength.QuadPart ||
4220 DPRINT(
"Disabling collapsing\n");
4224 SetFlag(Fobx->Flags, FOBX_FLAG_DISABLE_COLLAPSING);
4253 if (NoCache || !RxWriteCacheingAllowed(
Fcb, SrvOpen))
4274 DPRINT1(
"Failed to acquire lock for flush!\n");
4328 ValidDataLength =
Fcb->
Header.ValidDataLength.QuadPart;
4351 CalledByLazyWriter =
TRUE;
4386 RecursiveWriteThrough =
TRUE;
4393 if (!CalledByLazyWriter && !RecursiveWriteThrough &&
4407 SwitchBackToAsync =
TRUE;
4412 RxWriteReleaseResources(RxContext, 0);
4419 DPRINT1(
"Failed to acquire lock for extension!\n");
4433 ValidDataLength =
Fcb->
Header.ValidDataLength.QuadPart;
4441 SwitchBackToAsync =
FALSE;
4461 InitialValidDataLength = ValidDataLength;
4479 DPRINT(
"Need to extend file\n");
4480 ExtendingFile =
TRUE;
4494 DPRINT(
"Extending %p\n", RxContext);
4535 if (!CalledByLazyWriter && !RecursiveWriteThrough)
4539 ExtendingValidData =
TRUE;
4545 if (PagingIo || NoCache || !RxWriteCacheingAllowed(
Fcb, SrvOpen))
4548 if (SwitchBackToAsync)
4574 UnwindOutstandingAsync =
TRUE;
4602 ResourceOwnerSet =
TRUE;
4613 UnwindOutstandingAsync =
FALSE;
4644 &
Irp->MdlAddress, &
Irp->IoStatus);
4651 ULONG BreakpointsSave;
4655 if (SystemBuffer ==
NULL)
<