https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1716749bcbc33c24a99838...
commit 1716749bcbc33c24a9983849dd7c88e408de0cf5 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Wed May 17 23:31:52 2017 +0000 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Sun May 27 20:18:51 2018 +0200
[SETUPLIB] Consolidate the FsUtil and PartList modules of the SetupLib.
- Add a PreparePartitionForFormatting routine that sets the partition ID depending on the chosen filesystem. - The 'FORMATMACHINESTATE FormatState' machine-state and the 'TempPartition' members of the partition list structure is purely a USETUP convenience, so remove them from the PARTLIST structure and move them back into USETUP. - Attempt to recognize the filesystem (set the 'FileSystem' member of PARTENTRY) of partitions we are adding into the PARTLIST list. - Fix the return value of the SelectPartition function, which is by the way completely broken (it doesn't do what it is supposed to do; alternatively its naming is completely wrong...).
svn path=/branches/setup_improvements/; revision=74572 svn path=/branches/setup_improvements/; revision=74573 --- base/setup/lib/fsutil.c | 142 +++++++++++++++++++++++++++++++++++++++++-- base/setup/lib/fsutil.h | 6 ++ base/setup/lib/partlist.c | 83 ++++--------------------- base/setup/lib/partlist.h | 22 +------ base/setup/usetup/partlist.h | 2 - 5 files changed, 155 insertions(+), 100 deletions(-)
diff --git a/base/setup/lib/fsutil.c b/base/setup/lib/fsutil.c index 468fed9284..16da7f5a56 100644 --- a/base/setup/lib/fsutil.c +++ b/base/setup/lib/fsutil.c @@ -24,23 +24,28 @@ #include "fsutil.h" #include "partlist.h"
-/** For FileSystems **/ #include <fslib/vfatlib.h> -#include <fslib/ext2lib.h> +// #include <fslib/ext2lib.h> // #include <fslib/ntfslib.h>
#define NDEBUG #include <debug.h>
- FILE_SYSTEM RegisteredFileSystems[] = { { L"FAT" , VfatFormat, VfatChkdsk }, // { L"FAT32", VfatFormat, VfatChkdsk }, #if 0 + { L"FATX" , VfatxFormat, VfatxChkdsk }, + { L"NTFS" , NtfsFormat, NtfsChkdsk }, + { L"EXT2" , Ext2Format, Ext2Chkdsk }, - { L"NTFS" , NtfsFormat, NtfsChkdsk } + { L"EXT3" , Ext2Format, Ext2Chkdsk }, + { L"EXT4" , Ext2Format, Ext2Chkdsk }, + { L"BTRFS", BtrfsFormatEx, BtrfsChkdskEx }, + { L"FFS" , FfsFormat , FfsChkdsk }, + { L"REISERFS", ReiserfsFormat, ReiserfsChkdsk }, #endif };
@@ -198,7 +203,44 @@ GetFileSystem(
CurrentFileSystem = NULL;
-#if 0 // FIXME: To be fully enabled when our storage stack & al. will work better! +#if 0 // This is an example of old code... + + if ((PartEntry->PartitionType == PARTITION_FAT_12) || + (PartEntry->PartitionType == PARTITION_FAT_16) || + (PartEntry->PartitionType == PARTITION_HUGE) || + (PartEntry->PartitionType == PARTITION_XINT13) || + (PartEntry->PartitionType == PARTITION_FAT32) || + (PartEntry->PartitionType == PARTITION_FAT32_XINT13)) + { + if (CheckFatFormat()) + FileSystemName = L"FAT"; + else + FileSystemName = NULL; + } + else if (PartEntry->PartitionType == PARTITION_EXT2) + { + if (CheckExt2Format()) + FileSystemName = L"EXT2"; + else + FileSystemName = NULL; + } + else if (PartEntry->PartitionType == PARTITION_IFS) + { + if (CheckNtfsFormat()) + FileSystemName = L"NTFS"; + else if (CheckHpfsFormat()) + FileSystemName = L"HPFS"; + else + FileSystemName = NULL; + } + else + { + FileSystemName = NULL; + } + +#endif + +#if 0 // FIXME: To be fully enabled when our storage stack & al. work better!
/* * We don't have one... @@ -246,11 +288,13 @@ GetFileSystem( { // WARNING: See the warning above. FileSystemName = L"EXT2"; + // FIXME: We may have EXT3, 4 too... } else if (PartEntry->PartitionType == PARTITION_IFS) { // WARNING: See the warning above. FileSystemName = L"NTFS"; /* FIXME: Not quite correct! */ + // FIXME: We may have HPFS too... }
#if 0 @@ -268,9 +312,95 @@ Quit: // For code temporarily disabled above PartEntry->PartitionType, FileSystemName ? FileSystemName : L"None");
if (FileSystemName != NULL) - CurrentFileSystem = GetFileSystemByName(/*FileSystemList,*/ FileSystemName); + CurrentFileSystem = GetFileSystemByName(FileSystemName);
return CurrentFileSystem; }
+ +// +// Formatting routines +// + +BOOLEAN +PreparePartitionForFormatting( + IN struct _PARTENTRY* PartEntry, + IN PFILE_SYSTEM FileSystem) +{ + if (!FileSystem) + { + DPRINT1("No file system specified?\n"); + return FALSE; + } + + if (wcscmp(FileSystem->FileSystemName, L"FAT") == 0) + { + if (PartEntry->SectorCount.QuadPart < 8192) + { + /* FAT12 CHS partition (disk is smaller than 4.1MB) */ + SetPartitionType(PartEntry, PARTITION_FAT_12); + } + else if (PartEntry->StartSector.QuadPart < 1450560) + { + /* Partition starts below the 8.4GB boundary ==> CHS partition */ + + if (PartEntry->SectorCount.QuadPart < 65536) + { + /* FAT16 CHS partition (partition size < 32MB) */ + SetPartitionType(PartEntry, PARTITION_FAT_16); + } + else if (PartEntry->SectorCount.QuadPart < 1048576) + { + /* FAT16 CHS partition (partition size < 512MB) */ + SetPartitionType(PartEntry, PARTITION_HUGE); + } + else + { + /* FAT32 CHS partition (partition size >= 512MB) */ + SetPartitionType(PartEntry, PARTITION_FAT32); + } + } + else + { + /* Partition starts above the 8.4GB boundary ==> LBA partition */ + + if (PartEntry->SectorCount.QuadPart < 1048576) + { + /* FAT16 LBA partition (partition size < 512MB) */ + SetPartitionType(PartEntry, PARTITION_XINT13); + } + else + { + /* FAT32 LBA partition (partition size >= 512MB) */ + SetPartitionType(PartEntry, PARTITION_FAT32_XINT13); + } + } + } +#if 0 + else if (wcscmp(FileSystem->FileSystemName, L"EXT2") == 0) + { + SetPartitionType(PartEntry, PARTITION_EXT2); + } + else if (wcscmp(FileSystem->FileSystemName, L"NTFS") == 0) + { + SetPartitionType(PartEntry, PARTITION_IFS); + } +#endif + else + { + /* Unknown file system? */ + DPRINT1("Unknown file system "%S"?\n", FileSystem->FileSystemName); + return FALSE; + } + +// +// FIXME: Do this now, or after the partition was actually formatted?? +// + /* Set the new partition's file system proper */ + PartEntry->FormatState = Formatted; // Well... This may be set after the real formatting takes place (in which case we should change the FormatState to another value) + PartEntry->FileSystem = FileSystem; + + return TRUE; +} + /* EOF */ diff --git a/base/setup/lib/fsutil.h b/base/setup/lib/fsutil.h index 9d6d4a0a92..6fbd864f83 100644 --- a/base/setup/lib/fsutil.h +++ b/base/setup/lib/fsutil.h @@ -31,4 +31,10 @@ GetFileSystem( // IN PFILE_SYSTEM_LIST FileSystemList, IN struct _PARTENTRY* PartEntry);
+ +BOOLEAN +PreparePartitionForFormatting( + IN struct _PARTENTRY* PartEntry, + IN PFILE_SYSTEM FileSystem); + /* EOF */ diff --git a/base/setup/lib/partlist.c b/base/setup/lib/partlist.c index 40661b0126..583544b96c 100644 --- a/base/setup/lib/partlist.c +++ b/base/setup/lib/partlist.c @@ -487,6 +487,7 @@ AddPartitionToDisk( PPARTENTRY PartEntry;
PartitionInfo = &DiskEntry->LayoutBuffer->PartitionEntry[PartitionIndex]; + if (PartitionInfo->PartitionType == PARTITION_ENTRY_UNUSED || ((LogicalPartition != FALSE) && IsContainerPartition(PartitionInfo->PartitionType))) { @@ -497,9 +498,7 @@ AddPartitionToDisk( HEAP_ZERO_MEMORY, sizeof(PARTENTRY)); if (PartEntry == NULL) - { return; - }
PartEntry->DiskEntry = DiskEntry;
@@ -523,12 +522,10 @@ AddPartitionToDisk( if (LogicalPartition == FALSE && DiskEntry->ExtendedPartition == NULL) DiskEntry->ExtendedPartition = PartEntry; } -#if 0 else if (IsRecognizedPartition(PartEntry->PartitionType)) { - // FIXME FIXME! We should completely rework how we get this 'FileSystemList' available... - PartEntry->FileSystem = GetFileSystem(/*FileSystemList,*/ PartEntry); - if (!PartEntry->FileSystem) + PartEntry->FileSystem = GetFileSystem(PartEntry); + if (PartEntry->FileSystem) PartEntry->FormatState = Preformatted; else PartEntry->FormatState = Unformatted; @@ -536,63 +533,7 @@ AddPartitionToDisk( } else { - /* Unknown partition, so unknown partition format (may or may not be actually formatted) */ - PartEntry->FormatState = UnknownFormat; - } -#endif - else if ((PartEntry->PartitionType == PARTITION_FAT_12) || - (PartEntry->PartitionType == PARTITION_FAT_16) || - (PartEntry->PartitionType == PARTITION_HUGE) || - (PartEntry->PartitionType == PARTITION_XINT13) || - (PartEntry->PartitionType == PARTITION_FAT32) || - (PartEntry->PartitionType == PARTITION_FAT32_XINT13)) - { -#if 0 - if (CheckFatFormat()) - { - PartEntry->FormatState = Preformatted; - } - else - { - PartEntry->FormatState = Unformatted; - } -#endif - PartEntry->FormatState = Preformatted; - } - else if (PartEntry->PartitionType == PARTITION_EXT2) - { -#if 0 - if (CheckExt2Format()) - { - PartEntry->FormatState = Preformatted; - } - else - { - PartEntry->FormatState = Unformatted; - } -#endif - PartEntry->FormatState = Preformatted; - } - else if (PartEntry->PartitionType == PARTITION_IFS) - { -#if 0 - if (CheckNtfsFormat()) - { - PartEntry->FormatState = Preformatted; - } - else if (CheckHpfsFormat()) - { - PartEntry->FormatState = Preformatted; - } - else - { - PartEntry->FormatState = Unformatted; - } -#endif - PartEntry->FormatState = Preformatted; - } - else - { + /* Unknown partition, hence unknown partition format (may or may not be actually formatted) */ PartEntry->FormatState = UnknownFormat; }
@@ -1257,9 +1198,6 @@ CreatePartitionList(VOID) List->SystemPartition = NULL; List->OriginalSystemPartition = NULL;
- List->TempPartition = NULL; - List->FormatState = Start; - InitializeListHead(&List->DiskListHead); InitializeListHead(&List->BiosDiskListHead);
@@ -1392,7 +1330,10 @@ DestroyPartitionList( RtlFreeHeap(ProcessHeap, 0, List); }
-ULONG +// +// FIXME: This function is COMPLETELY BROKEN!!!! +// +BOOLEAN SelectPartition( IN PPARTLIST List, IN ULONG DiskNumber, @@ -2396,9 +2337,7 @@ DeleteCurrentPartition(
VOID CheckActiveSystemPartition( - IN PPARTLIST List // , - // IN PFILE_SYSTEM_LIST FileSystemList /* Needed for checking the FS of the candidate system partition */ - ) + IN PPARTLIST List) { PDISKENTRY DiskEntry; PPARTENTRY PartEntry; @@ -2575,7 +2514,7 @@ CheckActiveSystemPartition( * NOTE also that for those architectures looking for a * partition boot indicator is insufficient. */ - FileSystem = GetFileSystem(/*FileSystemList,*/ List->OriginalSystemPartition); + FileSystem = GetFileSystem(List->OriginalSystemPartition); if (FileSystem == NULL) { DPRINT1("System partition %lu in disk %lu with no FS?!\n", @@ -2584,7 +2523,7 @@ CheckActiveSystemPartition( goto FindAndUseAlternativeSystemPartition; } // HACK: WARNING: We cannot write on this FS yet! - // See fslist.c:GetFileSystem() + // See fsutil.c:GetFileSystem() if (List->OriginalSystemPartition->PartitionType == PARTITION_EXT2 || List->OriginalSystemPartition->PartitionType == PARTITION_IFS) { diff --git a/base/setup/lib/partlist.h b/base/setup/lib/partlist.h index 80a8823fb5..7a6cec9487 100644 --- a/base/setup/lib/partlist.h +++ b/base/setup/lib/partlist.h @@ -17,19 +17,6 @@ typedef enum _FORMATSTATE Formatted } FORMATSTATE, *PFORMATSTATE;
-typedef enum _FORMATMACHINESTATE -{ - Start, - FormatSystemPartition, - FormatInstallPartition, - FormatOtherPartition, - FormatDone, - CheckSystemPartition, - CheckInstallPartition, - CheckOtherPartition, - CheckDone -} FORMATMACHINESTATE, *PFORMATMACHINESTATE; - struct _FILE_SYSTEM;
typedef struct _PARTENTRY @@ -163,9 +150,6 @@ typedef struct _PARTLIST */ PPARTENTRY OriginalSystemPartition;
- PPARTENTRY TempPartition; - FORMATMACHINESTATE FormatState; - LIST_ENTRY DiskListHead; LIST_ENTRY BiosDiskListHead;
@@ -234,7 +218,7 @@ VOID DestroyPartitionList( IN PPARTLIST List);
-ULONG +BOOLEAN SelectPartition( IN PPARTLIST List, IN ULONG DiskNumber, @@ -271,9 +255,7 @@ DeleteCurrentPartition(
VOID CheckActiveSystemPartition( - IN PPARTLIST List // , - // IN PFILE_SYSTEM_LIST FileSystemList /* Needed for checking the FS of the candidate system partition */ - ); + IN PPARTLIST List);
BOOLEAN WritePartitionsToDisk( diff --git a/base/setup/usetup/partlist.h b/base/setup/usetup/partlist.h index 2ad6041d33..b8caf457d4 100644 --- a/base/setup/usetup/partlist.h +++ b/base/setup/usetup/partlist.h @@ -27,7 +27,6 @@
#include "../lib/partlist.h"
-#if 0 typedef enum _FORMATMACHINESTATE { Start, @@ -40,7 +39,6 @@ typedef enum _FORMATMACHINESTATE CheckOtherPartition, CheckDone } FORMATMACHINESTATE, *PFORMATMACHINESTATE; -#endif
typedef struct _PARTLIST_UI {