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.

156 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. Flush.c
  5. Abstract:
  6. This module implements device flush functionality for UDF.
  7. // @@BEGIN_DDKSPLIT
  8. Author:
  9. Tom Jolly [08-15-2000]
  10. Revision History:
  11. // @@END_DDKSPLIT
  12. --*/
  13. #include "UdfProcs.h"
  14. //
  15. // The Bug check file id for this module
  16. //
  17. #define BugCheckFileId (UDFS_BUG_CHECK_FLUSH)
  18. //
  19. // The local debug trace level
  20. //
  21. #define Dbg (UDFS_DEBUG_LEVEL_FLUSH)
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text(PAGE, UdfHijackIrpAndFlushDevice)
  24. #endif
  25. //
  26. // Local support routine
  27. //
  28. NTSTATUS
  29. UdfHijackCompletionRoutine (
  30. IN PDEVICE_OBJECT DeviceObject,
  31. IN PIRP Irp,
  32. IN PVOID Contxt
  33. )
  34. {
  35. //
  36. // Set the event so that our call will wake up.
  37. //
  38. KeSetEvent( (PKEVENT)Contxt, 0, FALSE );
  39. UNREFERENCED_PARAMETER( DeviceObject );
  40. UNREFERENCED_PARAMETER( Irp );
  41. return STATUS_MORE_PROCESSING_REQUIRED;
  42. }
  43. NTSTATUS
  44. UdfHijackIrpAndFlushDevice (
  45. IN PIRP_CONTEXT IrpContext,
  46. IN PIRP Irp,
  47. IN PDEVICE_OBJECT TargetDeviceObject
  48. )
  49. /*++
  50. Routine Description:
  51. This routine is called when we need to send a flush to a device but
  52. we don't have a flush Irp. What this routine does is make a copy
  53. of its current Irp stack location, but changes the Irp Major code
  54. to a IRP_MJ_FLUSH_BUFFERS amd then send it down, but cut it off at
  55. the knees in the completion routine, fix it up and return to the
  56. user as if nothing had happened.
  57. Arguments:
  58. Irp - The Irp to hijack
  59. TargetDeviceObject - The device to send the request to.
  60. Return Value:
  61. NTSTATUS - The Status from the flush in case anybody cares.
  62. --*/
  63. {
  64. KEVENT Event;
  65. NTSTATUS Status;
  66. PIO_STACK_LOCATION NextIrpSp;
  67. PAGED_CODE();
  68. //
  69. // Get the next stack location, and copy over the stack location
  70. //
  71. NextIrpSp = IoGetNextIrpStackLocation( Irp );
  72. *NextIrpSp = *IoGetCurrentIrpStackLocation( Irp );
  73. NextIrpSp->MajorFunction = IRP_MJ_FLUSH_BUFFERS;
  74. NextIrpSp->MinorFunction = 0;
  75. //
  76. // Set up the completion routine
  77. //
  78. KeInitializeEvent( &Event, NotificationEvent, FALSE );
  79. IoSetCompletionRoutine( Irp,
  80. UdfHijackCompletionRoutine,
  81. &Event,
  82. TRUE,
  83. TRUE,
  84. TRUE );
  85. //
  86. // Send the request.
  87. //
  88. Status = IoCallDriver( TargetDeviceObject, Irp );
  89. if (Status == STATUS_PENDING) {
  90. KeWaitForSingleObject( &Event, Executive, KernelMode, FALSE, NULL );
  91. Status = Irp->IoStatus.Status;
  92. }
  93. //
  94. // If the driver doesn't support flushes, return SUCCESS.
  95. //
  96. if (Status == STATUS_INVALID_DEVICE_REQUEST) {
  97. Status = STATUS_SUCCESS;
  98. }
  99. Irp->IoStatus.Status = 0;
  100. Irp->IoStatus.Information = 0;
  101. return Status;
  102. }