Enabled driver letter assignment for removable drives.

svn path=/trunk/; revision=2981
This commit is contained in:
Eric Kohl 2002-05-26 20:18:18 +00:00
parent 9ca6cf1169
commit 32e8099716

View file

@ -1,4 +1,4 @@
/* $Id: xhaldrv.c,v 1.21 2002/05/25 13:32:25 ekohl Exp $ /* $Id: xhaldrv.c,v 1.22 2002/05/26 20:18:18 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -64,73 +64,80 @@ NTSTATUS
xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName, xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName,
OUT PDRIVE_LAYOUT_INFORMATION *LayoutInfo) OUT PDRIVE_LAYOUT_INFORMATION *LayoutInfo)
{ {
IO_STATUS_BLOCK StatusBlock; IO_STATUS_BLOCK StatusBlock;
DISK_GEOMETRY DiskGeometry; DISK_GEOMETRY DiskGeometry;
PDEVICE_OBJECT DeviceObject = NULL; PDEVICE_OBJECT DeviceObject = NULL;
PFILE_OBJECT FileObject; PFILE_OBJECT FileObject;
KEVENT Event; KEVENT Event;
PIRP Irp; PIRP Irp;
NTSTATUS Status; NTSTATUS Status;
DPRINT("xHalpQueryDriveLayout %wZ %p\n", DPRINT("xHalpQueryDriveLayout %wZ %p\n",
DeviceName, DeviceName,
LayoutInfo); LayoutInfo);
/* Get the drives sector size */ /* Get the drives sector size */
Status = IoGetDeviceObjectPointer(DeviceName, Status = IoGetDeviceObjectPointer(DeviceName,
FILE_READ_DATA, FILE_READ_DATA,
&FileObject, &FileObject,
&DeviceObject); &DeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Status %x\n",Status); DPRINT("Status %x\n",Status);
return Status; return(Status);
} }
KeInitializeEvent(&Event, KeInitializeEvent(&Event,
NotificationEvent, NotificationEvent,
FALSE); FALSE);
Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY, Irp = IoBuildDeviceIoControlRequest(IOCTL_DISK_GET_DRIVE_GEOMETRY,
DeviceObject, DeviceObject,
NULL, NULL,
0, 0,
&DiskGeometry, &DiskGeometry,
sizeof(DISK_GEOMETRY), sizeof(DISK_GEOMETRY),
FALSE, FALSE,
&Event, &Event,
&StatusBlock); &StatusBlock);
if (Irp == NULL) if (Irp == NULL)
{ {
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return STATUS_INSUFFICIENT_RESOURCES; return(STATUS_INSUFFICIENT_RESOURCES);
} }
Status = IoCallDriver(DeviceObject, Status = IoCallDriver(DeviceObject,
Irp); Irp);
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
KeWaitForSingleObject(&Event, KeWaitForSingleObject(&Event,
Executive, Executive,
KernelMode, KernelMode,
FALSE, FALSE,
NULL); NULL);
Status = StatusBlock.Status; Status = StatusBlock.Status;
} }
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ObDereferenceObject(FileObject); if (DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA)
return Status; {
} DiskGeometry.BytesPerSector = 512;
}
else
{
ObDereferenceObject(FileObject);
return(Status);
}
}
DPRINT("DiskGeometry.BytesPerSector: %d\n", DPRINT("DiskGeometry.BytesPerSector: %d\n",
DiskGeometry.BytesPerSector); DiskGeometry.BytesPerSector);
/* read the partition table */ /* read the partition table */
Status = IoReadPartitionTable(DeviceObject, Status = IoReadPartitionTable(DeviceObject,
DiskGeometry.BytesPerSector, DiskGeometry.BytesPerSector,
FALSE, FALSE,
LayoutInfo); LayoutInfo);
if ((!NT_SUCCESS(Status) || (*LayoutInfo)->PartitionCount == 0) && if ((!NT_SUCCESS(Status) || (*LayoutInfo)->PartitionCount == 0) &&
DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) DeviceObject->Characteristics & FILE_REMOVABLE_MEDIA)
@ -156,9 +163,9 @@ xHalQueryDriveLayout(IN PUNICODE_STRING DeviceName,
} }
} }
ObDereferenceObject(FileObject); ObDereferenceObject(FileObject);
return Status; return(Status);
} }
@ -390,7 +397,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
&LayoutArray[i]); &LayoutArray[i]);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("xHalpQueryDriveLayout() failed (Status = 0x%lx)\n", DbgPrint("xHalQueryDriveLayout() failed (Status = 0x%lx)\n",
Status); Status);
LayoutArray[i] = NULL; LayoutArray[i] = NULL;
continue; continue;
@ -430,7 +437,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
DPRINT("Assigning bootable primary partition on first harddisk:\n"); DPRINT("Assigning bootable primary partition on first harddisk:\n");
if (ConfigInfo->DiskCount > 0) if (ConfigInfo->DiskCount > 0)
{ {
/* search for bootable partition */ /* Search for bootable partition */
for (j = 0; j < LayoutArray[0]->PartitionCount; j++) for (j = 0; j < LayoutArray[0]->PartitionCount; j++)
{ {
if ((LayoutArray[0]->PartitionEntry[j].BootIndicator == TRUE) && if ((LayoutArray[0]->PartitionEntry[j].BootIndicator == TRUE) &&
@ -442,7 +449,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
RtlInitUnicodeString(&UnicodeString2, RtlInitUnicodeString(&UnicodeString2,
Buffer2); Buffer2);
/* assign it */ /* Assign drive */
DPRINT(" %wZ\n", &UnicodeString2); DPRINT(" %wZ\n", &UnicodeString2);
HalpAssignDrive(&UnicodeString2, HalpAssignDrive(&UnicodeString2,
AUTO_DRIVE, AUTO_DRIVE,
@ -455,12 +462,13 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
DPRINT("Assigning remaining primary partitions:\n"); DPRINT("Assigning remaining primary partitions:\n");
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
{ {
/* search for primary partitions */ /* Search for primary partitions */
for (j = 0; j < PARTITION_TBL_SIZE; j++) for (j = 0; (j < PARTITION_TBL_SIZE) && (j < LayoutArray[i]->PartitionCount); j++)
{ {
if (!(i == 0 && if ((i == 0) && (LayoutArray[i]->PartitionEntry[j].BootIndicator == TRUE))
LayoutArray[i]->PartitionEntry[j].BootIndicator == TRUE) && continue;
IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType))
if (IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType))
{ {
swprintf(Buffer2, swprintf(Buffer2,
L"\\Device\\Harddisk%d\\Partition%d", L"\\Device\\Harddisk%d\\Partition%d",
@ -469,7 +477,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
RtlInitUnicodeString(&UnicodeString2, RtlInitUnicodeString(&UnicodeString2,
Buffer2); Buffer2);
/* assign it */ /* Assign drive */
DPRINT(" %wZ\n", DPRINT(" %wZ\n",
&UnicodeString2); &UnicodeString2);
HalpAssignDrive(&UnicodeString2, HalpAssignDrive(&UnicodeString2,
@ -485,7 +493,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
{ {
if (LayoutArray[i]) if (LayoutArray[i])
{ {
/* search for extended partitions */ /* Search for extended partitions */
for (j = PARTITION_TBL_SIZE; j < LayoutArray[i]->PartitionCount; j++) for (j = PARTITION_TBL_SIZE; j < LayoutArray[i]->PartitionCount; j++)
{ {
if (IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType) && if (IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType) &&
@ -498,7 +506,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
RtlInitUnicodeString(&UnicodeString2, RtlInitUnicodeString(&UnicodeString2,
Buffer2); Buffer2);
/* assign it */ /* Assign drive */
DPRINT(" %wZ\n", DPRINT(" %wZ\n",
&UnicodeString2); &UnicodeString2);
HalpAssignDrive(&UnicodeString2, HalpAssignDrive(&UnicodeString2,
@ -509,32 +517,28 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
} }
} }
#if 0
/* TEST */
/* Assign removable disk drives */ /* Assign removable disk drives */
DPRINT("Assigning extended (logical) partitions:\n"); DPRINT("Assigning removable disk drives:\n");
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
{ {
/* Search for virtual partitions */ /* Search for virtual partitions */
if (LayoutArray[i]->PartitionCount == 1 && if (LayoutArray[i]->PartitionCount == 1 &&
LayoutArray[i]->PartitionEntry[0].PartitionType == 0) LayoutArray[i]->PartitionEntry[0].PartitionType == 0)
{ {
swprintf(Buffer2, swprintf(Buffer2,
L"\\Device\\Harddisk%d\\Partition1", L"\\Device\\Harddisk%d\\Partition1",
i); i);
RtlInitUnicodeString(&UnicodeString2, RtlInitUnicodeString(&UnicodeString2,
Buffer2); Buffer2);
/* assign it */ /* Assign drive */
DPRINT(" %wZ\n", DPRINT(" %wZ\n",
&UnicodeString2); &UnicodeString2);
HalpAssignDrive(&UnicodeString2, HalpAssignDrive(&UnicodeString2,
AUTO_DRIVE, AUTO_DRIVE,
DOSDEVICE_DRIVE_REMOVABLE); DOSDEVICE_DRIVE_REMOVABLE);
} }
} }
/* TEST END */
#endif
/* Free layout array */ /* Free layout array */
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
@ -554,7 +558,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
RtlInitUnicodeString(&UnicodeString1, RtlInitUnicodeString(&UnicodeString1,
Buffer1); Buffer1);
/* assign drive letters A: or B: or first free drive letter */ /* Assign drive letters A: or B: or first free drive letter */
DPRINT(" %wZ\n", DPRINT(" %wZ\n",
&UnicodeString1); &UnicodeString1);
HalpAssignDrive(&UnicodeString1, HalpAssignDrive(&UnicodeString1,
@ -572,7 +576,7 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
RtlInitUnicodeString(&UnicodeString1, RtlInitUnicodeString(&UnicodeString1,
Buffer1); Buffer1);
/* assign first free drive letter */ /* Assign first free drive letter */
DPRINT(" %wZ\n", &UnicodeString1); DPRINT(" %wZ\n", &UnicodeString1);
HalpAssignDrive(&UnicodeString1, HalpAssignDrive(&UnicodeString1,
AUTO_DRIVE, AUTO_DRIVE,
@ -581,7 +585,6 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
/* Anything else ?? */ /* Anything else ?? */
ExFreePool(Buffer2); ExFreePool(Buffer2);
ExFreePool(Buffer1); ExFreePool(Buffer1);
} }
@ -666,11 +669,11 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("xHalIoReadPartitonTable failed (Status = 0x%08lx)\n", DPRINT("Failed to read partition table sector (Status = 0x%08lx)\n",
Status); Status);
ExFreePool(SectorBuffer); ExFreePool(SectorBuffer);
ExFreePool(LayoutBuffer); ExFreePool(LayoutBuffer);
return Status; return(Status);
} }
PartitionTable = (PPARTITION_TABLE)(SectorBuffer+PARTITION_OFFSET); PartitionTable = (PPARTITION_TABLE)(SectorBuffer+PARTITION_OFFSET);
@ -800,6 +803,7 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
NTSTATUS FASTCALL NTSTATUS FASTCALL
xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
IN ULONG SectorSize, IN ULONG SectorSize,