ReactOS  0.4.15-dev-1206-g731eddf
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 4489 of file class2.c.

4520 {
4521  IO_STATUS_BLOCK ioStatus;
4522  PIRP irp;
4523  PIO_STACK_LOCATION irpStack;
4524  KEVENT event;
4525  NTSTATUS status;
4526  SCSI_REQUEST_BLOCK srb;
4527 
4528  PAGED_CODE();
4529 
4530  if (NewPortDeviceObject != NULL) {
4531  *NewPortDeviceObject = NULL;
4532  }
4533 
4534  //
4535  // Clear the SRB fields.
4536  //
4537 
4538  RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
4539 
4540  //
4541  // Write length to SRB.
4542  //
4543 
4545 
4546  //
4547  // Set SCSI bus address.
4548  //
4549 
4550  srb.PathId = LunInfo->PathId;
4551  srb.TargetId = LunInfo->TargetId;
4552  srb.Lun = LunInfo->Lun;
4553 
4556 
4557  //
4558  // Set the event object to the unsignaled state.
4559  // It will be used to signal request completion.
4560  //
4561 
4563 
4564  //
4565  // Build synchronous request with no transfer.
4566  //
4567 
4569  PortDeviceObject,
4570  NULL,
4571  0,
4572  NULL,
4573  0,
4574  TRUE,
4575  &event,
4576  &ioStatus);
4577 
4578  if (irp == NULL) {
4579 
4580  DebugPrint((1, "ScsiClassClaimDevice: Can't allocate Irp\n"));
4582  }
4583 
4584  irpStack = IoGetNextIrpStackLocation(irp);
4585 
4586  //
4587  // Save SRB address in next stack for port driver.
4588  //
4589 
4590  irpStack->Parameters.Scsi.Srb = &srb;
4591 
4592  //
4593  // Set up IRP Address.
4594  //
4595 
4596  srb.OriginalRequest = irp;
4597 
4598  //
4599  // Call the port driver with the request and wait for it to complete.
4600  //
4601 
4602  status = IoCallDriver(PortDeviceObject, irp);
4603  if (status == STATUS_PENDING) {
4604 
4606  status = ioStatus.Status;
4607  }
4608 
4609  //
4610  // If this is a release request, then just decrement the reference count
4611  // and return. The status does not matter.
4612  //
4613 
4614  if (Release) {
4615 
4616  //ObDereferenceObject(PortDeviceObject);
4617  return STATUS_SUCCESS;
4618  }
4619 
4620  if (!NT_SUCCESS(status)) {
4621  return status;
4622  }
4623 
4624  ASSERT(srb.DataBuffer != NULL);
4625 
4626  //
4627  // Reference the new port driver object so that it will not go away while
4628  // it is being used.
4629  //
4630 
4632  0,
4633  NULL,
4634  KernelMode );
4635 
4636  if (!NT_SUCCESS(status)) {
4637 
4638  return status;
4639  }
4641 
4642  //
4643  // Return the new port device object pointer.
4644  //
4645 
4646  if (NewPortDeviceObject != NULL) {
4647  *NewPortDeviceObject = srb.DataBuffer;
4648  }
4649 
4650  return status;
4651 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PVOID OriginalRequest
Definition: srb.h:258
#define TRUE
Definition: types.h:120
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 FALSE
Definition: types.h:117
#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:2691
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:262
_In_ BOOLEAN Release
Definition: cdrom.h:920
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define PAGED_CODE()
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 531 of file class2.c.

560 {
561  PIRP irp;
562  IO_STATUS_BLOCK ioStatus;
563  KEVENT event;
565 
566  PAGED_CODE();
567 
568  //
569  // Create notification event object to be used to signal the
570  // request completion.
571  //
572 
574 
575  //
576  // Build the synchronous request to be sent to the port driver
577  // to perform the request.
578  //
579 
581  PortDeviceObject,
582  NULL,
583  0,
584  PortCapabilities,
585  sizeof(PVOID),
586  FALSE,
587  &event,
588  &ioStatus);
589 
590  if (irp == NULL) {
592  }
593 
594  //
595  // Pass request to port driver and wait for request to complete.
596  //
597 
598  status = IoCallDriver(PortDeviceObject, irp);
599 
600  if (status == STATUS_PENDING) {
602  return(ioStatus.Status);
603  }
604 
605  return status;
606 
607 } // 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 FALSE
Definition: types.h:117
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
#define PAGED_CODE()
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 4656 of file class2.c.

4685 {
4687  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
4688  PSCSI_REQUEST_BLOCK srb;
4689 
4690  ASSERT(*(PULONG)deviceExtension != '2slc');
4691 
4692  //
4693  // Get a pointer to the SRB.
4694  //
4695 
4696  srb = irpStack->Parameters.Scsi.Srb;
4697 
4698  //
4699  // Set SCSI bus address.
4700  //
4701 
4702  srb->PathId = deviceExtension->PathId;
4703  srb->TargetId = deviceExtension->TargetId;
4704  srb->Lun = deviceExtension->Lun;
4705 
4706  //
4707  // NOTICE: The SCSI-II specification indicates that this field should be
4708  // zero; however, some target controllers ignore the logical unit number
4709  // in the IDENTIFY message and only look at the logical unit number field
4710  // in the CDB.
4711  //
4712 
4713  srb->Cdb[1] |= deviceExtension->Lun << 5;
4714 
4715  //
4716  // Set the parameters in the next stack location.
4717  //
4718 
4719  irpStack = IoGetNextIrpStackLocation(Irp);
4720 
4721  irpStack->Parameters.Scsi.Srb = srb;
4722  irpStack->MajorFunction = IRP_MJ_SCSI;
4723  irpStack->MinorFunction = IRP_MN_SCSI_CLASS;
4724 
4726  return IoCallDriver(deviceExtension->PortDeviceObject, Irp);
4727 }
UCHAR Cdb[16]
Definition: srb.h:271
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define IRP_MJ_SCSI
NTSTATUS NTAPI ClassIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: class2.c:4731
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:2691
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
UCHAR PathId
Definition: srb.h:245
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
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:3107

◆ 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 714 of file class2.c.

736 {
737  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
738  ULONG retries = 1;
739  ULONG lastSector;
740  PCDB cdb;
741  PREAD_CAPACITY_DATA readCapacityBuffer;
742  SCSI_REQUEST_BLOCK srb;
744 
745  ASSERT(*(PULONG)deviceExtension != '2slc');
746 
747  //
748  // Allocate read capacity buffer from nonpaged pool.
749  //
750 
751  readCapacityBuffer = ExAllocatePool(NonPagedPoolCacheAligned,
752  sizeof(READ_CAPACITY_DATA));
753 
754  if (!readCapacityBuffer) {
756  }
757 
758  RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
759 
760  //
761  // Build the read capacity CDB.
762  //
763 
764  srb.CdbLength = 10;
765  cdb = (PCDB)srb.Cdb;
766 
767  //
768  // Set timeout value from device extension.
769  //
770 
771  srb.TimeOutValue = deviceExtension->TimeOutValue;
772 
773  cdb->CDB10.OperationCode = SCSIOP_READ_CAPACITY;
774 
775 Retry:
776 
778  &srb,
779  readCapacityBuffer,
780  sizeof(READ_CAPACITY_DATA),
781  FALSE);
782 
783  if (NT_SUCCESS(status)) {
784 
785  //
786  // Copy sector size from read capacity buffer to device extension
787  // in reverse byte order.
788  //
789 
790  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte0 =
791  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte3;
792 
793  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte1 =
794  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte2;
795 
796  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte2 =
797  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte1;
798 
799  ((PFOUR_BYTE)&deviceExtension->DiskGeometry->Geometry.BytesPerSector)->Byte3 =
800  ((PFOUR_BYTE)&readCapacityBuffer->BytesPerBlock)->Byte0;
801 
802  //
803  // Copy last sector in reverse byte order.
804  //
805 
806  ((PFOUR_BYTE)&lastSector)->Byte0 =
807  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte3;
808 
809  ((PFOUR_BYTE)&lastSector)->Byte1 =
810  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte2;
811 
812  ((PFOUR_BYTE)&lastSector)->Byte2 =
813  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte1;
814 
815  ((PFOUR_BYTE)&lastSector)->Byte3 =
816  ((PFOUR_BYTE)&readCapacityBuffer->LogicalBlockAddress)->Byte0;
817 
818  //
819  // Calculate sector to byte shift.
820  //
821 
822  WHICH_BIT(deviceExtension->DiskGeometry->Geometry.BytesPerSector, deviceExtension->SectorShift);
823 
824  DebugPrint((2,"SCSI ScsiClassReadDriveCapacity: Sector size is %d\n",
825  deviceExtension->DiskGeometry->Geometry.BytesPerSector));
826 
827  DebugPrint((2,"SCSI ScsiClassReadDriveCapacity: Number of Sectors is %d\n",
828  lastSector + 1));
829 
830  //
831  // Calculate number of cylinders.
832  //
833 
834  deviceExtension->DiskGeometry->Geometry.Cylinders.QuadPart = (LONGLONG)((lastSector + 1)/(DEFAULT_SECTORS_PER_TRACK * DEFAULT_TRACKS_PER_CYLINDER));
835 
836  //
837  // Calculate media capacity in bytes.
838  //
839 
840  deviceExtension->PartitionLength.QuadPart = (LONGLONG)(lastSector + 1);
841  deviceExtension->PartitionLength.QuadPart =
842  (deviceExtension->PartitionLength.QuadPart << deviceExtension->SectorShift);
843  deviceExtension->DiskGeometry->DiskSize.QuadPart = deviceExtension->PartitionLength.QuadPart;
844 
845  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
846 
847  //
848  // This device supports removable media.
849  //
850 
851  deviceExtension->DiskGeometry->Geometry.MediaType = RemovableMedia;
852 
853  } else {
854 
855  //
856  // Assume media type is fixed disk.
857  //
858 
859  deviceExtension->DiskGeometry->Geometry.MediaType = FixedMedia;
860  }
861 
862  //
863  // Assume sectors per track are DEFAULT_SECTORS_PER_TRACK;
864  //
865 
866  deviceExtension->DiskGeometry->Geometry.SectorsPerTrack = DEFAULT_SECTORS_PER_TRACK;
867 
868  //
869  // Assume tracks per cylinder (number of heads) is DEFAULT_TRACKS_PER_CYLINDER.
870  //
871 
872  deviceExtension->DiskGeometry->Geometry.TracksPerCylinder = DEFAULT_TRACKS_PER_CYLINDER;
873  }
874 
876 
877  //
878  // Routine ScsiClassSendSrbSynchronous does not retry
879  // requests returned with this status.
880  // Read Capacities should be retried
881  // anyway.
882  //
883 
884  if (retries--) {
885 
886  //
887  // Retry request.
888  //
889 
890  goto Retry;
891  }
892  }
893 
894  if (!NT_SUCCESS(status)) {
895 
896  //
897  // If the read capacity fails, set the geometry to reasonable parameter
898  // so things don't fail at unexpected places. Zero the geometry
899  // except for the bytes per sector and sector shift.
900  //
901 
902  RtlZeroMemory(deviceExtension->DiskGeometry, sizeof(DISK_GEOMETRY_EX));
903  deviceExtension->DiskGeometry->Geometry.BytesPerSector = 512;
904  deviceExtension->SectorShift = 9;
905  deviceExtension->PartitionLength.QuadPart = (LONGLONG) 0;
906  deviceExtension->DiskGeometry->DiskSize.QuadPart = (LONGLONG) 0;
907 
908  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
909 
910  //
911  // This device supports removable media.
912  //
913 
914  deviceExtension->DiskGeometry->Geometry.MediaType = RemovableMedia;
915 
916  } else {
917 
918  //
919  // Assume media type is fixed disk.
920  //
921 
922  deviceExtension->DiskGeometry->Geometry.MediaType = FixedMedia;
923  }
924  }
925 
926  //
927  // Deallocate read capacity buffer.
928  //
929 
930  ExFreePool(readCapacityBuffer);
931 
932  return status;
933 
934 } // 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 FALSE
Definition: types.h:117
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define DEFAULT_SECTORS_PER_TRACK
Definition: class2.c:37
union _CDB * PCDB
IN PSCSI_REQUEST_BLOCK IN OUT NTSTATUS IN OUT BOOLEAN * Retry
Definition: class2.h:49
int64_t LONGLONG
Definition: typedefs.h:68
#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: iotypes.h:2464
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:262
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:1856
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define DEFAULT_TRACKS_PER_CYLINDER
Definition: class2.c:38
Definition: ps.c:97

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

◆ ScsiClassReleaseQueue()

VOID ScsiClassReleaseQueue ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 939 of file class2.c.

963 {
964  PIO_STACK_LOCATION irpStack;
965  PIRP irp;
966  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
969  KIRQL currentIrql;
970 
971  ASSERT(*(PULONG)deviceExtension != '2slc');
972 
973  //
974  // Allocate context from nonpaged pool.
975  //
976 
978  sizeof(COMPLETION_CONTEXT));
979 
980  //
981  // Save the device object in the context for use by the completion
982  // routine.
983  //
984 
985  context->DeviceObject = DeviceObject;
986  srb = &context->Srb;
987 
988  //
989  // Zero out srb.
990  //
991 
993 
994  //
995  // Write length to SRB.
996  //
997 
999 
1000  //
1001  // Set up SCSI bus address.
1002  //
1003 
1004  srb->PathId = deviceExtension->PathId;
1005  srb->TargetId = deviceExtension->TargetId;
1006  srb->Lun = deviceExtension->Lun;
1007 
1008  //
1009  // If this device is removable then flush the queue. This will also
1010  // release it.
1011  //
1012 
1013  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
1014 
1016 
1017  } else {
1018 
1020 
1021  }
1022 
1023  //
1024  // Build the asynchronous request to be sent to the port driver.
1025  //
1026 
1027  irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
1028 
1029  if(irp == NULL) {
1030 
1031  //
1032  // We have no better way of dealing with this at the moment
1033  //
1034 
1035  KeBugCheck((ULONG)0x0000002DL);
1036 
1037  }
1038 
1041  context,
1042  TRUE,
1043  TRUE,
1044  TRUE);
1045 
1046  irpStack = IoGetNextIrpStackLocation(irp);
1047 
1048  irpStack->MajorFunction = IRP_MJ_SCSI;
1049 
1050  srb->OriginalRequest = irp;
1051 
1052  //
1053  // Store the SRB address in next stack for port driver.
1054  //
1055 
1056  irpStack->Parameters.Scsi.Srb = srb;
1057 
1058  //
1059  // Since this routine can cause outstanding requests to be completed, and
1060  // calling a completion routine at < DISPATCH_LEVEL is dangerous (if they
1061  // call IoStartNextPacket we will bugcheck) raise up to dispatch level before
1062  // issuing the request
1063  //
1064 
1065  currentIrql = KeGetCurrentIrql();
1066 
1067  if(currentIrql < DISPATCH_LEVEL) {
1068  KeRaiseIrql(DISPATCH_LEVEL, &currentIrql);
1069  IoCallDriver(deviceExtension->PortDeviceObject, irp);
1070  KeLowerIrql(currentIrql);
1071  } else {
1072  IoCallDriver(deviceExtension->PortDeviceObject, irp);
1073  }
1074 
1075  return;
1076 
1077 } // end ScsiClassReleaseQueue()
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
PVOID OriginalRequest
Definition: srb.h:258
Definition: http.c:7094
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI ScsiClassAsynchronousCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: class2.c:1217
#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:498
#define IRP_MJ_SCSI
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
smooth NULL
Definition: ftsmooth.c:416
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:2691
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
UCHAR PathId
Definition: srb.h:245
#define SCSI_REQUEST_BLOCK_SIZE
Definition: srb.h:274
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
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:2814
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

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()