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.

278 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. dispatch.c
  5. Abstract:
  6. This module contains the IRP dispatch code for SPUD.
  7. Author:
  8. Keith Moore (keithmo) 09-Feb-1998
  9. Revision History:
  10. --*/
  11. #include "spudp.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text( PAGE, SpudIrpCreate )
  14. #pragma alloc_text( PAGE, SpudIrpClose )
  15. #pragma alloc_text( PAGE, SpudIrpQuery )
  16. #endif
  17. #if 0
  18. NOT PAGEABLE -- SpudIrpCleanup
  19. #endif
  20. //
  21. // Public functions.
  22. //
  23. NTSTATUS
  24. SpudIrpCreate(
  25. IN PDEVICE_OBJECT DeviceObject,
  26. IN PIRP Irp
  27. )
  28. /*++
  29. Routine Description:
  30. This routine handles IRP_MJ_CREATE IRPs. IRP_MJ_CREATE is issued when
  31. a new file object is being created.
  32. Arguments:
  33. DeviceObject - Pointer to the target device object.
  34. Irp - Pointer to the I/O request packet.
  35. Return Value:
  36. NTSTATUS - Completion status.
  37. --*/
  38. {
  39. NTSTATUS status = STATUS_SUCCESS;
  40. PVOID xchg;
  41. //
  42. // Sanity check.
  43. //
  44. PAGED_CODE();
  45. //
  46. // Ensure this is the only process that may access the driver.
  47. //
  48. xchg = InterlockedCompareExchangePointer(
  49. (PVOID *)&SpudOwningProcess,
  50. (PVOID)PsGetCurrentProcess(),
  51. NULL
  52. );
  53. ASSERT( xchg == NULL );
  54. //
  55. // Complete the IRP.
  56. //
  57. Irp->IoStatus.Status = status;
  58. IoCompleteRequest( Irp, SPUD_PRIORITY_BOOST );
  59. return status;
  60. } // SpudIrpCreate
  61. NTSTATUS
  62. SpudIrpClose(
  63. IN PDEVICE_OBJECT DeviceObject,
  64. IN PIRP Irp
  65. )
  66. /*++
  67. Routine Description:
  68. This routine handles IRP_MJ_CLOSE IRPs. IRP_MJ_CLOSE is issued when
  69. the final reference to a file object is removed and the object is
  70. being destroyed.
  71. Arguments:
  72. DeviceObject - Pointer to the target device object.
  73. Irp - Pointer to the I/O request packet.
  74. Return Value:
  75. NTSTATUS - Completion status.
  76. --*/
  77. {
  78. NTSTATUS status = STATUS_SUCCESS;
  79. PVOID xchg;
  80. //
  81. // Sanity check.
  82. //
  83. PAGED_CODE();
  84. //
  85. // Clear the owner process.
  86. //
  87. xchg = InterlockedCompareExchangePointer(
  88. (PVOID *)&SpudOwningProcess,
  89. NULL,
  90. (PVOID)PsGetCurrentProcess()
  91. );
  92. ASSERT( xchg == (PVOID)PsGetCurrentProcess() );
  93. //
  94. // Dereference the I/O completion port.
  95. //
  96. SpudDereferenceCompletionPort();
  97. //
  98. // Complete the IRP;
  99. //
  100. Irp->IoStatus.Status = status;
  101. IoCompleteRequest( Irp, SPUD_PRIORITY_BOOST );
  102. return status;
  103. } // SpudIrpClose
  104. NTSTATUS
  105. SpudIrpCleanup(
  106. IN PDEVICE_OBJECT DeviceObject,
  107. IN PIRP Irp
  108. )
  109. /*++
  110. Routine Description:
  111. This routine handles IRP_MJ_CLEANUP IRPs. IRP_MJ_CLEANUP is issued
  112. when the last handle to a file object is closed.
  113. Arguments:
  114. DeviceObject - Pointer to the target device object.
  115. Irp - Pointer to the I/O request packet.
  116. Return Value:
  117. NTSTATUS - Completion status.
  118. --*/
  119. {
  120. NTSTATUS status = STATUS_SUCCESS;
  121. //
  122. // Complete the IRP;
  123. //
  124. Irp->IoStatus.Status = status;
  125. IoCompleteRequest( Irp, SPUD_PRIORITY_BOOST );
  126. return status;
  127. } // SpudIrpCleanup
  128. NTSTATUS
  129. SpudIrpQuery(
  130. IN PDEVICE_OBJECT DeviceObject,
  131. IN PIRP Irp
  132. )
  133. /*++
  134. Routine Description:
  135. This routine handles IRP_MJ_QUERY IRPs.
  136. Arguments:
  137. DeviceObject - Pointer to the target device object.
  138. Irp - Pointer to the I/O request packet.
  139. Return Value:
  140. NTSTATUS - Completion status.
  141. --*/
  142. {
  143. NTSTATUS status = STATUS_SUCCESS;
  144. PIO_STACK_LOCATION irpSp;
  145. PFILE_NAME_INFORMATION nameInfo;
  146. ULONG bytesRequired;
  147. //
  148. // Sanity check.
  149. //
  150. PAGED_CODE();
  151. //
  152. // Validate the input arguments.
  153. //
  154. irpSp = IoGetCurrentIrpStackLocation( Irp );
  155. bytesRequired = sizeof(*nameInfo) - sizeof(nameInfo->FileName);
  156. if( irpSp->Parameters.QueryFile.Length >= bytesRequired ) {
  157. status = STATUS_INVALID_PARAMETER;
  158. }
  159. //
  160. // Return an empty name.
  161. //
  162. if( NT_SUCCESS(status) ) {
  163. nameInfo = Irp->AssociatedIrp.SystemBuffer;
  164. nameInfo->FileNameLength = 0;
  165. Irp->IoStatus.Information = bytesRequired;
  166. }
  167. //
  168. // Complete the IRP.
  169. //
  170. Irp->IoStatus.Status = status;
  171. IoCompleteRequest( Irp, SPUD_PRIORITY_BOOST );
  172. return status;
  173. } // SpudIrpQuery