First part of the partition management code rewrite. This part fixes the handling of primary partitions. Extended partitions and logical drives are not handled yet. Safety checks and warnings are still missing! Partitions created by the new code are accepted by gparted and Windows.


svn path=/trunk/; revision=63355
This commit is contained in:
Eric Kohl 2014-05-18 15:14:24 +00:00
parent 9e6083e5c2
commit 005d881ce1
4 changed files with 953 additions and 1244 deletions

View file

@ -1444,7 +1444,6 @@ InstallFat16BootCodeToDisk(
NTSTATUS Status; NTSTATUS Status;
PFAT_BOOTSECTOR OrigBootSector; PFAT_BOOTSECTOR OrigBootSector;
PFAT_BOOTSECTOR NewBootSector; PFAT_BOOTSECTOR NewBootSector;
PARTITION_INFORMATION *PartInfo;
/* Allocate buffer for original bootsector */ /* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE); OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
@ -1543,8 +1542,7 @@ InstallFat16BootCodeToDisk(
FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) - FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
FIELD_OFFSET(FAT_BOOTSECTOR, OemName)); FIELD_OFFSET(FAT_BOOTSECTOR, OemName));
PartInfo = &PartitionList->CurrentPartition->PartInfo[PartitionList->CurrentPartitionNumber]; NewBootSector->HiddenSectors = PartitionList->CurrentDisk->SectorsPerTrack;
NewBootSector->HiddenSectors = PartInfo->HiddenSectors;
/* Free the original boot sector */ /* Free the original boot sector */
RtlFreeHeap(ProcessHeap, 0, OrigBootSector); RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
@ -1606,7 +1604,6 @@ InstallFat32BootCodeToDisk(
PFAT32_BOOTSECTOR NewBootSector; PFAT32_BOOTSECTOR NewBootSector;
LARGE_INTEGER FileOffset; LARGE_INTEGER FileOffset;
USHORT BackupBootSector; USHORT BackupBootSector;
PARTITION_INFORMATION *PartInfo;
/* Allocate buffer for original bootsector */ /* Allocate buffer for original bootsector */
OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE); OrigBootSector = RtlAllocateHeap(ProcessHeap, 0, SECTORSIZE);
@ -1704,8 +1701,7 @@ InstallFat32BootCodeToDisk(
FIELD_OFFSET(FAT32_BOOTSECTOR, BootCodeAndData) - FIELD_OFFSET(FAT32_BOOTSECTOR, BootCodeAndData) -
FIELD_OFFSET(FAT32_BOOTSECTOR, OemName)); FIELD_OFFSET(FAT32_BOOTSECTOR, OemName));
PartInfo = &PartitionList->CurrentPartition->PartInfo[PartitionList->CurrentPartitionNumber]; NewBootSector->HiddenSectors = PartitionList->CurrentDisk->SectorsPerTrack;
NewBootSector->HiddenSectors = PartInfo->HiddenSectors;
/* Get the location of the backup boot sector */ /* Get the location of the backup boot sector */
BackupBootSector = OrigBootSector->BackupBootSector; BackupBootSector = OrigBootSector->BackupBootSector;

View file

@ -1428,6 +1428,7 @@ LayoutSettingsPage(PINPUT_RECORD Ir)
} }
#if 0
static BOOL static BOOL
IsDiskSizeValid(PPARTENTRY PartEntry) IsDiskSizeValid(PPARTENTRY PartEntry)
{ {
@ -1456,6 +1457,7 @@ IsDiskSizeValid(PPARTENTRY PartEntry)
return TRUE; return TRUE;
} }
} }
#endif
static PAGE_NUMBER static PAGE_NUMBER
@ -1512,32 +1514,32 @@ SelectPartitionPage(PINPUT_RECORD Ir)
{ {
if (AutoPartition) if (AutoPartition)
{ {
PPARTENTRY PartEntry = PartitionList->CurrentPartition; #if 0
ULONG MaxSize = (PartEntry->UnpartitionedLength + (1 << 19)) >> 20; /* in MBytes (rounded) */ if (!IsDiskSizeValid(PartitionList->CurrentPartition))
if(!IsDiskSizeValid(PartitionList->CurrentPartition))
{ {
MUIDisplayError(ERROR_INSUFFICIENT_DISKSPACE, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(ERROR_INSUFFICIENT_DISKSPACE, Ir, POPUP_WAIT_ANY_KEY);
return SELECT_PARTITION_PAGE; /* let the user select another partition */ return SELECT_PARTITION_PAGE; /* let the user select another partition */
} }
#endif
CreateNewPartition(PartitionList, CreateNewPartition(PartitionList,
MaxSize, PartitionList->CurrentPartition->SectorCount.QuadPart,
TRUE); TRUE);
DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter[0]; DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter;
return SELECT_FILE_SYSTEM_PAGE; return SELECT_FILE_SYSTEM_PAGE;
} }
} }
else else
{ {
if(!IsDiskSizeValid(PartitionList->CurrentPartition)) #if 0
if (!IsDiskSizeValid(PartitionList->CurrentPartition))
{ {
MUIDisplayError(ERROR_INSUFFICIENT_DISKSPACE, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(ERROR_INSUFFICIENT_DISKSPACE, Ir, POPUP_WAIT_ANY_KEY);
return SELECT_PARTITION_PAGE; /* let the user select another partition */ return SELECT_PARTITION_PAGE; /* let the user select another partition */
} }
#endif
DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter[0]; DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter;
return SELECT_FILE_SYSTEM_PAGE; return SELECT_FILE_SYSTEM_PAGE;
} }
@ -1547,7 +1549,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
{ {
/* Update status text */ /* Update status text */
if (PartitionList->CurrentPartition == NULL || if (PartitionList->CurrentPartition == NULL ||
PartitionList->CurrentPartition->Unpartitioned == TRUE) PartitionList->CurrentPartition->IsPartitioned == FALSE)
{ {
CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION));
} }
@ -1582,26 +1584,28 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
{ {
if(!IsDiskSizeValid(PartitionList->CurrentPartition)) #if 0
if (!IsDiskSizeValid(PartitionList->CurrentPartition))
{ {
MUIDisplayError(ERROR_INSUFFICIENT_DISKSPACE, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(ERROR_INSUFFICIENT_DISKSPACE, Ir, POPUP_WAIT_ANY_KEY);
return SELECT_PARTITION_PAGE; /* let the user select another partition */ return SELECT_PARTITION_PAGE; /* let the user select another partition */
} }
#endif
if (PartitionList->CurrentPartition == NULL || if (PartitionList->CurrentPartition == NULL ||
PartitionList->CurrentPartition->Unpartitioned == TRUE) PartitionList->CurrentPartition->IsPartitioned == FALSE)
{ {
CreateNewPartition(PartitionList, CreateNewPartition(PartitionList,
0ULL, 0ULL,
TRUE); TRUE);
} }
DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter[0]; DestinationDriveLetter = (WCHAR)PartitionList->CurrentPartition->DriveLetter;
return SELECT_FILE_SYSTEM_PAGE; return SELECT_FILE_SYSTEM_PAGE;
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'C') /* C */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'C') /* C */
{ {
if (PartitionList->CurrentPartition->Unpartitioned == FALSE) if (PartitionList->CurrentPartition->IsPartitioned == TRUE)
{ {
MUIDisplayError(ERROR_NEW_PARTITION, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(ERROR_NEW_PARTITION, Ir, POPUP_WAIT_ANY_KEY);
return SELECT_PARTITION_PAGE; return SELECT_PARTITION_PAGE;
@ -1611,7 +1615,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */
{ {
if (PartitionList->CurrentPartition->Unpartitioned == TRUE) if (PartitionList->CurrentPartition->IsPartitioned == FALSE)
{ {
MUIDisplayError(ERROR_DELETE_SPACE, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(ERROR_DELETE_SPACE, Ir, POPUP_WAIT_ANY_KEY);
return SELECT_PARTITION_PAGE; return SELECT_PARTITION_PAGE;
@ -1779,6 +1783,7 @@ CreatePartitionPage(PINPUT_RECORD Ir)
ULONG MaxSize; ULONG MaxSize;
ULONGLONG PartSize; ULONGLONG PartSize;
ULONGLONG DiskSize; ULONGLONG DiskSize;
ULONGLONG SectorCount;
PCHAR Unit; PCHAR Unit;
if (PartitionList == NULL || if (PartitionList == NULL ||
@ -1796,17 +1801,17 @@ CreatePartitionPage(PINPUT_RECORD Ir)
CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHOOSENEWPARTITION)); CONSOLE_SetTextXY(6, 8, MUIGetString(STRING_CHOOSENEWPARTITION));
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0 #if 0
if (DiskEntry->DiskSize >= 0x280000000ULL) /* 10 GB */ if (DiskSize >= 10737418240) /* 10 GB */
{ {
DiskSize = (DiskEntry->DiskSize + (1 << 29)) >> 30; DiskSize = DiskSize / 1073741824;
Unit = MUIGetString(STRING_GB); Unit = MUIGetString(STRING_GB);
} }
else else
#endif #endif
{ {
DiskSize = (DiskEntry->DiskSize + (1 << 19)) >> 20; DiskSize = DiskSize / 1048576;
if (DiskSize == 0) if (DiskSize == 0)
DiskSize = 1; DiskSize = 1;
@ -1841,7 +1846,7 @@ CreatePartitionPage(PINPUT_RECORD Ir)
#if 0 #if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB", CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->UnpartitionedLength / (1024*1024)); PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / 1048576);
#endif #endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
@ -1849,9 +1854,10 @@ CreatePartitionPage(PINPUT_RECORD Ir)
PartEntry = PartitionList->CurrentPartition; PartEntry = PartitionList->CurrentPartition;
while (TRUE) while (TRUE)
{ {
MaxSize = (PartEntry->UnpartitionedLength + (1 << 19)) >> 20; /* in MBytes (rounded) */ MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / 1048576; /* in MBytes (rounded) */
if (MaxSize > PARTITION_MAXSIZE) MaxSize = PARTITION_MAXSIZE; if (MaxSize > PARTITION_MAXSIZE)
MaxSize = PARTITION_MAXSIZE;
ShowPartitionSizeInputBox(12, 14, xScreen - 12, 17, /* left, top, right, bottom */ ShowPartitionSizeInputBox(12, 14, xScreen - 12, 17, /* left, top, right, bottom */
MaxSize, InputBuffer, &Quit, &Cancel); MaxSize, InputBuffer, &Quit, &Cancel);
@ -1887,23 +1893,22 @@ CreatePartitionPage(PINPUT_RECORD Ir)
if (PartSize == MaxSize) if (PartSize == MaxSize)
{ {
/* Use all of the unpartitioned disk space */ /* Use all of the unpartitioned disk space */
PartSize = PartEntry->UnpartitionedLength; SectorCount = PartEntry->SectorCount.QuadPart;
} }
else else
{ {
/* Round-up by cylinder size */ /* Calculate the sector count from the size in MB */
PartSize = (PartSize * 1024 * 1024 + DiskEntry->CylinderSize - 1) / SectorCount = PartSize * 1048576 / DiskEntry->BytesPerSector;
DiskEntry->CylinderSize * DiskEntry->CylinderSize;
/* But never get larger than the unpartitioned disk space */ /* But never get larger than the unpartitioned disk space */
if (PartSize > PartEntry->UnpartitionedLength) if (SectorCount > PartEntry->SectorCount.QuadPart)
PartSize = PartEntry->UnpartitionedLength; SectorCount = PartEntry->SectorCount.QuadPart;
} }
DPRINT ("Partition size: %I64u bytes\n", PartSize); DPRINT ("Partition size: %I64u bytes\n", PartSize);
CreateNewPartition(PartitionList, CreateNewPartition(PartitionList,
PartSize, SectorCount,
FALSE); FALSE);
return SELECT_PARTITION_PAGE; return SELECT_PARTITION_PAGE;
@ -1923,7 +1928,6 @@ DeletePartitionPage(PINPUT_RECORD Ir)
ULONGLONG PartSize; ULONGLONG PartSize;
PCHAR Unit; PCHAR Unit;
PCHAR PartType; PCHAR PartType;
UCHAR PartNumber;
if (PartitionList == NULL || if (PartitionList == NULL ||
PartitionList->CurrentDisk == NULL || PartitionList->CurrentDisk == NULL ||
@ -1935,7 +1939,6 @@ DeletePartitionPage(PINPUT_RECORD Ir)
DiskEntry = PartitionList->CurrentDisk; DiskEntry = PartitionList->CurrentDisk;
PartEntry = PartitionList->CurrentPartition; PartEntry = PartitionList->CurrentPartition;
PartNumber = PartitionList->CurrentPartitionNumber;
MUIDisplayPage(DELETE_PARTITION_PAGE); MUIDisplayPage(DELETE_PARTITION_PAGE);
@ -1945,46 +1948,47 @@ DeletePartitionPage(PINPUT_RECORD Ir)
{ {
PartType = MUIGetString(STRING_UNFORMATTED); PartType = MUIGetString(STRING_UNFORMATTED);
} }
else if (PartEntry->Unpartitioned == FALSE) else if (PartEntry->IsPartitioned == TRUE)
{ {
if ((PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT_12) || if ((PartEntry->PartitionType == PARTITION_FAT_12) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT_16) || (PartEntry->PartitionType == PARTITION_FAT_16) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_HUGE) || (PartEntry->PartitionType == PARTITION_HUGE) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_XINT13)) (PartEntry->PartitionType == PARTITION_XINT13))
{ {
PartType = "FAT"; PartType = "FAT";
} }
else if ((PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT32) || else if ((PartEntry->PartitionType == PARTITION_FAT32) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT32_XINT13)) (PartEntry->PartitionType == PARTITION_FAT32_XINT13))
{ {
PartType = "FAT32"; PartType = "FAT32";
} }
else if (PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_EXT2) else if (PartEntry->PartitionType == PARTITION_EXT2)
{ {
PartType = "EXT2"; PartType = "EXT2";
} }
else if (PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_IFS) else if (PartEntry->PartitionType == PARTITION_IFS)
{ {
PartType = "NTFS"; /* FIXME: Not quite correct! */ PartType = "NTFS"; /* FIXME: Not quite correct! */
} }
} }
PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0 #if 0
if (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart >= 0x280000000LL) /* 10 GB */ if (PartSize >= 10737418240) /* 10 GB */
{ {
PartSize = (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart + (1 << 29)) >> 30; PartSize = PartSize / 1073741824;
Unit = MUIGetString(STRING_GB); Unit = MUIGetString(STRING_GB);
} }
else else
#endif #endif
if (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart >= 0xA00000LL) /* 10 MB */ if (PartSize >= 10485760) /* 10 MB */
{ {
PartSize = (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart + (1 << 19)) >> 20; PartSize = PartSize / 1048576;
Unit = MUIGetString(STRING_MB); Unit = MUIGetString(STRING_MB);
} }
else else
{ {
PartSize = (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart + (1 << 9)) >> 10; PartSize = PartSize / 1024;
Unit = MUIGetString(STRING_KB); Unit = MUIGetString(STRING_KB);
} }
@ -1992,9 +1996,9 @@ DeletePartitionPage(PINPUT_RECORD Ir)
{ {
CONSOLE_PrintTextXY(6, 10, CONSOLE_PrintTextXY(6, 10,
MUIGetString(STRING_HDDINFOUNK2), MUIGetString(STRING_HDDINFOUNK2),
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : PartEntry->DriveLetter[PartNumber], (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : ':', (PartEntry->DriveLetter == 0) ? '-' : ':',
PartEntry->PartInfo[PartNumber].PartitionType, PartEntry->PartitionType,
PartSize, PartSize,
Unit); Unit);
} }
@ -2002,24 +2006,24 @@ DeletePartitionPage(PINPUT_RECORD Ir)
{ {
CONSOLE_PrintTextXY(6, 10, CONSOLE_PrintTextXY(6, 10,
" %c%c %s %I64u %s", " %c%c %s %I64u %s",
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : PartEntry->DriveLetter[PartNumber], (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : ':', (PartEntry->DriveLetter == 0) ? '-' : ':',
PartType, PartType,
PartSize, PartSize,
Unit); Unit);
} }
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
#if 0 #if 0
if (DiskEntry->DiskSize >= 0x280000000ULL) /* 10 GB */ if (DiskSize >= 10737418240) /* 10 GB */
{ {
DiskSize = (DiskEntry->DiskSize + (1 << 29)) >> 30; DiskSize = DiskSize / 1073741824;
Unit = MUIGetString(STRING_GB); Unit = MUIGetString(STRING_GB);
} }
else else
#endif #endif
{ {
DiskSize = (DiskEntry->DiskSize + (1 << 19)) >> 20; DiskSize = DiskSize / 1048576;
if (DiskSize == 0) if (DiskSize == 0)
DiskSize = 1; DiskSize = 1;
@ -2085,7 +2089,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
UCHAR PartNumber;
ULONGLONG DiskSize; ULONGLONG DiskSize;
ULONGLONG PartSize; ULONGLONG PartSize;
PCHAR DiskUnit; PCHAR DiskUnit;
@ -2102,54 +2105,55 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
DiskEntry = PartitionList->CurrentDisk; DiskEntry = PartitionList->CurrentDisk;
PartEntry = PartitionList->CurrentPartition; PartEntry = PartitionList->CurrentPartition;
PartNumber = PartitionList->CurrentPartitionNumber;
/* adjust disk size */ /* adjust disk size */
if (DiskEntry->DiskSize >= 0x280000000ULL) /* 10 GB */ DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
if (DiskSize >= 10737418240) /* 10 GB */
{ {
DiskSize = (DiskEntry->DiskSize + (1 << 29)) >> 30; DiskSize = DiskSize / 1073741824;
DiskUnit = MUIGetString(STRING_GB); DiskUnit = MUIGetString(STRING_GB);
} }
else else
{ {
DiskSize = (DiskEntry->DiskSize + (1 << 19)) >> 20; DiskSize = DiskSize / 1048576;
DiskUnit = MUIGetString(STRING_MB); DiskUnit = MUIGetString(STRING_MB);
} }
/* adjust partition size */ /* adjust partition size */
if (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart >= 0x280000000LL) /* 10 GB */ PartSize = PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
if (PartSize >= 10737418240) /* 10 GB */
{ {
PartSize = (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart + (1 << 29)) >> 30; PartSize = PartSize / 1073741824;
PartUnit = MUIGetString(STRING_GB); PartUnit = MUIGetString(STRING_GB);
} }
else else
{ {
PartSize = (PartEntry->PartInfo[PartNumber].PartitionLength.QuadPart + (1 << 19)) >> 20; PartSize = PartSize / 1048576;
PartUnit = MUIGetString(STRING_MB); PartUnit = MUIGetString(STRING_MB);
} }
/* adjust partition type */ /* adjust partition type */
if ((PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT_12) || if ((PartEntry->PartitionType == PARTITION_FAT_12) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT_16) || (PartEntry->PartitionType == PARTITION_FAT_16) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_HUGE) || (PartEntry->PartitionType == PARTITION_HUGE) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_XINT13)) (PartEntry->PartitionType == PARTITION_XINT13))
{ {
PartType = "FAT"; PartType = "FAT";
} }
else if ((PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT32) || else if ((PartEntry->PartitionType == PARTITION_FAT32) ||
(PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_FAT32_XINT13)) (PartEntry->PartitionType == PARTITION_FAT32_XINT13))
{ {
PartType = "FAT32"; PartType = "FAT32";
} }
else if (PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_EXT2) else if (PartEntry->PartitionType == PARTITION_EXT2)
{ {
PartType = "EXT2"; PartType = "EXT2";
} }
else if (PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_IFS) else if (PartEntry->PartitionType == PARTITION_IFS)
{ {
PartType = "NTFS"; /* FIXME: Not quite correct! */ PartType = "NTFS"; /* FIXME: Not quite correct! */
} }
else if (PartEntry->PartInfo[PartNumber].PartitionType == PARTITION_ENTRY_UNUSED) else if (PartEntry->PartitionType == PARTITION_ENTRY_UNUSED)
{ {
PartType = MUIGetString(STRING_FORMATUNUSED); PartType = MUIGetString(STRING_FORMATUNUSED);
} }
@ -2164,7 +2168,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
#if 0 #if 0
CONSOLE_PrintTextXY(8, 10, "Partition %lu (%I64u %s) %s of", CONSOLE_PrintTextXY(8, 10, "Partition %lu (%I64u %s) %s of",
PartEntry->PartInfo[PartNumber].PartitionNumber, PartEntry->PartitionNumber,
PartSize, PartSize,
PartUnit, PartUnit,
PartType); PartType);
@ -2197,9 +2201,9 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
{ {
CONSOLE_PrintTextXY(8, 10, CONSOLE_PrintTextXY(8, 10,
MUIGetString(STRING_HDDINFOUNK4), MUIGetString(STRING_HDDINFOUNK4),
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : PartEntry->DriveLetter[PartNumber], (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : ':', (PartEntry->DriveLetter == 0) ? '-' : ':',
PartEntry->PartInfo[PartNumber].PartitionType, PartEntry->PartitionType,
PartSize, PartSize,
PartUnit); PartUnit);
} }
@ -2207,8 +2211,8 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
{ {
CONSOLE_PrintTextXY(8, 10, CONSOLE_PrintTextXY(8, 10,
"%c%c %s %I64u %s", "%c%c %s %I64u %s",
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : PartEntry->DriveLetter[PartNumber], (PartEntry->DriveLetter == 0) ? '-' : PartEntry->DriveLetter,
(PartEntry->DriveLetter[PartNumber] == 0) ? '-' : ':', (PartEntry->DriveLetter == 0) ? '-' : ':',
PartType, PartType,
PartSize, PartSize,
PartUnit); PartUnit);
@ -2237,6 +2241,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
/* FIXME: Add file systems to list */ /* FIXME: Add file systems to list */
} }
DrawFileSystemList(FileSystemList); DrawFileSystemList(FileSystemList);
if (RepairUpdateFlag) if (RepairUpdateFlag)
@ -2305,12 +2310,11 @@ static ULONG
FormatPartitionPage(PINPUT_RECORD Ir) FormatPartitionPage(PINPUT_RECORD Ir)
{ {
WCHAR PathBuffer[MAX_PATH]; WCHAR PathBuffer[MAX_PATH];
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
UCHAR PartNum;
NTSTATUS Status; NTSTATUS Status;
#ifndef NDEBUG #ifndef NDEBUG
PDISKENTRY DiskEntry;
ULONG Line; ULONG Line;
ULONG i; ULONG i;
PLIST_ENTRY Entry; PLIST_ENTRY Entry;
@ -2326,11 +2330,8 @@ FormatPartitionPage(PINPUT_RECORD Ir)
return QUIT_PAGE; return QUIT_PAGE;
} }
#ifndef NDEBUG
DiskEntry = PartitionList->CurrentDisk; DiskEntry = PartitionList->CurrentDisk;
#endif
PartEntry = PartitionList->CurrentPartition; PartEntry = PartitionList->CurrentPartition;
PartNum = PartitionList->CurrentPartitionNumber;
while (TRUE) while (TRUE)
{ {
@ -2355,50 +2356,55 @@ FormatPartitionPage(PINPUT_RECORD Ir)
if (wcscmp(FileSystemList->Selected->FileSystem, L"FAT") == 0) if (wcscmp(FileSystemList->Selected->FileSystem, L"FAT") == 0)
{ {
if (PartEntry->PartInfo[PartNum].PartitionLength.QuadPart < (4200LL * 1024LL)) if (PartEntry->SectorCount.QuadPart < 8192)
{ {
/* FAT12 CHS partition (disk is smaller than 4.1MB) */ /* FAT12 CHS partition (disk is smaller than 4.1MB) */
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_FAT_12; PartEntry->PartitionType = PARTITION_FAT_12;
} }
else if (PartEntry->PartInfo[PartNum].StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL)) else if (PartEntry->StartSector.QuadPart < 1450560)
{ {
/* Partition starts below the 8.4GB boundary ==> CHS partition */ /* Partition starts below the 8.4GB boundary ==> CHS partition */
if (PartEntry->PartInfo[PartNum].PartitionLength.QuadPart < (32LL * 1024LL * 1024LL)) if (PartEntry->SectorCount.QuadPart < 65536)
{ {
/* FAT16 CHS partition (partiton size < 32MB) */ /* FAT16 CHS partition (partiton size < 32MB) */
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_FAT_16; PartEntry->PartitionType = PARTITION_FAT_16;
} }
else if (PartEntry->PartInfo[PartNum].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) else if (PartEntry->SectorCount.QuadPart < 1048576)
{ {
/* FAT16 CHS partition (partition size < 512MB) */ /* FAT16 CHS partition (partition size < 512MB) */
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_HUGE; PartEntry->PartitionType = PARTITION_HUGE;
} }
else else
{ {
/* FAT32 CHS partition (partition size >= 512MB) */ /* FAT32 CHS partition (partition size >= 512MB) */
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_FAT32; PartEntry->PartitionType = PARTITION_FAT32;
} }
} }
else else
{ {
/* Partition starts above the 8.4GB boundary ==> LBA partition */ /* Partition starts above the 8.4GB boundary ==> LBA partition */
if (PartEntry->PartInfo[PartNum].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) if (PartEntry->SectorCount.QuadPart < 1048576)
{ {
/* FAT16 LBA partition (partition size < 512MB) */ /* FAT16 LBA partition (partition size < 512MB) */
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_XINT13; PartEntry->PartitionType = PARTITION_XINT13;
} }
else else
{ {
/* FAT32 LBA partition (partition size >= 512MB) */ /* FAT32 LBA partition (partition size >= 512MB) */
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_FAT32_XINT13; PartEntry->PartitionType = PARTITION_FAT32_XINT13;
} }
} }
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType;
} }
#if 0 #if 0
else if (wcscmp(FileSystemList->Selected->FileSystem, L"EXT2") == 0) else if (wcscmp(FileSystemList->Selected->FileSystem, L"EXT2") == 0)
{
PartEntry->PartInfo[PartNum].PartitionType = PARTITION_EXT2; PartEntry->PartInfo[PartNum].PartitionType = PARTITION_EXT2;
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType = PartEntry->PartitionType;
}
#endif #endif
else if (!FileSystemList->Selected->FormatFunc) else if (!FileSystemList->Selected->FormatFunc)
return QUIT_PAGE; return QUIT_PAGE;
@ -2414,27 +2420,21 @@ FormatPartitionPage(PINPUT_RECORD Ir)
DiskEntry = PartitionList->CurrentDisk; DiskEntry = PartitionList->CurrentDisk;
Entry = DiskEntry->PartListHead.Flink; Entry = DiskEntry->PartListHead.Flink;
while (Entry != &DiskEntry->PartListHead) while (Entry != &DiskEntry->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry); PartEntry = CONTAINING_RECORD(Entry, PARTENTRY, ListEntry);
if (PartEntry->Unpartitioned == FALSE) if (PartEntry->IsPartitioned == TRUE)
{ {
for (i = 0; i < 4; i++) CONSOLE_PrintTextXY(6, Line,
{ "%2u: %2u %c %12I64u %12I64u %2u %c",
CONSOLE_PrintTextXY(6, Line, i,
"%2u: %2u %c %12I64u %12I64u %2u %c", PartEntry->PartitionNumber,
i, PartEntry->BootIndicator ? 'A' : '-',
PartEntry->PartInfo[i].PartitionNumber, PartEntry->StartSector.QuadPart,
PartEntry->PartInfo[i].BootIndicator ? 'A' : '-', PartEntry->SectorCount.QuadPart,
PartEntry->PartInfo[i].StartingOffset.QuadPart, PartEntry->PartitionType,
PartEntry->PartInfo[i].PartitionLength.QuadPart, PartEntry->Dirty ? '*' : ' ');
PartEntry->PartInfo[i].PartitionType,
PartEntry->PartInfo[i].RewritePartition ? '*' : ' ');
Line++;
}
Line++; Line++;
} }
@ -2445,6 +2445,8 @@ FormatPartitionPage(PINPUT_RECORD Ir)
PartEntry = PartitionList->CurrentPartition; PartEntry = PartitionList->CurrentPartition;
#endif #endif
CheckActiveBootPartition(PartitionList);
if (WritePartitionsToDisk(PartitionList) == FALSE) if (WritePartitionsToDisk(PartitionList) == FALSE)
{ {
DPRINT("WritePartitionsToDisk() failed\n"); DPRINT("WritePartitionsToDisk() failed\n");
@ -2457,7 +2459,7 @@ FormatPartitionPage(PINPUT_RECORD Ir)
swprintf(PathBuffer, swprintf(PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu", L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->CurrentDisk->DiskNumber, PartitionList->CurrentDisk->DiskNumber,
PartitionList->CurrentPartition->PartInfo[PartNum].PartitionNumber); PartitionList->CurrentPartition->PartitionNumber);
RtlCreateUnicodeString(&DestinationRootPath, RtlCreateUnicodeString(&DestinationRootPath,
PathBuffer); PathBuffer);
DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath); DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath);
@ -2475,7 +2477,6 @@ FormatPartitionPage(PINPUT_RECORD Ir)
PartEntry->New = FALSE; PartEntry->New = FALSE;
CheckActiveBootPartition(PartitionList);
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -2500,7 +2501,6 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
WCHAR PathBuffer[MAX_PATH]; WCHAR PathBuffer[MAX_PATH];
CHAR Buffer[MAX_PATH]; CHAR Buffer[MAX_PATH];
NTSTATUS Status; NTSTATUS Status;
UCHAR PartNum = PartitionList->CurrentPartitionNumber;
/* FIXME: code duplicated in FormatPartitionPage */ /* FIXME: code duplicated in FormatPartitionPage */
/* Set DestinationRootPath */ /* Set DestinationRootPath */
@ -2508,7 +2508,7 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
swprintf(PathBuffer, swprintf(PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu", L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->CurrentDisk->DiskNumber, PartitionList->CurrentDisk->DiskNumber,
PartitionList->CurrentPartition->PartInfo[PartNum].PartitionNumber); PartitionList->CurrentPartition->PartitionNumber);
RtlCreateUnicodeString(&DestinationRootPath, PathBuffer); RtlCreateUnicodeString(&DestinationRootPath, PathBuffer);
DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath); DPRINT("DestinationRootPath: %wZ\n", &DestinationRootPath);
@ -2574,8 +2574,7 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
static PAGE_NUMBER static PAGE_NUMBER
InstallDirectoryPage1(PWCHAR InstallDir, InstallDirectoryPage1(PWCHAR InstallDir,
PDISKENTRY DiskEntry, PDISKENTRY DiskEntry,
PPARTENTRY PartEntry, PPARTENTRY PartEntry)
UCHAR PartNum)
{ {
WCHAR PathBuffer[MAX_PATH]; WCHAR PathBuffer[MAX_PATH];
@ -2599,7 +2598,7 @@ InstallDirectoryPage1(PWCHAR InstallDir,
swprintf(PathBuffer, swprintf(PathBuffer,
L"multi(0)disk(0)rdisk(%lu)partition(%lu)", L"multi(0)disk(0)rdisk(%lu)partition(%lu)",
DiskEntry->BiosDiskNumber, DiskEntry->BiosDiskNumber,
PartEntry->PartInfo[PartNum].PartitionNumber); PartEntry->PartitionNumber);
if (InstallDir[0] != L'\\') if (InstallDir[0] != L'\\')
wcscat(PathBuffer, L"\\"); wcscat(PathBuffer, L"\\");
@ -2643,8 +2642,7 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
{ {
return InstallDirectoryPage1(InstallDir, return InstallDirectoryPage1(InstallDir,
DiskEntry, DiskEntry,
PartEntry, PartEntry);
PartitionList->CurrentPartitionNumber);
} }
while (TRUE) while (TRUE)
@ -2663,8 +2661,7 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
{ {
return InstallDirectoryPage1(InstallDir, return InstallDirectoryPage1(InstallDir,
DiskEntry, DiskEntry,
PartEntry, PartEntry);
PartitionList->CurrentPartitionNumber);
} }
else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x08) /* BACKSPACE */ else if (Ir->Event.KeyEvent.uChar.AsciiChar == 0x08) /* BACKSPACE */
{ {
@ -3382,14 +3379,12 @@ BootLoaderPage(PINPUT_RECORD Ir)
swprintf(PathBuffer, swprintf(PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu", L"\\Device\\Harddisk%lu\\Partition%lu",
PartitionList->ActiveBootDisk->DiskNumber, PartitionList->ActiveBootDisk->DiskNumber,
PartitionList->ActiveBootPartition-> PartitionList->ActiveBootPartition->PartitionNumber);
PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionNumber);
RtlCreateUnicodeString(&SystemRootPath, RtlCreateUnicodeString(&SystemRootPath,
PathBuffer); PathBuffer);
DPRINT("SystemRootPath: %wZ\n", &SystemRootPath); DPRINT("SystemRootPath: %wZ\n", &SystemRootPath);
PartitionType = PartitionList->ActiveBootPartition-> PartitionType = PartitionList->ActiveBootPartition->PartitionType;
PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
if (IsUnattendedSetup) if (IsUnattendedSetup)
{ {
@ -3573,8 +3568,7 @@ BootLoaderHarddiskVbrPage(PINPUT_RECORD Ir)
UCHAR PartitionType; UCHAR PartitionType;
NTSTATUS Status; NTSTATUS Status;
PartitionType = PartitionList->ActiveBootPartition-> PartitionType = PartitionList->ActiveBootPartition->PartitionType;
PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
Status = InstallVBRToPartition(&SystemRootPath, Status = InstallVBRToPartition(&SystemRootPath,
&SourceRootPath, &SourceRootPath,
@ -3598,8 +3592,7 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
WCHAR SourceMbrPathBuffer[MAX_PATH]; WCHAR SourceMbrPathBuffer[MAX_PATH];
/* Step 1: Write the VBR */ /* Step 1: Write the VBR */
PartitionType = PartitionList->ActiveBootPartition-> PartitionType = PartitionList->ActiveBootPartition->PartitionType;
PartInfo[PartitionList->ActiveBootPartitionNumber].PartitionType;
Status = InstallVBRToPartition(&SystemRootPath, Status = InstallVBRToPartition(&SystemRootPath,
&SourceRootPath, &SourceRootPath,

File diff suppressed because it is too large Load diff

View file

@ -42,12 +42,23 @@ typedef struct _PARTENTRY
{ {
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
CHAR DriveLetter[4]; struct _DISKENTRY *DiskEntry;
ULARGE_INTEGER StartSector;
ULARGE_INTEGER SectorCount;
BOOLEAN BootIndicator;
UCHAR PartitionType;
ULONG HiddenSectors;
ULONG PartitionNumber;
ULONG PartitionIndex;
CHAR DriveLetter;
CHAR VolumeLabel[17]; CHAR VolumeLabel[17];
CHAR FileSystemName[9]; CHAR FileSystemName[9];
/* Partition is unused disk space */ /* Partition is partitioned disk space */
BOOLEAN Unpartitioned; BOOLEAN IsPartitioned;
/* Partition is new. Table does not exist on disk yet */ /* Partition is new. Table does not exist on disk yet */
BOOLEAN New; BOOLEAN New;
@ -57,15 +68,6 @@ typedef struct _PARTENTRY
FORMATSTATE FormatState; FORMATSTATE FormatState;
/*
* Raw offset and length of the unpartitioned disk space.
* Includes the leading, not yet existing, partition table.
*/
ULONGLONG UnpartitionedOffset;
ULONGLONG UnpartitionedLength;
PARTITION_INFORMATION PartInfo[4];
} PARTENTRY, *PPARTENTRY; } PARTENTRY, *PPARTENTRY;
@ -86,18 +88,17 @@ typedef struct _DISKENTRY
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
ULONGLONG Cylinders; ULONGLONG Cylinders;
ULONGLONG TracksPerCylinder; ULONG TracksPerCylinder;
ULONGLONG SectorsPerTrack; ULONG SectorsPerTrack;
ULONGLONG BytesPerSector; ULONG BytesPerSector;
ULONGLONG DiskSize; ULARGE_INTEGER SectorCount;
ULONGLONG CylinderSize; ULONG SectorAlignment;
ULONGLONG TrackSize;
BOOLEAN BiosFound; BOOLEAN BiosFound;
ULONG BiosDiskNumber; ULONG BiosDiskNumber;
ULONG Signature; // ULONG Signature;
ULONG Checksum; // ULONG Checksum;
ULONG DiskNumber; ULONG DiskNumber;
USHORT Port; USHORT Port;
@ -105,14 +106,17 @@ typedef struct _DISKENTRY
USHORT Id; USHORT Id;
/* Has the partition list been modified? */ /* Has the partition list been modified? */
BOOLEAN Modified; BOOLEAN Dirty;
BOOLEAN NewDisk; BOOLEAN NewDisk;
BOOLEAN NoMbr; /* MBR is absent */ BOOLEAN NoMbr; /* MBR is absent */
UNICODE_STRING DriverName; UNICODE_STRING DriverName;
LIST_ENTRY PartListHead; PDRIVE_LAYOUT_INFORMATION LayoutBuffer;
LIST_ENTRY PrimaryPartListHead;
LIST_ENTRY ExtendedPartListHead;
} DISKENTRY, *PDISKENTRY; } DISKENTRY, *PDISKENTRY;
@ -132,11 +136,9 @@ typedef struct _PARTLIST
PDISKENTRY CurrentDisk; PDISKENTRY CurrentDisk;
PPARTENTRY CurrentPartition; PPARTENTRY CurrentPartition;
UCHAR CurrentPartitionNumber;
PDISKENTRY ActiveBootDisk; PDISKENTRY ActiveBootDisk;
PPARTENTRY ActiveBootPartition; PPARTENTRY ActiveBootPartition;
UCHAR ActiveBootPartitionNumber;
LIST_ENTRY DiskListHead; LIST_ENTRY DiskListHead;
LIST_ENTRY BiosDiskListHead; LIST_ENTRY BiosDiskListHead;