Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. cache.c
  5. Abstract:
  6. This module implements the cache management routines for the Rx
  7. FSD and FSP, by calling the Common Cache Manager.
  8. Author:
  9. JoeLinn Created.
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. //
  15. // The Bug check file id for this module
  16. //
  17. #define BugCheckFileId (RDBSS_BUG_CHECK_CACHESUP)
  18. //
  19. // Local debug trace level
  20. //
  21. #define Dbg (DEBUG_TRACE_CACHESUP)
  22. BOOLEAN
  23. RxLockEnumerator (
  24. IN OUT PMRX_SRV_OPEN SrvOpen,
  25. IN OUT PVOID *ContinuationHandle,
  26. OUT PLARGE_INTEGER FileOffset,
  27. OUT PLARGE_INTEGER LockRange,
  28. OUT PBOOLEAN IsLockExclusive
  29. );
  30. #ifdef ALLOC_PRAGMA
  31. #pragma alloc_text(PAGE, RxCompleteMdl)
  32. //#pzragma alloc_text(PAGE, RxZeroData)
  33. #pragma alloc_text(PAGE, RxSyncUninitializeCacheMap)
  34. #pragma alloc_text(PAGE, RxLockEnumerator)
  35. #endif
  36. //
  37. // we can't use the Io system exported form of this because he does it on a file object. during a state
  38. // change, we don't know which fileobject it applies to (although, i suppose we could walk the list and
  39. // find out). so we need to apply this to the fcb instead.
  40. //
  41. #define RxIsFcbOpenedExclusively( FCB ) (((FCB)->ShareAccess.SharedRead \
  42. + (FCB)->ShareAccess.SharedWrite \
  43. + (FCB)->ShareAccess.SharedDelete) == 0)
  44. NTSTATUS
  45. RxCompleteMdl (
  46. IN PRX_CONTEXT RxContext,
  47. IN PIRP Irp
  48. )
  49. /*++
  50. Routine Description:
  51. This routine performs the function of completing Mdl read and write
  52. requests. It should be called only from RxFsdRead and RxFsdWrite.
  53. Arguments:
  54. RxContext - the Rx Context
  55. Return Value:
  56. RXSTATUS - Will always be RxStatus(PENDING) or STATUS_SUCCESS.
  57. --*/
  58. {
  59. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
  60. PFILE_OBJECT FileObject = IrpSp->FileObject;
  61. PAGED_CODE();
  62. RxDbgTrace( +1, Dbg, ("RxCompleteMdl\n", 0 ));
  63. RxDbgTrace( 0, Dbg, ("RxContext = %08lx\n", RxContext ));
  64. RxDbgTrace( 0, Dbg, ("Irp = %08lx\n", Irp ));
  65. switch( RxContext->MajorFunction ) {
  66. case IRP_MJ_READ:
  67. CcMdlReadComplete( FileObject, Irp->MdlAddress );
  68. break;
  69. case IRP_MJ_WRITE:
  70. ASSERT( FlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT ));
  71. CcMdlWriteComplete( FileObject, &IrpSp->Parameters.Write.ByteOffset, Irp->MdlAddress );
  72. Irp->IoStatus.Status = STATUS_SUCCESS;
  73. break;
  74. default:
  75. RxDbgTrace( 0, (DEBUG_TRACE_ERROR), ("Illegal Mdl Complete.\n", 0 ));
  76. RxBugCheck( RxContext->MajorFunction, 0, 0 );
  77. }
  78. //
  79. // Mdl is now deallocated.
  80. //
  81. Irp->MdlAddress = NULL;
  82. //
  83. // Complete the request and exit right away.
  84. //
  85. RxCompleteRequest( RxContext, STATUS_SUCCESS );
  86. RxDbgTrace(-1, Dbg, ("RxCompleteMdl -> RxStatus(SUCCESS\n)", 0 ));
  87. return STATUS_SUCCESS;
  88. }
  89. VOID
  90. RxSyncUninitializeCacheMap (
  91. IN PRX_CONTEXT RxContext,
  92. IN PFILE_OBJECT FileObject
  93. )
  94. /*++
  95. Routine Description:
  96. The routine performs a CcUnitializeCacheMap to LargeZero synchronously. That
  97. is it waits on the Cc event. This call is useful when we want to be certain
  98. when a close will actually some in.
  99. Return Value:
  100. None.
  101. --*/
  102. {
  103. CACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent;
  104. NTSTATUS WaitStatus;
  105. PAGED_CODE();
  106. KeInitializeEvent( &UninitializeCompleteEvent.Event,
  107. SynchronizationEvent,
  108. FALSE );
  109. CcUninitializeCacheMap( FileObject,
  110. &RxLargeZero,
  111. &UninitializeCompleteEvent );
  112. //
  113. // Now wait for the cache manager to finish purging the file.
  114. // This will garentee that Mm gets the purge before we
  115. // delete the Vcb.
  116. //
  117. WaitStatus = KeWaitForSingleObject( &UninitializeCompleteEvent.Event,
  118. Executive,
  119. KernelMode,
  120. FALSE,
  121. NULL);
  122. ASSERT( NT_SUCCESS( WaitStatus ));
  123. }
  124. BOOLEAN
  125. RxLockEnumerator (
  126. IN OUT PMRX_SRV_OPEN SrvOpen,
  127. IN OUT PVOID *ContinuationHandle,
  128. OUT PLARGE_INTEGER FileOffset,
  129. OUT PLARGE_INTEGER LockRange,
  130. OUT PBOOLEAN IsLockExclusive
  131. )
  132. /*++
  133. Routine Description:
  134. This routine is called from a minirdr to enumerate the filelocks on an FCB; it gets
  135. one lock on each call. currently, we just pass thru to the fsrtl routine which is very funky
  136. because it keeps the enumeration state internally; as a result, only one enumeration can be in progress
  137. at any time. we can change over to something better if it's ever required.
  138. Arguments:
  139. SrvOpen - a srvopen on the fcb to be enumerated.
  140. ContinuationHandle - a handle passed back and forth representing the state of the enumeration.
  141. if a NULL is passed in, then we are to start at the beginning.
  142. FileOffset,LockRange,IsLockExclusive - the description of the returned lock
  143. Return Value:
  144. a BOOLEAN. FALSE means you've reached the end of the list; TRUE means the returned lock data is valid
  145. --*/
  146. {
  147. PFILE_LOCK_INFO LockInfo;
  148. ULONG LockNumber;
  149. PFCB Fcb = ((PSRV_OPEN)SrvOpen)->Fcb;
  150. PAGED_CODE();
  151. RxDbgTrace( 0, Dbg, ("FCB (%lx) LOCK Enumeration Buffering Flags(%lx)\n", Fcb, Fcb->FcbState) );
  152. if (!FlagOn( Fcb->FcbState, FCB_STATE_LOCK_BUFFERING_ENABLED )) {
  153. return FALSE;
  154. }
  155. LockNumber = PtrToUlong( *ContinuationHandle );
  156. LockInfo = FsRtlGetNextFileLock( &Fcb->FileLock, (BOOLEAN)(LockNumber == 0) );
  157. LockNumber += 1;
  158. if (LockInfo == NULL) {
  159. return FALSE;
  160. }
  161. RxDbgTrace( 0, Dbg, ("Rxlockenum %08lx\n", LockNumber ));
  162. *FileOffset = LockInfo->StartingByte;
  163. *LockRange = LockInfo->Length;
  164. *IsLockExclusive = LockInfo->ExclusiveLock;
  165. *ContinuationHandle = LongToPtr( LockNumber );
  166. return TRUE;
  167. }