From 9243a83d80845647799e27e0c724ef611cab2285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Thu, 7 Sep 2006 22:42:28 +0000 Subject: [PATCH] Adapt usetup to handle more easily additional filesystems This also prepares ground for the Chkdsk disk page svn path=/trunk/; revision=23974 --- reactos/base/setup/usetup/format.c | 15 +- reactos/base/setup/usetup/format.h | 3 +- reactos/base/setup/usetup/fslist.c | 147 +++++++++++------- reactos/base/setup/usetup/fslist.h | 18 ++- reactos/base/setup/usetup/usetup.c | 229 ++++++++++++++--------------- reactos/base/setup/usetup/usetup.h | 2 +- 6 files changed, 230 insertions(+), 184 deletions(-) diff --git a/reactos/base/setup/usetup/format.c b/reactos/base/setup/usetup/format.c index 3c22a7f1d24..06137c42b5c 100644 --- a/reactos/base/setup/usetup/format.c +++ b/reactos/base/setup/usetup/format.c @@ -84,7 +84,8 @@ FormatCallback( NTSTATUS FormatPartition( - IN PUNICODE_STRING DriveRoot) + IN PUNICODE_STRING DriveRoot, + IN PFILE_SYSTEM_ITEM FileSystem) { NTSTATUS Status; @@ -96,12 +97,12 @@ FormatPartition( ProgressSetStepCount(ProgressBar, 100); - Status = VfatFormat(DriveRoot, - FMIFS_HARDDISK, /* MediaFlag */ - NULL, /* Label */ - TRUE, /* QuickFormat */ - 0, /* ClusterSize */ - FormatCallback); /* Callback */ + Status = FileSystem->FormatFunc(DriveRoot, + FMIFS_HARDDISK, /* MediaFlag */ + NULL, /* Label */ + FileSystem->QuickFormat, /* QuickFormat */ + 0, /* ClusterSize */ + FormatCallback); /* Callback */ DestroyProgressBar(ProgressBar); ProgressBar = NULL; diff --git a/reactos/base/setup/usetup/format.h b/reactos/base/setup/usetup/format.h index 1725664b27f..c72b86d96b0 100644 --- a/reactos/base/setup/usetup/format.h +++ b/reactos/base/setup/usetup/format.h @@ -29,7 +29,8 @@ NTSTATUS FormatPartition( - IN PUNICODE_STRING DriveRoot); + IN PUNICODE_STRING DriveRoot, + IN PFILE_SYSTEM_ITEM FileSystem); #endif /* __FILESUP_H__ */ diff --git a/reactos/base/setup/usetup/fslist.c b/reactos/base/setup/usetup/fslist.c index 34b4f22085c..b8712f82988 100644 --- a/reactos/base/setup/usetup/fslist.c +++ b/reactos/base/setup/usetup/fslist.c @@ -32,14 +32,49 @@ /* 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 CreateFileSystemList( IN SHORT Left, IN SHORT Top, IN BOOLEAN ForceFormat, - IN FILE_SYSTEM ForceFileSystem) + IN LPCSTR ForceFileSystem) { PFILE_SYSTEM_LIST List; + PFILE_SYSTEM_ITEM Item; + PLIST_ENTRY ListEntry; List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_LIST)); if (List == NULL) @@ -47,18 +82,30 @@ CreateFileSystemList( List->Left = Left; List->Top = Top; + List->Selected = NULL; + InitializeListHead(&List->ListHead); - List->ForceFormat = ForceFormat; - List->FileSystemCount = 1; - if (ForceFormat) + AddProvider(List, "FAT", VfatFormat, NULL); + 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++; - List->CurrentFileSystem = FsKeep; + Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); + 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; } @@ -67,6 +114,19 @@ VOID DestroyFileSystemList( 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); } @@ -74,66 +134,51 @@ VOID DrawFileSystemList( IN PFILE_SYSTEM_LIST List) { + PLIST_ENTRY ListEntry; + PFILE_SYSTEM_ITEM Item; COORD coPos; ULONG Written; - ULONG Index; + ULONG Index = 0; + CHAR Buffer[70]; - Index = 0; - - 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) + ListEntry = List->ListHead.Flink; + while (ListEntry != &List->ListHead) { - CONSOLE_SetInvertedTextXY(List->Left, - List->Top + Index, - " Format partition as FAT file system "); - } - else - { - CONSOLE_SetTextXY(List->Left, - List->Top + Index, - " Format partition as FAT file system "); - } - Index++; + Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); - if (List->ForceFormat == FALSE) - { coPos.X = List->Left; coPos.Y = List->Top + Index; FillConsoleOutputAttribute(StdOutput, FOREGROUND_WHITE | BACKGROUND_BLUE, - 50, + sizeof(Buffer), coPos, &Written); FillConsoleOutputCharacterA(StdOutput, ' ', - 50, + sizeof(Buffer), coPos, &Written); - if (List->CurrentFileSystem == FsKeep) + if (Item->FileSystem) { - CONSOLE_SetInvertedTextXY(List->Left, - List->Top + Index, - " Keep current file system (no changes) "); + if (Item->QuickFormat) + sprintf(Buffer, " Format partition as %s file system (quick format) ", Item->FileSystem); + else + sprintf(Buffer, " Format partition as %s file system ", Item->FileSystem); } 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, List->Top + Index, - " Keep current file system (no changes) "); - } + Buffer); + Index++; + ListEntry = ListEntry->Flink; } } @@ -141,9 +186,9 @@ VOID ScrollDownFileSystemList( 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); } } @@ -152,9 +197,9 @@ VOID ScrollUpFileSystemList( 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); } } diff --git a/reactos/base/setup/usetup/fslist.h b/reactos/base/setup/usetup/fslist.h index 98c0463c8e9..7e114f0371c 100644 --- a/reactos/base/setup/usetup/fslist.h +++ b/reactos/base/setup/usetup/fslist.h @@ -28,19 +28,21 @@ #ifndef __FSLIST_H__ #define __FSLIST_H__ -typedef enum +typedef struct _FILE_SYSTEM_ITEM { - FsFat = 0, - FsKeep = 1 -} FILE_SYSTEM; + LIST_ENTRY ListEntry; + LPCSTR FileSystem; /* Not owned by the item */ + FORMATEX FormatFunc; + CHKDSKEX ChkdskFunc; + BOOLEAN QuickFormat; +} FILE_SYSTEM_ITEM, *PFILE_SYSTEM_ITEM; typedef struct _FILE_SYSTEM_LIST { SHORT Left; SHORT Top; - BOOLEAN ForceFormat; - FILE_SYSTEM CurrentFileSystem; - ULONG FileSystemCount; + PFILE_SYSTEM_ITEM Selected; + LIST_ENTRY ListHead; /* List of FILE_SYSTEM_ITEM */ } FILE_SYSTEM_LIST, *PFILE_SYSTEM_LIST; @@ -49,7 +51,7 @@ CreateFileSystemList( IN SHORT Left, IN SHORT Top, IN BOOLEAN ForceFormat, - IN FILE_SYSTEM ForceFileSystem); + IN LPCSTR ForceFileSystem); VOID DestroyFileSystemList( diff --git a/reactos/base/setup/usetup/usetup.c b/reactos/base/setup/usetup/usetup.c index 681fb19de9f..7bb7e846d06 100644 --- a/reactos/base/setup/usetup/usetup.c +++ b/reactos/base/setup/usetup/usetup.c @@ -2099,7 +2099,7 @@ SelectFileSystemPage (PINPUT_RECORD Ir) if (FileSystemList == NULL) { - FileSystemList = CreateFileSystemList (6, 26, PartEntry->New, FsFat); + FileSystemList = CreateFileSystemList (6, 26, PartEntry->New, "FAT"); if (FileSystemList == NULL) { /* FIXME: show an error dialog */ @@ -2147,7 +2147,7 @@ SelectFileSystemPage (PINPUT_RECORD Ir) } else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */ { - if (FileSystemList->CurrentFileSystem == FsKeep) + if (!FileSystemList->Selected->FormatFunc) { return CHECK_FILE_SYSTEM_PAGE; } @@ -2212,60 +2212,55 @@ FormatPartitionPage (PINPUT_RECORD Ir) { CONSOLE_SetStatusText (" Please wait ..."); - if (PartEntry->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED) - { - switch (FileSystemList->CurrentFileSystem) - { - case FsFat: - if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (4200LL * 1024LL)) - { - /* FAT12 CHS partition (disk is smaller than 4.1MB) */ - PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_12; - } - else if (PartEntry->PartInfo[0].StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL)) - { - /* Partition starts below the 8.4GB boundary ==> CHS partition */ + if (PartEntry->PartInfo[0].PartitionType == PARTITION_ENTRY_UNUSED) + { + if (strcmp(FileSystemList->Selected->FileSystem, "FAT") == 0) + { + if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (4200LL * 1024LL)) + { + /* FAT12 CHS partition (disk is smaller than 4.1MB) */ + PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_12; + } + else if (PartEntry->PartInfo[0].StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL)) + { + /* Partition starts below the 8.4GB boundary ==> CHS partition */ - if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (32LL * 1024LL * 1024LL)) - { - /* FAT16 CHS partition (partiton size < 32MB) */ - PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16; - } - else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) - { - /* FAT16 CHS partition (partition size < 512MB) */ - PartEntry->PartInfo[0].PartitionType = PARTITION_HUGE; - } - else - { - /* FAT32 CHS partition (partition size >= 512MB) */ - PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32; - } - } - else - { - /* Partition starts above the 8.4GB boundary ==> LBA partition */ + if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (32LL * 1024LL * 1024LL)) + { + /* FAT16 CHS partition (partiton size < 32MB) */ + PartEntry->PartInfo[0].PartitionType = PARTITION_FAT_16; + } + else if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) + { + /* FAT16 CHS partition (partition size < 512MB) */ + PartEntry->PartInfo[0].PartitionType = PARTITION_HUGE; + } + else + { + /* FAT32 CHS partition (partition size >= 512MB) */ + PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32; + } + } + else + { + /* Partition starts above the 8.4GB boundary ==> LBA partition */ - if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) - { - /* FAT16 LBA partition (partition size < 512MB) */ - PartEntry->PartInfo[0].PartitionType = PARTITION_XINT13; - } - else - { - /* FAT32 LBA partition (partition size >= 512MB) */ - PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32_XINT13; - } - } - break; - - case FsKeep: - break; - - default: - return QUIT_PAGE; - } - } + if (PartEntry->PartInfo[0].PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) + { + /* FAT16 LBA partition (partition size < 512MB) */ + PartEntry->PartInfo[0].PartitionType = PARTITION_XINT13; + } + else + { + /* FAT32 LBA partition (partition size >= 512MB) */ + PartEntry->PartInfo[0].PartitionType = PARTITION_FAT32_XINT13; + } + } + break; + } + else if (FileSystemList->Selected->FormatFunc) + return QUIT_PAGE; + } CheckActiveBootPartition (PartitionList); @@ -2343,79 +2338,81 @@ FormatPartitionPage (PINPUT_RECORD Ir) DPRINT ("SystemRootPath: %wZ\n", &SystemRootPath); - switch (FileSystemList->CurrentFileSystem) - { - case FsFat: - Status = FormatPartition (&DestinationRootPath); - if (!NT_SUCCESS (Status)) - { - DPRINT1 ("FormatPartition() failed with status 0x%.08x\n", Status); - /* FIXME: show an error dialog */ - return QUIT_PAGE; - } + if (FileSystemList->Selected->FormatFunc) + { + Status = FormatPartition(&DestinationRootPath, FileSystemList->Selected); + if (!NT_SUCCESS(Status)) + { + DPRINT1("FormatPartition() failed with status 0x%08lx\n", Status); + /* FIXME: show an error dialog */ + return QUIT_PAGE; + } - PartEntry->New = FALSE; - if (FileSystemList != NULL) - { - DestroyFileSystemList (FileSystemList); - FileSystemList = NULL; - } + PartEntry->New = FALSE; - CheckActiveBootPartition (PartitionList); + CheckActiveBootPartition(PartitionList); + } - /* FIXME: Install boot code. This is a hack! */ - if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13) || - (PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32)) - { - wcscpy (PathBuffer, SourceRootPath.Buffer); - wcscat (PathBuffer, L"\\loader\\fat32.bin"); + if (strcmp(FileSystemList->Selected->FileSystem, "FAT") == 0) + { + /* FIXME: Install boot code. This is a hack! */ + if ((PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32_XINT13) + || (PartEntry->PartInfo[0].PartitionType == PARTITION_FAT32)) + { + wcscpy(PathBuffer, SourceRootPath.Buffer); + wcscat(PathBuffer, L"\\loader\\fat32.bin"); - DPRINT ("Install FAT32 bootcode: %S ==> %S\n", PathBuffer, - DestinationRootPath.Buffer); - Status = InstallFat32BootCodeToDisk (PathBuffer, - DestinationRootPath.Buffer); - if (!NT_SUCCESS (Status)) - { - DPRINT1 ("InstallFat32BootCodeToDisk() failed with status 0x%.08x\n", Status); - /* FIXME: show an error dialog */ - return QUIT_PAGE; - } - } - else - { - wcscpy (PathBuffer, SourceRootPath.Buffer); - wcscat (PathBuffer, L"\\loader\\fat.bin"); + DPRINT("Install FAT32 bootcode: %S ==> %S\n", PathBuffer, + DestinationRootPath.Buffer); + Status = InstallFat32BootCodeToDisk(PathBuffer, + DestinationRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat32BootCodeToDisk() failed with status 0x%08lx\n", Status); + /* FIXME: show an error dialog */ + DestroyFileSystemList(FileSystemList); + FileSystemList = NULL; + return QUIT_PAGE; + } + } + else + { + wcscpy(PathBuffer, SourceRootPath.Buffer); + wcscat(PathBuffer, L"\\loader\\fat.bin"); - DPRINT ("Install FAT bootcode: %S ==> %S\n", PathBuffer, - DestinationRootPath.Buffer); - Status = InstallFat16BootCodeToDisk (PathBuffer, - DestinationRootPath.Buffer); - if (!NT_SUCCESS (Status)) - { - DPRINT1 ("InstallFat16BootCodeToDisk() failed with status 0x%.08x\n", Status); - /* FIXME: show an error dialog */ - return QUIT_PAGE; - } - } - break; - - case FsKeep: - break; - - default: - return QUIT_PAGE; - } + DPRINT("Install FAT bootcode: %S ==> %S\n", PathBuffer, + DestinationRootPath.Buffer); + Status = InstallFat16BootCodeToDisk(PathBuffer, + DestinationRootPath.Buffer); + if (!NT_SUCCESS(Status)) + { + DPRINT1("InstallFat16BootCodeToDisk() failed with status 0x%.08x\n", Status); + /* FIXME: show an error dialog */ + DestroyFileSystemList(FileSystemList); + FileSystemList = NULL; + return QUIT_PAGE; + } + } + } + else if (FileSystemList->Selected->FormatFunc) + { + DestroyFileSystemList(FileSystemList); + FileSystemList = NULL; + return QUIT_PAGE; + } #ifndef NDEBUG - CONSOLE_SetStatusText (" Done. Press any key ..."); - CONSOLE_ConInKey(Ir); + CONSOLE_SetStatusText (" Done. Press any key ..."); + CONSOLE_ConInKey(Ir); #endif - return INSTALL_DIRECTORY_PAGE; - } + DestroyFileSystemList(FileSystemList); + FileSystemList = NULL; + return INSTALL_DIRECTORY_PAGE; + } } - return FORMAT_PARTITION_PAGE; + return FORMAT_PARTITION_PAGE; } diff --git a/reactos/base/setup/usetup/usetup.h b/reactos/base/setup/usetup/usetup.h index 133b76b9eb0..fa151f89071 100644 --- a/reactos/base/setup/usetup/usetup.h +++ b/reactos/base/setup/usetup/usetup.h @@ -64,8 +64,8 @@ #include "bootsup.h" #include "keytrans.h" #include "registry.h" -#include "format.h" #include "fslist.h" +#include "format.h" #include "cabinet.h" #include "filesup.h" #include "drivesup.h"