ReactOS  0.4.14-dev-49-gfb4591c
scsi_port.h File Reference
#include "srb.h"
Include dependency graph for scsi_port.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SCSI_PASS_THROUGH
 
struct  _SCSI_PASS_THROUGH_DIRECT
 
struct  _SCSI_BUS_DATA
 
struct  _SCSI_ADAPTER_BUS_INFO
 
struct  _SCSI_INQUIRY_DATA
 
struct  _SRB_IO_CONTROL
 
struct  _IO_SCSI_CAPABILITIES
 
struct  _SCSI_ADDRESS
 
struct  _DUMP_POINTERS
 

Macros

#define IOCTL_SCSI_BASE   FILE_DEVICE_CONTROLLER
 
#define DD_SCSI_DEVICE_NAME   "\\Device\\ScsiPort"
 
#define IOCTL_SCSI_PASS_THROUGH   CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
 
#define IOCTL_SCSI_MINIPORT   CTL_CODE(IOCTL_SCSI_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
 
#define IOCTL_SCSI_GET_INQUIRY_DATA   CTL_CODE(IOCTL_SCSI_BASE, 0x0403, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define IOCTL_SCSI_GET_CAPABILITIES   CTL_CODE(IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define IOCTL_SCSI_PASS_THROUGH_DIRECT   CTL_CODE(IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
 
#define IOCTL_SCSI_GET_ADDRESS   CTL_CODE(IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define IOCTL_SCSI_RESCAN_BUS   CTL_CODE(IOCTL_SCSI_BASE, 0x0407, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define IOCTL_SCSI_GET_DUMP_POINTERS   CTL_CODE(IOCTL_SCSI_BASE, 0x0408, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define SCSI_IOCTL_DATA_OUT   0
 
#define SCSI_IOCTL_DATA_IN   1
 
#define SCSI_IOCTL_DATA_UNSPECIFIED   2
 
#define CLASS_SPECIAL_CAUSE_NOT_REPORTABLE_HACK   0x00000020
 
#define SCSIPORT_API
 

Typedefs

typedef struct _SCSI_PASS_THROUGH SCSI_PASS_THROUGH
 
typedef struct _SCSI_PASS_THROUGHPSCSI_PASS_THROUGH
 
typedef struct _SCSI_PASS_THROUGH_DIRECT SCSI_PASS_THROUGH_DIRECT
 
typedef struct _SCSI_PASS_THROUGH_DIRECTPSCSI_PASS_THROUGH_DIRECT
 
typedef struct _SCSI_BUS_DATA SCSI_BUS_DATA
 
typedef struct _SCSI_BUS_DATAPSCSI_BUS_DATA
 
typedef struct _SCSI_ADAPTER_BUS_INFO SCSI_ADAPTER_BUS_INFO
 
typedef struct _SCSI_ADAPTER_BUS_INFOPSCSI_ADAPTER_BUS_INFO
 
typedef struct _SCSI_INQUIRY_DATA SCSI_INQUIRY_DATA
 
typedef struct _SCSI_INQUIRY_DATAPSCSI_INQUIRY_DATA
 
typedef struct _SRB_IO_CONTROL SRB_IO_CONTROL
 
typedef struct _SRB_IO_CONTROLPSRB_IO_CONTROL
 
typedef struct _IO_SCSI_CAPABILITIES IO_SCSI_CAPABILITIES
 
typedef struct _IO_SCSI_CAPABILITIESPIO_SCSI_CAPABILITIES
 
typedef struct _SCSI_ADDRESS SCSI_ADDRESS
 
typedef struct _SCSI_ADDRESSPSCSI_ADDRESS
 
typedef struct _DUMP_POINTERS DUMP_POINTERS
 
typedef struct _DUMP_POINTERSPDUMP_POINTERS
 

Functions

NTSTATUS ScsiClassGetInquiryData (IN PDEVICE_OBJECT PortDeviceObject, IN PSCSI_ADAPTER_BUS_INFO *ConfigInfo)
 
NTSTATUS ScsiClassReadDeviceInquiryData (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN DirectAccess)
 
NTSTATUS ScsiClassReadDriveCapacity (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS ScsiClassGetCapabilities (IN PDEVICE_OBJECT PortDeviceObject, OUT PIO_SCSI_CAPABILITIES *PortCapabilities)
 
NTSTATUS ScsiClassGetAddress (IN PDEVICE_OBJECT ClassDeviceObject, OUT PSCSI_ADDRESS Address)
 
VOID ScsiClassReleaseQueue (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS ScsiClassRemoveDevice (IN PDEVICE_OBJECT PortDeviceObject, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun)
 
NTSTATUS ScsiClassClaimDevice (IN PDEVICE_OBJECT PortDeviceObject, IN PSCSI_INQUIRY_DATA LunInfo, IN BOOLEAN Release, OUT PDEVICE_OBJECT *NewPortDeviceObject OPTIONAL)
 
NTSTATUS ScsiClassInternalIoControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS ScsiClassIoCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS ScsiClassSendSrbSynchronous (IN PDEVICE_OBJECT TargetDeviceObject, IN PSCSI_REQUEST_BLOCK _srb, IN PKEVENT event)
 
VOID ScsiClassInitSrbBusAddr (PSCSI_REQUEST_BLOCK Srb, PVOID DeviceExtension)
 
NTSTATUS DbgWaitForSingleObject_ (IN PVOID Object, IN PLARGE_INTEGER Timeout OPTIONAL)
 

Macro Definition Documentation

◆ CLASS_SPECIAL_CAUSE_NOT_REPORTABLE_HACK

#define CLASS_SPECIAL_CAUSE_NOT_REPORTABLE_HACK   0x00000020

Definition at line 175 of file scsi_port.h.

◆ DD_SCSI_DEVICE_NAME

#define DD_SCSI_DEVICE_NAME   "\\Device\\ScsiPort"

Definition at line 39 of file scsi_port.h.

◆ IOCTL_SCSI_BASE

#define IOCTL_SCSI_BASE   FILE_DEVICE_CONTROLLER

Definition at line 37 of file scsi_port.h.

◆ IOCTL_SCSI_GET_ADDRESS

#define IOCTL_SCSI_GET_ADDRESS   CTL_CODE(IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 52 of file scsi_port.h.

◆ IOCTL_SCSI_GET_CAPABILITIES

#define IOCTL_SCSI_GET_CAPABILITIES   CTL_CODE(IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 50 of file scsi_port.h.

◆ IOCTL_SCSI_GET_DUMP_POINTERS

#define IOCTL_SCSI_GET_DUMP_POINTERS   CTL_CODE(IOCTL_SCSI_BASE, 0x0408, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 54 of file scsi_port.h.

◆ IOCTL_SCSI_GET_INQUIRY_DATA

#define IOCTL_SCSI_GET_INQUIRY_DATA   CTL_CODE(IOCTL_SCSI_BASE, 0x0403, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 49 of file scsi_port.h.

◆ IOCTL_SCSI_MINIPORT

#define IOCTL_SCSI_MINIPORT   CTL_CODE(IOCTL_SCSI_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

Definition at line 48 of file scsi_port.h.

◆ IOCTL_SCSI_PASS_THROUGH

#define IOCTL_SCSI_PASS_THROUGH   CTL_CODE(IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

Definition at line 47 of file scsi_port.h.

◆ IOCTL_SCSI_PASS_THROUGH_DIRECT

#define IOCTL_SCSI_PASS_THROUGH_DIRECT   CTL_CODE(IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

Definition at line 51 of file scsi_port.h.

◆ IOCTL_SCSI_RESCAN_BUS

#define IOCTL_SCSI_RESCAN_BUS   CTL_CODE(IOCTL_SCSI_BASE, 0x0407, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 53 of file scsi_port.h.

◆ SCSI_IOCTL_DATA_IN

#define SCSI_IOCTL_DATA_IN   1

Definition at line 172 of file scsi_port.h.

◆ SCSI_IOCTL_DATA_OUT

#define SCSI_IOCTL_DATA_OUT   0

Definition at line 171 of file scsi_port.h.

◆ SCSI_IOCTL_DATA_UNSPECIFIED

#define SCSI_IOCTL_DATA_UNSPECIFIED   2

Definition at line 173 of file scsi_port.h.

◆ SCSIPORT_API

#define SCSIPORT_API

Definition at line 177 of file scsi_port.h.

Typedef Documentation

◆ DUMP_POINTERS

◆ IO_SCSI_CAPABILITIES

◆ PDUMP_POINTERS

◆ PIO_SCSI_CAPABILITIES

◆ PSCSI_ADAPTER_BUS_INFO

◆ PSCSI_ADDRESS

◆ PSCSI_BUS_DATA

◆ PSCSI_INQUIRY_DATA

◆ PSCSI_PASS_THROUGH

◆ PSCSI_PASS_THROUGH_DIRECT

◆ PSRB_IO_CONTROL

◆ SCSI_ADAPTER_BUS_INFO

◆ SCSI_ADDRESS

◆ SCSI_BUS_DATA

◆ SCSI_INQUIRY_DATA

◆ SCSI_PASS_THROUGH

◆ SCSI_PASS_THROUGH_DIRECT

◆ SRB_IO_CONTROL

Function Documentation

◆ DbgWaitForSingleObject_()

NTSTATUS DbgWaitForSingleObject_ ( IN PVOID  Object,
IN PLARGE_INTEGER Timeout  OPTIONAL 
)

◆ ScsiClassClaimDevice()

NTSTATUS ScsiClassClaimDevice ( IN PDEVICE_OBJECT  PortDeviceObject,
IN PSCSI_INQUIRY_DATA  LunInfo,
IN BOOLEAN  Release,
OUT PDEVICE_OBJECT *NewPortDeviceObject  OPTIONAL 
)

Definition at line 4740 of file class2.c.

4771 {
4772  IO_STATUS_BLOCK ioStatus;
4773  PIRP irp;
4774  PIO_STACK_LOCATION irpStack;
4775  KEVENT event;
4776  NTSTATUS status;
4777  SCSI_REQUEST_BLOCK srb;
4778 
4779  PAGED_CODE();
4780 
4781  if (NewPortDeviceObject != NULL) {
4782  *NewPortDeviceObject = NULL;
4783  }
4784 
4785  //
4786  // Clear the SRB fields.
4787  //
4788 
4789  RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
4790 
4791  //
4792  // Write length to SRB.
4793  //
4794 
4796 
4797  //
4798  // Set SCSI bus address.
4799  //
4800 
4801  srb.PathId = LunInfo->PathId;
4802  srb.TargetId = LunInfo->TargetId;
4803  srb.Lun = LunInfo->Lun;
4804 
4807 
4808  //
4809  // Set the event object to the unsignaled state.
4810  // It will be used to signal request completion.
4811  //
4812 
4814 
4815  //
4816  // Build synchronous request with no transfer.
4817  //
4818 
4820  PortDeviceObject,
4821  NULL,
4822  0,
4823  NULL,
4824  0,
4825  TRUE,
4826  &event,
4827  &ioStatus);
4828 
4829  if (irp == NULL) {
4830 
4831  DebugPrint((1, "ScsiClassClaimDevice: Can't allocate Irp\n"));
4833  }
4834 
4835  irpStack = IoGetNextIrpStackLocation(irp);
4836 
4837  //
4838  // Save SRB address in next stack for port driver.
4839  //
4840 
4841  irpStack->Parameters.Scsi.Srb = &srb;
4842 
4843  //
4844  // Set up IRP Address.
4845  //
4846 
4847  srb.OriginalRequest = irp;
4848 
4849  //
4850  // Call the port driver with the request and wait for it to complete.
4851  //
4852 
4853  status = IoCallDriver(PortDeviceObject, irp);
4854  if (status == STATUS_PENDING) {
4855 
4857  status = ioStatus.Status;
4858  }
4859 
4860  //
4861  // If this is a release request, then just decrement the reference count
4862  // and return. The status does not matter.
4863  //
4864 
4865  if (Release) {
4866 
4867  //ObDereferenceObject(PortDeviceObject);
4868  return STATUS_SUCCESS;
4869  }
4870 
4871  if (!NT_SUCCESS(status)) {
4872  return status;
4873  }
4874 
4875  ASSERT(srb.DataBuffer != NULL);
4876 
4877  //
4878  // Reference the new port driver object so that it will not go away while
4879  // it is being used.
4880  //
4881 
4883  0,
4884  NULL,
4885  KernelMode );
4886 
4887  if (!NT_SUCCESS(status)) {
4888 
4889  return status;
4890  }
4892 
4893  //
4894  // Return the new port device object pointer.
4895  //
4896 
4897  if (NewPortDeviceObject != NULL) {
4898  *NewPortDeviceObject = srb.DataBuffer;
4899  }
4900 
4901  return status;
4902 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID OriginalRequest
Definition: srb.h:258
_In_ BOOLEAN Release
Definition: classpnp.h:929
PVOID DataBuffer
Definition: srb.h:255
LONG NTSTATUS
Definition: precomp.h:26
#define SRB_FUNCTION_CLAIM_DEVICE
Definition: srb.h:308
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
#define SRB_FUNCTION_RELEASE_DEVICE
Definition: srb.h:313
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI ObReferenceObjectByPointer(IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode)
Definition: obref.c:383
UCHAR TargetId
Definition: srb.h:246
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
UCHAR Function
Definition: srb.h:242
USHORT Length
Definition: srb.h:241
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _cl_event * event
Definition: glext.h:7739
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define IOCTL_SCSI_EXECUTE_NONE
Definition: cdrw_hw.h:1453
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
UCHAR PathId
Definition: srb.h:245
#define SCSI_REQUEST_BLOCK_SIZE
Definition: srb.h:274
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by CreateCdRomDeviceObject(), and CreateDiskDeviceObject().

◆ ScsiClassGetAddress()

NTSTATUS ScsiClassGetAddress ( IN PDEVICE_OBJECT  ClassDeviceObject,
OUT PSCSI_ADDRESS  Address 
)

◆ ScsiClassGetCapabilities()

NTSTATUS ScsiClassGetCapabilities ( IN PDEVICE_OBJECT  PortDeviceObject,
OUT PIO_SCSI_CAPABILITIES PortCapabilities 
)

Definition at line 846 of file class2.c.

875 {
876  PIRP irp;
877  IO_STATUS_BLOCK ioStatus;
878  KEVENT event;
880 
881  PAGED_CODE();
882 
883  //
884  // Create notification event object to be used to signal the
885  // request completion.
886  //
887 
889 
890  //
891  // Build the synchronous request to be sent to the port driver
892  // to perform the request.
893  //
894 
896  PortDeviceObject,
897  NULL,
898  0,
899  PortCapabilities,
900  sizeof(PVOID),
901  FALSE,
902  &event,
903  &ioStatus);
904 
905  if (irp == NULL) {
907  }
908 
909  //
910  // Pass request to port driver and wait for request to complete.
911  //
912 
913  status = IoCallDriver(PortDeviceObject, irp);
914 
915  if (status == STATUS_PENDING) {
917  return(ioStatus.Status);
918  }
919 
920  return status;
921 
922 } // end ScsiClassGetCapabilities()
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _cl_event * event
Definition: glext.h:7739
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IOCTL_SCSI_GET_CAPABILITIES
Definition: scsi_port.h:50
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by FindScsiDisks(), and ScsiCdRomFindDevices().

◆ ScsiClassGetInquiryData()

NTSTATUS ScsiClassGetInquiryData ( IN PDEVICE_OBJECT  PortDeviceObject,
IN PSCSI_ADAPTER_BUS_INFO ConfigInfo 
)

◆ ScsiClassInitSrbBusAddr()

VOID ScsiClassInitSrbBusAddr ( PSCSI_REQUEST_BLOCK  Srb,
PVOID  DeviceExtension 
)

◆ ScsiClassInternalIoControl()

NTSTATUS NTAPI ScsiClassInternalIoControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 4907 of file class2.c.

4936 {
4938  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
4939  PSCSI_REQUEST_BLOCK srb;
4940 
4941  ASSERT(*(PULONG)deviceExtension != '2slc');
4942 
4943  //
4944  // Get a pointer to the SRB.
4945  //
4946 
4947  srb = irpStack->Parameters.Scsi.Srb;
4948 
4949  //
4950  // Set SCSI bus address.
4951  //
4952 
4953  srb->PathId = deviceExtension->PathId;
4954  srb->TargetId = deviceExtension->TargetId;
4955  srb->Lun = deviceExtension->Lun;
4956 
4957  //
4958  // NOTICE: The SCSI-II specification indicates that this field should be
4959  // zero; however, some target controllers ignore the logical unit number
4960  // in the IDENTIFY message and only look at the logical unit number field
4961  // in the CDB.
4962  //
4963 
4964  srb->Cdb[1] |= deviceExtension->Lun << 5;
4965 
4966  //
4967  // Set the parameters in the next stack location.
4968  //
4969 
4970  irpStack = IoGetNextIrpStackLocation(Irp);
4971 
4972  irpStack->Parameters.Scsi.Srb = srb;
4973  irpStack->MajorFunction = IRP_MJ_SCSI;
4974  irpStack->MinorFunction = IRP_MN_SCSI_CLASS;
4975 
4977  return IoCallDriver(deviceExtension->PortDeviceObject, Irp);
4978 }
#define TRUE
Definition: types.h:120
UCHAR Cdb[16]
Definition: srb.h:271
_In_ PIRP Irp
Definition: csq.h:116
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
#define IRP_MJ_SCSI
NTSTATUS NTAPI ClassIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: class2.c:4982
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
UCHAR TargetId
Definition: srb.h:246
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
UCHAR PathId
Definition: srb.h:245
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_SCSI_CLASS
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

◆ ScsiClassIoCompletion()

NTSTATUS ScsiClassIoCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

◆ ScsiClassReadDeviceInquiryData()

NTSTATUS ScsiClassReadDeviceInquiryData ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  DirectAccess 
)

◆ ScsiClassReadDriveCapacity()

NTSTATUS ScsiClassReadDriveCapacity ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1029 of file class2.c.

1051 {
1052  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
1053  ULONG retries = 1;
1054  ULONG lastSector;
1055  PCDB cdb;
1056  PREAD_CAPACITY_DATA readCapacityBuffer;
1057  SCSI_REQUEST_BLOCK srb;
1058  NTSTATUS status;
1059 
1060  ASSERT(*(PULONG)deviceExtension != '2slc');
1061 
1062  //
1063  // Allocate read capacity buffer from nonpaged pool.
1064  //
1065 
1066  readCapacityBuffer = ExAllocatePool(NonPagedPoolCacheAligned,
1067  sizeof(READ_CAPACITY_DATA));
1068 
1069  if (!readCapacityBuffer) {
1071  }
1072 
1073  RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
1074 
1075  //
1076  // Build the read capacity CDB.
1077  //
1078 
1079  srb.CdbLength = 10;
1080  cdb = (PCDB)srb.Cdb;
1081 
1082  //
1083  // Set timeout value from device extension.
1084  //
1085 
1086  srb.TimeOutValue = deviceExtension->TimeOutValue;
1087 
1088  cdb->CDB10.OperationCode = SCSIOP_READ_CAPACITY;
1089 
1090 Retry:
1091 
1093  &srb,
1094  readCapacityBuffer,
1095  sizeof(READ_CAPACITY_DATA),
1096  FALSE);
1097 
1098  if (NT_SUCCESS(status)) {
1099 
1100  //
1101  // Copy sector size from read capacity buffer to device extension
1102  // in reverse byte order.
1103  //
1104 
1105  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte0 =
1106  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte3;
1107 
1108  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte1 =
1109  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte2;
1110 
1111  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte2 =
1112  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte1;
1113 
1114  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte3 =
1115  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte0;
1116 
1117  //
1118  // Copy last sector in reverse byte order.
1119  //
1120 
1121  ((PFOUR_BYTE)&lastSector)->Byte0 =
1122  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte3;
1123 
1124  ((PFOUR_BYTE)&lastSector)->Byte1 =
1125  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte2;
1126 
1127  ((PFOUR_BYTE)&lastSector)->Byte2 =
1128  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte1;
1129 
1130  ((PFOUR_BYTE)&lastSector)->Byte3 =
1131  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte0;
1132 
1133  //
1134  // Calculate sector to byte shift.
1135  //
1136 
1137  WHICH_BIT(deviceExtension->DiskGeometry->Geometry.BytesPerSector, deviceExtension->SectorShift);
1138 
1139  DebugPrint((2,"SCSI ScsiClassReadDriveCapacity: Sector size is %d\n",
1140  deviceExtension->DiskGeometry->Geometry.BytesPerSector));
1141 
1142  DebugPrint((2,"SCSI ScsiClassReadDriveCapacity: Number of Sectors is %d\n",
1143  lastSector + 1));
1144 
1145  //
1146  // Calculate media capacity in bytes.
1147  //
1148 
1149  deviceExtension->PartitionLength.QuadPart = (LONGLONG)(lastSector + 1);
1150 
1151  //
1152  // Calculate number of cylinders.
1153  //
1154 
1155  deviceExtension->DiskGeometry->Geometry.Cylinders.QuadPart = (LONGLONG)((lastSector + 1)/(DEFAULT_SECTORS_PER_TRACK * DEFAULT_TRACKS_PER_CYLINDER));
1156 
1157  deviceExtension->PartitionLength.QuadPart =
1158  (deviceExtension->PartitionLength.QuadPart << deviceExtension->SectorShift);
1159 
1160  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
1161 
1162  //
1163  // This device supports removable media.
1164  //
1165 
1166  deviceExtension->DiskGeometry->Geometry.MediaType = RemovableMedia;
1167 
1168  } else {
1169 
1170  //
1171  // Assume media type is fixed disk.
1172  //
1173 
1174  deviceExtension->DiskGeometry->Geometry.MediaType = FixedMedia;
1175  }
1176 
1177  //
1178  // Assume sectors per track are DEFAULT_SECTORS_PER_TRACK;
1179  //
1180 
1181  deviceExtension->DiskGeometry->Geometry.SectorsPerTrack = DEFAULT_SECTORS_PER_TRACK;
1182 
1183  //
1184  // Assume tracks per cylinder (number of heads) is DEFAULT_TRACKS_PER_CYLINDER.
1185  //
1186 
1187  deviceExtension->DiskGeometry->Geometry.TracksPerCylinder = DEFAULT_TRACKS_PER_CYLINDER;
1188  }
1189 
1190  if (status == STATUS_VERIFY_REQUIRED) {
1191 
1192  //
1193  // Routine ScsiClassSendSrbSynchronous does not retry
1194  // requests returned with this status.
1195  // Read Capacities should be retried
1196  // anyway.
1197  //
1198 
1199  if (retries--) {
1200 
1201  //
1202  // Retry request.
1203  //
1204 
1205  goto Retry;
1206  }
1207  }
1208 
1209  if (!NT_SUCCESS(status)) {
1210 
1211  //
1212  // If the read capacity fails, set the geometry to reasonable parameter
1213  // so things don't fail at unexpected places. Zero the geometry
1214  // except for the bytes per sector and sector shift.
1215  //
1216 
1217  RtlZeroMemory(deviceExtension->DiskGeometry, sizeof(DISK_GEOMETRY_EX));
1218  deviceExtension->DiskGeometry->Geometry.BytesPerSector = 512;
1219  deviceExtension->SectorShift = 9;
1220  deviceExtension->PartitionLength.QuadPart = (LONGLONG) 0;
1221 
1222  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
1223 
1224  //
1225  // This device supports removable media.
1226  //
1227 
1228  deviceExtension->DiskGeometry->Geometry.MediaType = RemovableMedia;
1229 
1230  } else {
1231 
1232  //
1233  // Assume media type is fixed disk.
1234  //
1235 
1236  deviceExtension->DiskGeometry->Geometry.MediaType = FixedMedia;
1237  }
1238  }
1239 
1240  //
1241  // Deallocate read capacity buffer.
1242  //
1243 
1244  ExFreePool(readCapacityBuffer);
1245 
1246  return status;
1247 
1248 } // end ScsiClassReadDriveCapacity()
struct _FOUR_BYTE * PFOUR_BYTE
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR Cdb[16]
Definition: srb.h:271
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
UCHAR CdbLength
Definition: srb.h:250
ULONG LogicalBlockAddress
Definition: cdrw_hw.h:1471
struct _CDB::_CDB10 CDB10
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
ULONG TimeOutValue
Definition: srb.h:254
#define WHICH_BIT(Data, Bit)
Definition: tools.h:80
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define DEFAULT_SECTORS_PER_TRACK
Definition: class2.c:41
PVOID DeviceExtension
Definition: env_spec_w32.h:418
union _CDB * PCDB
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
int64_t LONGLONG
Definition: typedefs.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned int * PULONG
Definition: retypes.h:1
#define SCSIOP_READ_CAPACITY
Definition: cdrw_hw.h:904
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
static SERVICE_STATUS status
Definition: service.c:31
NTSTATUS NTAPI ScsiClassSendSrbSynchronous(PDEVICE_OBJECT DeviceObject, PSCSI_REQUEST_BLOCK Srb, PVOID BufferAddress, ULONG BufferLength, BOOLEAN WriteToDevice)
Definition: class2.c:2170
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define DEFAULT_TRACKS_PER_CYLINDER
Definition: class2.c:42
Definition: ps.c:97

Referenced by CreateCdRomDeviceObject(), CreateDiskDeviceObject(), ScsiDiskDeviceControl(), and UpdateRemovableGeometry().

◆ ScsiClassReleaseQueue()

VOID ScsiClassReleaseQueue ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1253 of file class2.c.

1277 {
1278  PIO_STACK_LOCATION irpStack;
1279  PIRP irp;
1280  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
1282  PSCSI_REQUEST_BLOCK srb;
1283  KIRQL currentIrql;
1284 
1285  ASSERT(*(PULONG)deviceExtension != '2slc');
1286 
1287  //
1288  // Allocate context from nonpaged pool.
1289  //
1290 
1292  sizeof(COMPLETION_CONTEXT));
1293 
1294  //
1295  // Save the device object in the context for use by the completion
1296  // routine.
1297  //
1298 
1299  context->DeviceObject = DeviceObject;
1300  srb = &context->Srb;
1301 
1302  //
1303  // Zero out srb.
1304  //
1305 
1307 
1308  //
1309  // Write length to SRB.
1310  //
1311 
1313 
1314  //
1315  // Set up SCSI bus address.
1316  //
1317 
1318  srb->PathId = deviceExtension->PathId;
1319  srb->TargetId = deviceExtension->TargetId;
1320  srb->Lun = deviceExtension->Lun;
1321 
1322  //
1323  // If this device is removable then flush the queue. This will also
1324  // release it.
1325  //
1326 
1327  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
1328 
1330 
1331  } else {
1332 
1334 
1335  }
1336 
1337  //
1338  // Build the asynchronous request to be sent to the port driver.
1339  //
1340 
1342 
1343  if(irp == NULL) {
1344 
1345  //
1346  // We have no better way of dealing with this at the moment
1347  //
1348 
1349  KeBugCheck((ULONG)0x0000002DL);
1350 
1351  }
1352 
1355  context,
1356  TRUE,
1357  TRUE,
1358  TRUE);
1359 
1360  irpStack = IoGetNextIrpStackLocation(irp);
1361 
1362  irpStack->MajorFunction = IRP_MJ_SCSI;
1363 
1364  srb->OriginalRequest = irp;
1365 
1366  //
1367  // Store the SRB address in next stack for port driver.
1368  //
1369 
1370  irpStack->Parameters.Scsi.Srb = srb;
1371 
1372  //
1373  // Since this routine can cause outstanding requests to be completed, and
1374  // calling a completion routine at < DISPATCH_LEVEL is dangerous (if they
1375  // call IoStartNextPacket we will bugcheck) raise up to dispatch level before
1376  // issuing the request
1377  //
1378 
1379  currentIrql = KeGetCurrentIrql();
1380 
1381  if(currentIrql < DISPATCH_LEVEL) {
1382  KeRaiseIrql(DISPATCH_LEVEL, &currentIrql);
1383  IoCallDriver(deviceExtension->PortDeviceObject, irp);
1384  KeLowerIrql(currentIrql);
1385  } else {
1386  IoCallDriver(deviceExtension->PortDeviceObject, irp);
1387  }
1388 
1389  return;
1390 
1391 } // end ScsiClassReleaseQueue()
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
PVOID OriginalRequest
Definition: srb.h:258
Definition: http.c:6587
NTSTATUS NTAPI ScsiClassAsynchronousCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: class2.c:1531
#define SRB_FUNCTION_FLUSH_QUEUE
Definition: srb.h:321
#define SRB_FUNCTION_RELEASE_QUEUE
Definition: srb.h:311
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
#define IRP_MJ_SCSI
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
UCHAR TargetId
Definition: srb.h:246
UCHAR Function
Definition: srb.h:242
USHORT Length
Definition: srb.h:241
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
UCHAR PathId
Definition: srb.h:245
#define SCSI_REQUEST_BLOCK_SIZE
Definition: srb.h:274
unsigned int * PULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
IO_COMPLETION_ROUTINE * PIO_COMPLETION_ROUTINE
Definition: iotypes.h:2480
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by CdRomDeviceControlCompletion(), CdRomMediaChangeCompletion(), CdRomSetVolumeIntermediateCompletion(), CdRomSwitchModeCompletion(), CdRomUpdateGeometryCompletion(), CdRomXACompletion(), and ToshibaProcessErrorCompletion().

◆ ScsiClassRemoveDevice()

NTSTATUS ScsiClassRemoveDevice ( IN PDEVICE_OBJECT  PortDeviceObject,
IN UCHAR  PathId,
IN UCHAR  TargetId,
IN UCHAR  Lun 
)

◆ ScsiClassSendSrbSynchronous()