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.

219 lines
3.6 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 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_CLOSE)
  17. //
  18. // local procedure prototypes
  19. //
  20. NTSTATUS
  21. NpCommonClose (
  22. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  23. IN PIRP Irp
  24. );
  25. #ifdef ALLOC_PRAGMA
  26. #pragma alloc_text(PAGE, NpCommonClose)
  27. #pragma alloc_text(PAGE, NpFsdClose)
  28. #endif
  29. NTSTATUS
  30. NpFsdClose (
  31. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  32. IN PIRP Irp
  33. )
  34. /*++
  35. Routine Description:
  36. This routine implements the FSD part of the NtCloseFile 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, "NpFsdClose\n", 0);
  47. //
  48. // Call the common Close routine.
  49. //
  50. FsRtlEnterFileSystem();
  51. Status = NpCommonClose( NpfsDeviceObject, Irp );
  52. FsRtlExitFileSystem();
  53. //
  54. // And return to our caller
  55. //
  56. DebugTrace(-1, Dbg, "NpFsdClose -> %08lx\n", Status );
  57. return Status;
  58. }
  59. //
  60. // Internal support routine
  61. //
  62. NTSTATUS
  63. NpCommonClose (
  64. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  65. IN PIRP Irp
  66. )
  67. /*++
  68. Routine Description:
  69. This is the common routine for creating/opening a file.
  70. Arguments:
  71. Irp - Supplies the Irp to process
  72. Return Value:
  73. NTSTATUS - the return status for the operation
  74. --*/
  75. {
  76. NTSTATUS Status;
  77. PIO_STACK_LOCATION IrpSp;
  78. NODE_TYPE_CODE NodeTypeCode;
  79. PFCB Fcb;
  80. PCCB Ccb;
  81. LIST_ENTRY DeferredList;
  82. PAGED_CODE();
  83. InitializeListHead (&DeferredList);
  84. //
  85. // Get the current stack location
  86. //
  87. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  88. DebugTrace(+1, Dbg, "NpCommonClose...\n", 0);
  89. DebugTrace( 0, Dbg, " Irp = %08lx\n", Irp);
  90. //
  91. // Now acquire exclusive access to the vcb
  92. //
  93. NpAcquireExclusiveVcb();
  94. //
  95. // Decode the file object to figure out who we are. If the result
  96. // is null then the pipe has been disconnected.
  97. //
  98. if ((NodeTypeCode = NpDecodeFileObject( IrpSp->FileObject,
  99. &Fcb,
  100. &Ccb,
  101. NULL )) == NTC_UNDEFINED) {
  102. DebugTrace(0, Dbg, "Pipe is disconnected from us\n", 0);
  103. } else {
  104. //
  105. // Now case on the type of file object we're closing
  106. //
  107. switch (NodeTypeCode) {
  108. case NPFS_NTC_VCB:
  109. //
  110. // Decrement the Open count
  111. //
  112. NpVcb->OpenCount -= 1;
  113. break;
  114. case NPFS_NTC_ROOT_DCB:
  115. //
  116. // Decrement the Open count and clear our fields in the file object
  117. //
  118. Fcb->OpenCount -= 1;
  119. //
  120. // Remove the root dcb ccb.
  121. //
  122. NpDeleteCcb (Ccb, &DeferredList);
  123. break;
  124. case NPFS_NTC_CCB:
  125. break;
  126. }
  127. }
  128. //
  129. // Complete the close irp
  130. //
  131. NpReleaseVcb( );
  132. //
  133. // Complete any deferred IRPs now we have droped the locks
  134. //
  135. NpCompleteDeferredIrps (&DeferredList);
  136. Status = STATUS_SUCCESS;
  137. NpCompleteRequest (Irp, Status);
  138. DebugTrace(-1, Dbg, "NpCommonClose -> %08lx\n", Status);
  139. return Status;
  140. }