mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 17:16:04 +00:00
[SCSIPORT]: Code formatting in the functions I'm going to touch next (in addition, add few "continue;" inside some loops so that I can reduce the indent level of code blocks).
svn path=/trunk/; revision=74594
This commit is contained in:
parent
5f36105c74
commit
b00727337e
1 changed files with 431 additions and 442 deletions
|
@ -3548,7 +3548,7 @@ SpiAllocateSrbStructures(PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
|
SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
|
||||||
IN PSCSI_LUN_INFO LunInfo)
|
IN PSCSI_LUN_INFO LunInfo)
|
||||||
{
|
{
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
PIO_STACK_LOCATION IrpStack;
|
PIO_STACK_LOCATION IrpStack;
|
||||||
|
@ -3569,11 +3569,11 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
DeviceExtension = (PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
DeviceExtension = (PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||||
|
|
||||||
InquiryBuffer = ExAllocatePoolWithTag (NonPagedPool, INQUIRYDATABUFFERSIZE, TAG_SCSIPORT);
|
InquiryBuffer = ExAllocatePoolWithTag(NonPagedPool, INQUIRYDATABUFFERSIZE, TAG_SCSIPORT);
|
||||||
if (InquiryBuffer == NULL)
|
if (InquiryBuffer == NULL)
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
SenseBuffer = ExAllocatePoolWithTag (NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT);
|
SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT);
|
||||||
if (SenseBuffer == NULL)
|
if (SenseBuffer == NULL)
|
||||||
{
|
{
|
||||||
ExFreePool(InquiryBuffer);
|
ExFreePool(InquiryBuffer);
|
||||||
|
@ -3589,14 +3589,14 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
/* Create an IRP */
|
/* Create an IRP */
|
||||||
Irp = IoBuildDeviceIoControlRequest(IOCTL_SCSI_EXECUTE_IN,
|
Irp = IoBuildDeviceIoControlRequest(IOCTL_SCSI_EXECUTE_IN,
|
||||||
DeviceObject,
|
DeviceObject,
|
||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
InquiryBuffer,
|
InquiryBuffer,
|
||||||
INQUIRYDATABUFFERSIZE,
|
INQUIRYDATABUFFERSIZE,
|
||||||
TRUE,
|
TRUE,
|
||||||
&Event,
|
&Event,
|
||||||
&IoStatusBlock);
|
&IoStatusBlock);
|
||||||
if (Irp == NULL)
|
if (Irp == NULL)
|
||||||
{
|
{
|
||||||
DPRINT("IoBuildDeviceIoControlRequest() failed\n");
|
DPRINT("IoBuildDeviceIoControlRequest() failed\n");
|
||||||
|
@ -3640,10 +3640,10 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
|
||||||
{
|
{
|
||||||
DPRINT("SpiSendInquiry(): Waiting for the driver to process request...\n");
|
DPRINT("SpiSendInquiry(): Waiting for the driver to process request...\n");
|
||||||
KeWaitForSingleObject(&Event,
|
KeWaitForSingleObject(&Event,
|
||||||
Executive,
|
Executive,
|
||||||
KernelMode,
|
KernelMode,
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
NULL);
|
||||||
Status = IoStatusBlock.Status;
|
Status = IoStatusBlock.Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3658,84 +3658,85 @@ SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
|
||||||
|
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
KeepTrying = FALSE;
|
KeepTrying = FALSE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DPRINT("Inquiry SRB failed with SrbStatus 0x%08X\n", Srb.SrbStatus);
|
||||||
|
|
||||||
|
/* Check if the queue is frozen */
|
||||||
|
if (Srb.SrbStatus & SRB_STATUS_QUEUE_FROZEN)
|
||||||
|
{
|
||||||
|
/* Something weird happened, deal with it (unfreeze the queue) */
|
||||||
|
KeepTrying = FALSE;
|
||||||
|
|
||||||
|
DPRINT("SpiSendInquiry(): the queue is frozen at TargetId %d\n", Srb.TargetId);
|
||||||
|
|
||||||
|
LunExtension = SpiGetLunExtension(DeviceExtension,
|
||||||
|
LunInfo->PathId,
|
||||||
|
LunInfo->TargetId,
|
||||||
|
LunInfo->Lun);
|
||||||
|
|
||||||
|
/* Clear frozen flag */
|
||||||
|
LunExtension->Flags &= ~LUNEX_FROZEN_QUEUE;
|
||||||
|
|
||||||
|
/* Acquire the spinlock */
|
||||||
|
KeAcquireSpinLock(&DeviceExtension->SpinLock, &Irql);
|
||||||
|
|
||||||
|
/* Process the request */
|
||||||
|
SpiGetNextRequestFromLun(DeviceObject->DeviceExtension, LunExtension);
|
||||||
|
|
||||||
|
/* SpiGetNextRequestFromLun() releases the spinlock,
|
||||||
|
so we just lower irql back to what it was before */
|
||||||
|
KeLowerIrql(Irql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if data overrun happened */
|
||||||
|
if (SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_DATA_OVERRUN)
|
||||||
|
{
|
||||||
|
DPRINT("Data overrun at TargetId %d\n", LunInfo->TargetId);
|
||||||
|
|
||||||
|
/* Nothing dramatic, just copy data, but limiting the size */
|
||||||
|
RtlCopyMemory(LunInfo->InquiryData,
|
||||||
|
InquiryBuffer,
|
||||||
|
(Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ?
|
||||||
|
INQUIRYDATABUFFERSIZE : Srb.DataTransferLength);
|
||||||
|
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
KeepTrying = FALSE;
|
||||||
|
}
|
||||||
|
else if ((Srb.SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
|
||||||
|
SenseBuffer->SenseKey == SCSI_SENSE_ILLEGAL_REQUEST)
|
||||||
|
{
|
||||||
|
/* LUN is not valid, but some device responds there.
|
||||||
|
Mark it as invalid anyway */
|
||||||
|
|
||||||
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
|
KeepTrying = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DPRINT("Inquiry SRB failed with SrbStatus 0x%08X\n", Srb.SrbStatus);
|
/* Retry a couple of times if no timeout happened */
|
||||||
/* Check if the queue is frozen */
|
if ((RetryCount < 2) &&
|
||||||
if (Srb.SrbStatus & SRB_STATUS_QUEUE_FROZEN)
|
(SRB_STATUS(Srb.SrbStatus) != SRB_STATUS_NO_DEVICE) &&
|
||||||
|
(SRB_STATUS(Srb.SrbStatus) != SRB_STATUS_SELECTION_TIMEOUT))
|
||||||
{
|
{
|
||||||
/* Something weird happened, deal with it (unfreeze the queue) */
|
RetryCount++;
|
||||||
KeepTrying = FALSE;
|
KeepTrying = TRUE;
|
||||||
|
|
||||||
DPRINT("SpiSendInquiry(): the queue is frozen at TargetId %d\n", Srb.TargetId);
|
|
||||||
|
|
||||||
LunExtension = SpiGetLunExtension(DeviceExtension,
|
|
||||||
LunInfo->PathId,
|
|
||||||
LunInfo->TargetId,
|
|
||||||
LunInfo->Lun);
|
|
||||||
|
|
||||||
/* Clear frozen flag */
|
|
||||||
LunExtension->Flags &= ~LUNEX_FROZEN_QUEUE;
|
|
||||||
|
|
||||||
/* Acquire the spinlock */
|
|
||||||
KeAcquireSpinLock(&DeviceExtension->SpinLock, &Irql);
|
|
||||||
|
|
||||||
/* Process the request */
|
|
||||||
SpiGetNextRequestFromLun(DeviceObject->DeviceExtension, LunExtension);
|
|
||||||
|
|
||||||
/* SpiGetNextRequestFromLun() releases the spinlock,
|
|
||||||
so we just lower irql back to what it was before */
|
|
||||||
KeLowerIrql(Irql);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if data overrun happened */
|
|
||||||
if (SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_DATA_OVERRUN)
|
|
||||||
{
|
|
||||||
DPRINT("Data overrun at TargetId %d\n", LunInfo->TargetId);
|
|
||||||
/* Nothing dramatic, just copy data, but limiting the size */
|
|
||||||
RtlCopyMemory(LunInfo->InquiryData,
|
|
||||||
InquiryBuffer,
|
|
||||||
(Srb.DataTransferLength > INQUIRYDATABUFFERSIZE) ?
|
|
||||||
INQUIRYDATABUFFERSIZE : Srb.DataTransferLength);
|
|
||||||
|
|
||||||
Status = STATUS_SUCCESS;
|
|
||||||
KeepTrying = FALSE;
|
|
||||||
}
|
|
||||||
else if ((Srb.SrbStatus & SRB_STATUS_AUTOSENSE_VALID) &&
|
|
||||||
SenseBuffer->SenseKey == SCSI_SENSE_ILLEGAL_REQUEST)
|
|
||||||
{
|
|
||||||
/* LUN is not valid, but some device responds there.
|
|
||||||
Mark it as invalid anyway */
|
|
||||||
|
|
||||||
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
||||||
KeepTrying = FALSE;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Retry a couple of times if no timeout happened */
|
/* That's all, go to exit */
|
||||||
if ((RetryCount < 2) &&
|
KeepTrying = FALSE;
|
||||||
(SRB_STATUS(Srb.SrbStatus) != SRB_STATUS_NO_DEVICE) &&
|
|
||||||
(SRB_STATUS(Srb.SrbStatus) != SRB_STATUS_SELECTION_TIMEOUT))
|
/* Set status according to SRB status */
|
||||||
|
if (SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_BAD_FUNCTION ||
|
||||||
|
SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_BAD_SRB_BLOCK_LENGTH)
|
||||||
{
|
{
|
||||||
RetryCount++;
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||||
KeepTrying = TRUE;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* That's all, go to exit */
|
Status = STATUS_IO_DEVICE_ERROR;
|
||||||
KeepTrying = FALSE;
|
|
||||||
|
|
||||||
/* Set status according to SRB status */
|
|
||||||
if (SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_BAD_FUNCTION ||
|
|
||||||
SRB_STATUS(Srb.SrbStatus) == SRB_STATUS_BAD_SRB_BLOCK_LENGTH)
|
|
||||||
{
|
|
||||||
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Status = STATUS_IO_DEVICE_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3968,7 +3969,7 @@ SpiScanAdapter(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
SpiGetInquiryData(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
|
SpiGetInquiryData(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
|
||||||
PIRP Irp)
|
IN PIRP Irp)
|
||||||
{
|
{
|
||||||
ULONG InquiryDataSize;
|
ULONG InquiryDataSize;
|
||||||
PSCSI_LUN_INFO LunInfo;
|
PSCSI_LUN_INFO LunInfo;
|
||||||
|
@ -5247,426 +5248,414 @@ ScsiPortIoTimer(PDEVICE_OBJECT DeviceObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* NAME INTERNAL
|
* NAME INTERNAL
|
||||||
* SpiBuildDeviceMap
|
* SpiBuildDeviceMap
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* Builds the registry device map of all device which are attached
|
* Builds the registry device map of all device which are attached
|
||||||
* to the given SCSI HBA port. The device map is located at:
|
* to the given SCSI HBA port. The device map is located at:
|
||||||
* \Registry\Machine\DeviceMap\Scsi
|
* \Registry\Machine\DeviceMap\Scsi
|
||||||
*
|
*
|
||||||
* RUN LEVEL
|
* RUN LEVEL
|
||||||
* PASSIVE_LEVEL
|
* PASSIVE_LEVEL
|
||||||
*
|
*
|
||||||
* ARGUMENTS
|
* ARGUMENTS
|
||||||
* DeviceExtension
|
* DeviceExtension
|
||||||
* ...
|
* ...
|
||||||
*
|
*
|
||||||
* RegistryPath
|
* RegistryPath
|
||||||
* Name of registry driver service key.
|
* Name of registry driver service key.
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* NTSTATUS
|
* NTSTATUS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static NTSTATUS
|
static NTSTATUS
|
||||||
SpiBuildDeviceMap (PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
|
SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
|
||||||
PUNICODE_STRING RegistryPath)
|
IN PUNICODE_STRING RegistryPath)
|
||||||
{
|
{
|
||||||
PSCSI_PORT_LUN_EXTENSION LunExtension;
|
PSCSI_PORT_LUN_EXTENSION LunExtension;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
UNICODE_STRING KeyName;
|
UNICODE_STRING KeyName;
|
||||||
UNICODE_STRING ValueName;
|
UNICODE_STRING ValueName;
|
||||||
WCHAR NameBuffer[64];
|
WCHAR NameBuffer[64];
|
||||||
ULONG Disposition;
|
ULONG Disposition;
|
||||||
HANDLE ScsiKey;
|
HANDLE ScsiKey;
|
||||||
HANDLE ScsiPortKey = NULL;
|
HANDLE ScsiPortKey = NULL;
|
||||||
HANDLE ScsiBusKey = NULL;
|
HANDLE ScsiBusKey = NULL;
|
||||||
HANDLE ScsiInitiatorKey = NULL;
|
HANDLE ScsiInitiatorKey = NULL;
|
||||||
HANDLE ScsiTargetKey = NULL;
|
HANDLE ScsiTargetKey = NULL;
|
||||||
HANDLE ScsiLunKey = NULL;
|
HANDLE ScsiLunKey = NULL;
|
||||||
ULONG BusNumber;
|
ULONG BusNumber;
|
||||||
ULONG Target;
|
ULONG Target;
|
||||||
ULONG CurrentTarget;
|
ULONG CurrentTarget;
|
||||||
ULONG Lun;
|
ULONG Lun;
|
||||||
PWCHAR DriverName;
|
PWCHAR DriverName;
|
||||||
ULONG UlongData;
|
ULONG UlongData;
|
||||||
PWCHAR TypeName;
|
PWCHAR TypeName;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT("SpiBuildDeviceMap() called\n");
|
DPRINT("SpiBuildDeviceMap() called\n");
|
||||||
|
|
||||||
if (DeviceExtension == NULL || RegistryPath == NULL)
|
if (DeviceExtension == NULL || RegistryPath == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("Invalid parameter\n");
|
DPRINT1("Invalid parameter\n");
|
||||||
return(STATUS_INVALID_PARAMETER);
|
return STATUS_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open or create the 'Scsi' subkey */
|
/* Open or create the 'Scsi' subkey */
|
||||||
RtlInitUnicodeString(&KeyName,
|
RtlInitUnicodeString(&KeyName,
|
||||||
L"\\Registry\\Machine\\Hardware\\DeviceMap\\Scsi");
|
L"\\Registry\\Machine\\Hardware\\DeviceMap\\Scsi");
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
&KeyName,
|
&KeyName,
|
||||||
OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_KERNEL_HANDLE,
|
OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_KERNEL_HANDLE,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
Status = ZwCreateKey(&ScsiKey,
|
Status = ZwCreateKey(&ScsiKey,
|
||||||
KEY_ALL_ACCESS,
|
KEY_ALL_ACCESS,
|
||||||
&ObjectAttributes,
|
&ObjectAttributes,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
REG_OPTION_VOLATILE,
|
REG_OPTION_VOLATILE,
|
||||||
&Disposition);
|
&Disposition);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create new 'Scsi Port X' subkey */
|
/* Create new 'Scsi Port X' subkey */
|
||||||
DPRINT("Scsi Port %lu\n",
|
DPRINT("Scsi Port %lu\n", DeviceExtension->PortNumber);
|
||||||
DeviceExtension->PortNumber);
|
|
||||||
|
|
||||||
swprintf(NameBuffer,
|
swprintf(NameBuffer,
|
||||||
L"Scsi Port %lu",
|
L"Scsi Port %lu",
|
||||||
DeviceExtension->PortNumber);
|
DeviceExtension->PortNumber);
|
||||||
RtlInitUnicodeString(&KeyName,
|
RtlInitUnicodeString(&KeyName, NameBuffer);
|
||||||
NameBuffer);
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
&KeyName,
|
||||||
&KeyName,
|
OBJ_KERNEL_HANDLE,
|
||||||
OBJ_KERNEL_HANDLE,
|
ScsiKey,
|
||||||
ScsiKey,
|
NULL);
|
||||||
NULL);
|
Status = ZwCreateKey(&ScsiPortKey,
|
||||||
Status = ZwCreateKey(&ScsiPortKey,
|
KEY_ALL_ACCESS,
|
||||||
KEY_ALL_ACCESS,
|
&ObjectAttributes,
|
||||||
&ObjectAttributes,
|
0,
|
||||||
0,
|
NULL,
|
||||||
NULL,
|
REG_OPTION_VOLATILE,
|
||||||
REG_OPTION_VOLATILE,
|
&Disposition);
|
||||||
&Disposition);
|
ZwClose(ScsiKey);
|
||||||
ZwClose(ScsiKey);
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create port-specific values
|
* Create port-specific values
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Set 'DMA Enabled' (REG_DWORD) value */
|
/* Set 'DMA Enabled' (REG_DWORD) value */
|
||||||
UlongData = (ULONG)!DeviceExtension->PortCapabilities.AdapterUsesPio;
|
UlongData = (ULONG)!DeviceExtension->PortCapabilities.AdapterUsesPio;
|
||||||
DPRINT(" DMA Enabled = %s\n", (UlongData) ? "TRUE" : "FALSE");
|
DPRINT(" DMA Enabled = %s\n", UlongData ? "TRUE" : "FALSE");
|
||||||
RtlInitUnicodeString(&ValueName,
|
RtlInitUnicodeString(&ValueName, L"DMA Enabled");
|
||||||
L"DMA Enabled");
|
Status = ZwSetValueKey(ScsiPortKey,
|
||||||
Status = ZwSetValueKey(ScsiPortKey,
|
&ValueName,
|
||||||
&ValueName,
|
0,
|
||||||
0,
|
REG_DWORD,
|
||||||
REG_DWORD,
|
&UlongData,
|
||||||
&UlongData,
|
sizeof(UlongData));
|
||||||
sizeof(ULONG));
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT("ZwSetValueKey('DMA Enabled') failed (Status %lx)\n", Status);
|
DPRINT("ZwSetValueKey('DMA Enabled') failed (Status %lx)\n", Status);
|
||||||
ZwClose(ScsiPortKey);
|
ZwClose(ScsiPortKey);
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set 'Driver' (REG_SZ) value */
|
/* Set 'Driver' (REG_SZ) value */
|
||||||
DriverName = wcsrchr(RegistryPath->Buffer, L'\\') + 1;
|
DriverName = wcsrchr(RegistryPath->Buffer, L'\\') + 1;
|
||||||
RtlInitUnicodeString(&ValueName,
|
RtlInitUnicodeString(&ValueName, L"Driver");
|
||||||
L"Driver");
|
Status = ZwSetValueKey(ScsiPortKey,
|
||||||
Status = ZwSetValueKey(ScsiPortKey,
|
&ValueName,
|
||||||
&ValueName,
|
0,
|
||||||
0,
|
REG_SZ,
|
||||||
REG_SZ,
|
DriverName,
|
||||||
DriverName,
|
(ULONG)((wcslen(DriverName) + 1) * sizeof(WCHAR)));
|
||||||
(ULONG)((wcslen(DriverName) + 1) * sizeof(WCHAR)));
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT("ZwSetValueKey('Driver') failed (Status %lx)\n", Status);
|
DPRINT("ZwSetValueKey('Driver') failed (Status %lx)\n", Status);
|
||||||
ZwClose(ScsiPortKey);
|
ZwClose(ScsiPortKey);
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set 'Interrupt' (REG_DWORD) value (NT4 only) */
|
/* Set 'Interrupt' (REG_DWORD) value (NT4 only) */
|
||||||
UlongData = (ULONG)DeviceExtension->PortConfig->BusInterruptLevel;
|
UlongData = (ULONG)DeviceExtension->PortConfig->BusInterruptLevel;
|
||||||
DPRINT(" Interrupt = %lu\n", UlongData);
|
DPRINT(" Interrupt = %lu\n", UlongData);
|
||||||
RtlInitUnicodeString(&ValueName,
|
RtlInitUnicodeString(&ValueName, L"Interrupt");
|
||||||
L"Interrupt");
|
Status = ZwSetValueKey(ScsiPortKey,
|
||||||
Status = ZwSetValueKey(ScsiPortKey,
|
&ValueName,
|
||||||
&ValueName,
|
0,
|
||||||
0,
|
REG_DWORD,
|
||||||
REG_DWORD,
|
&UlongData,
|
||||||
&UlongData,
|
sizeof(UlongData));
|
||||||
sizeof(ULONG));
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT("ZwSetValueKey('Interrupt') failed (Status %lx)\n", Status);
|
DPRINT("ZwSetValueKey('Interrupt') failed (Status %lx)\n", Status);
|
||||||
ZwClose(ScsiPortKey);
|
ZwClose(ScsiPortKey);
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set 'IOAddress' (REG_DWORD) value (NT4 only) */
|
/* Set 'IOAddress' (REG_DWORD) value (NT4 only) */
|
||||||
UlongData = ScsiPortConvertPhysicalAddressToUlong((*DeviceExtension->PortConfig->AccessRanges)[0].RangeStart);
|
UlongData = ScsiPortConvertPhysicalAddressToUlong((*DeviceExtension->PortConfig->AccessRanges)[0].RangeStart);
|
||||||
DPRINT(" IOAddress = %lx\n", UlongData);
|
DPRINT(" IOAddress = %lx\n", UlongData);
|
||||||
RtlInitUnicodeString(&ValueName,
|
RtlInitUnicodeString(&ValueName, L"IOAddress");
|
||||||
L"IOAddress");
|
Status = ZwSetValueKey(ScsiPortKey,
|
||||||
Status = ZwSetValueKey(ScsiPortKey,
|
&ValueName,
|
||||||
&ValueName,
|
0,
|
||||||
0,
|
REG_DWORD,
|
||||||
REG_DWORD,
|
&UlongData,
|
||||||
&UlongData,
|
sizeof(UlongData));
|
||||||
sizeof(ULONG));
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
DPRINT("ZwSetValueKey('IOAddress') failed (Status %lx)\n", Status);
|
DPRINT("ZwSetValueKey('IOAddress') failed (Status %lx)\n", Status);
|
||||||
ZwClose(ScsiPortKey);
|
ZwClose(ScsiPortKey);
|
||||||
return(Status);
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enumerate buses */
|
/* Enumerate buses */
|
||||||
for (BusNumber = 0; BusNumber < DeviceExtension->PortConfig->NumberOfBuses; BusNumber++)
|
for (BusNumber = 0; BusNumber < DeviceExtension->PortConfig->NumberOfBuses; BusNumber++)
|
||||||
{
|
{
|
||||||
/* Create 'Scsi Bus X' key */
|
/* Create 'Scsi Bus X' key */
|
||||||
DPRINT(" Scsi Bus %lu\n", BusNumber);
|
DPRINT(" Scsi Bus %lu\n", BusNumber);
|
||||||
swprintf(NameBuffer,
|
swprintf(NameBuffer,
|
||||||
L"Scsi Bus %lu",
|
L"Scsi Bus %lu",
|
||||||
BusNumber);
|
BusNumber);
|
||||||
RtlInitUnicodeString(&KeyName,
|
RtlInitUnicodeString(&KeyName, NameBuffer);
|
||||||
NameBuffer);
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
&KeyName,
|
||||||
&KeyName,
|
0,
|
||||||
0,
|
ScsiPortKey,
|
||||||
ScsiPortKey,
|
NULL);
|
||||||
NULL);
|
Status = ZwCreateKey(&ScsiBusKey,
|
||||||
Status = ZwCreateKey(&ScsiBusKey,
|
KEY_ALL_ACCESS,
|
||||||
KEY_ALL_ACCESS,
|
&ObjectAttributes,
|
||||||
&ObjectAttributes,
|
0,
|
||||||
0,
|
NULL,
|
||||||
NULL,
|
REG_OPTION_VOLATILE,
|
||||||
REG_OPTION_VOLATILE,
|
&Disposition);
|
||||||
&Disposition);
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
{
|
||||||
{
|
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
||||||
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
goto ByeBye;
|
||||||
goto ByeBye;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Create 'Initiator Id X' key */
|
/* Create 'Initiator Id X' key */
|
||||||
DPRINT(" Initiator Id %u\n",
|
DPRINT(" Initiator Id %lu\n",
|
||||||
DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
|
DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
|
||||||
swprintf(NameBuffer,
|
swprintf(NameBuffer,
|
||||||
L"Initiator Id %u",
|
L"Initiator Id %lu",
|
||||||
(unsigned int)(UCHAR)DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
|
(ULONG)(UCHAR)DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
|
||||||
RtlInitUnicodeString(&KeyName,
|
RtlInitUnicodeString(&KeyName, NameBuffer);
|
||||||
NameBuffer);
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
&KeyName,
|
||||||
&KeyName,
|
0,
|
||||||
0,
|
ScsiBusKey,
|
||||||
ScsiBusKey,
|
NULL);
|
||||||
NULL);
|
Status = ZwCreateKey(&ScsiInitiatorKey,
|
||||||
Status = ZwCreateKey(&ScsiInitiatorKey,
|
KEY_ALL_ACCESS,
|
||||||
KEY_ALL_ACCESS,
|
&ObjectAttributes,
|
||||||
&ObjectAttributes,
|
0,
|
||||||
0,
|
NULL,
|
||||||
NULL,
|
REG_OPTION_VOLATILE,
|
||||||
REG_OPTION_VOLATILE,
|
&Disposition);
|
||||||
&Disposition);
|
if (!NT_SUCCESS(Status))
|
||||||
if (!NT_SUCCESS(Status))
|
{
|
||||||
{
|
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
||||||
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
goto ByeBye;
|
||||||
goto ByeBye;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: Are there any initiator values (??) */
|
/* FIXME: Are there any initiator values (??) */
|
||||||
|
|
||||||
ZwClose(ScsiInitiatorKey);
|
ZwClose(ScsiInitiatorKey);
|
||||||
ScsiInitiatorKey = NULL;
|
ScsiInitiatorKey = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Enumerate targets */
|
/* Enumerate targets */
|
||||||
CurrentTarget = (ULONG)-1;
|
CurrentTarget = (ULONG)-1;
|
||||||
ScsiTargetKey = NULL;
|
ScsiTargetKey = NULL;
|
||||||
for (Target = 0; Target < DeviceExtension->PortConfig->MaximumNumberOfTargets; Target++)
|
for (Target = 0; Target < DeviceExtension->PortConfig->MaximumNumberOfTargets; Target++)
|
||||||
{
|
{
|
||||||
for (Lun = 0; Lun < SCSI_MAXIMUM_LOGICAL_UNITS; Lun++)
|
for (Lun = 0; Lun < SCSI_MAXIMUM_LOGICAL_UNITS; Lun++)
|
||||||
{
|
{
|
||||||
LunExtension = SpiGetLunExtension(DeviceExtension,
|
LunExtension = SpiGetLunExtension(DeviceExtension,
|
||||||
(UCHAR)BusNumber,
|
(UCHAR)BusNumber,
|
||||||
(UCHAR)Target,
|
(UCHAR)Target,
|
||||||
(UCHAR)Lun);
|
(UCHAR)Lun);
|
||||||
if (LunExtension != NULL)
|
if (LunExtension == NULL)
|
||||||
{
|
continue;
|
||||||
if (Target != CurrentTarget)
|
|
||||||
{
|
|
||||||
/* Close old target key */
|
|
||||||
if (ScsiTargetKey != NULL)
|
|
||||||
{
|
|
||||||
ZwClose(ScsiTargetKey);
|
|
||||||
ScsiTargetKey = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create 'Target Id X' key */
|
if (Target != CurrentTarget)
|
||||||
DPRINT(" Target Id %lu\n", Target);
|
{
|
||||||
swprintf(NameBuffer,
|
/* Close old target key */
|
||||||
L"Target Id %lu",
|
if (ScsiTargetKey != NULL)
|
||||||
Target);
|
{
|
||||||
RtlInitUnicodeString(&KeyName,
|
ZwClose(ScsiTargetKey);
|
||||||
NameBuffer);
|
ScsiTargetKey = NULL;
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
}
|
||||||
&KeyName,
|
|
||||||
0,
|
|
||||||
ScsiBusKey,
|
|
||||||
NULL);
|
|
||||||
Status = ZwCreateKey(&ScsiTargetKey,
|
|
||||||
KEY_ALL_ACCESS,
|
|
||||||
&ObjectAttributes,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
REG_OPTION_VOLATILE,
|
|
||||||
&Disposition);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
|
||||||
goto ByeBye;
|
|
||||||
}
|
|
||||||
|
|
||||||
CurrentTarget = Target;
|
/* Create 'Target Id X' key */
|
||||||
}
|
DPRINT(" Target Id %lu\n", Target);
|
||||||
|
swprintf(NameBuffer,
|
||||||
|
L"Target Id %lu",
|
||||||
|
Target);
|
||||||
|
RtlInitUnicodeString(&KeyName, NameBuffer);
|
||||||
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
|
&KeyName,
|
||||||
|
0,
|
||||||
|
ScsiBusKey,
|
||||||
|
NULL);
|
||||||
|
Status = ZwCreateKey(&ScsiTargetKey,
|
||||||
|
KEY_ALL_ACCESS,
|
||||||
|
&ObjectAttributes,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
REG_OPTION_VOLATILE,
|
||||||
|
&Disposition);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
||||||
|
goto ByeBye;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create 'Logical Unit Id X' key */
|
CurrentTarget = Target;
|
||||||
DPRINT(" Logical Unit Id %lu\n", Lun);
|
}
|
||||||
swprintf(NameBuffer,
|
|
||||||
L"Logical Unit Id %lu",
|
|
||||||
Lun);
|
|
||||||
RtlInitUnicodeString(&KeyName,
|
|
||||||
NameBuffer);
|
|
||||||
InitializeObjectAttributes(&ObjectAttributes,
|
|
||||||
&KeyName,
|
|
||||||
0,
|
|
||||||
ScsiTargetKey,
|
|
||||||
NULL);
|
|
||||||
Status = ZwCreateKey(&ScsiLunKey,
|
|
||||||
KEY_ALL_ACCESS,
|
|
||||||
&ObjectAttributes,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
REG_OPTION_VOLATILE,
|
|
||||||
&Disposition);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
|
||||||
goto ByeBye;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set 'Identifier' (REG_SZ) value */
|
/* Create 'Logical Unit Id X' key */
|
||||||
swprintf(NameBuffer,
|
DPRINT(" Logical Unit Id %lu\n", Lun);
|
||||||
L"%.8S%.16S%.4S",
|
swprintf(NameBuffer,
|
||||||
LunExtension->InquiryData.VendorId,
|
L"Logical Unit Id %lu",
|
||||||
LunExtension->InquiryData.ProductId,
|
Lun);
|
||||||
LunExtension->InquiryData.ProductRevisionLevel);
|
RtlInitUnicodeString(&KeyName, NameBuffer);
|
||||||
DPRINT(" Identifier = '%S'\n", NameBuffer);
|
InitializeObjectAttributes(&ObjectAttributes,
|
||||||
RtlInitUnicodeString(&ValueName,
|
&KeyName,
|
||||||
L"Identifier");
|
0,
|
||||||
Status = ZwSetValueKey(ScsiLunKey,
|
ScsiTargetKey,
|
||||||
&ValueName,
|
NULL);
|
||||||
0,
|
Status = ZwCreateKey(&ScsiLunKey,
|
||||||
REG_SZ,
|
KEY_ALL_ACCESS,
|
||||||
NameBuffer,
|
&ObjectAttributes,
|
||||||
(ULONG)((wcslen(NameBuffer) + 1) * sizeof(WCHAR)));
|
0,
|
||||||
if (!NT_SUCCESS(Status))
|
NULL,
|
||||||
{
|
REG_OPTION_VOLATILE,
|
||||||
DPRINT("ZwSetValueKey('Identifier') failed (Status %lx)\n", Status);
|
&Disposition);
|
||||||
goto ByeBye;
|
if (!NT_SUCCESS(Status))
|
||||||
}
|
{
|
||||||
|
DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
|
||||||
|
goto ByeBye;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set 'Type' (REG_SZ) value */
|
/* Set 'Identifier' (REG_SZ) value */
|
||||||
switch (LunExtension->InquiryData.DeviceType)
|
swprintf(NameBuffer,
|
||||||
{
|
L"%.8S%.16S%.4S",
|
||||||
case 0:
|
LunExtension->InquiryData.VendorId,
|
||||||
TypeName = L"DiskPeripheral";
|
LunExtension->InquiryData.ProductId,
|
||||||
break;
|
LunExtension->InquiryData.ProductRevisionLevel);
|
||||||
case 1:
|
DPRINT(" Identifier = '%S'\n", NameBuffer);
|
||||||
TypeName = L"TapePeripheral";
|
RtlInitUnicodeString(&ValueName, L"Identifier");
|
||||||
break;
|
Status = ZwSetValueKey(ScsiLunKey,
|
||||||
case 2:
|
&ValueName,
|
||||||
TypeName = L"PrinterPeripheral";
|
0,
|
||||||
break;
|
REG_SZ,
|
||||||
case 4:
|
NameBuffer,
|
||||||
TypeName = L"WormPeripheral";
|
(ULONG)((wcslen(NameBuffer) + 1) * sizeof(WCHAR)));
|
||||||
break;
|
if (!NT_SUCCESS(Status))
|
||||||
case 5:
|
{
|
||||||
TypeName = L"CdRomPeripheral";
|
DPRINT("ZwSetValueKey('Identifier') failed (Status %lx)\n", Status);
|
||||||
break;
|
goto ByeBye;
|
||||||
case 6:
|
}
|
||||||
TypeName = L"ScannerPeripheral";
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
TypeName = L"OpticalDiskPeripheral";
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
TypeName = L"MediumChangerPeripheral";
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
TypeName = L"CommunicationPeripheral";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
TypeName = L"OtherPeripheral";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DPRINT(" Type = '%S'\n", TypeName);
|
|
||||||
RtlInitUnicodeString(&ValueName,
|
|
||||||
L"Type");
|
|
||||||
Status = ZwSetValueKey(ScsiLunKey,
|
|
||||||
&ValueName,
|
|
||||||
0,
|
|
||||||
REG_SZ,
|
|
||||||
TypeName,
|
|
||||||
(ULONG)((wcslen(TypeName) + 1) * sizeof(WCHAR)));
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
DPRINT("ZwSetValueKey('Type') failed (Status %lx)\n", Status);
|
|
||||||
goto ByeBye;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZwClose(ScsiLunKey);
|
/* Set 'Type' (REG_SZ) value */
|
||||||
ScsiLunKey = NULL;
|
switch (LunExtension->InquiryData.DeviceType)
|
||||||
}
|
{
|
||||||
}
|
case 0:
|
||||||
|
TypeName = L"DiskPeripheral";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
TypeName = L"TapePeripheral";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
TypeName = L"PrinterPeripheral";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
TypeName = L"WormPeripheral";
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
TypeName = L"CdRomPeripheral";
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
TypeName = L"ScannerPeripheral";
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
TypeName = L"OpticalDiskPeripheral";
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
TypeName = L"MediumChangerPeripheral";
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
TypeName = L"CommunicationPeripheral";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
TypeName = L"OtherPeripheral";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DPRINT(" Type = '%S'\n", TypeName);
|
||||||
|
RtlInitUnicodeString(&ValueName, L"Type");
|
||||||
|
Status = ZwSetValueKey(ScsiLunKey,
|
||||||
|
&ValueName,
|
||||||
|
0,
|
||||||
|
REG_SZ,
|
||||||
|
TypeName,
|
||||||
|
(ULONG)((wcslen(TypeName) + 1) * sizeof(WCHAR)));
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DPRINT("ZwSetValueKey('Type') failed (Status %lx)\n", Status);
|
||||||
|
goto ByeBye;
|
||||||
|
}
|
||||||
|
|
||||||
/* Close old target key */
|
ZwClose(ScsiLunKey);
|
||||||
if (ScsiTargetKey != NULL)
|
ScsiLunKey = NULL;
|
||||||
{
|
}
|
||||||
ZwClose(ScsiTargetKey);
|
|
||||||
ScsiTargetKey = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ZwClose(ScsiBusKey);
|
/* Close old target key */
|
||||||
ScsiBusKey = NULL;
|
if (ScsiTargetKey != NULL)
|
||||||
|
{
|
||||||
|
ZwClose(ScsiTargetKey);
|
||||||
|
ScsiTargetKey = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZwClose(ScsiBusKey);
|
||||||
|
ScsiBusKey = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByeBye:
|
ByeBye:
|
||||||
if (ScsiLunKey != NULL)
|
if (ScsiLunKey != NULL)
|
||||||
ZwClose (ScsiLunKey);
|
ZwClose(ScsiLunKey);
|
||||||
|
|
||||||
if (ScsiInitiatorKey != NULL)
|
if (ScsiInitiatorKey != NULL)
|
||||||
ZwClose (ScsiInitiatorKey);
|
ZwClose(ScsiInitiatorKey);
|
||||||
|
|
||||||
if (ScsiTargetKey != NULL)
|
if (ScsiTargetKey != NULL)
|
||||||
ZwClose (ScsiTargetKey);
|
ZwClose(ScsiTargetKey);
|
||||||
|
|
||||||
if (ScsiBusKey != NULL)
|
if (ScsiBusKey != NULL)
|
||||||
ZwClose (ScsiBusKey);
|
ZwClose(ScsiBusKey);
|
||||||
|
|
||||||
if (ScsiPortKey != NULL)
|
if (ScsiPortKey != NULL)
|
||||||
ZwClose (ScsiPortKey);
|
ZwClose(ScsiPortKey);
|
||||||
|
|
||||||
DPRINT("SpiBuildDeviceMap() done\n");
|
DPRINT("SpiBuildDeviceMap() done\n");
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue