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.

162 lines
4.4 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1990 - 1998
  3. Module Name:
  4. pnp.c
  5. Abstract:
  6. This is the NT SCSI port driver. This file contains the self-contained plug
  7. and play code.
  8. Authors:
  9. Peter Wieland
  10. Environment:
  11. kernel mode only
  12. Notes:
  13. This module is a driver dll for scsi miniports.
  14. Revision History:
  15. --*/
  16. #include "port.h"
  17. #if DBG
  18. static const char *__file__ = __FILE__;
  19. #endif
  20. PDRIVER_DISPATCH AdapterMajorFunctionTable[IRP_MJ_MAXIMUM_FUNCTION + 1];
  21. PDRIVER_DISPATCH DeviceMajorFunctionTable[IRP_MJ_MAXIMUM_FUNCTION + 1];
  22. PDRIVER_DISPATCH Scsi1DeviceMajorFunctionTable[IRP_MJ_MAXIMUM_FUNCTION + 1];
  23. #ifdef ALLOC_PRAGMA
  24. #pragma alloc_text(PAGE, ScsiPortInitializeDispatchTables)
  25. #endif
  26. NTSTATUS
  27. ScsiPortDispatchUnimplemented(
  28. IN PDEVICE_OBJECT DeviceObject,
  29. IN PIRP Irp
  30. );
  31. //
  32. // Routines start
  33. //
  34. VOID
  35. ScsiPortInitializeDispatchTables(
  36. VOID
  37. )
  38. {
  39. ULONG i;
  40. //
  41. // Initialize the PDO dispatch table
  42. //
  43. for(i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
  44. DeviceMajorFunctionTable[i] = ScsiPortDispatchUnimplemented;
  45. }
  46. DeviceMajorFunctionTable[IRP_MJ_DEVICE_CONTROL] = ScsiPortPdoDeviceControl;
  47. Scsi1DeviceMajorFunctionTable[IRP_MJ_DEVICE_CONTROL] = ScsiPortPdoDeviceControl;
  48. DeviceMajorFunctionTable[IRP_MJ_SCSI] = ScsiPortPdoScsi;
  49. Scsi1DeviceMajorFunctionTable[IRP_MJ_SCSI] = ScsiPortScsi1PdoScsi;
  50. DeviceMajorFunctionTable[IRP_MJ_PNP] = ScsiPortPdoPnp;
  51. Scsi1DeviceMajorFunctionTable[IRP_MJ_PNP] = ScsiPortPdoPnp;
  52. DeviceMajorFunctionTable[IRP_MJ_CREATE] = ScsiPortPdoCreateClose;
  53. Scsi1DeviceMajorFunctionTable[IRP_MJ_CREATE] = ScsiPortPdoCreateClose;
  54. DeviceMajorFunctionTable[IRP_MJ_CLOSE] = ScsiPortPdoCreateClose;
  55. Scsi1DeviceMajorFunctionTable[IRP_MJ_CLOSE] = ScsiPortPdoCreateClose;
  56. DeviceMajorFunctionTable[IRP_MJ_SYSTEM_CONTROL] = ScsiPortSystemControlIrp;
  57. Scsi1DeviceMajorFunctionTable[IRP_MJ_SYSTEM_CONTROL] = ScsiPortSystemControlIrp;
  58. DeviceMajorFunctionTable[IRP_MJ_POWER] = ScsiPortDispatchPower;
  59. Scsi1DeviceMajorFunctionTable[IRP_MJ_POWER] = ScsiPortDispatchPower;
  60. //
  61. // Initialize the adapter dispatch table
  62. //
  63. for(i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
  64. AdapterMajorFunctionTable[i] = ScsiPortDispatchUnimplemented;
  65. }
  66. AdapterMajorFunctionTable[IRP_MJ_DEVICE_CONTROL] = ScsiPortFdoDeviceControl;
  67. AdapterMajorFunctionTable[IRP_MJ_SCSI] = ScsiPortFdoDispatch;
  68. AdapterMajorFunctionTable[IRP_MJ_PNP] = ScsiPortFdoPnp;
  69. AdapterMajorFunctionTable[IRP_MJ_CREATE] = ScsiPortFdoCreateClose;
  70. AdapterMajorFunctionTable[IRP_MJ_CLOSE] = ScsiPortFdoCreateClose;
  71. AdapterMajorFunctionTable[IRP_MJ_SYSTEM_CONTROL] = ScsiPortSystemControlIrp;
  72. AdapterMajorFunctionTable[IRP_MJ_POWER] = ScsiPortDispatchPower;
  73. return;
  74. }
  75. NTSTATUS
  76. ScsiPortGlobalDispatch(
  77. IN PDEVICE_OBJECT DeviceObject,
  78. IN PIRP Irp
  79. )
  80. {
  81. PCOMMON_EXTENSION commonExtension = DeviceObject->DeviceExtension;
  82. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  83. return (commonExtension->MajorFunction[irpStack->MajorFunction])(DeviceObject, Irp);
  84. }
  85. NTSTATUS
  86. ScsiPortDispatchUnimplemented(
  87. IN PDEVICE_OBJECT DeviceObject,
  88. IN PIRP Irp
  89. )
  90. {
  91. PCOMMON_EXTENSION commonExtension;
  92. PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
  93. ULONG isRemoved;
  94. isRemoved = SpAcquireRemoveLock(DeviceObject, Irp);
  95. if(isRemoved) {
  96. Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST;
  97. SpReleaseRemoveLock(DeviceObject, Irp);
  98. SpCompleteRequest(DeviceObject, Irp, NULL, IO_NO_INCREMENT);
  99. return STATUS_DEVICE_DOES_NOT_EXIST;
  100. }
  101. commonExtension = DeviceObject->DeviceExtension;
  102. DebugPrint((1, "ScsiPortDispatchUnimplemented: request %#p\n", Irp));
  103. DebugPrint((1, "/t/tFunction Code (%d, %d)\n",
  104. irpStack->MajorFunction,
  105. irpStack->MinorFunction));
  106. DebugPrint((1, "/t/tFor %s %#p\n",
  107. (commonExtension->IsPdo ? "PDO" : "FDO"),
  108. DeviceObject));
  109. Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
  110. SpReleaseRemoveLock(DeviceObject, Irp);
  111. SpCompleteRequest(DeviceObject, Irp, NULL, IO_NO_INCREMENT);
  112. return STATUS_INVALID_DEVICE_REQUEST;
  113. }