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.

226 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. FlushBuf.c
  5. Abstract:
  6. This module implements the File Flush Buffers routine for NPFS called by
  7. the 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_FLUSH_BUFFERS)
  17. //
  18. // local procedure prototypes
  19. //
  20. NTSTATUS
  21. NpCommonFlushBuffers (
  22. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  23. IN PIRP Irp
  24. );
  25. #ifdef ALLOC_PRAGMA
  26. #pragma alloc_text(PAGE, NpCommonFlushBuffers)
  27. #pragma alloc_text(PAGE, NpFsdFlushBuffers)
  28. #endif
  29. NTSTATUS
  30. NpFsdFlushBuffers (
  31. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  32. IN PIRP Irp
  33. )
  34. /*++
  35. Routine Description:
  36. This routine implements the FSD part of the NtFlushBuffersFile 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, "NpFsdFlushBuffers\n", 0);
  47. //
  48. // Call the common Flush routine.
  49. //
  50. FsRtlEnterFileSystem();
  51. NpAcquireSharedVcb();
  52. Status = NpCommonFlushBuffers( NpfsDeviceObject, Irp );
  53. NpReleaseVcb();
  54. FsRtlExitFileSystem();
  55. if (Status != STATUS_PENDING) {
  56. NpCompleteRequest( Irp, Status );
  57. }
  58. //
  59. // And return to our caller
  60. //
  61. DebugTrace(-1, Dbg, "NpFsdFlushBuffers -> %08lx\n", Status );
  62. return Status;
  63. }
  64. //
  65. // Internal support routine
  66. //
  67. NTSTATUS
  68. NpCommonFlushBuffers (
  69. IN PNPFS_DEVICE_OBJECT NpfsDeviceObject,
  70. IN PIRP Irp
  71. )
  72. /*++
  73. Routine Description:
  74. This is the common routine for Flushing buffers for a file.
  75. Arguments:
  76. Irp - Supplies the Irp to process
  77. Return Value:
  78. NTSTATUS - the return status for the operation
  79. --*/
  80. {
  81. NTSTATUS Status;
  82. PIO_STACK_LOCATION IrpSp;
  83. PCCB Ccb;
  84. NAMED_PIPE_END NamedPipeEnd;
  85. PDATA_QUEUE WriteQueue;
  86. //
  87. // Get the current stack location
  88. //
  89. PAGED_CODE();
  90. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  91. DebugTrace(+1, Dbg, "NpCommonFlushBuffers\n", 0);
  92. DebugTrace( 0, Dbg, "Irp = %08lx\n", Irp);
  93. DebugTrace( 0, Dbg, "FileObject = %08lx\n", IrpSp->FileObject);
  94. //
  95. // Decode the file object to figure out who we are. If the result
  96. // is not a ccb then the pipe has been disconnected. We don't need the
  97. // Fcb back from the call
  98. //
  99. if (NpDecodeFileObject( IrpSp->FileObject,
  100. NULL,
  101. &Ccb,
  102. &NamedPipeEnd ) != NPFS_NTC_CCB) {
  103. DebugTrace(0, Dbg, "Pipe is disconnected from us\n", 0);
  104. Status = STATUS_PIPE_DISCONNECTED;
  105. DebugTrace(-1, Dbg, "NpCommonFlushBuffers -> %08lx\n", Status );
  106. return Status;
  107. }
  108. NpAcquireExclusiveCcb(Ccb);
  109. try {
  110. //
  111. // Figure out the data queue that the flush buffer is
  112. // targetted at. It is the queue that we do writes into
  113. //
  114. if (NamedPipeEnd == FILE_PIPE_SERVER_END) {
  115. WriteQueue = &Ccb->DataQueue[ FILE_PIPE_OUTBOUND ];
  116. } else {
  117. WriteQueue = &Ccb->DataQueue[ FILE_PIPE_INBOUND ];
  118. }
  119. //
  120. // Now from the write queue check if contains write entries. If
  121. // it does not contain write entries then we immediately complete
  122. // this irp with success because there isn't anything to flush
  123. //
  124. if (!NpIsDataQueueWriters( WriteQueue )) {
  125. DebugTrace(0, Dbg, "Pipe does not contain write entries\n", 0);
  126. try_return(Status = STATUS_SUCCESS);
  127. }
  128. //
  129. // Otherwise the queue is full of writes so we simply
  130. // enqueue this irp to the back to the queue and set our
  131. // return status to pending, also mark the irp pending
  132. //
  133. Status = NpAddDataQueueEntry( NamedPipeEnd,
  134. Ccb,
  135. WriteQueue,
  136. WriteEntries,
  137. Flush,
  138. 0,
  139. Irp,
  140. NULL,
  141. 0 );
  142. try_exit: NOTHING;
  143. } finally {
  144. NpReleaseCcb(Ccb);
  145. }
  146. DebugTrace(-1, Dbg, "NpCommonFlushBuffers -> %08lx\n", Status);
  147. return Status;
  148. }