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.

500 lines
9.9 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 MSFS called by the
  7. dispatch driver.
  8. Author:
  9. Manny Weiser (mannyw) 18-Jan-1991
  10. Revision History:
  11. --*/
  12. #include "mailslot.h"
  13. //
  14. // The debug trace level
  15. //
  16. #define Dbg (DEBUG_TRACE_CLOSE)
  17. //
  18. // local procedure prototypes
  19. //
  20. NTSTATUS
  21. MsCommonClose (
  22. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  23. IN PIRP Irp
  24. );
  25. NTSTATUS
  26. MsCloseVcb (
  27. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  28. IN PIRP Irp,
  29. IN PVCB Vcb,
  30. IN PFILE_OBJECT FileObject
  31. );
  32. NTSTATUS
  33. MsCloseRootDcb (
  34. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  35. IN PIRP Irp,
  36. IN PROOT_DCB RootDcb,
  37. IN PROOT_DCB_CCB Ccb,
  38. IN PFILE_OBJECT FileObject
  39. );
  40. NTSTATUS
  41. MsCloseCcb (
  42. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  43. IN PIRP Irp,
  44. IN PCCB Ccb,
  45. IN PFILE_OBJECT FileObject
  46. );
  47. NTSTATUS
  48. MsCloseFcb (
  49. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  50. IN PIRP Irp,
  51. IN PFCB Fcb,
  52. IN PFILE_OBJECT FileObject
  53. );
  54. #ifdef ALLOC_PRAGMA
  55. #pragma alloc_text( PAGE, MsCloseCcb )
  56. #pragma alloc_text( PAGE, MsCloseFcb )
  57. #pragma alloc_text( PAGE, MsCloseRootDcb )
  58. #pragma alloc_text( PAGE, MsCloseVcb )
  59. #pragma alloc_text( PAGE, MsCommonClose )
  60. #pragma alloc_text( PAGE, MsFsdClose )
  61. #endif
  62. NTSTATUS
  63. MsFsdClose (
  64. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  65. IN PIRP Irp
  66. )
  67. /*++
  68. Routine Description:
  69. This routine implements the FSD part of the NtCloseFile API calls.
  70. Arguments:
  71. MsfsDeviceObject - Supplies the device object to use.
  72. Irp - Supplies the Irp being processed
  73. Return Value:
  74. NTSTATUS - The Fsd status for the Irp
  75. --*/
  76. {
  77. NTSTATUS status;
  78. PAGED_CODE();
  79. DebugTrace(+1, Dbg, "MsFsdClose\n", 0);
  80. //
  81. // Call the common close routine.
  82. //
  83. FsRtlEnterFileSystem();
  84. status = MsCommonClose( MsfsDeviceObject, Irp );
  85. FsRtlExitFileSystem();
  86. //
  87. // Return to our caller.
  88. //
  89. DebugTrace(-1, Dbg, "MsFsdClose -> %08lx\n", status );
  90. return status;
  91. }
  92. NTSTATUS
  93. MsCommonClose (
  94. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  95. IN PIRP Irp
  96. )
  97. /*++
  98. Routine Description:
  99. This is the common routine for closing a file.
  100. Arguments:
  101. MsfsDeviceObject - Supplies a pointer to our device object.
  102. Irp - Supplies the Irp to process
  103. Return Value:
  104. NTSTATUS - the return status for the operation
  105. --*/
  106. {
  107. NTSTATUS status;
  108. PIO_STACK_LOCATION irpSp;
  109. PVOID fsContext, fsContext2;
  110. PAGED_CODE();
  111. //
  112. // Get the current stack location
  113. //
  114. irpSp = IoGetCurrentIrpStackLocation( Irp );
  115. DebugTrace(+1, Dbg, "MsCommonClose...\n", 0);
  116. DebugTrace( 0, Dbg, " Irp = %08lx\n", (ULONG)Irp);
  117. //
  118. // Decode the file object to figure out who we are.
  119. //
  120. if (MsDecodeFileObject( irpSp->FileObject,
  121. &fsContext,
  122. &fsContext2 ) == NTC_UNDEFINED) {
  123. //
  124. // FCB and CCB nodes got marked inactive on cleanup. Reference them manualy.
  125. //
  126. MsReferenceNode( ((PNODE_HEADER)(fsContext)) );
  127. }
  128. //
  129. // Ignore the return code from MsDecode. Parse the fsContext
  130. // to decide how to process the close IRP.
  131. //
  132. switch ( NodeType( fsContext ) ) {
  133. case MSFS_NTC_VCB:
  134. status = MsCloseVcb( MsfsDeviceObject,
  135. Irp,
  136. (PVCB)fsContext,
  137. irpSp->FileObject );
  138. //
  139. // Release the reference to the VCB obtained from MsDecodeFileObject.
  140. //
  141. MsDereferenceVcb( (PVCB)fsContext );
  142. break;
  143. case MSFS_NTC_ROOT_DCB:
  144. status = MsCloseRootDcb( MsfsDeviceObject,
  145. Irp,
  146. (PROOT_DCB)fsContext,
  147. (PROOT_DCB_CCB)fsContext2,
  148. irpSp->FileObject );
  149. //
  150. // Release the reference to the root DCB obtained from
  151. // MsDecodeFileObject.
  152. //
  153. MsDereferenceRootDcb( (PROOT_DCB)fsContext );
  154. break;
  155. case MSFS_NTC_FCB:
  156. status = MsCloseFcb( MsfsDeviceObject,
  157. Irp,
  158. (PFCB)fsContext,
  159. irpSp->FileObject );
  160. //
  161. // Release the reference to the FCB obtained from MsDecodeFileObject.
  162. //
  163. MsDereferenceFcb( (PFCB)fsContext );
  164. break;
  165. case MSFS_NTC_CCB:
  166. status = MsCloseCcb( MsfsDeviceObject,
  167. Irp,
  168. (PCCB)fsContext,
  169. irpSp->FileObject );
  170. //
  171. // Release the reference to the CCB obtained from MsDecodeFileObject.
  172. //
  173. MsDereferenceCcb( (PCCB)fsContext );
  174. break;
  175. #ifdef MSDBG
  176. default:
  177. //
  178. // This is not one of ours.
  179. //
  180. KeBugCheck( MAILSLOT_FILE_SYSTEM );
  181. break;
  182. #endif
  183. }
  184. //
  185. // Complete the close IRP.
  186. //
  187. MsCompleteRequest( Irp, status );
  188. DebugTrace(-1, Dbg, "MsCommonClose -> %08lx\n", status);
  189. return status;
  190. }
  191. NTSTATUS
  192. MsCloseVcb (
  193. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  194. IN PIRP Irp,
  195. IN PVCB Vcb,
  196. IN PFILE_OBJECT FileObject
  197. )
  198. /*++
  199. Routine Description:
  200. This routine closes the a file object that had opened the file system.
  201. Arguments:
  202. MsfsDeviceObject - Supplies a pointer to our device object.
  203. Irp - Supplies the IRP associate with the close. This procedure
  204. completes the IRP.
  205. Vcb - Supplies the VCB for the mailslot file system.
  206. FileObject - Supplies the file object being closed.
  207. Return Value:
  208. NTSTATUS - STATUS_SUCCESS
  209. --*/
  210. {
  211. NTSTATUS status;
  212. PAGED_CODE();
  213. DebugTrace(+1, Dbg, "MsCloseVcb, Vcb = %08lx\n", (ULONG)Vcb);
  214. //
  215. // Clear the referenced pointer to the VCB in the file object
  216. // and derefence the VCB.
  217. //
  218. ASSERT ( FileObject->FsContext == Vcb );
  219. MsSetFileObject( FileObject, NULL, NULL );
  220. MsDereferenceVcb( Vcb );
  221. //
  222. // Return to the caller.
  223. //
  224. return STATUS_SUCCESS;
  225. }
  226. NTSTATUS
  227. MsCloseRootDcb (
  228. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  229. IN PIRP Irp,
  230. IN PROOT_DCB RootDcb,
  231. IN PROOT_DCB_CCB Ccb,
  232. IN PFILE_OBJECT FileObject
  233. )
  234. /*++
  235. Routine Description:
  236. This routine closes a file object that had opened the root directory
  237. Arguments:
  238. MsfsDeviceObject - Supplies a pointer to our device object.
  239. Irp - Supplies the Irp associated with the close. This procedure
  240. completes the Irp.
  241. RootDcb - Supplies the RootDcb for the mailslot file system.
  242. Ccb - Supplies the ccb.
  243. FileObject - Supplies the file object being closed
  244. Return Value:
  245. NTSTATUS - STATUS_SUCCESS
  246. --*/
  247. {
  248. NTSTATUS status;
  249. PAGED_CODE();
  250. DebugTrace(+1, Dbg, "MsCloseRootDcb, RootDcb = %08lx\n", (ULONG)RootDcb);
  251. //
  252. // Clear the file object pointers.
  253. //
  254. MsSetFileObject( FileObject, NULL, NULL );
  255. //
  256. // Drop the reference to the root DCB CCB. It should be deleted at this point.
  257. //
  258. MsDereferenceCcb( (PCCB)Ccb );
  259. //
  260. // Return to the caller.
  261. //
  262. return STATUS_SUCCESS;
  263. }
  264. NTSTATUS
  265. MsCloseCcb (
  266. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  267. IN PIRP Irp,
  268. IN PCCB Ccb,
  269. IN PFILE_OBJECT FileObject
  270. )
  271. /*++
  272. Routine Description:
  273. The routine closes a file object belonging the the client side of
  274. a mailslot file.
  275. Arguments:
  276. MsfsDeviceObject - Supplies a pointer to our device object.
  277. Irp - Supplies the Irp associated with the close, The irp either
  278. get completed here or is enqueued in the data queue to be completed
  279. later.
  280. Ccb - Supplies the ccb for the mailslot being closed.
  281. FileObject - Supplies the caller file object that is being closed.
  282. Return Value:
  283. NTSTATUS - An appropriate completion status.
  284. --*/
  285. {
  286. NTSTATUS status;
  287. PAGED_CODE();
  288. DebugTrace(+1, Dbg, "MsCloseCcb...\n", 0);
  289. status = STATUS_SUCCESS;
  290. //
  291. // Clear the file object pointers and delete the open
  292. // reference to the CCB.
  293. //
  294. MsSetFileObject( FileObject, NULL, NULL );
  295. MsDereferenceCcb( Ccb ); // Close the Ccb
  296. return status;
  297. }
  298. NTSTATUS
  299. MsCloseFcb (
  300. IN PMSFS_DEVICE_OBJECT MsfsDeviceObject,
  301. IN PIRP Irp,
  302. IN PFCB Fcb,
  303. IN PFILE_OBJECT FileObject
  304. )
  305. /*++
  306. Routine Description:
  307. The routine closes a server side file object that opened a mailslot.
  308. Arguments:
  309. MsfsDeviceObject - Supplies a pointer to our device object.
  310. Irp - Supplies the Irp associated with the close, The irp either
  311. get completed here or is enqueued in the data queue to be completed
  312. later
  313. Ccb - Supplies the ccb for the mailslot being closed
  314. FileObject - Supplies the caller file object that is being closed
  315. Return Value:
  316. NTSTATUS - An appropriate completion status.
  317. --*/
  318. {
  319. NTSTATUS status;
  320. PAGED_CODE();
  321. DebugTrace(+1, Dbg, "MsCloseCcb...\n", 0);
  322. status = STATUS_SUCCESS;
  323. //
  324. // The root directory has changed, complete any notify requests.
  325. //
  326. MsCheckForNotify( Fcb->ParentDcb, TRUE, STATUS_SUCCESS );
  327. //
  328. // Clear the FsContext pointer in the file object. This
  329. // indicates that the file is in the closing state. Finally
  330. // delete the open reference to the FCB.
  331. //
  332. MsSetFileObject( FileObject, NULL, NULL );
  333. MsDereferenceFcb( Fcb ); // Close the Fcb
  334. return status;
  335. }