Adapt usetup to handle more easily additional filesystems

This also prepares ground for the Chkdsk disk page

svn path=/trunk/; revision=23974
This commit is contained in:
Hervé Poussineau 2006-09-07 22:42:28 +00:00
parent e6fd23de2c
commit 9243a83d80
6 changed files with 230 additions and 184 deletions

View file

@ -84,7 +84,8 @@ FormatCallback(
NTSTATUS NTSTATUS
FormatPartition( FormatPartition(
IN PUNICODE_STRING DriveRoot) IN PUNICODE_STRING DriveRoot,
IN PFILE_SYSTEM_ITEM FileSystem)
{ {
NTSTATUS Status; NTSTATUS Status;
@ -96,12 +97,12 @@ FormatPartition(
ProgressSetStepCount(ProgressBar, 100); ProgressSetStepCount(ProgressBar, 100);
Status = VfatFormat(DriveRoot, Status = FileSystem->FormatFunc(DriveRoot,
FMIFS_HARDDISK, /* MediaFlag */ FMIFS_HARDDISK, /* MediaFlag */
NULL, /* Label */ NULL, /* Label */
TRUE, /* QuickFormat */ FileSystem->QuickFormat, /* QuickFormat */
0, /* ClusterSize */ 0, /* ClusterSize */
FormatCallback); /* Callback */ FormatCallback); /* Callback */
DestroyProgressBar(ProgressBar); DestroyProgressBar(ProgressBar);
ProgressBar = NULL; ProgressBar = NULL;

View file

@ -29,7 +29,8 @@
NTSTATUS NTSTATUS
FormatPartition( FormatPartition(
IN PUNICODE_STRING DriveRoot); IN PUNICODE_STRING DriveRoot,
IN PFILE_SYSTEM_ITEM FileSystem);
#endif /* __FILESUP_H__ */ #endif /* __FILESUP_H__ */

View file

@ -32,14 +32,49 @@
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
static VOID
AddProvider(
IN OUT PFILE_SYSTEM_LIST List,
IN LPCSTR FileSystem,
IN FORMATEX FormatFunc,
IN CHKDSKEX ChkdskFunc)
{
PFILE_SYSTEM_ITEM Item;
Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_ITEM));
if (!Item)
return;
Item->FileSystem = FileSystem;
Item->FormatFunc = FormatFunc;
Item->ChkdskFunc = ChkdskFunc;
Item->QuickFormat = FALSE;
InsertTailList(&List->ListHead, &Item->ListEntry);
if (!FormatFunc)
return;
Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_ITEM));
if (!Item)
return;
Item->FileSystem = FileSystem;
Item->FormatFunc = FormatFunc;
Item->ChkdskFunc = ChkdskFunc;
Item->QuickFormat = TRUE;
InsertTailList(&List->ListHead, &Item->ListEntry);
}
PFILE_SYSTEM_LIST PFILE_SYSTEM_LIST
CreateFileSystemList( CreateFileSystemList(
IN SHORT Left, IN SHORT Left,
IN SHORT Top, IN SHORT Top,
IN BOOLEAN ForceFormat, IN BOOLEAN ForceFormat,
IN FILE_SYSTEM ForceFileSystem) IN LPCSTR ForceFileSystem)
{ {
PFILE_SYSTEM_LIST List; PFILE_SYSTEM_LIST List;
PFILE_SYSTEM_ITEM Item;
PLIST_ENTRY ListEntry;
List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_LIST)); List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_LIST));
if (List == NULL) if (List == NULL)
@ -47,18 +82,30 @@ CreateFileSystemList(
List->Left = Left; List->Left = Left;
List->Top = Top; List->Top = Top;
List->Selected = NULL;
InitializeListHead(&List->ListHead);
List->ForceFormat = ForceFormat; AddProvider(List, "FAT", VfatFormat, NULL);
List->FileSystemCount = 1; if (!ForceFormat)
if (ForceFormat)
{ {
List->CurrentFileSystem = ForceFileSystem; /* Add 'Keep' provider */
AddProvider(List, NULL, NULL, NULL);
} }
else
/* Search for ForceFileSystem in list */
ListEntry = List->ListHead.Flink;
while (ListEntry != &List->ListHead)
{ {
List->FileSystemCount++; Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
List->CurrentFileSystem = FsKeep; if (Item->FileSystem && strcmp(ForceFileSystem, Item->FileSystem) == 0)
{
List->Selected = Item;
break;
}
ListEntry = ListEntry->Flink;
} }
if (!List->Selected)
List->Selected = CONTAINING_RECORD(List->ListHead.Flink, FILE_SYSTEM_ITEM, ListEntry);
return List; return List;
} }
@ -67,6 +114,19 @@ VOID
DestroyFileSystemList( DestroyFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
{ {
PLIST_ENTRY ListEntry = List->ListHead.Flink;
PFILE_SYSTEM_ITEM Item;
PLIST_ENTRY Next;
while (ListEntry != &List->ListHead)
{
Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
Next = ListEntry->Flink;
RtlFreeHeap(ProcessHeap, 0, Item);
ListEntry = Next;
}
RtlFreeHeap(ProcessHeap, 0, List); RtlFreeHeap(ProcessHeap, 0, List);
} }
@ -74,66 +134,51 @@ VOID
DrawFileSystemList( DrawFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
{ {
PLIST_ENTRY ListEntry;
PFILE_SYSTEM_ITEM Item;
COORD coPos; COORD coPos;
ULONG Written; ULONG Written;
ULONG Index; ULONG Index = 0;
CHAR Buffer[70];
Index = 0; ListEntry = List->ListHead.Flink;
while (ListEntry != &List->ListHead)
coPos.X = List->Left;
coPos.Y = List->Top + Index;
FillConsoleOutputAttribute(StdOutput,
FOREGROUND_WHITE | BACKGROUND_BLUE,
50,
coPos,
&Written);
FillConsoleOutputCharacterA(StdOutput,
' ',
50,
coPos,
&Written);
if (List->CurrentFileSystem == FsFat)
{ {
CONSOLE_SetInvertedTextXY(List->Left, Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
List->Top + Index,
" Format partition as FAT file system ");
}
else
{
CONSOLE_SetTextXY(List->Left,
List->Top + Index,
" Format partition as FAT file system ");
}
Index++;
if (List->ForceFormat == FALSE)
{
coPos.X = List->Left; coPos.X = List->Left;
coPos.Y = List->Top + Index; coPos.Y = List->Top + Index;
FillConsoleOutputAttribute(StdOutput, FillConsoleOutputAttribute(StdOutput,
FOREGROUND_WHITE | BACKGROUND_BLUE, FOREGROUND_WHITE | BACKGROUND_BLUE,
50, sizeof(Buffer),
coPos, coPos,
&Written); &Written);
FillConsoleOutputCharacterA(StdOutput, FillConsoleOutputCharacterA(StdOutput,
' ', ' ',
50, sizeof(Buffer),
coPos, coPos,
&Written); &Written);
if (List->CurrentFileSystem == FsKeep) if (Item->FileSystem)
{ {
CONSOLE_SetInvertedTextXY(List->Left, if (Item->QuickFormat)
List->Top + Index, sprintf(Buffer, " Format partition as %s file system (quick format) ", Item->FileSystem);
" Keep current file system (no changes) "); else
sprintf(Buffer, " Format partition as %s file system ", Item->FileSystem);
} }
else else
{ sprintf(Buffer, " Keep current file system (no changes) ");
if (ListEntry == &List->Selected->ListEntry)
CONSOLE_SetInvertedTextXY(List->Left,
List->Top + Index,
Buffer);
else
CONSOLE_SetTextXY(List->Left, CONSOLE_SetTextXY(List->Left,
List->Top + Index, List->Top + Index,
" Keep current file system (no changes) "); Buffer);
} Index++;
ListEntry = ListEntry->Flink;
} }
} }
@ -141,9 +186,9 @@ VOID
ScrollDownFileSystemList( ScrollDownFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
{ {
if ((ULONG)List->CurrentFileSystem < List->FileSystemCount - 1) if (List->Selected->ListEntry.Flink != &List->ListHead)
{ {
List->CurrentFileSystem++; List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Flink, FILE_SYSTEM_ITEM, ListEntry);
DrawFileSystemList(List); DrawFileSystemList(List);
} }
} }
@ -152,9 +197,9 @@ VOID
ScrollUpFileSystemList( ScrollUpFileSystemList(
IN PFILE_SYSTEM_LIST List) IN PFILE_SYSTEM_LIST List)
{ {
if ((ULONG)List->CurrentFileSystem > 0) if (List->Selected->ListEntry.Blink != &List->ListHead)
{ {
List->CurrentFileSystem--; List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Blink, FILE_SYSTEM_ITEM, ListEntry);
DrawFileSystemList(List); DrawFileSystemList(List);
} }
} }

View file

@ -28,19 +28,21 @@
#ifndef __FSLIST_H__ #ifndef __FSLIST_H__
#define __FSLIST_H__ #define __FSLIST_H__
typedef enum typedef struct _FILE_SYSTEM_ITEM
{ {
FsFat = 0, LIST_ENTRY ListEntry;
FsKeep = 1 LPCSTR FileSystem; /* Not owned by the item */
} FILE_SYSTEM; FORMATEX FormatFunc;
CHKDSKEX ChkdskFunc;
BOOLEAN QuickFormat;
} FILE_SYSTEM_ITEM, *PFILE_SYSTEM_ITEM;
typedef struct _FILE_SYSTEM_LIST typedef struct _FILE_SYSTEM_LIST
{ {
SHORT Left; SHORT Left;
SHORT Top; SHORT Top;
BOOLEAN ForceFormat; PFILE_SYSTEM_ITEM Selected;
FILE_SYSTEM CurrentFileSystem; LIST_ENTRY ListHead; /* List of FILE_SYSTEM_ITEM */
ULONG FileSystemCount;
} FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST; } FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST;
@ -49,7 +51,7 @@ CreateFileSystemList(
IN SHORT Left, IN SHORT Left,
IN SHORT Top, IN SHORT Top,
IN BOOLEAN ForceFormat, IN BOOLEAN ForceFormat,
IN FILE_SYSTEM ForceFileSystem); IN LPCSTR ForceFileSystem);
VOID VOID
DestroyFileSystemList( DestroyFileSystemList(

View file

@ -2099,7 +2099,7 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
if (FileSystemList == NULL) if (FileSystemList == NULL)
{ {
FileSystemList = CreateFileSystemList (6, 26, PartEntry->New, FsFat); FileSystemList = CreateFileSystemList (6, 26, PartEntry->New, "FAT");
if (FileSystemList == NULL) if (FileSystemList == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
@ -2147,7 +2147,7 @@ SelectFileSystemPage (PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
{ {
if (FileSystemList->CurrentFileSystem == FsKeep) if (!FileSystemList->Selected->FormatFunc)
{ {
return CHECK_FILE_SYSTEM_PAGE; return CHECK_FILE_SYSTEM_PAGE;
} }
@ -2212,60 +2212,55 @@ FormatPartitionPage (PINPUT_RECORD Ir)
{ {
CONSOLE_SetStatusText (" Please wait ..."); CONSOLE_SetStatusText (" Please wait ...");
if (PartEntry->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED) if (PartEntry->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED)
{ {
switch (FileSystemList->CurrentFileSystem) if (strcmp(FileSystemList->Selected->FileSystem, "FAT") == 0)
{ {
case FsFat: if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (4200LL * 1024LL))
if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (4200LL * 1024LL)) {
{ /* FAT12 CHS partition (disk is smaller than 4.1MB) */
/* FAT12 CHS partition (disk is smaller than 4.1MB) */ PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_12;
PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_12; }
} else if (PartEntry->PartInfo[0].StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL))
else if (PartEntry->PartInfo[0].StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL)) {
{ /* Partition starts below the 8.4GB boundary ==> CHS partition */
/* Partition starts below the 8.4GB boundary ==> CHS partition */
if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (32LL * 1024LL * 1024LL)) if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (32LL * 1024LL * 1024LL))
{ {
/* FAT16 CHS partition (partiton size < 32MB) */ /* FAT16 CHS partition (partiton size < 32MB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16; PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16;
} }
else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
{ {
/* FAT16 CHS partition (partition size < 512MB) */ /* FAT16 CHS partition (partition size < 512MB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_HUGE; PartEntry->PartInfo[0].PartitionType = PARTITION_HUGE;
} }
else else
{ {
/* FAT32 CHS partition (partition size >= 512MB) */ /* FAT32 CHS partition (partition size >= 512MB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32; PartEntry->PartInfo[0].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[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
{ {
/* FAT16 LBA partition (partition size < 512MB) */ /* FAT16 LBA partition (partition size < 512MB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_XINT13; PartEntry->PartInfo[0].PartitionType = PARTITION_XINT13;
} }
else else
{ {
/* FAT32 LBA partition (partition size >= 512MB) */ /* FAT32 LBA partition (partition size >= 512MB) */
PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32_XINT13; PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32_XINT13;
} }
} }
break; break;
}
case FsKeep: else if (FileSystemList->Selected->FormatFunc)
break; return QUIT_PAGE;
}
default:
return QUIT_PAGE;
}
}
CheckActiveBootPartition (PartitionList); CheckActiveBootPartition (PartitionList);
@ -2343,79 +2338,81 @@ FormatPartitionPage (PINPUT_RECORD Ir)
DPRINT ("SystemRootPath: %wZ\n", &SystemRootPath); DPRINT ("SystemRootPath: %wZ\n", &SystemRootPath);
switch (FileSystemList->CurrentFileSystem) if (FileSystemList->Selected->FormatFunc)
{ {
case FsFat: Status = FormatPartition(&DestinationRootPath, FileSystemList->Selected);
Status = FormatPartition (&DestinationRootPath); if (!NT_SUCCESS(Status))
if (!NT_SUCCESS (Status)) {
{ DPRINT1("FormatPartition() failed with status 0x%08lx\n", Status);
DPRINT1 ("FormatPartition() failed with status 0x%.08x\n", Status); /* FIXME: show an error dialog */
/* FIXME: show an error dialog */ return QUIT_PAGE;
return QUIT_PAGE; }
}
PartEntry->New = FALSE; PartEntry->New = FALSE;
if (FileSystemList != NULL)
{
DestroyFileSystemList (FileSystemList);
FileSystemList = NULL;
}
CheckActiveBootPartition (PartitionList); CheckActiveBootPartition(PartitionList);
}
/* FIXME: Install boot code. This is a hack! */ if (strcmp(FileSystemList->Selected->FileSystem, "FAT") == 0)
if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13) || {
(PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32)) /* FIXME: Install boot code. This is a hack! */
{ if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13)
wcscpy (PathBuffer, SourceRootPath.Buffer); || (PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32))
wcscat (PathBuffer, L"\\loader\\fat32.bin"); {
wcscpy(PathBuffer, SourceRootPath.Buffer);
wcscat(PathBuffer, L"\\loader\\fat32.bin");
DPRINT ("Install FAT32 bootcode: %S ==> %S\n", PathBuffer, DPRINT("Install FAT32 bootcode: %S ==> %S\n", PathBuffer,
DestinationRootPath.Buffer); DestinationRootPath.Buffer);
Status = InstallFat32BootCodeToDisk (PathBuffer, Status = InstallFat32BootCodeToDisk(PathBuffer,
DestinationRootPath.Buffer); DestinationRootPath.Buffer);
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1 ("InstallFat32BootCodeToDisk() failed with status 0x%.08x\n", Status); DPRINT1("InstallFat32BootCodeToDisk() failed with status 0x%08lx\n", Status);
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; DestroyFileSystemList(FileSystemList);
} FileSystemList = NULL;
} return QUIT_PAGE;
else }
{ }
wcscpy (PathBuffer, SourceRootPath.Buffer); else
wcscat (PathBuffer, L"\\loader\\fat.bin"); {
wcscpy(PathBuffer, SourceRootPath.Buffer);
wcscat(PathBuffer, L"\\loader\\fat.bin");
DPRINT ("Install FAT bootcode: %S ==> %S\n", PathBuffer, DPRINT("Install FAT bootcode: %S ==> %S\n", PathBuffer,
DestinationRootPath.Buffer); DestinationRootPath.Buffer);
Status = InstallFat16BootCodeToDisk (PathBuffer, Status = InstallFat16BootCodeToDisk(PathBuffer,
DestinationRootPath.Buffer); DestinationRootPath.Buffer);
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1 ("InstallFat16BootCodeToDisk() failed with status 0x%.08x\n", Status); DPRINT1("InstallFat16BootCodeToDisk() failed with status 0x%.08x\n", Status);
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; DestroyFileSystemList(FileSystemList);
} FileSystemList = NULL;
} return QUIT_PAGE;
break; }
}
case FsKeep: }
break; else if (FileSystemList->Selected->FormatFunc)
{
default: DestroyFileSystemList(FileSystemList);
return QUIT_PAGE; FileSystemList = NULL;
} return QUIT_PAGE;
}
#ifndef NDEBUG #ifndef NDEBUG
CONSOLE_SetStatusText (" Done. Press any key ..."); CONSOLE_SetStatusText (" Done. Press any key ...");
CONSOLE_ConInKey(Ir); CONSOLE_ConInKey(Ir);
#endif #endif
return INSTALL_DIRECTORY_PAGE; DestroyFileSystemList(FileSystemList);
} FileSystemList = NULL;
return INSTALL_DIRECTORY_PAGE;
}
} }
return FORMAT_PARTITION_PAGE; return FORMAT_PARTITION_PAGE;
} }

View file

@ -64,8 +64,8 @@
#include "bootsup.h" #include "bootsup.h"
#include "keytrans.h" #include "keytrans.h"
#include "registry.h" #include "registry.h"
#include "format.h"
#include "fslist.h" #include "fslist.h"
#include "format.h"
#include "cabinet.h" #include "cabinet.h"
#include "filesup.h" #include "filesup.h"
#include "drivesup.h" #include "drivesup.h"