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.

321 lines
5.9 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. close.c
  5. Abstract:
  6. This module implements the file close 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_CLOSE)
  16. NTSTATUS
  17. MupCloseVcb (
  18. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  19. IN PIRP Irp,
  20. IN PVCB Vcb,
  21. IN PFILE_OBJECT FileObject
  22. );
  23. NTSTATUS
  24. MupCloseFcb (
  25. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  26. IN PIRP Irp,
  27. IN PFCB Fcb,
  28. IN PFILE_OBJECT FileObject
  29. );
  30. #ifdef ALLOC_PRAGMA
  31. #pragma alloc_text( PAGE, MupClose )
  32. #pragma alloc_text( PAGE, MupCloseFcb )
  33. #pragma alloc_text( PAGE, MupCloseVcb )
  34. #endif
  35. NTSTATUS
  36. MupClose (
  37. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  38. IN PIRP Irp
  39. )
  40. /*++
  41. Routine Description:
  42. This routine implements the close IRP.
  43. Arguments:
  44. MupDeviceObject - Supplies the device object to use.
  45. Irp - Supplies the Irp being processed
  46. Return Value:
  47. NTSTATUS - The status for the IRP.
  48. --*/
  49. {
  50. NTSTATUS status;
  51. PIO_STACK_LOCATION irpSp;
  52. PVOID fsContext, fsContext2;
  53. PAGED_CODE();
  54. DebugTrace(+1, Dbg, "MupClose\n", 0);
  55. if (MupEnableDfs &&
  56. MupDeviceObject->DeviceObject.DeviceType == FILE_DEVICE_DFS) {
  57. status = DfsFsdClose((PDEVICE_OBJECT) MupDeviceObject, Irp);
  58. return( status );
  59. }
  60. FsRtlEnterFileSystem();
  61. try {
  62. //
  63. // Get the current stack location
  64. //
  65. irpSp = IoGetCurrentIrpStackLocation( Irp );
  66. DebugTrace(+1, Dbg, "MupClose...\n", 0);
  67. DebugTrace( 0, Dbg, " Irp = %08lx\n", (ULONG)Irp);
  68. //
  69. // Decode the file object to figure out who we are.
  70. //
  71. (PVOID)MupDecodeFileObject( irpSp->FileObject,
  72. &fsContext,
  73. &fsContext2 );
  74. if ( fsContext == NULL ) {
  75. DebugTrace(0, Dbg, "The file is disconnected\n", 0);
  76. MupCompleteRequest( Irp, STATUS_INVALID_HANDLE );
  77. status = STATUS_INVALID_HANDLE;
  78. DebugTrace(-1, Dbg, "MupClose -> %08lx\n", status );
  79. FsRtlExitFileSystem();
  80. return status;
  81. }
  82. //
  83. // Ignore the return code from MupDecode. Parse the fsContext
  84. // to decide how to process the close IRP.
  85. //
  86. switch ( BlockType( fsContext ) ) {
  87. case BlockTypeVcb:
  88. status = MupCloseVcb( MupDeviceObject,
  89. Irp,
  90. (PVCB)fsContext,
  91. irpSp->FileObject
  92. );
  93. //
  94. // Complete the close IRP.
  95. //
  96. MupCompleteRequest( Irp, STATUS_SUCCESS );
  97. break;
  98. case BlockTypeFcb:
  99. status = MupCloseFcb( MupDeviceObject,
  100. Irp,
  101. (PFCB)fsContext,
  102. irpSp->FileObject
  103. );
  104. //
  105. // Complete the close IRP.
  106. //
  107. MupCompleteRequest( Irp, STATUS_SUCCESS );
  108. break;
  109. #ifdef MUPDBG
  110. default:
  111. //
  112. // This is not one of ours.
  113. //
  114. KeBugCheck( FILE_SYSTEM );
  115. break;
  116. #endif
  117. }
  118. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  119. status = GetExceptionCode();
  120. }
  121. FsRtlExitFileSystem();
  122. DebugTrace(-1, Dbg, "MupClose -> %08lx\n", status);
  123. return status;
  124. }
  125. NTSTATUS
  126. MupCloseVcb (
  127. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  128. IN PIRP Irp,
  129. IN PVCB Vcb,
  130. IN PFILE_OBJECT FileObject
  131. )
  132. /*++
  133. Routine Description:
  134. This routine closes the a file object that had opened the file system.
  135. Arguments:
  136. MupDeviceObject - Supplies a pointer to our device object.
  137. Irp - Supplies the IRP associate with the close.
  138. Vcb - Supplies the VCB for the MUP.
  139. FileObject - Supplies the file object being closed.
  140. Return Value:
  141. NTSTATUS - STATUS_SUCCESS
  142. --*/
  143. {
  144. Irp;
  145. PAGED_CODE();
  146. DebugTrace(+1, Dbg, "MupCloseVcb, Vcb = %08lx\n", (ULONG)Vcb);
  147. //
  148. // Acquire exclusive access to the VCB.
  149. //
  150. MupAcquireGlobalLock();
  151. try {
  152. //
  153. // Clear the referenced pointer to the VCB in the file object
  154. // and derefence the VCB.
  155. //
  156. ASSERT ( FileObject->FsContext == Vcb );
  157. MupSetFileObject( FileObject, NULL, NULL );
  158. MupDereferenceVcb( Vcb );
  159. } finally {
  160. MupReleaseGlobalLock( );
  161. DebugTrace(-1, Dbg, "MupCloseVcb -> STATUS_SUCCESS\n", 0);
  162. }
  163. //
  164. // Return to the caller.
  165. //
  166. return STATUS_SUCCESS;
  167. }
  168. NTSTATUS
  169. MupCloseFcb (
  170. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  171. IN PIRP Irp,
  172. IN PFCB Fcb,
  173. IN PFILE_OBJECT FileObject
  174. )
  175. /*++
  176. Routine Description:
  177. This routine closes the a file control block.
  178. Arguments:
  179. MupDeviceObject - Supplies a pointer to our device object.
  180. Irp - Supplies the IRP associate with the close.
  181. Fcb - Supplies the FCB to close.
  182. FileObject - Supplies the file object being closed.
  183. Return Value:
  184. NTSTATUS - STATUS_SUCCESS
  185. --*/
  186. {
  187. MupDeviceObject; Irp;
  188. PAGED_CODE();
  189. DebugTrace(+1, Dbg, "MupCloseFcb, Fcb = %08lx\n", (ULONG)Fcb);
  190. //
  191. // Acquire exclusive access to the VCB.
  192. //
  193. MupAcquireGlobalLock();
  194. try {
  195. //
  196. // Clear the referenced pointer to the VCB in the file object
  197. // and derefence the VCB.
  198. //
  199. ASSERT ( FileObject->FsContext == Fcb );
  200. MupSetFileObject( FileObject, NULL, NULL );
  201. MupDereferenceFcb( Fcb );
  202. } finally {
  203. MupReleaseGlobalLock( );
  204. DebugTrace(-1, Dbg, "MupCloseFcb -> STATUS_SUCCESS\n", 0);
  205. }
  206. //
  207. // Return to the caller.
  208. //
  209. return STATUS_SUCCESS;
  210. }