Windows NT 4.0 source code leak
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.

373 lines
7.3 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. cleanup.c
  5. Abstract:
  6. This module implements the file cleanup routine for MUP.
  7. Author:
  8. Manny Weiser (mannyw) 28-Dec-1991
  9. Revision History:
  10. --*/
  11. #include "mup.h"
  12. //
  13. // The debug trace level
  14. //
  15. #define Dbg (DEBUG_TRACE_CLEANUP)
  16. //
  17. // local procedure prototypes
  18. //
  19. NTSTATUS
  20. MupCleanupVcb (
  21. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  22. IN PIRP Irp,
  23. IN PVCB Vcb
  24. );
  25. NTSTATUS
  26. MupCleanupFcb (
  27. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  28. IN PIRP Irp,
  29. IN PFCB Fcb
  30. );
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text( PAGE, MupCleanup )
  33. #pragma alloc_text( PAGE, MupCleanupFcb )
  34. #pragma alloc_text( PAGE, MupCleanupVcb )
  35. #endif
  36. NTSTATUS
  37. MupCleanup (
  38. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  39. IN PIRP Irp
  40. )
  41. /*++
  42. Routine Description:
  43. This routine implements the the cleanup IRP.
  44. Arguments:
  45. MupDeviceObject - Supplies the device object to use.
  46. Irp - Supplies the Irp being processed
  47. Return Value:
  48. NTSTATUS - The status for the Irp
  49. --*/
  50. {
  51. PIO_STACK_LOCATION irpSp;
  52. NTSTATUS status;
  53. BLOCK_TYPE blockType;
  54. PVOID fsContext, fsContext2;
  55. MupDeviceObject;
  56. PAGED_CODE();
  57. if (MupEnableDfs &&
  58. MupDeviceObject->DeviceObject.DeviceType == FILE_DEVICE_DFS) {
  59. status = DfsFsdCleanup((PDEVICE_OBJECT) MupDeviceObject, Irp);
  60. return( status );
  61. }
  62. FsRtlEnterFileSystem();
  63. try {
  64. irpSp = IoGetCurrentIrpStackLocation( Irp );
  65. DebugTrace(+1, Dbg, "MupCleanup\n", 0);
  66. DebugTrace( 0, Dbg, "MupDeviceObject = %08lx\n", (ULONG)MupDeviceObject);
  67. DebugTrace( 0, Dbg, "Irp = %08lx\n", (ULONG)Irp);
  68. DebugTrace( 0, Dbg, "FileObject = %08lx\n", (ULONG)irpSp->FileObject);
  69. //
  70. // Get the a referenced pointer to the node and make sure it is
  71. // not being closed.
  72. //
  73. if ((blockType = MupDecodeFileObject( irpSp->FileObject,
  74. &fsContext,
  75. &fsContext2 )) == BlockTypeUndefined) {
  76. DebugTrace(0, Dbg, "The file is closed\n", 0);
  77. FsRtlExitFileSystem();
  78. MupCompleteRequest( Irp, STATUS_INVALID_HANDLE );
  79. status = STATUS_INVALID_HANDLE;
  80. DebugTrace(-1, Dbg, "MupCleanup -> %08lx\n", status );
  81. return status;
  82. }
  83. //
  84. // Decide how to handle this IRP.
  85. //
  86. switch ( blockType ) {
  87. case BlockTypeVcb: // Cleanup MUP
  88. status = MupCleanupVcb( MupDeviceObject,
  89. Irp,
  90. (PVCB)fsContext
  91. );
  92. MupCompleteRequest( Irp, STATUS_SUCCESS );
  93. MupDereferenceVcb( (PVCB)fsContext );
  94. //
  95. // Cleanup the UNC Provider
  96. //
  97. if ( fsContext2 != NULL ) {
  98. MupCloseUncProvider((PUNC_PROVIDER)fsContext2 );
  99. MupDereferenceUncProvider( (PUNC_PROVIDER)fsContext2 );
  100. MupAcquireGlobalLock();
  101. MupProviderCount--;
  102. MupReleaseGlobalLock();
  103. }
  104. status = STATUS_SUCCESS;
  105. break;
  106. case BlockTypeFcb:
  107. status = MupCleanupFcb( MupDeviceObject,
  108. Irp,
  109. (PFCB)fsContext
  110. );
  111. MupCompleteRequest( Irp, STATUS_SUCCESS );
  112. MupDereferenceFcb( (PFCB)fsContext );
  113. status = STATUS_SUCCESS;
  114. break;
  115. #ifdef MUPDBG
  116. default:
  117. //
  118. // This is not one of ours.
  119. //
  120. KeBugCheck( FILE_SYSTEM );
  121. break;
  122. #endif
  123. }
  124. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  125. status = GetExceptionCode();
  126. }
  127. FsRtlExitFileSystem();
  128. DebugTrace(-1, Dbg, "MupCleanup -> %08lx\n", status);
  129. return status;
  130. }
  131. NTSTATUS
  132. MupCleanupVcb (
  133. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  134. IN PIRP Irp,
  135. IN PVCB Vcb
  136. )
  137. /*++
  138. Routine Description:
  139. The routine cleans up a VCB.
  140. Arguments:
  141. MupDeviceObject - A pointer the the MUP device object.
  142. Irp - Supplies the IRP associated with the cleanup.
  143. Vcb - Supplies the VCB for the MUP.
  144. Return Value:
  145. NTSTATUS - An appropriate completion status
  146. --*/
  147. {
  148. NTSTATUS status;
  149. PIO_STACK_LOCATION irpSp;
  150. MupDeviceObject;
  151. PAGED_CODE();
  152. DebugTrace(+1, Dbg, "MupCleanupVcb...\n", 0);
  153. //
  154. // Now acquire exclusive access to the Vcb
  155. //
  156. ExAcquireResourceExclusive( &MupVcbLock, TRUE );
  157. status = STATUS_SUCCESS;
  158. try {
  159. //
  160. // Ensure that this VCB is still active.
  161. //
  162. MupVerifyBlock( Vcb, BlockTypeVcb );
  163. irpSp = IoGetCurrentIrpStackLocation( Irp );
  164. IoRemoveShareAccess( irpSp->FileObject,
  165. &Vcb->ShareAccess );
  166. } finally {
  167. ExReleaseResource( &MupVcbLock );
  168. DebugTrace(-1, Dbg, "MupCleanupVcb -> %08lx\n", status);
  169. }
  170. //
  171. // And return to our caller
  172. //
  173. return status;
  174. }
  175. NTSTATUS
  176. MupCleanupFcb (
  177. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  178. IN PIRP Irp,
  179. IN PFCB Fcb
  180. )
  181. /*++
  182. Routine Description:
  183. The routine cleans up a FCB.
  184. Arguments:
  185. MupDeviceObject - A pointer the the MUP device object.
  186. Irp - Supplies the IRP associated with the cleanup.
  187. Vcb - Supplies the VCB for the MUP.
  188. Return Value:
  189. NTSTATUS - An appropriate completion status
  190. --*/
  191. {
  192. NTSTATUS status;
  193. PIO_STACK_LOCATION irpSp;
  194. BOOLEAN holdingGlobalLock;
  195. PLIST_ENTRY listEntry, nextListEntry;
  196. PCCB ccb;
  197. MupDeviceObject;
  198. PAGED_CODE();
  199. DebugTrace(+1, Dbg, "MupCleanupVcb...\n", 0);
  200. //
  201. // Now acquire exclusive access to the Vcb
  202. //
  203. MupAcquireGlobalLock();
  204. holdingGlobalLock = TRUE;
  205. status = STATUS_SUCCESS;
  206. try {
  207. //
  208. // Ensure that this FCB is still active.
  209. //
  210. MupVerifyBlock( Fcb, BlockTypeFcb );
  211. Fcb->BlockHeader.BlockState = BlockStateClosing;
  212. MupReleaseGlobalLock();
  213. holdingGlobalLock = FALSE;
  214. irpSp = IoGetCurrentIrpStackLocation( Irp );
  215. //
  216. // Loop through the list of CCBs, and release the open reference
  217. // to each one. We must be careful because:
  218. //
  219. // (1) We cannot dereference the Ccb with the CcbListLock held.
  220. // (2) Dereferncing a Ccb may cause it to be removed from this
  221. // list and freed.
  222. //
  223. ACQUIRE_LOCK( &MupCcbListLock );
  224. listEntry = Fcb->CcbList.Flink;
  225. while ( listEntry != &Fcb->CcbList ) {
  226. nextListEntry = listEntry->Flink;
  227. RELEASE_LOCK( &MupCcbListLock );
  228. ccb = CONTAINING_RECORD( listEntry, CCB, ListEntry );
  229. MupDereferenceCcb( ccb );
  230. ACQUIRE_LOCK( &MupCcbListLock );
  231. listEntry = nextListEntry;
  232. }
  233. RELEASE_LOCK( &MupCcbListLock );
  234. } finally {
  235. if ( holdingGlobalLock ) {
  236. MupReleaseGlobalLock();
  237. }
  238. DebugTrace(-1, Dbg, "MupCleanupFcb -> %08lx\n", status);
  239. }
  240. //
  241. // And return to our caller
  242. //
  243. return status;
  244. }