PVOID MapRegisterBase, PVOID Context);
static PSCSI_PORT_LUN_EXTENSION
-SpiAllocateLunExtension (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
+SpiAllocateLunExtension(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
static PSCSI_PORT_LUN_EXTENSION
SpiGetLunExtension (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
PSCSI_REQUEST_BLOCK Srb);
static NTSTATUS
-SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
- IN PSCSI_LUN_INFO LunInfo);
+SpiSendInquiry(IN PDEVICE_OBJECT DeviceObject,
+ IN OUT PSCSI_LUN_INFO LunInfo);
static VOID
SpiScanAdapter (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension);
IN PVOID Context);
static NTSTATUS
-SpiBuildDeviceMap (PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
- PUNICODE_STRING RegistryPath);
+SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
+ IN PUNICODE_STRING RegistryPath);
static NTSTATUS
SpiStatusSrbToNt(UCHAR SrbStatus);
}
static PSCSI_PORT_LUN_EXTENSION
-SpiAllocateLunExtension (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
+SpiAllocateLunExtension(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
{
PSCSI_PORT_LUN_EXTENSION LunExtension;
ULONG LunExtensionSize;
- DPRINT("SpiAllocateLunExtension (%p)\n",
- DeviceExtension);
+ DPRINT("SpiAllocateLunExtension(%p)\n", DeviceExtension);
/* Round LunExtensionSize first to the sizeof LONGLONG */
LunExtensionSize = (DeviceExtension->LunExtensionSize +
- sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
+ sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
LunExtensionSize += sizeof(SCSI_PORT_LUN_EXTENSION);
DPRINT("LunExtensionSize %lu\n", LunExtensionSize);
LunExtension->MaxQueueCount = 256;
/* Initialize request queue */
- KeInitializeDeviceQueue (&LunExtension->DeviceQueue);
+ KeInitializeDeviceQueue(&LunExtension->DeviceQueue);
return LunExtension;
}
static NTSTATUS
-SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
- IN PSCSI_LUN_INFO LunInfo)
+SpiSendInquiry(IN PDEVICE_OBJECT DeviceObject,
+ IN OUT PSCSI_LUN_INFO LunInfo)
{
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION IrpStack;
PSCSI_PORT_LUN_EXTENSION LunExtension;
PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
- DPRINT ("SpiSendInquiry() called\n");
+ DPRINT("SpiSendInquiry() called\n");
DeviceExtension = (PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT);
if (SenseBuffer == NULL)
{
- ExFreePool(InquiryBuffer);
+ ExFreePoolWithTag(InquiryBuffer, TAG_SCSIPORT);
return STATUS_INSUFFICIENT_RESOURCES;
}
if (Irp == NULL)
{
DPRINT("IoBuildDeviceIoControlRequest() failed\n");
- return STATUS_INSUFFICIENT_RESOURCES;
+
+ /* Quit the loop */
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ KeepTrying = FALSE;
+ continue;
}
/* Prepare SRB */
InquiryBuffer,
INQUIRYDATABUFFERSIZE);
+ /* Quit the loop */
Status = STATUS_SUCCESS;
KeepTrying = FALSE;
continue;
DPRINT("SpiSendInquiry(): the queue is frozen at TargetId %d\n", Srb.TargetId);
LunExtension = SpiGetLunExtension(DeviceExtension,
- LunInfo->PathId,
- LunInfo->TargetId,
- LunInfo->Lun);
+ LunInfo->PathId,
+ LunInfo->TargetId,
+ LunInfo->Lun);
/* Clear frozen flag */
LunExtension->Flags &= ~LUNEX_FROZEN_QUEUE;
(Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ?
INQUIRYDATABUFFERSIZE : Srb.DataTransferLength);
+ /* Quit the loop */
Status = STATUS_SUCCESS;
KeepTrying = FALSE;
}
else if ((Srb.SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
- SenseBuffer->SenseKey == SCSI_SENSE_ILLEGAL_REQUEST)
+ SenseBuffer->SenseKey == SCSI_SENSE_ILLEGAL_REQUEST)
{
/* LUN is not valid, but some device responds there.
Mark it as invalid anyway */
+ /* Quit the loop */
Status = STATUS_INVALID_DEVICE_REQUEST;
KeepTrying = FALSE;
}
}
else
{
- /* That's all, go to exit */
+ /* That's all, quit the loop */
KeepTrying = FALSE;
/* Set status according to SRB status */
}
/* Free buffers */
- ExFreePool(InquiryBuffer);
- ExFreePool(SenseBuffer);
+ ExFreePoolWithTag(InquiryBuffer, TAG_SCSIPORT);
+ ExFreePoolWithTag(SenseBuffer, TAG_SCSIPORT);
DPRINT("SpiSendInquiry() done with Status 0x%08X\n", Status);
{
/* We need to allocate this buffer */
BusScanInfo = ExAllocatePoolWithTag(NonPagedPool, sizeof(SCSI_BUS_SCAN_INFO), TAG_SCSIPORT);
-
if (!BusScanInfo)
{
DPRINT1("Out of resources!\n");
/* Create LUN information structure */
LunInfo = ExAllocatePoolWithTag(PagedPool, sizeof(SCSI_LUN_INFO), TAG_SCSIPORT);
-
- if (LunInfo == NULL)
+ if (!LunInfo)
{
DPRINT1("Out of resources!\n");
return;
RtlZeroMemory(LunInfo, sizeof(SCSI_LUN_INFO));
/* Create LunExtension */
- LunExtension = SpiAllocateLunExtension (DeviceExtension);
+ LunExtension = SpiAllocateLunExtension(DeviceExtension);
/* And send INQUIRY to every target */
for (Target = 0; Target < DeviceExtension->PortConfig->MaximumNumberOfTargets; Target++)
/* Fill Path, Target, Lun fields */
LunExtension->PathId = LunInfo->PathId = (UCHAR)Bus;
- LunExtension->TargetId = LunInfo->TargetId = (UCHAR) Target;
+ LunExtension->TargetId = LunInfo->TargetId = (UCHAR)Target;
LunExtension->Lun = LunInfo->Lun = (UCHAR)Lun;
/* Set flag to prevent race conditions */
/* Allocate another buffer */
LunInfo = ExAllocatePoolWithTag(PagedPool, sizeof(SCSI_LUN_INFO), TAG_SCSIPORT);
-
if (!LunInfo)
{
DPRINT1("Out of resources!\n");
ExFreePool(LunInfo);
/* Sum what we found */
- BusScanInfo->LogicalUnitsCount += (UCHAR) DevicesFound;
+ BusScanInfo->LogicalUnitsCount += (UCHAR)DevicesFound;
DPRINT(" Found %d devices on bus %d\n", DevicesFound, Bus);
}
- DPRINT ("SpiScanAdapter() done\n");
+ DPRINT("SpiScanAdapter() done\n");
}
sizeof(ULONG) - 1) & ~(sizeof(ULONG) - 1));
/* Calculate data size */
- Length = sizeof(SCSI_ADAPTER_BUS_INFO) + (BusCount - 1) *
- sizeof(SCSI_BUS_DATA);
+ Length = sizeof(SCSI_ADAPTER_BUS_INFO) + (BusCount - 1) * sizeof(SCSI_BUS_DATA);
Length += InquiryDataSize * LunCount;
/* Point InquiryData to the corresponding place inside Buffer */
InquiryData = (PSCSI_INQUIRY_DATA)(Buffer + sizeof(SCSI_ADAPTER_BUS_INFO) +
- (BusCount - 1) * sizeof(SCSI_BUS_DATA));
+ (BusCount - 1) * sizeof(SCSI_BUS_DATA));
/* Loop each bus */
for (Bus = 0; Bus < BusCount; Bus++)
while (LunInfo != NULL)
{
DPRINT("(Bus %lu Target %lu Lun %lu)\n",
- Bus, LunInfo->TargetId, LunInfo->Lun);
+ Bus, LunInfo->TargetId, LunInfo->Lun);
/* Fill InquiryData with values */
InquiryData->PathId = LunInfo->PathId;
/* Either mark the end, or set offset to 0 */
if (BusData->NumberOfLogicalUnits != 0)
- ((PSCSI_INQUIRY_DATA) ((PCHAR) InquiryData - InquiryDataSize))->NextInquiryDataOffset = 0;
+ ((PSCSI_INQUIRY_DATA) ((PCHAR)InquiryData - InquiryDataSize))->NextInquiryDataOffset = 0;
else
BusData->InquiryDataOffset = 0;
}
}
/* Set 'Type' (REG_SZ) value */
+ /*
+ * See https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-ide-devices
+ * and https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices
+ * for a list of types with their human-readable forms.
+ */
switch (LunExtension->InquiryData.DeviceType)
{
case 0:
case 2:
TypeName = L"PrinterPeripheral";
break;
+ // case 3: "ProcessorPeripheral", classified as 'other': fall back to default case.
case 4:
TypeName = L"WormPeripheral";
break;
TypeName = L"MediumChangerPeripheral";
break;
case 9:
- TypeName = L"CommunicationPeripheral";
+ TypeName = L"CommunicationsPeripheral";
break;
+
+ /* New peripheral types (SCSI only) */
+ case 10: case 11:
+ TypeName = L"ASCPrePressGraphicsPeripheral";
+ break;
+ case 12:
+ TypeName = L"ArrayPeripheral";
+ break;
+ case 13:
+ TypeName = L"EnclosurePeripheral";
+ break;
+ case 14:
+ TypeName = L"RBCPeripheral";
+ break;
+ case 15:
+ TypeName = L"CardReaderPeripheral";
+ break;
+ case 16:
+ TypeName = L"BridgePeripheral";
+ break;
+
default:
TypeName = L"OtherPeripheral";
break;