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.

359 lines
7.7 KiB

  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. PFILE_OBJECT FileObject;
  54. PAGED_CODE();
  55. DebugTrace(+1, Dbg, "MupClose\n", 0);
  56. if (MupEnableDfs) {
  57. if ((MupDeviceObject->DeviceObject.DeviceType == FILE_DEVICE_DFS) ||
  58. (MupDeviceObject->DeviceObject.DeviceType ==
  59. FILE_DEVICE_DFS_FILE_SYSTEM)) {
  60. status = DfsFsdClose((PDEVICE_OBJECT) MupDeviceObject, Irp);
  61. return( status );
  62. }
  63. }
  64. FsRtlEnterFileSystem();
  65. try {
  66. //
  67. // Get the current stack location
  68. //
  69. irpSp = IoGetCurrentIrpStackLocation( Irp );
  70. FileObject = irpSp->FileObject;
  71. MUP_TRACE_HIGH(TRACE_IRP, MupClose_Entry,
  72. LOGPTR(MupDeviceObject)
  73. LOGPTR(Irp)
  74. LOGPTR(FileObject));
  75. DebugTrace(+1, Dbg, "MupClose...\n", 0);
  76. DebugTrace( 0, Dbg, " Irp = %08lx\n", (ULONG)Irp);
  77. //
  78. // Decode the file object to figure out who we are.
  79. //
  80. (PVOID)MupDecodeFileObject( irpSp->FileObject,
  81. &fsContext,
  82. &fsContext2 );
  83. if ( fsContext == NULL ) {
  84. DebugTrace(0, Dbg, "The file is disconnected\n", 0);
  85. MupCompleteRequest( Irp, STATUS_INVALID_HANDLE );
  86. status = STATUS_INVALID_HANDLE;
  87. MUP_TRACE_HIGH(ERROR, MupClose_Error1,
  88. LOGSTATUS(status)
  89. LOGPTR(MupDeviceObject)
  90. LOGPTR(FileObject)
  91. LOGPTR(Irp));
  92. DebugTrace(-1, Dbg, "MupClose -> %08lx\n", status );
  93. FsRtlExitFileSystem();
  94. return status;
  95. }
  96. //
  97. // Ignore the return code from MupDecode. Parse the fsContext
  98. // to decide how to process the close IRP.
  99. //
  100. switch ( BlockType( fsContext ) ) {
  101. case BlockTypeVcb:
  102. status = MupCloseVcb( MupDeviceObject,
  103. Irp,
  104. (PVCB)fsContext,
  105. irpSp->FileObject
  106. );
  107. //
  108. // Complete the close IRP.
  109. //
  110. MupCompleteRequest( Irp, STATUS_SUCCESS );
  111. break;
  112. case BlockTypeFcb:
  113. //
  114. // MupDecodeFileObject bumped the refcount on the fcb,
  115. // so we decrement that extra ref here.
  116. //
  117. MupDereferenceFcb((PFCB)fsContext);
  118. status = MupCloseFcb( MupDeviceObject,
  119. Irp,
  120. (PFCB)fsContext,
  121. irpSp->FileObject
  122. );
  123. //
  124. // Complete the close IRP.
  125. //
  126. MupCompleteRequest( Irp, STATUS_SUCCESS );
  127. break;
  128. #ifdef MUPDBG
  129. default:
  130. //
  131. // This is not one of ours.
  132. //
  133. KeBugCheckEx( FILE_SYSTEM, 1, 0, 0, 0 );
  134. break;
  135. #else
  136. default:
  137. //
  138. // Complete the IRP with an error
  139. //
  140. MupCompleteRequest(Irp,STATUS_INVALID_HANDLE);
  141. status = STATUS_INVALID_HANDLE;
  142. MUP_TRACE_HIGH(ERROR, MupClose_Error2,
  143. LOGSTATUS(status)
  144. LOGPTR(MupDeviceObject)
  145. LOGPTR(FileObject)
  146. LOGPTR(Irp));
  147. break;
  148. #endif
  149. }
  150. } except ( EXCEPTION_EXECUTE_HANDLER ) {
  151. status = GetExceptionCode();
  152. }
  153. FsRtlExitFileSystem();
  154. MUP_TRACE_HIGH(TRACE_IRP, MupClose_Exit,
  155. LOGSTATUS(status)
  156. LOGPTR(MupDeviceObject)
  157. LOGPTR(FileObject)
  158. LOGPTR(Irp));
  159. DebugTrace(-1, Dbg, "MupClose -> %08lx\n", status);
  160. return status;
  161. }
  162. NTSTATUS
  163. MupCloseVcb (
  164. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  165. IN PIRP Irp,
  166. IN PVCB Vcb,
  167. IN PFILE_OBJECT FileObject
  168. )
  169. /*++
  170. Routine Description:
  171. This routine closes the a file object that had opened the file system.
  172. Arguments:
  173. MupDeviceObject - Supplies a pointer to our device object.
  174. Irp - Supplies the IRP associate with the close.
  175. Vcb - Supplies the VCB for the MUP.
  176. FileObject - Supplies the file object being closed.
  177. Return Value:
  178. NTSTATUS - STATUS_SUCCESS
  179. --*/
  180. {
  181. Irp;
  182. PAGED_CODE();
  183. DebugTrace(+1, Dbg, "MupCloseVcb, Vcb = %08lx\n", (ULONG)Vcb);
  184. //
  185. // Acquire exclusive access to the VCB.
  186. //
  187. MupAcquireGlobalLock();
  188. try {
  189. //
  190. // Clear the referenced pointer to the VCB in the file object
  191. // and derefence the VCB.
  192. //
  193. ASSERT ( FileObject->FsContext == Vcb );
  194. MupSetFileObject( FileObject, NULL, NULL );
  195. MupDereferenceVcb( Vcb );
  196. } finally {
  197. MupReleaseGlobalLock( );
  198. DebugTrace(-1, Dbg, "MupCloseVcb -> STATUS_SUCCESS\n", 0);
  199. }
  200. //
  201. // Return to the caller.
  202. //
  203. return STATUS_SUCCESS;
  204. }
  205. NTSTATUS
  206. MupCloseFcb (
  207. IN PMUP_DEVICE_OBJECT MupDeviceObject,
  208. IN PIRP Irp,
  209. IN PFCB Fcb,
  210. IN PFILE_OBJECT FileObject
  211. )
  212. /*++
  213. Routine Description:
  214. This routine closes the a file control block.
  215. Arguments:
  216. MupDeviceObject - Supplies a pointer to our device object.
  217. Irp - Supplies the IRP associate with the close.
  218. Fcb - Supplies the FCB to close.
  219. FileObject - Supplies the file object being closed.
  220. Return Value:
  221. NTSTATUS - STATUS_SUCCESS
  222. --*/
  223. {
  224. MupDeviceObject; Irp;
  225. PAGED_CODE();
  226. DebugTrace(+1, Dbg, "MupCloseFcb, Fcb = %08lx\n", (ULONG)Fcb);
  227. //
  228. // Acquire exclusive access to the VCB.
  229. //
  230. MupAcquireGlobalLock();
  231. try {
  232. //
  233. // Clear the referenced pointer to the VCB in the file object
  234. // and derefence the VCB.
  235. //
  236. ASSERT ( FileObject->FsContext == Fcb );
  237. MupSetFileObject( FileObject, NULL, NULL );
  238. MupDereferenceFcb( Fcb );
  239. } finally {
  240. MupReleaseGlobalLock( );
  241. DebugTrace(-1, Dbg, "MupCloseFcb -> STATUS_SUCCESS\n", 0);
  242. }
  243. //
  244. // Return to the caller.
  245. //
  246. return STATUS_SUCCESS;
  247. }