mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
[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
This commit is contained in:
parent
3a19ee6a96
commit
1716749bcb
5 changed files with 155 additions and 100 deletions
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue