Made NTFS-Partitions mountable.

svn path=/trunk/; revision=2980
This commit is contained in:
Eric Kohl 2002-05-25 13:32:51 +00:00
parent a9f79206fa
commit 9ca6cf1169
2 changed files with 219 additions and 217 deletions

View file

@ -1,4 +1,4 @@
/* $Id: disk.h,v 1.6 2001/06/28 02:42:27 rex Exp $ /* $Id: disk.h,v 1.7 2002/05/25 13:32:51 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -75,6 +75,7 @@
((P) == PTDOS3xPrimary || \ ((P) == PTDOS3xPrimary || \
(P) == PTOLDDOS16Bit || \ (P) == PTOLDDOS16Bit || \
(P) == PTDos5xPrimary || \ (P) == PTDos5xPrimary || \
(P) == PTIfs || \
(P) == PTWin95FAT32 || \ (P) == PTWin95FAT32 || \
(P) == PTWin95FAT32LBA || \ (P) == PTWin95FAT32LBA || \
(P) == PTWin95FAT16LBA || \ (P) == PTWin95FAT16LBA || \

View file

@ -1,4 +1,4 @@
/* $Id: xhaldrv.c,v 1.20 2002/04/26 19:58:48 ekohl Exp $ /* $Id: xhaldrv.c,v 1.21 2002/05/25 13:32:25 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -32,6 +32,7 @@
((P) == PTDOS3xPrimary || \ ((P) == PTDOS3xPrimary || \
(P) == PTOLDDOS16Bit || \ (P) == PTOLDDOS16Bit || \
(P) == PTDos5xPrimary || \ (P) == PTDos5xPrimary || \
(P) == PTIfs || \
(P) == PTWin95FAT32 || \ (P) == PTWin95FAT32 || \
(P) == PTWin95FAT32LBA || \ (P) == PTWin95FAT32LBA || \
(P) == PTWin95FAT16LBA) (P) == PTWin95FAT16LBA)
@ -309,159 +310,187 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
OUT PUCHAR NtSystemPath, OUT PUCHAR NtSystemPath,
OUT PSTRING NtSystemPathString) OUT PSTRING NtSystemPathString)
{ {
PDRIVE_LAYOUT_INFORMATION *LayoutArray; PDRIVE_LAYOUT_INFORMATION *LayoutArray;
PCONFIGURATION_INFORMATION ConfigInfo; PCONFIGURATION_INFORMATION ConfigInfo;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK StatusBlock; IO_STATUS_BLOCK StatusBlock;
UNICODE_STRING UnicodeString1; UNICODE_STRING UnicodeString1;
UNICODE_STRING UnicodeString2; UNICODE_STRING UnicodeString2;
HANDLE FileHandle; HANDLE FileHandle;
PWSTR Buffer1; PWSTR Buffer1;
PWSTR Buffer2; PWSTR Buffer2;
ULONG i; ULONG i;
NTSTATUS Status; NTSTATUS Status;
ULONG j; ULONG j;
DPRINT("xHalIoAssignDriveLetters()\n"); DPRINT("xHalIoAssignDriveLetters()\n");
ConfigInfo = IoGetConfigurationInformation (); ConfigInfo = IoGetConfigurationInformation();
Buffer1 = (PWSTR)ExAllocatePool(PagedPool, Buffer1 = (PWSTR)ExAllocatePool(PagedPool,
64 * sizeof(WCHAR)); 64 * sizeof(WCHAR));
Buffer2 = (PWSTR)ExAllocatePool(PagedPool, Buffer2 = (PWSTR)ExAllocatePool(PagedPool,
32 * sizeof(WCHAR)); 32 * sizeof(WCHAR));
/* Create PhysicalDrive links */ /* Create PhysicalDrive links */
DPRINT("Physical disk drives: %d\n", ConfigInfo->DiskCount); DPRINT("Physical disk drives: %d\n", ConfigInfo->DiskCount);
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
{ {
swprintf(Buffer1, swprintf(Buffer1,
L"\\Device\\Harddisk%d\\Partition0", L"\\Device\\Harddisk%d\\Partition0",
i); i);
RtlInitUnicodeString(&UnicodeString1, RtlInitUnicodeString(&UnicodeString1,
Buffer1); Buffer1);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&UnicodeString1, &UnicodeString1,
0, 0,
NULL, NULL,
NULL); NULL);
Status = NtOpenFile(&FileHandle, Status = NtOpenFile(&FileHandle,
0x10001, 0x10001,
&ObjectAttributes, &ObjectAttributes,
&StatusBlock, &StatusBlock,
1, 1,
FILE_SYNCHRONOUS_IO_NONALERT); FILE_SYNCHRONOUS_IO_NONALERT);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
NtClose(FileHandle); NtClose(FileHandle);
swprintf(Buffer2, swprintf(Buffer2,
L"\\??\\PhysicalDrive%d", L"\\??\\PhysicalDrive%d",
i); i);
RtlInitUnicodeString(&UnicodeString2, RtlInitUnicodeString(&UnicodeString2,
Buffer2); Buffer2);
DPRINT("Creating link: %S ==> %S\n", DPRINT("Creating link: %S ==> %S\n",
Buffer2, Buffer2,
Buffer1); Buffer1);
IoCreateSymbolicLink(&UnicodeString2, IoCreateSymbolicLink(&UnicodeString2,
&UnicodeString1); &UnicodeString1);
} }
} }
/* Initialize layout array */ /* Initialize layout array */
LayoutArray = ExAllocatePool(NonPagedPool, LayoutArray = ExAllocatePool(NonPagedPool,
ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION)); ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION));
RtlZeroMemory(LayoutArray, RtlZeroMemory(LayoutArray,
ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION)); ConfigInfo->DiskCount * sizeof(PDRIVE_LAYOUT_INFORMATION));
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
{ {
swprintf(Buffer1, swprintf(Buffer1,
L"\\Device\\Harddisk%d\\Partition0", L"\\Device\\Harddisk%d\\Partition0",
i); i);
RtlInitUnicodeString(&UnicodeString1, RtlInitUnicodeString(&UnicodeString1,
Buffer1); Buffer1);
Status = xHalQueryDriveLayout(&UnicodeString1, Status = xHalQueryDriveLayout(&UnicodeString1,
&LayoutArray[i]); &LayoutArray[i]);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("xHalpQueryDriveLayout() failed (Status = 0x%lx)\n", DbgPrint("xHalpQueryDriveLayout() failed (Status = 0x%lx)\n",
Status); Status);
LayoutArray[i] = NULL; LayoutArray[i] = NULL;
continue; continue;
} }
} }
#ifndef NDEBUG #ifndef NDEBUG
/* Dump layout array */ /* Dump layout array */
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
{ {
DPRINT("Harddisk %d:\n", DPRINT("Harddisk %d:\n",
i); i);
if (LayoutArray[i] == NULL) if (LayoutArray[i] == NULL)
continue; continue;
DPRINT("Logical partitions: %d\n", DPRINT("Logical partitions: %d\n",
LayoutArray[i]->PartitionCount); LayoutArray[i]->PartitionCount);
for (j = 0; j < LayoutArray[i]->PartitionCount; j++) for (j = 0; j < LayoutArray[i]->PartitionCount; j++)
{ {
DPRINT(" %d: nr:%x boot:%x type:%x startblock:%I64u count:%I64u\n", DPRINT(" %d: nr:%x boot:%x type:%x startblock:%I64u count:%I64u\n",
j, j,
LayoutArray[i]->PartitionEntry[j].PartitionNumber, LayoutArray[i]->PartitionEntry[j].PartitionNumber,
LayoutArray[i]->PartitionEntry[j].BootIndicator, LayoutArray[i]->PartitionEntry[j].BootIndicator,
LayoutArray[i]->PartitionEntry[j].PartitionType, LayoutArray[i]->PartitionEntry[j].PartitionType,
LayoutArray[i]->PartitionEntry[j].StartingOffset.QuadPart, LayoutArray[i]->PartitionEntry[j].StartingOffset.QuadPart,
LayoutArray[i]->PartitionEntry[j].PartitionLength.QuadPart); LayoutArray[i]->PartitionEntry[j].PartitionLength.QuadPart);
} }
} }
#endif #endif
/* Assign pre-assigned (registry) partitions */ /* Assign pre-assigned (registry) partitions */
/* Assign bootable partition on first harddisk */ /* Assign bootable partition on first harddisk */
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) &&
IsUsablePartition(LayoutArray[0]->PartitionEntry[j].PartitionType)) IsUsablePartition(LayoutArray[0]->PartitionEntry[j].PartitionType))
{ {
swprintf(Buffer2, swprintf(Buffer2,
L"\\Device\\Harddisk0\\Partition%d", L"\\Device\\Harddisk0\\Partition%d",
LayoutArray[0]->PartitionEntry[j].PartitionNumber); LayoutArray[0]->PartitionEntry[j].PartitionNumber);
RtlInitUnicodeString(&UnicodeString2, RtlInitUnicodeString(&UnicodeString2,
Buffer2); Buffer2);
DPRINT(" %wZ\n", &UnicodeString2); /* assign it */
DPRINT(" %wZ\n", &UnicodeString2);
HalpAssignDrive(&UnicodeString2,
AUTO_DRIVE,
DOSDEVICE_DRIVE_FIXED);
}
}
}
/* assign it */ /* Assign remaining primary partitions */
HalpAssignDrive(&UnicodeString2, DPRINT("Assigning remaining primary partitions:\n");
AUTO_DRIVE, for (i = 0; i < ConfigInfo->DiskCount; i++)
DOSDEVICE_DRIVE_FIXED); {
} /* search for primary partitions */
} for (j = 0; j < PARTITION_TBL_SIZE; j++)
} {
if (!(i == 0 &&
LayoutArray[i]->PartitionEntry[j].BootIndicator == TRUE) &&
IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType))
{
swprintf(Buffer2,
L"\\Device\\Harddisk%d\\Partition%d",
i,
LayoutArray[i]->PartitionEntry[j].PartitionNumber);
RtlInitUnicodeString(&UnicodeString2,
Buffer2);
/* Assign remaining primary partitions */ /* assign it */
DPRINT("Assigning remaining primary partitions:\n"); DPRINT(" %wZ\n",
for (i = 0; i < ConfigInfo->DiskCount; i++) &UnicodeString2);
{ HalpAssignDrive(&UnicodeString2,
/* search for primary partitions */ AUTO_DRIVE,
for (j = 0; j < PARTITION_TBL_SIZE; j++) DOSDEVICE_DRIVE_FIXED);
{ }
if (!(i == 0 && }
LayoutArray[i]->PartitionEntry[j].BootIndicator == TRUE) && }
IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType))
{ /* Assign extended (logical) partitions */
DPRINT("Assigning extended (logical) partitions:\n");
for (i = 0; i < ConfigInfo->DiskCount; i++)
{
if (LayoutArray[i])
{
/* search for extended partitions */
for (j = PARTITION_TBL_SIZE; j < LayoutArray[i]->PartitionCount; j++)
{
if (IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType) &&
(LayoutArray[i]->PartitionEntry[j].PartitionNumber != 0))
{
swprintf(Buffer2, swprintf(Buffer2,
L"\\Device\\Harddisk%d\\Partition%d", L"\\Device\\Harddisk%d\\Partition%d",
i, i,
@ -475,45 +504,17 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
HalpAssignDrive(&UnicodeString2, HalpAssignDrive(&UnicodeString2,
AUTO_DRIVE, AUTO_DRIVE,
DOSDEVICE_DRIVE_FIXED); DOSDEVICE_DRIVE_FIXED);
}
}
}
/* Assign extended (logical) partitions */
DPRINT("Assigning extended (logical) partitions:\n");
for (i = 0; i < ConfigInfo->DiskCount; i++)
{
if( LayoutArray[i] ){
/* search for extended partitions */
for (j = PARTITION_TBL_SIZE; j < LayoutArray[i]->PartitionCount; j++)
{
if (IsUsablePartition(LayoutArray[i]->PartitionEntry[j].PartitionType) &&
(LayoutArray[i]->PartitionEntry[j].PartitionNumber != 0))
{
swprintf(Buffer2,
L"\\Device\\Harddisk%d\\Partition%d",
i,
LayoutArray[i]->PartitionEntry[j].PartitionNumber);
RtlInitUnicodeString(&UnicodeString2,
Buffer2);
/* assign it */
DPRINT(" %wZ\n",
&UnicodeString2);
HalpAssignDrive(&UnicodeString2,
AUTO_DRIVE,
DOSDEVICE_DRIVE_FIXED);
}
}
} }
} }
}
}
#if 0 #if 0
/* TEST */ /* TEST */
/* Assign removable disk drives */ /* Assign removable disk drives */
DPRINT("Assigning extended (logical) partitions:\n"); DPRINT("Assigning extended (logical) partitions:\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)
@ -531,58 +532,58 @@ xHalIoAssignDriveLetters(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
AUTO_DRIVE, AUTO_DRIVE,
DOSDEVICE_DRIVE_REMOVABLE); DOSDEVICE_DRIVE_REMOVABLE);
} }
} }
/* TEST END */ /* TEST END */
#endif #endif
/* Free layout array */ /* Free layout array */
for (i = 0; i < ConfigInfo->DiskCount; i++) for (i = 0; i < ConfigInfo->DiskCount; i++)
{ {
if (LayoutArray[i] != NULL) if (LayoutArray[i] != NULL)
ExFreePool(LayoutArray[i]); ExFreePool(LayoutArray[i]);
} }
ExFreePool(LayoutArray); ExFreePool(LayoutArray);
/* Assign floppy drives */ /* Assign floppy drives */
DPRINT("Floppy drives: %d\n", ConfigInfo->FloppyCount); DPRINT("Floppy drives: %d\n", ConfigInfo->FloppyCount);
for (i = 0; i < ConfigInfo->FloppyCount; i++) for (i = 0; i < ConfigInfo->FloppyCount; i++)
{ {
swprintf(Buffer1, swprintf(Buffer1,
L"\\Device\\Floppy%d", L"\\Device\\Floppy%d",
i); i);
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,
(i < 2) ? i : AUTO_DRIVE, (i < 2) ? i : AUTO_DRIVE,
DOSDEVICE_DRIVE_REMOVABLE); DOSDEVICE_DRIVE_REMOVABLE);
} }
/* Assign cdrom drives */ /* Assign cdrom drives */
DPRINT("CD-Rom drives: %d\n", ConfigInfo->CDRomCount); DPRINT("CD-Rom drives: %d\n", ConfigInfo->CDRomCount);
for (i = 0; i < ConfigInfo->CDRomCount; i++) for (i = 0; i < ConfigInfo->CDRomCount; i++)
{ {
swprintf(Buffer1, swprintf(Buffer1,
L"\\Device\\CdRom%d", L"\\Device\\CdRom%d",
i); i);
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,
DOSDEVICE_DRIVE_CDROM); DOSDEVICE_DRIVE_CDROM);
} }
/* Anything else ?? */ /* Anything else ?? */
ExFreePool(Buffer2); ExFreePool(Buffer2);
ExFreePool(Buffer1); ExFreePool(Buffer1);
} }
@ -694,7 +695,7 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
PartitionTable->Partition[i].StartingHead, PartitionTable->Partition[i].StartingHead,
PartitionTable->Partition[i].StartingSector & 0x3f, PartitionTable->Partition[i].StartingSector & 0x3f,
(((PartitionTable->Partition[i].StartingSector) & 0xc0) << 2) + (((PartitionTable->Partition[i].StartingSector) & 0xc0) << 2) +
PartitionTable->Partition[i].StartingCylinder, PartitionTable->Partition[i].StartingCylinder,
PartitionTable->Partition[i].EndingHead, PartitionTable->Partition[i].EndingHead,
PartitionTable->Partition[i].EndingSector, PartitionTable->Partition[i].EndingSector,
PartitionTable->Partition[i].EndingCylinder, PartitionTable->Partition[i].EndingCylinder,
@ -780,13 +781,13 @@ xHalIoReadPartitionTable(PDEVICE_OBJECT DeviceObject,
if (IsExtendedPartition(PartitionTable->Partition[i].PartitionType)) if (IsExtendedPartition(PartitionTable->Partition[i].PartitionType))
{ {
ExtendedFound = TRUE; ExtendedFound = TRUE;
if ((ULONGLONG) containerOffset.QuadPart == (ULONGLONG) 0) if ((ULONGLONG) containerOffset.QuadPart == (ULONGLONG) 0)
{ {
containerOffset = PartitionOffset; containerOffset = PartitionOffset;
} }
nextPartitionOffset.QuadPart = (ULONGLONG) containerOffset.QuadPart + nextPartitionOffset.QuadPart = (ULONGLONG) containerOffset.QuadPart +
(ULONGLONG) PartitionTable->Partition[i].StartingBlock * (ULONGLONG) PartitionTable->Partition[i].StartingBlock *
(ULONGLONG) SectorSize; (ULONGLONG) SectorSize;
} }
} }
PartitionOffset = nextPartitionOffset; PartitionOffset = nextPartitionOffset;
@ -805,7 +806,7 @@ xHalIoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject,
IN ULONG PartitionNumber, IN ULONG PartitionNumber,
IN ULONG PartitionType) IN ULONG PartitionType)
{ {
return STATUS_NOT_IMPLEMENTED; return(STATUS_NOT_IMPLEMENTED);
} }
@ -816,7 +817,7 @@ xHalIoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject,
IN ULONG NumberOfHeads, IN ULONG NumberOfHeads,
IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer) IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
{ {
return STATUS_NOT_IMPLEMENTED; return(STATUS_NOT_IMPLEMENTED);
} }
/* EOF */ /* EOF */