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.

242 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. RawDisp.c
  5. Abstract:
  6. This module is the main entry point for all major function codes.
  7. It is responsible for dispatching the request to the appropriate
  8. routine.
  9. Author:
  10. David Goebel [DavidGoe] 28-Feb-1991
  11. Revision History:
  12. --*/
  13. #include "RawProcs.h"
  14. #ifdef ALLOC_PRAGMA
  15. #pragma alloc_text(PAGE, RawDispatch)
  16. #endif
  17. NTSTATUS
  18. RawDispatch (
  19. IN PVOLUME_DEVICE_OBJECT VolumeDeviceObject,
  20. IN PIRP Irp
  21. )
  22. /*++
  23. Routine Description:
  24. Dispatch the request to the appropriate function. It is the worker
  25. function's responsibility to appropriately complete the IRP.
  26. Arguments:
  27. VolumeDeviceObject - Supplies the volume device object to use.
  28. Irp - Supplies the Irp being processed
  29. Return Value:
  30. NTSTATUS - The status for the IRP
  31. --*/
  32. {
  33. NTSTATUS Status;
  34. PIO_STACK_LOCATION IrpSp;
  35. PVCB Vcb;
  36. PAGED_CODE();
  37. //
  38. // Get a pointer to the current stack location. This location contains
  39. // the function codes and parameters for this particular request.
  40. //
  41. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  42. //
  43. // Check for operations associated with our FileSystemDeviceObjects
  44. // as opposed to our VolumeDeviceObjects. Only mount is allowed to
  45. // continue through the normal dispatch in this case.
  46. //
  47. if ((((PDEVICE_OBJECT)VolumeDeviceObject)->Size == sizeof(DEVICE_OBJECT)) &&
  48. !((IrpSp->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL) &&
  49. (IrpSp->MinorFunction == IRP_MN_MOUNT_VOLUME))) {
  50. if ((IrpSp->MajorFunction == IRP_MJ_CREATE) ||
  51. (IrpSp->MajorFunction == IRP_MJ_CLEANUP) ||
  52. (IrpSp->MajorFunction == IRP_MJ_CLOSE)) {
  53. Status = STATUS_SUCCESS;
  54. } else {
  55. Status = STATUS_INVALID_DEVICE_REQUEST;
  56. }
  57. RawCompleteRequest( Irp, Status );
  58. return Status;
  59. }
  60. FsRtlEnterFileSystem();
  61. //
  62. // Get a pointer to the Vcb. Note that is we are mount a volume this
  63. // pointer will not have meaning, but that is OK since we will not
  64. // use it in that case.
  65. //
  66. Vcb = &VolumeDeviceObject->Vcb;
  67. //
  68. // Case on the function that is being performed by the requestor. We
  69. // should only see expected requests since we filled the dispatch table
  70. // by hand.
  71. //
  72. try {
  73. switch ( IrpSp->MajorFunction ) {
  74. case IRP_MJ_CLEANUP:
  75. Status = RawCleanup( Vcb, Irp, IrpSp );
  76. break;
  77. case IRP_MJ_CLOSE:
  78. Status = RawClose( Vcb, Irp, IrpSp );
  79. break;
  80. case IRP_MJ_CREATE:
  81. Status = RawCreate( Vcb, Irp, IrpSp );
  82. break;
  83. case IRP_MJ_FILE_SYSTEM_CONTROL:
  84. Status = RawFileSystemControl( Vcb, Irp, IrpSp );
  85. break;
  86. case IRP_MJ_PNP:
  87. if(IrpSp->MinorFunction == IRP_MN_QUERY_REMOVE_DEVICE) {
  88. Status = STATUS_DEVICE_BUSY;
  89. RawCompleteRequest(Irp, Status);
  90. break;
  91. }
  92. case IRP_MJ_READ:
  93. case IRP_MJ_WRITE:
  94. case IRP_MJ_DEVICE_CONTROL:
  95. Status = RawReadWriteDeviceControl( Vcb, Irp, IrpSp );
  96. break;
  97. case IRP_MJ_QUERY_INFORMATION:
  98. Status = RawQueryInformation( Vcb, Irp, IrpSp );
  99. break;
  100. case IRP_MJ_SET_INFORMATION:
  101. Status = RawSetInformation( Vcb, Irp, IrpSp );
  102. break;
  103. case IRP_MJ_QUERY_VOLUME_INFORMATION:
  104. Status = RawQueryVolumeInformation( Vcb, Irp, IrpSp );
  105. break;
  106. default:
  107. //
  108. // We should never get a request we don't expect.
  109. //
  110. KdPrint(("Raw: Illegal Irp major function code 0x%x.\n", IrpSp->MajorFunction));
  111. KeBugCheckEx( FILE_SYSTEM, 0, 0, 0, 0 );
  112. }
  113. } except( FsRtlIsNtstatusExpected(GetExceptionCode()) ?
  114. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) {
  115. //
  116. // No routine we call should ever generate an exception
  117. //
  118. Status = GetExceptionCode();
  119. KdPrint(("Raw: Unexpected excpetion %X.\n", Status));
  120. }
  121. //
  122. // And return to our caller
  123. //
  124. FsRtlExitFileSystem();
  125. return Status;
  126. }
  127. //
  128. // Completion routine for read, write, and device control to deal with
  129. // verify issues. Implemented in RawDisp.c
  130. //
  131. NTSTATUS
  132. RawCompletionRoutine(
  133. IN PDEVICE_OBJECT DeviceObject,
  134. IN PIRP Irp,
  135. IN PVOID Context
  136. )
  137. {
  138. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
  139. //
  140. // Simply update the file pointer context in the file object if we
  141. // were successful and this was a synrhonous read or write.
  142. //
  143. if (((IrpSp->MajorFunction == IRP_MJ_READ) ||
  144. (IrpSp->MajorFunction == IRP_MJ_WRITE)) &&
  145. (IrpSp->FileObject != NULL) &&
  146. FlagOn(IrpSp->FileObject->Flags, FO_SYNCHRONOUS_IO) &&
  147. NT_SUCCESS(Irp->IoStatus.Status)) {
  148. IrpSp->FileObject->CurrentByteOffset.QuadPart =
  149. IrpSp->FileObject->CurrentByteOffset.QuadPart +
  150. Irp->IoStatus.Information;
  151. }
  152. //
  153. // If IoCallDriver returned PENDING, mark our stack location
  154. // with pending.
  155. //
  156. if ( Irp->PendingReturned ) {
  157. IoMarkIrpPending( Irp );
  158. }
  159. UNREFERENCED_PARAMETER( DeviceObject );
  160. UNREFERENCED_PARAMETER( Context );
  161. return STATUS_SUCCESS;
  162. }
  163.