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.

218 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Cleanup.c
  5. Abstract:
  6. This module implements the File Cleanup routine for NPFS called by the
  7. dispatch driver.
  8. Author:
  9. Gary Kimura [GaryKi] 21-Aug-1990
  10. Revision History:
  11. --*/
  12. #include "NpProcs.h"
  13. //
  14. // The debug trace level
  15. //
  16. #define Dbg (DEBUG_TRACE_CLEANUP)
  17. //
  18. // local procedure prototypes
  19. //
  20. NTSTATUS
  21. NpCommonCleanup (
  22. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  23. IN PIRP Irp
  24. );
  25. #ifdef ALLOC_PRAGMA
  26. #pragma alloc_text(PAGE, NpCommonCleanup)
  27. #pragma alloc_text(PAGE, NpFsdCleanup)
  28. #endif
  29. NTSTATUS
  30. NpFsdCleanup (
  31. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  32. IN PIRP Irp
  33. )
  34. /*++
  35. Routine Description:
  36. This routine implements the FSD part of the NtCleanupFile API calls.
  37. Arguments:
  38. NpfsDeviceObject - Supplies the device object to use.
  39. Irp - Supplies the Irp being processed
  40. Return Value:
  41. NTSTATUS - The Fsd status for the Irp
  42. --*/
  43. {
  44. NTSTATUS Status;
  45. PAGED_CODE();
  46. DebugTrace(+1, Dbg, "NpFsdCleanup\n", 0);
  47. //
  48. // Call the common Cleanup routine.
  49. //
  50. FsRtlEnterFileSystem();
  51. Status = NpCommonCleanup( NpfsDeviceObject, Irp );
  52. FsRtlExitFileSystem();
  53. if (Status != STATUS_PENDING) {
  54. NpCompleteRequest (Irp, Status);
  55. }
  56. //
  57. // And return to our caller
  58. //
  59. DebugTrace(-1, Dbg, "NpFsdCleanup -> %08lx\n", Status );
  60. return Status;
  61. }
  62. //
  63. // Internal support routine
  64. //
  65. NTSTATUS
  66. NpCommonCleanup (
  67. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  68. IN PIRP Irp
  69. )
  70. /*++
  71. Routine Description:
  72. This is the common routine for cleanup
  73. Arguments:
  74. Irp - Supplies the Irp to process
  75. Return Value:
  76. NTSTATUS - the return status for the operation
  77. --*/
  78. {
  79. NTSTATUS Status;
  80. PIO_STACK_LOCATION IrpSp;
  81. NODE_TYPE_CODE NodeTypeCode;
  82. PCCB Ccb;
  83. PROOT_DCB RootDcb;
  84. NAMED_PIPE_END NamedPipeEnd;
  85. LIST_ENTRY DeferredList;
  86. PAGED_CODE();
  87. InitializeListHead (&DeferredList);
  88. //
  89. // Get the current stack location
  90. //
  91. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  92. DebugTrace(+1, Dbg, "NpCommonCleanup...\n", 0);
  93. DebugTrace( 0, Dbg, "Irp = %08lx\n", Irp);
  94. //
  95. // Now acquire exclusive access to the Vcb
  96. //
  97. NpAcquireExclusiveVcb();
  98. //
  99. // Decode the file object to figure out who we are. If the result
  100. // is null then the pipe has been disconnected.
  101. //
  102. if ((NodeTypeCode = NpDecodeFileObject( IrpSp->FileObject,
  103. &RootDcb,
  104. &Ccb,
  105. &NamedPipeEnd )) == NTC_UNDEFINED) {
  106. DebugTrace(0, Dbg, "Pipe is disconnected from us\n", 0);
  107. } else {
  108. //
  109. // Now case on the type of file object we're closing
  110. //
  111. switch (NodeTypeCode) {
  112. case NPFS_NTC_VCB:
  113. break;
  114. case NPFS_NTC_ROOT_DCB:
  115. break;
  116. case NPFS_NTC_CCB:
  117. //
  118. // If this is the server end of a pipe, decrement the count
  119. // of the number of instances the server end has open.
  120. // When this count is 0, attempts to connect to the pipe
  121. // return OBJECT_NAME_NOT_FOUND instead of
  122. // PIPE_NOT_AVAILABLE.
  123. //
  124. if ( NamedPipeEnd == FILE_PIPE_SERVER_END ) {
  125. ASSERT( Ccb->Fcb->ServerOpenCount != 0 );
  126. Ccb->Fcb->ServerOpenCount -= 1;
  127. }
  128. //
  129. // The set closing state routines does everything to transition
  130. // the named pipe to a closing state.
  131. //
  132. Status = NpSetClosingPipeState (Ccb, Irp, NamedPipeEnd, &DeferredList);
  133. break;
  134. }
  135. }
  136. NpReleaseVcb ();
  137. //
  138. // Complete any deferred IRPs now we have released our locks
  139. //
  140. NpCompleteDeferredIrps (&DeferredList);
  141. Status = STATUS_SUCCESS;
  142. DebugTrace(-1, Dbg, "NpCommonCleanup -> %08lx\n", Status);
  143. return Status;
  144. }