Windows NT 4.0 source code leak
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.

233 lines
5.3 KiB

4 years ago
  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_READ:
  87. case IRP_MJ_WRITE:
  88. case IRP_MJ_DEVICE_CONTROL:
  89. Status = RawReadWriteDeviceControl( Vcb, Irp, IrpSp );
  90. break;
  91. case IRP_MJ_QUERY_INFORMATION:
  92. Status = RawQueryInformation( Vcb, Irp, IrpSp );
  93. break;
  94. case IRP_MJ_SET_INFORMATION:
  95. Status = RawSetInformation( Vcb, Irp, IrpSp );
  96. break;
  97. case IRP_MJ_QUERY_VOLUME_INFORMATION:
  98. Status = RawQueryVolumeInformation( Vcb, Irp, IrpSp );
  99. break;
  100. default:
  101. //
  102. // We should never get a request we don't expect.
  103. //
  104. KdPrint(("Raw: Illegal Irp major function code 0x%x.\n", IrpSp->MajorFunction));
  105. KeBugCheck( FILE_SYSTEM );
  106. }
  107. } except( FsRtlIsNtstatusExpected(GetExceptionCode()) ?
  108. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) {
  109. //
  110. // No routine we call should ever generate an exception
  111. //
  112. Status = GetExceptionCode();
  113. KdPrint(("Raw: Unexpected excpetion %X.\n", Status));
  114. }
  115. //
  116. // And return to our caller
  117. //
  118. FsRtlExitFileSystem();
  119. return Status;
  120. }
  121. //
  122. // Completion routine for read, write, and device control to deal with
  123. // verify issues. Implemented in RawDisp.c
  124. //
  125. NTSTATUS
  126. RawCompletionRoutine(
  127. IN PDEVICE_OBJECT DeviceObject,
  128. IN PIRP Irp,
  129. IN PVOID Context
  130. )
  131. {
  132. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
  133. //
  134. // Simply update the file pointer context in the file object if we
  135. // were successful and this was a synrhonous read or write.
  136. //
  137. if (((IrpSp->MajorFunction == IRP_MJ_READ) ||
  138. (IrpSp->MajorFunction == IRP_MJ_WRITE)) &&
  139. (IrpSp->FileObject != NULL) &&
  140. FlagOn(IrpSp->FileObject->Flags, FO_SYNCHRONOUS_IO) &&
  141. NT_SUCCESS(Irp->IoStatus.Status)) {
  142. IrpSp->FileObject->CurrentByteOffset.QuadPart =
  143. IrpSp->FileObject->CurrentByteOffset.QuadPart +
  144. Irp->IoStatus.Information;
  145. }
  146. //
  147. // If IoCallDriver returned PENDING, mark our stack location
  148. // with pending.
  149. //
  150. if ( Irp->PendingReturned ) {
  151. IoMarkIrpPending( Irp );
  152. }
  153. UNREFERENCED_PARAMETER( DeviceObject );
  154. UNREFERENCED_PARAMETER( Context );
  155. return STATUS_SUCCESS;
  156. }