Source code of Windows XP (NT5)
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.

210 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. close.cxx
  5. Abstract:
  6. This module contains code for cleanup and close IRPs.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text( PAGE, UlClose )
  14. #endif // ALLOC_PRAGMA
  15. #if 0
  16. NOT PAGEABLE -- UlCleanup
  17. #endif
  18. //
  19. // Public functions.
  20. //
  21. /***************************************************************************++
  22. Routine Description:
  23. This is the routine that handles Cleanup IRPs in UL. Cleanup IRPs
  24. are issued after the last handle to the file object is closed.
  25. Arguments:
  26. pDeviceObject - Supplies a pointer to the target device object.
  27. pIrp - Supplies a pointer to IO request packet.
  28. Return Value:
  29. NTSTATUS - Completion status.
  30. --***************************************************************************/
  31. NTSTATUS
  32. UlCleanup(
  33. IN PDEVICE_OBJECT pDeviceObject,
  34. IN PIRP pIrp
  35. )
  36. {
  37. NTSTATUS status;
  38. PIO_STACK_LOCATION pIrpSp;
  39. UL_ENTER_DRIVER( "UlCleanup", pIrp );
  40. //
  41. // Snag the current IRP stack pointer.
  42. //
  43. pIrpSp = IoGetCurrentIrpStackLocation( pIrp );
  44. IF_DEBUG( OPEN_CLOSE )
  45. {
  46. KdPrint((
  47. "UlCleanup: cleanup on file object %lx\n",
  48. pIrpSp->FileObject
  49. ));
  50. }
  51. //
  52. // app pool or control channel?
  53. //
  54. if (pDeviceObject == g_pUlAppPoolDeviceObject &&
  55. IS_APP_POOL( pIrpSp->FileObject ))
  56. {
  57. //
  58. // app pool, let's detach this process from the app pool
  59. //
  60. status = UlDetachProcessFromAppPool(
  61. GET_APP_POOL_PROCESS(pIrpSp->FileObject)
  62. );
  63. MARK_INVALID_APP_POOL( pIrpSp->FileObject );
  64. }
  65. else if (pDeviceObject == g_pUlFilterDeviceObject &&
  66. IS_FILTER_PROCESS( pIrpSp->FileObject ))
  67. {
  68. //
  69. // filter channel
  70. //
  71. status = UlDetachFilterProcess(
  72. GET_FILTER_PROCESS(pIrpSp->FileObject)
  73. );
  74. MARK_INVALID_FILTER_CHANNEL( pIrpSp->FileObject );
  75. }
  76. else if (IS_CONTROL_CHANNEL( pIrpSp->FileObject ))
  77. {
  78. status = UlCloseControlChannel(
  79. GET_CONTROL_CHANNEL(pIrpSp->FileObject)
  80. );
  81. MARK_INVALID_CONTROL_CHANNEL( pIrpSp->FileObject );
  82. }
  83. else
  84. {
  85. status = STATUS_INVALID_DEVICE_REQUEST;
  86. }
  87. pIrp->IoStatus.Status = status;
  88. UlCompleteRequest( pIrp, g_UlPriorityBoost );
  89. UL_LEAVE_DRIVER( "UlCleanup" );
  90. RETURN(status);
  91. } // UlCleanup
  92. /***************************************************************************++
  93. Routine Description:
  94. This is the routine that handles Close IRPs in UL. Close IRPs are
  95. issued after the last reference to the file object is removed.
  96. Arguments:
  97. pDeviceObject - Supplies a pointer to the target device object.
  98. pIrp - Supplies a pointer to IO request packet.
  99. Return Value:
  100. NTSTATUS - Completion status.
  101. --***************************************************************************/
  102. NTSTATUS
  103. UlClose(
  104. IN PDEVICE_OBJECT pDeviceObject,
  105. IN PIRP pIrp
  106. )
  107. {
  108. NTSTATUS status;
  109. PIO_STACK_LOCATION pIrpSp;
  110. UNREFERENCED_PARAMETER( pDeviceObject );
  111. //
  112. // Sanity check.
  113. //
  114. PAGED_CODE();
  115. UL_ENTER_DRIVER( "UlClose", pIrp );
  116. status = STATUS_SUCCESS;
  117. //
  118. // Snag the current IRP stack pointer.
  119. //
  120. pIrpSp = IoGetCurrentIrpStackLocation( pIrp );
  121. //
  122. // If it's an App Pool or filter channel we have to delete
  123. // the associated object.
  124. //
  125. if (pDeviceObject == g_pUlAppPoolDeviceObject &&
  126. IS_EX_APP_POOL( pIrpSp->FileObject ))
  127. {
  128. UlFreeAppPoolProcess(GET_APP_POOL_PROCESS(pIrpSp->FileObject));
  129. }
  130. else if (pDeviceObject == g_pUlFilterDeviceObject &&
  131. IS_EX_FILTER_PROCESS( pIrpSp->FileObject ))
  132. {
  133. UlFreeFilterProcess(GET_FILTER_PROCESS(pIrpSp->FileObject));
  134. }
  135. IF_DEBUG( OPEN_CLOSE )
  136. {
  137. KdPrint((
  138. "UlClose: closing file object %lx\n",
  139. pIrpSp->FileObject
  140. ));
  141. }
  142. pIrp->IoStatus.Status = status;
  143. UlCompleteRequest( pIrp, g_UlPriorityBoost );
  144. UL_LEAVE_DRIVER( "UlClose" );
  145. RETURN(status);
  146. } // UlClose