ReactOS  0.4.14-dev-593-g1793dcc
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 4488 of file class2.c.

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

4684 {
4686  PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
4687  PSCSI_REQUEST_BLOCK srb;
4688 
4689  ASSERT(*(PULONG)deviceExtension != '2slc');
4690 
4691  //
4692  // Get a pointer to the SRB.
4693  //
4694 
4695  srb = irpStack->Parameters.Scsi.Srb;
4696 
4697  //
4698  // Set SCSI bus address.
4699  //
4700 
4701  srb->PathId = deviceExtension->PathId;
4702  srb->TargetId = deviceExtension->TargetId;
4703  srb->Lun = deviceExtension->Lun;
4704 
4705  //
4706  // NOTICE: The SCSI-II specification indicates that this field should be
4707  // zero; however, some target controllers ignore the logical unit number
4708  // in the IDENTIFY message and only look at the logical unit number field
4709  // in the CDB.
4710  //
4711 
4712  srb->Cdb[1] |= deviceExtension->Lun << 5;
4713 
4714  //
4715  // Set the parameters in the next stack location.
4716  //
4717 
4718  irpStack = IoGetNextIrpStackLocation(Irp);
4719 
4720  irpStack->Parameters.Scsi.Srb = srb;
4721  irpStack->MajorFunction = IRP_MJ_SCSI;
4722  irpStack->MinorFunction = IRP_MN_SCSI_CLASS;
4723 
4725  return IoCallDriver(deviceExtension->PortDeviceObject, Irp);
4726 }
#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:4730
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 714 of file class2.c.

736 {
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 media capacity in bytes.
832  //
833 
834  deviceExtension->PartitionLength.QuadPart = (LONGLONG)(lastSector + 1);
835 
836  //
837  // Calculate number of cylinders.
838  //
839 
840  deviceExtension->DiskGeometry->Geometry.Cylinders.QuadPart = (LONGLONG)((lastSector + 1)/(DEFAULT_SECTORS_PER_TRACK * DEFAULT_TRACKS_PER_CYLINDER));
841 
842  deviceExtension->PartitionLength.QuadPart =
843  (deviceExtension->PartitionLength.QuadPart << deviceExtension->SectorShift);
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 
907  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
908 
909  //
910  // This device supports removable media.
911  //
912 
913  deviceExtension->DiskGeometry->Geometry.MediaType = RemovableMedia;
914 
915  } else {
916 
917  //
918  // Assume media type is fixed disk.
919  //
920 
921  deviceExtension->DiskGeometry->Geometry.MediaType = FixedMedia;
922  }
923  }
924 
925  //
926  // Deallocate read capacity buffer.
927  //
928 
929  ExFreePool(readCapacityBuffer);
930 
931  return status;
932 
933 } // 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:37
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:1855
#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 938 of file class2.c.

962 {
963  PIO_STACK_LOCATION irpStack;
964  PIRP irp;
968  KIRQL currentIrql;
969 
970  ASSERT(*(PULONG)deviceExtension != '2slc');
971 
972  //
973  // Allocate context from nonpaged pool.
974  //
975 
977  sizeof(COMPLETION_CONTEXT));
978 
979  //
980  // Save the device object in the context for use by the completion
981  // routine.
982  //
983 
984  context->DeviceObject = DeviceObject;
985  srb = &context->Srb;
986 
987  //
988  // Zero out srb.
989  //
990 
992 
993  //
994  // Write length to SRB.
995  //
996 
998 
999  //
1000  // Set up SCSI bus address.
1001  //
1002 
1003  srb->PathId = deviceExtension->PathId;
1004  srb->TargetId = deviceExtension->TargetId;
1005  srb->Lun = deviceExtension->Lun;
1006 
1007  //
1008  // If this device is removable then flush the queue. This will also
1009  // release it.
1010  //
1011 
1012  if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) {
1013 
1015 
1016  } else {
1017 
1019 
1020  }
1021 
1022  //
1023  // Build the asynchronous request to be sent to the port driver.
1024  //
1025 
1027 
1028  if(irp == NULL) {
1029 
1030  //
1031  // We have no better way of dealing with this at the moment
1032  //
1033 
1034  KeBugCheck((ULONG)0x0000002DL);
1035 
1036  }
1037 
1040  context,
1041  TRUE,
1042  TRUE,
1043  TRUE);
1044 
1045  irpStack = IoGetNextIrpStackLocation(irp);
1046 
1047  irpStack->MajorFunction = IRP_MJ_SCSI;
1048 
1049  srb->OriginalRequest = irp;
1050 
1051  //
1052  // Store the SRB address in next stack for port driver.
1053  //
1054 
1055  irpStack->Parameters.Scsi.Srb = srb;
1056 
1057  //
1058  // Since this routine can cause outstanding requests to be completed, and
1059  // calling a completion routine at < DISPATCH_LEVEL is dangerous (if they
1060  // call IoStartNextPacket we will bugcheck) raise up to dispatch level before
1061  // issuing the request
1062  //
1063 
1064  currentIrql = KeGetCurrentIrql();
1065 
1066  if(currentIrql < DISPATCH_LEVEL) {
1067  KeRaiseIrql(DISPATCH_LEVEL, &currentIrql);
1068  IoCallDriver(deviceExtension->PortDeviceObject, irp);
1069  KeLowerIrql(currentIrql);
1070  } else {
1071  IoCallDriver(deviceExtension->PortDeviceObject, irp);
1072  }
1073 
1074  return;
1075 
1076 } // 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:7098
NTSTATUS NTAPI ScsiClassAsynchronousCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
Definition: class2.c:1216
#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()