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,10 +97,10 @@ 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 */

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)
{
Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
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 == FsFat) 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);
" Format partition as FAT file system "); 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,
" Format partition as FAT file system "); Buffer);
}
Index++; Index++;
ListEntry = ListEntry->Flink;
if (List->ForceFormat == FALSE)
{
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 == FsKeep)
{
CONSOLE_SetInvertedTextXY(List->Left,
List->Top + Index,
" Keep current file system (no changes) ");
}
else
{
CONSOLE_SetTextXY(List->Left,
List->Top + Index,
" Keep current file system (no changes) ");
}
} }
} }
@ -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;
} }
@ -2214,9 +2214,8 @@ FormatPartitionPage (PINPUT_RECORD Ir)
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) */
@ -2258,13 +2257,9 @@ FormatPartitionPage (PINPUT_RECORD Ir)
} }
} }
break; break;
case FsKeep:
break;
default:
return QUIT_PAGE;
} }
else if (FileSystemList->Selected->FormatFunc)
return QUIT_PAGE;
} }
CheckActiveBootPartition (PartitionList); CheckActiveBootPartition (PartitionList);
@ -2343,29 +2338,26 @@ 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%.08x\n", Status); DPRINT1("FormatPartition() failed with status 0x%08lx\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);
}
if (strcmp(FileSystemList->Selected->FileSystem, "FAT") == 0)
{
/* FIXME: Install boot code. This is a hack! */ /* FIXME: Install boot code. This is a hack! */
if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13) || if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13)
(PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32)) || (PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32))
{ {
wcscpy(PathBuffer, SourceRootPath.Buffer); wcscpy(PathBuffer, SourceRootPath.Buffer);
wcscat(PathBuffer, L"\\loader\\fat32.bin"); wcscat(PathBuffer, L"\\loader\\fat32.bin");
@ -2376,8 +2368,10 @@ FormatPartitionPage (PINPUT_RECORD Ir)
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 */
DestroyFileSystemList(FileSystemList);
FileSystemList = NULL;
return QUIT_PAGE; return QUIT_PAGE;
} }
} }
@ -2394,15 +2388,16 @@ FormatPartitionPage (PINPUT_RECORD Ir)
{ {
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 */
DestroyFileSystemList(FileSystemList);
FileSystemList = NULL;
return QUIT_PAGE; return QUIT_PAGE;
} }
} }
break; }
else if (FileSystemList->Selected->FormatFunc)
case FsKeep: {
break; DestroyFileSystemList(FileSystemList);
FileSystemList = NULL;
default:
return QUIT_PAGE; return QUIT_PAGE;
} }
@ -2411,6 +2406,8 @@ FormatPartitionPage (PINPUT_RECORD Ir)
CONSOLE_ConInKey(Ir); CONSOLE_ConInKey(Ir);
#endif #endif
DestroyFileSystemList(FileSystemList);
FileSystemList = NULL;
return INSTALL_DIRECTORY_PAGE; return INSTALL_DIRECTORY_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"