Author: hbelusca
Date: Fri May 19 14:49:23 2017
New Revision: 74594
URL:
http://svn.reactos.org/svn/reactos?rev=74594&view=rev
Log:
[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).
Modified:
trunk/reactos/drivers/storage/scsiport/scsiport.c
Modified: trunk/reactos/drivers/storage/scsiport/scsiport.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/storage/scsiport/s…
==============================================================================
--- trunk/reactos/drivers/storage/scsiport/scsiport.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/storage/scsiport/scsiport.c [iso-8859-1] Fri May 19 14:49:23
2017
@@ -3548,7 +3548,7 @@
static NTSTATUS
SpiSendInquiry (IN PDEVICE_OBJECT DeviceObject,
- IN PSCSI_LUN_INFO LunInfo)
+ IN PSCSI_LUN_INFO LunInfo)
{
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION IrpStack;
@@ -3569,11 +3569,11 @@
DeviceExtension = (PSCSI_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
- InquiryBuffer = ExAllocatePoolWithTag (NonPagedPool, INQUIRYDATABUFFERSIZE,
TAG_SCSIPORT);
+ InquiryBuffer = ExAllocatePoolWithTag(NonPagedPool, INQUIRYDATABUFFERSIZE,
TAG_SCSIPORT);
if (InquiryBuffer == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
- SenseBuffer = ExAllocatePoolWithTag (NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT);
+ SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, SENSE_BUFFER_SIZE, TAG_SCSIPORT);
if (SenseBuffer == NULL)
{
ExFreePool(InquiryBuffer);
@@ -3589,14 +3589,14 @@
/* Create an IRP */
Irp = IoBuildDeviceIoControlRequest(IOCTL_SCSI_EXECUTE_IN,
- DeviceObject,
- NULL,
- 0,
- InquiryBuffer,
- INQUIRYDATABUFFERSIZE,
- TRUE,
- &Event,
- &IoStatusBlock);
+ DeviceObject,
+ NULL,
+ 0,
+ InquiryBuffer,
+ INQUIRYDATABUFFERSIZE,
+ TRUE,
+ &Event,
+ &IoStatusBlock);
if (Irp == NULL)
{
DPRINT("IoBuildDeviceIoControlRequest() failed\n");
@@ -3640,10 +3640,10 @@
{
DPRINT("SpiSendInquiry(): Waiting for the driver to process
request...\n");
KeWaitForSingleObject(&Event,
- Executive,
- KernelMode,
- FALSE,
- NULL);
+ Executive,
+ KernelMode,
+ FALSE,
+ NULL);
Status = IoStatusBlock.Status;
}
@@ -3658,84 +3658,85 @@
Status = STATUS_SUCCESS;
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
{
- DPRINT("Inquiry SRB failed with SrbStatus 0x%08X\n",
Srb.SrbStatus);
- /* Check if the queue is frozen */
- if (Srb.SrbStatus & SRB_STATUS_QUEUE_FROZEN)
+ /* Retry a couple of times if no timeout happened */
+ if ((RetryCount < 2) &&
+ (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) */
- 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;
+ RetryCount++;
+ KeepTrying = TRUE;
}
else
{
- /* Retry a couple of times if no timeout happened */
- if ((RetryCount < 2) &&
- (SRB_STATUS(Srb.SrbStatus) != SRB_STATUS_NO_DEVICE) &&
- (SRB_STATUS(Srb.SrbStatus) != SRB_STATUS_SELECTION_TIMEOUT))
+ /* That's all, go to exit */
+ 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)
{
- RetryCount++;
- KeepTrying = TRUE;
+ Status = STATUS_INVALID_DEVICE_REQUEST;
}
else
{
- /* That's all, go to exit */
- 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;
- }
+ Status = STATUS_IO_DEVICE_ERROR;
}
}
}
@@ -3968,7 +3969,7 @@
static NTSTATUS
SpiGetInquiryData(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
- PIRP Irp)
+ IN PIRP Irp)
{
ULONG InquiryDataSize;
PSCSI_LUN_INFO LunInfo;
@@ -5247,426 +5248,414 @@
}
/**********************************************************************
- * NAME INTERNAL
- * SpiBuildDeviceMap
+ * NAME INTERNAL
+ * SpiBuildDeviceMap
*
* DESCRIPTION
- * Builds the registry device map of all device which are attached
- * to the given SCSI HBA port. The device map is located at:
- * \Registry\Machine\DeviceMap\Scsi
+ * Builds the registry device map of all device which are attached
+ * to the given SCSI HBA port. The device map is located at:
+ * \Registry\Machine\DeviceMap\Scsi
*
* RUN LEVEL
- * PASSIVE_LEVEL
+ * PASSIVE_LEVEL
*
* ARGUMENTS
- * DeviceExtension
- * ...
+ * DeviceExtension
+ * ...
*
- * RegistryPath
- * Name of registry driver service key.
+ * RegistryPath
+ * Name of registry driver service key.
*
* RETURNS
- * NTSTATUS
+ * NTSTATUS
*/
static NTSTATUS
-SpiBuildDeviceMap (PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
- PUNICODE_STRING RegistryPath)
+SpiBuildDeviceMap(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
+ IN PUNICODE_STRING RegistryPath)
{
- PSCSI_PORT_LUN_EXTENSION LunExtension;
- OBJECT_ATTRIBUTES ObjectAttributes;
- UNICODE_STRING KeyName;
- UNICODE_STRING ValueName;
- WCHAR NameBuffer[64];
- ULONG Disposition;
- HANDLE ScsiKey;
- HANDLE ScsiPortKey = NULL;
- HANDLE ScsiBusKey = NULL;
- HANDLE ScsiInitiatorKey = NULL;
- HANDLE ScsiTargetKey = NULL;
- HANDLE ScsiLunKey = NULL;
- ULONG BusNumber;
- ULONG Target;
- ULONG CurrentTarget;
- ULONG Lun;
- PWCHAR DriverName;
- ULONG UlongData;
- PWCHAR TypeName;
- NTSTATUS Status;
-
- DPRINT("SpiBuildDeviceMap() called\n");
-
- if (DeviceExtension == NULL || RegistryPath == NULL)
- {
- DPRINT1("Invalid parameter\n");
- return(STATUS_INVALID_PARAMETER);
- }
-
- /* Open or create the 'Scsi' subkey */
- RtlInitUnicodeString(&KeyName,
- L"\\Registry\\Machine\\Hardware\\DeviceMap\\Scsi");
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_KERNEL_HANDLE,
- 0,
- NULL);
- Status = ZwCreateKey(&ScsiKey,
- KEY_ALL_ACCESS,
- &ObjectAttributes,
- 0,
- NULL,
- REG_OPTION_VOLATILE,
- &Disposition);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
- return(Status);
- }
-
- /* Create new 'Scsi Port X' subkey */
- DPRINT("Scsi Port %lu\n",
- DeviceExtension->PortNumber);
-
- swprintf(NameBuffer,
- L"Scsi Port %lu",
- DeviceExtension->PortNumber);
- RtlInitUnicodeString(&KeyName,
- NameBuffer);
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- OBJ_KERNEL_HANDLE,
- ScsiKey,
- NULL);
- Status = ZwCreateKey(&ScsiPortKey,
- KEY_ALL_ACCESS,
- &ObjectAttributes,
- 0,
- NULL,
- REG_OPTION_VOLATILE,
- &Disposition);
- ZwClose(ScsiKey);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
- return(Status);
- }
-
- /*
- * Create port-specific values
- */
-
- /* Set 'DMA Enabled' (REG_DWORD) value */
- UlongData = (ULONG)!DeviceExtension->PortCapabilities.AdapterUsesPio;
- DPRINT(" DMA Enabled = %s\n", (UlongData) ? "TRUE" :
"FALSE");
- RtlInitUnicodeString(&ValueName,
- L"DMA Enabled");
- Status = ZwSetValueKey(ScsiPortKey,
- &ValueName,
- 0,
- REG_DWORD,
- &UlongData,
- sizeof(ULONG));
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwSetValueKey('DMA Enabled') failed (Status %lx)\n",
Status);
- ZwClose(ScsiPortKey);
- return(Status);
- }
-
- /* Set 'Driver' (REG_SZ) value */
- DriverName = wcsrchr(RegistryPath->Buffer, L'\\') + 1;
- RtlInitUnicodeString(&ValueName,
- L"Driver");
- Status = ZwSetValueKey(ScsiPortKey,
- &ValueName,
- 0,
- REG_SZ,
- DriverName,
- (ULONG)((wcslen(DriverName) + 1) * sizeof(WCHAR)));
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwSetValueKey('Driver') failed (Status %lx)\n", Status);
- ZwClose(ScsiPortKey);
- return(Status);
- }
-
- /* Set 'Interrupt' (REG_DWORD) value (NT4 only) */
- UlongData = (ULONG)DeviceExtension->PortConfig->BusInterruptLevel;
- DPRINT(" Interrupt = %lu\n", UlongData);
- RtlInitUnicodeString(&ValueName,
- L"Interrupt");
- Status = ZwSetValueKey(ScsiPortKey,
- &ValueName,
- 0,
- REG_DWORD,
- &UlongData,
- sizeof(ULONG));
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwSetValueKey('Interrupt') failed (Status %lx)\n",
Status);
- ZwClose(ScsiPortKey);
- return(Status);
- }
-
- /* Set 'IOAddress' (REG_DWORD) value (NT4 only) */
- UlongData =
ScsiPortConvertPhysicalAddressToUlong((*DeviceExtension->PortConfig->AccessRanges)[0].RangeStart);
- DPRINT(" IOAddress = %lx\n", UlongData);
- RtlInitUnicodeString(&ValueName,
- L"IOAddress");
- Status = ZwSetValueKey(ScsiPortKey,
- &ValueName,
- 0,
- REG_DWORD,
- &UlongData,
- sizeof(ULONG));
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwSetValueKey('IOAddress') failed (Status %lx)\n",
Status);
- ZwClose(ScsiPortKey);
- return(Status);
- }
-
- /* Enumerate buses */
- for (BusNumber = 0; BusNumber < DeviceExtension->PortConfig->NumberOfBuses;
BusNumber++)
- {
- /* Create 'Scsi Bus X' key */
- DPRINT(" Scsi Bus %lu\n", BusNumber);
- swprintf(NameBuffer,
- L"Scsi Bus %lu",
- BusNumber);
- RtlInitUnicodeString(&KeyName,
- NameBuffer);
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- 0,
- ScsiPortKey,
- NULL);
- Status = ZwCreateKey(&ScsiBusKey,
- KEY_ALL_ACCESS,
- &ObjectAttributes,
- 0,
- NULL,
- REG_OPTION_VOLATILE,
- &Disposition);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
- goto ByeBye;
- }
-
- /* Create 'Initiator Id X' key */
- DPRINT(" Initiator Id %u\n",
- DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
- swprintf(NameBuffer,
- L"Initiator Id %u",
- (unsigned
int)(UCHAR)DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
- RtlInitUnicodeString(&KeyName,
- NameBuffer);
- InitializeObjectAttributes(&ObjectAttributes,
- &KeyName,
- 0,
- ScsiBusKey,
- NULL);
- Status = ZwCreateKey(&ScsiInitiatorKey,
- KEY_ALL_ACCESS,
- &ObjectAttributes,
- 0,
- NULL,
- REG_OPTION_VOLATILE,
- &Disposition);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
- goto ByeBye;
- }
-
- /* FIXME: Are there any initiator values (??) */
-
- ZwClose(ScsiInitiatorKey);
- ScsiInitiatorKey = NULL;
-
-
- /* Enumerate targets */
- CurrentTarget = (ULONG)-1;
- ScsiTargetKey = NULL;
- for (Target = 0; Target <
DeviceExtension->PortConfig->MaximumNumberOfTargets; Target++)
- {
- for (Lun = 0; Lun < SCSI_MAXIMUM_LOGICAL_UNITS; Lun++)
- {
- LunExtension = SpiGetLunExtension(DeviceExtension,
- (UCHAR)BusNumber,
- (UCHAR)Target,
- (UCHAR)Lun);
- if (LunExtension != NULL)
- {
- if (Target != CurrentTarget)
- {
- /* Close old target key */
- if (ScsiTargetKey != NULL)
- {
- ZwClose(ScsiTargetKey);
- ScsiTargetKey = NULL;
- }
-
- /* 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;
- }
-
- CurrentTarget = Target;
- }
-
- /* Create 'Logical Unit Id X' key */
- 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 */
- swprintf(NameBuffer,
- L"%.8S%.16S%.4S",
- LunExtension->InquiryData.VendorId,
- LunExtension->InquiryData.ProductId,
- LunExtension->InquiryData.ProductRevisionLevel);
- DPRINT(" Identifier = '%S'\n", NameBuffer);
- RtlInitUnicodeString(&ValueName,
- L"Identifier");
- Status = ZwSetValueKey(ScsiLunKey,
- &ValueName,
- 0,
- REG_SZ,
- NameBuffer,
- (ULONG)((wcslen(NameBuffer) + 1) * sizeof(WCHAR)));
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ZwSetValueKey('Identifier') failed (Status %lx)\n",
Status);
- goto ByeBye;
- }
-
- /* Set 'Type' (REG_SZ) value */
- 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;
- }
-
- ZwClose(ScsiLunKey);
- ScsiLunKey = NULL;
- }
- }
-
- /* Close old target key */
- if (ScsiTargetKey != NULL)
- {
- ZwClose(ScsiTargetKey);
- ScsiTargetKey = NULL;
- }
- }
-
- ZwClose(ScsiBusKey);
- ScsiBusKey = NULL;
+ PSCSI_PORT_LUN_EXTENSION LunExtension;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ UNICODE_STRING KeyName;
+ UNICODE_STRING ValueName;
+ WCHAR NameBuffer[64];
+ ULONG Disposition;
+ HANDLE ScsiKey;
+ HANDLE ScsiPortKey = NULL;
+ HANDLE ScsiBusKey = NULL;
+ HANDLE ScsiInitiatorKey = NULL;
+ HANDLE ScsiTargetKey = NULL;
+ HANDLE ScsiLunKey = NULL;
+ ULONG BusNumber;
+ ULONG Target;
+ ULONG CurrentTarget;
+ ULONG Lun;
+ PWCHAR DriverName;
+ ULONG UlongData;
+ PWCHAR TypeName;
+ NTSTATUS Status;
+
+ DPRINT("SpiBuildDeviceMap() called\n");
+
+ if (DeviceExtension == NULL || RegistryPath == NULL)
+ {
+ DPRINT1("Invalid parameter\n");
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ /* Open or create the 'Scsi' subkey */
+ RtlInitUnicodeString(&KeyName,
+ L"\\Registry\\Machine\\Hardware\\DeviceMap\\Scsi");
+ InitializeObjectAttributes(&ObjectAttributes,
+ &KeyName,
+ OBJ_CASE_INSENSITIVE | OBJ_OPENIF | OBJ_KERNEL_HANDLE,
+ 0,
+ NULL);
+ Status = ZwCreateKey(&ScsiKey,
+ KEY_ALL_ACCESS,
+ &ObjectAttributes,
+ 0,
+ NULL,
+ REG_OPTION_VOLATILE,
+ &Disposition);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
+ return Status;
+ }
+
+ /* Create new 'Scsi Port X' subkey */
+ DPRINT("Scsi Port %lu\n", DeviceExtension->PortNumber);
+
+ swprintf(NameBuffer,
+ L"Scsi Port %lu",
+ DeviceExtension->PortNumber);
+ RtlInitUnicodeString(&KeyName, NameBuffer);
+ InitializeObjectAttributes(&ObjectAttributes,
+ &KeyName,
+ OBJ_KERNEL_HANDLE,
+ ScsiKey,
+ NULL);
+ Status = ZwCreateKey(&ScsiPortKey,
+ KEY_ALL_ACCESS,
+ &ObjectAttributes,
+ 0,
+ NULL,
+ REG_OPTION_VOLATILE,
+ &Disposition);
+ ZwClose(ScsiKey);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
+ return Status;
+ }
+
+ /*
+ * Create port-specific values
+ */
+
+ /* Set 'DMA Enabled' (REG_DWORD) value */
+ UlongData = (ULONG)!DeviceExtension->PortCapabilities.AdapterUsesPio;
+ DPRINT(" DMA Enabled = %s\n", UlongData ? "TRUE" :
"FALSE");
+ RtlInitUnicodeString(&ValueName, L"DMA Enabled");
+ Status = ZwSetValueKey(ScsiPortKey,
+ &ValueName,
+ 0,
+ REG_DWORD,
+ &UlongData,
+ sizeof(UlongData));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwSetValueKey('DMA Enabled') failed (Status %lx)\n",
Status);
+ ZwClose(ScsiPortKey);
+ return Status;
+ }
+
+ /* Set 'Driver' (REG_SZ) value */
+ DriverName = wcsrchr(RegistryPath->Buffer, L'\\') + 1;
+ RtlInitUnicodeString(&ValueName, L"Driver");
+ Status = ZwSetValueKey(ScsiPortKey,
+ &ValueName,
+ 0,
+ REG_SZ,
+ DriverName,
+ (ULONG)((wcslen(DriverName) + 1) * sizeof(WCHAR)));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwSetValueKey('Driver') failed (Status %lx)\n",
Status);
+ ZwClose(ScsiPortKey);
+ return Status;
+ }
+
+ /* Set 'Interrupt' (REG_DWORD) value (NT4 only) */
+ UlongData = (ULONG)DeviceExtension->PortConfig->BusInterruptLevel;
+ DPRINT(" Interrupt = %lu\n", UlongData);
+ RtlInitUnicodeString(&ValueName, L"Interrupt");
+ Status = ZwSetValueKey(ScsiPortKey,
+ &ValueName,
+ 0,
+ REG_DWORD,
+ &UlongData,
+ sizeof(UlongData));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwSetValueKey('Interrupt') failed (Status %lx)\n",
Status);
+ ZwClose(ScsiPortKey);
+ return Status;
+ }
+
+ /* Set 'IOAddress' (REG_DWORD) value (NT4 only) */
+ UlongData =
ScsiPortConvertPhysicalAddressToUlong((*DeviceExtension->PortConfig->AccessRanges)[0].RangeStart);
+ DPRINT(" IOAddress = %lx\n", UlongData);
+ RtlInitUnicodeString(&ValueName, L"IOAddress");
+ Status = ZwSetValueKey(ScsiPortKey,
+ &ValueName,
+ 0,
+ REG_DWORD,
+ &UlongData,
+ sizeof(UlongData));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwSetValueKey('IOAddress') failed (Status %lx)\n",
Status);
+ ZwClose(ScsiPortKey);
+ return Status;
+ }
+
+ /* Enumerate buses */
+ for (BusNumber = 0; BusNumber < DeviceExtension->PortConfig->NumberOfBuses;
BusNumber++)
+ {
+ /* Create 'Scsi Bus X' key */
+ DPRINT(" Scsi Bus %lu\n", BusNumber);
+ swprintf(NameBuffer,
+ L"Scsi Bus %lu",
+ BusNumber);
+ RtlInitUnicodeString(&KeyName, NameBuffer);
+ InitializeObjectAttributes(&ObjectAttributes,
+ &KeyName,
+ 0,
+ ScsiPortKey,
+ NULL);
+ Status = ZwCreateKey(&ScsiBusKey,
+ KEY_ALL_ACCESS,
+ &ObjectAttributes,
+ 0,
+ NULL,
+ REG_OPTION_VOLATILE,
+ &Disposition);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
+ goto ByeBye;
+ }
+
+ /* Create 'Initiator Id X' key */
+ DPRINT(" Initiator Id %lu\n",
+ DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
+ swprintf(NameBuffer,
+ L"Initiator Id %lu",
+
(ULONG)(UCHAR)DeviceExtension->PortConfig->InitiatorBusId[BusNumber]);
+ RtlInitUnicodeString(&KeyName, NameBuffer);
+ InitializeObjectAttributes(&ObjectAttributes,
+ &KeyName,
+ 0,
+ ScsiBusKey,
+ NULL);
+ Status = ZwCreateKey(&ScsiInitiatorKey,
+ KEY_ALL_ACCESS,
+ &ObjectAttributes,
+ 0,
+ NULL,
+ REG_OPTION_VOLATILE,
+ &Disposition);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwCreateKey() failed (Status %lx)\n", Status);
+ goto ByeBye;
+ }
+
+ /* FIXME: Are there any initiator values (??) */
+
+ ZwClose(ScsiInitiatorKey);
+ ScsiInitiatorKey = NULL;
+
+
+ /* Enumerate targets */
+ CurrentTarget = (ULONG)-1;
+ ScsiTargetKey = NULL;
+ for (Target = 0; Target <
DeviceExtension->PortConfig->MaximumNumberOfTargets; Target++)
+ {
+ for (Lun = 0; Lun < SCSI_MAXIMUM_LOGICAL_UNITS; Lun++)
+ {
+ LunExtension = SpiGetLunExtension(DeviceExtension,
+ (UCHAR)BusNumber,
+ (UCHAR)Target,
+ (UCHAR)Lun);
+ if (LunExtension == NULL)
+ continue;
+
+ if (Target != CurrentTarget)
+ {
+ /* Close old target key */
+ if (ScsiTargetKey != NULL)
+ {
+ ZwClose(ScsiTargetKey);
+ ScsiTargetKey = NULL;
+ }
+
+ /* 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;
+ }
+
+ CurrentTarget = Target;
+ }
+
+ /* Create 'Logical Unit Id X' key */
+ 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 */
+ swprintf(NameBuffer,
+ L"%.8S%.16S%.4S",
+ LunExtension->InquiryData.VendorId,
+ LunExtension->InquiryData.ProductId,
+ LunExtension->InquiryData.ProductRevisionLevel);
+ DPRINT(" Identifier = '%S'\n", NameBuffer);
+ RtlInitUnicodeString(&ValueName, L"Identifier");
+ Status = ZwSetValueKey(ScsiLunKey,
+ &ValueName,
+ 0,
+ REG_SZ,
+ NameBuffer,
+ (ULONG)((wcslen(NameBuffer) + 1) *
sizeof(WCHAR)));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("ZwSetValueKey('Identifier') failed (Status
%lx)\n", Status);
+ goto ByeBye;
+ }
+
+ /* Set 'Type' (REG_SZ) value */
+ 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;
+ }
+
+ ZwClose(ScsiLunKey);
+ ScsiLunKey = NULL;
+ }
+
+ /* Close old target key */
+ if (ScsiTargetKey != NULL)
+ {
+ ZwClose(ScsiTargetKey);
+ ScsiTargetKey = NULL;
+ }
+ }
+
+ ZwClose(ScsiBusKey);
+ ScsiBusKey = NULL;
}
ByeBye:
- if (ScsiLunKey != NULL)
- ZwClose (ScsiLunKey);
-
- if (ScsiInitiatorKey != NULL)
- ZwClose (ScsiInitiatorKey);
-
- if (ScsiTargetKey != NULL)
- ZwClose (ScsiTargetKey);
-
- if (ScsiBusKey != NULL)
- ZwClose (ScsiBusKey);
-
- if (ScsiPortKey != NULL)
- ZwClose (ScsiPortKey);
-
- DPRINT("SpiBuildDeviceMap() done\n");
-
- return Status;
+ if (ScsiLunKey != NULL)
+ ZwClose(ScsiLunKey);
+
+ if (ScsiInitiatorKey != NULL)
+ ZwClose(ScsiInitiatorKey);
+
+ if (ScsiTargetKey != NULL)
+ ZwClose(ScsiTargetKey);
+
+ if (ScsiBusKey != NULL)
+ ZwClose(ScsiBusKey);
+
+ if (ScsiPortKey != NULL)
+ ZwClose(ScsiPortKey);
+
+ DPRINT("SpiBuildDeviceMap() done\n");
+
+ return Status;
}
VOID